2001-04-10 Ken Raeburn <raeburn@mit.edu>
+ * des.h (des_pcbc_encrypt, des_quad_cksum, des_cbc_cksum,
+ des_cbc_encrypt, des_ecb_encrypt): Use const for some input args.
+
* krb.h (krb_get_admhst, krb_get_krbhst, krb_get_lrealm): Don't
use "index" as argument name.
KRB5_DLLIMP int KRB5_CALLCONV
des_pcbc_encrypt (C_Block FAR *in, C_Block FAR *out, long length,
- Key_schedule schedule, C_Block FAR *ivec, int encrypt);
+ const des_key_schedule schedule, C_Block FAR *ivec,
+ int encrypt);
KRB5_DLLIMP unsigned long KRB5_CALLCONV
-des_quad_cksum (unsigned char FAR *in, unsigned KRB4_32 FAR *out,
+des_quad_cksum (const unsigned char FAR *in, unsigned KRB4_32 FAR *out,
long length, int out_count, C_Block FAR *seed);
-KRB5_DLLIMP int KRB5_CALLCONV des_string_to_key (char FAR *, C_Block);
+KRB5_DLLIMP int KRB5_CALLCONV des_string_to_key (const char FAR *, C_Block);
/* new */
#ifdef KRB5_GENERAL__
+/* Why are we using krb5 types as part of this API? */
KRB5_DLLIMP void KRB5_CALLCONV
-des_cbc_cksum(krb5_octet *, krb5_octet *, unsigned long,
- des_key_schedule, krb5_octet *);
+des_cbc_cksum(const krb5_octet *, krb5_octet *, unsigned long,
+ const des_key_schedule, const krb5_octet *);
int des_cbc_encrypt(krb5_octet *, krb5_octet *, unsigned long,
- des_key_schedule, krb5_octet *, int);
+ const des_key_schedule, const krb5_octet *, int);
krb5_error_code des_read_password(des_cblock *, char *, int);
#endif
+/* The unsigned long pointers are indicative of the desired alignment;
+ the values there aren't really treated as long values. */
KRB5_DLLIMP int KRB5_CALLCONV des_ecb_encrypt(unsigned long *, unsigned long *,
- des_key_schedule, int);
+ const des_key_schedule, int);
void des_fixup_key_parity(des_cblock);
int des_check_key_parity(des_cblock);
KRB5_DLLIMP int KRB5_CALLCONV des_new_random_key(des_cblock);
2001-04-10 Ken Raeburn <raeburn@mit.edu>
+ * cksum.c (des_cbc_cksum): Arguments IN, KEY, and IV now const.
+ * des.c (des_ecb_encrypt): Change type of arg "schedule" to
+ const des_key_schedule and drop register decl. Make local
+ variable "iv" const.
+ * enc_dec.c (des_cbc_encrypt): Arguments KEY and IV now const.
+ * pcbc_encrypt.c (des_pcbc_encrypt): Argument SCHEDULE now const.
+ Drop some unnecessary casts.
+ * quad_cksum.c (vaxtohl, vaxtohs): Cast to pointer to const.
+ (des_quad_cksum): Argument IN now points to const.
+ * str_to_key.c (des_string_to_key): String argument now const.
+ Delete local declaration of des_cbc_cksum. Delete or fix some
+ casts.
+ * t_pcbc.c (main): Pass address of ivec to des_pcbc_encrypt.
+ * util.c (des_cblock_print_file): Delete unnecessary cast.
+
* Makefile.in (STLIBOBJS, OBJS, SRCS): Delete references to
k4_glue.c etc.
(clean): Remove t_quad and t_pcbc object files and test programs.
void
des_cbc_cksum(in,out,length,key,iv)
- krb5_octet *in; /* >= length bytes of inputtext */
- krb5_octet *out; /* >= length bytes of outputtext */
+ const krb5_octet *in; /* >= length bytes of inputtext */
+ krb5_octet *out; /* >= length bytes of outputtext */
register unsigned long length; /* in bytes */
- mit_des_key_schedule key; /* precomputed key schedule */
- krb5_octet *iv; /* 8 bytes of ivec */
+ const mit_des_key_schedule key; /* precomputed key schedule */
+ const krb5_octet *iv; /* 8 bytes of ivec */
{
mit_des_cbc_cksum(in, out, length, key, iv);
}
des_ecb_encrypt(clear, cipher, schedule, encrypt)
unsigned long *clear;
unsigned long *cipher;
- register mit_des_key_schedule schedule; /* r11 */
+ const mit_des_key_schedule schedule;
int encrypt; /* 0 ==> decrypt, else encrypt */
{
- static des_cblock iv;
+ const static des_cblock iv;
return (mit_des_cbc_encrypt((const des_cblock *) clear,
(des_cblock *) cipher,
int
des_cbc_encrypt(in,out,length,key,iv,encrypt)
- krb5_octet *in; /* >= length bytes of input text */
+ krb5_octet *in; /* >= length bytes of input text */
krb5_octet *out; /* >= length bytes of output text */
register unsigned long length; /* in bytes */
- mit_des_key_schedule key; /* precomputed key schedule */
- krb5_octet *iv; /* 8 bytes of ivec */
+ const mit_des_key_schedule key; /* precomputed key schedule */
+ const krb5_octet *iv; /* 8 bytes of ivec */
int encrypt; /* 0 ==> decrypt, else encrypt */
{
return (mit_des_cbc_encrypt((const des_cblock *) in,
des_cblock *in;
des_cblock *out;
long length;
- des_key_schedule schedule;
+ const des_key_schedule schedule;
des_cblock *ivec;
int encrypt;
{
register unsigned DES_INT32 left, right;
register unsigned DES_INT32 temp;
- register unsigned DES_INT32 *kp;
- register unsigned char *ip, *op;
+ const unsigned DES_INT32 *kp;
+ const unsigned char *ip;
+ unsigned char *op;
/*
* Copy the key pointer, just once
*/
- kp = (unsigned DES_INT32 *)schedule;
+ kp = (const unsigned DES_INT32 *)schedule;
/*
* 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 block of input. 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
/* vax byte order is LSB first. This is not performance critical, and
is far more readable this way. */
#define four_bytes_vax_to_nets(x) ((((((x[3]<<8)|x[2])<<8)|x[1])<<8)|x[0])
-#define vaxtohl(x) four_bytes_vax_to_nets(((unsigned char *)(x)))
+#define vaxtohl(x) four_bytes_vax_to_nets(((const unsigned char *)(x)))
#define two_bytes_vax_to_nets(x) ((x[1]<<8)|x[0])
-#define vaxtohs(x) two_bytes_vax_to_nets(((unsigned char *)(x)))
+#define vaxtohs(x) two_bytes_vax_to_nets(((const unsigned char *)(x)))
/* Externals */
extern char *errmsg();
KRB5_DLLIMP unsigned long KRB5_CALLCONV
des_quad_cksum(in,out,length,out_count,c_seed)
- unsigned char FAR *in; /* input block */
+ const unsigned char FAR *in; /* input block */
unsigned DES_INT32 FAR *out; /* optional longer output */
long length; /* original length in bytes */
int out_count; /* number of iterations */
register unsigned DES_INT32 z2;
register unsigned DES_INT32 x;
register unsigned DES_INT32 x2;
- register unsigned char *p;
+ const unsigned char *p;
register DES_INT32 len;
register int i;
/* use all 8 bytes of seed */
z = vaxtohl(c_seed);
- z2 = vaxtohl((char *)c_seed+4);
+ z2 = vaxtohl((const char *)c_seed+4);
if (out == NULL)
out_count = 1; /* default */
len -= 2;
}
else {
- x = (z + *(unsigned char *)p++);
+ x = (z + *(const unsigned char *)p++);
len = 0;
}
x2 = z2;
*/
KRB5_DLLIMP int KRB5_CALLCONV
des_string_to_key(str,key)
- char *str;
+ const char *str;
register mit_des_cblock key;
{
- register char *in_str;
+ const char *in_str;
register unsigned temp;
register int j;
- register long i, length;
+ unsigned long i, length;
unsigned char *k_p;
int forward;
register char *p_char;
char k_char[64];
mit_des_key_schedule key_sked;
- extern void des_cbc_cksum();
in_str = str;
forward = 1;
#ifdef DEBUG
if (mit_des_debug)
fprintf(stdout,
- "\n\ninput str length = %d string = %s\nstring = 0x ",
+ "\n\ninput str length = %ld string = %s\nstring = 0x ",
length,str);
#endif
des_fixup_key_parity(key);
/* Now one-way encrypt it with the folded key */
- (void) des_key_sched(key, *(Key_schedule *)&key_sked);
- (void) des_cbc_cksum((des_cblock *)in_str,key,length,key_sked,key);
+ (void) des_key_sched(key, key_sked);
+ (void) des_cbc_cksum((const unsigned char *) in_str, key, length,
+ key_sked, key);
/* erase key_sked */
- memset((char *)key_sked, 0,sizeof(key_sked));
+ memset(key_sked, 0,sizeof(key_sked));
/* now fix up key parity again */
des_fixup_key_parity(key);
des_key_sched (default_key, sked);
/* This could lose on alignment... */
des_pcbc_encrypt ((des_cblock *)&tests[i].text, out,
- strlen(tests[i].text) + 1, sked, ivec, 1);
+ strlen(tests[i].text) + 1, sked, &ivec, 1);
printf ("pcbc_encrypt(\"%s\") = {", tests[i].text);
jmax = (strlen (tests[i].text) + 8) & ~7U;
for (j = 0; j < jmax; j++) {
printf ("\n}\n");
/* reverse it */
- des_pcbc_encrypt (out, out2, jmax, sked, ivec, 0);
+ des_pcbc_encrypt (out, out2, jmax, sked, &ivec, 0);
if (strcmp ((char *)out2, tests[i].text)) {
printf ("decrypt failed\n");
wrong = 1;
des_cblock *x;
FILE *fp;
{
- unsigned char *y = (unsigned char *) x;
+ unsigned char *y = *x;
register int i = 0;
fprintf(fp," 0x { ");