summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bf
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bf')
-rw-r--r--src/lib/libcrypto/bf/asm/bf-586.pl4
-rw-r--r--src/lib/libcrypto/bf/bf_cbc.c39
-rw-r--r--src/lib/libcrypto/bf/bf_cfb64.c12
-rw-r--r--src/lib/libcrypto/bf/bf_ecb.c20
-rw-r--r--src/lib/libcrypto/bf/bf_enc.c129
-rw-r--r--src/lib/libcrypto/bf/bf_locl.h6
-rw-r--r--src/lib/libcrypto/bf/bf_ofb64.c11
-rw-r--r--src/lib/libcrypto/bf/bf_pi.h2
-rw-r--r--src/lib/libcrypto/bf/bf_skey.c11
-rw-r--r--src/lib/libcrypto/bf/blowfish.h67
10 files changed, 178 insertions, 123 deletions
diff --git a/src/lib/libcrypto/bf/asm/bf-586.pl b/src/lib/libcrypto/bf/asm/bf-586.pl
index 5c7ab14ab0..b556642c94 100644
--- a/src/lib/libcrypto/bf/asm/bf-586.pl
+++ b/src/lib/libcrypto/bf/asm/bf-586.pl
@@ -1,10 +1,10 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3push(@INC,"perlasm","../../perlasm"); 3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl"; 4require "x86asm.pl";
5require "cbc.pl"; 5require "cbc.pl";
6 6
7&asm_init($ARGV[0],"bf-586.pl"); 7&asm_init($ARGV[0],"bf-586.pl",$ARGV[$#ARGV] eq "386");
8 8
9$BF_ROUNDS=16; 9$BF_ROUNDS=16;
10$BF_OFF=($BF_ROUNDS+2)*4; 10$BF_OFF=($BF_ROUNDS+2)*4;
diff --git a/src/lib/libcrypto/bf/bf_cbc.c b/src/lib/libcrypto/bf/bf_cbc.c
index e0fa9ad763..f949629dc6 100644
--- a/src/lib/libcrypto/bf/bf_cbc.c
+++ b/src/lib/libcrypto/bf/bf_cbc.c
@@ -56,16 +56,11 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "blowfish.h" 59#include <openssl/blowfish.h>
60#include "bf_locl.h" 60#include "bf_locl.h"
61 61
62void BF_cbc_encrypt(in, out, length, ks, iv, encrypt) 62void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
63unsigned char *in; 63 const BF_KEY *schedule, unsigned char *ivec, int encrypt)
64unsigned char *out;
65long length;
66BF_KEY *ks;
67unsigned char *iv;
68int encrypt;
69 { 64 {
70 register BF_LONG tin0,tin1; 65 register BF_LONG tin0,tin1;
71 register BF_LONG tout0,tout1,xor0,xor1; 66 register BF_LONG tout0,tout1,xor0,xor1;
@@ -74,9 +69,9 @@ int encrypt;
74 69
75 if (encrypt) 70 if (encrypt)
76 { 71 {
77 n2l(iv,tout0); 72 n2l(ivec,tout0);
78 n2l(iv,tout1); 73 n2l(ivec,tout1);
79 iv-=8; 74 ivec-=8;
80 for (l-=8; l>=0; l-=8) 75 for (l-=8; l>=0; l-=8)
81 { 76 {
82 n2l(in,tin0); 77 n2l(in,tin0);
@@ -85,7 +80,7 @@ int encrypt;
85 tin1^=tout1; 80 tin1^=tout1;
86 tin[0]=tin0; 81 tin[0]=tin0;
87 tin[1]=tin1; 82 tin[1]=tin1;
88 BF_encrypt(tin,ks); 83 BF_encrypt(tin,schedule);
89 tout0=tin[0]; 84 tout0=tin[0];
90 tout1=tin[1]; 85 tout1=tin[1];
91 l2n(tout0,out); 86 l2n(tout0,out);
@@ -98,27 +93,27 @@ int encrypt;
98 tin1^=tout1; 93 tin1^=tout1;
99 tin[0]=tin0; 94 tin[0]=tin0;
100 tin[1]=tin1; 95 tin[1]=tin1;
101 BF_encrypt(tin,ks); 96 BF_encrypt(tin,schedule);
102 tout0=tin[0]; 97 tout0=tin[0];
103 tout1=tin[1]; 98 tout1=tin[1];
104 l2n(tout0,out); 99 l2n(tout0,out);
105 l2n(tout1,out); 100 l2n(tout1,out);
106 } 101 }
107 l2n(tout0,iv); 102 l2n(tout0,ivec);
108 l2n(tout1,iv); 103 l2n(tout1,ivec);
109 } 104 }
110 else 105 else
111 { 106 {
112 n2l(iv,xor0); 107 n2l(ivec,xor0);
113 n2l(iv,xor1); 108 n2l(ivec,xor1);
114 iv-=8; 109 ivec-=8;
115 for (l-=8; l>=0; l-=8) 110 for (l-=8; l>=0; l-=8)
116 { 111 {
117 n2l(in,tin0); 112 n2l(in,tin0);
118 n2l(in,tin1); 113 n2l(in,tin1);
119 tin[0]=tin0; 114 tin[0]=tin0;
120 tin[1]=tin1; 115 tin[1]=tin1;
121 BF_decrypt(tin,ks); 116 BF_decrypt(tin,schedule);
122 tout0=tin[0]^xor0; 117 tout0=tin[0]^xor0;
123 tout1=tin[1]^xor1; 118 tout1=tin[1]^xor1;
124 l2n(tout0,out); 119 l2n(tout0,out);
@@ -132,15 +127,15 @@ int encrypt;
132 n2l(in,tin1); 127 n2l(in,tin1);
133 tin[0]=tin0; 128 tin[0]=tin0;
134 tin[1]=tin1; 129 tin[1]=tin1;
135 BF_decrypt(tin,ks); 130 BF_decrypt(tin,schedule);
136 tout0=tin[0]^xor0; 131 tout0=tin[0]^xor0;
137 tout1=tin[1]^xor1; 132 tout1=tin[1]^xor1;
138 l2nn(tout0,tout1,out,l+8); 133 l2nn(tout0,tout1,out,l+8);
139 xor0=tin0; 134 xor0=tin0;
140 xor1=tin1; 135 xor1=tin1;
141 } 136 }
142 l2n(xor0,iv); 137 l2n(xor0,ivec);
143 l2n(xor1,iv); 138 l2n(xor1,ivec);
144 } 139 }
145 tin0=tin1=tout0=tout1=xor0=xor1=0; 140 tin0=tin1=tout0=tout1=xor0=xor1=0;
146 tin[0]=tin[1]=0; 141 tin[0]=tin[1]=0;
diff --git a/src/lib/libcrypto/bf/bf_cfb64.c b/src/lib/libcrypto/bf/bf_cfb64.c
index f9c66e7ced..6451c8d407 100644
--- a/src/lib/libcrypto/bf/bf_cfb64.c
+++ b/src/lib/libcrypto/bf/bf_cfb64.c
@@ -56,7 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "blowfish.h" 59#include <openssl/blowfish.h>
60#include "bf_locl.h" 60#include "bf_locl.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,8 @@
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 BF_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt) 67void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, long length,
68unsigned char *in; 68 const BF_KEY *schedule, unsigned char *ivec, int *num, int encrypt)
69unsigned char *out;
70long length;
71BF_KEY *schedule;
72unsigned char *ivec;
73int *num;
74int encrypt;
75 { 69 {
76 register BF_LONG v0,v1,t; 70 register BF_LONG v0,v1,t;
77 register int n= *num; 71 register int n= *num;
diff --git a/src/lib/libcrypto/bf/bf_ecb.c b/src/lib/libcrypto/bf/bf_ecb.c
index 6d16360bd9..341991636f 100644
--- a/src/lib/libcrypto/bf/bf_ecb.c
+++ b/src/lib/libcrypto/bf/bf_ecb.c
@@ -56,17 +56,18 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "blowfish.h" 59#include <openssl/blowfish.h>
60#include "bf_locl.h" 60#include "bf_locl.h"
61#include <openssl/opensslv.h>
61 62
62/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper' 63/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
63 * (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, 64 * (From LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
64 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) 65 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
65 */ 66 */
66 67
67char *BF_version="BlowFish part of SSLeay 0.9.0b 29-Jun-1998"; 68const char *BF_version="Blowfish" OPENSSL_VERSION_PTEXT;
68 69
69char *BF_options() 70const char *BF_options(void)
70 { 71 {
71#ifdef BF_PTR 72#ifdef BF_PTR
72 return("blowfish(ptr)"); 73 return("blowfish(ptr)");
@@ -77,20 +78,17 @@ char *BF_options()
77#endif 78#endif
78 } 79 }
79 80
80void BF_ecb_encrypt(in, out, ks, encrypt) 81void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
81unsigned char *in; 82 const BF_KEY *key, int encrypt)
82unsigned char *out;
83BF_KEY *ks;
84int encrypt;
85 { 83 {
86 BF_LONG l,d[2]; 84 BF_LONG l,d[2];
87 85
88 n2l(in,l); d[0]=l; 86 n2l(in,l); d[0]=l;
89 n2l(in,l); d[1]=l; 87 n2l(in,l); d[1]=l;
90 if (encrypt) 88 if (encrypt)
91 BF_encrypt(d,ks); 89 BF_encrypt(d,key);
92 else 90 else
93 BF_decrypt(d,ks); 91 BF_decrypt(d,key);
94 l=d[0]; l2n(l,out); 92 l=d[0]; l2n(l,out);
95 l=d[1]; l2n(l,out); 93 l=d[1]; l2n(l,out);
96 l=d[0]=d[1]=0; 94 l=d[0]=d[1]=0;
diff --git a/src/lib/libcrypto/bf/bf_enc.c b/src/lib/libcrypto/bf/bf_enc.c
index 66a8604c59..b380acf959 100644
--- a/src/lib/libcrypto/bf/bf_enc.c
+++ b/src/lib/libcrypto/bf/bf_enc.c
@@ -56,24 +56,24 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "blowfish.h" 59#include <openssl/blowfish.h>
60#include "bf_locl.h" 60#include "bf_locl.h"
61 61
62/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper' 62/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
63 * (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, 63 * (From LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
64 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) 64 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
65 */ 65 */
66 66
67#if (BF_ROUNDS != 16) && (BF_ROUNDS != 20) 67#if (BF_ROUNDS != 16) && (BF_ROUNDS != 20)
68If you set BF_ROUNDS to some value other than 16 or 20, you will have 68#error If you set BF_ROUNDS to some value other than 16 or 20, you will have \
69to modify the code. 69to modify the code.
70#endif 70#endif
71 71
72void BF_encrypt(data,key) 72void BF_encrypt(BF_LONG *data, const BF_KEY *key)
73BF_LONG *data;
74BF_KEY *key;
75 { 73 {
76 register BF_LONG l,r,*p,*s; 74#ifndef BF_PTR2
75 register BF_LONG l,r;
76 const register BF_LONG *p,*s;
77 77
78 p=key->P; 78 p=key->P;
79 s= &(key->S[0]); 79 s= &(key->S[0]);
@@ -107,15 +107,50 @@ BF_KEY *key;
107 107
108 data[1]=l&0xffffffffL; 108 data[1]=l&0xffffffffL;
109 data[0]=r&0xffffffffL; 109 data[0]=r&0xffffffffL;
110#else
111 register BF_LONG l,r,t,*k;
112
113 l=data[0];
114 r=data[1];
115 k=(BF_LONG*)key;
116
117 l^=k[0];
118 BF_ENC(r,l,k, 1);
119 BF_ENC(l,r,k, 2);
120 BF_ENC(r,l,k, 3);
121 BF_ENC(l,r,k, 4);
122 BF_ENC(r,l,k, 5);
123 BF_ENC(l,r,k, 6);
124 BF_ENC(r,l,k, 7);
125 BF_ENC(l,r,k, 8);
126 BF_ENC(r,l,k, 9);
127 BF_ENC(l,r,k,10);
128 BF_ENC(r,l,k,11);
129 BF_ENC(l,r,k,12);
130 BF_ENC(r,l,k,13);
131 BF_ENC(l,r,k,14);
132 BF_ENC(r,l,k,15);
133 BF_ENC(l,r,k,16);
134#if BF_ROUNDS == 20
135 BF_ENC(r,l,k,17);
136 BF_ENC(l,r,k,18);
137 BF_ENC(r,l,k,19);
138 BF_ENC(l,r,k,20);
139#endif
140 r^=k[BF_ROUNDS+1];
141
142 data[1]=l&0xffffffffL;
143 data[0]=r&0xffffffffL;
144#endif
110 } 145 }
111 146
112#ifndef BF_DEFAULT_OPTIONS 147#ifndef BF_DEFAULT_OPTIONS
113 148
114void BF_decrypt(data,key) 149void BF_decrypt(BF_LONG *data, const BF_KEY *key)
115BF_LONG *data;
116BF_KEY *key;
117 { 150 {
118 register BF_LONG l,r,*p,*s; 151#ifndef BF_PTR2
152 register BF_LONG l,r;
153 const register BF_LONG *p,*s;
119 154
120 p=key->P; 155 p=key->P;
121 s= &(key->S[0]); 156 s= &(key->S[0]);
@@ -149,15 +184,45 @@ BF_KEY *key;
149 184
150 data[1]=l&0xffffffffL; 185 data[1]=l&0xffffffffL;
151 data[0]=r&0xffffffffL; 186 data[0]=r&0xffffffffL;
187#else
188 register BF_LONG l,r,t,*k;
189
190 l=data[0];
191 r=data[1];
192 k=(BF_LONG *)key;
193
194 l^=k[BF_ROUNDS+1];
195#if BF_ROUNDS == 20
196 BF_ENC(r,l,k,20);
197 BF_ENC(l,r,k,19);
198 BF_ENC(r,l,k,18);
199 BF_ENC(l,r,k,17);
200#endif
201 BF_ENC(r,l,k,16);
202 BF_ENC(l,r,k,15);
203 BF_ENC(r,l,k,14);
204 BF_ENC(l,r,k,13);
205 BF_ENC(r,l,k,12);
206 BF_ENC(l,r,k,11);
207 BF_ENC(r,l,k,10);
208 BF_ENC(l,r,k, 9);
209 BF_ENC(r,l,k, 8);
210 BF_ENC(l,r,k, 7);
211 BF_ENC(r,l,k, 6);
212 BF_ENC(l,r,k, 5);
213 BF_ENC(r,l,k, 4);
214 BF_ENC(l,r,k, 3);
215 BF_ENC(r,l,k, 2);
216 BF_ENC(l,r,k, 1);
217 r^=k[0];
218
219 data[1]=l&0xffffffffL;
220 data[0]=r&0xffffffffL;
221#endif
152 } 222 }
153 223
154void BF_cbc_encrypt(in, out, length, ks, iv, encrypt) 224void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
155unsigned char *in; 225 const BF_KEY *schedule, unsigned char *ivec, int encrypt)
156unsigned char *out;
157long length;
158BF_KEY *ks;
159unsigned char *iv;
160int encrypt;
161 { 226 {
162 register BF_LONG tin0,tin1; 227 register BF_LONG tin0,tin1;
163 register BF_LONG tout0,tout1,xor0,xor1; 228 register BF_LONG tout0,tout1,xor0,xor1;
@@ -166,9 +231,9 @@ int encrypt;
166 231
167 if (encrypt) 232 if (encrypt)
168 { 233 {
169 n2l(iv,tout0); 234 n2l(ivec,tout0);
170 n2l(iv,tout1); 235 n2l(ivec,tout1);
171 iv-=8; 236 ivec-=8;
172 for (l-=8; l>=0; l-=8) 237 for (l-=8; l>=0; l-=8)
173 { 238 {
174 n2l(in,tin0); 239 n2l(in,tin0);
@@ -177,7 +242,7 @@ int encrypt;
177 tin1^=tout1; 242 tin1^=tout1;
178 tin[0]=tin0; 243 tin[0]=tin0;
179 tin[1]=tin1; 244 tin[1]=tin1;
180 BF_encrypt(tin,ks); 245 BF_encrypt(tin,schedule);
181 tout0=tin[0]; 246 tout0=tin[0];
182 tout1=tin[1]; 247 tout1=tin[1];
183 l2n(tout0,out); 248 l2n(tout0,out);
@@ -190,27 +255,27 @@ int encrypt;
190 tin1^=tout1; 255 tin1^=tout1;
191 tin[0]=tin0; 256 tin[0]=tin0;
192 tin[1]=tin1; 257 tin[1]=tin1;
193 BF_encrypt(tin,ks); 258 BF_encrypt(tin,schedule);
194 tout0=tin[0]; 259 tout0=tin[0];
195 tout1=tin[1]; 260 tout1=tin[1];
196 l2n(tout0,out); 261 l2n(tout0,out);
197 l2n(tout1,out); 262 l2n(tout1,out);
198 } 263 }
199 l2n(tout0,iv); 264 l2n(tout0,ivec);
200 l2n(tout1,iv); 265 l2n(tout1,ivec);
201 } 266 }
202 else 267 else
203 { 268 {
204 n2l(iv,xor0); 269 n2l(ivec,xor0);
205 n2l(iv,xor1); 270 n2l(ivec,xor1);
206 iv-=8; 271 ivec-=8;
207 for (l-=8; l>=0; l-=8) 272 for (l-=8; l>=0; l-=8)
208 { 273 {
209 n2l(in,tin0); 274 n2l(in,tin0);
210 n2l(in,tin1); 275 n2l(in,tin1);
211 tin[0]=tin0; 276 tin[0]=tin0;
212 tin[1]=tin1; 277 tin[1]=tin1;
213 BF_decrypt(tin,ks); 278 BF_decrypt(tin,schedule);
214 tout0=tin[0]^xor0; 279 tout0=tin[0]^xor0;
215 tout1=tin[1]^xor1; 280 tout1=tin[1]^xor1;
216 l2n(tout0,out); 281 l2n(tout0,out);
@@ -224,15 +289,15 @@ int encrypt;
224 n2l(in,tin1); 289 n2l(in,tin1);
225 tin[0]=tin0; 290 tin[0]=tin0;
226 tin[1]=tin1; 291 tin[1]=tin1;
227 BF_decrypt(tin,ks); 292 BF_decrypt(tin,schedule);
228 tout0=tin[0]^xor0; 293 tout0=tin[0]^xor0;
229 tout1=tin[1]^xor1; 294 tout1=tin[1]^xor1;
230 l2nn(tout0,tout1,out,l+8); 295 l2nn(tout0,tout1,out,l+8);
231 xor0=tin0; 296 xor0=tin0;
232 xor1=tin1; 297 xor1=tin1;
233 } 298 }
234 l2n(xor0,iv); 299 l2n(xor0,ivec);
235 l2n(xor1,iv); 300 l2n(xor1,ivec);
236 } 301 }
237 tin0=tin1=tout0=tout1=xor0=xor1=0; 302 tin0=tin1=tout0=tout1=xor0=xor1=0;
238 tin[0]=tin[1]=0; 303 tin[0]=tin[1]=0;
diff --git a/src/lib/libcrypto/bf/bf_locl.h b/src/lib/libcrypto/bf/bf_locl.h
index 05756b5d3b..cc7c3ec992 100644
--- a/src/lib/libcrypto/bf/bf_locl.h
+++ b/src/lib/libcrypto/bf/bf_locl.h
@@ -148,7 +148,7 @@
148 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ 148 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
149 *((c)++)=(unsigned char)(((l) )&0xff)) 149 *((c)++)=(unsigned char)(((l) )&0xff))
150 150
151/* This is actually a big endian algorithm, the most significate byte 151/* This is actually a big endian algorithm, the most significant byte
152 * is used to lookup array 0 */ 152 * is used to lookup array 0 */
153 153
154#if defined(BF_PTR2) 154#if defined(BF_PTR2)
@@ -183,8 +183,8 @@
183 183
184/* 184/*
185 * This is normally very good on RISC platforms where normally you 185 * This is normally very good on RISC platforms where normally you
186 * have to explicitely "multiplicate" array index by sizeof(BF_LONG) 186 * have to explicitly "multiply" array index by sizeof(BF_LONG)
187 * in order to caclulate the effective address. This implementation 187 * in order to calculate the effective address. This implementation
188 * excuses CPU from this extra work. Power[PC] uses should have most 188 * excuses CPU from this extra work. Power[PC] uses should have most
189 * fun as (R>>BF_i)&BF_M gets folded into a single instruction, namely 189 * fun as (R>>BF_i)&BF_M gets folded into a single instruction, namely
190 * rlwinm. So let'em double-check if their compiler does it. 190 * rlwinm. So let'em double-check if their compiler does it.
diff --git a/src/lib/libcrypto/bf/bf_ofb64.c b/src/lib/libcrypto/bf/bf_ofb64.c
index 5d844ac760..f2a9ff6e41 100644
--- a/src/lib/libcrypto/bf/bf_ofb64.c
+++ b/src/lib/libcrypto/bf/bf_ofb64.c
@@ -56,20 +56,15 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "blowfish.h" 59#include <openssl/blowfish.h>
60#include "bf_locl.h" 60#include "bf_locl.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 BF_ofb64_encrypt(in, out, length, schedule, ivec, num) 66void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, long length,
67unsigned char *in; 67 const BF_KEY *schedule, unsigned char *ivec, int *num)
68unsigned char *out;
69long length;
70BF_KEY *schedule;
71unsigned char *ivec;
72int *num;
73 { 68 {
74 register BF_LONG v0,v1,t; 69 register BF_LONG v0,v1,t;
75 register int n= *num; 70 register int n= *num;
diff --git a/src/lib/libcrypto/bf/bf_pi.h b/src/lib/libcrypto/bf/bf_pi.h
index 417b935538..9949513c68 100644
--- a/src/lib/libcrypto/bf/bf_pi.h
+++ b/src/lib/libcrypto/bf/bf_pi.h
@@ -56,7 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59static BF_KEY bf_init= { 59static const BF_KEY bf_init= {
60 { 60 {
61 0x243f6a88L, 0x85a308d3L, 0x13198a2eL, 0x03707344L, 61 0x243f6a88L, 0x85a308d3L, 0x13198a2eL, 0x03707344L,
62 0xa4093822L, 0x299f31d0L, 0x082efa98L, 0xec4e6c89L, 62 0xa4093822L, 0x299f31d0L, 0x082efa98L, 0xec4e6c89L,
diff --git a/src/lib/libcrypto/bf/bf_skey.c b/src/lib/libcrypto/bf/bf_skey.c
index 86574c0acc..3673cdee6e 100644
--- a/src/lib/libcrypto/bf/bf_skey.c
+++ b/src/lib/libcrypto/bf/bf_skey.c
@@ -58,21 +58,18 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include "blowfish.h" 61#include <openssl/blowfish.h>
62#include "bf_locl.h" 62#include "bf_locl.h"
63#include "bf_pi.h" 63#include "bf_pi.h"
64 64
65void BF_set_key(key,len,data) 65void BF_set_key(BF_KEY *key, int len, const unsigned char *data)
66BF_KEY *key;
67int len;
68unsigned char *data;
69 { 66 {
70 int i; 67 int i;
71 BF_LONG *p,ri,in[2]; 68 BF_LONG *p,ri,in[2];
72 unsigned char *d,*end; 69 const unsigned char *d,*end;
73 70
74 71
75 memcpy((char *)key,(char *)&bf_init,sizeof(BF_KEY)); 72 memcpy(key,&bf_init,sizeof(BF_KEY));
76 p=key->P; 73 p=key->P;
77 74
78 if (len > ((BF_ROUNDS+2)*4)) len=(BF_ROUNDS+2)*4; 75 if (len > ((BF_ROUNDS+2)*4)) len=(BF_ROUNDS+2)*4;
diff --git a/src/lib/libcrypto/bf/blowfish.h b/src/lib/libcrypto/bf/blowfish.h
index c4a8085a29..cd49e85ab2 100644
--- a/src/lib/libcrypto/bf/blowfish.h
+++ b/src/lib/libcrypto/bf/blowfish.h
@@ -59,18 +59,41 @@
59#ifndef HEADER_BLOWFISH_H 59#ifndef HEADER_BLOWFISH_H
60#define HEADER_BLOWFISH_H 60#define HEADER_BLOWFISH_H
61 61
62#include <openssl/e_os2.h>
63
62#ifdef __cplusplus 64#ifdef __cplusplus
63extern "C" { 65extern "C" {
64#endif 66#endif
65 67
68#ifdef OPENSSL_NO_BF
69#error BF is disabled.
70#endif
71
66#define BF_ENCRYPT 1 72#define BF_ENCRYPT 1
67#define BF_DECRYPT 0 73#define BF_DECRYPT 0
68 74
69/* If you make this 'unsigned int' the pointer variants will work on 75/*
70 * the Alpha, otherwise they will not. Strangly using the '8 byte' 76 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
71 * BF_LONG and the default 'non-pointer' inner loop is the best configuration 77 * ! BF_LONG has to be at least 32 bits wide. If it's wider, then !
72 * for the Alpha */ 78 * ! BF_LONG_LOG2 has to be defined along. !
79 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
80 */
81
82#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
83#define BF_LONG unsigned long
84#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
73#define BF_LONG unsigned long 85#define BF_LONG unsigned long
86#define BF_LONG_LOG2 3
87/*
88 * _CRAY note. I could declare short, but I have no idea what impact
89 * does it have on performance on none-T3E machines. I could declare
90 * int, but at least on C90 sizeof(int) can be chosen at compile time.
91 * So I've chosen long...
92 * <appro@fy.chalmers.se>
93 */
94#else
95#define BF_LONG unsigned int
96#endif
74 97
75#define BF_ROUNDS 16 98#define BF_ROUNDS 16
76#define BF_BLOCK 8 99#define BF_BLOCK 8
@@ -81,33 +104,21 @@ typedef struct bf_key_st
81 BF_LONG S[4*256]; 104 BF_LONG S[4*256];
82 } BF_KEY; 105 } BF_KEY;
83 106
84#ifndef NOPROTO
85 107
86void BF_set_key(BF_KEY *key, int len, unsigned char *data); 108void BF_set_key(BF_KEY *key, int len, const unsigned char *data);
87void BF_ecb_encrypt(unsigned char *in,unsigned char *out,BF_KEY *key,
88 int enc);
89void BF_encrypt(BF_LONG *data,BF_KEY *key);
90void BF_decrypt(BF_LONG *data,BF_KEY *key);
91void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
92 BF_KEY *ks, unsigned char *iv, int enc);
93void BF_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
94 BF_KEY *schedule, unsigned char *ivec, int *num, int enc);
95void BF_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
96 BF_KEY *schedule, unsigned char *ivec, int *num);
97char *BF_options(void);
98 109
99#else 110void BF_encrypt(BF_LONG *data,const BF_KEY *key);
100 111void BF_decrypt(BF_LONG *data,const BF_KEY *key);
101void BF_set_key();
102void BF_ecb_encrypt();
103void BF_encrypt();
104void BF_decrypt();
105void BF_cbc_encrypt();
106void BF_cfb64_encrypt();
107void BF_ofb64_encrypt();
108char *BF_options();
109 112
110#endif 113void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
114 const BF_KEY *key, int enc);
115void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
116 const BF_KEY *schedule, unsigned char *ivec, int enc);
117void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, long length,
118 const BF_KEY *schedule, unsigned char *ivec, int *num, int enc);
119void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, long length,
120 const BF_KEY *schedule, unsigned char *ivec, int *num);
121const char *BF_options(void);
111 122
112#ifdef __cplusplus 123#ifdef __cplusplus
113} 124}