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

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