The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/contrib/libsodium/test/default/generichash2.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 
    2 #define TEST_NAME "generichash2"
    3 #include "cmptest.h"
    4 
    5 int
    6 main(void)
    7 {
    8 #define MAXLEN 64
    9     crypto_generichash_state *st;
   10     unsigned char            in[MAXLEN];
   11     unsigned char            out[crypto_generichash_BYTES_MAX];
   12     unsigned char            k[crypto_generichash_KEYBYTES_MAX];
   13     size_t                   h, i, j;
   14 
   15     assert(crypto_generichash_statebytes() >= sizeof *st);
   16     st = (crypto_generichash_state *)
   17         sodium_malloc(crypto_generichash_statebytes());
   18     for (h = 0; h < crypto_generichash_KEYBYTES_MAX; ++h) {
   19         k[h] = (unsigned char) h;
   20     }
   21     for (i = 0; i < MAXLEN; ++i) {
   22         in[i] = (unsigned char) i;
   23         if (crypto_generichash_init(st, k,
   24                                     1 + i % crypto_generichash_KEYBYTES_MAX,
   25                                     1 + i % crypto_generichash_BYTES_MAX) != 0) {
   26             printf("crypto_generichash_init()\n");
   27             return 1;
   28         }
   29         crypto_generichash_update(st, in, i);
   30         crypto_generichash_update(st, in, i);
   31         crypto_generichash_update(st, in, i);
   32         if (crypto_generichash_final(st, out,
   33                                      1 + i % crypto_generichash_BYTES_MAX) != 0) {
   34             printf("crypto_generichash_final() should have returned 0\n");
   35         }
   36         for (j = 0; j < 1 + i % crypto_generichash_BYTES_MAX; ++j) {
   37             printf("%02x", (unsigned int) out[j]);
   38         }
   39         printf("\n");
   40         if (crypto_generichash_final(st, out,
   41                                      1 + i % crypto_generichash_BYTES_MAX) != -1) {
   42             printf("crypto_generichash_final() should have returned -1\n");
   43         }
   44     }
   45 
   46     assert(crypto_generichash_init(st, k, sizeof k, 0U) == -1);
   47     assert(crypto_generichash_init(st, k, sizeof k,
   48                                    crypto_generichash_BYTES_MAX + 1U) == -1);
   49     assert(crypto_generichash_init(st, k, crypto_generichash_KEYBYTES_MAX + 1U,
   50                                    sizeof out) == -1);
   51     assert(crypto_generichash_init(st, k, 0U, sizeof out) == 0);
   52     assert(crypto_generichash_init(st, k, 1U, sizeof out) == 0);
   53     assert(crypto_generichash_init(st, NULL, 1U, 0U) == -1);
   54     assert(crypto_generichash_init(st, NULL, crypto_generichash_KEYBYTES,
   55                                    1U) == 0);
   56     assert(crypto_generichash_init(st, NULL, crypto_generichash_KEYBYTES,
   57                                    0U) == -1);
   58 
   59     sodium_free(st);
   60 
   61     return 0;
   62 }

Cache object: 1ab03381f76a20e55829d58614a357e0


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.