1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! 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");
//! ```
// Send and Sync are part of the public contract: a change that loses
// either fails to compile here rather than in a caller.
const _: = ;
/// Equality of two byte strings in time that depends only on their
/// lengths, never on where they first differ.
///
/// ```
/// assert!(kevy_crypto::ct_eq(b"tag", b"tag"));
/// assert!(!kevy_crypto::ct_eq(b"tag", b"taG"));
/// ```