import libcrypto (LibreSSL 2.5.2)
[unleashed.git] / lib / libcrypto / man / BF_set_key.3
blobef5c7764b89aa5a1f61571e53094df89746bab25
1 .\"     $OpenBSD: BF_set_key.3,v 1.5 2016/11/11 01:20:53 schwarze Exp $
2 .\"     OpenSSL 99d63d46 Jul 19 09:27:53 2016 -0400
3 .\"
4 .\" This file was written by Richard Levitte <levitte@openssl.org>.
5 .\" Copyright (c) 2000, 2002, 2005, 2014, 2016 The OpenSSL Project.
6 .\" All rights reserved.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
11 .\"
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\"    notice, this list of conditions and the following disclaimer.
14 .\"
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\"    notice, this list of conditions and the following disclaimer in
17 .\"    the documentation and/or other materials provided with the
18 .\"    distribution.
19 .\"
20 .\" 3. All advertising materials mentioning features or use of this
21 .\"    software must display the following acknowledgment:
22 .\"    "This product includes software developed by the OpenSSL Project
23 .\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 .\"
25 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 .\"    endorse or promote products derived from this software without
27 .\"    prior written permission. For written permission, please contact
28 .\"    openssl-core@openssl.org.
29 .\"
30 .\" 5. Products derived from this software may not be called "OpenSSL"
31 .\"    nor may "OpenSSL" appear in their names without prior written
32 .\"    permission of the OpenSSL Project.
33 .\"
34 .\" 6. Redistributions of any form whatsoever must retain the following
35 .\"    acknowledgment:
36 .\"    "This product includes software developed by the OpenSSL Project
37 .\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 .\"
39 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
51 .\"
52 .Dd $Mdocdate: November 11 2016 $
53 .Dt BF_SET_KEY 3
54 .Os
55 .Sh NAME
56 .Nm BF_set_key ,
57 .Nm BF_encrypt ,
58 .Nm BF_decrypt ,
59 .Nm BF_ecb_encrypt ,
60 .Nm BF_cbc_encrypt ,
61 .Nm BF_cfb64_encrypt ,
62 .Nm BF_ofb64_encrypt ,
63 .Nm BF_options
64 .Nd Blowfish encryption
65 .Sh SYNOPSIS
66 .In openssl/blowfish.h
67 .Ft void
68 .Fo BF_set_key
69 .Fa "BF_KEY *key"
70 .Fa "int len"
71 .Fa "const unsigned char *data"
72 .Fc
73 .Ft void
74 .Fo BF_encrypt
75 .Fa "BF_LONG *data"
76 .Fa "const BF_KEY *key"
77 .Fc
78 .Ft void
79 .Fo BF_decrypt
80 .Fa "BF_LONG *data"
81 .Fa "const BF_KEY *key"
82 .Fc
83 .Ft void
84 .Fo BF_ecb_encrypt
85 .Fa "const unsigned char *in"
86 .Fa "unsigned char *out"
87 .Fa "BF_KEY *key"
88 .Fa "int enc"
89 .Fc
90 .Ft void
91 .Fo BF_cbc_encrypt
92 .Fa "const unsigned char *in"
93 .Fa "unsigned char *out"
94 .Fa "long length"
95 .Fa "BF_KEY *schedule"
96 .Fa "unsigned char *ivec"
97 .Fa "int enc"
98 .Fc
99 .Ft void
100 .Fo BF_cfb64_encrypt
101 .Fa "const unsigned char *in"
102 .Fa "unsigned char *out"
103 .Fa "long length"
104 .Fa "BF_KEY *schedule"
105 .Fa "unsigned char *ivec"
106 .Fa "int *num"
107 .Fa "int enc"
109 .Ft void
110 .Fo BF_ofb64_encrypt
111 .Fa "const unsigned char *in"
112 .Fa "unsigned char *out"
113 .Fa "long length"
114 .Fa "BF_KEY *schedule"
115 .Fa "unsigned char *ivec"
116 .Fa "int *num"
118 .Ft const char *
119 .Fo BF_options
120 .Fa void
122 .Sh DESCRIPTION
123 This library implements the Blowfish cipher,
124 which was invented and defined by
125 .An Counterpane .
126 Note that applications should use higher level functions such as
127 .Xr EVP_EncryptInit 3
128 instead of calling the Blowfish functions directly.
130 Blowfish is a block cipher that operates on 64-bit (8 byte) blocks of data.
131 It uses a variable size key, but typically, 128-bit (16 byte) keys
132 are considered good for strong encryption.
133 Blowfish can be used in the same modes as DES
134 and is currently one of the faster block ciphers.
135 It is quite a bit faster than DES, and much faster than IDEA or RC2.
137 Blowfish consists of a key setup phase
138 and the actual encryption or decryption phase.
140 .Fn BF_set_key
141 sets up the
142 .Vt BF_KEY
143 .Fa key
144 using the
145 .Fa len
146 bytes long key at
147 .Fa data .
149 .Fn BF_ecb_encrypt
150 is the basic Blowfish encryption and decryption function.
151 It encrypts or decrypts the first 64 bits of
152 .Fa in
153 using the key
154 .Fa key ,
155 putting the result in
156 .Fa out .
157 .Fa enc
158 decides if encryption
159 .Pq Dv BF_ENCRYPT
160 or decryption
161 .Pq Dv BF_DECRYPT
162 shall be performed.
163 The vector pointed at by
164 .Fa in
166 .Fa out
167 must be 64 bits in length, no less.
168 If they are larger, everything after the first 64 bits is ignored.
170 The mode functions
171 .Fn BF_cbc_encrypt ,
172 .Fn BF_cfb64_encrypt ,
174 .Fn BF_ofb64_encrypt
175 all operate on variable length data.
176 They all take an initialization vector
177 .Fa ivec
178 which needs to be passed along into the next call of the same function
179 for the same message.
180 .Fa ivec
181 may be initialized with anything, but the recipient needs to know what
182 it was initialized with, or it won't be able to decrypt.
183 Some programs and protocols simplify this, like SSH, where
184 .Fa ivec
185 is simply initialized to zero.
186 .Fn BF_cbc_encrypt
187 operates on data that is a multiple of 8 bytes long, while
188 .Fn BF_cfb64_encrypt
190 .Fn BF_ofb64_encrypt
191 are used to encrypt an variable number of bytes (the amount
192 does not have to be an exact multiple of 8).
193 The purpose of the latter two is to simulate stream ciphers and,
194 therefore, they need the parameter
195 .Fa num ,
196 which is a pointer to an integer where the current offset in
197 .Fa ivec
198 is stored between calls.
199 This integer must be initialized to zero when
200 .Fa ivec
201 is initialized.
203 .Fn BF_cbc_encrypt
204 is the Cipher Block Chaining function for Blowfish.
205 It encrypts or decrypts the 64-bit chunks of
206 .Fa in
207 using the key
208 .Fa schedule ,
209 putting the result in
210 .Fa out .
211 .Fa enc
212 decides if encryption
213 .Pq Dv BF_ENCRYPT
214 or decryption
215 .Pq Dv BF_DECRYPT
216 shall be performed.
217 .Fa ivec
218 must point at an 8-byte long initialization vector.
220 .Fn BF_cfb64_encrypt
221 is the CFB mode for Blowfish with 64-bit feedback.
222 It encrypts or decrypts the bytes in
223 .Fa in
224 using the key
225 .Fa schedule ,
226 putting the result in
227 .Fa out .
228 .Fa enc
229 decides if encryption
230 .Pq Dv BF_ENCRYPT
231 or decryption
232 .Pq Dv BF_DECRYPT
233 shall be performed.
234 .Fa ivec
235 must point at an
236 8-byte long initialization vector.
237 .Fa num
238 must point at an integer which must be initially zero.
240 .Fn BF_ofb64_encrypt
241 is the OFB mode for Blowfish with 64-bit feedback.
242 It uses the same parameters as
243 .Fn BF_cfb64_encrypt ,
244 which must be initialized the same way.
246 .Fn BF_encrypt
248 .Fn BF_decrypt
249 are the lowest level functions for Blowfish encryption.
250 They encrypt/decrypt the first 64 bits of the vector pointed by
251 .Fa data ,
252 using the key
253 .Fa key .
254 These functions should not be used unless implementing `modes' of Blowfish.
255 The alternative is to use
256 .Fn BF_ecb_encrypt .
257 Be aware that these functions take each 32-bit chunk in host-byte order,
258 which is little-endian on little-endian platforms
259 and big-endian on big-endian ones.
260 .Sh HISTORY
261 The Blowfish functions are available in all versions of SSLeay and OpenSSL.