2001-04-09 Ken Raeburn <raeburn@mit.edu>
- * des425.h: Renamed from des.h to avoid confusion with the other
- des.h in the source tree. Adjust include directives in all other
- files.
+ * des.h: Deleted to avoid confusion with the other des.h in the
+ tree. All files changed to include des_int.h and
+ (the other) des.h instead.
+ * new_rnd_key.c (des_init_random_number_generator): Cast seed data
+ pointer to keep compiler happy.
+ * read_passwd.c (intr_routine, des_read_pw_string): Add
+ prototypes.
+ (des_read_password): Fix call sequence for des_string_to_key.
+ * str_to_key.c (des_string_to_key): Remove static storage in favor
+ of automatic storage. Fix call sequence to des_key_sched. Delete
+ no-op while loop.
+ * t_quad.c (main): Fix call sequence for des_quad_cksum.
+ * verify.c (des_string_to_key, des_key_sched, des_ecb_encrypt,
+ des_cbc_encrypt): Removed declarations.
+ (do_encrypt, do_decrypt): Prototype. Make args point to unsigned
+ char, and return types void.
+ (main): Declare return type. Make automatic var in_length be
+ unsigned long; discard some casts, but cast it when passing to
+ memcmp. Remove extra arg passed to des_cbc_cksum.
+ (flip): Delete unused function.
* quad_cksum.c (des_quad_cksum): Add comments. Force 32-bit
arithmetic just to be careful.
* spm 8/85 MIT project athena
*/
-
-#include "des425.h"
+#include "des_int.h"
+#include "des.h"
/*
* This routine performs DES cipher-block-chaining checksum operation,
* originally written by Steve Miller, MIT Project Athena
*/
-
-#include "des425.h"
+#include "des_int.h"
+#include "des.h"
KRB5_DLLIMP int KRB5_CALLCONV
des_ecb_encrypt(clear, cipher, schedule, encrypt)
unsigned long *clear;
unsigned long *cipher;
- int encrypt; /* 0 ==> decrypt, else encrypt */
register mit_des_key_schedule schedule; /* r11 */
+ int encrypt; /* 0 ==> decrypt, else encrypt */
{
static des_cblock iv;
+++ /dev/null
-/*
- * lib/des425/des425.h (formerly des.h)
- *
- * Copyright 1991 by the Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- *
- *
- */
-
-/*
- * Include file for the Data Encryption Standard library.
- */
-
-/* only do the whole thing once */
-#ifndef DES_DEFS
-#define DES_DEFS
-
-#include <des_int.h>
-
-typedef mit_des_cblock des_cblock; /* crypto-block size */
-
-/* Key schedule */
-typedef mit_des_key_schedule des_key_schedule;
-
-#define DES_KEY_SZ (sizeof(des_cblock))
-#define DES_ENCRYPT 1
-#define DES_DECRYPT 0
-
-#ifndef NCOMPAT
-#define C_Block des_cblock
-#define Key_schedule des_key_schedule
-#define ENCRYPT DES_ENCRYPT
-#define DECRYPT DES_DECRYPT
-#define KEY_SZ DES_KEY_SZ
-#define string_to_key des_string_to_key
-#define read_pw_string des_read_pw_string
-#define random_key des_random_key
-#define pcbc_encrypt des_pcbc_encrypt
-#define key_sched des_key_sched
-#define cbc_encrypt des_cbc_encrypt
-#define cbc_cksum des_cbc_cksum
-#define C_Block_print des_cblock_print
-#define quad_cksum des_quad_cksum
-typedef struct des_ks_struct bit_64;
-#endif
-
-#define des_cblock_print(x) des_cblock_print_file(x, stdout)
-
-/*
- * Windows needs everything prototyped because we're exporting all the fuctions.
- */
-void des_cbc_cksum();
-KRB5_DLLIMP int KRB5_CALLCONV des_ecb_encrypt();
-int des_cbc_encrypt();
-void des_fixup_key_parity();
-int des_check_key_parity();
-KRB5_DLLIMP int KRB5_CALLCONV des_key_sched();
-KRB5_DLLIMP int KRB5_CALLCONV des_new_random_key();
-void des_init_random_number_generator();
-KRB5_DLLIMP void KRB5_CALLCONV des_set_random_generator_seed();
-void des_set_sequence_number();
-void des_generate_random_block();
-KRB5_DLLIMP int KRB5_CALLCONV des_pcbc_encrypt();
-KRB5_DLLIMP unsigned long KRB5_CALLCONV des_quad_cksum();
-int des_random_key();
-krb5_error_code des_read_password();
-KRB5_DLLIMP int KRB5_CALLCONV des_string_to_key();
-int des_is_weak_key();
-
-#endif /* DES_DEFS */
*
*/
-
-#include "des425.h"
+#include "des_int.h"
+#include "des.h"
/*
* This routine performs DES cipher-block-chaining operation, either
*
*/
-
-#include "des425.h"
+#include "des_int.h"
+#include "des.h"
/*
* des_fixup_key_parity: Forces odd parity per byte; parity is bits
#include <stdio.h>
-#include "des425.h"
+#include "des_int.h"
+#include "des.h"
KRB5_DLLIMP int KRB5_CALLCONV
des_key_sched(k,schedule)
- register mit_des_cblock k; /* r11 */
- mit_des_key_schedule schedule;
+ des_cblock k;
+ des_key_schedule schedule;
{
- return (mit_des_key_sched(k, schedule));
+ return (mit_des_key_sched(k, schedule));
}
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-
-#include "des425.h"
+#include "des_int.h"
+#include "des.h"
/*
* des_init_random_number_generator:
krb5_data seed;
seed.length = sizeof(key);
- seed.data = key;
+ seed.data = (char *) key;
if (krb5_c_random_seed(/* XXX */ 0, &seed))
/* XXX */ abort();
#include <stdio.h>
#include <errno.h>
-#include "des425.h"
+#include "des_int.h"
+#include "des.h"
/* Definitions for byte swapping */
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-#include "des425.h"
+#include "des_int.h"
+#include "des.h"
/* random_key */
int
#if !defined(_MSDOS)&&!defined(_WIN32)
-#include "des425.h"
+#include "des_int.h"
+#include "des.h"
#include <stdio.h>
#include <errno.h>
#include <signal.h>
static jmp_buf pwd_jump;
+static krb5_sigtype intr_routine (int);
+krb5_error_code des_read_pw_string (char *, int, char *, char *);
+
static krb5_sigtype
intr_routine(signo)
int signo;
prompt, verify ? prompt2 : 0);
if (ok == 0)
- des_string_to_key(key_string, k);
+ des_string_to_key(key_string, *k);
memset(key_string, 0, sizeof (key_string));
return ok;
#include <stdio.h>
#include <string.h>
-#include "des425.h"
-/* #include "des_internal.h" */
+#include "des_int.h"
+#include "des.h"
extern int mit_des_debug;
/*
- * convert an arbitrary length string to a DES key
+ * Convert an arbitrary length string to a DES key.
+ */
+
+/*
+ * For krb5, a change was made to this algorithm: When each key is
+ * generated, after fixing parity, a check for weak and semi-weak keys
+ * is done. If the key is weak or semi-weak, we XOR the last byte
+ * with 0xF0. (In the case of the intermediate key, the weakness is
+ * probably irrelevant, but there it is.) The odds that this will
+ * generate a different key for a random input string are pretty low,
+ * but non-zero. So we need this different function for krb4 to use.
*/
KRB5_DLLIMP int KRB5_CALLCONV
des_string_to_key(str,key)
register unsigned temp;
register int j;
register long i, length;
- static unsigned char *k_p;
- static int forward;
+ unsigned char *k_p;
+ int forward;
register char *p_char;
- static char k_char[64];
- static mit_des_key_schedule key_sked;
+ char k_char[64];
+ mit_des_key_schedule key_sked;
extern void des_cbc_cksum();
in_str = str;
else
*--p_char ^= (int) temp & 01;
temp = temp >> 1;
- } while (--j > 0);
+ }
/* check and flip direction */
if ((i%8) == 0)
des_fixup_key_parity(key);
/* Now one-way encrypt it with the folded key */
- (void) des_key_sched(key,key_sked);
+ (void) des_key_sched(key, *(Key_schedule *)&key_sked);
(void) des_cbc_cksum((des_cblock *)in_str,key,length,key_sked,key);
/* erase key_sked */
memset((char *)key_sked, 0,sizeof(key_sked));
*/
-#include "des425.h"
+#include "des.h"
#include "des_int.h"
#ifdef DEBUG
#include <stdio.h>
#include <errno.h>
-#include "des425.h"
+#include "des_int.h"
+#include "des.h"
extern char *errmsg();
extern int errno;
for (i = 0; i < 3; i++) {
int wrong = 0, j;
- des_quad_cksum (tests[i].text, out, 64L, 4, default_key);
+ des_quad_cksum (tests[i].text, out, 64L, 4,
+ (mit_des_cblock *) &default_key);
if (tests[i].text[0] == 2)
printf ("quad_cksum(<binary blob 1>) = {");
else
/* Application include files */
#include "k5-int.h"
-#include "des425.h"
+#include "des_int.h"
+#include "des.h"
void des_cblock_print_file(x, fp)
des_cblock *x;
#include <stdio.h>
#include <errno.h>
-#include "des425.h"
+#include "des_int.h"
+#include "des.h"
extern char *errmsg();
extern int errno;
-extern int des_string_to_key();
-extern int des_key_sched();
-extern int des_ecb_encrypt();
-extern int des_cbc_encrypt();
char *progname;
int nflag = 2;
int vflag;
0xa3, 0x80, 0xe0, 0x2a, 0x6b, 0xe5, 0x46, 0x96
};
-
+
/*
* Can also add :
* plaintext = 0, key = 0, cipher = 0x8ca64de9c1b123a7 (or is it a 1?)
*/
+void do_encrypt (unsigned char *, unsigned char *);
+void do_decrypt (unsigned char *, unsigned char *);
+
+int
main(argc,argv)
int argc;
char *argv[];
{
/* Local Declarations */
- long in_length;
+ unsigned long in_length;
progname=argv[0]; /* salt away invoking program */
printf("ACTUAL CBC\n\tclear \"%s\"\n",input);
in_length = strlen((char *) input);
- des_cbc_encrypt(input,cipher_text,(long) in_length,KS,ivec,1);
+ des_cbc_encrypt(input,cipher_text, in_length,KS,ivec,1);
printf("\tciphertext = (low to high bytes)\n");
for (i = 0; i <= 7; i++) {
printf("\t\t");
}
printf("\n");
}
- des_cbc_encrypt(cipher_text,clear_text,(long) in_length,KS,ivec,0);
+ des_cbc_encrypt(cipher_text,clear_text,in_length,KS,ivec,0);
printf("\tdecrypted clear_text = \"%s\"\n",clear_text);
- if ( memcmp((char *)cipher_text, (char *)cipher3, in_length) ) {
+ if ( memcmp(cipher_text, cipher3, (size_t) in_length) ) {
printf("verify: error in CBC encryption\n");
exit(-1);
}
printf("\tchecksum\t58 d2 e7 7e 86 06 27 33, ");
printf("or some part thereof\n");
input = clear_text2;
- des_cbc_cksum(input,cipher_text,(long) strlen((char *) input),KS,ivec,1);
+ des_cbc_cksum(input,cipher_text,(long) strlen((char *) input),KS,ivec);
printf("ACTUAL CBC checksum\n");
printf("\t\tencrypted cksum = (low to high bytes)\n\t\t");
for (j = 0; j<=7; j++)
exit(0);
}
-flip(array)
- char *array;
-{
- register old,new,i,j;
- /* flips the bit order within each byte from 0 lsb to 0 msb */
- for (i = 0; i<=7; i++) {
- old = *array;
- new = 0;
- for (j = 0; j<=7; j++) {
- if (old & 01)
- new = new | 01;
- if (j < 7) {
- old = old >> 1;
- new = new << 1;
- }
- }
- *array = new;
- array++;
- }
-}
-
+void
do_encrypt(in,out)
- char *in;
- char *out;
+ unsigned char *in;
+ unsigned char *out;
{
for (i =1; i<=nflag; i++) {
des_ecb_encrypt(in,out,KS,1);
if (des_debug) {
printf("\nclear %s\n",in);
for (j = 0; j<=7; j++)
- printf("%02 X ",in[j] & 0xff);
+ printf("%02X ",in[j] & 0xff);
printf("\tcipher ");
for (j = 0; j<=7; j++)
printf("%02X ",out[j] & 0xff);
}
}
+void
do_decrypt(in,out)
- char *out;
- char *in;
+ unsigned char *out;
+ unsigned char *in;
/* try to invert it */
{
for (i =1; i<=nflag; i++) {
* Originally written 8/85 by Steve Miller, MIT Project Athena.
*/
-
-#include "des425.h"
+#include "des_int.h"
+#include "des.h"
/*
* mit_des_is_weak_key: returns true iff key is a [semi-]weak des key.