1 /* This file is in the public domain. */
6 #include <crypto/chacha20/chacha.h>
7 #include <opencrypto/xform_enc.h>
10 chacha20_xform_setkey(u_int8_t **sched, u_int8_t *key, int len)
12 struct chacha_ctx *ctx;
14 if (len != CHACHA_MINKEYLEN && len != 32)
17 ctx = malloc(sizeof(*ctx), M_CRYPTO_DATA, M_NOWAIT | M_ZERO);
22 chacha_keysetup(ctx, key, len * 8);
27 chacha20_xform_reinit(caddr_t key, u_int8_t *iv)
29 struct chacha_ctx *ctx;
32 chacha_ivsetup(ctx, iv + 8, iv);
36 chacha20_xform_zerokey(u_int8_t **sched)
38 struct chacha_ctx *ctx;
41 explicit_bzero(ctx, sizeof(*ctx));
42 free(ctx, M_CRYPTO_DATA);
47 chacha20_xform_crypt(caddr_t cctx, u_int8_t *bytes)
49 struct chacha_ctx *ctx;
52 chacha_encrypt_bytes(ctx, bytes, bytes, 1);
56 chacha20_xform_crypt_multi(void *vctx, uint8_t *bytes, size_t len)
58 struct chacha_ctx *ctx;
61 chacha_encrypt_bytes(ctx, bytes, bytes, len);
64 struct enc_xform enc_xform_chacha20 = {
65 .type = CRYPTO_CHACHA20,
68 .ivsize = CHACHA_NONCELEN + CHACHA_CTRLEN,
69 .minkey = CHACHA_MINKEYLEN,
71 .encrypt = chacha20_xform_crypt,
72 .decrypt = chacha20_xform_crypt,
73 .setkey = chacha20_xform_setkey,
74 .zerokey = chacha20_xform_zerokey,
75 .reinit = chacha20_xform_reinit,
76 .encrypt_multi = chacha20_xform_crypt_multi,
77 .decrypt_multi = chacha20_xform_crypt_multi,