|
36 | 36 | static const uint8_t constants[16] = "expand 32-byte k";
|
37 | 37 |
|
38 | 38 | /* Chacha-20 quarter round function */
|
39 |
| -static void cx_chacha_quarter_round(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d) |
| 39 | +STATIC void cx_chacha_quarter_round(uint32_t *a, uint32_t *b, uint32_t *c, uint32_t *d) |
40 | 40 | {
|
41 | 41 | *a = PLUS(*a, *b);
|
42 | 42 | *d = ROTATE(XOR(*d, *a), 16);
|
@@ -69,7 +69,7 @@ static void cx_chacha_process_block(cx_chacha_context_t *ctx)
|
69 | 69 | cx_chacha_quarter_round(&x[3], &x[4], &x[9], &x[14]);
|
70 | 70 | }
|
71 | 71 | for (i = 0; i < CHACHA_STATE_ARRAY_SIZE; i++) {
|
72 |
| - x[i] = PLUS(x[i], ctx->state[i]); |
| 72 | + x[i] = x[i] + ctx->state[i]; |
73 | 73 | }
|
74 | 74 | }
|
75 | 75 |
|
@@ -177,74 +177,3 @@ cx_err_t cx_chacha_cipher(uint32_t nrounds,
|
177 | 177 | return error;
|
178 | 178 | }
|
179 | 179 | #endif // HAVE_CHACHA
|
180 |
| - |
181 |
| -#ifdef UNIT_TESTING |
182 |
| -#include <stdarg.h> |
183 |
| -#include <cmocka.h> |
184 |
| - |
185 |
| -static void test_chacha_round(void **state) |
186 |
| -{ |
187 |
| - (void) state; |
188 |
| - |
189 |
| - uint32_t state_array[16] = {0x61707865, |
190 |
| - 0x3320646e, |
191 |
| - 0x79622d32, |
192 |
| - 0x6b206574, |
193 |
| - 0x03020100, |
194 |
| - 0x07060504, |
195 |
| - 0x0b0a0908, |
196 |
| - 0x0f0e0d0c, |
197 |
| - 0x13121110, |
198 |
| - 0x17161514, |
199 |
| - 0x1b1a1918, |
200 |
| - 0x1f1e1d1c, |
201 |
| - 0x00000001, |
202 |
| - 0x09000000, |
203 |
| - 0x4a000000, |
204 |
| - 0x00000000}; |
205 |
| - uint32_t expected_array[16] = {0x837778ab, |
206 |
| - 0xe238d763, |
207 |
| - 0xa67ae21e, |
208 |
| - 0x5950bb2f, |
209 |
| - 0xc4f2d0c7, |
210 |
| - 0xfc62bb2f, |
211 |
| - 0x8fa018fc, |
212 |
| - 0x3f5ec7b7, |
213 |
| - 0x335271c2, |
214 |
| - 0xf29489f3, |
215 |
| - 0xeabda8fc, |
216 |
| - 0x82e46ebd, |
217 |
| - 0xd19c12b4, |
218 |
| - 0xb04e16de, |
219 |
| - 0x9e83d0cb, |
220 |
| - 0x4e3c50a2}; |
221 |
| - for (int i = 0; i < 10; i++) { |
222 |
| - cx_chacha_quarter_round( |
223 |
| - &state_array[0], &state_array[4], &state_array[8], &state_array[12]); |
224 |
| - cx_chacha_quarter_round( |
225 |
| - &state_array[1], &state_array[5], &state_array[9], &state_array[13]); |
226 |
| - cx_chacha_quarter_round( |
227 |
| - &state_array[2], &state_array[6], &state_array[10], &state_array[14]); |
228 |
| - cx_chacha_quarter_round( |
229 |
| - &state_array[3], &state_array[7], &state_array[11], &state_array[15]); |
230 |
| - |
231 |
| - cx_chacha_quarter_round( |
232 |
| - &state_array[0], &state_array[5], &state_array[10], &state_array[15]); |
233 |
| - cx_chacha_quarter_round( |
234 |
| - &state_array[1], &state_array[6], &state_array[11], &state_array[12]); |
235 |
| - cx_chacha_quarter_round( |
236 |
| - &state_array[2], &state_array[7], &state_array[8], &state_array[13]); |
237 |
| - cx_chacha_quarter_round( |
238 |
| - &state_array[3], &state_array[4], &state_array[9], &state_array[14]); |
239 |
| - } |
240 |
| - |
241 |
| - assert_memory_equal(state_array, expected_array, sizeof(state_array)); |
242 |
| -} |
243 |
| - |
244 |
| -int main(void) |
245 |
| -{ |
246 |
| - const struct CMUnitTest tests[] = {cmocka_unit_test(test_chacha_round)}; |
247 |
| - |
248 |
| - return cmocka_run_group_tests(tests, NULL, NULL); |
249 |
| -} |
250 |
| -#endif // UNIT_TESTING |
0 commit comments