mpvrc/openssl/sha/index.html

30 lines
No EOL
7.3 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-Regular-0fe48ade.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" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.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.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.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]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../openssl/index.html">openssl</a><span class="version">0.10.68</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"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">openssl</a></span><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><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Sha1.html" title="struct openssl::sha::Sha1">Sha1</a></div><div class="desc docblock-short">An object which calculates a SHA1 hash of some data.</div></li><li><div class="item-name"><a class="struct" href="struct.Sha224.html" title="struct openssl::sha::Sha224">Sha224</a></div><div class="desc docblock-short">An object which calculates a SHA224 hash of some data.</div></li><li><div class="item-name"><a class="struct" href="struct.Sha256.html" title="struct openssl::sha::Sha256">Sha256</a></div><div class="desc docblock-short">An object which calculates a SHA256 hash of some data.</div></li><li><div class="item-name"><a class="struct" href="struct.Sha384.html" title="struct openssl::sha::Sha384">Sha384</a></div><div class="desc docblock-short">An object which calculates a SHA384 hash of some data.</div></li><li><div class="item-name"><a class="struct" href="struct.Sha512.html" title="struct openssl::sha::Sha512">Sha512</a></div><div class="desc docblock-short">An object which calculates a SHA512 hash of some data.</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.sha1.html" title="fn openssl::sha::sha1">sha1</a></div><div class="desc docblock-short">Computes the SHA1 hash of some data.</div></li><li><div class="item-name"><a class="fn" href="fn.sha224.html" title="fn openssl::sha::sha224">sha224</a></div><div class="desc docblock-short">Computes the SHA224 hash of some data.</div></li><li><div class="item-name"><a class="fn" href="fn.sha256.html" title="fn openssl::sha::sha256">sha256</a></div><div class="desc docblock-short">Computes the SHA256 hash of some data.</div></li><li><div class="item-name"><a class="fn" href="fn.sha384.html" title="fn openssl::sha::sha384">sha384</a></div><div class="desc docblock-short">Computes the SHA384 hash of some data.</div></li><li><div class="item-name"><a class="fn" href="fn.sha512.html" title="fn openssl::sha::sha512">sha512</a></div><div class="desc docblock-short">Computes the SHA512 hash of some data.</div></li></ul></section></div></main></body></html>