aboutsummaryrefslogtreecommitdiff
path: root/sys/opencrypto
diff options
context:
space:
mode:
authorConrad Meyer <cem@FreeBSD.org>2018-03-29 04:02:50 +0000
committerConrad Meyer <cem@FreeBSD.org>2018-03-29 04:02:50 +0000
commit61590291a8be2f70a88cc0d5411f19d6093824e2 (patch)
treece62a99025af2c4f05195b1b2ed689f1bb05d221 /sys/opencrypto
parente5818a53dbd212809059bb306775a4b7e0e30c5f (diff)
Notes
Diffstat (limited to 'sys/opencrypto')
-rw-r--r--sys/opencrypto/cryptodev.c3
-rw-r--r--sys/opencrypto/cryptodev.h6
-rw-r--r--sys/opencrypto/cryptosoft.c6
-rw-r--r--sys/opencrypto/xform_enc.h3
4 files changed, 15 insertions, 3 deletions
diff --git a/sys/opencrypto/cryptodev.c b/sys/opencrypto/cryptodev.c
index 58e15212cdb7..984344492271 100644
--- a/sys/opencrypto/cryptodev.c
+++ b/sys/opencrypto/cryptodev.c
@@ -443,6 +443,9 @@ cryptof_ioctl(
case CRYPTO_AES_NIST_GCM_16:
txform = &enc_xform_aes_nist_gcm;
break;
+ case CRYPTO_CHACHA20:
+ txform = &enc_xform_chacha20;
+ break;
default:
CRYPTDEB("invalid cipher");
diff --git a/sys/opencrypto/cryptodev.h b/sys/opencrypto/cryptodev.h
index eea1a00c50b8..654225410fe9 100644
--- a/sys/opencrypto/cryptodev.h
+++ b/sys/opencrypto/cryptodev.h
@@ -112,7 +112,8 @@
#define AES_ICM_BLOCK_LEN 1
#define ARC4_BLOCK_LEN 1
#define CAMELLIA_BLOCK_LEN 16
-#define EALG_MAX_BLOCK_LEN AES_BLOCK_LEN /* Keep this updated */
+#define CHACHA20_NATIVE_BLOCK_LEN 64
+#define EALG_MAX_BLOCK_LEN CHACHA20_NATIVE_BLOCK_LEN /* Keep this updated */
/* IV Lengths */
@@ -180,7 +181,8 @@
#define CRYPTO_AES_256_NIST_GMAC 28 /* auth side */
#define CRYPTO_BLAKE2B 29 /* Blake2b hash */
#define CRYPTO_BLAKE2S 30 /* Blake2s hash */
-#define CRYPTO_ALGORITHM_MAX 30 /* Keep updated - see below */
+#define CRYPTO_CHACHA20 31 /* Chacha20 stream cipher */
+#define CRYPTO_ALGORITHM_MAX 31 /* Keep updated - see below */
#define CRYPTO_ALGO_VALID(x) ((x) >= CRYPTO_ALGORITHM_MIN && \
(x) <= CRYPTO_ALGORITHM_MAX)
diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c
index 6974015200de..f85f63e92a7c 100644
--- a/sys/opencrypto/cryptosoft.c
+++ b/sys/opencrypto/cryptosoft.c
@@ -830,6 +830,9 @@ swcr_newsession(device_t dev, u_int32_t *sid, struct cryptoini *cri)
case CRYPTO_NULL_CBC:
txf = &enc_xform_null;
goto enccommon;
+ case CRYPTO_CHACHA20:
+ txf = &enc_xform_chacha20;
+ goto enccommon;
enccommon:
if (cri->cri_key != NULL) {
error = txf->setkey(&((*swd)->sw_kschedule),
@@ -1056,6 +1059,7 @@ swcr_freesession_locked(device_t dev, u_int64_t tid)
case CRYPTO_AES_NIST_GMAC:
case CRYPTO_CAMELLIA_CBC:
case CRYPTO_NULL_CBC:
+ case CRYPTO_CHACHA20:
txf = swd->sw_exf;
if (swd->sw_kschedule)
@@ -1185,6 +1189,7 @@ swcr_process(device_t dev, struct cryptop *crp, int hint)
case CRYPTO_AES_XTS:
case CRYPTO_AES_ICM:
case CRYPTO_CAMELLIA_CBC:
+ case CRYPTO_CHACHA20:
if ((crp->crp_etype = swcr_encdec(crd, sw,
crp->crp_buf, crp->crp_flags)) != 0)
goto done;
@@ -1298,6 +1303,7 @@ swcr_attach(device_t dev)
REGISTER(CRYPTO_DEFLATE_COMP);
REGISTER(CRYPTO_BLAKE2B);
REGISTER(CRYPTO_BLAKE2S);
+ REGISTER(CRYPTO_CHACHA20);
#undef REGISTER
return 0;
diff --git a/sys/opencrypto/xform_enc.h b/sys/opencrypto/xform_enc.h
index dc49c7f4c4ee..545e0ec25497 100644
--- a/sys/opencrypto/xform_enc.h
+++ b/sys/opencrypto/xform_enc.h
@@ -51,7 +51,7 @@
struct enc_xform {
int type;
char *name;
- u_int16_t blocksize;
+ u_int16_t blocksize; /* Required input block size -- 1 for stream ciphers. */
u_int16_t ivsize;
u_int16_t minkey, maxkey;
void (*encrypt) (caddr_t, u_int8_t *);
@@ -83,6 +83,7 @@ extern struct enc_xform enc_xform_aes_nist_gmac;
extern struct enc_xform enc_xform_aes_xts;
extern struct enc_xform enc_xform_arc4;
extern struct enc_xform enc_xform_camellia;
+extern struct enc_xform enc_xform_chacha20;
struct aes_icm_ctx {
u_int32_t ac_ek[4*(RIJNDAEL_MAXNR + 1)];