summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/cast
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/cast')
-rw-r--r--src/lib/libcrypto/cast/asm/cast-586.pl267
-rw-r--r--src/lib/libcrypto/cast/c_cfb64.c25
-rw-r--r--src/lib/libcrypto/cast/c_ecb.c14
-rw-r--r--src/lib/libcrypto/cast/c_enc.c43
-rw-r--r--src/lib/libcrypto/cast/c_ofb64.c16
-rw-r--r--src/lib/libcrypto/cast/c_skey.c11
-rw-r--r--src/lib/libcrypto/cast/cast.h38
-rw-r--r--src/lib/libcrypto/cast/cast_lcl.h30
-rw-r--r--src/lib/libcrypto/cast/cast_s.h16
9 files changed, 229 insertions, 231 deletions
diff --git a/src/lib/libcrypto/cast/asm/cast-586.pl b/src/lib/libcrypto/cast/asm/cast-586.pl
index d0be004c99..6be0bfe572 100644
--- a/src/lib/libcrypto/cast/asm/cast-586.pl
+++ b/src/lib/libcrypto/cast/asm/cast-586.pl
@@ -1,4 +1,4 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3# define for pentium pro friendly version 3# define for pentium pro friendly version
4$ppro=1; 4$ppro=1;
@@ -7,7 +7,7 @@ push(@INC,"perlasm","../../perlasm");
7require "x86asm.pl"; 7require "x86asm.pl";
8require "cbc.pl"; 8require "cbc.pl";
9 9
10&asm_init($ARGV[0],"cast-586.pl"); 10&asm_init($ARGV[0],"cast-586.pl",$ARGV[$#ARGV] eq "386");
11 11
12$CAST_ROUNDS=16; 12$CAST_ROUNDS=16;
13$L="edi"; 13$L="edi";
@@ -32,136 +32,145 @@ $S4="CAST_S_table3";
32 32
33&asm_finish(); 33&asm_finish();
34 34
35sub CAST_encrypt 35sub CAST_encrypt {
36 { 36 local($name,$enc)=@_;
37 local($name,$enc)=@_;
38 37
39 local($win_ex)=<<"EOF"; 38 local($win_ex)=<<"EOF";
40EXTERN _CAST_S_table0:DWORD 39EXTERN _CAST_S_table0:DWORD
41EXTERN _CAST_S_table1:DWORD 40EXTERN _CAST_S_table1:DWORD
42EXTERN _CAST_S_table2:DWORD 41EXTERN _CAST_S_table2:DWORD
43EXTERN _CAST_S_table3:DWORD 42EXTERN _CAST_S_table3:DWORD
44EOF 43EOF
45 &main'external_label( 44 &main::external_label(
46 "CAST_S_table0", 45 "CAST_S_table0",
47 "CAST_S_table1", 46 "CAST_S_table1",
48 "CAST_S_table2", 47 "CAST_S_table2",
49 "CAST_S_table3", 48 "CAST_S_table3",
50 ); 49 );
51 50
52 &function_begin_B($name,$win_ex); 51 &function_begin_B($name,$win_ex);
53 52
54 &comment(""); 53 &comment("");
55 54
56 &push("ebp"); 55 &push("ebp");
57 &push("ebx"); 56 &push("ebx");
58 &mov($tmp2,&wparam(0)); 57 &mov($tmp2,&wparam(0));
59 &mov($K,&wparam(1)); 58 &mov($K,&wparam(1));
60 &push("esi"); 59 &push("esi");
61 &push("edi"); 60 &push("edi");
62 61
63 &comment("Load the 2 words"); 62 &comment("Load the 2 words");
64 &mov($L,&DWP(0,$tmp2,"",0)); 63 &mov($L,&DWP(0,$tmp2,"",0));
65 &mov($R,&DWP(4,$tmp2,"",0)); 64 &mov($R,&DWP(4,$tmp2,"",0));
66 65
67 &xor( $tmp3, $tmp3); 66 &comment('Get short key flag');
68 67 &mov($tmp3,&DWP(128,$K,"",0));
69 # encrypting part 68 if($enc) {
70 69 &push($tmp3);
71 if ($enc) 70 } else {
72 { 71 &or($tmp3,$tmp3);
73 &E_CAST( 0,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 72 &jnz(&label('cast_dec_skip'));
74 &E_CAST( 1,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 73 }
75 &E_CAST( 2,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 74
76 &E_CAST( 3,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 75 &xor($tmp3, $tmp3);
77 &E_CAST( 4,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 76
78 &E_CAST( 5,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 77 # encrypting part
79 &E_CAST( 6,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 78
80 &E_CAST( 7,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 79 if ($enc) {
81 &E_CAST( 8,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 80 &E_CAST( 0,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
82 &E_CAST( 9,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 81 &E_CAST( 1,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
83 &E_CAST(10,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 82 &E_CAST( 2,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
84 &E_CAST(11,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 83 &E_CAST( 3,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
85 &E_CAST(12,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 84 &E_CAST( 4,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
86 &E_CAST(13,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 85 &E_CAST( 5,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
87 &E_CAST(14,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 86 &E_CAST( 6,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
88 &E_CAST(15,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4,1); 87 &E_CAST( 7,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
89 } 88 &E_CAST( 8,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
90 else 89 &E_CAST( 9,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
91 { 90 &E_CAST(10,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
92 &E_CAST(15,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 91 &E_CAST(11,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
93 &E_CAST(14,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 92 &comment('test short key flag');
94 &E_CAST(13,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 93 &pop($tmp4);
95 &E_CAST(12,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 94 &or($tmp4,$tmp4);
96 &E_CAST(11,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 95 &jnz(&label('cast_enc_done'));
97 &E_CAST(10,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 96 &E_CAST(12,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
98 &E_CAST( 9,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 97 &E_CAST(13,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
99 &E_CAST( 8,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 98 &E_CAST(14,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
100 &E_CAST( 7,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 99 &E_CAST(15,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
101 &E_CAST( 6,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 100 } else {
102 &E_CAST( 5,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 101 &E_CAST(15,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
103 &E_CAST( 4,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 102 &E_CAST(14,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
104 &E_CAST( 3,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 103 &E_CAST(13,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
105 &E_CAST( 2,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 104 &E_CAST(12,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
106 &E_CAST( 1,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 105 &set_label('cast_dec_skip');
107 &E_CAST( 0,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4,1); 106 &E_CAST(11,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
108 } 107 &E_CAST(10,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
109 108 &E_CAST( 9,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
110 &nop(); 109 &E_CAST( 8,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
111 &mov(&DWP(4,$tmp3,"",0),$L); 110 &E_CAST( 7,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
112 &mov(&DWP(0,$tmp3,"",0),$R); 111 &E_CAST( 6,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
113 &function_end($name); 112 &E_CAST( 5,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
114 } 113 &E_CAST( 4,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
115 114 &E_CAST( 3,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
116sub E_CAST 115 &E_CAST( 2,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
117 { 116 &E_CAST( 1,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
118 local($i,$S,$L,$R,$K,$OP1,$OP2,$OP3,$tmp1,$tmp2,$tmp3,$tmp4,$lst)=@_; 117 &E_CAST( 0,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
119 # Ri needs to have 16 pre added. 118 }
120 119
121 &comment("round $i"); 120 &set_label('cast_enc_done') if $enc;
122 &mov( $tmp4, &DWP($i*8,$K,"",1)); 121# Why the nop? - Ben 17/1/99
123 122 &nop();
124 &mov( $tmp1, &DWP($i*8+4,$K,"",1));# must be word 123 &mov($tmp3,&wparam(0));
125 &$OP1( $tmp4, $R); 124 &mov(&DWP(4,$tmp3,"",0),$L);
126 125 &mov(&DWP(0,$tmp3,"",0),$R);
127 &rotl( $tmp4, &LB($tmp1)); 126 &function_end($name);
128 127}
129 if ($ppro) 128
130 { 129sub E_CAST {
131 &mov( $tmp2, $tmp4); # B 130 local($i,$S,$L,$R,$K,$OP1,$OP2,$OP3,$tmp1,$tmp2,$tmp3,$tmp4)=@_;
132 &xor( $tmp1, $tmp1); 131 # Ri needs to have 16 pre added.
133 132
134 &movb( &LB($tmp1), &HB($tmp4)); # A 133 &comment("round $i");
135 &and( $tmp2, 0xff); 134 &mov( $tmp4, &DWP($i*8,$K,"",1));
136 135
137 &shr( $tmp4, 16); # 136 &mov( $tmp1, &DWP($i*8+4,$K,"",1));
138 &xor( $tmp3, $tmp3); 137 &$OP1( $tmp4, $R);
139 } 138
140 else 139 &rotl( $tmp4, &LB($tmp1));
141 { 140
142 &mov( $tmp2, $tmp4); # B 141 if ($ppro) {
143 &movb( &LB($tmp1), &HB($tmp4)); # A # BAD BAD BAD 142 &mov( $tmp2, $tmp4); # B
144 143 &xor( $tmp1, $tmp1);
145 &shr( $tmp4, 16); # 144
146 &and( $tmp2, 0xff); 145 &movb( &LB($tmp1), &HB($tmp4)); # A
147 } 146 &and( $tmp2, 0xff);
148 147
149 &movb( &LB($tmp3), &HB($tmp4)); # C # BAD BAD BAD 148 &shr( $tmp4, 16); #
150 &and( $tmp4, 0xff); # D 149 &xor( $tmp3, $tmp3);
151 150 } else {
152 &mov( $tmp1, &DWP($S1,"",$tmp1,4)); 151 &mov( $tmp2, $tmp4); # B
153 &mov( $tmp2, &DWP($S2,"",$tmp2,4)); 152 &movb( &LB($tmp1), &HB($tmp4)); # A # BAD BAD BAD
154 153
155 &$OP2( $tmp1, $tmp2); 154 &shr( $tmp4, 16); #
156 &mov( $tmp2, &DWP($S3,"",$tmp3,4)); 155 &and( $tmp2, 0xff);
157 156 }
158 &$OP3( $tmp1, $tmp2); 157
159 &mov( $tmp2, &DWP($S4,"",$tmp4,4)); 158 &movb( &LB($tmp3), &HB($tmp4)); # C # BAD BAD BAD
160 159 &and( $tmp4, 0xff); # D
161 &$OP1( $tmp1, $tmp2); 160
162 &mov($tmp3,&wparam(0)) if $lst; 161 &mov( $tmp1, &DWP($S1,"",$tmp1,4));
163 # XXX 162 &mov( $tmp2, &DWP($S2,"",$tmp2,4));
164 163
165 &xor( $L, $tmp1); 164 &$OP2( $tmp1, $tmp2);
166 # XXX 165 &mov( $tmp2, &DWP($S3,"",$tmp3,4));
167 } 166
167 &$OP3( $tmp1, $tmp2);
168 &mov( $tmp2, &DWP($S4,"",$tmp4,4));
169
170 &$OP1( $tmp1, $tmp2);
171 # XXX
172
173 &xor( $L, $tmp1);
174 # XXX
175}
176
diff --git a/src/lib/libcrypto/cast/c_cfb64.c b/src/lib/libcrypto/cast/c_cfb64.c
index c46c375f75..514c005c32 100644
--- a/src/lib/libcrypto/cast/c_cfb64.c
+++ b/src/lib/libcrypto/cast/c_cfb64.c
@@ -56,7 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "cast.h" 59#include <openssl/cast.h>
60#include "cast_lcl.h" 60#include "cast_lcl.h"
61 61
62/* The input and output encrypted as though 64bit cfb mode is being 62/* The input and output encrypted as though 64bit cfb mode is being
@@ -64,14 +64,9 @@
64 * 64bit block we have used is contained in *num; 64 * 64bit block we have used is contained in *num;
65 */ 65 */
66 66
67void CAST_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt) 67void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out,
68unsigned char *in; 68 long length, CAST_KEY *schedule, unsigned char *ivec,
69unsigned char *out; 69 int *num, int enc)
70long length;
71CAST_KEY *schedule;
72unsigned char *ivec;
73int *num;
74int encrypt;
75 { 70 {
76 register CAST_LONG v0,v1,t; 71 register CAST_LONG v0,v1,t;
77 register int n= *num; 72 register int n= *num;
@@ -79,8 +74,8 @@ int encrypt;
79 CAST_LONG ti[2]; 74 CAST_LONG ti[2];
80 unsigned char *iv,c,cc; 75 unsigned char *iv,c,cc;
81 76
82 iv=(unsigned char *)ivec; 77 iv=ivec;
83 if (encrypt) 78 if (enc)
84 { 79 {
85 while (l--) 80 while (l--)
86 { 81 {
@@ -89,10 +84,10 @@ int encrypt;
89 n2l(iv,v0); ti[0]=v0; 84 n2l(iv,v0); ti[0]=v0;
90 n2l(iv,v1); ti[1]=v1; 85 n2l(iv,v1); ti[1]=v1;
91 CAST_encrypt((CAST_LONG *)ti,schedule); 86 CAST_encrypt((CAST_LONG *)ti,schedule);
92 iv=(unsigned char *)ivec; 87 iv=ivec;
93 t=ti[0]; l2n(t,iv); 88 t=ti[0]; l2n(t,iv);
94 t=ti[1]; l2n(t,iv); 89 t=ti[1]; l2n(t,iv);
95 iv=(unsigned char *)ivec; 90 iv=ivec;
96 } 91 }
97 c= *(in++)^iv[n]; 92 c= *(in++)^iv[n];
98 *(out++)=c; 93 *(out++)=c;
@@ -109,10 +104,10 @@ int encrypt;
109 n2l(iv,v0); ti[0]=v0; 104 n2l(iv,v0); ti[0]=v0;
110 n2l(iv,v1); ti[1]=v1; 105 n2l(iv,v1); ti[1]=v1;
111 CAST_encrypt((CAST_LONG *)ti,schedule); 106 CAST_encrypt((CAST_LONG *)ti,schedule);
112 iv=(unsigned char *)ivec; 107 iv=ivec;
113 t=ti[0]; l2n(t,iv); 108 t=ti[0]; l2n(t,iv);
114 t=ti[1]; l2n(t,iv); 109 t=ti[1]; l2n(t,iv);
115 iv=(unsigned char *)ivec; 110 iv=ivec;
116 } 111 }
117 cc= *(in++); 112 cc= *(in++);
118 c=iv[n]; 113 c=iv[n];
diff --git a/src/lib/libcrypto/cast/c_ecb.c b/src/lib/libcrypto/cast/c_ecb.c
index f0f2f4df0e..0b3da9ad87 100644
--- a/src/lib/libcrypto/cast/c_ecb.c
+++ b/src/lib/libcrypto/cast/c_ecb.c
@@ -56,22 +56,20 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "cast.h" 59#include <openssl/cast.h>
60#include "cast_lcl.h" 60#include "cast_lcl.h"
61#include <openssl/opensslv.h>
61 62
62char *CAST_version="CAST part of SSLeay 0.9.0b 29-Jun-1998"; 63const char *CAST_version="CAST" OPENSSL_VERSION_PTEXT;
63 64
64void CAST_ecb_encrypt(in, out, ks, encrypt) 65void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out,
65unsigned char *in; 66 CAST_KEY *ks, int enc)
66unsigned char *out;
67CAST_KEY *ks;
68int encrypt;
69 { 67 {
70 CAST_LONG l,d[2]; 68 CAST_LONG l,d[2];
71 69
72 n2l(in,l); d[0]=l; 70 n2l(in,l); d[0]=l;
73 n2l(in,l); d[1]=l; 71 n2l(in,l); d[1]=l;
74 if (encrypt) 72 if (enc)
75 CAST_encrypt(d,ks); 73 CAST_encrypt(d,ks);
76 else 74 else
77 CAST_decrypt(d,ks); 75 CAST_decrypt(d,ks);
diff --git a/src/lib/libcrypto/cast/c_enc.c b/src/lib/libcrypto/cast/c_enc.c
index d998dd4953..0fe2cffecc 100644
--- a/src/lib/libcrypto/cast/c_enc.c
+++ b/src/lib/libcrypto/cast/c_enc.c
@@ -56,12 +56,10 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "cast.h" 59#include <openssl/cast.h>
60#include "cast_lcl.h" 60#include "cast_lcl.h"
61 61
62void CAST_encrypt(data,key) 62void CAST_encrypt(CAST_LONG *data, CAST_KEY *key)
63CAST_LONG *data;
64CAST_KEY *key;
65 { 63 {
66 register CAST_LONG l,r,*k,t; 64 register CAST_LONG l,r,*k,t;
67 65
@@ -81,18 +79,19 @@ CAST_KEY *key;
81 E_CAST( 9,k,r,l,+,^,-); 79 E_CAST( 9,k,r,l,+,^,-);
82 E_CAST(10,k,l,r,^,-,+); 80 E_CAST(10,k,l,r,^,-,+);
83 E_CAST(11,k,r,l,-,+,^); 81 E_CAST(11,k,r,l,-,+,^);
84 E_CAST(12,k,l,r,+,^,-); 82 if(!key->short_key)
85 E_CAST(13,k,r,l,^,-,+); 83 {
86 E_CAST(14,k,l,r,-,+,^); 84 E_CAST(12,k,l,r,+,^,-);
87 E_CAST(15,k,r,l,+,^,-); 85 E_CAST(13,k,r,l,^,-,+);
86 E_CAST(14,k,l,r,-,+,^);
87 E_CAST(15,k,r,l,+,^,-);
88 }
88 89
89 data[1]=l&0xffffffffL; 90 data[1]=l&0xffffffffL;
90 data[0]=r&0xffffffffL; 91 data[0]=r&0xffffffffL;
91 } 92 }
92 93
93void CAST_decrypt(data,key) 94void CAST_decrypt(CAST_LONG *data, CAST_KEY *key)
94CAST_LONG *data;
95CAST_KEY *key;
96 { 95 {
97 register CAST_LONG l,r,*k,t; 96 register CAST_LONG l,r,*k,t;
98 97
@@ -100,10 +99,13 @@ CAST_KEY *key;
100 l=data[0]; 99 l=data[0];
101 r=data[1]; 100 r=data[1];
102 101
103 E_CAST(15,k,l,r,+,^,-); 102 if(!key->short_key)
104 E_CAST(14,k,r,l,-,+,^); 103 {
105 E_CAST(13,k,l,r,^,-,+); 104 E_CAST(15,k,l,r,+,^,-);
106 E_CAST(12,k,r,l,+,^,-); 105 E_CAST(14,k,r,l,-,+,^);
106 E_CAST(13,k,l,r,^,-,+);
107 E_CAST(12,k,r,l,+,^,-);
108 }
107 E_CAST(11,k,l,r,-,+,^); 109 E_CAST(11,k,l,r,-,+,^);
108 E_CAST(10,k,r,l,^,-,+); 110 E_CAST(10,k,r,l,^,-,+);
109 E_CAST( 9,k,l,r,+,^,-); 111 E_CAST( 9,k,l,r,+,^,-);
@@ -121,20 +123,15 @@ CAST_KEY *key;
121 data[0]=r&0xffffffffL; 123 data[0]=r&0xffffffffL;
122 } 124 }
123 125
124void CAST_cbc_encrypt(in, out, length, ks, iv, encrypt) 126void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
125unsigned char *in; 127 CAST_KEY *ks, unsigned char *iv, int enc)
126unsigned char *out;
127long length;
128CAST_KEY *ks;
129unsigned char *iv;
130int encrypt;
131 { 128 {
132 register CAST_LONG tin0,tin1; 129 register CAST_LONG tin0,tin1;
133 register CAST_LONG tout0,tout1,xor0,xor1; 130 register CAST_LONG tout0,tout1,xor0,xor1;
134 register long l=length; 131 register long l=length;
135 CAST_LONG tin[2]; 132 CAST_LONG tin[2];
136 133
137 if (encrypt) 134 if (enc)
138 { 135 {
139 n2l(iv,tout0); 136 n2l(iv,tout0);
140 n2l(iv,tout1); 137 n2l(iv,tout1);
diff --git a/src/lib/libcrypto/cast/c_ofb64.c b/src/lib/libcrypto/cast/c_ofb64.c
index 2aad2d6d96..fd0469a62f 100644
--- a/src/lib/libcrypto/cast/c_ofb64.c
+++ b/src/lib/libcrypto/cast/c_ofb64.c
@@ -56,20 +56,16 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "cast.h" 59#include <openssl/cast.h>
60#include "cast_lcl.h" 60#include "cast_lcl.h"
61 61
62/* The input and output encrypted as though 64bit ofb mode is being 62/* The input and output encrypted as though 64bit ofb mode is being
63 * used. The extra state information to record how much of the 63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num; 64 * 64bit block we have used is contained in *num;
65 */ 65 */
66void CAST_ofb64_encrypt(in, out, length, schedule, ivec, num) 66void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out,
67unsigned char *in; 67 long length, CAST_KEY *schedule, unsigned char *ivec,
68unsigned char *out; 68 int *num)
69long length;
70CAST_KEY *schedule;
71unsigned char *ivec;
72int *num;
73 { 69 {
74 register CAST_LONG v0,v1,t; 70 register CAST_LONG v0,v1,t;
75 register int n= *num; 71 register int n= *num;
@@ -80,7 +76,7 @@ int *num;
80 unsigned char *iv; 76 unsigned char *iv;
81 int save=0; 77 int save=0;
82 78
83 iv=(unsigned char *)ivec; 79 iv=ivec;
84 n2l(iv,v0); 80 n2l(iv,v0);
85 n2l(iv,v1); 81 n2l(iv,v1);
86 ti[0]=v0; 82 ti[0]=v0;
@@ -105,7 +101,7 @@ int *num;
105 { 101 {
106 v0=ti[0]; 102 v0=ti[0];
107 v1=ti[1]; 103 v1=ti[1];
108 iv=(unsigned char *)ivec; 104 iv=ivec;
109 l2n(v0,iv); 105 l2n(v0,iv);
110 l2n(v1,iv); 106 l2n(v1,iv);
111 } 107 }
diff --git a/src/lib/libcrypto/cast/c_skey.c b/src/lib/libcrypto/cast/c_skey.c
index 2fc3363dcd..76e40005c9 100644
--- a/src/lib/libcrypto/cast/c_skey.c
+++ b/src/lib/libcrypto/cast/c_skey.c
@@ -56,7 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "cast.h" 59#include <openssl/cast.h>
60#include "cast_lcl.h" 60#include "cast_lcl.h"
61#include "cast_s.h" 61#include "cast_s.h"
62 62
@@ -72,10 +72,7 @@
72#define S6 CAST_S_table6 72#define S6 CAST_S_table6
73#define S7 CAST_S_table7 73#define S7 CAST_S_table7
74 74
75void CAST_set_key(key,len,data) 75void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data)
76CAST_KEY *key;
77int len;
78unsigned char *data;
79 { 76 {
80 CAST_LONG x[16]; 77 CAST_LONG x[16];
81 CAST_LONG z[16]; 78 CAST_LONG z[16];
@@ -88,6 +85,10 @@ unsigned char *data;
88 if (len > 16) len=16; 85 if (len > 16) len=16;
89 for (i=0; i<len; i++) 86 for (i=0; i<len; i++)
90 x[i]=data[i]; 87 x[i]=data[i];
88 if(len <= 10)
89 key->short_key=1;
90 else
91 key->short_key=0;
91 92
92 K= &k[0]; 93 K= &k[0];
93 X[0]=((x[ 0]<<24)|(x[ 1]<<16)|(x[ 2]<<8)|x[ 3])&0xffffffffL; 94 X[0]=((x[ 0]<<24)|(x[ 1]<<16)|(x[ 2]<<8)|x[ 3])&0xffffffffL;
diff --git a/src/lib/libcrypto/cast/cast.h b/src/lib/libcrypto/cast/cast.h
index 528cb7c824..b28e4e4f3b 100644
--- a/src/lib/libcrypto/cast/cast.h
+++ b/src/lib/libcrypto/cast/cast.h
@@ -63,6 +63,10 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#ifdef OPENSSL_NO_CAST
67#error CAST is disabled.
68#endif
69
66#define CAST_ENCRYPT 1 70#define CAST_ENCRYPT 1
67#define CAST_DECRYPT 0 71#define CAST_DECRYPT 0
68 72
@@ -74,33 +78,23 @@ extern "C" {
74typedef struct cast_key_st 78typedef struct cast_key_st
75 { 79 {
76 CAST_LONG data[32]; 80 CAST_LONG data[32];
81 int short_key; /* Use reduced rounds for short key */
77 } CAST_KEY; 82 } CAST_KEY;
78 83
79#ifndef NOPROTO
80 84
81void CAST_set_key(CAST_KEY *key, int len, unsigned char *data); 85void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);
82void CAST_ecb_encrypt(unsigned char *in,unsigned char *out,CAST_KEY *key, 86void CAST_ecb_encrypt(const unsigned char *in,unsigned char *out,CAST_KEY *key,
83 int enc); 87 int enc);
84void CAST_encrypt(CAST_LONG *data,CAST_KEY *key); 88void CAST_encrypt(CAST_LONG *data,CAST_KEY *key);
85void CAST_decrypt(CAST_LONG *data,CAST_KEY *key); 89void CAST_decrypt(CAST_LONG *data,CAST_KEY *key);
86void CAST_cbc_encrypt(unsigned char *in, unsigned char *out, long length, 90void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
87 CAST_KEY *ks, unsigned char *iv, int enc); 91 CAST_KEY *ks, unsigned char *iv, int enc);
88void CAST_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, 92void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out,
89 CAST_KEY *schedule, unsigned char *ivec, int *num, int enc); 93 long length, CAST_KEY *schedule, unsigned char *ivec,
90void CAST_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, 94 int *num, int enc);
91 CAST_KEY *schedule, unsigned char *ivec, int *num); 95void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out,
92 96 long length, CAST_KEY *schedule, unsigned char *ivec,
93#else 97 int *num);
94
95void CAST_set_key();
96void CAST_ecb_encrypt();
97void CAST_encrypt();
98void CAST_decrypt();
99void CAST_cbc_encrypt();
100void CAST_cfb64_encrypt();
101void CAST_ofb64_encrypt();
102
103#endif
104 98
105#ifdef __cplusplus 99#ifdef __cplusplus
106} 100}
diff --git a/src/lib/libcrypto/cast/cast_lcl.h b/src/lib/libcrypto/cast/cast_lcl.h
index 6587952a96..37f41cc6a4 100644
--- a/src/lib/libcrypto/cast/cast_lcl.h
+++ b/src/lib/libcrypto/cast/cast_lcl.h
@@ -56,10 +56,19 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifdef WIN32 59
60#include "e_os.h"
61
62#ifdef OPENSSL_SYS_WIN32
60#include <stdlib.h> 63#include <stdlib.h>
61#endif 64#endif
62 65
66
67#ifdef OPENSSL_BUILD_SHLIBCRYPTO
68# undef OPENSSL_EXTERN
69# define OPENSSL_EXTERN OPENSSL_EXPORT
70#endif
71
63#undef c2l 72#undef c2l
64#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \ 73#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
65 l|=((unsigned long)(*((c)++)))<< 8L, \ 74 l|=((unsigned long)(*((c)++)))<< 8L, \
@@ -148,7 +157,7 @@
148 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ 157 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
149 *((c)++)=(unsigned char)(((l) )&0xff)) 158 *((c)++)=(unsigned char)(((l) )&0xff))
150 159
151#if defined(WIN32) 160#if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
152#define ROTL(a,n) (_lrotl(a,n)) 161#define ROTL(a,n) (_lrotl(a,n))
153#else 162#else
154#define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>(32-(n)))) 163#define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>(32-(n))))
@@ -213,12 +222,11 @@
213 } 222 }
214#endif 223#endif
215 224
216extern CAST_LONG CAST_S_table0[256]; 225OPENSSL_EXTERN const CAST_LONG CAST_S_table0[256];
217extern CAST_LONG CAST_S_table1[256]; 226OPENSSL_EXTERN const CAST_LONG CAST_S_table1[256];
218extern CAST_LONG CAST_S_table2[256]; 227OPENSSL_EXTERN const CAST_LONG CAST_S_table2[256];
219extern CAST_LONG CAST_S_table3[256]; 228OPENSSL_EXTERN const CAST_LONG CAST_S_table3[256];
220extern CAST_LONG CAST_S_table4[256]; 229OPENSSL_EXTERN const CAST_LONG CAST_S_table4[256];
221extern CAST_LONG CAST_S_table5[256]; 230OPENSSL_EXTERN const CAST_LONG CAST_S_table5[256];
222extern CAST_LONG CAST_S_table6[256]; 231OPENSSL_EXTERN const CAST_LONG CAST_S_table6[256];
223extern CAST_LONG CAST_S_table7[256]; 232OPENSSL_EXTERN const CAST_LONG CAST_S_table7[256];
224
diff --git a/src/lib/libcrypto/cast/cast_s.h b/src/lib/libcrypto/cast/cast_s.h
index 8fe0152149..c483fd5e43 100644
--- a/src/lib/libcrypto/cast/cast_s.h
+++ b/src/lib/libcrypto/cast/cast_s.h
@@ -55,7 +55,7 @@
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58CAST_LONG CAST_S_table0[256]={ 58OPENSSL_GLOBAL const CAST_LONG CAST_S_table0[256]={
59 0x30fb40d4,0x9fa0ff0b,0x6beccd2f,0x3f258c7a, 59 0x30fb40d4,0x9fa0ff0b,0x6beccd2f,0x3f258c7a,
60 0x1e213f2f,0x9c004dd3,0x6003e540,0xcf9fc949, 60 0x1e213f2f,0x9c004dd3,0x6003e540,0xcf9fc949,
61 0xbfd4af27,0x88bbbdb5,0xe2034090,0x98d09675, 61 0xbfd4af27,0x88bbbdb5,0xe2034090,0x98d09675,
@@ -121,7 +121,7 @@ CAST_LONG CAST_S_table0[256]={
121 0x1a69e783,0x02cc4843,0xa2f7c579,0x429ef47d, 121 0x1a69e783,0x02cc4843,0xa2f7c579,0x429ef47d,
122 0x427b169c,0x5ac9f049,0xdd8f0f00,0x5c8165bf, 122 0x427b169c,0x5ac9f049,0xdd8f0f00,0x5c8165bf,
123 }; 123 };
124CAST_LONG CAST_S_table1[256]={ 124OPENSSL_GLOBAL const CAST_LONG CAST_S_table1[256]={
125 0x1f201094,0xef0ba75b,0x69e3cf7e,0x393f4380, 125 0x1f201094,0xef0ba75b,0x69e3cf7e,0x393f4380,
126 0xfe61cf7a,0xeec5207a,0x55889c94,0x72fc0651, 126 0xfe61cf7a,0xeec5207a,0x55889c94,0x72fc0651,
127 0xada7ef79,0x4e1d7235,0xd55a63ce,0xde0436ba, 127 0xada7ef79,0x4e1d7235,0xd55a63ce,0xde0436ba,
@@ -187,7 +187,7 @@ CAST_LONG CAST_S_table1[256]={
187 0x43d79572,0x7e6dd07c,0x06dfdf1e,0x6c6cc4ef, 187 0x43d79572,0x7e6dd07c,0x06dfdf1e,0x6c6cc4ef,
188 0x7160a539,0x73bfbe70,0x83877605,0x4523ecf1, 188 0x7160a539,0x73bfbe70,0x83877605,0x4523ecf1,
189 }; 189 };
190CAST_LONG CAST_S_table2[256]={ 190OPENSSL_GLOBAL const CAST_LONG CAST_S_table2[256]={
191 0x8defc240,0x25fa5d9f,0xeb903dbf,0xe810c907, 191 0x8defc240,0x25fa5d9f,0xeb903dbf,0xe810c907,
192 0x47607fff,0x369fe44b,0x8c1fc644,0xaececa90, 192 0x47607fff,0x369fe44b,0x8c1fc644,0xaececa90,
193 0xbeb1f9bf,0xeefbcaea,0xe8cf1950,0x51df07ae, 193 0xbeb1f9bf,0xeefbcaea,0xe8cf1950,0x51df07ae,
@@ -253,7 +253,7 @@ CAST_LONG CAST_S_table2[256]={
253 0xf7baefd5,0x4142ed9c,0xa4315c11,0x83323ec5, 253 0xf7baefd5,0x4142ed9c,0xa4315c11,0x83323ec5,
254 0xdfef4636,0xa133c501,0xe9d3531c,0xee353783, 254 0xdfef4636,0xa133c501,0xe9d3531c,0xee353783,
255 }; 255 };
256CAST_LONG CAST_S_table3[256]={ 256OPENSSL_GLOBAL const CAST_LONG CAST_S_table3[256]={
257 0x9db30420,0x1fb6e9de,0xa7be7bef,0xd273a298, 257 0x9db30420,0x1fb6e9de,0xa7be7bef,0xd273a298,
258 0x4a4f7bdb,0x64ad8c57,0x85510443,0xfa020ed1, 258 0x4a4f7bdb,0x64ad8c57,0x85510443,0xfa020ed1,
259 0x7e287aff,0xe60fb663,0x095f35a1,0x79ebf120, 259 0x7e287aff,0xe60fb663,0x095f35a1,0x79ebf120,
@@ -319,7 +319,7 @@ CAST_LONG CAST_S_table3[256]={
319 0x7ae5290c,0x3cb9536b,0x851e20fe,0x9833557e, 319 0x7ae5290c,0x3cb9536b,0x851e20fe,0x9833557e,
320 0x13ecf0b0,0xd3ffb372,0x3f85c5c1,0x0aef7ed2, 320 0x13ecf0b0,0xd3ffb372,0x3f85c5c1,0x0aef7ed2,
321 }; 321 };
322CAST_LONG CAST_S_table4[256]={ 322OPENSSL_GLOBAL const CAST_LONG CAST_S_table4[256]={
323 0x7ec90c04,0x2c6e74b9,0x9b0e66df,0xa6337911, 323 0x7ec90c04,0x2c6e74b9,0x9b0e66df,0xa6337911,
324 0xb86a7fff,0x1dd358f5,0x44dd9d44,0x1731167f, 324 0xb86a7fff,0x1dd358f5,0x44dd9d44,0x1731167f,
325 0x08fbf1fa,0xe7f511cc,0xd2051b00,0x735aba00, 325 0x08fbf1fa,0xe7f511cc,0xd2051b00,0x735aba00,
@@ -385,7 +385,7 @@ CAST_LONG CAST_S_table4[256]={
385 0xe822fe15,0x88570983,0x750e6249,0xda627e55, 385 0xe822fe15,0x88570983,0x750e6249,0xda627e55,
386 0x5e76ffa8,0xb1534546,0x6d47de08,0xefe9e7d4, 386 0x5e76ffa8,0xb1534546,0x6d47de08,0xefe9e7d4,
387 }; 387 };
388CAST_LONG CAST_S_table5[256]={ 388OPENSSL_GLOBAL const CAST_LONG CAST_S_table5[256]={
389 0xf6fa8f9d,0x2cac6ce1,0x4ca34867,0xe2337f7c, 389 0xf6fa8f9d,0x2cac6ce1,0x4ca34867,0xe2337f7c,
390 0x95db08e7,0x016843b4,0xeced5cbc,0x325553ac, 390 0x95db08e7,0x016843b4,0xeced5cbc,0x325553ac,
391 0xbf9f0960,0xdfa1e2ed,0x83f0579d,0x63ed86b9, 391 0xbf9f0960,0xdfa1e2ed,0x83f0579d,0x63ed86b9,
@@ -451,7 +451,7 @@ CAST_LONG CAST_S_table5[256]={
451 0xa2d762cf,0x49c92f54,0x38b5f331,0x7128a454, 451 0xa2d762cf,0x49c92f54,0x38b5f331,0x7128a454,
452 0x48392905,0xa65b1db8,0x851c97bd,0xd675cf2f, 452 0x48392905,0xa65b1db8,0x851c97bd,0xd675cf2f,
453 }; 453 };
454CAST_LONG CAST_S_table6[256]={ 454OPENSSL_GLOBAL const CAST_LONG CAST_S_table6[256]={
455 0x85e04019,0x332bf567,0x662dbfff,0xcfc65693, 455 0x85e04019,0x332bf567,0x662dbfff,0xcfc65693,
456 0x2a8d7f6f,0xab9bc912,0xde6008a1,0x2028da1f, 456 0x2a8d7f6f,0xab9bc912,0xde6008a1,0x2028da1f,
457 0x0227bce7,0x4d642916,0x18fac300,0x50f18b82, 457 0x0227bce7,0x4d642916,0x18fac300,0x50f18b82,
@@ -517,7 +517,7 @@ CAST_LONG CAST_S_table6[256]={
517 0x518f36b2,0x84b1d370,0x0fedce83,0x878ddada, 517 0x518f36b2,0x84b1d370,0x0fedce83,0x878ddada,
518 0xf2a279c7,0x94e01be8,0x90716f4b,0x954b8aa3, 518 0xf2a279c7,0x94e01be8,0x90716f4b,0x954b8aa3,
519 }; 519 };
520CAST_LONG CAST_S_table7[256]={ 520OPENSSL_GLOBAL const CAST_LONG CAST_S_table7[256]={
521 0xe216300d,0xbbddfffc,0xa7ebdabd,0x35648095, 521 0xe216300d,0xbbddfffc,0xa7ebdabd,0x35648095,
522 0x7789f8b7,0xe6c1121b,0x0e241600,0x052ce8b5, 522 0x7789f8b7,0xe6c1121b,0x0e241600,0x052ce8b5,
523 0x11a9cfb0,0xe5952f11,0xece7990a,0x9386d174, 523 0x11a9cfb0,0xe5952f11,0xece7990a,0x9386d174,