30 lines
13 KiB
HTML
30 lines
13 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="A marker trait over `RngCore` for securely unpredictable RNGs"><title>CryptoRng in rand - 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" 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="icon" href="https://www.rust-lang.org/favicon.ico"></head><body class="rustdoc trait"><!--[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="#">CryptoRng</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../rand/index.html"><img src="https://www.rust-lang.org/logos/rust-logo-128x128-blk.png" alt="logo"></a><h2><a href="../rand/index.html">rand</a><span class="version">0.9.2</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Crypto<wbr>Rng</a></h2><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-CryptoRng-for-ChaCha8Rng" title="ChaCha8Rng">ChaCha8Rng</a></li><li><a href="#impl-CryptoRng-for-ChaCha12Rng" title="ChaCha12Rng">ChaCha12Rng</a></li><li><a href="#impl-CryptoRng-for-ChaCha20Rng" title="ChaCha20Rng">ChaCha20Rng</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate rand</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">rand</a></div><h1>Trait <span class="trait">Crypto<wbr>Rng</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/rand_core/lib.rs.html#204">Source</a> </span></div><pre class="rust item-decl"><code>pub trait CryptoRng: <a class="trait" href="trait.RngCore.html" title="trait rand::RngCore">RngCore</a> { }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A marker trait over <a href="trait.RngCore.html" title="trait rand::RngCore"><code>RngCore</code></a> for securely unpredictable RNGs</p>
|
||
<p>This marker trait indicates that the implementing generator is intended,
|
||
when correctly seeded and protected from side-channel attacks such as a
|
||
leaking of state, to be a cryptographically secure generator. This trait is
|
||
provided as a tool to aid review of cryptographic code, but does not by
|
||
itself guarantee suitability for cryptographic applications.</p>
|
||
<p>Implementors of <code>CryptoRng</code> automatically implement the <a href="trait.TryCryptoRng.html" title="trait rand::TryCryptoRng"><code>TryCryptoRng</code></a>
|
||
trait.</p>
|
||
<p>Implementors of <code>CryptoRng</code> should only implement <a href="https://doc.rust-lang.org/1.93.1/core/default/trait.Default.html" title="trait core::default::Default"><code>Default</code></a> if the
|
||
<code>default()</code> instances are themselves secure generators: for example if the
|
||
implementing type is a stateless interface over a secure external generator
|
||
(like <a href="rngs/struct.OsRng.html" title="struct rand::rngs::OsRng"><code>OsRng</code></a>) or if the <code>default()</code> instance uses a strong, fresh seed.</p>
|
||
<p>Formally, a CSPRNG (Cryptographically Secure Pseudo-Random Number Generator)
|
||
should satisfy an additional property over other generators: assuming that
|
||
the generator has been appropriately seeded and has unknown state, then
|
||
given the first <em>k</em> bits of an algorithm’s output
|
||
sequence, it should not be possible using polynomial-time algorithms to
|
||
predict the next bit with probability significantly greater than 50%.</p>
|
||
<p>An optional property of CSPRNGs is backtracking resistance: if the CSPRNG’s
|
||
state is revealed, it will not be computationally-feasible to reconstruct
|
||
prior output values. This property is not required by <code>CryptoRng</code>.</p>
|
||
</div></details><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><section id="impl-CryptoRng-for-ChaCha8Rng" class="impl"><a class="src rightside" href="../src/rand_chacha/chacha.rs.html#346-352">Source</a><a href="#impl-CryptoRng-for-ChaCha8Rng" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="../rand_chacha/chacha/struct.ChaCha8Rng.html" title="struct rand_chacha::chacha::ChaCha8Rng">ChaCha8Rng</a></h3></section><section id="impl-CryptoRng-for-ChaCha12Rng" class="impl"><a class="src rightside" href="../src/rand_chacha/chacha.rs.html#339-345">Source</a><a href="#impl-CryptoRng-for-ChaCha12Rng" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="../rand_chacha/chacha/struct.ChaCha12Rng.html" title="struct rand_chacha::chacha::ChaCha12Rng">ChaCha12Rng</a></h3></section><section id="impl-CryptoRng-for-ChaCha20Rng" class="impl"><a class="src rightside" href="../src/rand_chacha/chacha.rs.html#332-338">Source</a><a href="#impl-CryptoRng-for-ChaCha20Rng" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="../rand_chacha/chacha/struct.ChaCha20Rng.html" title="struct rand_chacha::chacha::ChaCha20Rng">ChaCha20Rng</a></h3></section><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-CryptoRng-for-StdRng" class="impl"><a class="src rightside" href="../src/rand/rngs/std.rs.html#99">Source</a><a href="#impl-CryptoRng-for-StdRng" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="rngs/struct.StdRng.html" title="struct rand::rngs::StdRng">StdRng</a></h3></section><section id="impl-CryptoRng-for-ThreadRng" class="impl"><a class="src rightside" href="../src/rand/rngs/thread.rs.html#194">Source</a><a href="#impl-CryptoRng-for-ThreadRng" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="rngs/struct.ThreadRng.html" title="struct rand::rngs::ThreadRng">ThreadRng</a></h3></section><section id="impl-CryptoRng-for-BlockRng64%3CR%3E" class="impl"><a class="src rightside" href="../src/rand_core/block.rs.html#424">Source</a><a href="#impl-CryptoRng-for-BlockRng64%3CR%3E" class="anchor">§</a><h3 class="code-header">impl<R> <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="../rand_core/block/struct.BlockRng64.html" title="struct rand_core::block::BlockRng64">BlockRng64</a><R><div class="where">where
|
||
R: <a class="trait" href="../rand_core/block/trait.CryptoBlockRng.html" title="trait rand_core::block::CryptoBlockRng">CryptoBlockRng</a><Item = <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u64.html">u64</a>> + <a class="trait" href="../rand_core/block/trait.BlockRngCore.html" title="trait rand_core::block::BlockRngCore">BlockRngCore</a>,</div></h3></section><section id="impl-CryptoRng-for-BlockRng%3CR%3E" class="impl"><a class="src rightside" href="../src/rand_core/block.rs.html#261">Source</a><a href="#impl-CryptoRng-for-BlockRng%3CR%3E" class="anchor">§</a><h3 class="code-header">impl<R> <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="../rand_core/block/struct.BlockRng.html" title="struct rand_core::block::BlockRng">BlockRng</a><R><div class="where">where
|
||
R: <a class="trait" href="../rand_core/block/trait.CryptoBlockRng.html" title="trait rand_core::block::CryptoBlockRng">CryptoBlockRng</a><Item = <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>> + <a class="trait" href="../rand_core/block/trait.BlockRngCore.html" title="trait rand_core::block::BlockRngCore">BlockRngCore</a>,</div></h3></section><section id="impl-CryptoRng-for-UnwrapErr%3CR%3E" class="impl"><a class="src rightside" href="../src/rand_core/lib.rs.html#317">Source</a><a href="#impl-CryptoRng-for-UnwrapErr%3CR%3E" class="anchor">§</a><h3 class="code-header">impl<R> <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="../rand_core/struct.UnwrapErr.html" title="struct rand_core::UnwrapErr">UnwrapErr</a><R><div class="where">where
|
||
R: <a class="trait" href="trait.TryCryptoRng.html" title="trait rand::TryCryptoRng">TryCryptoRng</a>,</div></h3></section><section id="impl-CryptoRng-for-UnwrapMut%3C'_,+R%3E" class="impl"><a class="src rightside" href="../src/rand_core/lib.rs.html#356">Source</a><a href="#impl-CryptoRng-for-UnwrapMut%3C'_,+R%3E" class="anchor">§</a><h3 class="code-header">impl<R> <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="../rand_core/struct.UnwrapMut.html" title="struct rand_core::UnwrapMut">UnwrapMut</a><'_, R><div class="where">where
|
||
R: <a class="trait" href="trait.TryCryptoRng.html" title="trait rand::TryCryptoRng">TryCryptoRng</a> + ?<a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section><section id="impl-CryptoRng-for-ReseedingRng%3CR,+Rsdr%3E" class="impl"><a class="src rightside" href="../src/rand/rngs/reseeding.rs.html#139-144">Source</a><a href="#impl-CryptoRng-for-ReseedingRng%3CR,+Rsdr%3E" class="anchor">§</a><h3 class="code-header">impl<R, Rsdr> <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for <a class="struct" href="rngs/struct.ReseedingRng.html" title="struct rand::rngs::ReseedingRng">ReseedingRng</a><R, Rsdr><div class="where">where
|
||
R: <a class="trait" href="../rand_core/block/trait.BlockRngCore.html" title="trait rand_core::block::BlockRngCore">BlockRngCore</a><Item = <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>> + <a class="trait" href="trait.SeedableRng.html" title="trait rand::SeedableRng">SeedableRng</a> + <a class="trait" href="../rand_core/block/trait.CryptoBlockRng.html" title="trait rand_core::block::CryptoBlockRng">CryptoBlockRng</a>,
|
||
Rsdr: <a class="trait" href="trait.TryCryptoRng.html" title="trait rand::TryCryptoRng">TryCryptoRng</a>,</div></h3></section><section id="impl-CryptoRng-for-T" class="impl"><a class="src rightside" href="../src/rand_core/lib.rs.html#206">Source</a><a href="#impl-CryptoRng-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a> for T<div class="where">where
|
||
T: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/deref/trait.DerefMut.html" title="trait core::ops::deref::DerefMut">DerefMut</a>,
|
||
<T as <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/1.93.1/core/ops/deref/trait.Deref.html#associatedtype.Target" title="type core::ops::deref::Deref::Target">Target</a>: <a class="trait" href="trait.CryptoRng.html" title="trait rand::CryptoRng">CryptoRng</a>,</div></h3></section></div><script src="../trait.impl/rand_core/trait.CryptoRng.js" data-ignore-extern-crates="rand_core,rand_chacha" async></script></section></div></main></body></html> |