use hex_lit::hex; use x25519_dalek::PublicKey; use crate::qcrypto::aead::{qcrypto_aead, qcrypto_aead_decrypt, qcrypto_xaead, qcrypto_xaead_decrypt}; use crate::qcrypto::{CONSTURCTION, IDENTIFIER}; use crate::qcrypto::hashes::{qcrypto_hash, qcrypto_hash_twice, qcrypto_hmac, qcrypto_mac}; use crate::qcrypto::hkdf::qcrypto_hkdf; use crate::qcrypto::pki::{qcrypto_dh_longterm, qcrypto_dh_generate_longterm}; #[test] fn qcrypto_hash_test() { assert_eq!(qcrypto_hash(&[0u8; 32]), hex!("320b5ea99e653bc2b593db4130d10a4efd3a0b4cc2e1a6672b678d71dfbd33ad")); assert_eq!(qcrypto_hash(CONSTURCTION.as_bytes()), [ 96, 226, 109, 174, 243, 39, 239, 192, 46, 195, 53, 226, 160, 37, 210, 208, 22, 235, 66, 6, 248, 114, 119, 245, 45, 56, 209, 152, 139, 120, 205, 54, ]); assert_eq!(qcrypto_hash_twice(&qcrypto_hash(CONSTURCTION.as_bytes()), IDENTIFIER.as_bytes()), [ 34, 17, 179, 97, 8, 26, 197, 102, 105, 18, 67, 219, 69, 138, 213, 50, 45, 156, 108, 102, 34, 147, 232, 183, 14, 225, 156, 101, 186, 7, 158, 243, ]); } #[test] fn qcrypto_mac_test() { assert_eq!(qcrypto_mac(&[0u8; 32], &[0u8; 32]), hex!("086de86cfb256a2bc40740062bcf4dcc")); } #[test] fn qcrypto_hmac_test() { assert_eq!(qcrypto_hmac(&[0u8; 32], &[0u8; 32]), hex!("025108dc4694cac66d549e152b967e41e516cc7568111822bf1ca44cb89bcbca")); } #[test] fn qcrypto_pki_generate_test() { let keypair = qcrypto_dh_generate_longterm(); assert_eq!(keypair.1, PublicKey::from(&keypair.0)) } #[test] fn qcrypto_dh_test() { let alice = qcrypto_dh_generate_longterm(); let bob = qcrypto_dh_generate_longterm(); let secret = qcrypto_dh_longterm(&alice.0, &bob.1); let secret2 = qcrypto_dh_longterm(&bob.0, &alice.1); assert_eq!(secret.as_bytes(), secret2.as_bytes()) } #[test] fn qcrypto_aead_test() { let ciphertext = qcrypto_aead(&[0u8; 32], 0, &[0u8; 32], &[0u8; 32]).unwrap(); assert_eq!(qcrypto_aead_decrypt(&[0u8; 32], 0, &ciphertext, &[0u8; 32]).unwrap(), [0u8; 32].to_vec()) } #[test] fn qcrypto_xaead_test() { let ciphertext = qcrypto_xaead(&[0u8; 32], &[0u8; 24], &[0u8; 32], &[0u8; 32]).unwrap(); assert_eq!(qcrypto_xaead_decrypt(&[0u8; 32], &[0u8; 24], &ciphertext, &[0u8; 32]).unwrap(), [0u8; 32].to_vec()); } #[test] fn qcrypto_hkdf_test() { let derived = qcrypto_hkdf::<1>(&[0u8; 32], &[0u8; 32]); assert_eq!(derived, [hex!("1090894613df8aef670b0b867e222daebc0d3e436cdddbc16c65855ab93cc91a")]); }