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/verify1.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 "verify1"
    3 #include "cmptest.h"
    4 
    5 int
    6 main(void)
    7 {
    8     unsigned char *v16, *v16x;
    9     unsigned char *v32, *v32x;
   10     unsigned char *v64, *v64x;
   11     uint32_t       r;
   12     uint8_t        o;
   13     int            i;
   14 
   15     v16  = (unsigned char *) sodium_malloc(16);
   16     v16x = (unsigned char *) sodium_malloc(16);
   17     v32  = (unsigned char *) sodium_malloc(32);
   18     v32x = (unsigned char *) sodium_malloc(32);
   19     v64  = (unsigned char *) sodium_malloc(64);
   20     v64x = (unsigned char *) sodium_malloc(64);
   21     for (i = 0; i < 10000; i++) {
   22         randombytes_buf(v16, 16);
   23         randombytes_buf(v32, 32);
   24         randombytes_buf(v64, 64);
   25 
   26         memcpy(v16x, v16, 16);
   27         memcpy(v32x, v32, 32);
   28         memcpy(v64x, v64, 64);
   29 
   30         if (crypto_verify_16(v16, v16x) != 0 ||
   31             crypto_verify_32(v32, v32x) != 0 ||
   32             crypto_verify_64(v64, v64x) != 0 ||
   33             sodium_memcmp(v16, v16x, 16) != 0 ||
   34             sodium_memcmp(v32, v32x, 32) != 0 ||
   35             sodium_memcmp(v64, v64x, 64) != 0) {
   36             printf("Failed\n");
   37         }
   38     }
   39     printf("OK\n");
   40 
   41     for (i = 0; i < 100000; i++) {
   42         r = randombytes_random();
   43         o = (uint8_t) randombytes_random();
   44         if (o == 0) {
   45             continue;
   46         }
   47         v16x[r & 15U] ^= o;
   48         v32x[r & 31U] ^= o;
   49         v64x[r & 63U] ^= o;
   50         if (crypto_verify_16(v16, v16x) != -1 ||
   51             crypto_verify_32(v32, v32x) != -1 ||
   52             crypto_verify_64(v64, v64x) != -1 ||
   53             sodium_memcmp(v16, v16x, 16) != -1 ||
   54             sodium_memcmp(v32, v32x, 32) != -1 ||
   55             sodium_memcmp(v64, v64x, 64) != -1) {
   56             printf("Failed\n");
   57         }
   58         v16x[r & 15U] ^= o;
   59         v32x[r & 31U] ^= o;
   60         v64x[r & 63U] ^= o;
   61     }
   62     printf("OK\n");
   63 
   64     assert(crypto_verify_16_bytes() == 16U);
   65     assert(crypto_verify_32_bytes() == 32U);
   66     assert(crypto_verify_64_bytes() == 64U);
   67 
   68     sodium_free(v16);
   69     sodium_free(v16x);
   70     sodium_free(v32);
   71     sodium_free(v32x);
   72     sodium_free(v64);
   73     sodium_free(v64x);
   74 
   75     return 0;
   76 }

Cache object: 72141400ae79f1f935fb7bf2cd3ec319


[ 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.