use aes::cipher::{BlockDecrypt, BlockEncrypt, KeyInit};
use hmac::{Hmac, Mac};
use sha1::Sha1;
pub const AES256_KEY_LEN: usize = 32;
pub const AES_BLOCK_LEN: usize = 16;
pub const AES128_KEY_LEN: usize = 16;
#[allow(clippy::large_enum_variant)]
enum AesKey {
K128(aes::Aes128),
K256(aes::Aes256),
}
impl AesKey {
fn new(key: &[u8]) -> Self {
match key.len() {
AES128_KEY_LEN => {
AesKey::K128(aes::Aes128::new_from_slice(key).expect("AES-128 key is 16 bytes"))
}
AES256_KEY_LEN => {
AesKey::K256(aes::Aes256::new_from_slice(key).expect("AES-256 key is 32 bytes"))
}
n => panic!("unsupported AES key length {n} (want 16 or 32)"),
}
}
#[inline]
fn encrypt_block(&self, b: &mut aes::Block) {
match self {
AesKey::K128(c) => c.encrypt_block(b),
AesKey::K256(c) => c.encrypt_block(b),
}
}
#[inline]
fn decrypt_block(&self, b: &mut aes::Block) {
match self {
AesKey::K128(c) => c.decrypt_block(b),
AesKey::K256(c) => c.decrypt_block(b),
}
}
}
fn lcm(a: usize, b: usize) -> usize {
fn gcd(mut x: usize, mut y: usize) -> usize {
while y != 0 {
let t = y;
y = x % y;
x = t;
}
x
}
a / gcd(a, b) * b
}
pub fn nfold(input: &[u8], n_bits: usize) -> Vec<u8> {
assert!(!input.is_empty(), "n-fold input must be non-empty");
assert!(
n_bits.is_multiple_of(8),
"n-fold output size must be a multiple of 8 bits"
);
let in_bits = input.len() * 8;
let copies = lcm(n_bits, in_bits) / in_bits;
let read_bit = |bit_idx: usize| -> u8 {
let byte_idx = bit_idx / 8;
let bit_off = 7 - (bit_idx % 8); (input[byte_idx] >> bit_off) & 1
};
let mut stream: Vec<u8> = Vec::with_capacity(copies * in_bits);
for i in 0..copies {
let shift = (13 * i) % in_bits;
for pos in 0..in_bits {
let src = (pos + in_bits - shift) % in_bits;
stream.push(read_bit(src));
}
}
let mut sum = vec![0u8; n_bits / 8];
let num_chunks = stream.len() / n_bits;
for chunk in 0..num_chunks {
let mut chunk_bytes = vec![0u8; n_bits / 8];
for bit in 0..n_bits {
let v = stream[chunk * n_bits + bit];
let byte_idx = bit / 8;
let bit_off = 7 - (bit % 8); chunk_bytes[byte_idx] |= v << bit_off;
}
let mut carry: u32 = 0;
for j in (0..sum.len()).rev() {
let s = sum[j] as u32 + chunk_bytes[j] as u32 + carry;
sum[j] = (s & 0xff) as u8;
carry = s >> 8;
}
while carry > 0 {
for j in (0..sum.len()).rev() {
let s = sum[j] as u32 + carry;
sum[j] = (s & 0xff) as u8;
carry = s >> 8;
if carry == 0 {
break;
}
}
}
}
sum
}
pub fn aes_cts_encrypt(key: &[u8], iv: &[u8; AES_BLOCK_LEN], plaintext: &[u8]) -> Vec<u8> {
assert!(
plaintext.len() >= AES_BLOCK_LEN,
"AES-CTS requires at least one full block; got {} bytes",
plaintext.len()
);
let cipher = AesKey::new(key);
let n = plaintext.len();
let full_blocks = n / AES_BLOCK_LEN;
let remainder = n % AES_BLOCK_LEN;
let mut cbc_out = Vec::with_capacity(n);
let mut prev = *iv;
for i in 0..full_blocks {
let mut block = [0u8; AES_BLOCK_LEN];
block.copy_from_slice(&plaintext[i * AES_BLOCK_LEN..(i + 1) * AES_BLOCK_LEN]);
for j in 0..AES_BLOCK_LEN {
block[j] ^= prev[j];
}
let mut b = aes::cipher::generic_array::GenericArray::clone_from_slice(&block);
cipher.encrypt_block(&mut b);
prev.copy_from_slice(&b);
cbc_out.extend_from_slice(&b);
}
if remainder == 0 {
if full_blocks >= 2 {
let m = cbc_out.len();
for k in 0..AES_BLOCK_LEN {
cbc_out.swap(m - 2 * AES_BLOCK_LEN + k, m - AES_BLOCK_LEN + k);
}
}
return cbc_out;
}
let mut final_block = [0u8; AES_BLOCK_LEN];
final_block[..remainder].copy_from_slice(&plaintext[full_blocks * AES_BLOCK_LEN..]);
for j in 0..AES_BLOCK_LEN {
final_block[j] ^= prev[j];
}
let mut b = aes::cipher::generic_array::GenericArray::clone_from_slice(&final_block);
cipher.encrypt_block(&mut b);
let last_full_start = (full_blocks - 1) * AES_BLOCK_LEN;
let saved_last_full: [u8; AES_BLOCK_LEN] = cbc_out
[last_full_start..last_full_start + AES_BLOCK_LEN]
.try_into()
.expect("copied a full block");
cbc_out.truncate(last_full_start);
cbc_out.extend_from_slice(&b);
cbc_out.extend_from_slice(&saved_last_full[..remainder]);
cbc_out
}
pub fn aes_cts_decrypt(key: &[u8], iv: &[u8; AES_BLOCK_LEN], ciphertext: &[u8]) -> Vec<u8> {
assert!(
ciphertext.len() >= AES_BLOCK_LEN,
"AES-CTS ciphertext requires at least one full block; got {} bytes",
ciphertext.len()
);
let cipher = AesKey::new(key);
let n = ciphertext.len();
let full_blocks = n / AES_BLOCK_LEN;
let remainder = n % AES_BLOCK_LEN;
if remainder == 0 {
let mut ct = ciphertext.to_vec();
if full_blocks >= 2 {
let m = ct.len();
for k in 0..AES_BLOCK_LEN {
ct.swap(m - 2 * AES_BLOCK_LEN + k, m - AES_BLOCK_LEN + k);
}
}
let mut out = Vec::with_capacity(n);
let mut prev = *iv;
for i in 0..full_blocks {
let mut b = aes::cipher::generic_array::GenericArray::clone_from_slice(
&ct[i * AES_BLOCK_LEN..(i + 1) * AES_BLOCK_LEN],
);
let saved: [u8; AES_BLOCK_LEN] = b.as_slice().try_into().expect("block-sized");
cipher.decrypt_block(&mut b);
for j in 0..AES_BLOCK_LEN {
out.push(b[j] ^ prev[j]);
}
prev = saved;
}
return out;
}
let mut out = Vec::with_capacity(n);
let mut prev = *iv;
for i in 0..(full_blocks - 1) {
let mut b = aes::cipher::generic_array::GenericArray::clone_from_slice(
&ciphertext[i * AES_BLOCK_LEN..(i + 1) * AES_BLOCK_LEN],
);
let saved: [u8; AES_BLOCK_LEN] = b.as_slice().try_into().expect("block-sized");
cipher.decrypt_block(&mut b);
for j in 0..AES_BLOCK_LEN {
out.push(b[j] ^ prev[j]);
}
prev = saved;
}
let c_prime_off = (full_blocks - 1) * AES_BLOCK_LEN;
let mut c_prime = aes::cipher::generic_array::GenericArray::clone_from_slice(
&ciphertext[c_prime_off..c_prime_off + AES_BLOCK_LEN],
);
cipher.decrypt_block(&mut c_prime);
let x: [u8; AES_BLOCK_LEN] = c_prime.as_slice().try_into().expect("block-sized");
let mut c_last_full = [0u8; AES_BLOCK_LEN];
c_last_full[..remainder].copy_from_slice(&ciphertext[full_blocks * AES_BLOCK_LEN..n]);
c_last_full[remainder..].copy_from_slice(&x[remainder..]);
let p_last_padded: [u8; AES_BLOCK_LEN] = std::array::from_fn(|i| x[i] ^ c_last_full[i]);
let mut b = aes::cipher::generic_array::GenericArray::clone_from_slice(&c_last_full);
cipher.decrypt_block(&mut b);
for j in 0..AES_BLOCK_LEN {
out.push(b[j] ^ prev[j]);
}
out.extend_from_slice(&p_last_padded[..remainder]);
out
}
pub fn dr(key: &[u8], constant: &[u8]) -> Vec<u8> {
let zero_iv = [0u8; AES_BLOCK_LEN];
let n1 = nfold(constant, AES_BLOCK_LEN * 8);
let klen = key.len();
let mut out = Vec::with_capacity(klen);
let mut r = n1;
while out.len() < klen {
let encrypted = aes_cts_encrypt(key, &zero_iv, &r);
out.extend_from_slice(&encrypted);
r = encrypted;
}
out.truncate(klen);
out
}
pub fn dk(key: &[u8], constant: &[u8]) -> Vec<u8> {
dr(key, constant)
}
pub fn hmac_sha1_96(key: &[u8], data: &[u8]) -> [u8; 12] {
let mut mac = <Hmac<Sha1> as Mac>::new_from_slice(key).expect("Hmac accepts any key length");
mac.update(data);
let full = mac.finalize().into_bytes();
let mut out = [0u8; 12];
out.copy_from_slice(&full[..12]);
out
}
pub const KG_USAGE_ACCEPTOR_SEAL: u32 = 22;
pub const KG_USAGE_ACCEPTOR_SIGN: u32 = 23;
pub const KG_USAGE_INITIATOR_SEAL: u32 = 24;
pub const KG_USAGE_INITIATOR_SIGN: u32 = 25;
fn subkey_constant(usage: u32, tag: u8) -> [u8; 5] {
let u = usage.to_be_bytes();
[u[0], u[1], u[2], u[3], tag]
}
pub fn derive_kc(session_key: &[u8], usage: u32) -> Vec<u8> {
dk(session_key, &subkey_constant(usage, 0x99))
}
pub fn derive_ke(session_key: &[u8], usage: u32) -> Vec<u8> {
dk(session_key, &subkey_constant(usage, 0xAA))
}
pub fn derive_ki(session_key: &[u8], usage: u32) -> Vec<u8> {
dk(session_key, &subkey_constant(usage, 0x55))
}
pub const CONFOUNDER_LEN: usize = AES_BLOCK_LEN;
pub const HMAC_TRUNC_LEN: usize = 12;
#[derive(Debug)]
#[non_exhaustive]
pub enum DecryptError {
TooShort { got: usize, need_at_least: usize },
HmacMismatch,
}
impl core::fmt::Display for DecryptError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::TooShort { got, need_at_least } => {
write!(
f,
"sealed message too short: got {got} bytes, need at least {need_at_least}"
)
}
Self::HmacMismatch => write!(f, "HMAC-SHA1-96 tag verification failed"),
}
}
}
impl std::error::Error for DecryptError {}
pub fn encrypt_message(
session_key: &[u8],
usage: u32,
confounder: &[u8; CONFOUNDER_LEN],
payload: &[u8],
) -> Vec<u8> {
let ke = derive_ke(session_key, usage);
let ki = derive_ki(session_key, usage);
let mut e1 = Vec::with_capacity(CONFOUNDER_LEN + payload.len());
e1.extend_from_slice(confounder);
e1.extend_from_slice(payload);
let ct = aes_cts_encrypt(&ke, &[0u8; AES_BLOCK_LEN], &e1);
let mac = hmac_sha1_96(&ki, &e1);
let mut out = Vec::with_capacity(ct.len() + HMAC_TRUNC_LEN);
out.extend_from_slice(&ct);
out.extend_from_slice(&mac);
out
}
pub fn decrypt_message(
session_key: &[u8],
usage: u32,
sealed: &[u8],
) -> Result<Vec<u8>, DecryptError> {
let need = CONFOUNDER_LEN + HMAC_TRUNC_LEN;
if sealed.len() < need {
return Err(DecryptError::TooShort {
got: sealed.len(),
need_at_least: need,
});
}
let ke = derive_ke(session_key, usage);
let ki = derive_ki(session_key, usage);
let (ct, tag) = sealed.split_at(sealed.len() - HMAC_TRUNC_LEN);
let e1 = aes_cts_decrypt(&ke, &[0u8; AES_BLOCK_LEN], ct);
let expect = hmac_sha1_96(&ki, &e1);
let mut diff: u8 = 0;
for i in 0..HMAC_TRUNC_LEN {
diff |= expect[i] ^ tag[i];
}
if diff != 0 {
return Err(DecryptError::HmacMismatch);
}
Ok(e1[CONFOUNDER_LEN..].to_vec())
}
fn hmac_sha1_full(key: &[u8], data: &[u8]) -> Vec<u8> {
let mut mac = <Hmac<Sha1> as Mac>::new_from_slice(key).expect("Hmac accepts any key length");
mac.update(data);
mac.finalize().into_bytes().to_vec()
}
pub(crate) fn pbkdf2<F: Fn(&[u8], &[u8]) -> Vec<u8>>(
prf: F,
hlen: usize,
password: &[u8],
salt: &[u8],
iterations: u32,
dk_len: usize,
) -> Vec<u8> {
let n_blocks = dk_len.div_ceil(hlen);
let mut out = Vec::with_capacity(n_blocks * hlen);
for block in 1..=n_blocks as u32 {
let mut salt_i = salt.to_vec();
salt_i.extend_from_slice(&block.to_be_bytes());
let mut u = prf(password, &salt_i);
let mut t = u.clone();
for _ in 1..iterations {
u = prf(password, &u);
for (ti, ui) in t.iter_mut().zip(u.iter()) {
*ti ^= ui;
}
}
out.extend_from_slice(&t);
}
out.truncate(dk_len);
out
}
pub fn string_to_key(key_len: usize, passphrase: &[u8], salt: &[u8], iterations: u32) -> Vec<u8> {
let tkey = pbkdf2(hmac_sha1_full, 20, passphrase, salt, iterations, key_len);
dk(&tkey, b"kerberos")
}
#[cfg(test)]
mod tests {
use super::*;
fn hexs(b: &[u8]) -> String {
b.iter().map(|x| format!("{x:02x}")).collect()
}
#[test]
fn pbkdf2_hmac_sha1_rfc6070() {
assert_eq!(
hexs(&pbkdf2(hmac_sha1_full, 20, b"password", b"salt", 1, 20)),
"0c60c80f961f0e71f3a9b524af6012062fe037a6"
);
assert_eq!(
hexs(&pbkdf2(hmac_sha1_full, 20, b"password", b"salt", 2, 20)),
"ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957"
);
assert_eq!(
hexs(&pbkdf2(hmac_sha1_full, 20, b"password", b"salt", 4096, 20)),
"4b007901b765489abead49d926f721d065a429c1"
);
}
#[test]
fn aes_string_to_key_rfc3962() {
assert_eq!(
hexs(&string_to_key(16, b"password", b"ATHENA.MIT.EDUraeburn", 1)),
"42263c6e89f4fc28b8df68ee09799f15"
);
assert_eq!(
hexs(&string_to_key(
16,
b"password",
b"ATHENA.MIT.EDUraeburn",
1200
)),
"4c01cd46d632d01e6dbe230a01ed642a"
);
let k256 = string_to_key(32, b"password", b"ATHENA.MIT.EDUraeburn", 1);
assert_eq!(k256.len(), 32);
assert_eq!(
k256,
string_to_key(32, b"password", b"ATHENA.MIT.EDUraeburn", 1)
);
}
#[test]
fn nfold_matches_ietf_vector() {
let got = nfold(b"012345", 64);
let want: [u8; 8] = [0xbe, 0x07, 0x26, 0x31, 0x27, 0x6b, 0x19, 0x55];
assert_eq!(&got[..], &want[..]);
}
#[test]
fn nfold_output_size_multiple_of_8_bits() {
for &bits in &[64usize, 128, 192, 256, 320] {
let out = nfold(b"any-input", bits);
assert_eq!(out.len() * 8, bits);
}
}
#[test]
fn aes128_cts_roundtrip_across_lengths() {
let key = [0x11u8; AES128_KEY_LEN];
for len in [16usize, 17, 31, 32, 47, 48, 64] {
let pt: Vec<u8> = (0..len).map(|i| i as u8).collect();
let ct = aes_cts_encrypt(&key, &[0u8; AES_BLOCK_LEN], &pt);
let back = aes_cts_decrypt(&key, &[0u8; AES_BLOCK_LEN], &ct);
assert_eq!(back, pt, "AES-128 CTS round-trip failed at len {len}");
}
}
#[test]
fn aes128_dk_preserves_16_byte_key_size() {
let base = [0x22u8; AES128_KEY_LEN];
let sub = dk(&base, &subkey_constant(2, 0xAA));
assert_eq!(sub.len(), AES128_KEY_LEN);
let base256 = [0x33u8; AES256_KEY_LEN];
assert_eq!(
dk(&base256, &subkey_constant(2, 0xAA)).len(),
AES256_KEY_LEN
);
}
#[test]
fn aes128_encrypt_message_roundtrip_and_tamper() {
let session_key = [0x44u8; AES128_KEY_LEN];
let conf = [0x55u8; CONFOUNDER_LEN];
let msg = b"etype-17 sealed payload";
let sealed = encrypt_message(&session_key, KG_USAGE_INITIATOR_SEAL, &conf, msg);
let got = decrypt_message(&session_key, KG_USAGE_INITIATOR_SEAL, &sealed).unwrap();
assert_eq!(got, msg);
let mut bad = sealed.clone();
bad[0] ^= 0x01;
assert!(matches!(
decrypt_message(&session_key, KG_USAGE_INITIATOR_SEAL, &bad),
Err(DecryptError::HmacMismatch)
));
}
#[test]
#[should_panic(expected = "unsupported AES key length")]
fn unsupported_key_length_panics_loudly() {
let _ = aes_cts_encrypt(&[0u8; 24], &[0u8; AES_BLOCK_LEN], &[0u8; 16]);
}
fn zero_iv() -> [u8; AES_BLOCK_LEN] {
[0u8; AES_BLOCK_LEN]
}
fn test_key256() -> [u8; AES256_KEY_LEN] {
let mut k = [0u8; 32];
for (i, byte) in k.iter_mut().enumerate() {
*byte = i as u8 ^ 0x5C;
}
k
}
#[test]
fn cts_roundtrip_exactly_one_block() {
let key = test_key256();
let iv = zero_iv();
let pt: Vec<u8> = (0..16u8).collect();
let ct = aes_cts_encrypt(&key, &iv, &pt);
assert_eq!(ct.len(), 16);
let round = aes_cts_decrypt(&key, &iv, &ct);
assert_eq!(round, pt);
}
#[test]
fn cts_roundtrip_general_partial() {
let key = test_key256();
let iv = zero_iv();
for &len in &[17usize, 31, 47, 63] {
let pt: Vec<u8> = (0..len as u8).map(|b| b.wrapping_mul(37)).collect();
let ct = aes_cts_encrypt(&key, &iv, &pt);
assert_eq!(ct.len(), len, "ciphertext len must match plaintext len");
let round = aes_cts_decrypt(&key, &iv, &ct);
assert_eq!(round, pt, "round-trip failed at len={len}");
}
}
#[test]
fn cts_roundtrip_exact_multiple_of_block() {
let key = test_key256();
let iv = zero_iv();
for &len in &[32usize, 48, 64] {
let pt: Vec<u8> = (0..len as u8).map(|b| b.wrapping_mul(53)).collect();
let ct = aes_cts_encrypt(&key, &iv, &pt);
assert_eq!(ct.len(), len);
let round = aes_cts_decrypt(&key, &iv, &ct);
assert_eq!(round, pt, "exact-multiple round-trip failed at len={len}");
}
}
#[test]
fn dr_output_is_32_bytes_for_aes256() {
let key = test_key256();
let out = dr(&key, b"any-usage-constant");
assert_eq!(out.len(), AES256_KEY_LEN);
}
#[test]
fn dr_is_deterministic() {
let key = test_key256();
assert_eq!(dr(&key, b"c1"), dr(&key, b"c1"));
}
#[test]
fn dr_different_constants_different_outputs() {
let key = test_key256();
assert_ne!(dr(&key, b"c1"), dr(&key, b"c2"));
}
#[test]
fn dk_equals_dr_for_aes_random_to_key_identity() {
let key = test_key256();
assert_eq!(dk(&key, b"c-99"), dr(&key, b"c-99"));
}
#[test]
fn hmac_sha1_96_matches_rfc_2202_test_case_1() {
let key = [0x0bu8; 20];
let got = hmac_sha1_96(&key, b"Hi There");
let want: [u8; 12] = [
0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64, 0xe2, 0x8b, 0xc0, 0xb6,
];
assert_eq!(got, want);
}
#[test]
fn subkeys_are_distinct_for_same_usage() {
let key = test_key256();
let kc = derive_kc(&key, KG_USAGE_INITIATOR_SEAL);
let ke = derive_ke(&key, KG_USAGE_INITIATOR_SEAL);
let ki = derive_ki(&key, KG_USAGE_INITIATOR_SEAL);
assert_ne!(kc, ke);
assert_ne!(ke, ki);
assert_ne!(kc, ki);
assert_eq!(kc.len(), AES256_KEY_LEN);
assert_eq!(ke.len(), AES256_KEY_LEN);
assert_eq!(ki.len(), AES256_KEY_LEN);
}
#[test]
fn subkeys_differ_across_usages() {
let key = test_key256();
assert_ne!(
derive_ke(&key, KG_USAGE_INITIATOR_SEAL),
derive_ke(&key, KG_USAGE_ACCEPTOR_SEAL)
);
}
fn test_confounder() -> [u8; CONFOUNDER_LEN] {
let mut c = [0u8; CONFOUNDER_LEN];
for (i, b) in c.iter_mut().enumerate() {
*b = (i as u8).wrapping_mul(0x11) ^ 0xA5;
}
c
}
#[test]
fn encrypt_decrypt_roundtrip_short_payload() {
let key = test_key256();
let conf = test_confounder();
let plain = b"hello, sealed RPC world!";
let sealed = encrypt_message(&key, KG_USAGE_INITIATOR_SEAL, &conf, plain);
assert_eq!(sealed.len(), plain.len() + CONFOUNDER_LEN + HMAC_TRUNC_LEN);
let round = decrypt_message(&key, KG_USAGE_INITIATOR_SEAL, &sealed).unwrap();
assert_eq!(round, plain);
}
#[test]
fn encrypt_decrypt_roundtrip_various_lengths() {
let key = test_key256();
let conf = test_confounder();
for &len in &[0usize, 1, 15, 16, 17, 31, 32, 33, 47, 63, 64, 65, 1023] {
let plain: Vec<u8> = (0..len as u32).map(|i| ((i * 7) & 0xff) as u8).collect();
let sealed = encrypt_message(&key, KG_USAGE_INITIATOR_SEAL, &conf, &plain);
let round = decrypt_message(&key, KG_USAGE_INITIATOR_SEAL, &sealed).unwrap();
assert_eq!(round, plain, "roundtrip failed at len={len}");
}
}
#[test]
fn tampered_ciphertext_byte_fails_hmac() {
let key = test_key256();
let conf = test_confounder();
let plain = b"payload-to-tamper-with";
let mut sealed = encrypt_message(&key, KG_USAGE_INITIATOR_SEAL, &conf, plain);
sealed[8] ^= 0x01;
match decrypt_message(&key, KG_USAGE_INITIATOR_SEAL, &sealed) {
Err(DecryptError::HmacMismatch) => {}
other => panic!("expected HmacMismatch, got {other:?}"),
}
}
#[test]
fn tampered_hmac_byte_fails_verification() {
let key = test_key256();
let conf = test_confounder();
let plain = b"another-payload";
let mut sealed = encrypt_message(&key, KG_USAGE_INITIATOR_SEAL, &conf, plain);
let last = sealed.len() - 1;
sealed[last] ^= 0xff;
assert!(matches!(
decrypt_message(&key, KG_USAGE_INITIATOR_SEAL, &sealed),
Err(DecryptError::HmacMismatch)
));
}
#[test]
fn wrong_usage_number_fails_verification() {
let key = test_key256();
let conf = test_confounder();
let plain = b"direction-matters";
let sealed = encrypt_message(&key, KG_USAGE_INITIATOR_SEAL, &conf, plain);
assert!(matches!(
decrypt_message(&key, KG_USAGE_ACCEPTOR_SEAL, &sealed),
Err(DecryptError::HmacMismatch)
));
}
#[test]
fn too_short_sealed_message_is_rejected_gracefully() {
let key = test_key256();
let short = vec![0u8; CONFOUNDER_LEN + HMAC_TRUNC_LEN - 1];
assert!(matches!(
decrypt_message(&key, KG_USAGE_INITIATOR_SEAL, &short),
Err(DecryptError::TooShort { .. })
));
}
}