1
0
Fork 0
mirror of https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git synced 2025-12-28 20:42:18 +01:00
redox-ssh/ring/agreement/index.html

223 lines
No EOL
13 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 `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">
<link rel="stylesheet" type="text/css" href="../../main.css">
</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">
<p class='location'>Module agreement</p><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#constants">Constants</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><script>window.sidebarCurrent = {name: 'agreement', ty: 'mod', 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'>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'>&#x2212;</span>]
</a>
</span><a class='srclink' href='../../src/ring/agreement.rs.html#15-217' 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>
<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">use</span> <span class="ident">untrusted</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">&amp;</span><span class="ident">agreement</span>::<span class="ident">X25519</span>, <span class="kw-2">&amp;</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="kw-2">mut</span> <span class="ident">my_public_key</span> <span class="op">=</span> [<span class="number">0u8</span>; <span class="ident">agreement</span>::<span class="ident">PUBLIC_KEY_MAX_LEN</span>];
<span class="kw">let</span> <span class="ident">my_public_key</span> <span class="op">=</span>
<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">my_public_key</span>[..<span class="ident">my_private_key</span>.<span class="ident">public_key_len</span>()];
<span class="ident">my_private_key</span>.<span class="ident">compute_public_key</span>(<span class="ident">my_public_key</span>)<span class="question-mark">?</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="kw-2">mut</span> <span class="ident">peer_public_key_buf</span> <span class="op">=</span> [<span class="number">0u8</span>; <span class="ident">agreement</span>::<span class="ident">PUBLIC_KEY_MAX_LEN</span>];
<span class="kw">let</span> <span class="ident">peer_public_key</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">&amp;</span><span class="ident">agreement</span>::<span class="ident">X25519</span>, <span class="kw-2">&amp;</span><span class="ident">rng</span>)<span class="question-mark">?</span>;
<span class="ident">peer_public_key</span> <span class="op">=</span>
<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">peer_public_key_buf</span>[..<span class="ident">peer_private_key</span>.<span class="ident">public_key_len</span>()];
<span class="ident">peer_private_key</span>.<span class="ident">compute_public_key</span>(<span class="ident">peer_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="ident">untrusted</span>::<span class="ident">Input</span>::<span class="ident">from</span>(<span class="ident">peer_public_key</span>);
<span class="comment">// In a real application, the protocol specifies how to determine what</span>
<span class="comment">// algorithm was used to generate the peer&#39;s private key. Here, we know it</span>
<span class="comment">// is X25519 since we just generated it.</span>
<span class="kw">let</span> <span class="ident">peer_public_key_alg</span> <span class="op">=</span> <span class="kw-2">&amp;</span><span class="ident">agreement</span>::<span class="ident">X25519</span>;
<span class="ident">agreement</span>::<span class="ident">agree_ephemeral</span>(<span class="ident">my_private_key</span>, <span class="ident">peer_public_key_alg</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&#39;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>(())
})</pre>
</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='struct ring::agreement::Algorithm'>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='struct ring::agreement::EphemeralPrivateKey'>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></table><h2 id='constants' class='section-header'><a href="#constants">Constants</a></h2>
<table>
<tr class=' module-item'>
<td><a class="constant" href="constant.PUBLIC_KEY_MAX_LEN.html"
title='constant ring::agreement::PUBLIC_KEY_MAX_LEN'>PUBLIC_KEY_MAX_LEN</a></td>
<td class='docblock-short'>
<p>The maximum length, in bytes, of an encoded public key.</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='static ring::agreement::ECDH_P256'>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='static ring::agreement::ECDH_P384'>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='static ring::agreement::X25519'>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='fn ring::agreement::agree_ephemeral'>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>
<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 = "ring";
</script>
<script src="../../jquery.js"></script>
<script src="../../main.js"></script>
<script defer src="../../search-index.js"></script>
</body>
</html>