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/box7.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 "box7"
    3 #include "cmptest.h"
    4 
    5 static unsigned char alicesk[crypto_box_SECRETKEYBYTES];
    6 static unsigned char alicepk[crypto_box_PUBLICKEYBYTES];
    7 static unsigned char bobsk[crypto_box_SECRETKEYBYTES];
    8 static unsigned char bobpk[crypto_box_PUBLICKEYBYTES];
    9 static unsigned char n[crypto_box_NONCEBYTES];
   10 
   11 int
   12 main(void)
   13 {
   14     unsigned char *m;
   15     unsigned char *c;
   16     unsigned char *m2;
   17     size_t         mlen;
   18     size_t         mlen_max = 1000;
   19     size_t         i;
   20     int            ret;
   21 
   22     m  = (unsigned char *) sodium_malloc(mlen_max);
   23     c  = (unsigned char *) sodium_malloc(mlen_max);
   24     m2 = (unsigned char *) sodium_malloc(mlen_max);
   25     memset(m, 0, crypto_box_ZEROBYTES);
   26     crypto_box_keypair(alicepk, alicesk);
   27     crypto_box_keypair(bobpk, bobsk);
   28     for (mlen = 0; mlen + crypto_box_ZEROBYTES <= mlen_max; mlen++) {
   29         randombytes_buf(n, crypto_box_NONCEBYTES);
   30         randombytes_buf(m + crypto_box_ZEROBYTES, mlen);
   31         ret = crypto_box(c, m, mlen + crypto_box_ZEROBYTES, n, bobpk, alicesk);
   32         assert(ret == 0);
   33         if (crypto_box_open(m2, c, mlen + crypto_box_ZEROBYTES, n, alicepk,
   34                             bobsk) == 0) {
   35             for (i = 0; i < mlen + crypto_box_ZEROBYTES; ++i) {
   36                 if (m2[i] != m[i]) {
   37                     printf("bad decryption\n");
   38                     break;
   39                 }
   40             }
   41         } else {
   42             printf("ciphertext fails verification\n");
   43         }
   44     }
   45     sodium_free(m);
   46     sodium_free(c);
   47     sodium_free(m2);
   48 
   49     return 0;
   50 }

Cache object: 8a08cf30a5bcf696c1abf2912e96e9ed


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