46 lines
7.4 KiB
HTML
46 lines
7.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="Key Agreement: ECDH, including X25519."><title>ring::agreement - 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="ring" 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="alternate icon" type="image/png" href="../../static.files/favicon-32x32-eab170b8.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]--><rustdoc-topbar><h2><a href="#">Module agreement</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../ring/index.html">ring</a><span class="version">0.17.14</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module agreement</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example" title="Example">Example</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="#statics" title="Statics">Statics</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 ring</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">ring</a></div><h1>Module <span>agreement</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/ring/agreement.rs.html#15-311">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Key Agreement: ECDH, including X25519.</p>
|
|
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
|
|
<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"><code><span class="kw">use </span>ring::{agreement, rand};
|
|
|
|
<span class="kw">let </span>rng = rand::SystemRandom::new();
|
|
|
|
<span class="kw">let </span>my_private_key = agreement::EphemeralPrivateKey::generate(<span class="kw-2">&</span>agreement::X25519, <span class="kw-2">&</span>rng)<span class="question-mark">?</span>;
|
|
|
|
<span class="comment">// Make `my_public_key` a byte slice containing my public key. In a real
|
|
// application, this would be sent to the peer in an encoded protocol
|
|
// message.
|
|
</span><span class="kw">let </span>my_public_key = my_private_key.compute_public_key()<span class="question-mark">?</span>;
|
|
|
|
<span class="kw">let </span>peer_public_key_bytes = {
|
|
<span class="comment">// In a real application, the peer public key would be parsed out of a
|
|
// protocol message. Here we just generate one.
|
|
</span><span class="kw">let </span>peer_private_key =
|
|
agreement::EphemeralPrivateKey::generate(<span class="kw-2">&</span>agreement::X25519, <span class="kw-2">&</span>rng)<span class="question-mark">?</span>;
|
|
peer_private_key.compute_public_key()<span class="question-mark">?
|
|
</span>};
|
|
|
|
<span class="kw">let </span>peer_public_key = agreement::UnparsedPublicKey::new(
|
|
<span class="kw-2">&</span>agreement::X25519,
|
|
peer_public_key_bytes);
|
|
|
|
agreement::agree_ephemeral(
|
|
my_private_key,
|
|
<span class="kw-2">&</span>peer_public_key,
|
|
|_key_material| {
|
|
<span class="comment">// In a real application, we'd apply a KDF to the key material and the
|
|
// public keys (as recommended in RFC 7748) and then derive session
|
|
// keys from the result. We omit all that here.
|
|
</span>},
|
|
)<span class="question-mark">?</span>;
|
|
</code></pre></div></div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.Algorithm.html" title="struct ring::agreement::Algorithm">Algorithm</a></dt><dd>A key agreement algorithm.</dd><dt><a class="struct" href="struct.EphemeralPrivateKey.html" title="struct ring::agreement::EphemeralPrivateKey">Ephemeral<wbr>Private<wbr>Key</a></dt><dd>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.</dd><dt><a class="struct" href="struct.PublicKey.html" title="struct ring::agreement::PublicKey">Public<wbr>Key</a></dt><dd>A public key for key agreement.</dd><dt><a class="struct" href="struct.UnparsedPublicKey.html" title="struct ring::agreement::UnparsedPublicKey">Unparsed<wbr>Public<wbr>Key</a></dt><dd>An unparsed, possibly malformed, public key for key agreement.</dd></dl><h2 id="statics" class="section-header">Statics<a href="#statics" class="anchor">§</a></h2><dl class="item-table"><dt><a class="static" href="static.ECDH_P256.html" title="static ring::agreement::ECDH_P256">ECDH_<wbr>P256</a></dt><dd>ECDH using the NSA Suite B
|
|
P-256 (secp256r1)
|
|
curve.</dd><dt><a class="static" href="static.ECDH_P384.html" title="static ring::agreement::ECDH_P384">ECDH_<wbr>P384</a></dt><dd>ECDH using the NSA Suite B
|
|
P-384 (secp384r1)
|
|
curve.</dd><dt><a class="static" href="static.X25519.html" title="static ring::agreement::X25519">X25519</a></dt><dd>X25519 (ECDH using Curve25519) as described in <a href="https://tools.ietf.org/html/rfc7748">RFC 7748</a>.</dd></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.agree_ephemeral.html" title="fn ring::agreement::agree_ephemeral">agree_<wbr>ephemeral</a></dt><dd>Performs a key agreement with an ephemeral private key and the given public
|
|
key.</dd></dl></section></div></main></body></html> |