29 lines
6.8 KiB
HTML
29 lines
6.8 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="The SHA family of hashes."><title>openssl::sha - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="openssl" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Module sha</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../openssl/index.html">openssl</a><span class="version">0.10.75</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module sha</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate openssl</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">openssl</a></div><h1>Module <span>sha</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/openssl/sha.rs.html#1-463">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>The SHA family of hashes.</p>
|
|
<p>SHA, or Secure Hash Algorithms, are a family of cryptographic hashing algorithms published by
|
|
the National Institute of Standards and Technology (NIST). Hash algorithms such as those in
|
|
the SHA family are used to map data of an arbitrary size to a fixed-size string of bytes.
|
|
As cryptographic hashing algorithms, these mappings have the property of being irreversible.
|
|
This property makes hash algorithms like these excellent for uses such as verifying the
|
|
contents of a file- if you know the hash you expect beforehand, then you can verify that the
|
|
data you have is correct if it hashes to the same value.</p>
|
|
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
|
<p>When dealing with data that becomes available in chunks, such as while buffering data from IO,
|
|
you can create a hasher that you can repeatedly update to add bytes to.</p>
|
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>openssl::sha;
|
|
|
|
<span class="kw">let </span><span class="kw-2">mut </span>hasher = sha::Sha256::new();
|
|
|
|
hasher.update(<span class="string">b"Hello, "</span>);
|
|
hasher.update(<span class="string">b"world"</span>);
|
|
|
|
<span class="kw">let </span>hash = hasher.finish();
|
|
<span class="macro">println!</span>(<span class="string">"Hashed \"Hello, world\" to {}"</span>, hex::encode(hash));</code></pre></div>
|
|
<p>On the other hand, if you already have access to all of the data you would like to hash, you
|
|
may prefer to use the slightly simpler method of simply calling the hash function corresponding
|
|
to the algorithm you want to use.</p>
|
|
|
|
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>openssl::sha::sha256;
|
|
|
|
<span class="kw">let </span>hash = sha256(<span class="string">b"your data or message"</span>);
|
|
<span class="macro">println!</span>(<span class="string">"Hash = {}"</span>, hex::encode(hash));</code></pre></div></div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.Sha1.html" title="struct openssl::sha::Sha1">Sha1</a></dt><dd>An object which calculates a SHA1 hash of some data.</dd><dt><a class="struct" href="struct.Sha224.html" title="struct openssl::sha::Sha224">Sha224</a></dt><dd>An object which calculates a SHA224 hash of some data.</dd><dt><a class="struct" href="struct.Sha256.html" title="struct openssl::sha::Sha256">Sha256</a></dt><dd>An object which calculates a SHA256 hash of some data.</dd><dt><a class="struct" href="struct.Sha384.html" title="struct openssl::sha::Sha384">Sha384</a></dt><dd>An object which calculates a SHA384 hash of some data.</dd><dt><a class="struct" href="struct.Sha512.html" title="struct openssl::sha::Sha512">Sha512</a></dt><dd>An object which calculates a SHA512 hash of some data.</dd></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.sha1.html" title="fn openssl::sha::sha1">sha1</a></dt><dd>Computes the SHA1 hash of some data.</dd><dt><a class="fn" href="fn.sha224.html" title="fn openssl::sha::sha224">sha224</a></dt><dd>Computes the SHA224 hash of some data.</dd><dt><a class="fn" href="fn.sha256.html" title="fn openssl::sha::sha256">sha256</a></dt><dd>Computes the SHA256 hash of some data.</dd><dt><a class="fn" href="fn.sha384.html" title="fn openssl::sha::sha384">sha384</a></dt><dd>Computes the SHA384 hash of some data.</dd><dt><a class="fn" href="fn.sha512.html" title="fn openssl::sha::sha512">sha512</a></dt><dd>Computes the SHA512 hash of some data.</dd></dl></section></div></main></body></html> |