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/opencrypto/xform_cml.c | |
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/opencrypto/xform_cml.c')
-rw-r--r-- | sys/opencrypto/xform_cml.c | 55 |
1 files changed, 20 insertions, 35 deletions
diff --git a/sys/opencrypto/xform_cml.c b/sys/opencrypto/xform_cml.c index 2f857fe6a39d..3f25f2cb6aaf 100644 --- a/sys/opencrypto/xform_cml.c +++ b/sys/opencrypto/xform_cml.c @@ -53,61 +53,46 @@ __FBSDID("$FreeBSD$"); #include <crypto/camellia/camellia.h> #include <opencrypto/xform_enc.h> -static int cml_setkey(u_int8_t **, const u_int8_t *, int); -static void cml_encrypt(caddr_t, u_int8_t *); -static void cml_decrypt(caddr_t, u_int8_t *); -static void cml_zerokey(u_int8_t **); +static int cml_setkey(void *, const uint8_t *, int); +static void cml_encrypt(void *, const uint8_t *, uint8_t *); +static void cml_decrypt(void *, const uint8_t *, uint8_t *); /* Encryption instances */ struct enc_xform enc_xform_camellia = { - CRYPTO_CAMELLIA_CBC, "Camellia", - CAMELLIA_BLOCK_LEN, CAMELLIA_BLOCK_LEN, CAMELLIA_MIN_KEY, - CAMELLIA_MAX_KEY, - cml_encrypt, - cml_decrypt, - cml_setkey, - cml_zerokey, - NULL, + .type = CRYPTO_CAMELLIA_CBC, + .name = "Camellia-CBC", + .ctxsize = sizeof(camellia_ctx), + .blocksize = CAMELLIA_BLOCK_LEN, + .ivsize = CAMELLIA_BLOCK_LEN, + .minkey = CAMELLIA_MIN_KEY, + .maxkey = CAMELLIA_MAX_KEY, + .encrypt = cml_encrypt, + .decrypt = cml_decrypt, + .setkey = cml_setkey, }; /* * Encryption wrapper routines. */ static void -cml_encrypt(caddr_t key, u_int8_t *blk) +cml_encrypt(void *ctx, const uint8_t *in, uint8_t *out) { - camellia_encrypt((camellia_ctx *) key, (u_char *) blk, (u_char *) blk); + camellia_encrypt(ctx, in, out); } static void -cml_decrypt(caddr_t key, u_int8_t *blk) +cml_decrypt(void *ctx, const uint8_t *in, uint8_t *out) { - camellia_decrypt(((camellia_ctx *) key), (u_char *) blk, - (u_char *) blk); + camellia_decrypt(ctx, in, out); } static int -cml_setkey(u_int8_t **sched, const u_int8_t *key, int len) +cml_setkey(void *ctx, const uint8_t *key, int len) { - int err; if (len != 16 && len != 24 && len != 32) return (EINVAL); - *sched = KMALLOC(sizeof(camellia_ctx), M_CRYPTO_DATA, - M_NOWAIT|M_ZERO); - if (*sched != NULL) { - camellia_set_key((camellia_ctx *) *sched, key, - len * 8); - err = 0; - } else - err = ENOMEM; - return err; -} -static void -cml_zerokey(u_int8_t **sched) -{ - bzero(*sched, sizeof(camellia_ctx)); - KFREE(*sched, M_CRYPTO_DATA); - *sched = NULL; + camellia_set_key(ctx, key, len * 8); + return (0); } |