1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-27 08:00:11 +00:00

Stop using des_cblock * for arguments to DES functions.

This amounts to a char ** since it is a char[8] *.  Evil casts mostly
resolved the fact that what was actually passed in were plain char *.
Instead, change the DES functions to use 'unsigned char *' for keys
and for input and output buffers.

Reviewed by:	cem, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D21389
This commit is contained in:
John Baldwin 2019-08-26 17:25:07 +00:00
parent 15ddc5e43f
commit 87210a0c6d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=351513
8 changed files with 41 additions and 52 deletions

View File

@ -82,7 +82,7 @@ typedef struct des_ks_struct
extern int des_check_key; /* defaults to false */
char *des_options(void);
void des_ecb_encrypt(des_cblock *, des_cblock *, des_key_schedule, int);
void des_ecb_encrypt(unsigned char *, unsigned char *, des_key_schedule, int);
void des_encrypt1(DES_LONG *, des_key_schedule, int);
void des_encrypt2(DES_LONG *, des_key_schedule, int);
@ -91,24 +91,17 @@ void des_encrypt3(DES_LONG *, des_key_schedule, des_key_schedule,
void des_decrypt3(DES_LONG *, des_key_schedule, des_key_schedule,
des_key_schedule);
void des_ecb3_encrypt(des_cblock *, des_cblock *, des_key_schedule,
void des_ecb3_encrypt(unsigned char *, unsigned char *, des_key_schedule,
des_key_schedule, des_key_schedule, int);
void des_ncbc_encrypt(const unsigned char *, unsigned char *, long,
des_key_schedule, des_cblock *, int);
void des_ede3_cbc_encrypt(const unsigned char *, unsigned char *, long,
des_key_schedule, des_key_schedule,
des_key_schedule, des_cblock *, int);
void des_set_odd_parity(des_cblock *);
void des_fixup_key_parity(des_cblock *);
int des_is_weak_key(const des_cblock *);
int des_set_key(const des_cblock *, des_key_schedule);
int des_key_sched(const des_cblock *, des_key_schedule);
int des_set_key_checked(const des_cblock *, des_key_schedule);
void des_set_key_unchecked(const des_cblock *, des_key_schedule);
int des_check_key_parity(const des_cblock *);
void des_set_odd_parity(unsigned char *);
void des_fixup_key_parity(unsigned char *);
int des_is_weak_key(const unsigned char *);
int des_set_key(const unsigned char *, des_key_schedule);
int des_key_sched(const unsigned char *, des_key_schedule);
int des_set_key_checked(const unsigned char *, des_key_schedule);
void des_set_key_unchecked(const unsigned char *, des_key_schedule);
int des_check_key_parity(const unsigned char *);
#ifdef __cplusplus
}

View File

@ -97,13 +97,13 @@ char *des_options(void)
}
return(buf);
}
void des_ecb_encrypt(des_cblock *input, des_cblock *output,
void des_ecb_encrypt(unsigned char *input, unsigned char *output,
des_key_schedule ks, int enc)
{
register DES_LONG l;
DES_LONG ll[2];
const unsigned char *in=&(*input)[0];
unsigned char *out = &(*output)[0];
const unsigned char *in = input;
unsigned char *out = output;
c2l(in,l); ll[0]=l;
c2l(in,l); ll[1]=l;
@ -113,14 +113,14 @@ void des_ecb_encrypt(des_cblock *input, des_cblock *output,
l=ll[0]=ll[1]=0;
}
void des_ecb3_encrypt(des_cblock *input, des_cblock *output,
void des_ecb3_encrypt(unsigned char *input, unsigned char *output,
des_key_schedule ks1, des_key_schedule ks2, des_key_schedule ks3,
int enc)
{
register DES_LONG l0,l1;
DES_LONG ll[2];
const unsigned char *in = &(*input)[0];
unsigned char *out = &(*output)[0];
const unsigned char *in = input;
unsigned char *out = output;
c2l(in,l0);
c2l(in,l1);

View File

@ -67,21 +67,21 @@ __FBSDID("$FreeBSD$");
int des_check_key=0;
void des_set_odd_parity(des_cblock *key)
void des_set_odd_parity(unsigned char *key)
{
int i;
for (i=0; i<DES_KEY_SZ; i++)
(*key)[i]=odd_parity[(*key)[i]];
key[i]=odd_parity[key[i]];
}
int des_check_key_parity(const des_cblock *key)
int des_check_key_parity(const unsigned char *key)
{
int i;
for (i=0; i<DES_KEY_SZ; i++)
{
if ((*key)[i] != odd_parity[(*key)[i]])
if (key[i] != odd_parity[key[i]])
return(0);
}
return(1);
@ -117,7 +117,7 @@ static des_cblock weak_keys[NUM_WEAK_KEY]={
{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 unsigned char *key)
{
int i;
@ -142,7 +142,7 @@ 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)
int des_set_key(const unsigned char *key, des_key_schedule schedule)
{
if (des_check_key)
{
@ -159,7 +159,7 @@ int des_set_key(const des_cblock *key, des_key_schedule schedule)
* 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 unsigned char *key, des_key_schedule schedule)
{
if (!des_check_key_parity(key))
return(-1);
@ -169,7 +169,7 @@ int des_set_key_checked(const des_cblock *key, des_key_schedule schedule)
return 0;
}
void des_set_key_unchecked(const des_cblock *key, des_key_schedule schedule)
void des_set_key_unchecked(const unsigned char *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};
DES_LONG c,d,t,s,t2;
@ -178,7 +178,7 @@ void des_set_key_unchecked(const des_cblock *key, des_key_schedule schedule)
int i;
k = &schedule->ks.deslong[0];
in = &(*key)[0];
in = key;
c2l(in,c);
c2l(in,d);
@ -225,12 +225,12 @@ void des_set_key_unchecked(const des_cblock *key, des_key_schedule schedule)
}
}
int des_key_sched(const des_cblock *key, des_key_schedule schedule)
int des_key_sched(const unsigned char *key, des_key_schedule schedule)
{
return(des_set_key(key,schedule));
}
void des_fixup_key_parity(des_cblock *key)
void des_fixup_key_parity(unsigned char *key)
{
des_set_odd_parity(key);
}

View File

@ -135,8 +135,8 @@ des1_random_to_key(struct krb5_key_state *ks, const void *in)
| ((inkey[4] & 1) << 5)
| ((inkey[5] & 1) << 6)
| ((inkey[6] & 1) << 7));
des_set_odd_parity((des_cblock *) outkey);
if (des_is_weak_key((des_cblock *) outkey))
des_set_odd_parity(outkey);
if (des_is_weak_key(outkey))
outkey[7] ^= 0xf0;
des1_set_key(ks, ks->ks_key);

View File

@ -144,8 +144,8 @@ des3_random_to_key(struct krb5_key_state *ks, const void *in)
| ((inkey[4] & 1) << 5)
| ((inkey[5] & 1) << 6)
| ((inkey[6] & 1) << 7));
des_set_odd_parity((des_cblock *) outkey);
if (des_is_weak_key((des_cblock *) outkey))
des_set_odd_parity(outkey);
if (des_is_weak_key(outkey))
outkey[7] ^= 0xf0;
}

View File

@ -83,8 +83,8 @@ smb_E(const u_char *key, u_char *data, u_char *dest)
kk[6] = key[5] << 2 | (key[6] >> 6 & 0xfe);
kk[7] = key[6] << 1;
ksp = malloc(sizeof(des_key_schedule), M_SMBTEMP, M_WAITOK);
des_set_key((des_cblock *)kk, *ksp);
des_ecb_encrypt((des_cblock *)data, (des_cblock *)dest, *ksp, 1);
des_set_key(kk, *ksp);
des_ecb_encrypt(data, dest, *ksp, 1);
free(ksp, M_SMBTEMP);
}

View File

@ -75,19 +75,17 @@ struct enc_xform enc_xform_des = {
static void
des1_encrypt(caddr_t key, u_int8_t *blk)
{
des_cblock *cb = (des_cblock *) blk;
des_key_schedule *p = (des_key_schedule *) key;
des_ecb_encrypt(cb, cb, p[0], DES_ENCRYPT);
des_ecb_encrypt(blk, blk, p[0], DES_ENCRYPT);
}
static void
des1_decrypt(caddr_t key, u_int8_t *blk)
{
des_cblock *cb = (des_cblock *) blk;
des_key_schedule *p = (des_key_schedule *) key;
des_ecb_encrypt(cb, cb, p[0], DES_DECRYPT);
des_ecb_encrypt(blk, blk, p[0], DES_DECRYPT);
}
static int
@ -99,7 +97,7 @@ des1_setkey(u_int8_t **sched, const u_int8_t *key, int len)
p = KMALLOC(sizeof (des_key_schedule),
M_CRYPTO_DATA, M_NOWAIT|M_ZERO);
if (p != NULL) {
des_set_key((const des_cblock *) key, p[0]);
des_set_key(key, p[0]);
err = 0;
} else
err = ENOMEM;

View File

@ -76,19 +76,17 @@ struct enc_xform enc_xform_3des = {
static void
des3_encrypt(caddr_t key, u_int8_t *blk)
{
des_cblock *cb = (des_cblock *) blk;
des_key_schedule *p = (des_key_schedule *) key;
des_ecb3_encrypt(cb, cb, p[0], p[1], p[2], DES_ENCRYPT);
des_ecb3_encrypt(blk, blk, p[0], p[1], p[2], DES_ENCRYPT);
}
static void
des3_decrypt(caddr_t key, u_int8_t *blk)
{
des_cblock *cb = (des_cblock *) blk;
des_key_schedule *p = (des_key_schedule *) key;
des_ecb3_encrypt(cb, cb, p[0], p[1], p[2], DES_DECRYPT);
des_ecb3_encrypt(blk, blk, p[0], p[1], p[2], DES_DECRYPT);
}
static int
@ -100,9 +98,9 @@ des3_setkey(u_int8_t **sched, const u_int8_t *key, int len)
p = KMALLOC(3*sizeof (des_key_schedule),
M_CRYPTO_DATA, M_NOWAIT|M_ZERO);
if (p != NULL) {
des_set_key((const des_cblock *)(key + 0), p[0]);
des_set_key((const des_cblock *)(key + 8), p[1]);
des_set_key((const des_cblock *)(key + 16), p[2]);
des_set_key(key + 0, p[0]);
des_set_key(key + 8, p[1]);
des_set_key(key + 16, p[2]);
err = 0;
} else
err = ENOMEM;