Path: blob/main/sys/contrib/libsodium/test/default/core3.c
48375 views
1#define TEST_NAME "core3"2#include "cmptest.h"34static unsigned char SECONDKEY[32] = { 0xdc, 0x90, 0x8d, 0xda, 0x0b, 0x93, 0x44,50xa9, 0x53, 0x62, 0x9b, 0x73, 0x38, 0x20,60x77, 0x88, 0x80, 0xf3, 0xce, 0xb4, 0x21,70xbb, 0x61, 0xb9, 0x1c, 0xbd, 0x4c, 0x3e,80x66, 0x25, 0x6c, 0xe4 };910static unsigned char NONCESUFFIX[8] = { 0x82, 0x19, 0xe0, 0x03,110x6b, 0x7a, 0x0b, 0x37 };1213static unsigned char C[16] = { 0x65, 0x78, 0x70, 0x61, 0x6e, 0x64, 0x20, 0x33,140x32, 0x2d, 0x62, 0x79, 0x74, 0x65, 0x20, 0x6b };1516int17main(void)18{19unsigned char *secondkey;20unsigned char *c;21unsigned char *noncesuffix;22unsigned char *in;23unsigned char *output;24unsigned char *h;25size_t output_len = 64 * 256 * 256;26size_t pos = 0;27int i;2829pos = 0;30secondkey = (unsigned char *) sodium_malloc(32);31memcpy(secondkey, SECONDKEY, 32);32noncesuffix = (unsigned char *) sodium_malloc(8);33memcpy(noncesuffix, NONCESUFFIX, 8);34c = (unsigned char *) sodium_malloc(16);35memcpy(c, C, 16);36in = (unsigned char *) sodium_malloc(16);37output = (unsigned char *) sodium_malloc(output_len);38h = (unsigned char *) sodium_malloc(32);3940for (i = 0; i < 8; i++) {41in[i] = noncesuffix[i];42}43for (; i < 16; i++) {44in[i] = 0;45}46do {47do {48crypto_core_salsa20(output + pos, in, secondkey, c);49pos += 64;50in[8]++;51} while (in[8] != 0);52in[9]++;53} while (in[9] != 0);5455crypto_hash_sha256(h, output, output_len);5657for (i = 0; i < 32; ++i) {58printf("%02x", h[i]);59}60printf("\n");6162#ifndef SODIUM_LIBRARY_MINIMAL63pos = 0;64do {65do {66crypto_core_salsa2012(output + pos, in, secondkey, c);67pos += 64;68in[8]++;69} while (in[8] != 0);70in[9]++;71} while (in[9] != 0);7273crypto_hash_sha256(h, output, output_len);7475for (i = 0; i < 32; ++i) {76printf("%02x", h[i]);77}78printf("\n");7980pos = 0;81do {82do {83crypto_core_salsa208(output + pos, in, secondkey, c);84pos += 64;85in[8]++;86} while (in[8] != 0);87in[9]++;88} while (in[9] != 0);8990crypto_hash_sha256(h, output, output_len);9192for (i = 0; i < 32; ++i) {93printf("%02x", h[i]);94}95printf("\n");96#else97printf("a4e3147dddd2ba7775939b50208a22eb3277d4e4bad8a1cfbc999c6bd392b638\n"98"017421baa9959cbe894bd003ec87938254f47c1e757eb66cf89c353d0c2b68de\n");99#endif100101sodium_free(h);102sodium_free(output);103sodium_free(in);104sodium_free(c);105sodium_free(noncesuffix);106sodium_free(secondkey);107108assert(crypto_core_salsa20_outputbytes() == crypto_core_salsa20_OUTPUTBYTES);109assert(crypto_core_salsa20_inputbytes() == crypto_core_salsa20_INPUTBYTES);110assert(crypto_core_salsa20_keybytes() == crypto_core_salsa20_KEYBYTES);111assert(crypto_core_salsa20_constbytes() == crypto_core_salsa20_CONSTBYTES);112113return 0;114}115116117