Files
GopherGate/target/doc/rand_chacha/index.html
2026-02-26 12:00:21 -05:00

43 lines
9.5 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 ChaCha random number generators."><title>rand_chacha - 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="rand_chacha" 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="../crates.js"></script><script defer src="../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-263c88ec.css"></noscript><link rel="icon" href="https://www.rust-lang.org/favicon.ico"></head><body class="rustdoc mod crate"><!--[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="#">Crate rand_chacha</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../rand_chacha/index.html"><img src="https://www.rust-lang.org/logos/rust-logo-128x128-blk.png" alt="logo"></a><h2><a href="../rand_chacha/index.html">rand_<wbr>chacha</a><span class="version">0.9.0</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#generators" title="Generators">Generators</a></li><li><a href="#cryptographic-secure-usage" title="Cryptographic (secure) usage">Cryptographic (secure) usage</a></li><li><a href="#seeding-construction" title="Seeding (construction)">Seeding (construction)</a></li><li><a href="#generation" title="Generation">Generation</a></li></ul><h3><a href="#reexports">Crate Items</a></h3><ul class="block"><li><a href="#reexports" title="Re-exports">Re-exports</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"></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"><h1>Crate <span>rand_<wbr>chacha</span>&nbsp;<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/rand_chacha/lib.rs.html#9-106">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>The ChaCha random number generators.</p>
<p>These are native Rust implementations of RNGs derived from the
<a href="https://cr.yp.to/chacha.html">ChaCha stream ciphers</a> by D J Bernstein.</p>
<h3 id="generators"><a class="doc-anchor" href="#generators">§</a>Generators</h3>
<p>This crate provides 8-, 12- and 20-round variants of generators via a “core”
implementation (of <a href="../rand_core/block/trait.BlockRngCore.html" title="trait rand_core::block::BlockRngCore"><code>BlockRngCore</code></a>), each with an associated “RNG” type
(implementing <a href="../rand_core/trait.RngCore.html" title="trait rand_core::RngCore"><code>RngCore</code></a>).</p>
<p>These generators are all deterministic and portable (see <a href="https://rust-random.github.io/book/crate-reprod.html">Reproducibility</a>
in the book), with testing against reference vectors.</p>
<h3 id="cryptographic-secure-usage"><a class="doc-anchor" href="#cryptographic-secure-usage">§</a>Cryptographic (secure) usage</h3>
<p>Where secure unpredictable generators are required, it is suggested to use
<a href="struct.ChaCha12Rng.html" title="struct rand_chacha::ChaCha12Rng"><code>ChaCha12Rng</code></a> or <a href="struct.ChaCha20Rng.html" title="struct rand_chacha::ChaCha20Rng"><code>ChaCha20Rng</code></a> and to seed via
<a href="../rand_core/trait.SeedableRng.html#method.from_os_rng" title="associated function rand_core::SeedableRng::from_os_rng"><code>SeedableRng::from_os_rng</code></a>.</p>
<p>See also the <a href="https://rust-random.github.io/book/guide-rngs.html#security">Security</a> chapter in the rand book. The crate is provided
“as is”, without any form of guarantee, and without a security audit.</p>
<h3 id="seeding-construction"><a class="doc-anchor" href="#seeding-construction">§</a>Seeding (construction)</h3>
<p>Generators implement the <a href="../rand_core/trait.SeedableRng.html" title="trait rand_core::SeedableRng"><code>SeedableRng</code></a> trait. Any method may be used,
but note that <code>seed_from_u64</code> is not suitable for usage where security is
important. Some suggestions:</p>
<ol>
<li>With a fresh seed, <strong>direct from the OS</strong> (implies a syscall):
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>rng = ChaCha12Rng::from_os_rng();</code></pre></div></li>
<li><strong>From a master generator.</strong> This could be <a href="https://docs.rs/rand/latest/rand/fn.rng.html"><code>rand::rng</code></a>
(effectively a fresh seed without the need for a syscall on each usage)
or a deterministic generator such as <a href="struct.ChaCha20Rng.html" title="struct rand_chacha::ChaCha20Rng"><code>ChaCha20Rng</code></a>.
Beware that should a weak master generator be used, correlations may be
detectable between the outputs of its child generators.
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested"></a><pre class="rust rust-example-rendered"><code><span class="kw">let </span>rng = ChaCha12Rng::from_rng(<span class="kw-2">&amp;mut </span>rand::rng());</code></pre></div></li>
</ol>
<p>See also <a href="https://rust-random.github.io/book/guide-seeding.html">Seeding RNGs</a> in the book.</p>
<h3 id="generation"><a class="doc-anchor" href="#generation">§</a>Generation</h3>
<p>Generators implement <a href="../rand_core/trait.RngCore.html" title="trait rand_core::RngCore"><code>RngCore</code></a>, whose methods may be used directly to
generate unbounded integer or byte values.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>rand_core::{SeedableRng, RngCore};
<span class="kw">use </span>rand_chacha::ChaCha12Rng;
<span class="kw">let </span><span class="kw-2">mut </span>rng = ChaCha12Rng::from_seed(Default::default());
<span class="kw">let </span>x = rng.next_u64();
<span class="macro">assert_eq!</span>(x, <span class="number">0x53f955076a9af49b</span>);</code></pre></div>
<p>It is often more convenient to use the <a href="https://docs.rs/rand/latest/rand/fn.rng.html"><code>rand::Rng</code></a> trait, which provides
further functionality. See also the <a href="https://rust-random.github.io/book/guide-values.html">Random Values</a> chapter in the book.</p>
</div></details><h2 id="reexports" class="section-header">Re-exports<a href="#reexports" class="anchor">§</a></h2><dl class="item-table reexports"><dt id="reexport.rand_core"><code>pub use <a class="mod" href="../rand_core/index.html" title="mod rand_core">rand_core</a>;</code></dt></dl><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.ChaCha8Core.html" title="struct rand_chacha::ChaCha8Core">ChaCha8<wbr>Core</a></dt><dd>ChaCha with 8 rounds</dd><dt><a class="struct" href="struct.ChaCha8Rng.html" title="struct rand_chacha::ChaCha8Rng">ChaCha8<wbr>Rng</a></dt><dd>A cryptographically secure random number generator that uses the ChaCha algorithm.</dd><dt><a class="struct" href="struct.ChaCha12Core.html" title="struct rand_chacha::ChaCha12Core">ChaCha12<wbr>Core</a></dt><dd>ChaCha with 12 rounds</dd><dt><a class="struct" href="struct.ChaCha12Rng.html" title="struct rand_chacha::ChaCha12Rng">ChaCha12<wbr>Rng</a></dt><dd>A cryptographically secure random number generator that uses the ChaCha algorithm.</dd><dt><a class="struct" href="struct.ChaCha20Core.html" title="struct rand_chacha::ChaCha20Core">ChaCha20<wbr>Core</a></dt><dd>ChaCha with 20 rounds</dd><dt><a class="struct" href="struct.ChaCha20Rng.html" title="struct rand_chacha::ChaCha20Rng">ChaCha20<wbr>Rng</a></dt><dd>A cryptographically secure random number generator that uses the ChaCha algorithm.</dd></dl><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><dl class="item-table"><dt><a class="type" href="type.ChaChaCore.html" title="type rand_chacha::ChaChaCore">ChaCha<wbr>Core</a></dt><dd>ChaCha with 20 rounds, low-level interface</dd><dt><a class="type" href="type.ChaChaRng.html" title="type rand_chacha::ChaChaRng">ChaCha<wbr>Rng</a></dt><dd>ChaCha with 20 rounds</dd></dl></section></div></main></body></html>