Source-Changes-HG archive

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

[src/trunk]: src/sys pass key to rijndael logic as binary, not hexadecimal st...



details:   https://anonhg.NetBSD.org/src/rev/008088fa431a
branches:  trunk
changeset: 504436:008088fa431a
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Mar 02 15:42:39 2001 +0000

description:
pass key to rijndael logic as binary, not hexadecimal string.
sync with kame

diffstat:

 sys/crypto/rijndael/rijndael-api-fst.c |  45 +--------------------------------
 sys/netinet6/esp_rijndael.c            |  25 +++---------------
 2 files changed, 6 insertions(+), 64 deletions(-)

diffs (114 lines):

diff -r e92c1617696d -r 008088fa431a sys/crypto/rijndael/rijndael-api-fst.c
--- a/sys/crypto/rijndael/rijndael-api-fst.c    Fri Mar 02 10:27:00 2001 +0000
+++ b/sys/crypto/rijndael/rijndael-api-fst.c    Fri Mar 02 15:42:39 2001 +0000
@@ -1,5 +1,5 @@
-/*     $NetBSD: rijndael-api-fst.c,v 1.4 2000/11/06 14:11:41 itojun Exp $      */
-/*     $KAME: rijndael-api-fst.c,v 1.7 2000/11/06 13:58:09 itojun Exp $        */
+/*     $NetBSD: rijndael-api-fst.c,v 1.5 2001/03/02 15:42:39 itojun Exp $      */
+/*     $KAME: rijndael-api-fst.c,v 1.8 2001/03/02 05:53:05 itojun Exp $        */
 
 /*
  * rijndael-api-fst.c   v2.3   April '2000
@@ -56,29 +56,9 @@
 
        /* initialize key schedule: */
        keyMat = key->keyMaterial;
-#ifndef BINARY_KEY_MATERIAL
-       for (i = 0; i < key->keyLen/8; i++) {
-               int t, j;
-
-               t = *keyMat++;
-               if ((t >= '0') && (t <= '9')) j = (t - '0') << 4;
-               else if ((t >= 'a') && (t <= 'f')) j = (t - 'a' + 10) << 4; 
-               else if ((t >= 'A') && (t <= 'F')) j = (t - 'A' + 10) << 4; 
-               else return BAD_KEY_MAT;
-               
-               t = *keyMat++;
-               if ((t >= '0') && (t <= '9')) j ^= (t - '0');
-               else if ((t >= 'a') && (t <= 'f')) j ^= (t - 'a' + 10); 
-               else if ((t >= 'A') && (t <= 'F')) j ^= (t - 'A' + 10); 
-               else return BAD_KEY_MAT;
-               
-               k[i >> 2][i & 3] = (word8)j; 
-       }
-#else
        for (i = 0; i < key->keyLen/8; i++) {
                k[i >> 2][i & 3] = (word8)keyMat[i]; 
        }
-#endif /* ?BINARY_KEY_MATERIAL */
        rijndaelKeySched(k, key->keySched, key->ROUNDS);
        if (direction == DIR_DECRYPT) {
                rijndaelKeyEncToDec(key->keySched, key->ROUNDS);
@@ -94,28 +74,7 @@
                return BAD_CIPHER_MODE;
        }
        if (IV != NULL) {
-#ifndef BINARY_KEY_MATERIAL
-               int i;
-               for (i = 0; i < MAX_IV_SIZE; i++) {
-                       int t, j;
-
-                       t = IV[2*i];
-                       if ((t >= '0') && (t <= '9')) j = (t - '0') << 4;
-                       else if ((t >= 'a') && (t <= 'f')) j = (t - 'a' + 10) << 4; 
-                       else if ((t >= 'A') && (t <= 'F')) j = (t - 'A' + 10) << 4; 
-                       else return BAD_CIPHER_INSTANCE;
-               
-                       t = IV[2*i+1];
-                       if ((t >= '0') && (t <= '9')) j ^= (t - '0');
-                       else if ((t >= 'a') && (t <= 'f')) j ^= (t - 'a' + 10); 
-                       else if ((t >= 'A') && (t <= 'F')) j ^= (t - 'A' + 10); 
-                       else return BAD_CIPHER_INSTANCE;
-                       
-                       cipher->IV[i] = (word8)j;
-               }
-#else
                bcopy(IV, cipher->IV, MAX_IV_SIZE);
-#endif /* ?BINARY_KEY_MATERIAL */
        } else {
                bzero(cipher->IV, MAX_IV_SIZE);
        }
diff -r e92c1617696d -r 008088fa431a sys/netinet6/esp_rijndael.c
--- a/sys/netinet6/esp_rijndael.c       Fri Mar 02 10:27:00 2001 +0000
+++ b/sys/netinet6/esp_rijndael.c       Fri Mar 02 15:42:39 2001 +0000
@@ -1,5 +1,5 @@
-/*     $NetBSD: esp_rijndael.c,v 1.3 2000/11/08 04:57:57 itojun Exp $  */
-/*     $KAME: esp_rijndael.c,v 1.3 2000/11/08 04:54:52 itojun Exp $    */
+/*     $NetBSD: esp_rijndael.c,v 1.4 2001/03/02 15:42:40 itojun Exp $  */
+/*     $KAME: esp_rijndael.c,v 1.4 2001/03/02 05:53:05 itojun Exp $    */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -63,30 +63,13 @@
        struct secasvar *sav;
 {
        keyInstance *k;
-       char keymat[256 / 4 + 1];
-       u_char *p, *ep;
-       char *q, *eq;
-
-       /* rijndael_makeKey wants hex string for the key */
-       if (_KEYLEN(sav->key_enc) * 2 > sizeof(keymat) - 1)
-               return -1;
-       p = _KEYBUF(sav->key_enc); 
-       ep = p + _KEYLEN(sav->key_enc);
-       q = keymat;
-       eq = &keymat[sizeof(keymat) - 1];
-       while (p < ep && q < eq) {
-               sprintf(q, "%02x", *p);
-               q += 2;
-               p++;
-       }
-       *eq = '\0';
 
        k = (keyInstance *)sav->sched;
        if (rijndael_makeKey(&k[0], DIR_DECRYPT, _KEYLEN(sav->key_enc) * 8,
-           keymat) < 0)
+           _KEYBUF(sav->key_enc)) < 0)
                return -1;
        if (rijndael_makeKey(&k[1], DIR_ENCRYPT, _KEYLEN(sav->key_enc) * 8,
-           keymat) < 0)
+           _KEYBUF(sav->key_enc)) < 0)
                return -1;
        return 0;
 }



Home | Main Index | Thread Index | Old Index