Skip to content

Commit 0e9f4a4

Browse files
authored
salsa20: add ECRYPT test vectors (#428)
1 parent e6b847a commit 0e9f4a4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

salsa20/tests/data/ecrypt.blb

31 KB
Binary file not shown.

salsa20/tests/ecrypt.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use cipher::{KeyIvInit, StreamCipher, StreamCipherSeek, blobby};
2+
use salsa20::Salsa20;
3+
4+
static DATA: &[u8] = include_bytes!("data/ecrypt.blb");
5+
6+
/// ECRYPT test vectors:
7+
/// https://github.com/das-labor/legacy/blob/master/microcontroller-2/arm-crypto-lib/testvectors/salsa20-256.64-verified.test-vectors
8+
#[test]
9+
fn salsa20_ecrypt() {
10+
let test_vectors = blobby::Blob4Iterator::new(DATA).unwrap();
11+
for test_vector in test_vectors {
12+
let [key, iv, pos, expected] = test_vector.unwrap();
13+
14+
let key = key.try_into().unwrap();
15+
let iv = iv.try_into().unwrap();
16+
let pos = u32::from_be_bytes(pos.try_into().unwrap());
17+
18+
let mut c = Salsa20::new(key, iv);
19+
c.seek(pos);
20+
21+
let mut buf = [0u8; 64];
22+
c.apply_keystream(&mut buf);
23+
24+
assert_eq!(buf, expected);
25+
}
26+
}

0 commit comments

Comments
 (0)