diff options
author | John Baldwin <jhb@FreeBSD.org> | 2020-05-20 21:21:01 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2020-05-20 21:21:01 +0000 |
commit | 3e9470482a1357eef90d007b27ec5d9725ae1111 (patch) | |
tree | db3cd1b049da8705d5f9328628e9ee7b8d9d9549 /sys/crypto | |
parent | 2aa1dc7e3b637876f4bfdc6b19c35253d922e10a (diff) | |
download | src-3e9470482a1357eef90d007b27ec5d9725ae1111.tar.gz src-3e9470482a1357eef90d007b27ec5d9725ae1111.zip |
Various cleanups to the software encryption transform interface.
- Consistently use 'void *' for key schedules / key contexts instead
of a mix of 'caddr_t', 'uint8_t *', and 'void *'.
- Add a ctxsize member to enc_xform similar to what auth transforms use
and require callers to malloc/zfree the context. The setkey callback
now supplies the caller-allocated context pointer and the zerokey
callback is removed. Callers now always use zfree() to ensure
key contexts are zeroed.
- Consistently use C99 initializers for all statically-initialized
instances of 'struct enc_xform'.
- Change the encrypt and decrypt functions to accept separate in and
out buffer pointers. Almost all of the backend crypto functions
already supported separate input and output buffers and this makes
it simpler to support separate buffers in OCF.
- Remove xform_userland.h shim to permit transforms to be compiled in
userland. Transforms no longer call malloc/free directly.
Reviewed by: cem (earlier version)
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D24855
Notes
Notes:
svn path=/head/; revision=361298
Diffstat (limited to 'sys/crypto')
-rw-r--r-- | sys/crypto/chacha20/chacha-sw.c | 38 |
1 files changed, 8 insertions, 30 deletions
diff --git a/sys/crypto/chacha20/chacha-sw.c b/sys/crypto/chacha20/chacha-sw.c index d9a0b70252c3..bb78f0b5d4a0 100644 --- a/sys/crypto/chacha20/chacha-sw.c +++ b/sys/crypto/chacha20/chacha-sw.c @@ -7,63 +7,42 @@ __FBSDID("$FreeBSD$"); #include <opencrypto/xform_enc.h> static int -chacha20_xform_setkey(u_int8_t **sched, const u_int8_t *key, int len) +chacha20_xform_setkey(void *ctx, const uint8_t *key, int len) { - struct chacha_ctx *ctx; if (len != CHACHA_MINKEYLEN && len != 32) return (EINVAL); - ctx = malloc(sizeof(*ctx), M_CRYPTO_DATA, M_NOWAIT | M_ZERO); - *sched = (void *)ctx; - if (ctx == NULL) - return (ENOMEM); - chacha_keysetup(ctx, key, len * 8); return (0); } static void -chacha20_xform_reinit(caddr_t key, const u_int8_t *iv) +chacha20_xform_reinit(void *ctx, const u_int8_t *iv) { - struct chacha_ctx *ctx; - ctx = (void *)key; chacha_ivsetup(ctx, iv + 8, iv); } static void -chacha20_xform_zerokey(u_int8_t **sched) -{ - struct chacha_ctx *ctx; - - ctx = (void *)*sched; - explicit_bzero(ctx, sizeof(*ctx)); - free(ctx, M_CRYPTO_DATA); - *sched = NULL; -} - -static void -chacha20_xform_crypt(caddr_t cctx, u_int8_t *bytes) +chacha20_xform_crypt(void *ctx, const uint8_t *in, uint8_t *out) { - struct chacha_ctx *ctx; - ctx = (void *)cctx; - chacha_encrypt_bytes(ctx, bytes, bytes, 1); + chacha_encrypt_bytes(ctx, in, out, 1); } static void -chacha20_xform_crypt_multi(void *vctx, uint8_t *bytes, size_t len) +chacha20_xform_crypt_multi(void *ctx, const uint8_t *in, uint8_t *out, + size_t len) { - struct chacha_ctx *ctx; - ctx = vctx; - chacha_encrypt_bytes(ctx, bytes, bytes, len); + chacha_encrypt_bytes(ctx, in, out, len); } struct enc_xform enc_xform_chacha20 = { .type = CRYPTO_CHACHA20, .name = "chacha20", + .ctxsize = sizeof(struct chacha_ctx), .blocksize = 1, .ivsize = CHACHA_NONCELEN + CHACHA_CTRLEN, .minkey = CHACHA_MINKEYLEN, @@ -71,7 +50,6 @@ struct enc_xform enc_xform_chacha20 = { .encrypt = chacha20_xform_crypt, .decrypt = chacha20_xform_crypt, .setkey = chacha20_xform_setkey, - .zerokey = chacha20_xform_zerokey, .reinit = chacha20_xform_reinit, .encrypt_multi = chacha20_xform_crypt_multi, .decrypt_multi = chacha20_xform_crypt_multi, |