Sha256: c9e3234fa2212f72a705029b4956ebc8817d20b6c26873f02f28bbf496ee9556

Contents?: true

Size: 1.88 KB

Versions: 5

Compression:

Stored size: 1.88 KB

Contents

#define TEST_NAME "generichash2"
#include "cmptest.h"

int
main(void)
{
#define MAXLEN 64
    crypto_generichash_state st;
    unsigned char in[MAXLEN], out[crypto_generichash_BYTES_MAX],
        k[crypto_generichash_KEYBYTES_MAX];
    size_t h, i, j;

    assert(crypto_generichash_statebytes() >= sizeof st);
    for (h = 0; h < crypto_generichash_KEYBYTES_MAX; ++h)
        k[h] = h;

    for (i = 0; i < MAXLEN; ++i) {
        in[i] = i;
        if (crypto_generichash_init(&st, k,
                                    1 + i % crypto_generichash_KEYBYTES_MAX,
                                    1 + i % crypto_generichash_BYTES_MAX) != 0) {
            printf("crypto_generichash_init()\n");
            return 1;
        }
        crypto_generichash_update(&st, in, i);
        crypto_generichash_update(&st, in, i);
        crypto_generichash_update(&st, in, i);
        crypto_generichash_final(&st, out,
                                 1 + i % crypto_generichash_BYTES_MAX);
        for (j = 0; j < 1 + i % crypto_generichash_BYTES_MAX; ++j) {
            printf("%02x", (unsigned int)out[j]);
        }
        printf("\n");
    }

    assert(crypto_generichash_init(&st, k, sizeof k, 0U) == -1);
    assert(crypto_generichash_init(&st, k, sizeof k,
                                   crypto_generichash_BYTES_MAX + 1U) == -1);
    assert(crypto_generichash_init(&st, k, crypto_generichash_KEYBYTES_MAX + 1U,
                                   sizeof out) == -1);
    assert(crypto_generichash_init(&st, k, 0U, sizeof out) == 0);
    assert(crypto_generichash_init(&st, k, 1U, sizeof out) == 0);
    assert(crypto_generichash_init(&st, NULL, 1U, 0U) == -1);
    assert(crypto_generichash_init(&st, NULL, crypto_generichash_KEYBYTES,
                                   1U) == 0);
    assert(crypto_generichash_init(&st, NULL, crypto_generichash_KEYBYTES,
                                   0U) == -1);
    return 0;
}

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rbnacl-libsodium-1.0.8 vendor/libsodium/test/default/generichash2.c
rbnacl-libsodium-1.0.7 vendor/libsodium/test/default/generichash2.c
rbnacl-libsodium-1.0.6 vendor/libsodium/test/default/generichash2.c
rbnacl-libsodium-1.0.5 vendor/libsodium/test/default/generichash2.c
rbnacl-libsodium-1.0.4 vendor/libsodium/test/default/generichash2.c