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/secretbox8.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 "secretbox8"
    3 #include "cmptest.h"
    4 
    5 static unsigned char k[crypto_secretbox_KEYBYTES];
    6 static unsigned char n[crypto_secretbox_NONCEBYTES];
    7 static unsigned char m[10000];
    8 static unsigned char c[10000];
    9 static unsigned char m2[10000];
   10 
   11 int
   12 main(void)
   13 {
   14     size_t mlen;
   15     size_t i;
   16     int    caught;
   17 
   18     for (mlen = 0; mlen < 1000 && mlen + crypto_secretbox_ZEROBYTES < sizeof m;
   19          ++mlen) {
   20         crypto_secretbox_keygen(k);
   21         randombytes_buf(n, crypto_secretbox_NONCEBYTES);
   22         randombytes_buf(m + crypto_secretbox_ZEROBYTES, mlen);
   23         crypto_secretbox(c, m, mlen + crypto_secretbox_ZEROBYTES, n, k);
   24         caught = 0;
   25         while (caught < 10) {
   26             c[rand() % (mlen + crypto_secretbox_ZEROBYTES)] = rand();
   27             if (crypto_secretbox_open(m2, c, mlen + crypto_secretbox_ZEROBYTES,
   28                                       n, k) == 0) {
   29                 for (i = 0; i < mlen + crypto_secretbox_ZEROBYTES; ++i) {
   30                     if (m2[i] != m[i]) {
   31                         printf("forgery\n");
   32                         return 100;
   33                     }
   34                 }
   35             } else {
   36                 ++caught;
   37             }
   38         }
   39     }
   40     return 0;
   41 }

Cache object: a3c533b49e7c76b962b1877b76f2ac7e


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