1
2
3
4
5 package salsa
6
7 import "math/bits"
8
9
10
11 func Core208(out *[64]byte, in *[64]byte) {
12 j0 := uint32(in[0]) | uint32(in[1])<<8 | uint32(in[2])<<16 | uint32(in[3])<<24
13 j1 := uint32(in[4]) | uint32(in[5])<<8 | uint32(in[6])<<16 | uint32(in[7])<<24
14 j2 := uint32(in[8]) | uint32(in[9])<<8 | uint32(in[10])<<16 | uint32(in[11])<<24
15 j3 := uint32(in[12]) | uint32(in[13])<<8 | uint32(in[14])<<16 | uint32(in[15])<<24
16 j4 := uint32(in[16]) | uint32(in[17])<<8 | uint32(in[18])<<16 | uint32(in[19])<<24
17 j5 := uint32(in[20]) | uint32(in[21])<<8 | uint32(in[22])<<16 | uint32(in[23])<<24
18 j6 := uint32(in[24]) | uint32(in[25])<<8 | uint32(in[26])<<16 | uint32(in[27])<<24
19 j7 := uint32(in[28]) | uint32(in[29])<<8 | uint32(in[30])<<16 | uint32(in[31])<<24
20 j8 := uint32(in[32]) | uint32(in[33])<<8 | uint32(in[34])<<16 | uint32(in[35])<<24
21 j9 := uint32(in[36]) | uint32(in[37])<<8 | uint32(in[38])<<16 | uint32(in[39])<<24
22 j10 := uint32(in[40]) | uint32(in[41])<<8 | uint32(in[42])<<16 | uint32(in[43])<<24
23 j11 := uint32(in[44]) | uint32(in[45])<<8 | uint32(in[46])<<16 | uint32(in[47])<<24
24 j12 := uint32(in[48]) | uint32(in[49])<<8 | uint32(in[50])<<16 | uint32(in[51])<<24
25 j13 := uint32(in[52]) | uint32(in[53])<<8 | uint32(in[54])<<16 | uint32(in[55])<<24
26 j14 := uint32(in[56]) | uint32(in[57])<<8 | uint32(in[58])<<16 | uint32(in[59])<<24
27 j15 := uint32(in[60]) | uint32(in[61])<<8 | uint32(in[62])<<16 | uint32(in[63])<<24
28
29 x0, x1, x2, x3, x4, x5, x6, x7, x8 := j0, j1, j2, j3, j4, j5, j6, j7, j8
30 x9, x10, x11, x12, x13, x14, x15 := j9, j10, j11, j12, j13, j14, j15
31
32 for i := 0; i < 8; i += 2 {
33 u := x0 + x12
34 x4 ^= bits.RotateLeft32(u, 7)
35 u = x4 + x0
36 x8 ^= bits.RotateLeft32(u, 9)
37 u = x8 + x4
38 x12 ^= bits.RotateLeft32(u, 13)
39 u = x12 + x8
40 x0 ^= bits.RotateLeft32(u, 18)
41
42 u = x5 + x1
43 x9 ^= bits.RotateLeft32(u, 7)
44 u = x9 + x5
45 x13 ^= bits.RotateLeft32(u, 9)
46 u = x13 + x9
47 x1 ^= bits.RotateLeft32(u, 13)
48 u = x1 + x13
49 x5 ^= bits.RotateLeft32(u, 18)
50
51 u = x10 + x6
52 x14 ^= bits.RotateLeft32(u, 7)
53 u = x14 + x10
54 x2 ^= bits.RotateLeft32(u, 9)
55 u = x2 + x14
56 x6 ^= bits.RotateLeft32(u, 13)
57 u = x6 + x2
58 x10 ^= bits.RotateLeft32(u, 18)
59
60 u = x15 + x11
61 x3 ^= bits.RotateLeft32(u, 7)
62 u = x3 + x15
63 x7 ^= bits.RotateLeft32(u, 9)
64 u = x7 + x3
65 x11 ^= bits.RotateLeft32(u, 13)
66 u = x11 + x7
67 x15 ^= bits.RotateLeft32(u, 18)
68
69 u = x0 + x3
70 x1 ^= bits.RotateLeft32(u, 7)
71 u = x1 + x0
72 x2 ^= bits.RotateLeft32(u, 9)
73 u = x2 + x1
74 x3 ^= bits.RotateLeft32(u, 13)
75 u = x3 + x2
76 x0 ^= bits.RotateLeft32(u, 18)
77
78 u = x5 + x4
79 x6 ^= bits.RotateLeft32(u, 7)
80 u = x6 + x5
81 x7 ^= bits.RotateLeft32(u, 9)
82 u = x7 + x6
83 x4 ^= bits.RotateLeft32(u, 13)
84 u = x4 + x7
85 x5 ^= bits.RotateLeft32(u, 18)
86
87 u = x10 + x9
88 x11 ^= bits.RotateLeft32(u, 7)
89 u = x11 + x10
90 x8 ^= bits.RotateLeft32(u, 9)
91 u = x8 + x11
92 x9 ^= bits.RotateLeft32(u, 13)
93 u = x9 + x8
94 x10 ^= bits.RotateLeft32(u, 18)
95
96 u = x15 + x14
97 x12 ^= bits.RotateLeft32(u, 7)
98 u = x12 + x15
99 x13 ^= bits.RotateLeft32(u, 9)
100 u = x13 + x12
101 x14 ^= bits.RotateLeft32(u, 13)
102 u = x14 + x13
103 x15 ^= bits.RotateLeft32(u, 18)
104 }
105 x0 += j0
106 x1 += j1
107 x2 += j2
108 x3 += j3
109 x4 += j4
110 x5 += j5
111 x6 += j6
112 x7 += j7
113 x8 += j8
114 x9 += j9
115 x10 += j10
116 x11 += j11
117 x12 += j12
118 x13 += j13
119 x14 += j14
120 x15 += j15
121
122 out[0] = byte(x0)
123 out[1] = byte(x0 >> 8)
124 out[2] = byte(x0 >> 16)
125 out[3] = byte(x0 >> 24)
126
127 out[4] = byte(x1)
128 out[5] = byte(x1 >> 8)
129 out[6] = byte(x1 >> 16)
130 out[7] = byte(x1 >> 24)
131
132 out[8] = byte(x2)
133 out[9] = byte(x2 >> 8)
134 out[10] = byte(x2 >> 16)
135 out[11] = byte(x2 >> 24)
136
137 out[12] = byte(x3)
138 out[13] = byte(x3 >> 8)
139 out[14] = byte(x3 >> 16)
140 out[15] = byte(x3 >> 24)
141
142 out[16] = byte(x4)
143 out[17] = byte(x4 >> 8)
144 out[18] = byte(x4 >> 16)
145 out[19] = byte(x4 >> 24)
146
147 out[20] = byte(x5)
148 out[21] = byte(x5 >> 8)
149 out[22] = byte(x5 >> 16)
150 out[23] = byte(x5 >> 24)
151
152 out[24] = byte(x6)
153 out[25] = byte(x6 >> 8)
154 out[26] = byte(x6 >> 16)
155 out[27] = byte(x6 >> 24)
156
157 out[28] = byte(x7)
158 out[29] = byte(x7 >> 8)
159 out[30] = byte(x7 >> 16)
160 out[31] = byte(x7 >> 24)
161
162 out[32] = byte(x8)
163 out[33] = byte(x8 >> 8)
164 out[34] = byte(x8 >> 16)
165 out[35] = byte(x8 >> 24)
166
167 out[36] = byte(x9)
168 out[37] = byte(x9 >> 8)
169 out[38] = byte(x9 >> 16)
170 out[39] = byte(x9 >> 24)
171
172 out[40] = byte(x10)
173 out[41] = byte(x10 >> 8)
174 out[42] = byte(x10 >> 16)
175 out[43] = byte(x10 >> 24)
176
177 out[44] = byte(x11)
178 out[45] = byte(x11 >> 8)
179 out[46] = byte(x11 >> 16)
180 out[47] = byte(x11 >> 24)
181
182 out[48] = byte(x12)
183 out[49] = byte(x12 >> 8)
184 out[50] = byte(x12 >> 16)
185 out[51] = byte(x12 >> 24)
186
187 out[52] = byte(x13)
188 out[53] = byte(x13 >> 8)
189 out[54] = byte(x13 >> 16)
190 out[55] = byte(x13 >> 24)
191
192 out[56] = byte(x14)
193 out[57] = byte(x14 >> 8)
194 out[58] = byte(x14 >> 16)
195 out[59] = byte(x14 >> 24)
196
197 out[60] = byte(x15)
198 out[61] = byte(x15 >> 8)
199 out[62] = byte(x15 >> 16)
200 out[63] = byte(x15 >> 24)
201 }
202
View as plain text