1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
.Dd $Mdocdate: September 9 2015 $
.Dt BF_SET_KEY 3
.Os
.Sh NAME
.Nm BF_set_key ,
.Nm BF_encrypt ,
.Nm BF_decrypt ,
.Nm BF_ecb_encrypt ,
.Nm BF_cbc_encrypt ,
.Nm BF_cfb64_encrypt ,
.Nm BF_ofb64_encrypt ,
.Nm BF_options
.Nd Blowfish encryption
.Sh SYNOPSIS
.In openssl/blowfish.h
.Ft void
.Fo BF_set_key
.Fa "BF_KEY *key"
.Fa "int len"
.Fa "const unsigned char *data"
.Fc
.Ft void
.Fo BF_ecb_encrypt
.Fa "const unsigned char *in"
.Fa "unsigned char *out"
.Fa "BF_KEY *key"
.Fa "int enc"
.Fc
.Ft void
.Fo BF_cbc_encrypt
.Fa "const unsigned char *in"
.Fa "unsigned char *out"
.Fa "long length"
.Fa "BF_KEY *schedule"
.Fa "unsigned char *ivec"
.Fa "int enc"
.Fc
.Ft void
.Fo BF_cfb64_encrypt
.Fa "const unsigned char *in"
.Fa "unsigned char *out"
.Fa "long length"
.Fa "BF_KEY *schedule"
.Fa "unsigned char *ivec"
.Fa "int *num"
.Fa "int enc"
.Fc
.Ft void
.Fo BF_ofb64_encrypt
.Fa "const unsigned char *in"
.Fa "unsigned char *out"
.Fa "long length"
.Fa "BF_KEY *schedule"
.Fa "unsigned char *ivec"
.Fa "int *num"
.Fc
.Ft const char *
.Fo BF_options
.Fa void
.Fc
.Ft void
.Fo BF_encrypt
.Fa "BF_LONG *data"
.Fa "const BF_KEY *key"
.Fc
.Ft void
.Fo BF_decrypt
.Fa "BF_LONG *data"
.Fa "const BF_KEY *key"
.Fc
.Sh DESCRIPTION
This library implements the Blowfish cipher,
which was invented and described by
.An Counterpane .
.Pp
Blowfish is a block cipher that operates on 64 bit (8 byte) blocks of data.
It uses a variable size key, but typically, 128 bit (16 byte) keys
are considered good for strong encryption.
Blowfish can be used in the same modes as DES (see
.Xr des_modes 3 ) .
Blowfish is currently one of the faster block ciphers.
It is quite a bit faster than DES, and much faster than IDEA or RC2.
.Pp
Blowfish consists of a key setup phase
and the actual encryption or decryption phase.
.Pp
.Fn BF_set_key
sets up the
.Vt BF_KEY
.Fa key
using the
.Fa len
bytes long key at
.Fa data .
.Pp
.Fn BF_ecb_encrypt
is the basic Blowfish encryption and decryption function.
It encrypts or decrypts the first 64 bits of
.Fa in
using the key
.Fa key ,
putting the result in
.Fa out .
.Fa enc
decides if encryption
.Pq Dv BF_ENCRYPT
or decryption
.Pq Dv BF_DECRYPT
shall be performed.
The vector pointed at by
.Fa in
and
.Fa out
must be 64 bits in length, no less.
If they are larger, everything after the first 64 bits is ignored.
.Pp
The mode functions
.Fn BF_cbc_encrypt ,
.Fn BF_cfb64_encrypt ,
and
.Fn BF_ofb64_encrypt
all operate on variable length data.
They all take an initialization vector
.Fa ivec
which needs to be passed along into the next call of the same function
for the same message.
.Fa ivec
may be initialized with anything, but the recipient needs to know what
it was initialized with, or it won't be able to decrypt.
Some programs and protocols simplify this, like SSH, where
.Fa ivec
is simply initialized to zero.
.Fn BF_cbc_encrypt
operates on data that is a multiple of 8 bytes long, while
.Fn BF_cfb64_encrypt
and
.Fn BF_ofb64_encrypt
are used to encrypt an variable number of bytes (the amount
does not have to be an exact multiple of 8).
The purpose of the latter two is to simulate stream ciphers,
and therefore, they need the parameter
.Fa num ,
which is a pointer to an integer where the current offset in
.Fa ivec
is stored between calls.
This integer must be initialized to zero when
.Fa ivec
is initialized.
.Pp
.Fn BF_cbc_encrypt
is the Cipher Block Chaining function for Blowfish.
It encrypts or decrypts the 64 bits chunks of
.Fa in
using the key
.Fa schedule ,
putting the result in
.Fa out .
.Fa enc
decides if encryption
.Pq Dv BF_ENCRYPT
or decryption
.Pq Dv BF_DECRYPT
shall be performed.
.Fa ivec
must point at an 8 byte long initialization vector.
.Pp
.Fn BF_cfb64_encrypt
is the CFB mode for Blowfish with 64 bit feedback.
It encrypts or decrypts the bytes in
.Fa in
using the key
.Fa schedule ,
putting the result in
.Fa out .
.Fa enc
decides if encryption
.Pq Dv BF_ENCRYPT
or decryption
.Pq Dv BF_DECRYPT
shall be performed.
.Fa ivec
must point at an
8 byte long initialization vector.
.Fa num
must point at an integer which must be initially zero.
.Pp
.Fn BF_ofb64_encrypt
is the OFB mode for Blowfish with 64 bit feedback.
It uses the same parameters as
.Fn BF_cfb64_encrypt ,
which must be initialized the same way.
.Pp
.Fn BF_encrypt
and
.Fn BF_decrypt
are the lowest level functions for Blowfish encryption.
They encrypt/decrypt the first 64 bits of the vector pointed by
.Fa data ,
using the key
.Fa key .
These functions should not be used unless you implement 'modes' of Blowfish.
The alternative is to use
.Fn BF_ecb_encrypt .
If you still want to use these functions, you should be aware
that they take each 32-bit chunk in host-byte order,
which is little-endian on little-endian platforms
and big-endian on big-endian ones.
.Sh RETURN VALUES
None of the functions presented here return any value.
.Sh NOTE
Applications should use the higher level functions
.Xr EVP_EncryptInit 3
etc. instead of calling the blowfish functions directly.
.Sh HISTORY
The Blowfish functions are available in all versions of SSLeay and OpenSSL.
|