Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src-draft/trunk]: src/sys/arch/x86 padlock(4): Convert legacy rijndael API t...
details: https://anonhg.NetBSD.org/src-all/rev/44881f84c525
branches: trunk
changeset: 934937:44881f84c525
user: Taylor R Campbell <riastradh%NetBSD.org@localhost>
date: Sun Jun 14 19:51:43 2020 +0000
description:
padlock(4): Convert legacy rijndael API to new aes API.
XXX Compile-tested only.
XXX The byte-order business here seems highly questionable.
diffstat:
sys/arch/x86/conf/files.x86 | 2 +-
sys/arch/x86/include/via_padlock.h | 8 ++++----
sys/arch/x86/x86/via_padlock.c | 27 ++++++++++++++++-----------
3 files changed, 21 insertions(+), 16 deletions(-)
diffs (111 lines):
diff -r 3e7c306a1ba3 -r 44881f84c525 sys/arch/x86/conf/files.x86
--- a/sys/arch/x86/conf/files.x86 Sun Jun 14 19:50:33 2020 +0000
+++ b/sys/arch/x86/conf/files.x86 Sun Jun 14 19:51:43 2020 +0000
@@ -59,7 +59,7 @@
attach odcm at cpufeaturebus
file arch/x86/x86/odcm.c odcm
-device padlock: opencrypto, rijndael
+device padlock: opencrypto, aes
attach padlock at cpufeaturebus
file arch/x86/x86/via_padlock.c padlock
diff -r 3e7c306a1ba3 -r 44881f84c525 sys/arch/x86/include/via_padlock.h
--- a/sys/arch/x86/include/via_padlock.h Sun Jun 14 19:50:33 2020 +0000
+++ b/sys/arch/x86/include/via_padlock.h Sun Jun 14 19:51:43 2020 +0000
@@ -25,7 +25,8 @@
#include <sys/rndsource.h>
#include <sys/callout.h>
-#include <crypto/rijndael/rijndael.h>
+
+#include <crypto/aes/aes.h>
/* VIA C3 xcrypt-* instruction context control options */
#define C3_CRYPT_CWLO_ROUND_M 0x0000000f
@@ -43,9 +44,8 @@
#define C3_CRYPT_CWLO_KEY256 0x0000080e /* 256bit, 15 rds */
struct via_padlock_session {
- uint32_t ses_ekey[4 * (RIJNDAEL_MAXNR + 1) + 4]; /* 128 bit aligned */
- uint32_t ses_dkey[4 * (RIJNDAEL_MAXNR + 1) + 4]; /* 128 bit aligned */
- uint8_t ses_iv[16]; /* 128 bit aligned */
+ struct aesenc ses_ekey;
+ struct aesdec ses_dkey;
uint32_t ses_cw0;
struct swcr_data *swd;
int ses_klen;
diff -r 3e7c306a1ba3 -r 44881f84c525 sys/arch/x86/x86/via_padlock.c
--- a/sys/arch/x86/x86/via_padlock.c Sun Jun 14 19:50:33 2020 +0000
+++ b/sys/arch/x86/x86/via_padlock.c Sun Jun 14 19:51:43 2020 +0000
@@ -37,10 +37,11 @@
#include <machine/cpufunc.h>
#include <machine/cpuvar.h>
+#include <crypto/aes/aes.h>
+
#include <opencrypto/cryptodev.h>
#include <opencrypto/cryptosoft.h>
#include <opencrypto/xform.h>
-#include <crypto/rijndael/rijndael.h>
#include <opencrypto/cryptosoft_xform.c>
@@ -176,12 +177,18 @@
case CRYPTO_AES_CBC:
switch (c->cri_klen) {
case 128:
+ aes_setenckey128(&ses->ses_ekey, c->cri_key);
+ aes_setdeckey128(&ses->ses_dkey, c->cri_key);
cw0 = C3_CRYPT_CWLO_KEY128;
break;
case 192:
+ aes_setenckey192(&ses->ses_ekey, c->cri_key);
+ aes_setdeckey192(&ses->ses_dkey, c->cri_key);
cw0 = C3_CRYPT_CWLO_KEY192;
break;
case 256:
+ aes_setenckey256(&ses->ses_ekey, c->cri_key);
+ aes_setdeckey256(&ses->ses_dkey, c->cri_key);
cw0 = C3_CRYPT_CWLO_KEY256;
break;
default:
@@ -194,14 +201,12 @@
ses->ses_klen = c->cri_klen;
ses->ses_cw0 = cw0;
- /* Build expanded keys for both directions */
- rijndaelKeySetupEnc(ses->ses_ekey, c->cri_key,
- c->cri_klen);
- rijndaelKeySetupDec(ses->ses_dkey, c->cri_key,
- c->cri_klen);
- for (i = 0; i < 4 * (RIJNDAEL_MAXNR + 1); i++) {
- ses->ses_ekey[i] = ntohl(ses->ses_ekey[i]);
- ses->ses_dkey[i] = ntohl(ses->ses_dkey[i]);
+ /* Convert words to host byte order (???) */
+ for (i = 0; i < 4 * (AES_256_NROUNDS + 1); i++) {
+ ses->ses_ekey.aese_aes.aes_rk[i] =
+ ntohl(ses->ses_ekey.aese_aes.aes_rk[i]);
+ ses->ses_dkey.aesd_aes.aes_rk[i] =
+ ntohl(ses->ses_dkey.aesd_aes.aes_rk[i]);
}
break;
@@ -379,7 +384,7 @@
if (crd->crd_flags & CRD_F_ENCRYPT) {
sc->op_cw[0] = ses->ses_cw0 | C3_CRYPT_CWLO_ENCRYPT;
- key = ses->ses_ekey;
+ key = ses->ses_ekey.aese_aes.aes_rk;
if (crd->crd_flags & CRD_F_IV_EXPLICIT)
memcpy(sc->op_iv, crd->crd_iv, 16);
else
@@ -398,7 +403,7 @@
}
} else {
sc->op_cw[0] = ses->ses_cw0 | C3_CRYPT_CWLO_DECRYPT;
- key = ses->ses_dkey;
+ key = ses->ses_dkey.aesd_aes.aes_rk;
if (crd->crd_flags & CRD_F_IV_EXPLICIT)
memcpy(sc->op_iv, crd->crd_iv, 16);
else {
Home |
Main Index |
Thread Index |
Old Index