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/crypto/chacha20/chacha-sw.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 /* This file is in the public domain. */
    2 
    3 #include <sys/cdefs.h>
    4 __FBSDID("$FreeBSD$");
    5 
    6 #include <crypto/chacha20/chacha.h>
    7 #include <opencrypto/xform_enc.h>
    8 
    9 static int
   10 chacha20_xform_setkey(void *ctx, const uint8_t *key, int len)
   11 {
   12 
   13         if (len != CHACHA_MINKEYLEN && len != 32)
   14                 return (EINVAL);
   15 
   16         chacha_keysetup(ctx, key, len * 8);
   17         return (0);
   18 }
   19 
   20 static void
   21 chacha20_xform_reinit(void *ctx, const uint8_t *iv, size_t ivlen)
   22 {
   23         KASSERT(ivlen == CHACHA_NONCELEN + CHACHA_CTRLEN,
   24             ("%s: invalid IV length", __func__));
   25         chacha_ivsetup(ctx, iv + 8, iv);
   26 }
   27 
   28 static void
   29 chacha20_xform_crypt(void *ctx, const uint8_t *in, uint8_t *out)
   30 {
   31 
   32         chacha_encrypt_bytes(ctx, in, out, CHACHA_BLOCKLEN);
   33 }
   34 
   35 static void
   36 chacha20_xform_crypt_multi(void *ctx, const uint8_t *in, uint8_t *out,
   37     size_t len)
   38 {
   39         KASSERT(len % CHACHA_BLOCKLEN == 0, ("%s: invalid length", __func__));
   40         chacha_encrypt_bytes(ctx, in, out, len);
   41 }
   42 
   43 static void
   44 chacha20_xform_crypt_last(void *ctx, const uint8_t *in, uint8_t *out,
   45     size_t len)
   46 {
   47 
   48         chacha_encrypt_bytes(ctx, in, out, len);
   49 }
   50 
   51 const struct enc_xform enc_xform_chacha20 = {
   52         .type = CRYPTO_CHACHA20,
   53         .name = "chacha20",
   54         .ctxsize = sizeof(struct chacha_ctx),
   55         .blocksize = 1,
   56         .native_blocksize = CHACHA_BLOCKLEN,
   57         .ivsize = CHACHA_NONCELEN + CHACHA_CTRLEN,
   58         .minkey = CHACHA_MINKEYLEN,
   59         .maxkey = 32,
   60         .setkey = chacha20_xform_setkey,
   61         .reinit = chacha20_xform_reinit,
   62         .encrypt = chacha20_xform_crypt,
   63         .decrypt = chacha20_xform_crypt,
   64         .encrypt_multi = chacha20_xform_crypt_multi,
   65         .decrypt_multi = chacha20_xform_crypt_multi,
   66         .encrypt_last = chacha20_xform_crypt_last,
   67         .decrypt_last = chacha20_xform_crypt_last,
   68 };

Cache object: 85cf9f30af3c7dc6141fdfeb1a983cb4


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