1
0
Fork 0
mirror of https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git synced 2025-12-28 18:42:18 +01:00
redox-ssh/crypto/sha1/fn.sha1_digest_block.html

161 lines
No EOL
8.5 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="API documentation for the Rust `sha1_digest_block` fn in crate `crypto`.">
<meta name="keywords" content="rust, rustlang, rust-lang, sha1_digest_block">
<title>crypto::sha1::sha1_digest_block - Rust</title>
<link rel="stylesheet" type="text/css" href="../../normalize.css">
<link rel="stylesheet" type="text/css" href="../../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../../main.css">
</head>
<body class="rustdoc fn">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
<p class='location'><a href='../index.html'>crypto</a>::<wbr><a href='index.html'>sha1</a></p><script>window.sidebarCurrent = {name: 'sha1_digest_block', ty: 'fn', relpath: ''};</script><script defer src="sidebar-items.js"></script>
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content">
<h1 class='fqn'><span class='in-band'>Function <a href='../index.html'>crypto</a>::<wbr><a href='index.html'>sha1</a>::<wbr><a class="fn" href=''>sha1_digest_block</a></span><span class='out-of-band'><span id='render-detail'>
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
[<span class='inner'>&#x2212;</span>]
</a>
</span><a class='srclink' href='../../src/crypto/sha1.rs.html#348-353' title='goto source code'>[src]</a></span></h1>
<pre class='rust fn'>pub fn sha1_digest_block(state: &amp;mut <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">; 5]</a>, block: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>)</pre><div class='docblock'><p>Process a block with the SHA-1 algorithm. (See more...)</p>
<p>SHA-1 is a cryptographic hash function, and as such, it operates
on an arbitrary number of bytes. This function operates on a fixed
number of bytes. If you call this function with anything other than
64 bytes, then it will panic! This function takes two arguments:</p>
<ul>
<li><code>state</code> is reference to an <strong>array</strong> of 5 words.</li>
<li><code>block</code> is reference to a <strong>slice</strong> of 64 bytes.</li>
</ul>
<p>If you want the function that performs a message digest on an arbitrary
number of bytes, then see also the <code>Sha1</code> struct above.</p>
<h1 id='implementation' class='section-header'><a href='#implementation'>Implementation</a></h1>
<p>First, some background. Both ARM and Intel are releasing documentation
that they plan to include instruction set extensions for SHA1 and SHA256
sometime in the near future. Second, LLVM won&#39;t lower these intrinsics yet,
so these functions were written emulate these instructions. Finally,
the block function implemented with these emulated intrinsics turned out
to be quite fast! What follows is a discussion of this CPU-level view
of the SHA-1 algorithm and how it relates to the mathematical definition.</p>
<p>The SHA instruction set extensions can be divided up into two categories:</p>
<ul>
<li>message work schedule update calculation (&quot;schedule&quot; v., &quot;work&quot; n.)</li>
<li>message block 80-round digest calculation (&quot;digest&quot; v., &quot;block&quot; n.)</li>
</ul>
<p>The schedule-related functions can be used to easily perform 4 rounds
of the message work schedule update calculation, as shown below:</p>
<pre class="rust rust-example-rendered">
<span class="macro">macro_rules</span><span class="macro">!</span> <span class="ident">schedule_x4</span> {
(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">v0</span>:<span class="ident">expr</span>, <span class="macro-nonterminal">$</span><span class="macro-nonterminal">v1</span>:<span class="ident">expr</span>, <span class="macro-nonterminal">$</span><span class="macro-nonterminal">v2</span>:<span class="ident">expr</span>, <span class="macro-nonterminal">$</span><span class="macro-nonterminal">v3</span>:<span class="ident">expr</span>) <span class="op">=&gt;</span> (
<span class="ident">sha1msg2</span>(<span class="ident">sha1msg1</span>(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">v0</span>, <span class="macro-nonterminal">$</span><span class="macro-nonterminal">v1</span>) <span class="op">^</span> <span class="macro-nonterminal">$</span><span class="macro-nonterminal">v2</span>, <span class="macro-nonterminal">$</span><span class="macro-nonterminal">v3</span>)
)
}
<span class="macro">macro_rules</span><span class="macro">!</span> <span class="ident">round_x4</span> {
(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">h0</span>:<span class="ident">ident</span>, <span class="macro-nonterminal">$</span><span class="macro-nonterminal">h1</span>:<span class="ident">ident</span>, <span class="macro-nonterminal">$</span><span class="macro-nonterminal">wk</span>:<span class="ident">expr</span>, <span class="macro-nonterminal">$</span><span class="macro-nonterminal">i</span>:<span class="ident">expr</span>) <span class="op">=&gt;</span> (
<span class="ident">sha1rnds4</span>(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">h0</span>, <span class="ident">sha1_first_half</span>(<span class="macro-nonterminal">$</span><span class="macro-nonterminal">h1</span>, <span class="macro-nonterminal">$</span><span class="macro-nonterminal">wk</span>), <span class="macro-nonterminal">$</span><span class="macro-nonterminal">i</span>)
)
}</pre>
<p>and also shown above is how the digest-related functions can be used to
perform 4 rounds of the message block digest calculation.</p>
</div></section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../../";
window.currentCrate = "crypto";
</script>
<script src="../../main.js"></script>
<script defer src="../../search-index.js"></script>
</body>
</html>