Blame SOURCES/libsodium-1.0.18/test/default/core3.c

rdobuilder 775784
rdobuilder 775784
#define TEST_NAME "core3"
rdobuilder 775784
#include "cmptest.h"
rdobuilder 775784
rdobuilder 775784
static unsigned char SECONDKEY[32] = { 0xdc, 0x90, 0x8d, 0xda, 0x0b, 0x93, 0x44,
rdobuilder 775784
                                       0xa9, 0x53, 0x62, 0x9b, 0x73, 0x38, 0x20,
rdobuilder 775784
                                       0x77, 0x88, 0x80, 0xf3, 0xce, 0xb4, 0x21,
rdobuilder 775784
                                       0xbb, 0x61, 0xb9, 0x1c, 0xbd, 0x4c, 0x3e,
rdobuilder 775784
                                       0x66, 0x25, 0x6c, 0xe4 };
rdobuilder 775784
rdobuilder 775784
static unsigned char NONCESUFFIX[8] = { 0x82, 0x19, 0xe0, 0x03,
rdobuilder 775784
                                        0x6b, 0x7a, 0x0b, 0x37 };
rdobuilder 775784
rdobuilder 775784
static unsigned char C[16] = { 0x65, 0x78, 0x70, 0x61, 0x6e, 0x64, 0x20, 0x33,
rdobuilder 775784
                               0x32, 0x2d, 0x62, 0x79, 0x74, 0x65, 0x20, 0x6b };
rdobuilder 775784
rdobuilder 775784
int
rdobuilder 775784
main(void)
rdobuilder 775784
{
rdobuilder 775784
    unsigned char *secondkey;
rdobuilder 775784
    unsigned char *c;
rdobuilder 775784
    unsigned char *noncesuffix;
rdobuilder 775784
    unsigned char *in;
rdobuilder 775784
    unsigned char *output;
rdobuilder 775784
    unsigned char *h;
rdobuilder 775784
    size_t         output_len = 64 * 256 * 256;
rdobuilder 775784
    size_t         pos = 0;
rdobuilder 775784
    int            i;
rdobuilder 775784
rdobuilder 775784
    pos = 0;
rdobuilder 775784
    secondkey = (unsigned char *) sodium_malloc(32);
rdobuilder 775784
    memcpy(secondkey, SECONDKEY, 32);
rdobuilder 775784
    noncesuffix = (unsigned char *) sodium_malloc(8);
rdobuilder 775784
    memcpy(noncesuffix, NONCESUFFIX, 8);
rdobuilder 775784
    c = (unsigned char *) sodium_malloc(16);
rdobuilder 775784
    memcpy(c, C, 16);
rdobuilder 775784
    in = (unsigned char *) sodium_malloc(16);
rdobuilder 775784
    output = (unsigned char *) sodium_malloc(output_len);
rdobuilder 775784
    h = (unsigned char *) sodium_malloc(32);
rdobuilder 775784
rdobuilder 775784
    for (i = 0; i < 8; i++) {
rdobuilder 775784
        in[i] = noncesuffix[i];
rdobuilder 775784
    }
rdobuilder 775784
    for (; i < 16; i++) {
rdobuilder 775784
        in[i] = 0;
rdobuilder 775784
    }
rdobuilder 775784
    do {
rdobuilder 775784
        do {
rdobuilder 775784
            crypto_core_salsa20(output + pos, in, secondkey, c);
rdobuilder 775784
            pos += 64;
rdobuilder 775784
            in[8]++;
rdobuilder 775784
        } while (in[8] != 0);
rdobuilder 775784
        in[9]++;
rdobuilder 775784
    } while (in[9] != 0);
rdobuilder 775784
rdobuilder 775784
    crypto_hash_sha256(h, output, output_len);
rdobuilder 775784
rdobuilder 775784
    for (i = 0; i < 32; ++i) {
rdobuilder 775784
        printf("%02x", h[i]);
rdobuilder 775784
    }
rdobuilder 775784
    printf("\n");
rdobuilder 775784
rdobuilder 775784
#ifndef SODIUM_LIBRARY_MINIMAL
rdobuilder 775784
    pos = 0;
rdobuilder 775784
    do {
rdobuilder 775784
        do {
rdobuilder 775784
            crypto_core_salsa2012(output + pos, in, secondkey, c);
rdobuilder 775784
            pos += 64;
rdobuilder 775784
            in[8]++;
rdobuilder 775784
        } while (in[8] != 0);
rdobuilder 775784
        in[9]++;
rdobuilder 775784
    } while (in[9] != 0);
rdobuilder 775784
rdobuilder 775784
    crypto_hash_sha256(h, output, output_len);
rdobuilder 775784
rdobuilder 775784
    for (i = 0; i < 32; ++i) {
rdobuilder 775784
        printf("%02x", h[i]);
rdobuilder 775784
    }
rdobuilder 775784
    printf("\n");
rdobuilder 775784
rdobuilder 775784
    pos = 0;
rdobuilder 775784
    do {
rdobuilder 775784
        do {
rdobuilder 775784
            crypto_core_salsa208(output + pos, in, secondkey, c);
rdobuilder 775784
            pos += 64;
rdobuilder 775784
            in[8]++;
rdobuilder 775784
        } while (in[8] != 0);
rdobuilder 775784
        in[9]++;
rdobuilder 775784
    } while (in[9] != 0);
rdobuilder 775784
rdobuilder 775784
    crypto_hash_sha256(h, output, output_len);
rdobuilder 775784
rdobuilder 775784
    for (i = 0; i < 32; ++i) {
rdobuilder 775784
        printf("%02x", h[i]);
rdobuilder 775784
    }
rdobuilder 775784
    printf("\n");
rdobuilder 775784
#else
rdobuilder 775784
    printf("a4e3147dddd2ba7775939b50208a22eb3277d4e4bad8a1cfbc999c6bd392b638\n"
rdobuilder 775784
           "017421baa9959cbe894bd003ec87938254f47c1e757eb66cf89c353d0c2b68de\n");
rdobuilder 775784
#endif
rdobuilder 775784
rdobuilder 775784
    sodium_free(h);
rdobuilder 775784
    sodium_free(output);
rdobuilder 775784
    sodium_free(in);
rdobuilder 775784
    sodium_free(c);
rdobuilder 775784
    sodium_free(noncesuffix);
rdobuilder 775784
    sodium_free(secondkey);
rdobuilder 775784
rdobuilder 775784
    assert(crypto_core_salsa20_outputbytes() == crypto_core_salsa20_OUTPUTBYTES);
rdobuilder 775784
    assert(crypto_core_salsa20_inputbytes() == crypto_core_salsa20_INPUTBYTES);
rdobuilder 775784
    assert(crypto_core_salsa20_keybytes() == crypto_core_salsa20_KEYBYTES);
rdobuilder 775784
    assert(crypto_core_salsa20_constbytes() == crypto_core_salsa20_CONSTBYTES);
rdobuilder 775784
rdobuilder 775784
    return 0;
rdobuilder 775784
}