Changeset View
Changeset View
Standalone View
Standalone View
head/sys/opencrypto/xform_rijndael.c
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <crypto/rijndael/rijndael.h> | #include <crypto/rijndael/rijndael.h> | ||||
#include <opencrypto/xform_enc.h> | #include <opencrypto/xform_enc.h> | ||||
static int rijndael128_setkey(u_int8_t **, const u_int8_t *, int); | static int rijndael128_setkey(void *, const u_int8_t *, int); | ||||
static void rijndael128_encrypt(caddr_t, u_int8_t *); | static void rijndael128_encrypt(void *, const uint8_t *, uint8_t *); | ||||
static void rijndael128_decrypt(caddr_t, u_int8_t *); | static void rijndael128_decrypt(void *, const uint8_t *, uint8_t *); | ||||
static void rijndael128_zerokey(u_int8_t **); | |||||
/* Encryption instances */ | /* Encryption instances */ | ||||
struct enc_xform enc_xform_rijndael128 = { | struct enc_xform enc_xform_rijndael128 = { | ||||
CRYPTO_RIJNDAEL128_CBC, "Rijndael-128/AES", | .type = CRYPTO_RIJNDAEL128_CBC, | ||||
RIJNDAEL128_BLOCK_LEN, RIJNDAEL128_BLOCK_LEN, RIJNDAEL_MIN_KEY, | .name = "Rijndael-128/AES", | ||||
RIJNDAEL_MAX_KEY, | .ctxsize = sizeof(rijndael_ctx), | ||||
rijndael128_encrypt, | .blocksize = RIJNDAEL128_BLOCK_LEN, | ||||
rijndael128_decrypt, | .ivsize = RIJNDAEL128_BLOCK_LEN, | ||||
rijndael128_setkey, | .minkey = RIJNDAEL_MIN_KEY, | ||||
rijndael128_zerokey, | .maxkey = RIJNDAEL_MAX_KEY, | ||||
NULL, | .encrypt = rijndael128_encrypt, | ||||
.decrypt = rijndael128_decrypt, | |||||
.setkey = rijndael128_setkey, | |||||
}; | }; | ||||
/* | /* | ||||
* Encryption wrapper routines. | * Encryption wrapper routines. | ||||
*/ | */ | ||||
static void | static void | ||||
rijndael128_encrypt(caddr_t key, u_int8_t *blk) | rijndael128_encrypt(void *key, const uint8_t *in, uint8_t *out) | ||||
{ | { | ||||
rijndael_encrypt((rijndael_ctx *) key, (u_char *) blk, (u_char *) blk); | rijndael_encrypt(key, in, out); | ||||
} | } | ||||
static void | static void | ||||
rijndael128_decrypt(caddr_t key, u_int8_t *blk) | rijndael128_decrypt(void *key, const uint8_t *in, uint8_t *out) | ||||
{ | { | ||||
rijndael_decrypt(((rijndael_ctx *) key), (u_char *) blk, | rijndael_decrypt(key, in, out); | ||||
(u_char *) blk); | |||||
} | } | ||||
static int | static int | ||||
rijndael128_setkey(u_int8_t **sched, const u_int8_t *key, int len) | rijndael128_setkey(void *sched, const uint8_t *key, int len) | ||||
{ | { | ||||
int err; | |||||
if (len != 16 && len != 24 && len != 32) | if (len != 16 && len != 24 && len != 32) | ||||
return (EINVAL); | return (EINVAL); | ||||
*sched = KMALLOC(sizeof(rijndael_ctx), M_CRYPTO_DATA, | |||||
M_NOWAIT|M_ZERO); | |||||
if (*sched != NULL) { | |||||
rijndael_set_key((rijndael_ctx *) *sched, key, | |||||
len * 8); | |||||
err = 0; | |||||
} else | |||||
err = ENOMEM; | |||||
return err; | |||||
} | |||||
static void | rijndael_set_key(sched, key, len * 8); | ||||
rijndael128_zerokey(u_int8_t **sched) | return (0); | ||||
{ | |||||
bzero(*sched, sizeof(rijndael_ctx)); | |||||
KFREE(*sched, M_CRYPTO_DATA); | |||||
*sched = NULL; | |||||
} | } |