From 91bd9d3334fb89fca4a857eaaa2c55b108f877a8 Mon Sep 17 00:00:00 2001 From: Mike Belopuhov Date: Wed, 17 May 2017 17:54:30 +0000 Subject: Revert MI AES-XTS code back to T-tables amid poor performance Suffered by many, the revert tested by stsp@. --- sys/crypto/aes.h | 2 ++ sys/crypto/xform.c | 17 +++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'sys/crypto') diff --git a/sys/crypto/aes.h b/sys/crypto/aes.h index a670a2b522c..9718115fc65 100644 --- a/sys/crypto/aes.h +++ b/sys/crypto/aes.h @@ -26,7 +26,9 @@ #ifndef _AES_H_ #define _AES_H_ +#ifndef AES_MAXROUNDS #define AES_MAXROUNDS (14) +#endif typedef struct aes_ctx { uint32_t sk[60]; diff --git a/sys/crypto/xform.c b/sys/crypto/xform.c index 0579345f4f1..71e173b44fd 100644 --- a/sys/crypto/xform.c +++ b/sys/crypto/xform.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xform.c,v 1.56 2017/05/02 11:44:32 mikeb Exp $ */ +/* $OpenBSD: xform.c,v 1.57 2017/05/17 17:54:29 mikeb Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr), @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -121,8 +122,8 @@ struct aes_ctr_ctx { #define AES_XTS_ALPHA 0x87 /* GF(2^128) generator polynomial */ struct aes_xts_ctx { - AES_CTX key1; - AES_CTX key2; + rijndael_ctx key1; + rijndael_ctx key2; u_int8_t tweak[AES_XTS_BLOCKSIZE]; }; @@ -496,7 +497,7 @@ aes_xts_reinit(caddr_t key, u_int8_t *iv) /* Last 64 bits of IV are always zero */ bzero(ctx->tweak + AES_XTS_IVSIZE, AES_XTS_IVSIZE); - AES_Encrypt(&ctx->key2, ctx->tweak, ctx->tweak); + rijndael_encrypt(&ctx->key2, ctx->tweak, ctx->tweak); } void @@ -509,9 +510,9 @@ aes_xts_crypt(struct aes_xts_ctx *ctx, u_int8_t *data, u_int do_encrypt) block[i] = data[i] ^ ctx->tweak[i]; if (do_encrypt) - AES_Encrypt(&ctx->key1, block, data); + rijndael_encrypt(&ctx->key1, block, data); else - AES_Decrypt(&ctx->key1, block, data); + rijndael_decrypt(&ctx->key1, block, data); for (i = 0; i < AES_XTS_BLOCKSIZE; i++) data[i] ^= ctx->tweak[i]; @@ -550,8 +551,8 @@ aes_xts_setkey(void *sched, u_int8_t *key, int len) ctx = (struct aes_xts_ctx *)sched; - AES_Setkey(&ctx->key1, key, len / 2); - AES_Setkey(&ctx->key2, key + (len / 2), len / 2); + rijndael_set_key(&ctx->key1, key, len * 4); + rijndael_set_key(&ctx->key2, key + (len / 2), len * 4); return 0; } -- cgit v1.2.3