From: Ken Raeburn Date: Tue, 10 Apr 2001 08:31:43 +0000 (+0000) Subject: more cleanup - add const, reduce casting X-Git-Tag: krb5-1.3-alpha1~1577 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a633be77bd368474338d0888082647d130cf8ee3;p=krb5.git more cleanup - add const, reduce casting git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13169 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/crypto/des/ChangeLog b/src/lib/crypto/des/ChangeLog index c157d4811..af3bd971f 100644 --- a/src/lib/crypto/des/ChangeLog +++ b/src/lib/crypto/des/ChangeLog @@ -1,12 +1,23 @@ 2001-04-10 Ken Raeburn * 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. diff --git a/src/lib/crypto/des/d3_cbc.c b/src/lib/crypto/des/d3_cbc.c index 0204b719b..84d0af39a 100644 --- a/src/lib/crypto/des/d3_cbc.c +++ b/src/lib/crypto/des/d3_cbc.c @@ -32,21 +32,22 @@ mit_des3_cbc_encrypt(in, out, length, ks1, ks2, ks3, ivec, encrypt) 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. @@ -56,7 +57,7 @@ mit_des3_cbc_encrypt(in, out, length, ks1, ks2, ks3, ivec, encrypt) * 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); @@ -64,8 +65,8 @@ mit_des3_cbc_encrypt(in, out, length, ks1, ks2, ks3, ivec, encrypt) * 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 @@ -130,15 +131,15 @@ mit_des3_cbc_encrypt(in, out, length, ks1, ks2, ks3, ivec, encrypt) /* * 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 diff --git a/src/lib/crypto/des/d3_kysched.c b/src/lib/crypto/des/d3_kysched.c index efd91c44b..6d9c27697 100644 --- a/src/lib/crypto/des/d3_kysched.c +++ b/src/lib/crypto/des/d3_kysched.c @@ -24,13 +24,10 @@ #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]); diff --git a/src/lib/crypto/des/des_int.h b/src/lib/crypto/des/des_int.h index 01d840d0d..8ff40ecd6 100644 --- a/src/lib/crypto/des/des_int.h +++ b/src/lib/crypto/des/des_int.h @@ -217,6 +217,7 @@ krb5_error_code mit_des_combine_subkeys 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); @@ -248,13 +249,13 @@ extern int mit_des3_ecb_encrypt /* 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 diff --git a/src/lib/crypto/des/f_cbc.c b/src/lib/crypto/des/f_cbc.c index fdc125016..b6443328c 100644 --- a/src/lib/crypto/des/f_cbc.c +++ b/src/lib/crypto/des/f_cbc.c @@ -64,7 +64,7 @@ mit_des_cbc_encrypt(in, out, length, schedule, ivec, encrypt) * 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); @@ -72,8 +72,8 @@ mit_des_cbc_encrypt(in, out, length, schedule, ivec, encrypt) * 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 @@ -143,15 +143,15 @@ mit_des_cbc_encrypt(in, out, length, schedule, ivec, encrypt) /* * 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 diff --git a/src/lib/crypto/des/f_cksum.c b/src/lib/crypto/des/f_cksum.c index 4fe971123..0cfadc112 100644 --- a/src/lib/crypto/des/f_cksum.c +++ b/src/lib/crypto/des/f_cksum.c @@ -47,7 +47,7 @@ mit_des_cbc_cksum(in, out, length, schedule, ivec) * 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); @@ -55,7 +55,7 @@ mit_des_cbc_cksum(in, out, length, schedule, ivec) * Suitably initialized, now work the length down 8 bytes * at a time. */ - ip = (const unsigned char *)in; + ip = in; len = length; while (len > 0) { /* @@ -111,7 +111,7 @@ mit_des_cbc_cksum(in, out, length, schedule, ivec) * 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); diff --git a/src/lib/crypto/des/f_sched.c b/src/lib/crypto/des/f_sched.c index eeea4f8b5..6dbde1fcd 100644 --- a/src/lib/crypto/des/f_sched.c +++ b/src/lib/crypto/des/f_sched.c @@ -230,13 +230,13 @@ make_key_sched(key, schedule) /* * 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 diff --git a/src/lib/crypto/des/weak_key.c b/src/lib/crypto/des/weak_key.c index 293c25e22..4408d8a96 100644 --- a/src/lib/crypto/des/weak_key.c +++ b/src/lib/crypto/des/weak_key.c @@ -78,7 +78,7 @@ mit_des_is_weak_key(key) 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; }