1 /*
2 * Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the License); you may
5 * not use this file except in compliance with the License.
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 */
9
10
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <gmssl/chacha20.h>
16
17
main(void)18 int main(void)
19 {
20 int err = 0;
21 int i;
22 const unsigned char key[] = {
23 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
24 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
25 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
26 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
27 };
28 const unsigned char nonce[] = {
29 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x4a,
30 0x00, 0x00, 0x00, 0x00,
31 };
32 uint32_t counter = 1;
33 const unsigned char testdata[] = {
34 0x10, 0xf1, 0xe7, 0xe4, 0xd1, 0x3b, 0x59, 0x15,
35 0x50, 0x0f, 0xdd, 0x1f, 0xa3, 0x20, 0x71, 0xc4,
36 0xc7, 0xd1, 0xf4, 0xc7, 0x33, 0xc0, 0x68, 0x03,
37 0x04, 0x22, 0xaa, 0x9a, 0xc3, 0xd4, 0x6c, 0x4e,
38 0xd2, 0x82, 0x64, 0x46, 0x07, 0x9f, 0xaa, 0x09,
39 0x14, 0xc2, 0xd7, 0x05, 0xd9, 0x8b, 0x02, 0xa2,
40 0xb5, 0x12, 0x9c, 0xd1, 0xde, 0x16, 0x4e, 0xb9,
41 0xcb, 0xd0, 0x83, 0xe8, 0xa2, 0x50, 0x3c, 0x4e,
42 };
43 unsigned char buf[64];
44
45 CHACHA20_STATE state;
46 chacha20_init(&state, key, nonce, counter);
47 chacha20_generate_keystream(&state, 1, buf);
48
49 printf("chacha20 test ");
50 if (memcmp(buf, testdata, sizeof(testdata)) != 0) {
51 printf("failed\n");
52 err++;
53 } else {
54 printf("ok\n");
55 }
56
57 return err;
58 }
59
60