2001-04-10 Ken Raeburn <raeburn@mit.edu>
* f_cksum.c (mit_des_cbc_cksum): Use const for input, key
- schedule, and initial vector.
+ schedule, and initial vector. Get rid of casts when possible.
* f_cbc.c (mit_des_cbc_encrypt): Likewise.
- * des_int.h (mit_des_cbc_cksum, mit_des_cbc_encrypt): Update
- decls.
+ * f_sched.c (make_key_sched): Likewise.
+ * d3_cbc.c (mit_des3_cbc_encrypt): Likewise.
+ * d3_kysched.c (mit_des3_key_sched): Don't create new variables to
+ point to components of key and schedule, just index into the
+ argument variables.
+ * des_int.h (mit_des_cbc_cksum, mit_des_cbc_encrypt,
+ mit_des3_cbc_encrypt): Update decls.
(mit_des_string_to_key_int): New decl.
+ * weak_key.c (mit_des_is_weak_key): Get rid of some unneeded
+ casts.
+
+ * des_int.h (make_key_sched): Define a macro to rename with
+ mit_des_ prefix.
+
* des_int.h (des_cblock, des_key_schedule): Duplicate definitions
here and in kerberosIV/des.h, using macro
KRB5INT_DES_TYPES_DEFINED to avoid duplication.
const mit_des_cblock FAR *in;
mit_des_cblock FAR *out;
unsigned long length;
- mit_des_key_schedule ks1, ks2, ks3;
- mit_des_cblock ivec;
+ const mit_des_key_schedule ks1, ks2, ks3;
+ const mit_des_cblock ivec;
int encrypt;
{
register unsigned DES_INT32 left, right;
register unsigned DES_INT32 temp;
- register unsigned DES_INT32 *kp1, *kp2, *kp3;
- register unsigned char *ip, *op;
+ const unsigned DES_INT32 *kp1, *kp2, *kp3;
+ const unsigned char *ip;
+ unsigned char *op;
/*
* Get key pointer here. This won't need to be reinitialized
*/
- kp1 = (unsigned DES_INT32 *)ks1;
- kp2 = (unsigned DES_INT32 *)ks2;
- kp3 = (unsigned DES_INT32 *)ks3;
+ kp1 = (const unsigned DES_INT32 *)ks1;
+ kp2 = (const unsigned DES_INT32 *)ks2;
+ kp3 = (const unsigned DES_INT32 *)ks3;
/*
* Deal with encryption and decryption separately.
* Initialize left and right with the contents of the initial
* vector.
*/
- ip = (unsigned char *)ivec;
+ ip = ivec;
GET_HALF_BLOCK(left, ip);
GET_HALF_BLOCK(right, ip);
* Suitably initialized, now work the length down 8 bytes
* at a time.
*/
- ip = (unsigned char *)in;
- op = (unsigned char *)out;
+ ip = *in;
+ op = *out;
while (length > 0) {
/*
* Get more input, xor it in. If the length is
/*
* Prime the old cipher with ivec.
*/
- ip = (unsigned char *)ivec;
+ ip = ivec;
GET_HALF_BLOCK(ocipherl, ip);
GET_HALF_BLOCK(ocipherr, ip);
/*
* Now do this in earnest until we run out of length.
*/
- ip = (unsigned char *)in;
- op = (unsigned char *)out;
+ ip = *in;
+ op = *out;
for (;;) { /* check done inside loop */
/*
* Read a block from the input into left and
#include "des_int.h"
int
-mit_des3_key_sched(key,key_sched)
- mit_des3_cblock key;
- mit_des3_key_schedule key_sched;
+mit_des3_key_sched(k,schedule)
+ mit_des3_cblock k;
+ mit_des3_key_schedule schedule;
{
- mit_des_cblock *k = (mit_des_cblock *)key;
- mit_des_key_schedule *schedule = (mit_des_key_schedule *)key_sched;
-
make_key_sched(k[0],schedule[0]);
make_key_sched(k[1],schedule[1]);
make_key_sched(k[2],schedule[2]);
int mit_des_pcbc_encrypt ();
/* f_sched.c */
+#define make_key_sched mit_des_make_key_sched
int make_key_sched (mit_des_cblock, mit_des_key_schedule);
/* d3_cbc.c */
extern int mit_des3_cbc_encrypt
(const mit_des_cblock FAR *in,
- mit_des_cblock FAR *out,
- unsigned long length,
- mit_des_key_schedule ks1,
- mit_des_key_schedule ks2,
- mit_des_key_schedule ks3,
- mit_des_cblock ivec,
- int encrypt);
+ mit_des_cblock FAR *out,
+ unsigned long length,
+ const mit_des_key_schedule ks1,
+ const mit_des_key_schedule ks2,
+ const mit_des_key_schedule ks3,
+ const mit_des_cblock ivec,
+ int encrypt);
/* d3_procky.c */
extern krb5_error_code mit_des3_process_key
* Initialize left and right with the contents of the initial
* vector.
*/
- ip = (const unsigned char *)ivec;
+ ip = ivec;
GET_HALF_BLOCK(left, ip);
GET_HALF_BLOCK(right, ip);
* Suitably initialized, now work the length down 8 bytes
* at a time.
*/
- ip = (unsigned char *)in;
- op = (unsigned char *)out;
+ ip = *in;
+ op = *out;
while (length > 0) {
/*
* Get more input, xor it in. If the length is
/*
* Prime the old cipher with ivec.
*/
- ip = (const unsigned char *)ivec;
+ ip = ivec;
GET_HALF_BLOCK(ocipherl, ip);
GET_HALF_BLOCK(ocipherr, ip);
/*
* Now do this in earnest until we run out of length.
*/
- ip = (unsigned char *)in;
- op = (unsigned char *)out;
+ ip = *in;
+ op = *out;
for (;;) { /* check done inside loop */
/*
* Read a block from the input into left and
* Initialize left and right with the contents of the initial
* vector.
*/
- ip = (const unsigned char *)ivec;
+ ip = ivec;
GET_HALF_BLOCK(left, ip);
GET_HALF_BLOCK(right, ip);
* Suitably initialized, now work the length down 8 bytes
* at a time.
*/
- ip = (const unsigned char *)in;
+ ip = in;
len = length;
while (len > 0) {
/*
* Done. Left and right have the checksum. Put it into
* the output.
*/
- op = (unsigned char *)out;
+ op = out;
PUT_HALF_BLOCK(left, op);
PUT_HALF_BLOCK(right, op);
/*
* Need a pointer for the keys and a temporary DES_INT32
*/
- register unsigned char *k;
+ const unsigned char *k;
register unsigned DES_INT32 tmp;
/*
* Fetch the key into something we can work with
*/
- k = (unsigned char *)key;
+ k = key;
/*
* The first permutted choice gives us the 28 bits for C0 and
const mit_des_cblock *weak_p = weak;
for (i = 0; i < (sizeof(weak)/sizeof(mit_des_cblock)); i++) {
- if (!memcmp((char *)weak_p++,(char *)key,sizeof(mit_des_cblock)))
+ if (!memcmp(weak_p++,key,sizeof(mit_des_cblock)))
return 1;
}