mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-02-23 15:49:49 +01:00
65 lines
9.4 KiB
HTML
65 lines
9.4 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="API documentation for the Rust `agreement` mod in crate `ring`."><meta name="keywords" content="rust, rustlang, rust-lang, agreement"><title>ring::agreement - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg">
|
||
<link rel="alternate icon" type="image/png" href="../../favicon-16x16.png">
|
||
<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../../ring/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Module agreement</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#statics">Statics</a></li><li><a href="#functions">Functions</a></li></ul></div><p class="location"><a href="../index.html">ring</a></p><div id="sidebar-vars" data-name="agreement" data-ty="mod" data-relpath="../"></div><script defer src="../sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button>
|
||
<a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Module <a href="../index.html">ring</a>::<wbr><a class="mod" href="">agreement</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">−</span>]</a></span><a class="srclink" href="../../src/ring/agreement.rs.html#15-320" title="goto source code">[src]</a></span></h1><div class="docblock"><p>Key Agreement: ECDH, including X25519.</p>
|
||
<h1 id="example" class="section-header"><a href="#example">Example</a></h1>
|
||
<p>Note that this example uses X25519, but ECDH using NIST P-256/P-384 is done
|
||
exactly the same way, just substituting
|
||
<code>agreement::ECDH_P256</code>/<code>agreement::ECDH_P384</code> for <code>agreement::X25519</code>.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">ring</span>::{<span class="ident">agreement</span>, <span class="ident">rand</span>};
|
||
|
||
<span class="kw">let</span> <span class="ident">rng</span> <span class="op">=</span> <span class="ident">rand</span>::<span class="ident">SystemRandom</span>::<span class="ident">new</span>();
|
||
|
||
<span class="kw">let</span> <span class="ident">my_private_key</span> <span class="op">=</span> <span class="ident">agreement</span>::<span class="ident">EphemeralPrivateKey</span>::<span class="ident">generate</span>(<span class="kw-2">&</span><span class="ident">agreement</span>::<span class="ident">X25519</span>, <span class="kw-2">&</span><span class="ident">rng</span>)<span class="question-mark">?</span>;
|
||
|
||
<span class="comment">// Make `my_public_key` a byte slice containing my public key. In a real</span>
|
||
<span class="comment">// application, this would be sent to the peer in an encoded protocol</span>
|
||
<span class="comment">// message.</span>
|
||
<span class="kw">let</span> <span class="ident">my_public_key</span> <span class="op">=</span> <span class="ident">my_private_key</span>.<span class="ident">compute_public_key</span>()<span class="question-mark">?</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">peer_public_key</span> <span class="op">=</span> {
|
||
<span class="comment">// In a real application, the peer public key would be parsed out of a</span>
|
||
<span class="comment">// protocol message. Here we just generate one.</span>
|
||
<span class="kw">let</span> <span class="ident">peer_public_key</span> <span class="op">=</span> {
|
||
<span class="kw">let</span> <span class="ident">peer_private_key</span> <span class="op">=</span>
|
||
<span class="ident">agreement</span>::<span class="ident">EphemeralPrivateKey</span>::<span class="ident">generate</span>(<span class="kw-2">&</span><span class="ident">agreement</span>::<span class="ident">X25519</span>, <span class="kw-2">&</span><span class="ident">rng</span>)<span class="question-mark">?</span>;
|
||
<span class="ident">peer_private_key</span>.<span class="ident">compute_public_key</span>()<span class="question-mark">?</span>
|
||
};
|
||
|
||
<span class="ident">agreement</span>::<span class="ident">UnparsedPublicKey</span>::<span class="ident">new</span>(<span class="kw-2">&</span><span class="ident">agreement</span>::<span class="ident">X25519</span>, <span class="ident">peer_public_key</span>)
|
||
};
|
||
|
||
<span class="ident">agreement</span>::<span class="ident">agree_ephemeral</span>(
|
||
<span class="ident">my_private_key</span>,
|
||
<span class="kw-2">&</span><span class="ident">peer_public_key</span>,
|
||
<span class="ident">ring</span>::<span class="ident">error</span>::<span class="ident">Unspecified</span>,
|
||
<span class="op">|</span><span class="ident">_key_material</span><span class="op">|</span> {
|
||
<span class="comment">// In a real application, we'd apply a KDF to the key material and the</span>
|
||
<span class="comment">// public keys (as recommended in RFC 7748) and then derive session</span>
|
||
<span class="comment">// keys from the result. We omit all that here.</span>
|
||
<span class="prelude-val">Ok</span>(())
|
||
},
|
||
)<span class="question-mark">?</span>;
|
||
</pre></div>
|
||
</div><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2>
|
||
<table><tr class="module-item"><td><a class="struct" href="struct.Algorithm.html" title="ring::agreement::Algorithm struct">Algorithm</a></td><td class="docblock-short"><p>A key agreement algorithm.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.EphemeralPrivateKey.html" title="ring::agreement::EphemeralPrivateKey struct">EphemeralPrivateKey</a></td><td class="docblock-short"><p>An ephemeral private key for use (only) with <code>agree_ephemeral</code>. The
|
||
signature of <code>agree_ephemeral</code> ensures that an <code>EphemeralPrivateKey</code> can be
|
||
used for at most one key agreement.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.PublicKey.html" title="ring::agreement::PublicKey struct">PublicKey</a></td><td class="docblock-short"><p>A public key for key agreement.</p>
|
||
</td></tr><tr class="module-item"><td><a class="struct" href="struct.UnparsedPublicKey.html" title="ring::agreement::UnparsedPublicKey struct">UnparsedPublicKey</a></td><td class="docblock-short"><p>An unparsed, possibly malformed, public key for key agreement.</p>
|
||
</td></tr></table><h2 id="statics" class="section-header"><a href="#statics">Statics</a></h2>
|
||
<table><tr class="module-item"><td><a class="static" href="static.ECDH_P256.html" title="ring::agreement::ECDH_P256 static">ECDH_P256</a></td><td class="docblock-short"><p>ECDH using the NSA Suite B
|
||
P-256 (secp256r1)
|
||
curve.</p>
|
||
</td></tr><tr class="module-item"><td><a class="static" href="static.ECDH_P384.html" title="ring::agreement::ECDH_P384 static">ECDH_P384</a></td><td class="docblock-short"><p>ECDH using the NSA Suite B
|
||
P-384 (secp384r1)
|
||
curve.</p>
|
||
</td></tr><tr class="module-item"><td><a class="static" href="static.X25519.html" title="ring::agreement::X25519 static">X25519</a></td><td class="docblock-short"><p>X25519 (ECDH using Curve25519) as described in <a href="https://tools.ietf.org/html/rfc7748">RFC 7748</a>.</p>
|
||
</td></tr></table><h2 id="functions" class="section-header"><a href="#functions">Functions</a></h2>
|
||
<table><tr class="module-item"><td><a class="fn" href="fn.agree_ephemeral.html" title="ring::agreement::agree_ephemeral fn">agree_ephemeral</a></td><td class="docblock-short"><p>Performs a key agreement with an ephemeral private key and the given public
|
||
key.</p>
|
||
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="ring"></div>
|
||
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html> |