Add functions des_set_key_checked, des_set_key_unchecked.
authorBodo Möller <bodo@openssl.org>
Fri, 3 Dec 1999 20:24:21 +0000 (20:24 +0000)
committerBodo Möller <bodo@openssl.org>
Fri, 3 Dec 1999 20:24:21 +0000 (20:24 +0000)
Never use des_set_key (it depends on the global variable des_check_key),
but usually des_set_key_unchecked.
Only destest.c bothered to look at the return values of des_set_key,
but it did not set des_check_key -- if it had done so,
most checks would have failed because of wrong parity and
because of weak keys.

21 files changed:
CHANGES
apps/speed.c
crypto/des/des.c
crypto/des/des.h
crypto/des/des_opts.c
crypto/des/destest.c
crypto/des/fcrypt.c
crypto/des/rand_key.c
crypto/des/rpc_enc.c
crypto/des/set_key.c
crypto/des/speed.c
crypto/des/str2key.c
crypto/evp/e_cbc_3d.c
crypto/evp/e_cfb_3d.c
crypto/evp/e_cfb_d.c
crypto/evp/e_ecb_3d.c
crypto/evp/e_ecb_d.c
crypto/evp/e_ofb_3d.c
crypto/evp/e_ofb_d.c
crypto/evp/e_xcbc_d.c
crypto/mdc2/mdc2dgst.c

diff --git a/CHANGES b/CHANGES
index 5dcd6d8..247d65a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,14 @@
 
  Changes between 0.9.4 and 0.9.5  [xx XXX 1999]
 
+  *) Add variants des_set_key_checked and des_set_key_unchecked of
+     des_set_key (aka des_key_sched).  Global variable des_check_key
+     decides which of these is called by des_set_key; this way
+     des_check_key behaves as it always did, but applications and
+     the library itself, which was buggy for des_check_key == 1,
+     have a cleaner way to pick the version they need.
+     [Bodo Moeller]
+
   *) New function PKCS12_newpass() which changes the password of a
      PKCS12 structure.
      [Steve Henson]
index 779ee03..caf47e2 100644 (file)
@@ -590,9 +590,9 @@ int MAIN(int argc, char **argv)
 #endif
 
 #ifndef NO_DES
-       des_set_key(&key,sch);
-       des_set_key(&key2,sch2);
-       des_set_key(&key3,sch3);
+       des_set_key_unchecked(&key,sch);
+       des_set_key_unchecked(&key2,sch2);
+       des_set_key_unchecked(&key3,sch3);
 #endif
 #ifndef NO_IDEA
        idea_set_encrypt_key(key16,&idea_ks);
index 206e377..5cd3373 100644 (file)
@@ -425,7 +425,7 @@ void doencryption(void)
                        else
                                k2[i-8]=k;
                        }
-               des_set_key(&k2,ks2);
+               des_set_key_unchecked(&k2,ks2);
                memset(k2,0,sizeof(k2));
                }
        else if (longk || flag3)
@@ -433,7 +433,7 @@ void doencryption(void)
                if (flag3)
                        {
                        des_string_to_2keys(key,&kk,&k2);
-                       des_set_key(&k2,ks2);
+                       des_set_key_unchecked(&k2,ks2);
                        memset(k2,0,sizeof(k2));
                        }
                else
@@ -455,7 +455,7 @@ void doencryption(void)
                                kk[i]=key[i]|0x80;
                        }
 
-       des_set_key(&kk,ks);
+       des_set_key_unchecked(&kk,ks);
        memset(key,0,sizeof(key));
        memset(kk,0,sizeof(kk));
        /* woops - A bug that does not showup under unix :-( */
index 67f90aa..b492002 100644 (file)
@@ -193,8 +193,13 @@ int des_read_2passwords(des_cblock *key1,des_cblock *key2,
 int des_read_pw_string(char *buf,int length,const char *prompt,int verify);
 void des_set_odd_parity(des_cblock *key);
 int des_is_weak_key(const_des_cblock *key);
+/* des_set_key (= set_key = des_key_sched = key_sched) calls
+ * des_set_key_checked if global variable des_check_key is set,
+ * des_set_key_unchecked otherwise. */
 int des_set_key(const_des_cblock *key,des_key_schedule schedule);
 int des_key_sched(const_des_cblock *key,des_key_schedule schedule);
+int des_set_key_checked(const_des_cblock *key,des_key_schedule schedule);
+void des_set_key_unchecked(const_des_cblock *key,des_key_schedule schedule);
 void des_string_to_key(const char *str,des_cblock *key);
 void des_string_to_2keys(const char *str,des_cblock *key1,des_cblock *key2);
 void des_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
index 746c456..545075c 100644 (file)
@@ -438,13 +438,13 @@ int main(int argc, char **argv)
        fprintf(stderr,"program when this computer is idle.\n");
 #endif
 
-       des_set_key(&key,sch);
-       des_set_key(&key2,sch2);
-       des_set_key(&key3,sch3);
+       des_set_key_unchecked(&key,sch);
+       des_set_key_unchecked(&key2,sch2);
+       des_set_key_unchecked(&key3,sch3);
 
 #ifndef SIGALRM
        fprintf(stderr,"First we calculate the approximate speed ...\n");
-       des_set_key(&key,sch);
+       des_set_key_unchecked(&key,sch);
        count=10;
        do      {
                long i;
index 69155ed..7efd83d 100644 (file)
@@ -234,7 +234,8 @@ static unsigned char cipher_ecb2[NUM_TESTS-1][8]={
        {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}};
 
 static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
-static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
+/* static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; */
+static unsigned char cbc2_key[8]={0xf1,0xe0,0xd3,0xc2,0xb5,0xa4,0x97,0x86};
 static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
 static unsigned char cbc_iv  [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
 /* Changed the following text constant to binary so it will work on ebcdic
@@ -331,17 +332,17 @@ int main(int argc, char *argv[])
 
 #ifndef NO_DESCBCM
        printf("Doing cbcm\n");
-       if ((j=des_key_sched(&cbc_key,ks)) != 0)
+       if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
                {
                printf("Key error %d\n",j);
                err=1;
                }
-       if ((j=des_key_sched(&cbc2_key,ks2)) != 0)
+       if ((j=des_set_key_checked(&cbc2_key,ks2)) != 0)
                {
                printf("Key error %d\n",j);
                err=1;
                }
-       if ((j=des_key_sched(&cbc3_key,ks3)) != 0)
+       if ((j=des_set_key_checked(&cbc3_key,ks3)) != 0)
                {
                printf("Key error %d\n",j);
                err=1;
@@ -385,11 +386,7 @@ int main(int argc, char *argv[])
        printf("Doing ecb\n");
        for (i=0; i<NUM_TESTS; i++)
                {
-               if ((j=des_key_sched(&key_data[i],ks)) != 0)
-                       {
-                       printf("Key error %2d:%d\n",i+1,j);
-                       err=1;
-                       }
+               des_set_key_unchecked(&key_data[i],ks);
                memcpy(in,plain_data[i],8);
                memset(out,0,8);
                memset(outin,0,8);
@@ -415,21 +412,9 @@ int main(int argc, char *argv[])
        printf("Doing ede ecb\n");
        for (i=0; i<(NUM_TESTS-1); i++)
                {
-               if ((j=des_key_sched(&key_data[i],ks)) != 0)
-                       {
-                       err=1;
-                       printf("Key error %2d:%d\n",i+1,j);
-                       }
-               if ((j=des_key_sched(&key_data[i+1],ks2)) != 0)
-                       {
-                       printf("Key error %2d:%d\n",i+2,j);
-                       err=1;
-                       }
-               if ((j=des_key_sched(&key_data[i+2],ks3)) != 0)
-                       {
-                       printf("Key error %2d:%d\n",i+3,j);
-                       err=1;
-                       }
+               des_set_key_unchecked(&key_data[i],ks);
+               des_set_key_unchecked(&key_data[i+1],ks2);
+               des_set_key_unchecked(&key_data[i+2],ks3);
                memcpy(in,plain_data[i],8);
                memset(out,0,8);
                memset(outin,0,8);
@@ -453,7 +438,7 @@ int main(int argc, char *argv[])
 #endif
 
        printf("Doing cbc\n");
-       if ((j=des_key_sched(&cbc_key,ks)) != 0)
+       if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
                {
                printf("Key error %d\n",j);
                err=1;
@@ -477,7 +462,7 @@ int main(int argc, char *argv[])
 
 #ifndef LIBDES_LIT
        printf("Doing desx cbc\n");
-       if ((j=des_key_sched(&cbc_key,ks)) != 0)
+       if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
                {
                printf("Key error %d\n",j);
                err=1;
@@ -502,17 +487,17 @@ int main(int argc, char *argv[])
 #endif
 
        printf("Doing ede cbc\n");
-       if ((j=des_key_sched(&cbc_key,ks)) != 0)
+       if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
                {
                printf("Key error %d\n",j);
                err=1;
                }
-       if ((j=des_key_sched(&cbc2_key,ks2)) != 0)
+       if ((j=des_set_key_checked(&cbc2_key,ks2)) != 0)
                {
                printf("Key error %d\n",j);
                err=1;
                }
-       if ((j=des_key_sched(&cbc3_key,ks3)) != 0)
+       if ((j=des_set_key_checked(&cbc3_key,ks3)) != 0)
                {
                printf("Key error %d\n",j);
                err=1;
@@ -543,7 +528,7 @@ int main(int argc, char *argv[])
 
 #ifndef LIBDES_LIT
        printf("Doing pcbc\n");
-       if ((j=des_key_sched(&cbc_key,ks)) != 0)
+       if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
                {
                printf("Key error %d\n",j);
                err=1;
@@ -606,7 +591,7 @@ int main(int argc, char *argv[])
        printf("done\n");
 
        printf("Doing ofb\n");
-       des_key_sched(&ofb_key,ks);
+       des_set_key_checked(&ofb_key,ks);
        memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
        des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp);
        if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
@@ -635,7 +620,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
                }
 
        printf("Doing ofb64\n");
-       des_key_sched(&ofb_key,ks);
+       des_set_key_checked(&ofb_key,ks);
        memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
        memset(ofb_buf1,0,sizeof(ofb_buf1));
        memset(ofb_buf2,0,sizeof(ofb_buf1));
@@ -660,7 +645,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
                }
 
        printf("Doing ede_ofb64\n");
-       des_key_sched(&ofb_key,ks);
+       des_set_key_checked(&ofb_key,ks);
        memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
        memset(ofb_buf1,0,sizeof(ofb_buf1));
        memset(ofb_buf2,0,sizeof(ofb_buf1));
@@ -686,7 +671,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
                }
 
        printf("Doing cbc_cksum\n");
-       des_key_sched(&cbc_key,ks);
+       des_set_key_checked(&cbc_key,ks);
        cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv);
        if (cs != cbc_cksum_ret)
                {
@@ -825,7 +810,7 @@ static int cfb_test(int bits, unsigned char *cfb_cipher)
        des_key_schedule ks;
        int i,err=0;
 
-       des_key_sched(&cfb_key,ks);
+       des_set_key_checked(&cfb_key,ks);
        memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
        des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp,
                        DES_ENCRYPT);
@@ -854,7 +839,7 @@ static int cfb64_test(unsigned char *cfb_cipher)
        des_key_schedule ks;
        int err=0,i,n;
 
-       des_key_sched(&cfb_key,ks);
+       des_set_key_checked(&cfb_key,ks);
        memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
        n=0;
        des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT);
@@ -887,7 +872,7 @@ static int ede_cfb64_test(unsigned char *cfb_cipher)
        des_key_schedule ks;
        int err=0,i,n;
 
-       des_key_sched(&cfb_key,ks);
+       des_set_key_checked(&cfb_key,ks);
        memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
        n=0;
        des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n,
index b59855c..889715a 100644 (file)
@@ -151,7 +151,7 @@ r=(r+7)/8;
        for (; i<8; i++)
                key[i]=0;
 
-       des_set_key(&key,ks);
+       des_set_key_unchecked(&key,ks);
        fcrypt_body(&(out[0]),ks,Eswap0,Eswap1);
 
        ll=out[0]; l2c(ll,b);
index fc11792..2032c59 100644 (file)
@@ -100,11 +100,11 @@ void des_random_key(des_cblock *ret)
        l2c(t,p);
 
        des_set_odd_parity(&data);
-       des_set_key(&data,ks);
+       des_set_key_unchecked(&data,ks);
        des_cbc_cksum(key,&key,sizeof(key),ks,&data);
 
        des_set_odd_parity(&key);
-       des_set_key(&key,ks);
+       des_set_key_unchecked(&key,ks);
        des_cbc_cksum(key,&data,sizeof(key),ks,&key);
 
        memcpy(ret,data,sizeof(key));
index c96c204..32d96d5 100644 (file)
@@ -66,7 +66,7 @@ int _des_crypt(char *buf, int len, struct desparams *desp)
        des_key_schedule ks;
        int enc;
 
-       des_set_key(&desp->des_key,ks);
+       des_set_key_unchecked(&desp->des_key,ks);
        enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT;
 
        if (desp->des_mode == CBC)
index 52553a4..eb64bd5 100644 (file)
@@ -145,11 +145,34 @@ int des_is_weak_key(const_des_cblock *key)
 #define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
        (a)=(a)^(t)^(t>>(16-(n))))
 
+int des_set_key(const_des_cblock *key, des_key_schedule schedule)
+       {
+       if (des_check_key)
+               {
+               return des_set_key_checked(key, schedule);
+               }
+       else
+               {
+               des_set_key_unchecked(key, schedule);
+               return 0;
+               }
+       }
+
 /* return 0 if key parity is odd (correct),
  * return -1 if key parity error,
  * return -2 if illegal weak key.
  */
-int des_set_key(const_des_cblock *key, des_key_schedule schedule)
+int des_set_key_checked(const_des_cblock *key, des_key_schedule schedule)
+       {
+       if (!check_parity(key))
+               return(-1);
+       if (des_is_weak_key(key))
+               return(-2);
+       des_set_key_unchecked(key, schedule);
+       return 0;
+       }
+
+void des_set_key_unchecked(const_des_cblock *key, des_key_schedule schedule)
        {
        static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
        register DES_LONG c,d,t,s,t2;
@@ -157,15 +180,6 @@ int des_set_key(const_des_cblock *key, des_key_schedule schedule)
        register DES_LONG *k;
        register int i;
 
-       if (des_check_key)
-               {
-               if (!check_parity(key))
-                       return(-1);
-
-               if (des_is_weak_key(key))
-                       return(-2);
-               }
-
        k = &schedule->ks.deslong[0];
        in = &(*key)[0];
 
@@ -225,7 +239,6 @@ int des_set_key(const_des_cblock *key, des_key_schedule schedule)
                t2=((s>>16L)|(t&0xffff0000L));
                *(k++)=ROTATE(t2,26)&0xffffffffL;
                }
-       return(0);
        }
 
 int des_key_sched(const_des_cblock *key, des_key_schedule schedule)
index da41abc..652cf5b 100644 (file)
@@ -190,12 +190,12 @@ int main(int argc, char **argv)
        printf("program when this computer is idle.\n");
 #endif
 
-       des_set_key(&key2,sch2);
-       des_set_key(&key3,sch3);
+       des_set_key_unchecked(&key2,sch2);
+       des_set_key_unchecked(&key3,sch3);
 
 #ifndef SIGALRM
        printf("First we calculate the approximate speed ...\n");
-       des_set_key(&key,sch);
+       des_set_key_unchecked(&key,sch);
        count=10;
        do      {
                long i;
@@ -225,7 +225,7 @@ int main(int argc, char **argv)
 
        Time_F(START);
        for (count=0,run=1; COND(ca); count++)
-               des_set_key(&key,sch);
+               des_set_key_unchecked(&key,sch);
        d=Time_F(STOP);
        printf("%ld set_key's in %.2f seconds\n",count,d);
        a=((double)COUNT(ca))/d;
index 2484145..5522824 100644 (file)
@@ -58,8 +58,6 @@
 
 #include "des_locl.h"
 
-OPENSSL_EXTERN int des_check_key;
-
 void des_string_to_key(const char *str, des_cblock *key)
        {
        des_key_schedule ks;
@@ -88,10 +86,7 @@ void des_string_to_key(const char *str, des_cblock *key)
                }
 #endif
        des_set_odd_parity(key);
-       i=des_check_key;
-       des_check_key=0;
-       des_set_key(key,ks);
-       des_check_key=i;
+       des_set_key_unchecked(key,ks);
        des_cbc_cksum((unsigned char*)str,key,length,ks,key);
        memset(ks,0,sizeof(ks));
        des_set_odd_parity(key);
@@ -150,13 +145,10 @@ void des_string_to_2keys(const char *str, des_cblock *key1, des_cblock *key2)
 #endif
        des_set_odd_parity(key1);
        des_set_odd_parity(key2);
-       i=des_check_key;
-       des_check_key=0;
-       des_set_key(key1,ks);
+       des_set_key_unchecked(key1,ks);
        des_cbc_cksum((unsigned char*)str,key1,length,ks,key1);
-       des_set_key(key2,ks);
+       des_set_key_unchecked(key2,ks);
        des_cbc_cksum((unsigned char*)str,key2,length,ks,key2);
-       des_check_key=i;
        memset(ks,0,sizeof(ks));
        des_set_odd_parity(key1);
        des_set_odd_parity(key2);
index 02ccc6d..5d16b86 100644 (file)
@@ -115,8 +115,8 @@ static void des_cbc_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
 
        if (deskey != NULL)
                {
-               des_set_key(&deskey[0],ctx->c.des_ede.ks1);
-               des_set_key(&deskey[1],ctx->c.des_ede.ks2);
+               des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+               des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
                memcpy( (char *)ctx->c.des_ede.ks3,
                        (char *)ctx->c.des_ede.ks1,
                        sizeof(ctx->c.des_ede.ks1));
@@ -134,9 +134,9 @@ static void des_cbc_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
 
        if (deskey != NULL)
                {
-               des_set_key(&deskey[0],ctx->c.des_ede.ks1);
-               des_set_key(&deskey[1],ctx->c.des_ede.ks2);
-               des_set_key(&deskey[2],ctx->c.des_ede.ks3);
+               des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+               des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
+               des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
                }
        }
 
index bd32b07..b364bd4 100644 (file)
@@ -116,8 +116,8 @@ static void des_ede_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
        memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
        if (deskey != NULL)
                {
-               des_set_key(&deskey[0],ctx->c.des_ede.ks1);
-               des_set_key(&deskey[1],ctx->c.des_ede.ks2);
+               des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+               des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
                memcpy( (char *)ctx->c.des_ede.ks3,
                        (char *)ctx->c.des_ede.ks1,
                        sizeof(ctx->c.des_ede.ks1));
@@ -136,9 +136,9 @@ static void des_ede3_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
        memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
        if (deskey != NULL)
                {
-               des_set_key(&deskey[0],ctx->c.des_ede.ks1);
-               des_set_key(&deskey[1],ctx->c.des_ede.ks2);
-               des_set_key(&deskey[2],ctx->c.des_ede.ks3);
+               des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+               des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
+               des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
                }
        }
 
index 6bdf20b..9e1714b 100644 (file)
@@ -95,7 +95,7 @@ static void des_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
                memcpy(&(ctx->oiv[0]),iv,8);
        memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
        if (deskey != NULL)
-               des_set_key(deskey,ctx->c.des_ks);
+               des_set_key_unchecked(deskey,ctx->c.des_ks);
        }
 
 static void des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
index 354a8b7..806e971 100644 (file)
@@ -110,8 +110,8 @@ static void des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
 
        if (deskey != NULL)
                {
-               des_set_key(&deskey[0],ctx->c.des_ede.ks1);
-               des_set_key(&deskey[1],ctx->c.des_ede.ks2);
+               des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+               des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
                memcpy( (char *)ctx->c.des_ede.ks3,
                        (char *)ctx->c.des_ede.ks1,
                        sizeof(ctx->c.des_ede.ks1));
@@ -125,9 +125,9 @@ static void des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
 
        if (deskey != NULL)
                {
-               des_set_key(&deskey[0],ctx->c.des_ede.ks1);
-               des_set_key(&deskey[1],ctx->c.des_ede.ks2);
-               des_set_key(&deskey[2],ctx->c.des_ede.ks3);
+               des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+               des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
+               des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
                }
        }
 
index 5fb4e64..c11bef5 100644 (file)
@@ -90,7 +90,7 @@ static void des_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
        des_cblock *deskey = (des_cblock *)key;
 
        if (deskey != NULL)
-               des_set_key(deskey,ctx->c.des_ks);
+               des_set_key_unchecked(deskey,ctx->c.des_ks);
        }
 
 static void des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
index 5233567..d1a33e2 100644 (file)
@@ -116,8 +116,8 @@ static void des_ede_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
        memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
        if (deskey != NULL)
                {
-               des_set_key(&deskey[0],ctx->c.des_ede.ks1);
-               des_set_key(&deskey[1],ctx->c.des_ede.ks2);
+               des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+               des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
                memcpy( (char *)ctx->c.des_ede.ks3,
                        (char *)ctx->c.des_ede.ks1,
                        sizeof(ctx->c.des_ede.ks1));
@@ -136,9 +136,9 @@ static void des_ede3_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
        memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
        if (deskey != NULL)
                {
-               des_set_key(&deskey[0],ctx->c.des_ede.ks1);
-               des_set_key(&deskey[1],ctx->c.des_ede.ks2);
-               des_set_key(&deskey[2],ctx->c.des_ede.ks3);
+               des_set_key_unchecked(&deskey[0],ctx->c.des_ede.ks1);
+               des_set_key_unchecked(&deskey[1],ctx->c.des_ede.ks2);
+               des_set_key_unchecked(&deskey[2],ctx->c.des_ede.ks3);
                }
        }
 
index 398b3a0..d51ce23 100644 (file)
@@ -95,7 +95,7 @@ static void des_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
                memcpy(&(ctx->oiv[0]),iv,8);
        memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
        if (deskey != NULL)
-               des_set_key(deskey,ctx->c.des_ks);
+               des_set_key_unchecked(deskey,ctx->c.des_ks);
        }
 
 static void des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
index 3a6628a..7568fad 100644 (file)
@@ -94,7 +94,7 @@ static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
        memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
        if (deskey != NULL)
                {
-               des_set_key(deskey,ctx->c.desx_cbc.ks);
+               des_set_key_unchecked(deskey,ctx->c.desx_cbc.ks);
                memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8);
                memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8);
                }
index 4fc39ed..aed715c 100644 (file)
@@ -135,11 +135,11 @@ static void mdc2_body(MDC2_CTX *c, unsigned char *in, unsigned int len)
                c->hh[0]=(c->hh[0]&0x9f)|0x20;
 
                des_set_odd_parity(&c->h);
-               des_set_key(&c->h,k);
+               des_set_key_unchecked(&c->h,k);
                des_encrypt(d,k,1);
 
                des_set_odd_parity(&c->hh);
-               des_set_key(&c->hh,k);
+               des_set_key_unchecked(&c->hh,k);
                des_encrypt(dd,k,1);
 
                ttin0=tin0^dd[0];