mpvrc/openssl/aes/index.html

41 lines
No EOL
8.5 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="Low level AES IGE and key wrapping functionality"><title>openssl::aes - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.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" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="openssl" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.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]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../openssl/index.html">openssl</a><span class="version">0.10.68</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module aes</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a><ul><li><a href="#aes-ige" title="AES IGE">AES IGE</a></li><li><a href="#key-wrapping" title="Key wrapping">Key wrapping</a></li></ul></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="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate openssl</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">openssl</a></span><h1>Module <span>aes</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/openssl/aes.rs.html#1-319">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Low level AES IGE and key wrapping functionality</p>
<p>AES ECB, CBC, XTS, CTR, CFB, GCM and other conventional symmetric encryption
modes are found in <a href="../symm/index.html"><code>symm</code></a>. This is the implementation of AES IGE and key wrapping</p>
<p>Advanced Encryption Standard (AES) provides symmetric key cipher that
the same key is used to encrypt and decrypt data. This implementation
uses 128, 192, or 256 bit keys. This module provides functions to
create a new key with <a href="struct.AesKey.html#method.new_encrypt"><code>new_encrypt</code></a> and perform an encryption/decryption
using that key with <a href="fn.aes_ige.html"><code>aes_ige</code></a>.</p>
<p>The <a href="../symm/index.html"><code>symm</code></a> module should be used in preference to this module in most cases.
The IGE block cipher is a non-traditional cipher mode. More traditional AES
encryption methods are found in the <a href="../symm/struct.Crypter.html"><code>Crypter</code></a> and <a href="../symm/struct.Cipher.html"><code>Cipher</code></a> structs.</p>
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
<p>\</p>
<h3 id="aes-ige"><a class="doc-anchor" href="#aes-ige">§</a>AES IGE</h3>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>openssl::aes::{AesKey, aes_ige};
<span class="kw">use </span>openssl::symm::Mode;
<span class="kw">let </span>key = <span class="string">b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"</span>;
<span class="kw">let </span>plaintext = <span class="string">b"\x12\x34\x56\x78\x90\x12\x34\x56\x12\x34\x56\x78\x90\x12\x34\x56"</span>;
<span class="kw">let </span><span class="kw-2">mut </span>iv = <span class="kw-2">*</span><span class="string">b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\
\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"</span>;
<span class="kw">let </span>key = AesKey::new_encrypt(key).unwrap();
<span class="kw">let </span><span class="kw-2">mut </span>output = [<span class="number">0u8</span>; <span class="number">16</span>];
aes_ige(plaintext, <span class="kw-2">&amp;mut </span>output, <span class="kw-2">&amp;</span>key, <span class="kw-2">&amp;mut </span>iv, Mode::Encrypt);
<span class="macro">assert_eq!</span>(output, <span class="kw-2">*</span><span class="string">b"\xa6\xad\x97\x4d\x5c\xea\x1d\x36\xd2\xf3\x67\x98\x09\x07\xed\x32"</span>);</code></pre></div>
<h3 id="key-wrapping"><a class="doc-anchor" href="#key-wrapping">§</a>Key wrapping</h3>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>openssl::aes::{AesKey, unwrap_key, wrap_key};
<span class="kw">let </span>kek = <span class="string">b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"</span>;
<span class="kw">let </span>key_to_wrap = <span class="string">b"\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF"</span>;
<span class="kw">let </span>enc_key = AesKey::new_encrypt(kek).unwrap();
<span class="kw">let </span><span class="kw-2">mut </span>ciphertext = [<span class="number">0u8</span>; <span class="number">24</span>];
wrap_key(<span class="kw-2">&amp;</span>enc_key, <span class="prelude-val">None</span>, <span class="kw-2">&amp;mut </span>ciphertext, <span class="kw-2">&amp;</span>key_to_wrap[..]).unwrap();
<span class="kw">let </span>dec_key = AesKey::new_decrypt(kek).unwrap();
<span class="kw">let </span><span class="kw-2">mut </span>orig_key = [<span class="number">0u8</span>; <span class="number">16</span>];
unwrap_key(<span class="kw-2">&amp;</span>dec_key, <span class="prelude-val">None</span>, <span class="kw-2">&amp;mut </span>orig_key, <span class="kw-2">&amp;</span>ciphertext[..]).unwrap();
<span class="macro">assert_eq!</span>(<span class="kw-2">&amp;</span>orig_key[..], <span class="kw-2">&amp;</span>key_to_wrap[..]);</code></pre></div>
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.AesKey.html" title="struct openssl::aes::AesKey">AesKey</a></div><div class="desc docblock-short">The key used to encrypt or decrypt cipher blocks.</div></li><li><div class="item-name"><a class="struct" href="struct.KeyError.html" title="struct openssl::aes::KeyError">KeyError</a></div><div class="desc docblock-short">Provides Error handling for parsing keys.</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.aes_ige.html" title="fn openssl::aes::aes_ige">aes_ige</a></div><div class="desc docblock-short">Performs AES IGE encryption or decryption</div></li><li><div class="item-name"><a class="fn" href="fn.unwrap_key.html" title="fn openssl::aes::unwrap_key">unwrap_<wbr>key</a></div><div class="desc docblock-short">Unwrap a key, according to <a href="https://tools.ietf.org/html/rfc3394">RFC 3394</a></div></li><li><div class="item-name"><a class="fn" href="fn.wrap_key.html" title="fn openssl::aes::wrap_key">wrap_<wbr>key</a></div><div class="desc docblock-short">Wrap a key, according to <a href="https://tools.ietf.org/html/rfc3394">RFC 3394</a></div></li></ul></section></div></main></body></html>