mirror of
https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git
synced 2025-12-28 18:42:18 +01:00
160 lines
No EOL
8.4 KiB
HTML
160 lines
No EOL
8.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 `open_in_place` fn in crate `ring`.">
|
||
<meta name="keywords" content="rust, rustlang, rust-lang, open_in_place">
|
||
|
||
<title>ring::aead::open_in_place - 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 fn">
|
||
<!--[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'><a href='../index.html'>ring</a>::<wbr><a href='index.html'>aead</a></p><script>window.sidebarCurrent = {name: 'open_in_place', ty: 'fn', 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'>Function <a href='../index.html'>ring</a>::<wbr><a href='index.html'>aead</a>::<wbr><a class="fn" href=''>open_in_place</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/aead/aead.rs.html#126-156' title='goto source code'>[src]</a></span></h1>
|
||
<pre class='rust fn'>pub fn open_in_place<'a>(<br> key: &<a class="struct" href="../../ring/aead/struct.OpeningKey.html" title="struct ring::aead::OpeningKey">OpeningKey</a>, <br> nonce: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>, <br> ad: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&[</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>, <br> in_prefix_len: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <br> ciphertext_and_tag_modified_in_place: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'a mut [</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a><br>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&'a mut [</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">]</a>, <a class="struct" href="../../ring/error/struct.Unspecified.html" title="struct ring::error::Unspecified">Unspecified</a>></pre><div class='docblock'><p>Authenticates and decrypts (“opens”) data in place. When</p>
|
||
|
||
<p>The input may have a prefix that is <code>in_prefix_len</code> bytes long; any such
|
||
prefix is ignored on input and overwritten on output. The last
|
||
<code>key.algorithm().tag_len()</code> bytes of <code>ciphertext_and_tag_modified_in_place</code>
|
||
must be the tag. The part of <code>ciphertext_and_tag_modified_in_place</code> between
|
||
the prefix and the tag is the input ciphertext.</p>
|
||
|
||
<p>When <code>open_in_place()</code> returns <code>Ok(plaintext)</code>, the decrypted output is
|
||
<code>plaintext</code>, which is
|
||
<code>&mut ciphertext_and_tag_modified_in_place[..plaintext.len()]</code>. That is,
|
||
the output plaintext overwrites some or all of the prefix and ciphertext.
|
||
To put it another way, the ciphertext is shifted forward <code>in_prefix_len</code>
|
||
bytes and then decrypted in place. To have the output overwrite the input
|
||
without shifting, pass 0 as <code>in_prefix_len</code>.</p>
|
||
|
||
<p>When <code>open_in_place()</code> returns <code>Err(..)</code>,
|
||
<code>ciphertext_and_tag_modified_in_place</code> may have been overwritten in an
|
||
unspecified way.</p>
|
||
|
||
<p>The shifting feature is useful in the case where multiple packets are
|
||
being reassembled in place. Consider this example where the peer has sent
|
||
the message “Split stream reassembled in place” split into three sealed
|
||
packets:</p>
|
||
|
||
<pre><code class="language-ascii-art"> Packet 1 Packet 2 Packet 3
|
||
Input: [Header][Ciphertext][Tag][Header][Ciphertext][Tag][Header][Ciphertext][Tag]
|
||
| +--------------+ |
|
||
+------+ +-----+ +----------------------------------+
|
||
v v v
|
||
Output: [Plaintext][Plaintext][Plaintext]
|
||
“Split stream reassembled in place”
|
||
</code></pre>
|
||
|
||
<p>Let's say the header is always 5 bytes (like TLS 1.2) and the tag is always
|
||
16 bytes (as for AES-GCM and ChaCha20-Poly1305). Then for this example,
|
||
<code>in_prefix_len</code> would be <code>5</code> for the first packet, <code>(5 + 16) + 5</code> for the
|
||
second packet, and <code>(2 * (5 + 16)) + 5</code> for the third packet.</p>
|
||
|
||
<p>(The input/output buffer is expressed as combination of <code>in_prefix_len</code>
|
||
and <code>ciphertext_and_tag_modified_in_place</code> because Rust's type system
|
||
does not allow us to have two slices, one mutable and one immutable, that
|
||
reference overlapping memory.)</p>
|
||
|
||
<p>C analog: <code>EVP_AEAD_CTX_open</code></p>
|
||
|
||
<p>Go analog: <a href="https://golang.org/pkg/crypto/cipher/#AEAD"><code>AEAD.Open</code></a></p>
|
||
</div></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>⇤</dt>
|
||
<dd>Move up in search results</dd>
|
||
<dt>⇥</dt>
|
||
<dd>Move down in search results</dd>
|
||
<dt>⏎</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> |