Expand description
The primitives of Noise_*_25519_ChaChaPoly_BLAKE2s, in pure Rust with
no dependencies: ChaCha20-Poly1305 (RFC 8439), X25519 (RFC 7748),
BLAKE2s (RFC 7693), and HMAC/HKDF over BLAKE2s as the Noise Protocol
Framework defines them.
No branch and no memory index depends on a key, a scalar or a tag. That is how the code is written, and statistical timing checks on x86_64 and aarch64 found no dependence; a compiler does not promise it, and the crate has not been audited by a third party.
use kevy_crypto::{aead, blake2s, x25519};
// two parties agree on a key...
let (a, b) = ([3u8; 32], [5u8; 32]);
let shared = x25519::x25519(&a, &x25519::x25519(&b, &x25519::BASEPOINT));
let key = blake2s::hash(&shared);
// ...and use it to seal a message
let mut msg = *b"attack at dawn";
let tag = aead::seal(&key, &[0; 12], b"", &mut msg);
aead::open(&key, &[0; 12], b"", &mut msg, &tag).unwrap();
assert_eq!(&msg, b"attack at dawn");Modules§
- aead
- ChaCha20-Poly1305 AEAD (RFC 8439 §2.8), in place.
- blake2s
- BLAKE2s (RFC 7693): 32-bit words, digests of 1 to 32 bytes, optional key.
- hkdf
- HMAC (RFC 2104) over BLAKE2s, and the HKDF that the Noise Protocol Framework builds from it (§4.3 of the Noise specification, revision 34).
- x25519
- X25519 (RFC 7748 §5): the Montgomery ladder over Curve25519.
Functions§
- ct_eq
- Equality of two byte strings in time that depends only on their lengths, never on where they first differ.