39 lines
8.3 KiB
HTML
39 lines
8.3 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-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="openssl" 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 aes</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../openssl/index.html">openssl</a><span class="version">0.10.75</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" 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">openssl</a></div><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-323">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">&mut </span>output, <span class="kw-2">&</span>key, <span class="kw-2">&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">&</span>enc_key, <span class="prelude-val">None</span>, <span class="kw-2">&mut </span>ciphertext, <span class="kw-2">&</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">&</span>dec_key, <span class="prelude-val">None</span>, <span class="kw-2">&mut </span>orig_key, <span class="kw-2">&</span>ciphertext[..]).unwrap();
|
|
|
|
<span class="macro">assert_eq!</span>(<span class="kw-2">&</span>orig_key[..], <span class="kw-2">&</span>key_to_wrap[..]);</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.AesKey.html" title="struct openssl::aes::AesKey">AesKey</a></dt><dd>The key used to encrypt or decrypt cipher blocks.</dd><dt><a class="struct" href="struct.KeyError.html" title="struct openssl::aes::KeyError">KeyError</a></dt><dd>Provides Error handling for parsing keys.</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.aes_ige.html" title="fn openssl::aes::aes_ige">aes_ige</a></dt><dd>Performs AES IGE encryption or decryption</dd><dt><a class="fn" href="fn.unwrap_key.html" title="fn openssl::aes::unwrap_key">unwrap_<wbr>key</a></dt><dd>Unwrap a key, according to <a href="https://tools.ietf.org/html/rfc3394">RFC 3394</a></dd><dt><a class="fn" href="fn.wrap_key.html" title="fn openssl::aes::wrap_key">wrap_<wbr>key</a></dt><dd>Wrap a key, according to <a href="https://tools.ietf.org/html/rfc3394">RFC 3394</a></dd></dl></section></div></main></body></html> |