use crabgraph::{
aead::{AesGcm256, CrabAead},
hash::sha256,
kdf::pbkdf2_derive_sha256,
mac::hmac_sha256,
CrabResult,
};
use hex_literal::hex;
#[test]
fn test_aes_gcm_nist_vector() -> CrabResult<()> {
let key = [0u8; 32];
let cipher = AesGcm256::new(&key)?;
let plaintext = b"";
let nonce = [0u8; 12];
let ciphertext = cipher.encrypt_with_nonce(plaintext, &nonce, None)?;
let decrypted = cipher.decrypt(&ciphertext, None)?;
assert_eq!(decrypted, plaintext);
Ok(())
}
#[test]
fn test_sha256_rfc_vectors() {
let hash = sha256(b"");
let expected = hex!("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
assert_eq!(hash, expected);
let hash = sha256(b"abc");
let expected = hex!("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
assert_eq!(hash, expected);
}
#[test]
fn test_hmac_sha256_rfc_vectors() -> CrabResult<()> {
let key = b"Jefe";
let message = b"what do ya want for nothing?";
let expected = hex!("5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843");
let tag = hmac_sha256(key, message)?;
assert_eq!(&tag[..], &expected[..]);
Ok(())
}
#[test]
fn test_pbkdf2_deterministic() -> CrabResult<()> {
let password = b"password";
let salt = b"salt_16_bytes!!!";
let iterations = 10_000;
let key1 = pbkdf2_derive_sha256(password, salt, iterations, 32)?;
let key2 = pbkdf2_derive_sha256(password, salt, iterations, 32)?;
assert_eq!(key1.as_slice(), key2.as_slice());
Ok(())
}
#[test]
fn test_openssl_compatibility_notes() {
}
#[test]
fn test_web_crypto_compatibility_notes() {
}
#[test]
fn test_cryptojs_migration_notes() {
}