summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des
diff options
context:
space:
mode:
authorbeck <>2000-03-19 11:13:58 +0000
committerbeck <>2000-03-19 11:13:58 +0000
commit796d609550df3a33fc11468741c5d2f6d3df4c11 (patch)
tree6c6d539061caa20372dad0ac4ddb1dfae2fbe7fe /src/lib/libcrypto/des
parent5be3114c1fd7e0dfea1e38d3abb4cbba75244419 (diff)
downloadopenbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.tar.gz
openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.tar.bz2
openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.zip
OpenSSL 0.9.5 merge
*warning* this bumps shared lib minors for libssl and libcrypto from 2.1 to 2.2 if you are using the ssl26 packages for ssh and other things to work you will need to get new ones (see ~beck/libsslsnap/<arch>) on cvs or ~beck/src-patent.tar.gz on cvs
Diffstat (limited to 'src/lib/libcrypto/des')
-rw-r--r--src/lib/libcrypto/des/Makefile.ssl14
-rw-r--r--src/lib/libcrypto/des/cbc3_enc.c20
-rw-r--r--src/lib/libcrypto/des/des.c22
-rw-r--r--src/lib/libcrypto/des/des.h7
-rw-r--r--src/lib/libcrypto/des/des_locl.h10
-rw-r--r--src/lib/libcrypto/des/des_opts.c10
-rw-r--r--src/lib/libcrypto/des/destest.c81
-rw-r--r--src/lib/libcrypto/des/enc_read.c4
-rw-r--r--src/lib/libcrypto/des/enc_writ.c13
-rw-r--r--src/lib/libcrypto/des/fcrypt.c10
-rw-r--r--src/lib/libcrypto/des/fcrypt_b.c2
-rw-r--r--src/lib/libcrypto/des/rand_key.c153
-rw-r--r--src/lib/libcrypto/des/read_pwd.c19
-rw-r--r--src/lib/libcrypto/des/rpc_enc.c2
-rw-r--r--src/lib/libcrypto/des/set_key.c37
-rw-r--r--src/lib/libcrypto/des/speed.c10
-rw-r--r--src/lib/libcrypto/des/str2key.c20
17 files changed, 213 insertions, 221 deletions
diff --git a/src/lib/libcrypto/des/Makefile.ssl b/src/lib/libcrypto/des/Makefile.ssl
index 7f9600cf02..41976655e9 100644
--- a/src/lib/libcrypto/des/Makefile.ssl
+++ b/src/lib/libcrypto/des/Makefile.ssl
@@ -15,6 +15,7 @@ MAKE= make -f Makefile.ssl
15MAKEDEPEND= $(TOP)/util/domd $(TOP) 15MAKEDEPEND= $(TOP)/util/domd $(TOP)
16MAKEFILE= Makefile.ssl 16MAKEFILE= Makefile.ssl
17AR= ar r 17AR= ar r
18RANLIB= ranlib
18DES_ENC= des_enc.o fcrypt_b.o 19DES_ENC= des_enc.o fcrypt_b.o
19# or use 20# or use
20#DES_ENC= dx86-elf.o yx86-elf.o 21#DES_ENC= dx86-elf.o yx86-elf.o
@@ -162,14 +163,15 @@ enc_read.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
162enc_read.o: ../../include/openssl/crypto.h ../../include/openssl/des.h 163enc_read.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
163enc_read.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 164enc_read.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
164enc_read.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 165enc_read.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
165enc_read.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 166enc_read.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
166enc_read.o: ../cryptlib.h des_locl.h 167enc_read.o: ../../include/openssl/stack.h ../cryptlib.h des_locl.h
167enc_writ.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 168enc_writ.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
168enc_writ.o: ../../include/openssl/crypto.h ../../include/openssl/des.h 169enc_writ.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
169enc_writ.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 170enc_writ.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
170enc_writ.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 171enc_writ.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
171enc_writ.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h 172enc_writ.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
172enc_writ.o: ../../include/openssl/stack.h ../cryptlib.h des_locl.h 173enc_writ.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
174enc_writ.o: ../cryptlib.h des_locl.h
173fcrypt.o: ../../include/openssl/des.h ../../include/openssl/des.h 175fcrypt.o: ../../include/openssl/des.h ../../include/openssl/des.h
174fcrypt.o: ../../include/openssl/e_os2.h ../../include/openssl/e_os2.h 176fcrypt.o: ../../include/openssl/e_os2.h ../../include/openssl/e_os2.h
175fcrypt.o: ../../include/openssl/opensslconf.h 177fcrypt.o: ../../include/openssl/opensslconf.h
@@ -187,15 +189,15 @@ pcbc_enc.o: ../../include/openssl/opensslconf.h des_locl.h
187qud_cksm.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h 189qud_cksm.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
188qud_cksm.o: ../../include/openssl/opensslconf.h des_locl.h 190qud_cksm.o: ../../include/openssl/opensslconf.h des_locl.h
189rand_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h 191rand_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
190rand_key.o: ../../include/openssl/opensslconf.h des_locl.h 192rand_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/rand.h
191read2pwd.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h 193read2pwd.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
192read2pwd.o: ../../include/openssl/opensslconf.h des_locl.h 194read2pwd.o: ../../include/openssl/opensslconf.h des_locl.h
193read_pwd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 195read_pwd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
194read_pwd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h 196read_pwd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
195read_pwd.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h 197read_pwd.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
196read_pwd.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h 198read_pwd.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
197read_pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h 199read_pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
198read_pwd.o: ../cryptlib.h des_locl.h 200read_pwd.o: ../../include/openssl/stack.h ../cryptlib.h des_locl.h
199rpc_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h 201rpc_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
200rpc_enc.o: ../../include/openssl/opensslconf.h des_locl.h des_ver.h rpc_des.h 202rpc_enc.o: ../../include/openssl/opensslconf.h des_locl.h des_ver.h rpc_des.h
201set_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h 203set_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
diff --git a/src/lib/libcrypto/des/cbc3_enc.c b/src/lib/libcrypto/des/cbc3_enc.c
index 3863a676d4..527e74f3de 100644
--- a/src/lib/libcrypto/des/cbc3_enc.c
+++ b/src/lib/libcrypto/des/cbc3_enc.c
@@ -58,7 +58,7 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61/* HAS BUGS? DON'T USE - this is only present for use in des.c */ 61/* HAS BUGS! DON'T USE - this is only present for use in des.c */
62void des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length, 62void des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length,
63 des_key_schedule ks1, des_key_schedule ks2, des_cblock *iv1, 63 des_key_schedule ks1, des_key_schedule ks2, des_cblock *iv1,
64 des_cblock *iv2, int enc) 64 des_cblock *iv2, int enc)
@@ -69,11 +69,14 @@ void des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length,
69 69
70 if (enc == DES_ENCRYPT) 70 if (enc == DES_ENCRYPT)
71 { 71 {
72 des_cbc_encrypt(input,output,length,ks1,iv1,enc); 72 des_cbc_encrypt((unsigned char*)input,
73 (unsigned char*)output,length,ks1,iv1,enc);
73 if (length >= sizeof(des_cblock)) 74 if (length >= sizeof(des_cblock))
74 memcpy(niv1,output[off],sizeof(des_cblock)); 75 memcpy(niv1,output[off],sizeof(des_cblock));
75 des_cbc_encrypt(output,output,l8,ks2,iv1,!enc); 76 des_cbc_encrypt((unsigned char*)output,
76 des_cbc_encrypt(output,output,l8,ks1,iv2, enc); 77 (unsigned char*)output,l8,ks2,iv1,!enc);
78 des_cbc_encrypt((unsigned char*)output,
79 (unsigned char*)output,l8,ks1,iv2,enc);
77 if (length >= sizeof(des_cblock)) 80 if (length >= sizeof(des_cblock))
78 memcpy(niv2,output[off],sizeof(des_cblock)); 81 memcpy(niv2,output[off],sizeof(des_cblock));
79 } 82 }
@@ -81,11 +84,14 @@ void des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length,
81 { 84 {
82 if (length >= sizeof(des_cblock)) 85 if (length >= sizeof(des_cblock))
83 memcpy(niv2,input[off],sizeof(des_cblock)); 86 memcpy(niv2,input[off],sizeof(des_cblock));
84 des_cbc_encrypt(input,output,l8,ks1,iv2,enc); 87 des_cbc_encrypt((unsigned char*)input,
85 des_cbc_encrypt(output,output,l8,ks2,iv1,!enc); 88 (unsigned char*)output,l8,ks1,iv2,enc);
89 des_cbc_encrypt((unsigned char*)output,
90 (unsigned char*)output,l8,ks2,iv1,!enc);
86 if (length >= sizeof(des_cblock)) 91 if (length >= sizeof(des_cblock))
87 memcpy(niv1,output[off],sizeof(des_cblock)); 92 memcpy(niv1,output[off],sizeof(des_cblock));
88 des_cbc_encrypt(output,output,length,ks1,iv1, enc); 93 des_cbc_encrypt((unsigned char*)output,
94 (unsigned char*)output,length,ks1,iv1,enc);
89 } 95 }
90 memcpy(*iv1,niv1,sizeof(des_cblock)); 96 memcpy(*iv1,niv1,sizeof(des_cblock));
91 memcpy(*iv2,niv2,sizeof(des_cblock)); 97 memcpy(*iv2,niv2,sizeof(des_cblock));
diff --git a/src/lib/libcrypto/des/des.c b/src/lib/libcrypto/des/des.c
index b2d7f0da78..91d7153b34 100644
--- a/src/lib/libcrypto/des/des.c
+++ b/src/lib/libcrypto/des/des.c
@@ -325,25 +325,25 @@ void usage(void)
325"des <options> [input-file [output-file]]", 325"des <options> [input-file [output-file]]",
326"options:", 326"options:",
327"-v : des(1) version number", 327"-v : des(1) version number",
328"-e : encrypt using sunOS compatible user key to DES key conversion.", 328"-e : encrypt using SunOS compatible user key to DES key conversion.",
329"-E : encrypt ", 329"-E : encrypt ",
330"-d : decrypt using sunOS compatible user key to DES key conversion.", 330"-d : decrypt using SunOS compatible user key to DES key conversion.",
331"-D : decrypt ", 331"-D : decrypt ",
332"-c[ckname] : generate a cbc_cksum using sunOS compatible user key to", 332"-c[ckname] : generate a cbc_cksum using SunOS compatible user key to",
333" DES key conversion and output to ckname (stdout default,", 333" DES key conversion and output to ckname (stdout default,",
334" stderr if data being output on stdout). The checksum is", 334" stderr if data being output on stdout). The checksum is",
335" generated before encryption and after decryption if used", 335" generated before encryption and after decryption if used",
336" in conjunction with -[eEdD].", 336" in conjunction with -[eEdD].",
337"-C[ckname] : generate a cbc_cksum as for -c but compatible with -[ED].", 337"-C[ckname] : generate a cbc_cksum as for -c but compatible with -[ED].",
338"-k key : use key 'key'", 338"-k key : use key 'key'",
339"-h : the key that is entered will be a hexidecimal number", 339"-h : the key that is entered will be a hexadecimal number",
340" that is used directly as the des key", 340" that is used directly as the des key",
341"-u[uuname] : input file is uudecoded if -[dD] or output uuencoded data if -[eE]", 341"-u[uuname] : input file is uudecoded if -[dD] or output uuencoded data if -[eE]",
342" (uuname is the filename to put in the uuencode header).", 342" (uuname is the filename to put in the uuencode header).",
343"-b : encrypt using DES in ecb encryption mode, the defaut is cbc mode.", 343"-b : encrypt using DES in ecb encryption mode, the default is cbc mode.",
344"-3 : encrypt using tripple DES encryption. This uses 2 keys", 344"-3 : encrypt using triple DES encryption. This uses 2 keys",
345" generated from the input key. If the input key is less", 345" generated from the input key. If the input key is less",
346" than 8 characters long, this is equivelent to normal", 346" than 8 characters long, this is equivalent to normal",
347" encryption. Default is triple cbc, -b makes it triple ecb.", 347" encryption. Default is triple cbc, -b makes it triple ecb.",
348NULL 348NULL
349}; 349};
@@ -425,7 +425,7 @@ void doencryption(void)
425 else 425 else
426 k2[i-8]=k; 426 k2[i-8]=k;
427 } 427 }
428 des_set_key(&k2,ks2); 428 des_set_key_unchecked(&k2,ks2);
429 memset(k2,0,sizeof(k2)); 429 memset(k2,0,sizeof(k2));
430 } 430 }
431 else if (longk || flag3) 431 else if (longk || flag3)
@@ -433,7 +433,7 @@ void doencryption(void)
433 if (flag3) 433 if (flag3)
434 { 434 {
435 des_string_to_2keys(key,&kk,&k2); 435 des_string_to_2keys(key,&kk,&k2);
436 des_set_key(&k2,ks2); 436 des_set_key_unchecked(&k2,ks2);
437 memset(k2,0,sizeof(k2)); 437 memset(k2,0,sizeof(k2));
438 } 438 }
439 else 439 else
@@ -455,7 +455,7 @@ void doencryption(void)
455 kk[i]=key[i]|0x80; 455 kk[i]=key[i]|0x80;
456 } 456 }
457 457
458 des_set_key(&kk,ks); 458 des_set_key_unchecked(&kk,ks);
459 memset(key,0,sizeof(key)); 459 memset(key,0,sizeof(key));
460 memset(kk,0,sizeof(kk)); 460 memset(kk,0,sizeof(kk));
461 /* woops - A bug that does not showup under unix :-( */ 461 /* woops - A bug that does not showup under unix :-( */
@@ -484,7 +484,7 @@ void doencryption(void)
484 if (feof(DES_IN)) 484 if (feof(DES_IN))
485 { 485 {
486 for (i=7-rem; i>0; i--) 486 for (i=7-rem; i>0; i--)
487 RAND_bytes(buf + l++, 1); 487 RAND_pseudo_bytes(buf + l++, 1);
488 buf[l++]=rem; 488 buf[l++]=rem;
489 ex=1; 489 ex=1;
490 len+=rem; 490 len+=rem;
diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h
index 67f90aaf17..98a9c4127c 100644
--- a/src/lib/libcrypto/des/des.h
+++ b/src/lib/libcrypto/des/des.h
@@ -186,15 +186,20 @@ void des_pcbc_encrypt(const unsigned char *input,unsigned char *output,
186DES_LONG des_quad_cksum(const unsigned char *input,des_cblock output[], 186DES_LONG des_quad_cksum(const unsigned char *input,des_cblock output[],
187 long length,int out_count,des_cblock *seed); 187 long length,int out_count,des_cblock *seed);
188void des_random_seed(des_cblock *key); 188void des_random_seed(des_cblock *key);
189void des_random_key(des_cblock *ret); 189int des_random_key(des_cblock *ret);
190int des_read_password(des_cblock *key,const char *prompt,int verify); 190int des_read_password(des_cblock *key,const char *prompt,int verify);
191int des_read_2passwords(des_cblock *key1,des_cblock *key2, 191int des_read_2passwords(des_cblock *key1,des_cblock *key2,
192 const char *prompt,int verify); 192 const char *prompt,int verify);
193int des_read_pw_string(char *buf,int length,const char *prompt,int verify); 193int des_read_pw_string(char *buf,int length,const char *prompt,int verify);
194void des_set_odd_parity(des_cblock *key); 194void des_set_odd_parity(des_cblock *key);
195int des_is_weak_key(const_des_cblock *key); 195int des_is_weak_key(const_des_cblock *key);
196/* des_set_key (= set_key = des_key_sched = key_sched) calls
197 * des_set_key_checked if global variable des_check_key is set,
198 * des_set_key_unchecked otherwise. */
196int des_set_key(const_des_cblock *key,des_key_schedule schedule); 199int des_set_key(const_des_cblock *key,des_key_schedule schedule);
197int des_key_sched(const_des_cblock *key,des_key_schedule schedule); 200int des_key_sched(const_des_cblock *key,des_key_schedule schedule);
201int des_set_key_checked(const_des_cblock *key,des_key_schedule schedule);
202void des_set_key_unchecked(const_des_cblock *key,des_key_schedule schedule);
198void des_string_to_key(const char *str,des_cblock *key); 203void des_string_to_key(const char *str,des_cblock *key);
199void des_string_to_2keys(const char *str,des_cblock *key1,des_cblock *key2); 204void des_string_to_2keys(const char *str,des_cblock *key1,des_cblock *key2);
200void des_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length, 205void des_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h
index d6ea17cb68..4dfed199a7 100644
--- a/src/lib/libcrypto/des/des_locl.h
+++ b/src/lib/libcrypto/des/des_locl.h
@@ -72,7 +72,11 @@
72 72
73#ifndef MSDOS 73#ifndef MSDOS
74#if !defined(VMS) || defined(__DECC) 74#if !defined(VMS) || defined(__DECC)
75#include OPENSSL_UNISTD 75#ifdef OPENSSL_UNISTD
76# include OPENSSL_UNISTD
77#else
78# include <unistd.h>
79#endif
76#include <math.h> 80#include <math.h>
77#endif 81#endif
78#endif 82#endif
@@ -178,14 +182,14 @@
178#endif 182#endif
179 183
180/* The changes to this macro may help or hinder, depending on the 184/* The changes to this macro may help or hinder, depending on the
181 * compiler and the achitecture. gcc2 always seems to do well :-). 185 * compiler and the architecture. gcc2 always seems to do well :-).
182 * Inspired by Dana How <how@isl.stanford.edu> 186 * Inspired by Dana How <how@isl.stanford.edu>
183 * DO NOT use the alternative version on machines with 8 byte longs. 187 * DO NOT use the alternative version on machines with 8 byte longs.
184 * It does not seem to work on the Alpha, even when DES_LONG is 4 188 * It does not seem to work on the Alpha, even when DES_LONG is 4
185 * bytes, probably an issue of accessing non-word aligned objects :-( */ 189 * bytes, probably an issue of accessing non-word aligned objects :-( */
186#ifdef DES_PTR 190#ifdef DES_PTR
187 191
188/* It recently occured to me that 0^0^0^0^0^0^0 == 0, so there 192/* It recently occurred to me that 0^0^0^0^0^0^0 == 0, so there
189 * is no reason to not xor all the sub items together. This potentially 193 * is no reason to not xor all the sub items together. This potentially
190 * saves a register since things can be xored directly into L */ 194 * saves a register since things can be xored directly into L */
191 195
diff --git a/src/lib/libcrypto/des/des_opts.c b/src/lib/libcrypto/des/des_opts.c
index 746c456f8f..b2ca7ac31d 100644
--- a/src/lib/libcrypto/des/des_opts.c
+++ b/src/lib/libcrypto/des/des_opts.c
@@ -434,17 +434,17 @@ int main(int argc, char **argv)
434 } 434 }
435 435
436#ifndef TIMES 436#ifndef TIMES
437 fprintf(stderr,"To get the most acurate results, try to run this\n"); 437 fprintf(stderr,"To get the most accurate results, try to run this\n");
438 fprintf(stderr,"program when this computer is idle.\n"); 438 fprintf(stderr,"program when this computer is idle.\n");
439#endif 439#endif
440 440
441 des_set_key(&key,sch); 441 des_set_key_unchecked(&key,sch);
442 des_set_key(&key2,sch2); 442 des_set_key_unchecked(&key2,sch2);
443 des_set_key(&key3,sch3); 443 des_set_key_unchecked(&key3,sch3);
444 444
445#ifndef SIGALRM 445#ifndef SIGALRM
446 fprintf(stderr,"First we calculate the approximate speed ...\n"); 446 fprintf(stderr,"First we calculate the approximate speed ...\n");
447 des_set_key(&key,sch); 447 des_set_key_unchecked(&key,sch);
448 count=10; 448 count=10;
449 do { 449 do {
450 long i; 450 long i;
diff --git a/src/lib/libcrypto/des/destest.c b/src/lib/libcrypto/des/destest.c
index 5a04fc9298..9ad4ecb072 100644
--- a/src/lib/libcrypto/des/destest.c
+++ b/src/lib/libcrypto/des/destest.c
@@ -234,7 +234,7 @@ static unsigned char cipher_ecb2[NUM_TESTS-1][8]={
234 {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}}; 234 {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}};
235 235
236static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; 236static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
237static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; 237static unsigned char cbc2_key[8]={0xf1,0xe0,0xd3,0xc2,0xb5,0xa4,0x97,0x86};
238static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; 238static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
239static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; 239static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
240/* Changed the following text constant to binary so it will work on ebcdic 240/* Changed the following text constant to binary so it will work on ebcdic
@@ -254,12 +254,24 @@ static unsigned char cbc_ok[32]={
254 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68, 254 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68,
255 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; 255 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
256 256
257#ifdef SCREW_THE_PARITY
258#error "SCREW_THE_PARITY is not ment to be defined."
259#error "Original vectors are preserved for reference only."
260static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
257static unsigned char xcbc_ok[32]={ 261static unsigned char xcbc_ok[32]={
258 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48, 262 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48,
259 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD, 263 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD,
260 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76, 264 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76,
261 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2, 265 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2,
262 }; 266 };
267#else
268static unsigned char xcbc_ok[32]={
269 0x84,0x6B,0x29,0x14,0x85,0x1E,0x9A,0x29,
270 0x54,0x73,0x2F,0x8A,0xA0,0xA6,0x11,0xC1,
271 0x15,0xCD,0xC2,0xD7,0x95,0x1B,0x10,0x53,
272 0xA6,0x3C,0x5E,0x03,0xB2,0x1A,0xA3,0xC4,
273 };
274#endif
263 275
264static unsigned char cbc3_ok[32]={ 276static unsigned char cbc3_ok[32]={
265 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0, 277 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0,
@@ -309,8 +321,8 @@ static unsigned char ofb_cipher[24]=
309 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3 321 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3
310 }; 322 };
311 323
312DES_LONG cbc_cksum_ret=0xB462FEF7L; 324static DES_LONG cbc_cksum_ret=0xB462FEF7L;
313unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; 325static unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
314 326
315static char *pt(unsigned char *p); 327static char *pt(unsigned char *p);
316static int cfb_test(int bits, unsigned char *cfb_cipher); 328static int cfb_test(int bits, unsigned char *cfb_cipher);
@@ -331,17 +343,17 @@ int main(int argc, char *argv[])
331 343
332#ifndef NO_DESCBCM 344#ifndef NO_DESCBCM
333 printf("Doing cbcm\n"); 345 printf("Doing cbcm\n");
334 if ((j=des_key_sched(&cbc_key,ks)) != 0) 346 if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
335 { 347 {
336 printf("Key error %d\n",j); 348 printf("Key error %d\n",j);
337 err=1; 349 err=1;
338 } 350 }
339 if ((j=des_key_sched(&cbc2_key,ks2)) != 0) 351 if ((j=des_set_key_checked(&cbc2_key,ks2)) != 0)
340 { 352 {
341 printf("Key error %d\n",j); 353 printf("Key error %d\n",j);
342 err=1; 354 err=1;
343 } 355 }
344 if ((j=des_key_sched(&cbc3_key,ks3)) != 0) 356 if ((j=des_set_key_checked(&cbc3_key,ks3)) != 0)
345 { 357 {
346 printf("Key error %d\n",j); 358 printf("Key error %d\n",j);
347 err=1; 359 err=1;
@@ -385,11 +397,7 @@ int main(int argc, char *argv[])
385 printf("Doing ecb\n"); 397 printf("Doing ecb\n");
386 for (i=0; i<NUM_TESTS; i++) 398 for (i=0; i<NUM_TESTS; i++)
387 { 399 {
388 if ((j=des_key_sched(&key_data[i],ks)) != 0) 400 des_set_key_unchecked(&key_data[i],ks);
389 {
390 printf("Key error %2d:%d\n",i+1,j);
391 err=1;
392 }
393 memcpy(in,plain_data[i],8); 401 memcpy(in,plain_data[i],8);
394 memset(out,0,8); 402 memset(out,0,8);
395 memset(outin,0,8); 403 memset(outin,0,8);
@@ -415,21 +423,9 @@ int main(int argc, char *argv[])
415 printf("Doing ede ecb\n"); 423 printf("Doing ede ecb\n");
416 for (i=0; i<(NUM_TESTS-1); i++) 424 for (i=0; i<(NUM_TESTS-1); i++)
417 { 425 {
418 if ((j=des_key_sched(&key_data[i],ks)) != 0) 426 des_set_key_unchecked(&key_data[i],ks);
419 { 427 des_set_key_unchecked(&key_data[i+1],ks2);
420 err=1; 428 des_set_key_unchecked(&key_data[i+2],ks3);
421 printf("Key error %2d:%d\n",i+1,j);
422 }
423 if ((j=des_key_sched(&key_data[i+1],ks2)) != 0)
424 {
425 printf("Key error %2d:%d\n",i+2,j);
426 err=1;
427 }
428 if ((j=des_key_sched(&key_data[i+2],ks3)) != 0)
429 {
430 printf("Key error %2d:%d\n",i+3,j);
431 err=1;
432 }
433 memcpy(in,plain_data[i],8); 429 memcpy(in,plain_data[i],8);
434 memset(out,0,8); 430 memset(out,0,8);
435 memset(outin,0,8); 431 memset(outin,0,8);
@@ -453,7 +449,7 @@ int main(int argc, char *argv[])
453#endif 449#endif
454 450
455 printf("Doing cbc\n"); 451 printf("Doing cbc\n");
456 if ((j=des_key_sched(&cbc_key,ks)) != 0) 452 if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
457 { 453 {
458 printf("Key error %d\n",j); 454 printf("Key error %d\n",j);
459 err=1; 455 err=1;
@@ -464,7 +460,10 @@ int main(int argc, char *argv[])
464 des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks, 460 des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
465 &iv3,DES_ENCRYPT); 461 &iv3,DES_ENCRYPT);
466 if (memcmp(cbc_out,cbc_ok,32) != 0) 462 if (memcmp(cbc_out,cbc_ok,32) != 0)
463 {
467 printf("cbc_encrypt encrypt error\n"); 464 printf("cbc_encrypt encrypt error\n");
465 err=1;
466 }
468 467
469 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 468 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
470 des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks, 469 des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
@@ -477,7 +476,7 @@ int main(int argc, char *argv[])
477 476
478#ifndef LIBDES_LIT 477#ifndef LIBDES_LIT
479 printf("Doing desx cbc\n"); 478 printf("Doing desx cbc\n");
480 if ((j=des_key_sched(&cbc_key,ks)) != 0) 479 if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
481 { 480 {
482 printf("Key error %d\n",j); 481 printf("Key error %d\n",j);
483 err=1; 482 err=1;
@@ -490,6 +489,7 @@ int main(int argc, char *argv[])
490 if (memcmp(cbc_out,xcbc_ok,32) != 0) 489 if (memcmp(cbc_out,xcbc_ok,32) != 0)
491 { 490 {
492 printf("des_xcbc_encrypt encrypt error\n"); 491 printf("des_xcbc_encrypt encrypt error\n");
492 err=1;
493 } 493 }
494 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 494 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
495 des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks, 495 des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
@@ -502,17 +502,17 @@ int main(int argc, char *argv[])
502#endif 502#endif
503 503
504 printf("Doing ede cbc\n"); 504 printf("Doing ede cbc\n");
505 if ((j=des_key_sched(&cbc_key,ks)) != 0) 505 if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
506 { 506 {
507 printf("Key error %d\n",j); 507 printf("Key error %d\n",j);
508 err=1; 508 err=1;
509 } 509 }
510 if ((j=des_key_sched(&cbc2_key,ks2)) != 0) 510 if ((j=des_set_key_checked(&cbc2_key,ks2)) != 0)
511 { 511 {
512 printf("Key error %d\n",j); 512 printf("Key error %d\n",j);
513 err=1; 513 err=1;
514 } 514 }
515 if ((j=des_key_sched(&cbc3_key,ks3)) != 0) 515 if ((j=des_set_key_checked(&cbc3_key,ks3)) != 0)
516 { 516 {
517 printf("Key error %d\n",j); 517 printf("Key error %d\n",j);
518 err=1; 518 err=1;
@@ -543,7 +543,7 @@ int main(int argc, char *argv[])
543 543
544#ifndef LIBDES_LIT 544#ifndef LIBDES_LIT
545 printf("Doing pcbc\n"); 545 printf("Doing pcbc\n");
546 if ((j=des_key_sched(&cbc_key,ks)) != 0) 546 if ((j=des_set_key_checked(&cbc_key,ks)) != 0)
547 { 547 {
548 printf("Key error %d\n",j); 548 printf("Key error %d\n",j);
549 err=1; 549 err=1;
@@ -606,7 +606,7 @@ int main(int argc, char *argv[])
606 printf("done\n"); 606 printf("done\n");
607 607
608 printf("Doing ofb\n"); 608 printf("Doing ofb\n");
609 des_key_sched(&ofb_key,ks); 609 des_set_key_checked(&ofb_key,ks);
610 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 610 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
611 des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp); 611 des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp);
612 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) 612 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
@@ -635,7 +635,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
635 } 635 }
636 636
637 printf("Doing ofb64\n"); 637 printf("Doing ofb64\n");
638 des_key_sched(&ofb_key,ks); 638 des_set_key_checked(&ofb_key,ks);
639 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 639 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
640 memset(ofb_buf1,0,sizeof(ofb_buf1)); 640 memset(ofb_buf1,0,sizeof(ofb_buf1));
641 memset(ofb_buf2,0,sizeof(ofb_buf1)); 641 memset(ofb_buf2,0,sizeof(ofb_buf1));
@@ -660,7 +660,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
660 } 660 }
661 661
662 printf("Doing ede_ofb64\n"); 662 printf("Doing ede_ofb64\n");
663 des_key_sched(&ofb_key,ks); 663 des_set_key_checked(&ofb_key,ks);
664 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 664 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
665 memset(ofb_buf1,0,sizeof(ofb_buf1)); 665 memset(ofb_buf1,0,sizeof(ofb_buf1));
666 memset(ofb_buf2,0,sizeof(ofb_buf1)); 666 memset(ofb_buf2,0,sizeof(ofb_buf1));
@@ -686,7 +686,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
686 } 686 }
687 687
688 printf("Doing cbc_cksum\n"); 688 printf("Doing cbc_cksum\n");
689 des_key_sched(&cbc_key,ks); 689 des_set_key_checked(&cbc_key,ks);
690 cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv); 690 cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv);
691 if (cs != cbc_cksum_ret) 691 if (cs != cbc_cksum_ret)
692 { 692 {
@@ -795,8 +795,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
795 err=1; 795 err=1;
796 } 796 }
797 printf("\n"); 797 printf("\n");
798 exit(err); 798 return(err);
799 return(0);
800 } 799 }
801 800
802static char *pt(unsigned char *p) 801static char *pt(unsigned char *p)
@@ -825,7 +824,7 @@ static int cfb_test(int bits, unsigned char *cfb_cipher)
825 des_key_schedule ks; 824 des_key_schedule ks;
826 int i,err=0; 825 int i,err=0;
827 826
828 des_key_sched(&cfb_key,ks); 827 des_set_key_checked(&cfb_key,ks);
829 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 828 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
830 des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp, 829 des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp,
831 DES_ENCRYPT); 830 DES_ENCRYPT);
@@ -854,7 +853,7 @@ static int cfb64_test(unsigned char *cfb_cipher)
854 des_key_schedule ks; 853 des_key_schedule ks;
855 int err=0,i,n; 854 int err=0,i,n;
856 855
857 des_key_sched(&cfb_key,ks); 856 des_set_key_checked(&cfb_key,ks);
858 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 857 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
859 n=0; 858 n=0;
860 des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT); 859 des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT);
@@ -887,7 +886,7 @@ static int ede_cfb64_test(unsigned char *cfb_cipher)
887 des_key_schedule ks; 886 des_key_schedule ks;
888 int err=0,i,n; 887 int err=0,i,n;
889 888
890 des_key_sched(&cfb_key,ks); 889 des_set_key_checked(&cfb_key,ks);
891 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 890 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
892 n=0; 891 n=0;
893 des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n, 892 des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n,
diff --git a/src/lib/libcrypto/des/enc_read.c b/src/lib/libcrypto/des/enc_read.c
index 694970ccd2..7399ff7269 100644
--- a/src/lib/libcrypto/des/enc_read.c
+++ b/src/lib/libcrypto/des/enc_read.c
@@ -147,7 +147,7 @@ int des_enc_read(int fd, void *buf, int len, des_key_schedule sched,
147 /* first - get the length */ 147 /* first - get the length */
148 while (net_num < HDRSIZE) 148 while (net_num < HDRSIZE)
149 { 149 {
150 i=read(fd,&(net[net_num]),HDRSIZE-net_num); 150 i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
151#ifdef EINTR 151#ifdef EINTR
152 if ((i == -1) && (errno == EINTR)) continue; 152 if ((i == -1) && (errno == EINTR)) continue;
153#endif 153#endif
@@ -169,7 +169,7 @@ int des_enc_read(int fd, void *buf, int len, des_key_schedule sched,
169 net_num=0; 169 net_num=0;
170 while (net_num < rnum) 170 while (net_num < rnum)
171 { 171 {
172 i=read(fd,&(net[net_num]),rnum-net_num); 172 i=read(fd,(void *)&(net[net_num]),rnum-net_num);
173#ifdef EINTR 173#ifdef EINTR
174 if ((i == -1) && (errno == EINTR)) continue; 174 if ((i == -1) && (errno == EINTR)) continue;
175#endif 175#endif
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c
index ba3f0822ef..4d3452724e 100644
--- a/src/lib/libcrypto/des/enc_writ.c
+++ b/src/lib/libcrypto/des/enc_writ.c
@@ -130,12 +130,12 @@ int des_enc_write(int fd, const void *_buf, int len,
130 { 130 {
131 cp=shortbuf; 131 cp=shortbuf;
132 memcpy(shortbuf,buf,len); 132 memcpy(shortbuf,buf,len);
133 RAND_bytes(shortbuf+len, 8-len); 133 RAND_pseudo_bytes(shortbuf+len, 8-len);
134 rnum=8; 134 rnum=8;
135 } 135 }
136 else 136 else
137 { 137 {
138 cp=(unsigned char*)buf; 138 cp=buf;
139 rnum=((len+7)/8*8); /* round up to nearest eight */ 139 rnum=((len+7)/8*8); /* round up to nearest eight */
140 } 140 }
141 141
@@ -152,13 +152,16 @@ int des_enc_write(int fd, const void *_buf, int len,
152 for (j=0; j<outnum; j+=i) 152 for (j=0; j<outnum; j+=i)
153 { 153 {
154 /* eay 26/08/92 I was not doing writing from where we 154 /* eay 26/08/92 I was not doing writing from where we
155 * got upto. */ 155 * got up to. */
156 i=write(fd,&(outbuf[j]),outnum-j); 156 i=write(fd,(void *)&(outbuf[j]),outnum-j);
157 if (i == -1) 157 if (i == -1)
158 { 158 {
159#ifdef EINTR
159 if (errno == EINTR) 160 if (errno == EINTR)
160 i=0; 161 i=0;
161 else /* This is really a bad error - very bad 162 else
163#endif
164 /* This is really a bad error - very bad
162 * It will stuff-up both ends. */ 165 * It will stuff-up both ends. */
163 return(-1); 166 return(-1);
164 } 167 }
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c
index f36746b376..fa1b8aa34a 100644
--- a/src/lib/libcrypto/des/fcrypt.c
+++ b/src/lib/libcrypto/des/fcrypt.c
@@ -1,7 +1,7 @@
1/* NOCW */ 1/* NOCW */
2#include <stdio.h> 2#include <stdio.h>
3 3
4/* This version of crypt has been developed from my MIT compatable 4/* This version of crypt has been developed from my MIT compatible
5 * DES library. 5 * DES library.
6 * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au 6 * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au
7 * Eric Young (eay@cryptsoft.com) 7 * Eric Young (eay@cryptsoft.com)
@@ -11,7 +11,7 @@
11 * I have included directive PARA for shared memory computers. 11 * I have included directive PARA for shared memory computers.
12 * I have included a directive LONGCRYPT to using this routine to cipher 12 * I have included a directive LONGCRYPT to using this routine to cipher
13 * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN 13 * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN
14 * definition is the maximum of lenght of password and can changed. I have 14 * definition is the maximum of length of password and can changed. I have
15 * defined 24. 15 * defined 24.
16 */ 16 */
17 17
@@ -103,8 +103,8 @@ char *ret;
103 * returns *\0XXXXXXXXX 103 * returns *\0XXXXXXXXX
104 * The \0 makes the string look like * so the pwd "*" would 104 * The \0 makes the string look like * so the pwd "*" would
105 * crypt to "*". This was found when replacing the crypt in 105 * crypt to "*". This was found when replacing the crypt in
106 * our shared libraries. People found that the disbled 106 * our shared libraries. People found that the disabled
107 * accounts effectivly had no passwd :-(. */ 107 * accounts effectively had no passwd :-(. */
108 x=ret[0]=((salt[0] == '\0')?'A':salt[0]); 108 x=ret[0]=((salt[0] == '\0')?'A':salt[0]);
109 Eswap0=con_salt[x]<<2; 109 Eswap0=con_salt[x]<<2;
110 x=ret[1]=((salt[1] == '\0')?'A':salt[1]); 110 x=ret[1]=((salt[1] == '\0')?'A':salt[1]);
@@ -123,7 +123,7 @@ r=(r+7)/8;
123 for (; i<8; i++) 123 for (; i<8; i++)
124 key[i]=0; 124 key[i]=0;
125 125
126 des_set_key((des_cblock *)(key),ks); 126 des_set_key_unchecked(&key,ks);
127 fcrypt_body(&(out[0]),ks,Eswap0,Eswap1); 127 fcrypt_body(&(out[0]),ks,Eswap0,Eswap1);
128 128
129 ll=out[0]; l2c(ll,b); 129 ll=out[0]; l2c(ll,b);
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c
index 9cbea97c1f..83c94054e3 100644
--- a/src/lib/libcrypto/des/fcrypt_b.c
+++ b/src/lib/libcrypto/des/fcrypt_b.c
@@ -58,7 +58,7 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60 60
61/* This version of crypt has been developed from my MIT compatable 61/* This version of crypt has been developed from my MIT compatible
62 * DES library. 62 * DES library.
63 * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au 63 * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au
64 * Eric Young (eay@cryptsoft.com) 64 * Eric Young (eay@cryptsoft.com)
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c
index fc11792cda..7816a8f25c 100644
--- a/src/lib/libcrypto/des/rand_key.c
+++ b/src/lib/libcrypto/des/rand_key.c
@@ -1,114 +1,69 @@
1/* crypto/des/rand_key.c */ 1/* crypto/des/rand_key.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@openssl.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
57 */ 54 */
58 55
59#include "des_locl.h" 56#include <openssl/des.h>
60#include <time.h> 57#include <openssl/rand.h>
61
62static int seed=0;
63static des_cblock init;
64 58
65void des_random_seed(des_cblock *key) 59void des_random_seed(des_cblock *key)
66 { 60 {
67 memcpy(&init,key,sizeof(des_cblock)); 61 RAND_seed(key, sizeof(des_cblock));
68 seed=1;
69 } 62 }
70 63
71void des_random_key(des_cblock *ret) 64int des_random_key(des_cblock *ret)
72 { 65 {
73 des_key_schedule ks; 66 int r = RAND_bytes((unsigned char *)ret, sizeof(des_cblock));
74 static DES_LONG c=0; 67 des_set_odd_parity(ret);
75 static unsigned short pid=0; 68 return r;
76 static des_cblock data={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
77 des_cblock key;
78 unsigned char *p;
79 DES_LONG t;
80 int i;
81
82#ifdef MSDOS
83 pid=1;
84#else
85 if (!pid) pid=getpid();
86#endif
87 p=key;
88 if (seed)
89 {
90 for (i=0; i<8; i++)
91 {
92 data[i] ^= init[i];
93 init[i]=0;
94 }
95 seed=0;
96 }
97 t=(DES_LONG)time(NULL);
98 l2c(t,p);
99 t=(DES_LONG)((pid)|((c++)<<16));
100 l2c(t,p);
101
102 des_set_odd_parity(&data);
103 des_set_key(&data,ks);
104 des_cbc_cksum(key,&key,sizeof(key),ks,&data);
105
106 des_set_odd_parity(&key);
107 des_set_key(&key,ks);
108 des_cbc_cksum(key,&data,sizeof(key),ks,&key);
109
110 memcpy(ret,data,sizeof(key));
111 memset(key,0,sizeof(key));
112 memset(ks,0,sizeof(ks));
113 t=0;
114 } 69 }
diff --git a/src/lib/libcrypto/des/read_pwd.c b/src/lib/libcrypto/des/read_pwd.c
index fed49652c0..fa2d67da64 100644
--- a/src/lib/libcrypto/des/read_pwd.c
+++ b/src/lib/libcrypto/des/read_pwd.c
@@ -58,7 +58,11 @@
58 58
59#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32) 59#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32)
60#include <openssl/opensslconf.h> 60#include <openssl/opensslconf.h>
61#include OPENSSL_UNISTD 61#ifdef OPENSSL_UNISTD
62# include OPENSSL_UNISTD
63#else
64# include <unistd.h>
65#endif
62/* If unistd.h defines _POSIX_VERSION, we conclude that we 66/* If unistd.h defines _POSIX_VERSION, we conclude that we
63 * are on a POSIX system and have sigaction and termios. */ 67 * are on a POSIX system and have sigaction and termios. */
64#if defined(_POSIX_VERSION) 68#if defined(_POSIX_VERSION)
@@ -123,7 +127,7 @@
123#undef SGTTY 127#undef SGTTY
124#endif 128#endif
125 129
126#if !defined(TERMIO) && !defined(TERMIOS) && !defined(VMS) && !defined(MSDOS) 130#if !defined(TERMIO) && !defined(TERMIOS) && !defined(VMS) && !defined(MSDOS) && !defined(MAC_OS_pre_X) && !defined(MAC_OS_GUSI_SOURCE)
127#undef TERMIOS 131#undef TERMIOS
128#undef TERMIO 132#undef TERMIO
129#define SGTTY 133#define SGTTY
@@ -153,7 +157,7 @@
153#define TTY_set(tty,data) ioctl(tty,TIOCSETP,data) 157#define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
154#endif 158#endif
155 159
156#if !defined(_LIBC) && !defined(MSDOS) && !defined(VMS) 160#if !defined(_LIBC) && !defined(MSDOS) && !defined(VMS) && !defined(MAC_OS_pre_X)
157#include <sys/ioctl.h> 161#include <sys/ioctl.h>
158#endif 162#endif
159 163
@@ -174,6 +178,15 @@ struct IOSB {
174 }; 178 };
175#endif 179#endif
176 180
181#if defined(MAC_OS_pre_X) || defined(MAC_OS_GUSI_SOURCE)
182/*
183 * This one needs work. As a matter of fact the code is unoperational
184 * and this is only a trick to get it compiled.
185 * <appro@fy.chalmers.se>
186 */
187#define TTY_STRUCT int
188#endif
189
177#ifndef NX509_SIG 190#ifndef NX509_SIG
178#define NX509_SIG 32 191#define NX509_SIG 32
179#endif 192#endif
diff --git a/src/lib/libcrypto/des/rpc_enc.c b/src/lib/libcrypto/des/rpc_enc.c
index c96c204147..32d96d5cae 100644
--- a/src/lib/libcrypto/des/rpc_enc.c
+++ b/src/lib/libcrypto/des/rpc_enc.c
@@ -66,7 +66,7 @@ int _des_crypt(char *buf, int len, struct desparams *desp)
66 des_key_schedule ks; 66 des_key_schedule ks;
67 int enc; 67 int enc;
68 68
69 des_set_key(&desp->des_key,ks); 69 des_set_key_unchecked(&desp->des_key,ks);
70 enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT; 70 enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT;
71 71
72 if (desp->des_mode == CBC) 72 if (desp->des_mode == CBC)
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c
index 52553a4c16..bbdc71ba6b 100644
--- a/src/lib/libcrypto/des/set_key.c
+++ b/src/lib/libcrypto/des/set_key.c
@@ -125,7 +125,7 @@ int des_is_weak_key(const_des_cblock *key)
125 int i; 125 int i;
126 126
127 for (i=0; i<NUM_WEAK_KEY; i++) 127 for (i=0; i<NUM_WEAK_KEY; i++)
128 /* Added == 0 to comparision, I obviously don't run 128 /* Added == 0 to comparison, I obviously don't run
129 * this section very often :-(, thanks to 129 * this section very often :-(, thanks to
130 * engineering@MorningStar.Com for the fix 130 * engineering@MorningStar.Com for the fix
131 * eay 93/06/29 131 * eay 93/06/29
@@ -145,11 +145,34 @@ int des_is_weak_key(const_des_cblock *key)
145#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ 145#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
146 (a)=(a)^(t)^(t>>(16-(n)))) 146 (a)=(a)^(t)^(t>>(16-(n))))
147 147
148int des_set_key(const_des_cblock *key, des_key_schedule schedule)
149 {
150 if (des_check_key)
151 {
152 return des_set_key_checked(key, schedule);
153 }
154 else
155 {
156 des_set_key_unchecked(key, schedule);
157 return 0;
158 }
159 }
160
148/* return 0 if key parity is odd (correct), 161/* return 0 if key parity is odd (correct),
149 * return -1 if key parity error, 162 * return -1 if key parity error,
150 * return -2 if illegal weak key. 163 * return -2 if illegal weak key.
151 */ 164 */
152int des_set_key(const_des_cblock *key, des_key_schedule schedule) 165int des_set_key_checked(const_des_cblock *key, des_key_schedule schedule)
166 {
167 if (!check_parity(key))
168 return(-1);
169 if (des_is_weak_key(key))
170 return(-2);
171 des_set_key_unchecked(key, schedule);
172 return 0;
173 }
174
175void des_set_key_unchecked(const_des_cblock *key, des_key_schedule schedule)
153 { 176 {
154 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0}; 177 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
155 register DES_LONG c,d,t,s,t2; 178 register DES_LONG c,d,t,s,t2;
@@ -157,15 +180,6 @@ int des_set_key(const_des_cblock *key, des_key_schedule schedule)
157 register DES_LONG *k; 180 register DES_LONG *k;
158 register int i; 181 register int i;
159 182
160 if (des_check_key)
161 {
162 if (!check_parity(key))
163 return(-1);
164
165 if (des_is_weak_key(key))
166 return(-2);
167 }
168
169 k = &schedule->ks.deslong[0]; 183 k = &schedule->ks.deslong[0];
170 in = &(*key)[0]; 184 in = &(*key)[0];
171 185
@@ -225,7 +239,6 @@ int des_set_key(const_des_cblock *key, des_key_schedule schedule)
225 t2=((s>>16L)|(t&0xffff0000L)); 239 t2=((s>>16L)|(t&0xffff0000L));
226 *(k++)=ROTATE(t2,26)&0xffffffffL; 240 *(k++)=ROTATE(t2,26)&0xffffffffL;
227 } 241 }
228 return(0);
229 } 242 }
230 243
231int des_key_sched(const_des_cblock *key, des_key_schedule schedule) 244int des_key_sched(const_des_cblock *key, des_key_schedule schedule)
diff --git a/src/lib/libcrypto/des/speed.c b/src/lib/libcrypto/des/speed.c
index da41abcb03..814b86f4ae 100644
--- a/src/lib/libcrypto/des/speed.c
+++ b/src/lib/libcrypto/des/speed.c
@@ -186,16 +186,16 @@ int main(int argc, char **argv)
186#endif 186#endif
187 187
188#ifndef TIMES 188#ifndef TIMES
189 printf("To get the most acurate results, try to run this\n"); 189 printf("To get the most accurate results, try to run this\n");
190 printf("program when this computer is idle.\n"); 190 printf("program when this computer is idle.\n");
191#endif 191#endif
192 192
193 des_set_key(&key2,sch2); 193 des_set_key_unchecked(&key2,sch2);
194 des_set_key(&key3,sch3); 194 des_set_key_unchecked(&key3,sch3);
195 195
196#ifndef SIGALRM 196#ifndef SIGALRM
197 printf("First we calculate the approximate speed ...\n"); 197 printf("First we calculate the approximate speed ...\n");
198 des_set_key(&key,sch); 198 des_set_key_unchecked(&key,sch);
199 count=10; 199 count=10;
200 do { 200 do {
201 long i; 201 long i;
@@ -225,7 +225,7 @@ int main(int argc, char **argv)
225 225
226 Time_F(START); 226 Time_F(START);
227 for (count=0,run=1; COND(ca); count++) 227 for (count=0,run=1; COND(ca); count++)
228 des_set_key(&key,sch); 228 des_set_key_unchecked(&key,sch);
229 d=Time_F(STOP); 229 d=Time_F(STOP);
230 printf("%ld set_key's in %.2f seconds\n",count,d); 230 printf("%ld set_key's in %.2f seconds\n",count,d);
231 a=((double)COUNT(ca))/d; 231 a=((double)COUNT(ca))/d;
diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c
index 24841452f1..c6abb87201 100644
--- a/src/lib/libcrypto/des/str2key.c
+++ b/src/lib/libcrypto/des/str2key.c
@@ -58,8 +58,6 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61OPENSSL_EXTERN int des_check_key;
62
63void des_string_to_key(const char *str, des_cblock *key) 61void des_string_to_key(const char *str, des_cblock *key)
64 { 62 {
65 des_key_schedule ks; 63 des_key_schedule ks;
@@ -88,11 +86,8 @@ void des_string_to_key(const char *str, des_cblock *key)
88 } 86 }
89#endif 87#endif
90 des_set_odd_parity(key); 88 des_set_odd_parity(key);
91 i=des_check_key; 89 des_set_key_unchecked(key,ks);
92 des_check_key=0; 90 des_cbc_cksum((const unsigned char*)str,key,length,ks,key);
93 des_set_key(key,ks);
94 des_check_key=i;
95 des_cbc_cksum((unsigned char*)str,key,length,ks,key);
96 memset(ks,0,sizeof(ks)); 91 memset(ks,0,sizeof(ks));
97 des_set_odd_parity(key); 92 des_set_odd_parity(key);
98 } 93 }
@@ -150,13 +145,10 @@ void des_string_to_2keys(const char *str, des_cblock *key1, des_cblock *key2)
150#endif 145#endif
151 des_set_odd_parity(key1); 146 des_set_odd_parity(key1);
152 des_set_odd_parity(key2); 147 des_set_odd_parity(key2);
153 i=des_check_key; 148 des_set_key_unchecked(key1,ks);
154 des_check_key=0; 149 des_cbc_cksum((const unsigned char*)str,key1,length,ks,key1);
155 des_set_key(key1,ks); 150 des_set_key_unchecked(key2,ks);
156 des_cbc_cksum((unsigned char*)str,key1,length,ks,key1); 151 des_cbc_cksum((const unsigned char*)str,key2,length,ks,key2);
157 des_set_key(key2,ks);
158 des_cbc_cksum((unsigned char*)str,key2,length,ks,key2);
159 des_check_key=i;
160 memset(ks,0,sizeof(ks)); 152 memset(ks,0,sizeof(ks));
161 des_set_odd_parity(key1); 153 des_set_odd_parity(key1);
162 des_set_odd_parity(key2); 154 des_set_odd_parity(key2);