12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /*
- * Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the License); you may
- * not use this file except in compliance with the License.
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <gmssl/chacha20.h>
- int main(void)
- {
- int err = 0;
- const unsigned char key[] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
- };
- const unsigned char nonce[] = {
- 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x4a,
- 0x00, 0x00, 0x00, 0x00,
- };
- uint32_t counter = 1;
- const unsigned char testdata[] = {
- 0x10, 0xf1, 0xe7, 0xe4, 0xd1, 0x3b, 0x59, 0x15,
- 0x50, 0x0f, 0xdd, 0x1f, 0xa3, 0x20, 0x71, 0xc4,
- 0xc7, 0xd1, 0xf4, 0xc7, 0x33, 0xc0, 0x68, 0x03,
- 0x04, 0x22, 0xaa, 0x9a, 0xc3, 0xd4, 0x6c, 0x4e,
- 0xd2, 0x82, 0x64, 0x46, 0x07, 0x9f, 0xaa, 0x09,
- 0x14, 0xc2, 0xd7, 0x05, 0xd9, 0x8b, 0x02, 0xa2,
- 0xb5, 0x12, 0x9c, 0xd1, 0xde, 0x16, 0x4e, 0xb9,
- 0xcb, 0xd0, 0x83, 0xe8, 0xa2, 0x50, 0x3c, 0x4e,
- };
- unsigned char buf[64];
- CHACHA20_STATE state;
- chacha20_init(&state, key, nonce, counter);
- chacha20_generate_keystream(&state, 1, buf);
- printf("chacha20 test ");
- if (memcmp(buf, testdata, sizeof(testdata)) != 0) {
- printf("failed\n");
- err++;
- } else {
- printf("ok\n");
- }
- return err;
- }
|