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/box_seal.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 "box_seal"
    3 #include "cmptest.h"
    4 
    5 int
    6 main(void)
    7 {
    8     unsigned char  pk[crypto_box_PUBLICKEYBYTES];
    9     unsigned char  sk[crypto_box_SECRETKEYBYTES];
   10     unsigned char *c;
   11     unsigned char *m;
   12     unsigned char *m2;
   13     size_t         m_len;
   14     size_t         c_len;
   15 
   16     crypto_box_keypair(pk, sk);
   17     m_len = (size_t) randombytes_uniform(1000);
   18     c_len = crypto_box_SEALBYTES + m_len;
   19     m     = (unsigned char *) sodium_malloc(m_len);
   20     m2    = (unsigned char *) sodium_malloc(m_len);
   21     c     = (unsigned char *) sodium_malloc(c_len);
   22     randombytes_buf(m, m_len);
   23     if (crypto_box_seal(c, m, m_len, pk) != 0) {
   24         printf("crypto_box_seal() failure\n");
   25         return 1;
   26     }
   27     if (crypto_box_seal_open(m2, c, c_len, pk, sk) != 0) {
   28         printf("crypto_box_seal_open() failure\n");
   29         return 1;
   30     }
   31     printf("%d\n", memcmp(m, m2, m_len));
   32 
   33     printf("%d\n", crypto_box_seal_open(m, c, 0U, pk, sk));
   34     printf("%d\n", crypto_box_seal_open(m, c, c_len - 1U, pk, sk));
   35     printf("%d\n", crypto_box_seal_open(m, c, c_len, sk, pk));
   36 
   37     sodium_free(c);
   38     sodium_free(m);
   39     sodium_free(m2);
   40 
   41     assert(crypto_box_sealbytes() == crypto_box_SEALBYTES);
   42 
   43     return 0;
   44 }

Cache object: 9ceb7fa8904997b745db90afafdfe03d


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