-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmixcolumns.balsa
76 lines (67 loc) · 2.19 KB
/
mixcolumns.balsa
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
69
70
71
72
73
74
75
76
(--
This file is part of naive-AES-balsa.
naive-AES-balsa is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
naive-AES-balsa is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with naive-AES-balsa. If not, see <http://www.gnu.org/licenses/>.
--)
import [balsa.types.basic]
import [mixcolumn]
--Version for key arranged as:
-- 0 4 8 C
-- 1 5 9 D
-- 2 6 A E
-- 3 7 B F
procedure mixcolumns (input i : 128 bits;
output o : 128 bits) is
array 4 of channel col, mix : 32 bits
begin
for || k in 0..3 then
mixcolumn(col[k], mix[k])
end ||
loop i -> then
col[0] <- (#i[0..31] as 32 bits) ||
col[1] <- (#i[32..63] as 32 bits) ||
col[2] <- (#i[64..95] as 32 bits) ||
col[3] <- (#i[96..127] as 32 bits) ||
select mix[0], mix[1], mix[2], mix[3] then
o <- ((#(mix[0]) @ #(mix[1]) @ #(mix[2]) @ #(mix[3])) as 128 bits)
end
end end
end
-- Version for key arranged as:
-- 0 1 2 3
-- 4 5 6 7
-- 8 9 A B
-- C D E F
(--
procedure mixcolumns (input i : array 16 of byte;
output o : array 16 of byte) is
array 4 of channel col, mix : array 4 of byte
begin
loop i -> then
-- TODO: Make strided loop
col[0] <- {i[0], i[4], i[8], i[12]} ||
col[1] <- {i[0+1], i[4+1], i[8+1], i[12+1]} ||
col[2] <- {i[0+2], i[4+2], i[8+2], i[12+2]} ||
col[3] <- {i[0+3], i[4+3], i[8+3], i[12+3]}
end end ||
for || k in 0..3 then
mixcolumn(col[k], mix[k])
end ||
loop
mix[0], mix[1], mix[2], mix[3] -> then
o <- {mix[0][0], mix[1][0], mix[2][0], mix[3][0],
mix[0][1], mix[1][1], mix[2][1], mix[3][1],
mix[0][2], mix[1][2], mix[2][2], mix[3][2],
mix[0][3], mix[1][3], mix[2][3], mix[3][3]
}
end end
end
--)