*/
#include "des_locl.h"
-OPENSSL_GLOBAL int des_check_key=0;
+OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key,0) /* defaults to false */
static const unsigned char odd_parity[256]={
1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239,
241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254};
-void des_set_odd_parity(des_cblock *key)
+void DES_set_odd_parity(DES_cblock *key)
{
- int i;
+ unsigned int i;
for (i=0; i<DES_KEY_SZ; i++)
(*key)[i]=odd_parity[(*key)[i]];
}
-int des_check_key_parity(const_des_cblock *key)
+int DES_check_key_parity(const_DES_cblock *key)
{
- int i;
+ unsigned int i;
for (i=0; i<DES_KEY_SZ; i++)
{
* (and actual cblock values).
*/
#define NUM_WEAK_KEY 16
-static des_cblock weak_keys[NUM_WEAK_KEY]={
+static const DES_cblock weak_keys[NUM_WEAK_KEY]={
/* weak keys */
{0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
{0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
{0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
{0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
-int des_is_weak_key(const_des_cblock *key)
+int DES_is_weak_key(const_DES_cblock *key)
{
int i;
* eay 93/06/29
* Another problem, I was comparing only the first 4
* bytes, 97/03/18 */
- if (memcmp(weak_keys[i],key,sizeof(des_cblock)) == 0) return(1);
+ if (memcmp(weak_keys[i],key,sizeof(DES_cblock)) == 0) return(1);
return(0);
}
0x00002822L,0x04002822L,0x00042822L,0x04042822L,
}};
-int des_set_key(const_des_cblock *key, des_key_schedule schedule)
+int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule)
{
- if (des_check_key)
+ if (DES_check_key)
{
- return des_set_key_checked(key, schedule);
+ return DES_set_key_checked(key, schedule);
}
else
{
- des_set_key_unchecked(key, schedule);
+ DES_set_key_unchecked(key, schedule);
return 0;
}
}
* return -1 if key parity error,
* return -2 if illegal weak key.
*/
-int des_set_key_checked(const_des_cblock *key, des_key_schedule schedule)
+int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule)
{
- if (!des_check_key_parity(key))
+ if (!DES_check_key_parity(key))
return(-1);
- if (des_is_weak_key(key))
+ if (DES_is_weak_key(key))
return(-2);
- des_set_key_unchecked(key, schedule);
+ DES_set_key_unchecked(key, schedule);
return 0;
}
-void des_set_key_unchecked(const_des_cblock *key, des_key_schedule schedule)
+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};
+ static const 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;
register const unsigned char *in;
register DES_LONG *k;
register int i;
- k = &schedule->ks.deslong[0];
+#ifdef OPENBSD_DEV_CRYPTO
+ memcpy(schedule->key,key,sizeof schedule->key);
+ schedule->session=NULL;
+#endif
+ k = &schedule->ks->deslong[0];
in = &(*key)[0];
c2l(in,c);
}
}
-int des_key_sched(const_des_cblock *key, des_key_schedule schedule)
+int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule)
{
- return(des_set_key(key,schedule));
+ return(DES_set_key(key,schedule));
}
/*
#undef des_fixup_key_parity