summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des
diff options
context:
space:
mode:
authormarkus <>2002-09-05 12:51:50 +0000
committermarkus <>2002-09-05 12:51:50 +0000
commit15b5d84f9da2ce4bfae8580e56e34a859f74ad71 (patch)
treebf939e82d7fd73cc8a01cf6959002209972091bc /src/lib/libcrypto/des
parent027351f729b9e837200dae6e1520cda6577ab930 (diff)
downloadopenbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.gz
openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.bz2
openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.zip
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/des')
-rw-r--r--src/lib/libcrypto/des/asm/crypt586.pl12
-rw-r--r--src/lib/libcrypto/des/asm/des-586.pl30
-rw-r--r--src/lib/libcrypto/des/asm/desboth.pl16
-rw-r--r--src/lib/libcrypto/des/cbc_cksm.c18
-rw-r--r--src/lib/libcrypto/des/cbc_enc.c78
-rw-r--r--src/lib/libcrypto/des/cfb64ede.c39
-rw-r--r--src/lib/libcrypto/des/cfb64enc.c27
-rw-r--r--src/lib/libcrypto/des/cfb_enc.c18
-rw-r--r--src/lib/libcrypto/des/des.h303
-rw-r--r--src/lib/libcrypto/des/des_enc.c165
-rw-r--r--src/lib/libcrypto/des/des_locl.h89
-rw-r--r--src/lib/libcrypto/des/ecb3_enc.c20
-rw-r--r--src/lib/libcrypto/des/ecb_enc.c26
-rw-r--r--src/lib/libcrypto/des/ede_cbcm_enc.c24
-rw-r--r--src/lib/libcrypto/des/enc_read.c90
-rw-r--r--src/lib/libcrypto/des/enc_writ.c73
-rw-r--r--src/lib/libcrypto/des/fcrypt.c96
-rw-r--r--src/lib/libcrypto/des/fcrypt_b.c13
-rw-r--r--src/lib/libcrypto/des/ncbc_enc.c52
-rw-r--r--src/lib/libcrypto/des/ofb64ede.c32
-rw-r--r--src/lib/libcrypto/des/ofb64enc.c24
-rw-r--r--src/lib/libcrypto/des/ofb_enc.c16
-rw-r--r--src/lib/libcrypto/des/pcbc_enc.c23
-rw-r--r--src/lib/libcrypto/des/qud_cksm.c53
-rw-r--r--src/lib/libcrypto/des/rand_key.c162
-rw-r--r--src/lib/libcrypto/des/set_key.c273
-rw-r--r--src/lib/libcrypto/des/spr.h2
-rw-r--r--src/lib/libcrypto/des/str2key.c70
-rw-r--r--src/lib/libcrypto/des/xcbc_enc.c57
29 files changed, 917 insertions, 984 deletions
diff --git a/src/lib/libcrypto/des/asm/crypt586.pl b/src/lib/libcrypto/des/asm/crypt586.pl
index 297e38dec8..3d41d82f69 100644
--- a/src/lib/libcrypto/des/asm/crypt586.pl
+++ b/src/lib/libcrypto/des/asm/crypt586.pl
@@ -1,4 +1,4 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# 2#
3# The inner loop instruction sequence and the IP/FP modifications are from 3# The inner loop instruction sequence and the IP/FP modifications are from
4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> 4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
@@ -14,7 +14,7 @@ require "x86asm.pl";
14$L="edi"; 14$L="edi";
15$R="esi"; 15$R="esi";
16 16
17&external_label("des_SPtrans"); 17&external_label("DES_SPtrans");
18&fcrypt_body("fcrypt_body"); 18&fcrypt_body("fcrypt_body");
19&asm_finish(); 19&asm_finish();
20 20
@@ -22,7 +22,7 @@ sub fcrypt_body
22 { 22 {
23 local($name,$do_ip)=@_; 23 local($name,$do_ip)=@_;
24 24
25 &function_begin($name,"EXTRN _des_SPtrans:DWORD"); 25 &function_begin($name,"EXTRN _DES_SPtrans:DWORD");
26 26
27 &comment(""); 27 &comment("");
28 &comment("Load the 2 words"); 28 &comment("Load the 2 words");
@@ -32,18 +32,18 @@ sub fcrypt_body
32 &xor( $R, $R); 32 &xor( $R, $R);
33 &mov($ks,&wparam(1)); 33 &mov($ks,&wparam(1));
34 34
35 &push(25); # add a variable 35 &push(&DWC(25)); # add a variable
36 36
37 &set_label("start"); 37 &set_label("start");
38 for ($i=0; $i<16; $i+=2) 38 for ($i=0; $i<16; $i+=2)
39 { 39 {
40 &comment(""); 40 &comment("");
41 &comment("Round $i"); 41 &comment("Round $i");
42 &D_ENCRYPT($i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); 42 &D_ENCRYPT($i,$L,$R,$i*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx");
43 43
44 &comment(""); 44 &comment("");
45 &comment("Round ".sprintf("%d",$i+1)); 45 &comment("Round ".sprintf("%d",$i+1));
46 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); 46 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx");
47 } 47 }
48 &mov("ebx", &swtmp(0)); 48 &mov("ebx", &swtmp(0));
49 &mov("eax", $L); 49 &mov("eax", $L);
diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl
index 7f2e09fa7a..0d08e8a3a9 100644
--- a/src/lib/libcrypto/des/asm/des-586.pl
+++ b/src/lib/libcrypto/des/asm/des-586.pl
@@ -1,4 +1,4 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# 2#
3# The inner loop instruction sequence and the IP/FP modifications are from 3# The inner loop instruction sequence and the IP/FP modifications are from
4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> 4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
@@ -19,21 +19,21 @@ require "desboth.pl";
19$L="edi"; 19$L="edi";
20$R="esi"; 20$R="esi";
21 21
22&external_label("des_SPtrans"); 22&external_label("DES_SPtrans");
23&des_encrypt("des_encrypt",1); 23&DES_encrypt("DES_encrypt1",1);
24&des_encrypt("des_encrypt2",0); 24&DES_encrypt("DES_encrypt2",0);
25&des_encrypt3("des_encrypt3",1); 25&DES_encrypt3("DES_encrypt3",1);
26&des_encrypt3("des_decrypt3",0); 26&DES_encrypt3("DES_decrypt3",0);
27&cbc("des_ncbc_encrypt","des_encrypt","des_encrypt",0,4,5,3,5,-1); 27&cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1);
28&cbc("des_ede3_cbc_encrypt","des_encrypt3","des_decrypt3",0,6,7,3,4,5); 28&cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5);
29 29
30&asm_finish(); 30&asm_finish();
31 31
32sub des_encrypt 32sub DES_encrypt
33 { 33 {
34 local($name,$do_ip)=@_; 34 local($name,$do_ip)=@_;
35 35
36 &function_begin_B($name,"EXTRN _des_SPtrans:DWORD"); 36 &function_begin_B($name,"EXTRN _DES_SPtrans:DWORD");
37 37
38 &push("esi"); 38 &push("esi");
39 &push("edi"); 39 &push("edi");
@@ -80,11 +80,11 @@ sub des_encrypt
80 { 80 {
81 &comment(""); 81 &comment("");
82 &comment("Round $i"); 82 &comment("Round $i");
83 &D_ENCRYPT($i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); 83 &D_ENCRYPT($i,$L,$R,$i*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx");
84 84
85 &comment(""); 85 &comment("");
86 &comment("Round ".sprintf("%d",$i+1)); 86 &comment("Round ".sprintf("%d",$i+1));
87 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); 87 &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx");
88 } 88 }
89 &jmp(&label("end")); 89 &jmp(&label("end"));
90 90
@@ -94,10 +94,10 @@ sub des_encrypt
94 { 94 {
95 &comment(""); 95 &comment("");
96 &comment("Round $i"); 96 &comment("Round $i");
97 &D_ENCRYPT(15-$i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); 97 &D_ENCRYPT(15-$i,$L,$R,$i*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx");
98 &comment(""); 98 &comment("");
99 &comment("Round ".sprintf("%d",$i-1)); 99 &comment("Round ".sprintf("%d",$i-1));
100 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); 100 &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx");
101 } 101 }
102 102
103 &set_label("end"); 103 &set_label("end");
@@ -187,6 +187,8 @@ sub R_PERM_OP
187 &mov( $tt, $a ); 187 &mov( $tt, $a );
188 &xor( $a, $b ); 188 &xor( $a, $b );
189 &and( $a, $mask ); 189 &and( $a, $mask );
190 # This can never succeed, and besides it is difficult to see what the
191 # idea was - Ben 13 Feb 99
190 if (!$last eq $b) 192 if (!$last eq $b)
191 { 193 {
192 &xor( $b, $a ); 194 &xor( $b, $a );
diff --git a/src/lib/libcrypto/des/asm/desboth.pl b/src/lib/libcrypto/des/asm/desboth.pl
index 8f939953a6..eec00886e4 100644
--- a/src/lib/libcrypto/des/asm/desboth.pl
+++ b/src/lib/libcrypto/des/asm/desboth.pl
@@ -1,9 +1,9 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3$L="edi"; 3$L="edi";
4$R="esi"; 4$R="esi";
5 5
6sub des_encrypt3 6sub DES_encrypt3
7 { 7 {
8 local($name,$enc)=@_; 8 local($name,$enc)=@_;
9 9
@@ -44,18 +44,18 @@ sub des_encrypt3
44 &mov("edi",&wparam(2)); 44 &mov("edi",&wparam(2));
45 &mov("eax",&wparam(3)); 45 &mov("eax",&wparam(3));
46 } 46 }
47 &mov(&swtmp(2), (($enc)?"1":"0")); 47 &mov(&swtmp(2), (DWC(($enc)?"1":"0")));
48 &mov(&swtmp(1), "eax"); 48 &mov(&swtmp(1), "eax");
49 &mov(&swtmp(0), "ebx"); 49 &mov(&swtmp(0), "ebx");
50 &call("des_encrypt2"); 50 &call("DES_encrypt2");
51 &mov(&swtmp(2), (($enc)?"0":"1")); 51 &mov(&swtmp(2), (DWC(($enc)?"0":"1")));
52 &mov(&swtmp(1), "edi"); 52 &mov(&swtmp(1), "edi");
53 &mov(&swtmp(0), "ebx"); 53 &mov(&swtmp(0), "ebx");
54 &call("des_encrypt2"); 54 &call("DES_encrypt2");
55 &mov(&swtmp(2), (($enc)?"1":"0")); 55 &mov(&swtmp(2), (DWC(($enc)?"1":"0")));
56 &mov(&swtmp(1), "esi"); 56 &mov(&swtmp(1), "esi");
57 &mov(&swtmp(0), "ebx"); 57 &mov(&swtmp(0), "ebx");
58 &call("des_encrypt2"); 58 &call("DES_encrypt2");
59 59
60 &stack_pop(3); 60 &stack_pop(3);
61 &mov($L,&DWP(0,"ebx","",0)); 61 &mov($L,&DWP(0,"ebx","",0));
diff --git a/src/lib/libcrypto/des/cbc_cksm.c b/src/lib/libcrypto/des/cbc_cksm.c
index edfdec8a0f..6c5305b99d 100644
--- a/src/lib/libcrypto/des/cbc_cksm.c
+++ b/src/lib/libcrypto/des/cbc_cksm.c
@@ -58,21 +58,15 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61DES_LONG des_cbc_cksum(input, output, length, schedule, ivec) 61DES_LONG DES_cbc_cksum(const unsigned char *in, DES_cblock *output,
62des_cblock (*input); 62 long length, DES_key_schedule *schedule,
63des_cblock (*output); 63 const_DES_cblock *ivec)
64long length;
65des_key_schedule schedule;
66des_cblock (*ivec);
67 { 64 {
68 register DES_LONG tout0,tout1,tin0,tin1; 65 register DES_LONG tout0,tout1,tin0,tin1;
69 register long l=length; 66 register long l=length;
70 DES_LONG tin[2]; 67 DES_LONG tin[2];
71 unsigned char *in,*out,*iv; 68 unsigned char *out = &(*output)[0];
72 69 const unsigned char *iv = &(*ivec)[0];
73 in=(unsigned char *)input;
74 out=(unsigned char *)output;
75 iv=(unsigned char *)ivec;
76 70
77 c2l(iv,tout0); 71 c2l(iv,tout0);
78 c2l(iv,tout1); 72 c2l(iv,tout1);
@@ -88,7 +82,7 @@ des_cblock (*ivec);
88 82
89 tin0^=tout0; tin[0]=tin0; 83 tin0^=tout0; tin[0]=tin0;
90 tin1^=tout1; tin[1]=tin1; 84 tin1^=tout1; tin[1]=tin1;
91 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); 85 DES_encrypt1((DES_LONG *)tin,schedule,DES_ENCRYPT);
92 /* fix 15/10/91 eay - thanks to keithr@sco.COM */ 86 /* fix 15/10/91 eay - thanks to keithr@sco.COM */
93 tout0=tin[0]; 87 tout0=tin[0];
94 tout1=tin[1]; 88 tout1=tin[1];
diff --git a/src/lib/libcrypto/des/cbc_enc.c b/src/lib/libcrypto/des/cbc_enc.c
index a84a53633c..677903ae4e 100644
--- a/src/lib/libcrypto/des/cbc_enc.c
+++ b/src/lib/libcrypto/des/cbc_enc.c
@@ -56,80 +56,6 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "des_locl.h" 59#define CBC_ENC_C__DONT_UPDATE_IV
60
61void des_cbc_encrypt(input, output, length, schedule, ivec, enc)
62des_cblock (*input);
63des_cblock (*output);
64long length;
65des_key_schedule schedule;
66des_cblock (*ivec);
67int enc;
68 {
69 register DES_LONG tin0,tin1;
70 register DES_LONG tout0,tout1,xor0,xor1;
71 register unsigned char *in,*out;
72 register long l=length;
73 DES_LONG tin[2];
74 unsigned char *iv;
75
76 in=(unsigned char *)input;
77 out=(unsigned char *)output;
78 iv=(unsigned char *)ivec;
79
80 if (enc)
81 {
82 c2l(iv,tout0);
83 c2l(iv,tout1);
84 for (l-=8; l>=0; l-=8)
85 {
86 c2l(in,tin0);
87 c2l(in,tin1);
88 tin0^=tout0; tin[0]=tin0;
89 tin1^=tout1; tin[1]=tin1;
90 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
91 tout0=tin[0]; l2c(tout0,out);
92 tout1=tin[1]; l2c(tout1,out);
93 }
94 if (l != -8)
95 {
96 c2ln(in,tin0,tin1,l+8);
97 tin0^=tout0; tin[0]=tin0;
98 tin1^=tout1; tin[1]=tin1;
99 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
100 tout0=tin[0]; l2c(tout0,out);
101 tout1=tin[1]; l2c(tout1,out);
102 }
103 }
104 else
105 {
106 c2l(iv,xor0);
107 c2l(iv,xor1);
108 for (l-=8; l>=0; l-=8)
109 {
110 c2l(in,tin0); tin[0]=tin0;
111 c2l(in,tin1); tin[1]=tin1;
112 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
113 tout0=tin[0]^xor0;
114 tout1=tin[1]^xor1;
115 l2c(tout0,out);
116 l2c(tout1,out);
117 xor0=tin0;
118 xor1=tin1;
119 }
120 if (l != -8)
121 {
122 c2l(in,tin0); tin[0]=tin0;
123 c2l(in,tin1); tin[1]=tin1;
124 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
125 tout0=tin[0]^xor0;
126 tout1=tin[1]^xor1;
127 l2cn(tout0,tout1,out,l+8);
128 /* xor0=tin0;
129 xor1=tin1; */
130 }
131 }
132 tin0=tin1=tout0=tout1=xor0=xor1=0;
133 tin[0]=tin[1]=0;
134 }
135 60
61#include "ncbc_enc.c" /* des_cbc_encrypt */
diff --git a/src/lib/libcrypto/des/cfb64ede.c b/src/lib/libcrypto/des/cfb64ede.c
index 80b8a9eaaa..60c1aa08db 100644
--- a/src/lib/libcrypto/des/cfb64ede.c
+++ b/src/lib/libcrypto/des/cfb64ede.c
@@ -63,14 +63,10 @@
63 * 64bit block we have used is contained in *num; 63 * 64bit block we have used is contained in *num;
64 */ 64 */
65 65
66void des_ede3_cfb64_encrypt(in, out, length, ks1,ks2,ks3, ivec, num, enc) 66void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
67unsigned char *in; 67 long length, DES_key_schedule *ks1,
68unsigned char *out; 68 DES_key_schedule *ks2, DES_key_schedule *ks3,
69long length; 69 DES_cblock *ivec, int *num, int enc)
70des_key_schedule ks1,ks2,ks3;
71des_cblock (*ivec);
72int *num;
73int enc;
74 { 70 {
75 register DES_LONG v0,v1; 71 register DES_LONG v0,v1;
76 register long l=length; 72 register long l=length;
@@ -78,7 +74,7 @@ int enc;
78 DES_LONG ti[2]; 74 DES_LONG ti[2];
79 unsigned char *iv,c,cc; 75 unsigned char *iv,c,cc;
80 76
81 iv=(unsigned char *)ivec; 77 iv=&(*ivec)[0];
82 if (enc) 78 if (enc)
83 { 79 {
84 while (l--) 80 while (l--)
@@ -90,14 +86,14 @@ int enc;
90 86
91 ti[0]=v0; 87 ti[0]=v0;
92 ti[1]=v1; 88 ti[1]=v1;
93 des_encrypt3((DES_LONG *)ti,ks1,ks2,ks3); 89 DES_encrypt3(ti,ks1,ks2,ks3);
94 v0=ti[0]; 90 v0=ti[0];
95 v1=ti[1]; 91 v1=ti[1];
96 92
97 iv=(unsigned char *)ivec; 93 iv = &(*ivec)[0];
98 l2c(v0,iv); 94 l2c(v0,iv);
99 l2c(v1,iv); 95 l2c(v1,iv);
100 iv=(unsigned char *)ivec; 96 iv = &(*ivec)[0];
101 } 97 }
102 c= *(in++)^iv[n]; 98 c= *(in++)^iv[n];
103 *(out++)=c; 99 *(out++)=c;
@@ -116,14 +112,14 @@ int enc;
116 112
117 ti[0]=v0; 113 ti[0]=v0;
118 ti[1]=v1; 114 ti[1]=v1;
119 des_encrypt3((DES_LONG *)ti,ks1,ks2,ks3); 115 DES_encrypt3(ti,ks1,ks2,ks3);
120 v0=ti[0]; 116 v0=ti[0];
121 v1=ti[1]; 117 v1=ti[1];
122 118
123 iv=(unsigned char *)ivec; 119 iv = &(*ivec)[0];
124 l2c(v0,iv); 120 l2c(v0,iv);
125 l2c(v1,iv); 121 l2c(v1,iv);
126 iv=(unsigned char *)ivec; 122 iv = &(*ivec)[0];
127 } 123 }
128 cc= *(in++); 124 cc= *(in++);
129 c=iv[n]; 125 c=iv[n];
@@ -137,15 +133,10 @@ int enc;
137 } 133 }
138 134
139#ifdef undef /* MACRO */ 135#ifdef undef /* MACRO */
140void des_ede2_cfb64_encrypt(in, out, length, ks1,ks2, ivec, num, enc) 136void DES_ede2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
141unsigned char *in; 137 DES_key_schedule ks1, DES_key_schedule ks2, DES_cblock (*ivec),
142unsigned char *out; 138 int *num, int enc)
143long length;
144des_key_schedule ks1,ks2;
145des_cblock (*ivec);
146int *num;
147int enc;
148 { 139 {
149 des_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc); 140 DES_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc);
150 } 141 }
151#endif 142#endif
diff --git a/src/lib/libcrypto/des/cfb64enc.c b/src/lib/libcrypto/des/cfb64enc.c
index 403da479df..5ec8683e40 100644
--- a/src/lib/libcrypto/des/cfb64enc.c
+++ b/src/lib/libcrypto/des/cfb64enc.c
@@ -63,14 +63,9 @@
63 * 64bit block we have used is contained in *num; 63 * 64bit block we have used is contained in *num;
64 */ 64 */
65 65
66void des_cfb64_encrypt(in, out, length, schedule, ivec, num, enc) 66void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
67unsigned char *in; 67 long length, DES_key_schedule *schedule,
68unsigned char *out; 68 DES_cblock *ivec, int *num, int enc)
69long length;
70des_key_schedule schedule;
71des_cblock (*ivec);
72int *num;
73int enc;
74 { 69 {
75 register DES_LONG v0,v1; 70 register DES_LONG v0,v1;
76 register long l=length; 71 register long l=length;
@@ -78,7 +73,7 @@ int enc;
78 DES_LONG ti[2]; 73 DES_LONG ti[2];
79 unsigned char *iv,c,cc; 74 unsigned char *iv,c,cc;
80 75
81 iv=(unsigned char *)ivec; 76 iv = &(*ivec)[0];
82 if (enc) 77 if (enc)
83 { 78 {
84 while (l--) 79 while (l--)
@@ -87,12 +82,11 @@ int enc;
87 { 82 {
88 c2l(iv,v0); ti[0]=v0; 83 c2l(iv,v0); ti[0]=v0;
89 c2l(iv,v1); ti[1]=v1; 84 c2l(iv,v1); ti[1]=v1;
90 des_encrypt((DES_LONG *)ti, 85 DES_encrypt1(ti,schedule,DES_ENCRYPT);
91 schedule,DES_ENCRYPT); 86 iv = &(*ivec)[0];
92 iv=(unsigned char *)ivec;
93 v0=ti[0]; l2c(v0,iv); 87 v0=ti[0]; l2c(v0,iv);
94 v0=ti[1]; l2c(v0,iv); 88 v0=ti[1]; l2c(v0,iv);
95 iv=(unsigned char *)ivec; 89 iv = &(*ivec)[0];
96 } 90 }
97 c= *(in++)^iv[n]; 91 c= *(in++)^iv[n];
98 *(out++)=c; 92 *(out++)=c;
@@ -108,12 +102,11 @@ int enc;
108 { 102 {
109 c2l(iv,v0); ti[0]=v0; 103 c2l(iv,v0); ti[0]=v0;
110 c2l(iv,v1); ti[1]=v1; 104 c2l(iv,v1); ti[1]=v1;
111 des_encrypt((DES_LONG *)ti, 105 DES_encrypt1(ti,schedule,DES_ENCRYPT);
112 schedule,DES_ENCRYPT); 106 iv = &(*ivec)[0];
113 iv=(unsigned char *)ivec;
114 v0=ti[0]; l2c(v0,iv); 107 v0=ti[0]; l2c(v0,iv);
115 v0=ti[1]; l2c(v0,iv); 108 v0=ti[1]; l2c(v0,iv);
116 iv=(unsigned char *)ivec; 109 iv = &(*ivec)[0];
117 } 110 }
118 cc= *(in++); 111 cc= *(in++);
119 c=iv[n]; 112 c=iv[n];
diff --git a/src/lib/libcrypto/des/cfb_enc.c b/src/lib/libcrypto/des/cfb_enc.c
index 342e785691..17bf77ca9e 100644
--- a/src/lib/libcrypto/des/cfb_enc.c
+++ b/src/lib/libcrypto/des/cfb_enc.c
@@ -64,14 +64,8 @@
64 * the second. The second 12 bits will come from the 3rd and half the 4th 64 * the second. The second 12 bits will come from the 3rd and half the 4th
65 * byte. 65 * byte.
66 */ 66 */
67void des_cfb_encrypt(in, out, numbits, length, schedule, ivec, enc) 67void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
68unsigned char *in; 68 long length, DES_key_schedule *schedule, DES_cblock *ivec, int enc)
69unsigned char *out;
70int numbits;
71long length;
72des_key_schedule schedule;
73des_cblock (*ivec);
74int enc;
75 { 69 {
76 register DES_LONG d0,d1,v0,v1,n=(numbits+7)/8; 70 register DES_LONG d0,d1,v0,v1,n=(numbits+7)/8;
77 register DES_LONG mask0,mask1; 71 register DES_LONG mask0,mask1;
@@ -96,7 +90,7 @@ int enc;
96 mask1=0x00000000L; 90 mask1=0x00000000L;
97 } 91 }
98 92
99 iv=(unsigned char *)ivec; 93 iv = &(*ivec)[0];
100 c2l(iv,v0); 94 c2l(iv,v0);
101 c2l(iv,v1); 95 c2l(iv,v1);
102 if (enc) 96 if (enc)
@@ -106,7 +100,7 @@ int enc;
106 l-=n; 100 l-=n;
107 ti[0]=v0; 101 ti[0]=v0;
108 ti[1]=v1; 102 ti[1]=v1;
109 des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); 103 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
110 c2ln(in,d0,d1,n); 104 c2ln(in,d0,d1,n);
111 in+=n; 105 in+=n;
112 d0=(d0^ti[0])&mask0; 106 d0=(d0^ti[0])&mask0;
@@ -138,7 +132,7 @@ int enc;
138 l-=n; 132 l-=n;
139 ti[0]=v0; 133 ti[0]=v0;
140 ti[1]=v1; 134 ti[1]=v1;
141 des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); 135 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
142 c2ln(in,d0,d1,n); 136 c2ln(in,d0,d1,n);
143 in+=n; 137 in+=n;
144 /* 30-08-94 - eay - changed because l>>32 and 138 /* 30-08-94 - eay - changed because l>>32 and
@@ -163,7 +157,7 @@ int enc;
163 out+=n; 157 out+=n;
164 } 158 }
165 } 159 }
166 iv=(unsigned char *)ivec; 160 iv = &(*ivec)[0];
167 l2c(v0,iv); 161 l2c(v0,iv);
168 l2c(v1,iv); 162 l2c(v1,iv);
169 v0=v1=d0=d1=ti[0]=ti[1]=0; 163 v0=v1=d0=d1=ti[0]=ti[1]=0;
diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h
index 67f90aaf17..4cb9d84fdf 100644
--- a/src/lib/libcrypto/des/des.h
+++ b/src/lib/libcrypto/des/des.h
@@ -59,43 +59,50 @@
59#ifndef HEADER_DES_H 59#ifndef HEADER_DES_H
60#define HEADER_DES_H 60#define HEADER_DES_H
61 61
62#ifdef __cplusplus 62#ifdef OPENSSL_NO_DES
63extern "C" {
64#endif
65
66#ifdef NO_DES
67#error DES is disabled. 63#error DES is disabled.
68#endif 64#endif
69 65
70#ifdef _KERBEROS_DES_H
71#error <openssl/des.h> replaces <kerberos/des.h>.
72#endif
73
74#include <stdio.h>
75#include <openssl/opensslconf.h> /* DES_LONG */ 66#include <openssl/opensslconf.h> /* DES_LONG */
76#include <openssl/e_os2.h> /* OPENSSL_EXTERN */ 67#include <openssl/e_os2.h> /* OPENSSL_EXTERN */
77 68
78typedef unsigned char des_cblock[8]; 69#ifdef OPENSSL_BUILD_SHLIBCRYPTO
79typedef /* const */ unsigned char const_des_cblock[8]; 70# undef OPENSSL_EXTERN
80/* With "const", gcc 2.8.1 on Solaris thinks that des_cblock * 71# define OPENSSL_EXTERN OPENSSL_EXPORT
81 * and const_des_cblock * are incompatible pointer types. 72#endif
82 * I haven't seen that warning on other systems ... I'll look 73
83 * what the standard says. */ 74#ifdef __cplusplus
75extern "C" {
76#endif
84 77
78typedef unsigned char DES_cblock[8];
79typedef /* const */ unsigned char const_DES_cblock[8];
80/* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock *
81 * and const_DES_cblock * are incompatible pointer types. */
85 82
86typedef struct des_ks_struct 83typedef struct DES_ks
84 {
85 union
87 { 86 {
88 union { 87 DES_cblock cblock;
89 des_cblock cblock; 88 /* make sure things are correct size on machines with
90 /* make sure things are correct size on machines with 89 * 8 byte longs */
91 * 8 byte longs */ 90 DES_LONG deslong[2];
92 DES_LONG deslong[2]; 91 } ks[16];
93 } ks; 92 } DES_key_schedule;
94 int weak_key; 93
95 } des_key_schedule[16]; 94#ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT
96 95# ifndef OPENSSL_ENABLE_OLD_DES_SUPPORT
97#define DES_KEY_SZ (sizeof(des_cblock)) 96# define OPENSSL_ENABLE_OLD_DES_SUPPORT
98#define DES_SCHEDULE_SZ (sizeof(des_key_schedule)) 97# endif
98#endif
99
100#ifdef OPENSSL_ENABLE_OLD_DES_SUPPORT
101# include <openssl/des_old.h>
102#endif
103
104#define DES_KEY_SZ (sizeof(DES_cblock))
105#define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
99 106
100#define DES_ENCRYPT 1 107#define DES_ENCRYPT 1
101#define DES_DECRYPT 0 108#define DES_DECRYPT 0
@@ -103,144 +110,128 @@ typedef struct des_ks_struct
103#define DES_CBC_MODE 0 110#define DES_CBC_MODE 0
104#define DES_PCBC_MODE 1 111#define DES_PCBC_MODE 1
105 112
106#define des_ecb2_encrypt(i,o,k1,k2,e) \ 113#define DES_ecb2_encrypt(i,o,k1,k2,e) \
107 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) 114 DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
108 115
109#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ 116#define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
110 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) 117 DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
111 118
112#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ 119#define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
113 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) 120 DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
114 121
115#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ 122#define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
116 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) 123 DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
117 124
118OPENSSL_EXTERN int des_check_key; /* defaults to false */ 125OPENSSL_DECLARE_GLOBAL(int,DES_check_key); /* defaults to false */
119OPENSSL_EXTERN int des_rw_mode; /* defaults to DES_PCBC_MODE */ 126#define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key)
120OPENSSL_EXTERN int des_set_weak_key_flag; /* set the weak key flag */ 127OPENSSL_DECLARE_GLOBAL(int,DES_rw_mode); /* defaults to DES_PCBC_MODE */
121 128#define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode)
122const char *des_options(void); 129
123void des_ecb3_encrypt(const_des_cblock *input, des_cblock *output, 130const char *DES_options(void);
124 des_key_schedule ks1,des_key_schedule ks2, 131void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
125 des_key_schedule ks3, int enc); 132 DES_key_schedule *ks1,DES_key_schedule *ks2,
126DES_LONG des_cbc_cksum(const unsigned char *input,des_cblock *output, 133 DES_key_schedule *ks3, int enc);
127 long length,des_key_schedule schedule, 134DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output,
128 const_des_cblock *ivec); 135 long length,DES_key_schedule *schedule,
129/* des_cbc_encrypt does not update the IV! Use des_ncbc_encrypt instead. */ 136 const_DES_cblock *ivec);
130void des_cbc_encrypt(const unsigned char *input,unsigned char *output, 137/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
131 long length,des_key_schedule schedule,des_cblock *ivec, 138void DES_cbc_encrypt(const unsigned char *input,unsigned char *output,
139 long length,DES_key_schedule *schedule,DES_cblock *ivec,
132 int enc); 140 int enc);
133void des_ncbc_encrypt(const unsigned char *input,unsigned char *output, 141void DES_ncbc_encrypt(const unsigned char *input,unsigned char *output,
134 long length,des_key_schedule schedule,des_cblock *ivec, 142 long length,DES_key_schedule *schedule,DES_cblock *ivec,
135 int enc); 143 int enc);
136void des_xcbc_encrypt(const unsigned char *input,unsigned char *output, 144void DES_xcbc_encrypt(const unsigned char *input,unsigned char *output,
137 long length,des_key_schedule schedule,des_cblock *ivec, 145 long length,DES_key_schedule *schedule,DES_cblock *ivec,
138 const_des_cblock *inw,const_des_cblock *outw,int enc); 146 const_DES_cblock *inw,const_DES_cblock *outw,int enc);
139void des_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits, 147void DES_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
140 long length,des_key_schedule schedule,des_cblock *ivec, 148 long length,DES_key_schedule *schedule,DES_cblock *ivec,
141 int enc); 149 int enc);
142void des_ecb_encrypt(const_des_cblock *input,des_cblock *output, 150void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output,
143 des_key_schedule ks,int enc); 151 DES_key_schedule *ks,int enc);
144void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc); 152
145void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc); 153/* This is the DES encryption function that gets called by just about
146void des_encrypt3(DES_LONG *data, des_key_schedule ks1, 154 every other DES routine in the library. You should not use this
147 des_key_schedule ks2, des_key_schedule ks3); 155 function except to implement 'modes' of DES. I say this because the
148void des_decrypt3(DES_LONG *data, des_key_schedule ks1, 156 functions that call this routine do the conversion from 'char *' to
149 des_key_schedule ks2, des_key_schedule ks3); 157 long, and this needs to be done to make sure 'non-aligned' memory
150void des_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output, 158 access do not occur. The characters are loaded 'little endian'.
159 Data is a pointer to 2 unsigned long's and ks is the
160 DES_key_schedule to use. enc, is non zero specifies encryption,
161 zero if decryption. */
162void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc);
163
164/* This functions is the same as DES_encrypt1() except that the DES
165 initial permutation (IP) and final permutation (FP) have been left
166 out. As for DES_encrypt1(), you should not use this function.
167 It is used by the routines in the library that implement triple DES.
168 IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same
169 as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */
170void DES_encrypt2(DES_LONG *data,DES_key_schedule *ks, int enc);
171
172void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
173 DES_key_schedule *ks2, DES_key_schedule *ks3);
174void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
175 DES_key_schedule *ks2, DES_key_schedule *ks3);
176void DES_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output,
151 long length, 177 long length,
152 des_key_schedule ks1,des_key_schedule ks2, 178 DES_key_schedule *ks1,DES_key_schedule *ks2,
153 des_key_schedule ks3,des_cblock *ivec,int enc); 179 DES_key_schedule *ks3,DES_cblock *ivec,int enc);
154void des_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out, 180void DES_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,
155 long length, 181 long length,
156 des_key_schedule ks1,des_key_schedule ks2, 182 DES_key_schedule *ks1,DES_key_schedule *ks2,
157 des_key_schedule ks3, 183 DES_key_schedule *ks3,
158 des_cblock *ivec1,des_cblock *ivec2, 184 DES_cblock *ivec1,DES_cblock *ivec2,
159 int enc); 185 int enc);
160void des_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out, 186void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out,
161 long length,des_key_schedule ks1, 187 long length,DES_key_schedule *ks1,
162 des_key_schedule ks2,des_key_schedule ks3, 188 DES_key_schedule *ks2,DES_key_schedule *ks3,
163 des_cblock *ivec,int *num,int enc); 189 DES_cblock *ivec,int *num,int enc);
164void des_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out, 190void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
165 long length,des_key_schedule ks1, 191 long length,DES_key_schedule *ks1,
166 des_key_schedule ks2,des_key_schedule ks3, 192 DES_key_schedule *ks2,DES_key_schedule *ks3,
167 des_cblock *ivec,int *num); 193 DES_cblock *ivec,int *num);
168 194
169void des_xwhite_in2out(const_des_cblock *des_key,const_des_cblock *in_white, 195void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white,
170 des_cblock *out_white); 196 DES_cblock *out_white);
171 197
172int des_enc_read(int fd,void *buf,int len,des_key_schedule sched, 198int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched,
173 des_cblock *iv); 199 DES_cblock *iv);
174int des_enc_write(int fd,const void *buf,int len,des_key_schedule sched, 200int DES_enc_write(int fd,const void *buf,int len,DES_key_schedule *sched,
175 des_cblock *iv); 201 DES_cblock *iv);
176char *des_fcrypt(const char *buf,const char *salt, char *ret); 202char *DES_fcrypt(const char *buf,const char *salt, char *ret);
177char *des_crypt(const char *buf,const char *salt); 203char *DES_crypt(const char *buf,const char *salt);
178#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT) 204void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
179char *crypt(const char *buf,const char *salt); 205 long length,DES_key_schedule *schedule,DES_cblock *ivec);
180#endif 206void DES_pcbc_encrypt(const unsigned char *input,unsigned char *output,
181void des_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits, 207 long length,DES_key_schedule *schedule,DES_cblock *ivec,
182 long length,des_key_schedule schedule,des_cblock *ivec);
183void des_pcbc_encrypt(const unsigned char *input,unsigned char *output,
184 long length,des_key_schedule schedule,des_cblock *ivec,
185 int enc); 208 int enc);
186DES_LONG des_quad_cksum(const unsigned char *input,des_cblock output[], 209DES_LONG DES_quad_cksum(const unsigned char *input,DES_cblock output[],
187 long length,int out_count,des_cblock *seed); 210 long length,int out_count,DES_cblock *seed);
188void des_random_seed(des_cblock *key); 211int DES_random_key(DES_cblock *ret);
189void des_random_key(des_cblock *ret); 212void DES_set_odd_parity(DES_cblock *key);
190int des_read_password(des_cblock *key,const char *prompt,int verify); 213int DES_check_key_parity(const_DES_cblock *key);
191int des_read_2passwords(des_cblock *key1,des_cblock *key2, 214int DES_is_weak_key(const_DES_cblock *key);
192 const char *prompt,int verify); 215/* DES_set_key (= set_key = DES_key_sched = key_sched) calls
193int des_read_pw_string(char *buf,int length,const char *prompt,int verify); 216 * DES_set_key_checked if global variable DES_check_key is set,
194void des_set_odd_parity(des_cblock *key); 217 * DES_set_key_unchecked otherwise. */
195int des_is_weak_key(const_des_cblock *key); 218int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule);
196int des_set_key(const_des_cblock *key,des_key_schedule schedule); 219int DES_key_sched(const_DES_cblock *key,DES_key_schedule *schedule);
197int des_key_sched(const_des_cblock *key,des_key_schedule schedule); 220int DES_set_key_checked(const_DES_cblock *key,DES_key_schedule *schedule);
198void des_string_to_key(const char *str,des_cblock *key); 221void DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule);
199void des_string_to_2keys(const char *str,des_cblock *key1,des_cblock *key2); 222void DES_string_to_key(const char *str,DES_cblock *key);
200void des_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length, 223void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2);
201 des_key_schedule schedule,des_cblock *ivec,int *num, 224void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
225 DES_key_schedule *schedule,DES_cblock *ivec,int *num,
202 int enc); 226 int enc);
203void des_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length, 227void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,
204 des_key_schedule schedule,des_cblock *ivec,int *num); 228 DES_key_schedule *schedule,DES_cblock *ivec,int *num);
205int des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
206 229
207/* Extra functions from Mark Murray <mark@grondar.za> */ 230int DES_read_password(DES_cblock *key, const char *prompt, int verify);
208void des_cblock_print_file(const_des_cblock *cb, FILE *fp); 231int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt,
209 232 int verify);
210/* The following definitions provide compatibility with the MIT Kerberos
211 * library. The des_key_schedule structure is not binary compatible. */
212
213#define _KERBEROS_DES_H
214
215#define KRBDES_ENCRYPT DES_ENCRYPT
216#define KRBDES_DECRYPT DES_DECRYPT
217
218#ifdef KERBEROS
219# define ENCRYPT DES_ENCRYPT
220# define DECRYPT DES_DECRYPT
221#endif
222
223#ifndef NCOMPAT
224# define C_Block des_cblock
225# define Key_schedule des_key_schedule
226# define KEY_SZ DES_KEY_SZ
227# define string_to_key des_string_to_key
228# define read_pw_string des_read_pw_string
229# define random_key des_random_key
230# define pcbc_encrypt des_pcbc_encrypt
231# define set_key des_set_key
232# define key_sched des_key_sched
233# define ecb_encrypt des_ecb_encrypt
234# define cbc_encrypt des_cbc_encrypt
235# define ncbc_encrypt des_ncbc_encrypt
236# define xcbc_encrypt des_xcbc_encrypt
237# define cbc_cksum des_cbc_cksum
238# define quad_cksum des_quad_cksum
239#endif
240 233
241typedef des_key_schedule bit_64; 234#define DES_fixup_key_parity DES_set_odd_parity
242#define des_fixup_key_parity des_set_odd_parity
243#define des_check_key_parity check_parity
244 235
245#ifdef __cplusplus 236#ifdef __cplusplus
246} 237}
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c
index e4db09299e..1c37ab96d3 100644
--- a/src/lib/libcrypto/des/des_enc.c
+++ b/src/lib/libcrypto/des/des_enc.c
@@ -58,14 +58,11 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61void des_encrypt(data, ks, enc) 61void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
62DES_LONG *data;
63des_key_schedule ks;
64int enc;
65 { 62 {
66 register DES_LONG l,r,t,u; 63 register DES_LONG l,r,t,u;
67#ifdef DES_PTR 64#ifdef DES_PTR
68 register unsigned char *des_SP=(unsigned char *)des_SPtrans; 65 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
69#endif 66#endif
70#ifndef DES_UNROLL 67#ifndef DES_UNROLL
71 register int i; 68 register int i;
@@ -78,7 +75,7 @@ int enc;
78 IP(r,l); 75 IP(r,l);
79 /* Things have been modified so that the initial rotate is 76 /* Things have been modified so that the initial rotate is
80 * done outside the loop. This required the 77 * done outside the loop. This required the
81 * des_SPtrans values in sp.h to be rotated 1 bit to the right. 78 * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
82 * One perl script later and things have a 5% speed up on a sparc2. 79 * One perl script later and things have a 5% speed up on a sparc2.
83 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM> 80 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
84 * for pointing this out. */ 81 * for pointing this out. */
@@ -87,7 +84,7 @@ int enc;
87 r=ROTATE(r,29)&0xffffffffL; 84 r=ROTATE(r,29)&0xffffffffL;
88 l=ROTATE(l,29)&0xffffffffL; 85 l=ROTATE(l,29)&0xffffffffL;
89 86
90 s=(DES_LONG *)ks; 87 s=ks->ks->deslong;
91 /* I don't know if it is worth the effort of loop unrolling the 88 /* I don't know if it is worth the effort of loop unrolling the
92 * inner loop */ 89 * inner loop */
93 if (enc) 90 if (enc)
@@ -159,14 +156,11 @@ int enc;
159 l=r=t=u=0; 156 l=r=t=u=0;
160 } 157 }
161 158
162void des_encrypt2(data, ks, enc) 159void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
163DES_LONG *data;
164des_key_schedule ks;
165int enc;
166 { 160 {
167 register DES_LONG l,r,t,u; 161 register DES_LONG l,r,t,u;
168#ifdef DES_PTR 162#ifdef DES_PTR
169 register unsigned char *des_SP=(unsigned char *)des_SPtrans; 163 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
170#endif 164#endif
171#ifndef DES_UNROLL 165#ifndef DES_UNROLL
172 register int i; 166 register int i;
@@ -178,7 +172,7 @@ int enc;
178 172
179 /* Things have been modified so that the initial rotate is 173 /* Things have been modified so that the initial rotate is
180 * done outside the loop. This required the 174 * done outside the loop. This required the
181 * des_SPtrans values in sp.h to be rotated 1 bit to the right. 175 * DES_SPtrans values in sp.h to be rotated 1 bit to the right.
182 * One perl script later and things have a 5% speed up on a sparc2. 176 * One perl script later and things have a 5% speed up on a sparc2.
183 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM> 177 * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
184 * for pointing this out. */ 178 * for pointing this out. */
@@ -186,7 +180,7 @@ int enc;
186 r=ROTATE(r,29)&0xffffffffL; 180 r=ROTATE(r,29)&0xffffffffL;
187 l=ROTATE(l,29)&0xffffffffL; 181 l=ROTATE(l,29)&0xffffffffL;
188 182
189 s=(DES_LONG *)ks; 183 s=ks->ks->deslong;
190 /* I don't know if it is worth the effort of loop unrolling the 184 /* I don't know if it is worth the effort of loop unrolling the
191 * inner loop */ 185 * inner loop */
192 if (enc) 186 if (enc)
@@ -253,11 +247,8 @@ int enc;
253 l=r=t=u=0; 247 l=r=t=u=0;
254 } 248 }
255 249
256void des_encrypt3(data,ks1,ks2,ks3) 250void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
257DES_LONG *data; 251 DES_key_schedule *ks2, DES_key_schedule *ks3)
258des_key_schedule ks1;
259des_key_schedule ks2;
260des_key_schedule ks3;
261 { 252 {
262 register DES_LONG l,r; 253 register DES_LONG l,r;
263 254
@@ -266,9 +257,9 @@ des_key_schedule ks3;
266 IP(l,r); 257 IP(l,r);
267 data[0]=l; 258 data[0]=l;
268 data[1]=r; 259 data[1]=r;
269 des_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT); 260 DES_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT);
270 des_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT); 261 DES_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT);
271 des_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT); 262 DES_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT);
272 l=data[0]; 263 l=data[0];
273 r=data[1]; 264 r=data[1];
274 FP(r,l); 265 FP(r,l);
@@ -276,11 +267,8 @@ des_key_schedule ks3;
276 data[1]=r; 267 data[1]=r;
277 } 268 }
278 269
279void des_decrypt3(data,ks1,ks2,ks3) 270void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
280DES_LONG *data; 271 DES_key_schedule *ks2, DES_key_schedule *ks3)
281des_key_schedule ks1;
282des_key_schedule ks2;
283des_key_schedule ks3;
284 { 272 {
285 register DES_LONG l,r; 273 register DES_LONG l,r;
286 274
@@ -289,9 +277,9 @@ des_key_schedule ks3;
289 IP(l,r); 277 IP(l,r);
290 data[0]=l; 278 data[0]=l;
291 data[1]=r; 279 data[1]=r;
292 des_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT); 280 DES_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT);
293 des_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT); 281 DES_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT);
294 des_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT); 282 DES_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT);
295 l=data[0]; 283 l=data[0];
296 r=data[1]; 284 r=data[1];
297 FP(r,l); 285 FP(r,l);
@@ -301,108 +289,25 @@ des_key_schedule ks3;
301 289
302#ifndef DES_DEFAULT_OPTIONS 290#ifndef DES_DEFAULT_OPTIONS
303 291
304void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) 292#undef CBC_ENC_C__DONT_UPDATE_IV
305des_cblock (*input); 293#include "ncbc_enc.c" /* DES_ncbc_encrypt */
306des_cblock (*output);
307long length;
308des_key_schedule schedule;
309des_cblock (*ivec);
310int enc;
311 {
312 register DES_LONG tin0,tin1;
313 register DES_LONG tout0,tout1,xor0,xor1;
314 register unsigned char *in,*out;
315 register long l=length;
316 DES_LONG tin[2];
317 unsigned char *iv;
318
319 in=(unsigned char *)input;
320 out=(unsigned char *)output;
321 iv=(unsigned char *)ivec;
322
323 if (enc)
324 {
325 c2l(iv,tout0);
326 c2l(iv,tout1);
327 for (l-=8; l>=0; l-=8)
328 {
329 c2l(in,tin0);
330 c2l(in,tin1);
331 tin0^=tout0; tin[0]=tin0;
332 tin1^=tout1; tin[1]=tin1;
333 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
334 tout0=tin[0]; l2c(tout0,out);
335 tout1=tin[1]; l2c(tout1,out);
336 }
337 if (l != -8)
338 {
339 c2ln(in,tin0,tin1,l+8);
340 tin0^=tout0; tin[0]=tin0;
341 tin1^=tout1; tin[1]=tin1;
342 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
343 tout0=tin[0]; l2c(tout0,out);
344 tout1=tin[1]; l2c(tout1,out);
345 }
346 iv=(unsigned char *)ivec;
347 l2c(tout0,iv);
348 l2c(tout1,iv);
349 }
350 else
351 {
352 c2l(iv,xor0);
353 c2l(iv,xor1);
354 for (l-=8; l>=0; l-=8)
355 {
356 c2l(in,tin0); tin[0]=tin0;
357 c2l(in,tin1); tin[1]=tin1;
358 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
359 tout0=tin[0]^xor0;
360 tout1=tin[1]^xor1;
361 l2c(tout0,out);
362 l2c(tout1,out);
363 xor0=tin0;
364 xor1=tin1;
365 }
366 if (l != -8)
367 {
368 c2l(in,tin0); tin[0]=tin0;
369 c2l(in,tin1); tin[1]=tin1;
370 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
371 tout0=tin[0]^xor0;
372 tout1=tin[1]^xor1;
373 l2cn(tout0,tout1,out,l+8);
374 xor0=tin0;
375 xor1=tin1;
376 }
377
378 iv=(unsigned char *)ivec;
379 l2c(xor0,iv);
380 l2c(xor1,iv);
381 }
382 tin0=tin1=tout0=tout1=xor0=xor1=0;
383 tin[0]=tin[1]=0;
384 }
385 294
386void des_ede3_cbc_encrypt(input, output, length, ks1, ks2, ks3, ivec, enc) 295void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
387des_cblock (*input); 296 long length, DES_key_schedule *ks1,
388des_cblock (*output); 297 DES_key_schedule *ks2, DES_key_schedule *ks3,
389long length; 298 DES_cblock *ivec, int enc)
390des_key_schedule ks1;
391des_key_schedule ks2;
392des_key_schedule ks3;
393des_cblock (*ivec);
394int enc;
395 { 299 {
396 register DES_LONG tin0,tin1; 300 register DES_LONG tin0,tin1;
397 register DES_LONG tout0,tout1,xor0,xor1; 301 register DES_LONG tout0,tout1,xor0,xor1;
398 register unsigned char *in,*out; 302 register const unsigned char *in;
303 unsigned char *out;
399 register long l=length; 304 register long l=length;
400 DES_LONG tin[2]; 305 DES_LONG tin[2];
401 unsigned char *iv; 306 unsigned char *iv;
402 307
403 in=(unsigned char *)input; 308 in=input;
404 out=(unsigned char *)output; 309 out=output;
405 iv=(unsigned char *)ivec; 310 iv = &(*ivec)[0];
406 311
407 if (enc) 312 if (enc)
408 { 313 {
@@ -417,7 +322,7 @@ int enc;
417 322
418 tin[0]=tin0; 323 tin[0]=tin0;
419 tin[1]=tin1; 324 tin[1]=tin1;
420 des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3); 325 DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
421 tout0=tin[0]; 326 tout0=tin[0];
422 tout1=tin[1]; 327 tout1=tin[1];
423 328
@@ -432,14 +337,14 @@ int enc;
432 337
433 tin[0]=tin0; 338 tin[0]=tin0;
434 tin[1]=tin1; 339 tin[1]=tin1;
435 des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3); 340 DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
436 tout0=tin[0]; 341 tout0=tin[0];
437 tout1=tin[1]; 342 tout1=tin[1];
438 343
439 l2c(tout0,out); 344 l2c(tout0,out);
440 l2c(tout1,out); 345 l2c(tout1,out);
441 } 346 }
442 iv=(unsigned char *)ivec; 347 iv = &(*ivec)[0];
443 l2c(tout0,iv); 348 l2c(tout0,iv);
444 l2c(tout1,iv); 349 l2c(tout1,iv);
445 } 350 }
@@ -459,7 +364,7 @@ int enc;
459 364
460 tin[0]=tin0; 365 tin[0]=tin0;
461 tin[1]=tin1; 366 tin[1]=tin1;
462 des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3); 367 DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
463 tout0=tin[0]; 368 tout0=tin[0];
464 tout1=tin[1]; 369 tout1=tin[1];
465 370
@@ -480,7 +385,7 @@ int enc;
480 385
481 tin[0]=tin0; 386 tin[0]=tin0;
482 tin[1]=tin1; 387 tin[1]=tin1;
483 des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3); 388 DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
484 tout0=tin[0]; 389 tout0=tin[0];
485 tout1=tin[1]; 390 tout1=tin[1];
486 391
@@ -491,7 +396,7 @@ int enc;
491 xor1=t1; 396 xor1=t1;
492 } 397 }
493 398
494 iv=(unsigned char *)ivec; 399 iv = &(*ivec)[0];
495 l2c(xor0,iv); 400 l2c(xor0,iv);
496 l2c(xor1,iv); 401 l2c(xor1,iv);
497 } 402 }
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h
index d6ea17cb68..70e833be3f 100644
--- a/src/lib/libcrypto/des/des_locl.h
+++ b/src/lib/libcrypto/des/des_locl.h
@@ -59,36 +59,45 @@
59#ifndef HEADER_DES_LOCL_H 59#ifndef HEADER_DES_LOCL_H
60#define HEADER_DES_LOCL_H 60#define HEADER_DES_LOCL_H
61 61
62#if defined(WIN32) || defined(WIN16) 62#include <openssl/e_os2.h>
63#ifndef MSDOS 63
64#define MSDOS 64#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
65#ifndef OPENSSL_SYS_MSDOS
66#define OPENSSL_SYS_MSDOS
65#endif 67#endif
66#endif 68#endif
67 69
68#include <stdio.h> 70#include <stdio.h>
69#include <stdlib.h> 71#include <stdlib.h>
70 72
71#include <openssl/opensslconf.h> 73#ifndef OPENSSL_SYS_MSDOS
72 74#if !defined(OPENSSL_SYS_VMS) || defined(__DECC)
73#ifndef MSDOS 75#ifdef OPENSSL_UNISTD
74#if !defined(VMS) || defined(__DECC) 76# include OPENSSL_UNISTD
75#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
79#include <openssl/des.h> 83#include <openssl/des.h>
80 84
81#ifdef MSDOS /* Visual C++ 2.1 (Windows NT/95) */ 85#ifdef OPENSSL_SYS_MSDOS /* Visual C++ 2.1 (Windows NT/95) */
82#include <stdlib.h> 86#include <stdlib.h>
83#include <errno.h> 87#include <errno.h>
84#include <time.h> 88#include <time.h>
85#include <io.h> 89#include <io.h>
86#endif 90#endif
87 91
88#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS) 92#if defined(__STDC__) || defined(OPENSSL_SYS_VMS) || defined(M_XENIX) || defined(OPENSSL_SYS_MSDOS)
89#include <string.h> 93#include <string.h>
90#endif 94#endif
91 95
96#ifdef OPENSSL_BUILD_SHLIBCRYPTO
97# undef OPENSSL_EXTERN
98# define OPENSSL_EXTERN OPENSSL_EXPORT
99#endif
100
92#define ITERATIONS 16 101#define ITERATIONS 16
93#define HALF_ITERATIONS 8 102#define HALF_ITERATIONS 8
94 103
@@ -151,7 +160,7 @@
151 } \ 160 } \
152 } 161 }
153 162
154#if defined(WIN32) 163#if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
155#define ROTATE(a,n) (_lrotr(a,n)) 164#define ROTATE(a,n) (_lrotr(a,n))
156#else 165#else
157#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n)))) 166#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n))))
@@ -178,14 +187,14 @@
178#endif 187#endif
179 188
180/* The changes to this macro may help or hinder, depending on the 189/* The changes to this macro may help or hinder, depending on the
181 * compiler and the achitecture. gcc2 always seems to do well :-). 190 * compiler and the architecture. gcc2 always seems to do well :-).
182 * Inspired by Dana How <how@isl.stanford.edu> 191 * Inspired by Dana How <how@isl.stanford.edu>
183 * DO NOT use the alternative version on machines with 8 byte longs. 192 * 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 193 * 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 :-( */ 194 * bytes, probably an issue of accessing non-word aligned objects :-( */
186#ifdef DES_PTR 195#ifdef DES_PTR
187 196
188/* It recently occured to me that 0^0^0^0^0^0^0 == 0, so there 197/* 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 198 * 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 */ 199 * saves a register since things can be xored directly into L */
191 200
@@ -274,24 +283,24 @@
274 u1=(int)u&0x3f; \ 283 u1=(int)u&0x3f; \
275 u2&=0x3f; \ 284 u2&=0x3f; \
276 u>>=16L; \ 285 u>>=16L; \
277 LL^=des_SPtrans[0][u1]; \ 286 LL^=DES_SPtrans[0][u1]; \
278 LL^=des_SPtrans[2][u2]; \ 287 LL^=DES_SPtrans[2][u2]; \
279 u3=(int)u>>8L; \ 288 u3=(int)u>>8L; \
280 u1=(int)u&0x3f; \ 289 u1=(int)u&0x3f; \
281 u3&=0x3f; \ 290 u3&=0x3f; \
282 LL^=des_SPtrans[4][u1]; \ 291 LL^=DES_SPtrans[4][u1]; \
283 LL^=des_SPtrans[6][u3]; \ 292 LL^=DES_SPtrans[6][u3]; \
284 u2=(int)t>>8L; \ 293 u2=(int)t>>8L; \
285 u1=(int)t&0x3f; \ 294 u1=(int)t&0x3f; \
286 u2&=0x3f; \ 295 u2&=0x3f; \
287 t>>=16L; \ 296 t>>=16L; \
288 LL^=des_SPtrans[1][u1]; \ 297 LL^=DES_SPtrans[1][u1]; \
289 LL^=des_SPtrans[3][u2]; \ 298 LL^=DES_SPtrans[3][u2]; \
290 u3=(int)t>>8L; \ 299 u3=(int)t>>8L; \
291 u1=(int)t&0x3f; \ 300 u1=(int)t&0x3f; \
292 u3&=0x3f; \ 301 u3&=0x3f; \
293 LL^=des_SPtrans[5][u1]; \ 302 LL^=DES_SPtrans[5][u1]; \
294 LL^=des_SPtrans[7][u3]; } 303 LL^=DES_SPtrans[7][u3]; }
295#endif 304#endif
296#ifdef DES_RISC2 305#ifdef DES_RISC2
297#define D_ENCRYPT(LL,R,S) {\ 306#define D_ENCRYPT(LL,R,S) {\
@@ -302,25 +311,25 @@
302 u2=(int)u>>8L; \ 311 u2=(int)u>>8L; \
303 u1=(int)u&0x3f; \ 312 u1=(int)u&0x3f; \
304 u2&=0x3f; \ 313 u2&=0x3f; \
305 LL^=des_SPtrans[0][u1]; \ 314 LL^=DES_SPtrans[0][u1]; \
306 LL^=des_SPtrans[2][u2]; \ 315 LL^=DES_SPtrans[2][u2]; \
307 s1=(int)u>>16L; \ 316 s1=(int)u>>16L; \
308 s2=(int)u>>24L; \ 317 s2=(int)u>>24L; \
309 s1&=0x3f; \ 318 s1&=0x3f; \
310 s2&=0x3f; \ 319 s2&=0x3f; \
311 LL^=des_SPtrans[4][s1]; \ 320 LL^=DES_SPtrans[4][s1]; \
312 LL^=des_SPtrans[6][s2]; \ 321 LL^=DES_SPtrans[6][s2]; \
313 u2=(int)t>>8L; \ 322 u2=(int)t>>8L; \
314 u1=(int)t&0x3f; \ 323 u1=(int)t&0x3f; \
315 u2&=0x3f; \ 324 u2&=0x3f; \
316 LL^=des_SPtrans[1][u1]; \ 325 LL^=DES_SPtrans[1][u1]; \
317 LL^=des_SPtrans[3][u2]; \ 326 LL^=DES_SPtrans[3][u2]; \
318 s1=(int)t>>16; \ 327 s1=(int)t>>16; \
319 s2=(int)t>>24L; \ 328 s2=(int)t>>24L; \
320 s1&=0x3f; \ 329 s1&=0x3f; \
321 s2&=0x3f; \ 330 s2&=0x3f; \
322 LL^=des_SPtrans[5][s1]; \ 331 LL^=DES_SPtrans[5][s1]; \
323 LL^=des_SPtrans[7][s2]; } 332 LL^=DES_SPtrans[7][s2]; }
324#endif 333#endif
325 334
326#else 335#else
@@ -329,14 +338,14 @@
329 LOAD_DATA_tmp(R,S,u,t,E0,E1); \ 338 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
330 t=ROTATE(t,4); \ 339 t=ROTATE(t,4); \
331 LL^=\ 340 LL^=\
332 des_SPtrans[0][(u>> 2L)&0x3f]^ \ 341 DES_SPtrans[0][(u>> 2L)&0x3f]^ \
333 des_SPtrans[2][(u>>10L)&0x3f]^ \ 342 DES_SPtrans[2][(u>>10L)&0x3f]^ \
334 des_SPtrans[4][(u>>18L)&0x3f]^ \ 343 DES_SPtrans[4][(u>>18L)&0x3f]^ \
335 des_SPtrans[6][(u>>26L)&0x3f]^ \ 344 DES_SPtrans[6][(u>>26L)&0x3f]^ \
336 des_SPtrans[1][(t>> 2L)&0x3f]^ \ 345 DES_SPtrans[1][(t>> 2L)&0x3f]^ \
337 des_SPtrans[3][(t>>10L)&0x3f]^ \ 346 DES_SPtrans[3][(t>>10L)&0x3f]^ \
338 des_SPtrans[5][(t>>18L)&0x3f]^ \ 347 DES_SPtrans[5][(t>>18L)&0x3f]^ \
339 des_SPtrans[7][(t>>26L)&0x3f]; } 348 DES_SPtrans[7][(t>>26L)&0x3f]; }
340#endif 349#endif
341#endif 350#endif
342 351
@@ -401,8 +410,8 @@
401 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \ 410 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
402 } 411 }
403 412
404OPENSSL_EXTERN const DES_LONG des_SPtrans[8][64]; 413OPENSSL_EXTERN const DES_LONG DES_SPtrans[8][64];
405 414
406void fcrypt_body(DES_LONG *out,des_key_schedule ks, 415void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
407 DES_LONG Eswap0, DES_LONG Eswap1); 416 DES_LONG Eswap0, DES_LONG Eswap1);
408#endif 417#endif
diff --git a/src/lib/libcrypto/des/ecb3_enc.c b/src/lib/libcrypto/des/ecb3_enc.c
index 140f6b5285..c3437bc606 100644
--- a/src/lib/libcrypto/des/ecb3_enc.c
+++ b/src/lib/libcrypto/des/ecb3_enc.c
@@ -58,28 +58,24 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61void des_ecb3_encrypt(input, output, ks1, ks2, ks3, enc) 61void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
62des_cblock (*input); 62 DES_key_schedule *ks1, DES_key_schedule *ks2,
63des_cblock (*output); 63 DES_key_schedule *ks3,
64des_key_schedule ks1; 64 int enc)
65des_key_schedule ks2;
66des_key_schedule ks3;
67int enc;
68 { 65 {
69 register DES_LONG l0,l1; 66 register DES_LONG l0,l1;
70 register unsigned char *in,*out;
71 DES_LONG ll[2]; 67 DES_LONG ll[2];
68 const unsigned char *in = &(*input)[0];
69 unsigned char *out = &(*output)[0];
72 70
73 in=(unsigned char *)input;
74 out=(unsigned char *)output;
75 c2l(in,l0); 71 c2l(in,l0);
76 c2l(in,l1); 72 c2l(in,l1);
77 ll[0]=l0; 73 ll[0]=l0;
78 ll[1]=l1; 74 ll[1]=l1;
79 if (enc) 75 if (enc)
80 des_encrypt3(ll,ks1,ks2,ks3); 76 DES_encrypt3(ll,ks1,ks2,ks3);
81 else 77 else
82 des_decrypt3(ll,ks1,ks2,ks3); 78 DES_decrypt3(ll,ks1,ks2,ks3);
83 l0=ll[0]; 79 l0=ll[0];
84 l1=ll[1]; 80 l1=ll[1];
85 l2c(l0,out); 81 l2c(l0,out);
diff --git a/src/lib/libcrypto/des/ecb_enc.c b/src/lib/libcrypto/des/ecb_enc.c
index acf23fdd00..4650f2fa0f 100644
--- a/src/lib/libcrypto/des/ecb_enc.c
+++ b/src/lib/libcrypto/des/ecb_enc.c
@@ -58,20 +58,20 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60#include "spr.h" 60#include "spr.h"
61#include <openssl/opensslv.h>
61 62
62char *libdes_version="libdes v 3.24 - 20-Apr-1996 - eay"; 63OPENSSL_GLOBAL const char *libdes_version="libdes" OPENSSL_VERSION_PTEXT;
63char *DES_version="DES part of SSLeay 0.9.0b 29-Jun-1998"; 64OPENSSL_GLOBAL const char *DES_version="DES" OPENSSL_VERSION_PTEXT;
64 65
65char *des_options() 66const char *DES_options(void)
66 { 67 {
67 static int init=1; 68 static int init=1;
68 static char buf[32]; 69 static char buf[32];
69 70
70 if (init) 71 if (init)
71 { 72 {
72 char *ptr,*unroll,*risc,*size; 73 const char *ptr,*unroll,*risc,*size;
73 74
74 init=0;
75#ifdef DES_PTR 75#ifdef DES_PTR
76 ptr="ptr"; 76 ptr="ptr";
77#else 77#else
@@ -97,28 +97,24 @@ char *des_options()
97 else 97 else
98 size="long"; 98 size="long";
99 sprintf(buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,size); 99 sprintf(buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,size);
100 init=0;
100 } 101 }
101 return(buf); 102 return(buf);
102 } 103 }
103 104
104 105
105void des_ecb_encrypt(input, output, ks, enc) 106void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
106des_cblock (*input); 107 DES_key_schedule *ks, int enc)
107des_cblock (*output);
108des_key_schedule ks;
109int enc;
110 { 108 {
111 register DES_LONG l; 109 register DES_LONG l;
112 register unsigned char *in,*out;
113 DES_LONG ll[2]; 110 DES_LONG ll[2];
111 const unsigned char *in = &(*input)[0];
112 unsigned char *out = &(*output)[0];
114 113
115 in=(unsigned char *)input;
116 out=(unsigned char *)output;
117 c2l(in,l); ll[0]=l; 114 c2l(in,l); ll[0]=l;
118 c2l(in,l); ll[1]=l; 115 c2l(in,l); ll[1]=l;
119 des_encrypt(ll,ks,enc); 116 DES_encrypt1(ll,ks,enc);
120 l=ll[0]; l2c(l,out); 117 l=ll[0]; l2c(l,out);
121 l=ll[1]; l2c(l,out); 118 l=ll[1]; l2c(l,out);
122 l=ll[0]=ll[1]=0; 119 l=ll[0]=ll[1]=0;
123 } 120 }
124
diff --git a/src/lib/libcrypto/des/ede_cbcm_enc.c b/src/lib/libcrypto/des/ede_cbcm_enc.c
index c53062481d..fa45aa272b 100644
--- a/src/lib/libcrypto/des/ede_cbcm_enc.c
+++ b/src/lib/libcrypto/des/ede_cbcm_enc.c
@@ -68,12 +68,12 @@ http://www.cs.technion.ac.il/users/wwwb/cgi-bin/tr-get.cgi/1998/CS/CS0928.ps.gz
68 68
69*/ 69*/
70 70
71#ifndef NO_DESCBCM 71#ifndef OPENSSL_NO_DESCBCM
72#include "des_locl.h" 72#include "des_locl.h"
73 73
74void des_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out, 74void DES_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
75 long length, des_key_schedule ks1, des_key_schedule ks2, 75 long length, DES_key_schedule *ks1, DES_key_schedule *ks2,
76 des_key_schedule ks3, des_cblock *ivec1, des_cblock *ivec2, 76 DES_key_schedule *ks3, DES_cblock *ivec1, DES_cblock *ivec2,
77 int enc) 77 int enc)
78 { 78 {
79 register DES_LONG tin0,tin1; 79 register DES_LONG tin0,tin1;
@@ -95,7 +95,7 @@ void des_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
95 { 95 {
96 tin[0]=m0; 96 tin[0]=m0;
97 tin[1]=m1; 97 tin[1]=m1;
98 des_encrypt(tin,ks3,1); 98 DES_encrypt1(tin,ks3,1);
99 m0=tin[0]; 99 m0=tin[0];
100 m1=tin[1]; 100 m1=tin[1];
101 101
@@ -113,13 +113,13 @@ void des_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
113 113
114 tin[0]=tin0; 114 tin[0]=tin0;
115 tin[1]=tin1; 115 tin[1]=tin1;
116 des_encrypt(tin,ks1,1); 116 DES_encrypt1(tin,ks1,1);
117 tin[0]^=m0; 117 tin[0]^=m0;
118 tin[1]^=m1; 118 tin[1]^=m1;
119 des_encrypt(tin,ks2,0); 119 DES_encrypt1(tin,ks2,0);
120 tin[0]^=m0; 120 tin[0]^=m0;
121 tin[1]^=m1; 121 tin[1]^=m1;
122 des_encrypt(tin,ks1,1); 122 DES_encrypt1(tin,ks1,1);
123 tout0=tin[0]; 123 tout0=tin[0];
124 tout1=tin[1]; 124 tout1=tin[1];
125 125
@@ -146,7 +146,7 @@ void des_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
146 { 146 {
147 tin[0]=m0; 147 tin[0]=m0;
148 tin[1]=m1; 148 tin[1]=m1;
149 des_encrypt(tin,ks3,1); 149 DES_encrypt1(tin,ks3,1);
150 m0=tin[0]; 150 m0=tin[0];
151 m1=tin[1]; 151 m1=tin[1];
152 152
@@ -158,13 +158,13 @@ void des_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
158 158
159 tin[0]=tin0; 159 tin[0]=tin0;
160 tin[1]=tin1; 160 tin[1]=tin1;
161 des_encrypt(tin,ks1,0); 161 DES_encrypt1(tin,ks1,0);
162 tin[0]^=m0; 162 tin[0]^=m0;
163 tin[1]^=m1; 163 tin[1]^=m1;
164 des_encrypt(tin,ks2,1); 164 DES_encrypt1(tin,ks2,1);
165 tin[0]^=m0; 165 tin[0]^=m0;
166 tin[1]^=m1; 166 tin[1]^=m1;
167 des_encrypt(tin,ks1,0); 167 DES_encrypt1(tin,ks1,0);
168 tout0=tin[0]; 168 tout0=tin[0];
169 tout1=tin[1]; 169 tout1=tin[1];
170 170
diff --git a/src/lib/libcrypto/des/enc_read.c b/src/lib/libcrypto/des/enc_read.c
index e08a904d75..c70fb686b8 100644
--- a/src/lib/libcrypto/des/enc_read.c
+++ b/src/lib/libcrypto/des/enc_read.c
@@ -58,18 +58,34 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <errno.h> 60#include <errno.h>
61#include "cryptlib.h"
61#include "des_locl.h" 62#include "des_locl.h"
62 63
63/* This has some uglies in it but it works - even over sockets. */ 64/* This has some uglies in it but it works - even over sockets. */
64/*extern int errno;*/ 65/*extern int errno;*/
65int des_rw_mode=DES_PCBC_MODE; 66OPENSSL_IMPLEMENT_GLOBAL(int,DES_rw_mode)=DES_PCBC_MODE;
66 67
67int des_enc_read(fd, buf, len, sched, iv) 68
68int fd; 69/*
69char *buf; 70 * WARNINGS:
70int len; 71 *
71des_key_schedule sched; 72 * - The data format used by DES_enc_write() and DES_enc_read()
72des_cblock (*iv); 73 * has a cryptographic weakness: When asked to write more
74 * than MAXWRITE bytes, DES_enc_write will split the data
75 * into several chunks that are all encrypted
76 * using the same IV. So don't use these functions unless you
77 * are sure you know what you do (in which case you might
78 * not want to use them anyway).
79 *
80 * - This code cannot handle non-blocking sockets.
81 *
82 * - This function uses an internal state and thus cannot be
83 * used on multiple files.
84 */
85
86
87int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
88 DES_cblock *iv)
73 { 89 {
74 /* data to be unencrypted */ 90 /* data to be unencrypted */
75 int net_num=0; 91 int net_num=0;
@@ -77,27 +93,27 @@ des_cblock (*iv);
77 /* extra unencrypted data 93 /* extra unencrypted data
78 * for when a block of 100 comes in but is des_read one byte at 94 * for when a block of 100 comes in but is des_read one byte at
79 * a time. */ 95 * a time. */
80 static char *unnet=NULL; 96 static unsigned char *unnet=NULL;
81 static int unnet_start=0; 97 static int unnet_start=0;
82 static int unnet_left=0; 98 static int unnet_left=0;
83 static char *tmpbuf=NULL; 99 static unsigned char *tmpbuf=NULL;
84 int i; 100 int i;
85 long num=0,rnum; 101 long num=0,rnum;
86 unsigned char *p; 102 unsigned char *p;
87 103
88 if (tmpbuf == NULL) 104 if (tmpbuf == NULL)
89 { 105 {
90 tmpbuf=(char *)malloc(BSIZE); 106 tmpbuf=OPENSSL_malloc(BSIZE);
91 if (tmpbuf == NULL) return(-1); 107 if (tmpbuf == NULL) return(-1);
92 } 108 }
93 if (net == NULL) 109 if (net == NULL)
94 { 110 {
95 net=(unsigned char *)malloc(BSIZE); 111 net=OPENSSL_malloc(BSIZE);
96 if (net == NULL) return(-1); 112 if (net == NULL) return(-1);
97 } 113 }
98 if (unnet == NULL) 114 if (unnet == NULL)
99 { 115 {
100 unnet=(char *)malloc(BSIZE); 116 unnet=OPENSSL_malloc(BSIZE);
101 if (unnet == NULL) return(-1); 117 if (unnet == NULL) return(-1);
102 } 118 }
103 /* left over data from last decrypt */ 119 /* left over data from last decrypt */
@@ -109,7 +125,7 @@ des_cblock (*iv);
109 * with the number of bytes we have - should always 125 * with the number of bytes we have - should always
110 * check the return value */ 126 * check the return value */
111 memcpy(buf,&(unnet[unnet_start]), 127 memcpy(buf,&(unnet[unnet_start]),
112 (unsigned int)unnet_left); 128 unnet_left);
113 /* eay 26/08/92 I had the next 2 lines 129 /* eay 26/08/92 I had the next 2 lines
114 * reversed :-( */ 130 * reversed :-( */
115 i=unnet_left; 131 i=unnet_left;
@@ -117,7 +133,7 @@ des_cblock (*iv);
117 } 133 }
118 else 134 else
119 { 135 {
120 memcpy(buf,&(unnet[unnet_start]),(unsigned int)len); 136 memcpy(buf,&(unnet[unnet_start]),len);
121 unnet_start+=len; 137 unnet_start+=len;
122 unnet_left-=len; 138 unnet_left-=len;
123 i=len; 139 i=len;
@@ -131,7 +147,7 @@ des_cblock (*iv);
131 /* first - get the length */ 147 /* first - get the length */
132 while (net_num < HDRSIZE) 148 while (net_num < HDRSIZE)
133 { 149 {
134 i=read(fd,&(net[net_num]),(unsigned int)HDRSIZE-net_num); 150 i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num);
135#ifdef EINTR 151#ifdef EINTR
136 if ((i == -1) && (errno == EINTR)) continue; 152 if ((i == -1) && (errno == EINTR)) continue;
137#endif 153#endif
@@ -153,7 +169,7 @@ des_cblock (*iv);
153 net_num=0; 169 net_num=0;
154 while (net_num < rnum) 170 while (net_num < rnum)
155 { 171 {
156 i=read(fd,&(net[net_num]),(unsigned int)rnum-net_num); 172 i=read(fd,(void *)&(net[net_num]),rnum-net_num);
157#ifdef EINTR 173#ifdef EINTR
158 if ((i == -1) && (errno == EINTR)) continue; 174 if ((i == -1) && (errno == EINTR)) continue;
159#endif 175#endif
@@ -164,15 +180,13 @@ des_cblock (*iv);
164 /* Check if there will be data left over. */ 180 /* Check if there will be data left over. */
165 if (len < num) 181 if (len < num)
166 { 182 {
167 if (des_rw_mode & DES_PCBC_MODE) 183 if (DES_rw_mode & DES_PCBC_MODE)
168 des_pcbc_encrypt((des_cblock *)net,(des_cblock *)unnet, 184 DES_pcbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
169 num,sched,iv,DES_DECRYPT);
170 else 185 else
171 des_cbc_encrypt((des_cblock *)net,(des_cblock *)unnet, 186 DES_cbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
172 num,sched,iv,DES_DECRYPT); 187 memcpy(buf,unnet,len);
173 memcpy(buf,unnet,(unsigned int)len);
174 unnet_start=len; 188 unnet_start=len;
175 unnet_left=(int)num-len; 189 unnet_left=num-len;
176 190
177 /* The following line is done because we return num 191 /* The following line is done because we return num
178 * as the number of bytes read. */ 192 * as the number of bytes read. */
@@ -188,31 +202,27 @@ des_cblock (*iv);
188 if (len < rnum) 202 if (len < rnum)
189 { 203 {
190 204
191 if (des_rw_mode & DES_PCBC_MODE) 205 if (DES_rw_mode & DES_PCBC_MODE)
192 des_pcbc_encrypt((des_cblock *)net, 206 DES_pcbc_encrypt(net,tmpbuf,num,sched,iv,
193 (des_cblock *)tmpbuf, 207 DES_DECRYPT);
194 num,sched,iv,DES_DECRYPT);
195 else 208 else
196 des_cbc_encrypt((des_cblock *)net, 209 DES_cbc_encrypt(net,tmpbuf,num,sched,iv,
197 (des_cblock *)tmpbuf, 210 DES_DECRYPT);
198 num,sched,iv,DES_DECRYPT);
199 211
200 /* eay 26/08/92 fix a bug that returned more 212 /* eay 26/08/92 fix a bug that returned more
201 * bytes than you asked for (returned len bytes :-( */ 213 * bytes than you asked for (returned len bytes :-( */
202 memcpy(buf,tmpbuf,(unsigned int)num); 214 memcpy(buf,tmpbuf,num);
203 } 215 }
204 else 216 else
205 { 217 {
206 if (des_rw_mode & DES_PCBC_MODE) 218 if (DES_rw_mode & DES_PCBC_MODE)
207 des_pcbc_encrypt((des_cblock *)net, 219 DES_pcbc_encrypt(net,buf,num,sched,iv,
208 (des_cblock *)buf,num,sched,iv, 220 DES_DECRYPT);
209 DES_DECRYPT);
210 else 221 else
211 des_cbc_encrypt((des_cblock *)net, 222 DES_cbc_encrypt(net,buf,num,sched,iv,
212 (des_cblock *)buf,num,sched,iv, 223 DES_DECRYPT);
213 DES_DECRYPT);
214 } 224 }
215 } 225 }
216 return((int)num); 226 return num;
217 } 227 }
218 228
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c
index 29a7330fb0..af5b8c2349 100644
--- a/src/lib/libcrypto/des/enc_writ.c
+++ b/src/lib/libcrypto/des/enc_writ.c
@@ -58,32 +58,44 @@
58 58
59#include <errno.h> 59#include <errno.h>
60#include <time.h> 60#include <time.h>
61#include <stdio.h>
62#include "cryptlib.h"
61#include "des_locl.h" 63#include "des_locl.h"
64#include <openssl/rand.h>
62 65
63int des_enc_write(fd, buf, len, sched, iv) 66/*
64int fd; 67 * WARNINGS:
65char *buf; 68 *
66int len; 69 * - The data format used by DES_enc_write() and DES_enc_read()
67des_key_schedule sched; 70 * has a cryptographic weakness: When asked to write more
68des_cblock (*iv); 71 * than MAXWRITE bytes, DES_enc_write will split the data
72 * into several chunks that are all encrypted
73 * using the same IV. So don't use these functions unless you
74 * are sure you know what you do (in which case you might
75 * not want to use them anyway).
76 *
77 * - This code cannot handle non-blocking sockets.
78 */
79
80int DES_enc_write(int fd, const void *_buf, int len,
81 DES_key_schedule *sched, DES_cblock *iv)
69 { 82 {
70#ifdef _LIBC 83#ifdef _LIBC
71 extern int srandom();
72 extern unsigned long time(); 84 extern unsigned long time();
73 extern int random();
74 extern int write(); 85 extern int write();
75#endif 86#endif
76 87 const unsigned char *buf=_buf;
77 long rnum; 88 long rnum;
78 int i,j,k,outnum; 89 int i,j,k,outnum;
79 static char *outbuf=NULL; 90 static unsigned char *outbuf=NULL;
80 char shortbuf[8]; 91 unsigned char shortbuf[8];
81 char *p; 92 unsigned char *p;
93 const unsigned char *cp;
82 static int start=1; 94 static int start=1;
83 95
84 if (outbuf == NULL) 96 if (outbuf == NULL)
85 { 97 {
86 outbuf=(char *)malloc(BSIZE+HDRSIZE); 98 outbuf=OPENSSL_malloc(BSIZE+HDRSIZE);
87 if (outbuf == NULL) return(-1); 99 if (outbuf == NULL) return(-1);
88 } 100 }
89 /* If we are sending less than 8 bytes, the same char will look 101 /* If we are sending less than 8 bytes, the same char will look
@@ -91,7 +103,6 @@ des_cblock (*iv);
91 if (start) 103 if (start)
92 { 104 {
93 start=0; 105 start=0;
94 srandom((unsigned int)time(NULL));
95 } 106 }
96 107
97 /* lets recurse if we want to send the data in small chunks */ 108 /* lets recurse if we want to send the data in small chunks */
@@ -100,7 +111,7 @@ des_cblock (*iv);
100 j=0; 111 j=0;
101 for (i=0; i<len; i+=k) 112 for (i=0; i<len; i+=k)
102 { 113 {
103 k=des_enc_write(fd,&(buf[i]), 114 k=DES_enc_write(fd,&(buf[i]),
104 ((len-i) > MAXWRITE)?MAXWRITE:(len-i),sched,iv); 115 ((len-i) > MAXWRITE)?MAXWRITE:(len-i),sched,iv);
105 if (k < 0) 116 if (k < 0)
106 return(k); 117 return(k);
@@ -117,40 +128,40 @@ des_cblock (*iv);
117 /* pad short strings */ 128 /* pad short strings */
118 if (len < 8) 129 if (len < 8)
119 { 130 {
120 p=shortbuf; 131 cp=shortbuf;
121 memcpy(shortbuf,buf,(unsigned int)len); 132 memcpy(shortbuf,buf,len);
122 for (i=len; i<8; i++) 133 RAND_pseudo_bytes(shortbuf+len, 8-len);
123 shortbuf[i]=random();
124 rnum=8; 134 rnum=8;
125 } 135 }
126 else 136 else
127 { 137 {
128 p=buf; 138 cp=buf;
129 rnum=((len+7)/8*8); /* round up to nearest eight */ 139 rnum=((len+7)/8*8); /* round up to nearest eight */
130 } 140 }
131 141
132 if (des_rw_mode & DES_PCBC_MODE) 142 if (DES_rw_mode & DES_PCBC_MODE)
133 des_pcbc_encrypt((des_cblock *)p, 143 DES_pcbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
134 (des_cblock *)&(outbuf[HDRSIZE]), 144 DES_ENCRYPT);
135 (long)((len<8)?8:len),sched,iv,DES_ENCRYPT);
136 else 145 else
137 des_cbc_encrypt((des_cblock *)p, 146 DES_cbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
138 (des_cblock *)&(outbuf[HDRSIZE]), 147 DES_ENCRYPT);
139 (long)((len<8)?8:len),sched,iv,DES_ENCRYPT);
140 148
141 /* output */ 149 /* output */
142 outnum=(int)rnum+HDRSIZE; 150 outnum=rnum+HDRSIZE;
143 151
144 for (j=0; j<outnum; j+=i) 152 for (j=0; j<outnum; j+=i)
145 { 153 {
146 /* 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
147 * got upto. */ 155 * got up to. */
148 i=write(fd,&(outbuf[j]),(unsigned int)(outnum-j)); 156 i=write(fd,(void *)&(outbuf[j]),outnum-j);
149 if (i == -1) 157 if (i == -1)
150 { 158 {
159#ifdef EINTR
151 if (errno == EINTR) 160 if (errno == EINTR)
152 i=0; 161 i=0;
153 else /* This is really a bad error - very bad 162 else
163#endif
164 /* This is really a bad error - very bad
154 * It will stuff-up both ends. */ 165 * It will stuff-up both ends. */
155 return(-1); 166 return(-1);
156 } 167 }
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c
index 129beb27da..2758c32656 100644
--- a/src/lib/libcrypto/des/fcrypt.c
+++ b/src/lib/libcrypto/des/fcrypt.c
@@ -1,9 +1,16 @@
1/* NOCW */ 1/* NOCW */
2#include <stdio.h> 2#include <stdio.h>
3#ifdef _OSD_POSIX
4#ifndef CHARSET_EBCDIC
5#define CHARSET_EBCDIC 1
6#endif
7#endif
8#ifdef CHARSET_EBCDIC
9#include <openssl/ebcdic.h>
10#endif
3 11
4/* This version of crypt has been developed from my MIT compatable 12/* This version of crypt has been developed from my MIT compatible
5 * DES library. 13 * DES library.
6 * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au
7 * Eric Young (eay@cryptsoft.com) 14 * Eric Young (eay@cryptsoft.com)
8 */ 15 */
9 16
@@ -11,7 +18,7 @@
11 * I have included directive PARA for shared memory computers. 18 * I have included directive PARA for shared memory computers.
12 * I have included a directive LONGCRYPT to using this routine to cipher 19 * 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 20 * 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 21 * definition is the maximum of length of password and can changed. I have
15 * defined 24. 22 * defined 24.
16 */ 23 */
17 24
@@ -51,48 +58,54 @@ static unsigned const char cov_2char[64]={
510x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A 580x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A
52}; 59};
53 60
54#ifndef NOPROTO 61void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
55void fcrypt_body(DES_LONG *out,des_key_schedule ks, 62 DES_LONG Eswap0, DES_LONG Eswap1);
56 DES_LONG Eswap0, DES_LONG Eswap1);
57 63
58#if defined(PERL5) || defined(FreeBSD) 64char *DES_crypt(const char *buf, const char *salt)
59char *des_crypt(const char *buf,const char *salt);
60#else
61char *crypt(const char *buf,const char *salt);
62#endif
63#else
64void fcrypt_body();
65#ifdef PERL5
66char *des_crypt();
67#else
68char *crypt();
69#endif
70#endif
71
72#if defined(PERL5) || defined(FreeBSD)
73char *des_crypt(buf,salt)
74#else
75char *crypt(buf,salt)
76#endif
77const char *buf;
78const char *salt;
79 { 65 {
80 static char buff[14]; 66 static char buff[14];
81 67
82 return(des_fcrypt(buf,salt,buff)); 68#ifndef CHARSET_EBCDIC
69 return(DES_fcrypt(buf,salt,buff));
70#else
71 char e_salt[2+1];
72 char e_buf[32+1]; /* replace 32 by 8 ? */
73 char *ret;
74
75 /* Copy at most 2 chars of salt */
76 if ((e_salt[0] = salt[0]) != '\0')
77 e_salt[1] = salt[1];
78
79 /* Copy at most 32 chars of password */
80 strncpy (e_buf, buf, sizeof(e_buf));
81
82 /* Make sure we have a delimiter */
83 e_salt[sizeof(e_salt)-1] = e_buf[sizeof(e_buf)-1] = '\0';
84
85 /* Convert the e_salt to ASCII, as that's what DES_fcrypt works on */
86 ebcdic2ascii(e_salt, e_salt, sizeof e_salt);
87
88 /* Convert the cleartext password to ASCII */
89 ebcdic2ascii(e_buf, e_buf, sizeof e_buf);
90
91 /* Encrypt it (from/to ASCII) */
92 ret = DES_fcrypt(e_buf,e_salt,buff);
93
94 /* Convert the result back to EBCDIC */
95 ascii2ebcdic(ret, ret, strlen(ret));
96
97 return ret;
98#endif
83 } 99 }
84 100
85 101
86char *des_fcrypt(buf,salt,ret) 102char *DES_fcrypt(const char *buf, const char *salt, char *ret)
87const char *buf;
88const char *salt;
89char *ret;
90 { 103 {
91 unsigned int i,j,x,y; 104 unsigned int i,j,x,y;
92 DES_LONG Eswap0,Eswap1; 105 DES_LONG Eswap0,Eswap1;
93 DES_LONG out[2],ll; 106 DES_LONG out[2],ll;
94 des_cblock key; 107 DES_cblock key;
95 des_key_schedule ks; 108 DES_key_schedule ks;
96 unsigned char bb[9]; 109 unsigned char bb[9];
97 unsigned char *b=bb; 110 unsigned char *b=bb;
98 unsigned char c,u; 111 unsigned char c,u;
@@ -103,12 +116,19 @@ char *ret;
103 * returns *\0XXXXXXXXX 116 * returns *\0XXXXXXXXX
104 * The \0 makes the string look like * so the pwd "*" would 117 * The \0 makes the string look like * so the pwd "*" would
105 * crypt to "*". This was found when replacing the crypt in 118 * crypt to "*". This was found when replacing the crypt in
106 * our shared libraries. People found that the disbled 119 * our shared libraries. People found that the disabled
107 * accounts effectivly had no passwd :-(. */ 120 * accounts effectively had no passwd :-(. */
121#ifndef CHARSET_EBCDIC
108 x=ret[0]=((salt[0] == '\0')?'A':salt[0]); 122 x=ret[0]=((salt[0] == '\0')?'A':salt[0]);
109 Eswap0=con_salt[x]<<2; 123 Eswap0=con_salt[x]<<2;
110 x=ret[1]=((salt[1] == '\0')?'A':salt[1]); 124 x=ret[1]=((salt[1] == '\0')?'A':salt[1]);
111 Eswap1=con_salt[x]<<6; 125 Eswap1=con_salt[x]<<6;
126#else
127 x=ret[0]=((salt[0] == '\0')?os_toascii['A']:salt[0]);
128 Eswap0=con_salt[x]<<2;
129 x=ret[1]=((salt[1] == '\0')?os_toascii['A']:salt[1]);
130 Eswap1=con_salt[x]<<6;
131#endif
112 132
113/* EAY 133/* EAY
114r=strlen(buf); 134r=strlen(buf);
@@ -123,8 +143,8 @@ r=(r+7)/8;
123 for (; i<8; i++) 143 for (; i<8; i++)
124 key[i]=0; 144 key[i]=0;
125 145
126 des_set_key((des_cblock *)(key),ks); 146 DES_set_key_unchecked(&key,&ks);
127 fcrypt_body(&(out[0]),ks,Eswap0,Eswap1); 147 fcrypt_body(&(out[0]),&ks,Eswap0,Eswap1);
128 148
129 ll=out[0]; l2c(ll,b); 149 ll=out[0]; l2c(ll,b);
130 ll=out[1]; l2c(ll,b); 150 ll=out[1]; l2c(ll,b);
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c
index 1544634bc1..1390138787 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)
@@ -77,15 +77,12 @@
77#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ 77#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
78 (a)=(a)^(t)^(t>>(16-(n))))\ 78 (a)=(a)^(t)^(t>>(16-(n))))\
79 79
80void fcrypt_body(out, ks, Eswap0, Eswap1) 80void fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0,
81DES_LONG *out; 81 DES_LONG Eswap1)
82des_key_schedule ks;
83DES_LONG Eswap0;
84DES_LONG Eswap1;
85 { 82 {
86 register DES_LONG l,r,t,u; 83 register DES_LONG l,r,t,u;
87#ifdef DES_PTR 84#ifdef DES_PTR
88 register unsigned char *des_SP=(unsigned char *)des_SPtrans; 85 register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans;
89#endif 86#endif
90 register DES_LONG *s; 87 register DES_LONG *s;
91 register int j; 88 register int j;
@@ -100,7 +97,7 @@ DES_LONG Eswap1;
100 97
101 for (j=0; j<25; j++) 98 for (j=0; j<25; j++)
102 { 99 {
103#ifdef DES_UNROLL 100#ifndef DES_UNROLL
104 register int i; 101 register int i;
105 102
106 for (i=0; i<32; i+=8) 103 for (i=0; i<32; i+=8)
diff --git a/src/lib/libcrypto/des/ncbc_enc.c b/src/lib/libcrypto/des/ncbc_enc.c
index 1d1a368c22..fda23d522f 100644
--- a/src/lib/libcrypto/des/ncbc_enc.c
+++ b/src/lib/libcrypto/des/ncbc_enc.c
@@ -1,4 +1,9 @@
1/* crypto/des/ncbc_enc.c */ 1/* crypto/des/ncbc_enc.c */
2/*
3 * #included by:
4 * cbc_enc.c (DES_cbc_encrypt)
5 * des_enc.c (DES_ncbc_encrypt)
6 */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 7/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 8 * All rights reserved.
4 * 9 *
@@ -58,24 +63,21 @@
58 63
59#include "des_locl.h" 64#include "des_locl.h"
60 65
61void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) 66#ifdef CBC_ENC_C__DONT_UPDATE_IV
62des_cblock (*input); 67void DES_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
63des_cblock (*output); 68 DES_key_schedule *_schedule, DES_cblock *ivec, int enc)
64long length; 69#else
65des_key_schedule schedule; 70void DES_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length,
66des_cblock (*ivec); 71 DES_key_schedule *_schedule, DES_cblock *ivec, int enc)
67int enc; 72#endif
68 { 73 {
69 register DES_LONG tin0,tin1; 74 register DES_LONG tin0,tin1;
70 register DES_LONG tout0,tout1,xor0,xor1; 75 register DES_LONG tout0,tout1,xor0,xor1;
71 register unsigned char *in,*out;
72 register long l=length; 76 register long l=length;
73 DES_LONG tin[2]; 77 DES_LONG tin[2];
74 unsigned char *iv; 78 unsigned char *iv;
75 79
76 in=(unsigned char *)input; 80 iv = &(*ivec)[0];
77 out=(unsigned char *)output;
78 iv=(unsigned char *)ivec;
79 81
80 if (enc) 82 if (enc)
81 { 83 {
@@ -87,7 +89,7 @@ int enc;
87 c2l(in,tin1); 89 c2l(in,tin1);
88 tin0^=tout0; tin[0]=tin0; 90 tin0^=tout0; tin[0]=tin0;
89 tin1^=tout1; tin[1]=tin1; 91 tin1^=tout1; tin[1]=tin1;
90 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); 92 DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT);
91 tout0=tin[0]; l2c(tout0,out); 93 tout0=tin[0]; l2c(tout0,out);
92 tout1=tin[1]; l2c(tout1,out); 94 tout1=tin[1]; l2c(tout1,out);
93 } 95 }
@@ -96,13 +98,15 @@ int enc;
96 c2ln(in,tin0,tin1,l+8); 98 c2ln(in,tin0,tin1,l+8);
97 tin0^=tout0; tin[0]=tin0; 99 tin0^=tout0; tin[0]=tin0;
98 tin1^=tout1; tin[1]=tin1; 100 tin1^=tout1; tin[1]=tin1;
99 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); 101 DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT);
100 tout0=tin[0]; l2c(tout0,out); 102 tout0=tin[0]; l2c(tout0,out);
101 tout1=tin[1]; l2c(tout1,out); 103 tout1=tin[1]; l2c(tout1,out);
102 } 104 }
103 iv=(unsigned char *)ivec; 105#ifndef CBC_ENC_C__DONT_UPDATE_IV
106 iv = &(*ivec)[0];
104 l2c(tout0,iv); 107 l2c(tout0,iv);
105 l2c(tout1,iv); 108 l2c(tout1,iv);
109#endif
106 } 110 }
107 else 111 else
108 { 112 {
@@ -112,7 +116,7 @@ int enc;
112 { 116 {
113 c2l(in,tin0); tin[0]=tin0; 117 c2l(in,tin0); tin[0]=tin0;
114 c2l(in,tin1); tin[1]=tin1; 118 c2l(in,tin1); tin[1]=tin1;
115 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); 119 DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT);
116 tout0=tin[0]^xor0; 120 tout0=tin[0]^xor0;
117 tout1=tin[1]^xor1; 121 tout1=tin[1]^xor1;
118 l2c(tout0,out); 122 l2c(tout0,out);
@@ -120,11 +124,25 @@ int enc;
120 xor0=tin0; 124 xor0=tin0;
121 xor1=tin1; 125 xor1=tin1;
122 } 126 }
123 iv=(unsigned char *)ivec; 127 if (l != -8)
128 {
129 c2l(in,tin0); tin[0]=tin0;
130 c2l(in,tin1); tin[1]=tin1;
131 DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT);
132 tout0=tin[0]^xor0;
133 tout1=tin[1]^xor1;
134 l2cn(tout0,tout1,out,l+8);
135#ifndef CBC_ENC_C__DONT_UPDATE_IV
136 xor0=tin0;
137 xor1=tin1;
138#endif
139 }
140#ifndef CBC_ENC_C__DONT_UPDATE_IV
141 iv = &(*ivec)[0];
124 l2c(xor0,iv); 142 l2c(xor0,iv);
125 l2c(xor1,iv); 143 l2c(xor1,iv);
144#endif
126 } 145 }
127 tin0=tin1=tout0=tout1=xor0=xor1=0; 146 tin0=tin1=tout0=tout1=xor0=xor1=0;
128 tin[0]=tin[1]=0; 147 tin[0]=tin[1]=0;
129 } 148 }
130
diff --git a/src/lib/libcrypto/des/ofb64ede.c b/src/lib/libcrypto/des/ofb64ede.c
index 4b1b0199f1..26bbf9a6a7 100644
--- a/src/lib/libcrypto/des/ofb64ede.c
+++ b/src/lib/libcrypto/des/ofb64ede.c
@@ -62,24 +62,22 @@
62 * used. The extra state information to record how much of the 62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num; 63 * 64bit block we have used is contained in *num;
64 */ 64 */
65void des_ede3_ofb64_encrypt(in, out, length, k1,k2,k3, ivec, num) 65void DES_ede3_ofb64_encrypt(register const unsigned char *in,
66register unsigned char *in; 66 register unsigned char *out, long length,
67register unsigned char *out; 67 DES_key_schedule *k1, DES_key_schedule *k2,
68long length; 68 DES_key_schedule *k3, DES_cblock *ivec,
69des_key_schedule k1,k2,k3; 69 int *num)
70des_cblock (*ivec);
71int *num;
72 { 70 {
73 register DES_LONG v0,v1; 71 register DES_LONG v0,v1;
74 register int n= *num; 72 register int n= *num;
75 register long l=length; 73 register long l=length;
76 des_cblock d; 74 DES_cblock d;
77 register char *dp; 75 register char *dp;
78 DES_LONG ti[2]; 76 DES_LONG ti[2];
79 unsigned char *iv; 77 unsigned char *iv;
80 int save=0; 78 int save=0;
81 79
82 iv=(unsigned char *)ivec; 80 iv = &(*ivec)[0];
83 c2l(iv,v0); 81 c2l(iv,v0);
84 c2l(iv,v1); 82 c2l(iv,v1);
85 ti[0]=v0; 83 ti[0]=v0;
@@ -93,7 +91,7 @@ int *num;
93 { 91 {
94 /* ti[0]=v0; */ 92 /* ti[0]=v0; */
95 /* ti[1]=v1; */ 93 /* ti[1]=v1; */
96 des_encrypt3((DES_LONG *)ti,k1,k2,k3); 94 DES_encrypt3(ti,k1,k2,k3);
97 v0=ti[0]; 95 v0=ti[0];
98 v1=ti[1]; 96 v1=ti[1];
99 97
@@ -109,7 +107,7 @@ int *num;
109 { 107 {
110/* v0=ti[0]; 108/* v0=ti[0];
111 v1=ti[1];*/ 109 v1=ti[1];*/
112 iv=(unsigned char *)ivec; 110 iv = &(*ivec)[0];
113 l2c(v0,iv); 111 l2c(v0,iv);
114 l2c(v1,iv); 112 l2c(v1,iv);
115 } 113 }
@@ -118,14 +116,10 @@ int *num;
118 } 116 }
119 117
120#ifdef undef /* MACRO */ 118#ifdef undef /* MACRO */
121void des_ede2_ofb64_encrypt(in, out, length, k1,k2, ivec, num) 119void DES_ede2_ofb64_encrypt(register unsigned char *in,
122register unsigned char *in; 120 register unsigned char *out, long length, DES_key_schedule k1,
123register unsigned char *out; 121 DES_key_schedule k2, DES_cblock (*ivec), int *num)
124long length;
125des_key_schedule k1,k2;
126des_cblock (*ivec);
127int *num;
128 { 122 {
129 des_ede3_ofb64_encrypt(in, out, length, k1,k2,k1, ivec, num); 123 DES_ede3_ofb64_encrypt(in, out, length, k1,k2,k1, ivec, num);
130 } 124 }
131#endif 125#endif
diff --git a/src/lib/libcrypto/des/ofb64enc.c b/src/lib/libcrypto/des/ofb64enc.c
index ea7e612697..8ca3d49dea 100644
--- a/src/lib/libcrypto/des/ofb64enc.c
+++ b/src/lib/libcrypto/des/ofb64enc.c
@@ -62,37 +62,33 @@
62 * used. The extra state information to record how much of the 62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num; 63 * 64bit block we have used is contained in *num;
64 */ 64 */
65void des_ofb64_encrypt(in, out, length, schedule, ivec, num) 65void DES_ofb64_encrypt(register const unsigned char *in,
66register unsigned char *in; 66 register unsigned char *out, long length,
67register unsigned char *out; 67 DES_key_schedule *schedule, DES_cblock *ivec, int *num)
68long length;
69des_key_schedule schedule;
70des_cblock (*ivec);
71int *num;
72 { 68 {
73 register DES_LONG v0,v1,t; 69 register DES_LONG v0,v1,t;
74 register int n= *num; 70 register int n= *num;
75 register long l=length; 71 register long l=length;
76 des_cblock d; 72 DES_cblock d;
77 register char *dp; 73 register unsigned char *dp;
78 DES_LONG ti[2]; 74 DES_LONG ti[2];
79 unsigned char *iv; 75 unsigned char *iv;
80 int save=0; 76 int save=0;
81 77
82 iv=(unsigned char *)ivec; 78 iv = &(*ivec)[0];
83 c2l(iv,v0); 79 c2l(iv,v0);
84 c2l(iv,v1); 80 c2l(iv,v1);
85 ti[0]=v0; 81 ti[0]=v0;
86 ti[1]=v1; 82 ti[1]=v1;
87 dp=(char *)d; 83 dp=d;
88 l2c(v0,dp); 84 l2c(v0,dp);
89 l2c(v1,dp); 85 l2c(v1,dp);
90 while (l--) 86 while (l--)
91 { 87 {
92 if (n == 0) 88 if (n == 0)
93 { 89 {
94 des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); 90 DES_encrypt1(ti,schedule,DES_ENCRYPT);
95 dp=(char *)d; 91 dp=d;
96 t=ti[0]; l2c(t,dp); 92 t=ti[0]; l2c(t,dp);
97 t=ti[1]; l2c(t,dp); 93 t=ti[1]; l2c(t,dp);
98 save++; 94 save++;
@@ -104,7 +100,7 @@ int *num;
104 { 100 {
105 v0=ti[0]; 101 v0=ti[0];
106 v1=ti[1]; 102 v1=ti[1];
107 iv=(unsigned char *)ivec; 103 iv = &(*ivec)[0];
108 l2c(v0,iv); 104 l2c(v0,iv);
109 l2c(v1,iv); 105 l2c(v1,iv);
110 } 106 }
diff --git a/src/lib/libcrypto/des/ofb_enc.c b/src/lib/libcrypto/des/ofb_enc.c
index 4db0cdbd60..e887a3c6f4 100644
--- a/src/lib/libcrypto/des/ofb_enc.c
+++ b/src/lib/libcrypto/des/ofb_enc.c
@@ -64,13 +64,9 @@
64 * the second. The second 12 bits will come from the 3rd and half the 4th 64 * the second. The second 12 bits will come from the 3rd and half the 4th
65 * byte. 65 * byte.
66 */ 66 */
67void des_ofb_encrypt(in, out, numbits, length, schedule, ivec) 67void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
68unsigned char *in; 68 long length, DES_key_schedule *schedule,
69unsigned char *out; 69 DES_cblock *ivec)
70int numbits;
71long length;
72des_key_schedule schedule;
73des_cblock (*ivec);
74 { 70 {
75 register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8; 71 register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8;
76 register DES_LONG mask0,mask1; 72 register DES_LONG mask0,mask1;
@@ -97,7 +93,7 @@ des_cblock (*ivec);
97 mask1=0x00000000L; 93 mask1=0x00000000L;
98 } 94 }
99 95
100 iv=(unsigned char *)ivec; 96 iv = &(*ivec)[0];
101 c2l(iv,v0); 97 c2l(iv,v0);
102 c2l(iv,v1); 98 c2l(iv,v1);
103 ti[0]=v0; 99 ti[0]=v0;
@@ -106,7 +102,7 @@ des_cblock (*ivec);
106 { 102 {
107 ti[0]=v0; 103 ti[0]=v0;
108 ti[1]=v1; 104 ti[1]=v1;
109 des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); 105 DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT);
110 vv0=ti[0]; 106 vv0=ti[0];
111 vv1=ti[1]; 107 vv1=ti[1];
112 c2ln(in,d0,d1,n); 108 c2ln(in,d0,d1,n);
@@ -131,7 +127,7 @@ des_cblock (*ivec);
131 v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL; 127 v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL;
132 } 128 }
133 } 129 }
134 iv=(unsigned char *)ivec; 130 iv = &(*ivec)[0];
135 l2c(v0,iv); 131 l2c(v0,iv);
136 l2c(v1,iv); 132 l2c(v1,iv);
137 v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0; 133 v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0;
diff --git a/src/lib/libcrypto/des/pcbc_enc.c b/src/lib/libcrypto/des/pcbc_enc.c
index 4513207d90..17a40f9520 100644
--- a/src/lib/libcrypto/des/pcbc_enc.c
+++ b/src/lib/libcrypto/des/pcbc_enc.c
@@ -58,21 +58,18 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61void des_pcbc_encrypt(input, output, length, schedule, ivec, enc) 61void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
62des_cblock (*input); 62 long length, DES_key_schedule *schedule,
63des_cblock (*output); 63 DES_cblock *ivec, int enc)
64long length;
65des_key_schedule schedule;
66des_cblock (*ivec);
67int enc;
68 { 64 {
69 register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1; 65 register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1;
70 DES_LONG tin[2]; 66 DES_LONG tin[2];
71 unsigned char *in,*out,*iv; 67 const unsigned char *in;
68 unsigned char *out,*iv;
72 69
73 in=(unsigned char *)input; 70 in=input;
74 out=(unsigned char *)output; 71 out=output;
75 iv=(unsigned char *)ivec; 72 iv = &(*ivec)[0];
76 73
77 if (enc) 74 if (enc)
78 { 75 {
@@ -89,7 +86,7 @@ int enc;
89 c2ln(in,sin0,sin1,length); 86 c2ln(in,sin0,sin1,length);
90 tin[0]=sin0^xor0; 87 tin[0]=sin0^xor0;
91 tin[1]=sin1^xor1; 88 tin[1]=sin1^xor1;
92 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); 89 DES_encrypt1((DES_LONG *)tin,schedule,DES_ENCRYPT);
93 tout0=tin[0]; 90 tout0=tin[0];
94 tout1=tin[1]; 91 tout1=tin[1];
95 xor0=sin0^tout0; 92 xor0=sin0^tout0;
@@ -107,7 +104,7 @@ int enc;
107 c2l(in,sin1); 104 c2l(in,sin1);
108 tin[0]=sin0; 105 tin[0]=sin0;
109 tin[1]=sin1; 106 tin[1]=sin1;
110 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); 107 DES_encrypt1((DES_LONG *)tin,schedule,DES_DECRYPT);
111 tout0=tin[0]^xor0; 108 tout0=tin[0]^xor0;
112 tout1=tin[1]^xor1; 109 tout1=tin[1]^xor1;
113 if (length >= 8) 110 if (length >= 8)
diff --git a/src/lib/libcrypto/des/qud_cksm.c b/src/lib/libcrypto/des/qud_cksm.c
index 8526abf334..dac201227e 100644
--- a/src/lib/libcrypto/des/qud_cksm.c
+++ b/src/lib/libcrypto/des/qud_cksm.c
@@ -73,28 +73,32 @@
73/* Got the value MIT uses via brute force :-) 2/10/90 eay */ 73/* Got the value MIT uses via brute force :-) 2/10/90 eay */
74#define NOISE ((DES_LONG)83653421L) 74#define NOISE ((DES_LONG)83653421L)
75 75
76DES_LONG des_quad_cksum(input, output, length, out_count, seed) 76DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
77des_cblock (*input); 77 long length, int out_count, DES_cblock *seed)
78des_cblock (*output);
79long length;
80int out_count;
81des_cblock (*seed);
82 { 78 {
83 DES_LONG z0,z1,t0,t1; 79 DES_LONG z0,z1,t0,t1;
84 int i; 80 int i;
85 long l; 81 long l;
86 unsigned char *cp; 82 const unsigned char *cp;
87 unsigned char *lp; 83#ifdef _CRAY
84 struct lp_st { int a:32; int b:32; } *lp;
85#else
86 DES_LONG *lp;
87#endif
88 88
89 if (out_count < 1) out_count=1; 89 if (out_count < 1) out_count=1;
90 lp=(unsigned char *)output; 90#ifdef _CRAY
91 lp = (struct lp_st *) &(output[0])[0];
92#else
93 lp = (DES_LONG *) &(output[0])[0];
94#endif
91 95
92 z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]); 96 z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]);
93 z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]); 97 z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]);
94 98
95 for (i=0; ((i<4)&&(i<out_count)); i++) 99 for (i=0; ((i<4)&&(i<out_count)); i++)
96 { 100 {
97 cp=(unsigned char *)input; 101 cp=input;
98 l=length; 102 l=length;
99 while (l > 0) 103 while (l > 0)
100 { 104 {
@@ -118,25 +122,16 @@ des_cblock (*seed);
118 } 122 }
119 if (lp != NULL) 123 if (lp != NULL)
120 { 124 {
121 /* I believe I finally have things worked out. 125 /* The MIT library assumes that the checksum is
122 * The MIT library assumes that the checksum 126 * composed of 2*out_count 32 bit ints */
123 * is one huge number and it is returned in a 127#ifdef _CRAY
124 * host dependant byte order. 128 (*lp).a = z0;
125 */ 129 (*lp).b = z1;
126 static DES_LONG ltmp=1; 130 lp++;
127 static unsigned char *c=(unsigned char *)&ltmp; 131#else
128 132 *lp++ = z0;
129 if (c[0]) 133 *lp++ = z1;
130 { 134#endif
131 l2c(z0,lp);
132 l2c(z1,lp);
133 }
134 else
135 {
136 lp=output[out_count-i-1];
137 l2n(z1,lp);
138 l2n(z0,lp);
139 }
140 } 135 }
141 } 136 }
142 return(z0); 137 return(z0);
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c
index 8c30bd029a..2398165568 100644
--- a/src/lib/libcrypto/des/rand_key.c
+++ b/src/lib/libcrypto/des/rand_key.c
@@ -1,118 +1,68 @@
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 58
62static int seed=0; 59int DES_random_key(DES_cblock *ret)
63static des_cblock init;
64
65void des_random_seed(key)
66des_cblock key;
67 {
68 memcpy(init,key,sizeof(des_cblock));
69 seed=1;
70 }
71
72void des_random_key(ret)
73unsigned char *ret;
74 { 60 {
75 des_key_schedule ks; 61 do
76 static DES_LONG c=0;
77 static unsigned short pid=0;
78 static des_cblock data={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
79 des_cblock key;
80 unsigned char *p;
81 DES_LONG t;
82 int i;
83
84#ifdef MSDOS
85 pid=1;
86#else
87 if (!pid) pid=getpid();
88#endif
89 p=key;
90 if (seed)
91 { 62 {
92 for (i=0; i<8; i++) 63 if (RAND_bytes((unsigned char *)ret, sizeof(DES_cblock)) != 1)
93 { 64 return (0);
94 data[i] ^= init[i]; 65 } while (DES_is_weak_key(ret));
95 init[i]=0; 66 DES_set_odd_parity(ret);
96 } 67 return (1);
97 seed=0;
98 }
99 t=(DES_LONG)time(NULL);
100 l2c(t,p);
101 t=(DES_LONG)((pid)|((c++)<<16));
102 l2c(t,p);
103
104 des_set_odd_parity((des_cblock *)data);
105 des_set_key((des_cblock *)data,ks);
106 des_cbc_cksum((des_cblock *)key,(des_cblock *)key,
107 (long)sizeof(key),ks,(des_cblock *)data);
108
109 des_set_odd_parity((des_cblock *)key);
110 des_set_key((des_cblock *)key,ks);
111 des_cbc_cksum((des_cblock *)key,(des_cblock *)data,
112 (long)sizeof(key),ks,(des_cblock *)key);
113
114 memcpy(ret,data,sizeof(key));
115 memset(key,0,sizeof(key));
116 memset(ks,0,sizeof(ks));
117 t=0;
118 } 68 }
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c
index c3bcd7ee2b..683916e71b 100644
--- a/src/lib/libcrypto/des/set_key.c
+++ b/src/lib/libcrypto/des/set_key.c
@@ -64,19 +64,28 @@
64 * 1.0 First working version 64 * 1.0 First working version
65 */ 65 */
66#include "des_locl.h" 66#include "des_locl.h"
67#include "podd.h"
68#include "sk.h"
69 67
70#ifndef NOPROTO 68OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key); /* defaults to false */
71static int check_parity(des_cblock (*key));
72#else
73static int check_parity();
74#endif
75 69
76int des_check_key=0; 70static const unsigned char odd_parity[256]={
71 1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
72 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
73 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
74 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
75 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
76 81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
77 97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110,
78112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127,
79128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143,
80145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158,
81161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174,
82176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191,
83193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206,
84208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223,
85224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239,
86241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254};
77 87
78void des_set_odd_parity(key) 88void DES_set_odd_parity(DES_cblock *key)
79des_cblock (*key);
80 { 89 {
81 int i; 90 int i;
82 91
@@ -84,8 +93,7 @@ des_cblock (*key);
84 (*key)[i]=odd_parity[(*key)[i]]; 93 (*key)[i]=odd_parity[(*key)[i]];
85 } 94 }
86 95
87static int check_parity(key) 96int DES_check_key_parity(const_DES_cblock *key)
88des_cblock (*key);
89 { 97 {
90 int i; 98 int i;
91 99
@@ -107,12 +115,12 @@ des_cblock (*key);
107 * (and actual cblock values). 115 * (and actual cblock values).
108 */ 116 */
109#define NUM_WEAK_KEY 16 117#define NUM_WEAK_KEY 16
110static des_cblock weak_keys[NUM_WEAK_KEY]={ 118static DES_cblock weak_keys[NUM_WEAK_KEY]={
111 /* weak keys */ 119 /* weak keys */
112 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, 120 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
113 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE}, 121 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
114 {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, 122 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
115 {0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0}, 123 {0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1},
116 /* semi-weak keys */ 124 /* semi-weak keys */
117 {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE}, 125 {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
118 {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01}, 126 {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
@@ -127,19 +135,18 @@ static des_cblock weak_keys[NUM_WEAK_KEY]={
127 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, 135 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
128 {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}}; 136 {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
129 137
130int des_is_weak_key(key) 138int DES_is_weak_key(const_DES_cblock *key)
131des_cblock (*key);
132 { 139 {
133 int i; 140 int i;
134 141
135 for (i=0; i<NUM_WEAK_KEY; i++) 142 for (i=0; i<NUM_WEAK_KEY; i++)
136 /* Added == 0 to comparision, I obviously don't run 143 /* Added == 0 to comparison, I obviously don't run
137 * this section very often :-(, thanks to 144 * this section very often :-(, thanks to
138 * engineering@MorningStar.Com for the fix 145 * engineering@MorningStar.Com for the fix
139 * eay 93/06/29 146 * eay 93/06/29
140 * Another problem, I was comparing only the first 4 147 * Another problem, I was comparing only the first 4
141 * bytes, 97/03/18 */ 148 * bytes, 97/03/18 */
142 if (memcmp(weak_keys[i],key,sizeof(des_cblock)) == 0) return(1); 149 if (memcmp(weak_keys[i],key,sizeof(DES_cblock)) == 0) return(1);
143 return(0); 150 return(0);
144 } 151 }
145 152
@@ -153,49 +160,199 @@ des_cblock (*key);
153#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ 160#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
154 (a)=(a)^(t)^(t>>(16-(n)))) 161 (a)=(a)^(t)^(t>>(16-(n))))
155 162
163static const DES_LONG des_skb[8][64]={
164 {
165 /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
166 0x00000000L,0x00000010L,0x20000000L,0x20000010L,
167 0x00010000L,0x00010010L,0x20010000L,0x20010010L,
168 0x00000800L,0x00000810L,0x20000800L,0x20000810L,
169 0x00010800L,0x00010810L,0x20010800L,0x20010810L,
170 0x00000020L,0x00000030L,0x20000020L,0x20000030L,
171 0x00010020L,0x00010030L,0x20010020L,0x20010030L,
172 0x00000820L,0x00000830L,0x20000820L,0x20000830L,
173 0x00010820L,0x00010830L,0x20010820L,0x20010830L,
174 0x00080000L,0x00080010L,0x20080000L,0x20080010L,
175 0x00090000L,0x00090010L,0x20090000L,0x20090010L,
176 0x00080800L,0x00080810L,0x20080800L,0x20080810L,
177 0x00090800L,0x00090810L,0x20090800L,0x20090810L,
178 0x00080020L,0x00080030L,0x20080020L,0x20080030L,
179 0x00090020L,0x00090030L,0x20090020L,0x20090030L,
180 0x00080820L,0x00080830L,0x20080820L,0x20080830L,
181 0x00090820L,0x00090830L,0x20090820L,0x20090830L,
182 },{
183 /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
184 0x00000000L,0x02000000L,0x00002000L,0x02002000L,
185 0x00200000L,0x02200000L,0x00202000L,0x02202000L,
186 0x00000004L,0x02000004L,0x00002004L,0x02002004L,
187 0x00200004L,0x02200004L,0x00202004L,0x02202004L,
188 0x00000400L,0x02000400L,0x00002400L,0x02002400L,
189 0x00200400L,0x02200400L,0x00202400L,0x02202400L,
190 0x00000404L,0x02000404L,0x00002404L,0x02002404L,
191 0x00200404L,0x02200404L,0x00202404L,0x02202404L,
192 0x10000000L,0x12000000L,0x10002000L,0x12002000L,
193 0x10200000L,0x12200000L,0x10202000L,0x12202000L,
194 0x10000004L,0x12000004L,0x10002004L,0x12002004L,
195 0x10200004L,0x12200004L,0x10202004L,0x12202004L,
196 0x10000400L,0x12000400L,0x10002400L,0x12002400L,
197 0x10200400L,0x12200400L,0x10202400L,0x12202400L,
198 0x10000404L,0x12000404L,0x10002404L,0x12002404L,
199 0x10200404L,0x12200404L,0x10202404L,0x12202404L,
200 },{
201 /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
202 0x00000000L,0x00000001L,0x00040000L,0x00040001L,
203 0x01000000L,0x01000001L,0x01040000L,0x01040001L,
204 0x00000002L,0x00000003L,0x00040002L,0x00040003L,
205 0x01000002L,0x01000003L,0x01040002L,0x01040003L,
206 0x00000200L,0x00000201L,0x00040200L,0x00040201L,
207 0x01000200L,0x01000201L,0x01040200L,0x01040201L,
208 0x00000202L,0x00000203L,0x00040202L,0x00040203L,
209 0x01000202L,0x01000203L,0x01040202L,0x01040203L,
210 0x08000000L,0x08000001L,0x08040000L,0x08040001L,
211 0x09000000L,0x09000001L,0x09040000L,0x09040001L,
212 0x08000002L,0x08000003L,0x08040002L,0x08040003L,
213 0x09000002L,0x09000003L,0x09040002L,0x09040003L,
214 0x08000200L,0x08000201L,0x08040200L,0x08040201L,
215 0x09000200L,0x09000201L,0x09040200L,0x09040201L,
216 0x08000202L,0x08000203L,0x08040202L,0x08040203L,
217 0x09000202L,0x09000203L,0x09040202L,0x09040203L,
218 },{
219 /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
220 0x00000000L,0x00100000L,0x00000100L,0x00100100L,
221 0x00000008L,0x00100008L,0x00000108L,0x00100108L,
222 0x00001000L,0x00101000L,0x00001100L,0x00101100L,
223 0x00001008L,0x00101008L,0x00001108L,0x00101108L,
224 0x04000000L,0x04100000L,0x04000100L,0x04100100L,
225 0x04000008L,0x04100008L,0x04000108L,0x04100108L,
226 0x04001000L,0x04101000L,0x04001100L,0x04101100L,
227 0x04001008L,0x04101008L,0x04001108L,0x04101108L,
228 0x00020000L,0x00120000L,0x00020100L,0x00120100L,
229 0x00020008L,0x00120008L,0x00020108L,0x00120108L,
230 0x00021000L,0x00121000L,0x00021100L,0x00121100L,
231 0x00021008L,0x00121008L,0x00021108L,0x00121108L,
232 0x04020000L,0x04120000L,0x04020100L,0x04120100L,
233 0x04020008L,0x04120008L,0x04020108L,0x04120108L,
234 0x04021000L,0x04121000L,0x04021100L,0x04121100L,
235 0x04021008L,0x04121008L,0x04021108L,0x04121108L,
236 },{
237 /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
238 0x00000000L,0x10000000L,0x00010000L,0x10010000L,
239 0x00000004L,0x10000004L,0x00010004L,0x10010004L,
240 0x20000000L,0x30000000L,0x20010000L,0x30010000L,
241 0x20000004L,0x30000004L,0x20010004L,0x30010004L,
242 0x00100000L,0x10100000L,0x00110000L,0x10110000L,
243 0x00100004L,0x10100004L,0x00110004L,0x10110004L,
244 0x20100000L,0x30100000L,0x20110000L,0x30110000L,
245 0x20100004L,0x30100004L,0x20110004L,0x30110004L,
246 0x00001000L,0x10001000L,0x00011000L,0x10011000L,
247 0x00001004L,0x10001004L,0x00011004L,0x10011004L,
248 0x20001000L,0x30001000L,0x20011000L,0x30011000L,
249 0x20001004L,0x30001004L,0x20011004L,0x30011004L,
250 0x00101000L,0x10101000L,0x00111000L,0x10111000L,
251 0x00101004L,0x10101004L,0x00111004L,0x10111004L,
252 0x20101000L,0x30101000L,0x20111000L,0x30111000L,
253 0x20101004L,0x30101004L,0x20111004L,0x30111004L,
254 },{
255 /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
256 0x00000000L,0x08000000L,0x00000008L,0x08000008L,
257 0x00000400L,0x08000400L,0x00000408L,0x08000408L,
258 0x00020000L,0x08020000L,0x00020008L,0x08020008L,
259 0x00020400L,0x08020400L,0x00020408L,0x08020408L,
260 0x00000001L,0x08000001L,0x00000009L,0x08000009L,
261 0x00000401L,0x08000401L,0x00000409L,0x08000409L,
262 0x00020001L,0x08020001L,0x00020009L,0x08020009L,
263 0x00020401L,0x08020401L,0x00020409L,0x08020409L,
264 0x02000000L,0x0A000000L,0x02000008L,0x0A000008L,
265 0x02000400L,0x0A000400L,0x02000408L,0x0A000408L,
266 0x02020000L,0x0A020000L,0x02020008L,0x0A020008L,
267 0x02020400L,0x0A020400L,0x02020408L,0x0A020408L,
268 0x02000001L,0x0A000001L,0x02000009L,0x0A000009L,
269 0x02000401L,0x0A000401L,0x02000409L,0x0A000409L,
270 0x02020001L,0x0A020001L,0x02020009L,0x0A020009L,
271 0x02020401L,0x0A020401L,0x02020409L,0x0A020409L,
272 },{
273 /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
274 0x00000000L,0x00000100L,0x00080000L,0x00080100L,
275 0x01000000L,0x01000100L,0x01080000L,0x01080100L,
276 0x00000010L,0x00000110L,0x00080010L,0x00080110L,
277 0x01000010L,0x01000110L,0x01080010L,0x01080110L,
278 0x00200000L,0x00200100L,0x00280000L,0x00280100L,
279 0x01200000L,0x01200100L,0x01280000L,0x01280100L,
280 0x00200010L,0x00200110L,0x00280010L,0x00280110L,
281 0x01200010L,0x01200110L,0x01280010L,0x01280110L,
282 0x00000200L,0x00000300L,0x00080200L,0x00080300L,
283 0x01000200L,0x01000300L,0x01080200L,0x01080300L,
284 0x00000210L,0x00000310L,0x00080210L,0x00080310L,
285 0x01000210L,0x01000310L,0x01080210L,0x01080310L,
286 0x00200200L,0x00200300L,0x00280200L,0x00280300L,
287 0x01200200L,0x01200300L,0x01280200L,0x01280300L,
288 0x00200210L,0x00200310L,0x00280210L,0x00280310L,
289 0x01200210L,0x01200310L,0x01280210L,0x01280310L,
290 },{
291 /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
292 0x00000000L,0x04000000L,0x00040000L,0x04040000L,
293 0x00000002L,0x04000002L,0x00040002L,0x04040002L,
294 0x00002000L,0x04002000L,0x00042000L,0x04042000L,
295 0x00002002L,0x04002002L,0x00042002L,0x04042002L,
296 0x00000020L,0x04000020L,0x00040020L,0x04040020L,
297 0x00000022L,0x04000022L,0x00040022L,0x04040022L,
298 0x00002020L,0x04002020L,0x00042020L,0x04042020L,
299 0x00002022L,0x04002022L,0x00042022L,0x04042022L,
300 0x00000800L,0x04000800L,0x00040800L,0x04040800L,
301 0x00000802L,0x04000802L,0x00040802L,0x04040802L,
302 0x00002800L,0x04002800L,0x00042800L,0x04042800L,
303 0x00002802L,0x04002802L,0x00042802L,0x04042802L,
304 0x00000820L,0x04000820L,0x00040820L,0x04040820L,
305 0x00000822L,0x04000822L,0x00040822L,0x04040822L,
306 0x00002820L,0x04002820L,0x00042820L,0x04042820L,
307 0x00002822L,0x04002822L,0x00042822L,0x04042822L,
308 }};
309
310int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule)
311 {
312 if (DES_check_key)
313 {
314 return DES_set_key_checked(key, schedule);
315 }
316 else
317 {
318 DES_set_key_unchecked(key, schedule);
319 return 0;
320 }
321 }
322
156/* return 0 if key parity is odd (correct), 323/* return 0 if key parity is odd (correct),
157 * return -1 if key parity error, 324 * return -1 if key parity error,
158 * return -2 if illegal weak key. 325 * return -2 if illegal weak key.
159 */ 326 */
160int des_set_key(key, schedule) 327int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule)
161des_cblock (*key); 328 {
162des_key_schedule schedule; 329 if (!DES_check_key_parity(key))
330 return(-1);
331 if (DES_is_weak_key(key))
332 return(-2);
333 DES_set_key_unchecked(key, schedule);
334 return 0;
335 }
336
337void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)
163 { 338 {
164 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0}; 339 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
165 register DES_LONG c,d,t,s,t2; 340 register DES_LONG c,d,t,s,t2;
166 register unsigned char *in; 341 register const unsigned char *in;
167 register DES_LONG *k; 342 register DES_LONG *k;
168 register int i; 343 register int i;
169 344
170 if (des_check_key) 345#if OPENBSD_DEV_CRYPTO
171 { 346 memcpy(schedule->key,key,sizeof schedule->key);
172 if (!check_parity(key)) 347 schedule->session=NULL;
173 return(-1); 348#endif
174 349 k = &schedule->ks->deslong[0];
175 if (des_is_weak_key(key)) 350 in = &(*key)[0];
176 return(-2);
177 }
178
179 k=(DES_LONG *)schedule;
180 in=(unsigned char *)key;
181 351
182 c2l(in,c); 352 c2l(in,c);
183 c2l(in,d); 353 c2l(in,d);
184 354
185 /* do PC1 in 60 simple operations */ 355 /* do PC1 in 47 simple operations :-)
186/* PERM_OP(d,c,t,4,0x0f0f0f0fL);
187 HPERM_OP(c,t,-2, 0xcccc0000L);
188 HPERM_OP(c,t,-1, 0xaaaa0000L);
189 HPERM_OP(c,t, 8, 0x00ff0000L);
190 HPERM_OP(c,t,-1, 0xaaaa0000L);
191 HPERM_OP(d,t,-8, 0xff000000L);
192 HPERM_OP(d,t, 8, 0x00ff0000L);
193 HPERM_OP(d,t, 2, 0x33330000L);
194 d=((d&0x00aa00aaL)<<7L)|((d&0x55005500L)>>7L)|(d&0xaa55aa55L);
195 d=(d>>8)|((c&0xf0000000L)>>4);
196 c&=0x0fffffffL; */
197
198 /* I now do it in 47 simple operations :-)
199 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov) 356 * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
200 * for the inspiration. :-) */ 357 * for the inspiration. :-) */
201 PERM_OP (d,c,t,4,0x0f0f0f0fL); 358 PERM_OP (d,c,t,4,0x0f0f0f0fL);
@@ -219,9 +376,9 @@ des_key_schedule schedule;
219 /* could be a few less shifts but I am to lazy at this 376 /* could be a few less shifts but I am to lazy at this
220 * point in time to investigate */ 377 * point in time to investigate */
221 s= des_skb[0][ (c )&0x3f ]| 378 s= des_skb[0][ (c )&0x3f ]|
222 des_skb[1][((c>> 6)&0x03)|((c>> 7L)&0x3c)]| 379 des_skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]|
223 des_skb[2][((c>>13)&0x0f)|((c>>14L)&0x30)]| 380 des_skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]|
224 des_skb[3][((c>>20)&0x01)|((c>>21L)&0x06) | 381 des_skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) |
225 ((c>>22L)&0x38)]; 382 ((c>>22L)&0x38)];
226 t= des_skb[4][ (d )&0x3f ]| 383 t= des_skb[4][ (d )&0x3f ]|
227 des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]| 384 des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]|
@@ -235,12 +392,16 @@ des_key_schedule schedule;
235 t2=((s>>16L)|(t&0xffff0000L)); 392 t2=((s>>16L)|(t&0xffff0000L));
236 *(k++)=ROTATE(t2,26)&0xffffffffL; 393 *(k++)=ROTATE(t2,26)&0xffffffffL;
237 } 394 }
238 return(0);
239 } 395 }
240 396
241int des_key_sched(key, schedule) 397int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule)
242des_cblock (*key); 398 {
243des_key_schedule schedule; 399 return(DES_set_key(key,schedule));
400 }
401/*
402#undef des_fixup_key_parity
403void des_fixup_key_parity(des_cblock *key)
244 { 404 {
245 return(des_set_key(key,schedule)); 405 des_set_odd_parity(key);
246 } 406 }
407*/
diff --git a/src/lib/libcrypto/des/spr.h b/src/lib/libcrypto/des/spr.h
index 81813f9f7a..b91936a5a5 100644
--- a/src/lib/libcrypto/des/spr.h
+++ b/src/lib/libcrypto/des/spr.h
@@ -56,7 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59const DES_LONG des_SPtrans[8][64]={ 59OPENSSL_GLOBAL const DES_LONG DES_SPtrans[8][64]={
60{ 60{
61/* nibble 0 */ 61/* nibble 0 */
620x02080800L, 0x00080000L, 0x02000002L, 0x02080802L, 620x02080800L, 0x00080000L, 0x02000002L, 0x02080802L,
diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c
index 3365c1bcf3..36c3f81d99 100644
--- a/src/lib/libcrypto/des/str2key.c
+++ b/src/lib/libcrypto/des/str2key.c
@@ -58,13 +58,9 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61extern int des_check_key; 61void DES_string_to_key(const char *str, DES_cblock *key)
62
63void des_string_to_key(str, key)
64char *str;
65des_cblock (*key);
66 { 62 {
67 des_key_schedule ks; 63 DES_key_schedule ks;
68 int i,length; 64 int i,length;
69 register unsigned char j; 65 register unsigned char j;
70 66
@@ -89,23 +85,22 @@ des_cblock (*key);
89 } 85 }
90 } 86 }
91#endif 87#endif
92 des_set_odd_parity((des_cblock *)key); 88 DES_set_odd_parity(key);
93 i=des_check_key; 89#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
94 des_check_key=0; 90 if(DES_is_weak_key(key))
95 des_set_key((des_cblock *)key,ks); 91 (*key)[7] ^= 0xF0;
96 des_check_key=i; 92 DES_set_key(key,&ks);
97 des_cbc_cksum((des_cblock *)str,(des_cblock *)key,(long)length,ks, 93#else
98 (des_cblock *)key); 94 DES_set_key_unchecked(key,&ks);
99 memset(ks,0,sizeof(ks)); 95#endif
100 des_set_odd_parity((des_cblock *)key); 96 DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key);
97 memset(&ks,0,sizeof(ks));
98 DES_set_odd_parity(key);
101 } 99 }
102 100
103void des_string_to_2keys(str, key1, key2) 101void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2)
104char *str;
105des_cblock (*key1);
106des_cblock (*key2);
107 { 102 {
108 des_key_schedule ks; 103 DES_key_schedule ks;
109 int i,length; 104 int i,length;
110 register unsigned char j; 105 register unsigned char j;
111 106
@@ -154,18 +149,25 @@ des_cblock (*key2);
154 } 149 }
155 if (length <= 8) memcpy(key2,key1,8); 150 if (length <= 8) memcpy(key2,key1,8);
156#endif 151#endif
157 des_set_odd_parity((des_cblock *)key1); 152 DES_set_odd_parity(key1);
158 des_set_odd_parity((des_cblock *)key2); 153 DES_set_odd_parity(key2);
159 i=des_check_key; 154#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
160 des_check_key=0; 155 if(DES_is_weak_key(key1))
161 des_set_key((des_cblock *)key1,ks); 156 (*key1)[7] ^= 0xF0;
162 des_cbc_cksum((des_cblock *)str,(des_cblock *)key1,(long)length,ks, 157 DES_set_key(key1,&ks);
163 (des_cblock *)key1); 158#else
164 des_set_key((des_cblock *)key2,ks); 159 DES_set_key_unchecked(key1,&ks);
165 des_cbc_cksum((des_cblock *)str,(des_cblock *)key2,(long)length,ks, 160#endif
166 (des_cblock *)key2); 161 DES_cbc_cksum((const unsigned char*)str,key1,length,&ks,key1);
167 des_check_key=i; 162#ifdef EXPERIMENTAL_STR_TO_STRONG_KEY
168 memset(ks,0,sizeof(ks)); 163 if(DES_is_weak_key(key2))
169 des_set_odd_parity(key1); 164 (*key2)[7] ^= 0xF0;
170 des_set_odd_parity(key2); 165 DES_set_key(key2,&ks);
166#else
167 DES_set_key_unchecked(key2,&ks);
168#endif
169 DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2);
170 memset(&ks,0,sizeof(ks));
171 DES_set_odd_parity(key1);
172 DES_set_odd_parity(key2);
171 } 173 }
diff --git a/src/lib/libcrypto/des/xcbc_enc.c b/src/lib/libcrypto/des/xcbc_enc.c
index 031589bf50..47246eb466 100644
--- a/src/lib/libcrypto/des/xcbc_enc.c
+++ b/src/lib/libcrypto/des/xcbc_enc.c
@@ -79,18 +79,14 @@ static unsigned char desx_white_in2out[256]={
790xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF,0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB, 790xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF,0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB,
80 }; 80 };
81 81
82void des_xwhite_in2out(des_key,in_white,out_white) 82void DES_xwhite_in2out(const_DES_cblock *des_key, const_DES_cblock *in_white,
83des_cblock (*des_key); 83 DES_cblock *out_white)
84des_cblock (*in_white);
85des_cblock (*out_white);
86 { 84 {
87 unsigned char *key,*in,*out;
88 int out0,out1; 85 int out0,out1;
89 int i; 86 int i;
90 87 const unsigned char *key = &(*des_key)[0];
91 key=(unsigned char *)des_key; 88 const unsigned char *in = &(*in_white)[0];
92 in=(unsigned char *)in_white; 89 unsigned char *out = &(*out_white)[0];
93 out=(unsigned char *)out_white;
94 90
95 out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0; 91 out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0;
96 out0=out1=0; 92 out0=out1=0;
@@ -111,34 +107,27 @@ des_cblock (*out_white);
111 } 107 }
112 } 108 }
113 109
114void des_xcbc_encrypt(input, output, length, schedule, ivec, inw,outw,enc) 110void DES_xcbc_encrypt(const unsigned char *in, unsigned char *out,
115des_cblock (*input); 111 long length, DES_key_schedule *schedule,
116des_cblock (*output); 112 DES_cblock *ivec, const_DES_cblock *inw,
117long length; 113 const_DES_cblock *outw, int enc)
118des_key_schedule schedule;
119des_cblock (*ivec);
120des_cblock (*inw);
121des_cblock (*outw);
122int enc;
123 { 114 {
124 register DES_LONG tin0,tin1; 115 register DES_LONG tin0,tin1;
125 register DES_LONG tout0,tout1,xor0,xor1; 116 register DES_LONG tout0,tout1,xor0,xor1;
126 register DES_LONG inW0,inW1,outW0,outW1; 117 register DES_LONG inW0,inW1,outW0,outW1;
127 register unsigned char *in,*out; 118 register const unsigned char *in2;
128 register long l=length; 119 register long l=length;
129 DES_LONG tin[2]; 120 DES_LONG tin[2];
130 unsigned char *iv; 121 unsigned char *iv;
131 122
132 in=(unsigned char *)inw; 123 in2 = &(*inw)[0];
133 c2l(in,inW0); 124 c2l(in2,inW0);
134 c2l(in,inW1); 125 c2l(in2,inW1);
135 in=(unsigned char *)outw; 126 in2 = &(*outw)[0];
136 c2l(in,outW0); 127 c2l(in2,outW0);
137 c2l(in,outW1); 128 c2l(in2,outW1);
138 129
139 in=(unsigned char *)input; 130 iv = &(*ivec)[0];
140 out=(unsigned char *)output;
141 iv=(unsigned char *)ivec;
142 131
143 if (enc) 132 if (enc)
144 { 133 {
@@ -150,7 +139,7 @@ int enc;
150 c2l(in,tin1); 139 c2l(in,tin1);
151 tin0^=tout0^inW0; tin[0]=tin0; 140 tin0^=tout0^inW0; tin[0]=tin0;
152 tin1^=tout1^inW1; tin[1]=tin1; 141 tin1^=tout1^inW1; tin[1]=tin1;
153 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); 142 DES_encrypt1(tin,schedule,DES_ENCRYPT);
154 tout0=tin[0]^outW0; l2c(tout0,out); 143 tout0=tin[0]^outW0; l2c(tout0,out);
155 tout1=tin[1]^outW1; l2c(tout1,out); 144 tout1=tin[1]^outW1; l2c(tout1,out);
156 } 145 }
@@ -159,11 +148,11 @@ int enc;
159 c2ln(in,tin0,tin1,l+8); 148 c2ln(in,tin0,tin1,l+8);
160 tin0^=tout0^inW0; tin[0]=tin0; 149 tin0^=tout0^inW0; tin[0]=tin0;
161 tin1^=tout1^inW1; tin[1]=tin1; 150 tin1^=tout1^inW1; tin[1]=tin1;
162 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); 151 DES_encrypt1(tin,schedule,DES_ENCRYPT);
163 tout0=tin[0]^outW0; l2c(tout0,out); 152 tout0=tin[0]^outW0; l2c(tout0,out);
164 tout1=tin[1]^outW1; l2c(tout1,out); 153 tout1=tin[1]^outW1; l2c(tout1,out);
165 } 154 }
166 iv=(unsigned char *)ivec; 155 iv = &(*ivec)[0];
167 l2c(tout0,iv); 156 l2c(tout0,iv);
168 l2c(tout1,iv); 157 l2c(tout1,iv);
169 } 158 }
@@ -175,7 +164,7 @@ int enc;
175 { 164 {
176 c2l(in,tin0); tin[0]=tin0^outW0; 165 c2l(in,tin0); tin[0]=tin0^outW0;
177 c2l(in,tin1); tin[1]=tin1^outW1; 166 c2l(in,tin1); tin[1]=tin1^outW1;
178 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); 167 DES_encrypt1(tin,schedule,DES_DECRYPT);
179 tout0=tin[0]^xor0^inW0; 168 tout0=tin[0]^xor0^inW0;
180 tout1=tin[1]^xor1^inW1; 169 tout1=tin[1]^xor1^inW1;
181 l2c(tout0,out); 170 l2c(tout0,out);
@@ -187,7 +176,7 @@ int enc;
187 { 176 {
188 c2l(in,tin0); tin[0]=tin0^outW0; 177 c2l(in,tin0); tin[0]=tin0^outW0;
189 c2l(in,tin1); tin[1]=tin1^outW1; 178 c2l(in,tin1); tin[1]=tin1^outW1;
190 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); 179 DES_encrypt1(tin,schedule,DES_DECRYPT);
191 tout0=tin[0]^xor0^inW0; 180 tout0=tin[0]^xor0^inW0;
192 tout1=tin[1]^xor1^inW1; 181 tout1=tin[1]^xor1^inW1;
193 l2cn(tout0,tout1,out,l+8); 182 l2cn(tout0,tout1,out,l+8);
@@ -195,7 +184,7 @@ int enc;
195 xor1=tin1; 184 xor1=tin1;
196 } 185 }
197 186
198 iv=(unsigned char *)ivec; 187 iv = &(*ivec)[0];
199 l2c(xor0,iv); 188 l2c(xor0,iv);
200 l2c(xor1,iv); 189 l2c(xor1,iv);
201 } 190 }