Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys simplify rijndael.c API - always schedule encrypt/decryp...



details:   https://anonhg.NetBSD.org/src/rev/e2e0eccc5c96
branches:  trunk
changeset: 551015:e2e0eccc5c96
user:      itojun <itojun%NetBSD.org@localhost>
date:      Wed Aug 27 14:23:25 2003 +0000

description:
simplify rijndael.c API - always schedule encrypt/decrypt key.
reviewed by thorpej

diffstat:

 sys/crypto/rijndael/rijndael.c |  18 ++++--------------
 sys/crypto/rijndael/rijndael.h |   4 ++--
 sys/netinet6/esp_rijndael.c    |  18 +++++++-----------
 sys/opencrypto/xform.c         |  10 ++++------
 4 files changed, 17 insertions(+), 33 deletions(-)

diffs (165 lines):

diff -r a7cb6658cc0f -r e2e0eccc5c96 sys/crypto/rijndael/rijndael.c
--- a/sys/crypto/rijndael/rijndael.c    Wed Aug 27 14:21:51 2003 +0000
+++ b/sys/crypto/rijndael/rijndael.c    Wed Aug 27 14:23:25 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rijndael.c,v 1.5 2003/08/27 03:35:35 itojun Exp $      */
+/*     $NetBSD: rijndael.c,v 1.6 2003/08/27 14:23:27 itojun Exp $      */
 
 /**             
  * rijndael-alg-fst.c 
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rijndael.c,v 1.5 2003/08/27 03:35:35 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rijndael.c,v 1.6 2003/08/27 14:23:27 itojun Exp $");
 
 #include <sys/types.h>
 #include <sys/systm.h>
@@ -35,25 +35,17 @@
 #include <crypto/rijndael/rijndael.h>
 
 void
-rijndael_set_key(rijndael_ctx *ctx, const u_char *key, int bits, int encrypt)
+rijndael_set_key(rijndael_ctx *ctx, const u_char *key, int bits)
 {
 
        ctx->Nr = rijndaelKeySetupEnc(ctx->ek, key, bits);
-       if (encrypt) {
-               ctx->decrypt = 0;
-               memset(ctx->dk, 0, sizeof(ctx->dk));
-       } else {
-               ctx->decrypt = 1;
-               rijndaelKeySetupDec(ctx->dk, key, bits);
-       }
+       rijndaelKeySetupDec(ctx->dk, key, bits);
 }
 
 void
 rijndael_decrypt(const rijndael_ctx *ctx, const u_char *src, u_char *dst)
 {
 
-       if (!ctx->decrypt)
-               panic("rijndael_decrypt: encryption context is passed");
        rijndaelDecrypt(ctx->dk, ctx->Nr, src, dst);
 }
 
@@ -61,7 +53,5 @@
 rijndael_encrypt(const rijndael_ctx *ctx, const u_char *src, u_char *dst)
 {
 
-       if (ctx->decrypt)
-               panic("rijndael_encrypt: decryption context is passed");
        rijndaelEncrypt(ctx->ek, ctx->Nr, src, dst);
 }
diff -r a7cb6658cc0f -r e2e0eccc5c96 sys/crypto/rijndael/rijndael.h
--- a/sys/crypto/rijndael/rijndael.h    Wed Aug 27 14:21:51 2003 +0000
+++ b/sys/crypto/rijndael/rijndael.h    Wed Aug 27 14:23:25 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rijndael.h,v 1.7 2003/08/26 20:07:59 thorpej Exp $     */
+/*     $NetBSD: rijndael.h,v 1.8 2003/08/27 14:23:27 itojun Exp $      */
 /*     $KAME: rijndael.h,v 1.3 2003/07/15 10:47:16 itojun Exp $        */
 
 /**
@@ -40,7 +40,7 @@
        uint32_t dk[4 * (RIJNDAEL_MAXNR + 1)];  /* decrypt key schedule */
 } rijndael_ctx;
 
-void   rijndael_set_key(rijndael_ctx *, const u_char *, int, int);
+void   rijndael_set_key(rijndael_ctx *, const u_char *, int);
 void   rijndael_decrypt(const rijndael_ctx *, const u_char *, u_char *);
 void   rijndael_encrypt(const rijndael_ctx *, const u_char *, u_char *);
 
diff -r a7cb6658cc0f -r e2e0eccc5c96 sys/netinet6/esp_rijndael.c
--- a/sys/netinet6/esp_rijndael.c       Wed Aug 27 14:21:51 2003 +0000
+++ b/sys/netinet6/esp_rijndael.c       Wed Aug 27 14:23:25 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: esp_rijndael.c,v 1.16 2003/08/27 02:42:09 itojun Exp $ */
+/*     $NetBSD: esp_rijndael.c,v 1.17 2003/08/27 14:23:25 itojun Exp $ */
 /*     $KAME: esp_rijndael.c,v 1.4 2001/03/02 05:53:05 itojun Exp $    */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: esp_rijndael.c,v 1.16 2003/08/27 02:42:09 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: esp_rijndael.c,v 1.17 2003/08/27 14:23:25 itojun Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -55,7 +55,7 @@
        const struct esp_algorithm *algo;
 {
 
-       return sizeof(rijndael_ctx) * 2;
+       return sizeof(rijndael_ctx);
 }
 
 int
@@ -66,12 +66,8 @@
        rijndael_ctx *ctx;
 
        ctx = (rijndael_ctx *)sav->sched;
-       /* decryption schedule */
-       rijndael_set_key(&ctx[0],
-           (u_char *)_KEYBUF(sav->key_enc), _KEYLEN(sav->key_enc) * 8, 0);
-       /* encryption schedule */
-       rijndael_set_key(&ctx[1],
-           (u_char *)_KEYBUF(sav->key_enc), _KEYLEN(sav->key_enc) * 8, 1);
+       rijndael_set_key(ctx,
+           (u_char *)_KEYBUF(sav->key_enc), _KEYLEN(sav->key_enc) * 8);
        return 0;
 }
 
@@ -85,7 +81,7 @@
        rijndael_ctx *ctx;
 
        ctx = (rijndael_ctx *)sav->sched;
-       rijndael_decrypt(&ctx[0], s, d);
+       rijndael_decrypt(ctx, s, d);
        return 0;
 }
 
@@ -99,6 +95,6 @@
        rijndael_ctx *ctx;
 
        ctx = (rijndael_ctx *)sav->sched;
-       rijndael_encrypt(&ctx[1], s, d);
+       rijndael_encrypt(ctx, s, d);
        return 0;
 }
diff -r a7cb6658cc0f -r e2e0eccc5c96 sys/opencrypto/xform.c
--- a/sys/opencrypto/xform.c    Wed Aug 27 14:21:51 2003 +0000
+++ b/sys/opencrypto/xform.c    Wed Aug 27 14:23:25 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xform.c,v 1.9 2003/08/27 00:20:56 thorpej Exp $ */
+/*     $NetBSD: xform.c,v 1.10 2003/08/27 14:23:28 itojun Exp $ */
 /*     $FreeBSD: src/sys/opencrypto/xform.c,v 1.1.2.1 2002/11/21 23:34:23 sam Exp $    */
 /*     $OpenBSD: xform.c,v 1.19 2002/08/16 22:47:25 dhartmei Exp $     */
 
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xform.c,v 1.9 2003/08/27 00:20:56 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xform.c,v 1.10 2003/08/27 14:23:28 itojun Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -549,13 +549,11 @@
 {
        int err;
 
-       MALLOC(*sched, u_int8_t *, 2 * sizeof(rijndael_ctx), M_CRYPTO_DATA,
+       MALLOC(*sched, u_int8_t *, sizeof(rijndael_ctx), M_CRYPTO_DATA,
            M_WAITOK);
        if (*sched != NULL) {
                bzero(*sched, 2 * sizeof(rijndael_ctx));
-               rijndael_set_key((rijndael_ctx *) *sched, (u_char *) key, len * 8, 1);
-               rijndael_set_key(((rijndael_ctx *) *sched) + 1, (u_char *) key,
-                   len * 8, 0);
+               rijndael_set_key((rijndael_ctx *) *sched, (u_char *) key, len * 8);
                err = 0;
        } else
                err = ENOMEM;



Home | Main Index | Thread Index | Old Index