tech-crypto archive

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

Re: opencrypto and rijndael/AES



>>      true.  i'm not 100% sure what is the intent of the author of
>>      rijndael_set_key().  we could simplify it to always setup key for
>>      both dir... where did the code come from?
>sys/opencrypto -- so, openbsd, I guess.

        as a simplification we could always schedule both.  what do you think?

itojun


Index: netinet6/esp_rijndael.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/esp_rijndael.c,v
retrieving revision 1.16
diff -u -r1.16 esp_rijndael.c
--- netinet6/esp_rijndael.c     2003/08/27 02:42:09     1.16
+++ netinet6/esp_rijndael.c     2003/08/27 07:38:48
@@ -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;
 }
Index: crypto/rijndael/rijndael.c
===================================================================
RCS file: /cvsroot/src/sys/crypto/rijndael/rijndael.c,v
retrieving revision 1.5
diff -u -r1.5 rijndael.c
--- crypto/rijndael/rijndael.c  2003/08/27 03:35:35     1.5
+++ crypto/rijndael/rijndael.c  2003/08/27 07:38:49
@@ -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);
 }
Index: crypto/rijndael/rijndael.h
===================================================================
RCS file: /cvsroot/src/sys/crypto/rijndael/rijndael.h,v
retrieving revision 1.7
diff -u -r1.7 rijndael.h
--- crypto/rijndael/rijndael.h  2003/08/26 20:07:59     1.7
+++ crypto/rijndael/rijndael.h  2003/08/27 07:38:49
@@ -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 *);
 
Index: opencrypto/xform.c
===================================================================
RCS file: /cvsroot/src/sys/opencrypto/xform.c,v
retrieving revision 1.9
diff -u -r1.9 xform.c
--- opencrypto/xform.c  2003/08/27 00:20:56     1.9
+++ opencrypto/xform.c  2003/08/27 07:38:49
@@ -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