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

rdobuilder 775784
rdobuilder 775784
#define TEST_NAME "stream2"
rdobuilder 775784
#include "cmptest.h"
rdobuilder 775784
rdobuilder 775784
static const unsigned char secondkey[32] = {
rdobuilder 775784
    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
rdobuilder 775784
static const unsigned char noncesuffix[8] = {
rdobuilder 775784
    0x82, 0x19, 0xe0, 0x03, 0x6b, 0x7a, 0x0b, 0x37
rdobuilder 775784
};
rdobuilder 775784
rdobuilder 775784
rdobuilder 775784
rdobuilder 775784
int
rdobuilder 775784
main(void)
rdobuilder 775784
{
rdobuilder 775784
    unsigned char *output;
rdobuilder 775784
    char          *hex;
rdobuilder 775784
    unsigned char  h[32];
rdobuilder 775784
    size_t         sizeof_hex = 32 * 2 + 1;
rdobuilder 775784
    size_t         sizeof_output = 4194304;
rdobuilder 775784
    int            i;
rdobuilder 775784
rdobuilder 775784
    output = (unsigned char *) sodium_malloc(sizeof_output);
rdobuilder 775784
    hex = (char *) sodium_malloc(sizeof_hex);
rdobuilder 775784
rdobuilder 775784
    crypto_stream_salsa20(output, sizeof_output, noncesuffix, secondkey);
rdobuilder 775784
    crypto_hash_sha256(h, output, sizeof_output);
rdobuilder 775784
    sodium_bin2hex(hex, sizeof_hex, h, sizeof h);
rdobuilder 775784
    printf("%s\n", hex);
rdobuilder 775784
rdobuilder 775784
    assert(sizeof_output > 4000);
rdobuilder 775784
rdobuilder 775784
    crypto_stream_salsa20_xor_ic(output, output, 4000, noncesuffix, 0U,
rdobuilder 775784
                                 secondkey);
rdobuilder 775784
    for (i = 0; i < 4000; i++) {
rdobuilder 775784
        assert(output[i] == 0);
rdobuilder 775784
    }
rdobuilder 775784
rdobuilder 775784
    crypto_stream_salsa20_xor_ic(output, output, 4000, noncesuffix, 1U,
rdobuilder 775784
                                 secondkey);
rdobuilder 775784
    crypto_hash_sha256(h, output, sizeof_output);
rdobuilder 775784
    sodium_bin2hex(hex, sizeof_hex, h, sizeof h);
rdobuilder 775784
    printf("%s\n", hex);
rdobuilder 775784
rdobuilder 775784
    sodium_free(hex);
rdobuilder 775784
    sodium_free(output);
rdobuilder 775784
rdobuilder 775784
    assert(crypto_stream_salsa20_keybytes() > 0U);
rdobuilder 775784
    assert(crypto_stream_salsa20_noncebytes() > 0U);
rdobuilder 775784
    assert(crypto_stream_salsa20_messagebytes_max() > 0U);
rdobuilder 775784
rdobuilder 775784
    return 0;
rdobuilder 775784
}