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
66
67
68
use super::Key;
pub (super) type Word = u32;
pub (super) const WORD_ARRAY_LEN: usize = 16;
pub (super) type WordArray = [Word; WORD_ARRAY_LEN];
const SIGMA: [u8; 16] = *b"expand 32-byte k";
#[allow(dead_code)]
const TAU: [u8; 16] = *b"expand 16-byte k";
pub (crate) fn new<K, IV>(key: K, iv: IV) -> WordArray where K: Into<Key>, IV: Into<super::IV> {
let key = key.into();
let iv = iv.into();
[
Word::from_le_bytes([SIGMA[ 0], SIGMA[ 1], SIGMA[ 2], SIGMA[ 3]]),
Word::from_le_bytes([SIGMA[ 4], SIGMA[ 5], SIGMA[ 6], SIGMA[ 7]]),
Word::from_le_bytes([SIGMA[ 8], SIGMA[ 9], SIGMA[10], SIGMA[11]]),
Word::from_le_bytes([SIGMA[12], SIGMA[13], SIGMA[14], SIGMA[15]]),
Word::from_le_bytes([key[ 0], key[ 1], key[ 2], key[ 3]]),
Word::from_le_bytes([key[ 4], key[ 5], key[ 6], key[ 7]]),
Word::from_le_bytes([key[ 8], key[ 9], key[10], key[11]]),
Word::from_le_bytes([key[12], key[13], key[14], key[15]]),
Word::from_le_bytes([key[16], key[17], key[18], key[19]]),
Word::from_le_bytes([key[20], key[21], key[22], key[23]]),
Word::from_le_bytes([key[24], key[25], key[26], key[27]]),
Word::from_le_bytes([key[28], key[29], key[30], key[31]]),
Word::from_le_bytes([iv[ 0], iv[ 1], iv[ 2], iv[ 3]]),
Word::from_le_bytes([iv[ 4], iv[ 5], iv[ 6], iv[ 7]]),
Word::from_le_bytes([iv[ 8], iv[ 9], iv[10], iv[11]]),
Word::from_le_bytes([iv[12], iv[13], iv[14], iv[15]]),
]
}