use oxicrypto::{aead_impl, kdf_impl, AeadAlgo, KdfAlgo};
fn main() {
let ikm = b"shared-secret-input-key-material";
let salt = b"oxicrypto-encrypt-example-salt";
let info = b"aes-256-gcm session key v1";
let kdf = kdf_impl(KdfAlgo::HkdfSha256);
let mut session_key = [0u8; 32]; kdf.derive(ikm, salt, info, &mut session_key)
.expect("HKDF-SHA-256 key derivation failed");
println!("Derived 32-byte AES-256-GCM session key via HKDF-SHA-256");
let aead = aead_impl(AeadAlgo::Aes256Gcm);
let nonce = [0x42u8; 12];
let aad = b"example-plaintext-header";
let plaintext = b"Hello, post-quantum world! This message is confidential.";
let ciphertext = aead
.seal_to_vec(&session_key, &nonce, aad, plaintext)
.expect("AES-256-GCM encryption failed");
println!(
"Encrypted {} bytes of plaintext into {} bytes of ciphertext (incl. 16-byte tag)",
plaintext.len(),
ciphertext.len()
);
let recovered = aead
.open_to_vec(&session_key, &nonce, aad, &ciphertext)
.expect("AES-256-GCM decryption/authentication failed");
assert_eq!(
recovered.as_slice(),
plaintext.as_ref(),
"Recovered plaintext does not match original"
);
println!(
"Decryption succeeded. Recovered: {:?}",
core::str::from_utf8(&recovered).unwrap_or("<binary>")
);
let mut tampered = ciphertext.clone();
tampered[0] ^= 0xff;
let tamper_result = aead.open_to_vec(&session_key, &nonce, aad, &tampered);
assert!(
tamper_result.is_err(),
"AES-256-GCM must reject tampered ciphertext"
);
println!("Tamper detection: correctly rejected modified ciphertext");
}