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/secretbox7.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 "secretbox7"
    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 
   17     for (mlen = 0; mlen < 1000 && mlen + crypto_secretbox_ZEROBYTES < sizeof m;
   18          ++mlen) {
   19         crypto_secretbox_keygen(k);
   20         randombytes_buf(n, crypto_secretbox_NONCEBYTES);
   21         randombytes_buf(m + crypto_secretbox_ZEROBYTES, mlen);
   22         crypto_secretbox(c, m, mlen + crypto_secretbox_ZEROBYTES, n, k);
   23         if (crypto_secretbox_open(m2, c, mlen + crypto_secretbox_ZEROBYTES, n,
   24                                   k) == 0) {
   25             for (i = 0; i < mlen + crypto_secretbox_ZEROBYTES; ++i) {
   26                 if (m2[i] != m[i]) {
   27                     printf("bad decryption\n");
   28                     break;
   29                 }
   30             }
   31         } else {
   32             printf("ciphertext fails verification\n");
   33         }
   34     }
   35     return 0;
   36 }

Cache object: 7749b595b5450389780c49f2f252906a


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