-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathecrypt.rs
More file actions
56 lines (46 loc) · 1.59 KB
/
ecrypt.rs
File metadata and controls
56 lines (46 loc) · 1.59 KB
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
use cipher::{KeyIvInit, StreamCipher, StreamCipherSeek, blobby};
use salsa20::{Salsa20, Salsa20_16};
/// ECRYPT test vectors:
/// https://github.com/das-labor/legacy/blob/master/microcontroller-2/arm-crypto-lib/testvectors/salsa20-256.64-verified.test-vectors
#[test]
fn salsa20_ecrypt() {
blobby::parse_into_structs!(
include_bytes!("data/ecrypt.blb");
#[define_struct]
static TEST_VECTORS: &[
TestVector { key, iv, pos, expected }
];
);
for tv in TEST_VECTORS {
let key = tv.key.try_into().unwrap();
let iv = tv.iv.try_into().unwrap();
let pos = u32::from_be_bytes(tv.pos.try_into().unwrap());
let mut c = Salsa20::new(key, iv);
c.seek(pos);
let mut buf = [0u8; 64];
c.apply_keystream(&mut buf);
assert_eq!(buf, tv.expected);
}
}
/// ECRYPT test vectors:
/// https://github.com/das-labor/legacy/blob/master/microcontroller-2/arm-crypto-lib/testvectors/salsa20-128.64-verified.test-vectors
#[test]
fn salsa20_ecrypt16() {
blobby::parse_into_structs!(
include_bytes!("data/ecrypt16.blb");
#[define_struct]
static TEST_VECTORS: &[
TestVector { key, iv, pos, expected }
];
);
for tv in TEST_VECTORS {
let key = tv.key.try_into().unwrap();
let iv = tv.iv.try_into().unwrap();
let pos = u32::from_be_bytes(tv.pos.try_into().unwrap());
let mut c = Salsa20_16::new(key, iv);
c.seek(pos);
let mut buf = [0u8; 64];
c.apply_keystream(&mut buf);
assert_eq!(buf, tv.expected);
}
}