Changeset View
Changeset View
Standalone View
Standalone View
head/sys/crypto/chacha20/chacha-sw.c
/* This file is in the public domain. */ | /* This file is in the public domain. */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <crypto/chacha20/chacha.h> | #include <crypto/chacha20/chacha.h> | ||||
#include <opencrypto/xform_enc.h> | #include <opencrypto/xform_enc.h> | ||||
static int | static int | ||||
chacha20_xform_setkey(u_int8_t **sched, u_int8_t *key, int len) | chacha20_xform_setkey(u_int8_t **sched, const u_int8_t *key, int len) | ||||
{ | { | ||||
struct chacha_ctx *ctx; | struct chacha_ctx *ctx; | ||||
if (len != CHACHA_MINKEYLEN && len != 32) | if (len != CHACHA_MINKEYLEN && len != 32) | ||||
return (EINVAL); | return (EINVAL); | ||||
ctx = malloc(sizeof(*ctx), M_CRYPTO_DATA, M_NOWAIT | M_ZERO); | ctx = malloc(sizeof(*ctx), M_CRYPTO_DATA, M_NOWAIT | M_ZERO); | ||||
*sched = (void *)ctx; | *sched = (void *)ctx; | ||||
if (ctx == NULL) | if (ctx == NULL) | ||||
return (ENOMEM); | return (ENOMEM); | ||||
chacha_keysetup(ctx, key, len * 8); | chacha_keysetup(ctx, key, len * 8); | ||||
return (0); | return (0); | ||||
} | } | ||||
static void | static void | ||||
chacha20_xform_reinit(caddr_t key, u_int8_t *iv) | chacha20_xform_reinit(caddr_t key, const u_int8_t *iv) | ||||
{ | { | ||||
struct chacha_ctx *ctx; | struct chacha_ctx *ctx; | ||||
ctx = (void *)key; | ctx = (void *)key; | ||||
chacha_ivsetup(ctx, iv + 8, iv); | chacha_ivsetup(ctx, iv + 8, iv); | ||||
} | } | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 43 Lines • Show Last 20 Lines |