Merge from vendor branch OPENSSH:
[dragonfly.git] / secure / lib / libcrypto / man / blowfish.3
1 .\" Automatically generated by Pod::Man version 1.15
2 .\" Wed Feb 19 16:43:01 2003
3 .\"
4 .\" Standard preamble:
5 .\" ======================================================================
6 .de Sh \" Subsection heading
7 .br
8 .if t .Sp
9 .ne 5
10 .PP
11 \fB\\$1\fR
12 .PP
13 ..
14 .de Sp \" Vertical space (when we can't use .PP)
15 .if t .sp .5v
16 .if n .sp
17 ..
18 .de Ip \" List item
19 .br
20 .ie \\n(.$>=3 .ne \\$3
21 .el .ne 3
22 .IP "\\$1" \\$2
23 ..
24 .de Vb \" Begin verbatim text
25 .ft CW
26 .nf
27 .ne \\$1
28 ..
29 .de Ve \" End verbatim text
30 .ft R
31
32 .fi
33 ..
34 .\" Set up some character translations and predefined strings.  \*(-- will
35 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
36 .\" double quote, and \*(R" will give a right double quote.  | will give a
37 .\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used
38 .\" to do unbreakable dashes and therefore won't be available.  \*(C` and
39 .\" \*(C' expand to `' in nroff, nothing in troff, for use with C<>
40 .tr \(*W-|\(bv\*(Tr
41 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
42 .ie n \{\
43 .    ds -- \(*W-
44 .    ds PI pi
45 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
46 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
47 .    ds L" ""
48 .    ds R" ""
49 .    ds C` ""
50 .    ds C' ""
51 'br\}
52 .el\{\
53 .    ds -- \|\(em\|
54 .    ds PI \(*p
55 .    ds L" ``
56 .    ds R" ''
57 'br\}
58 .\"
59 .\" If the F register is turned on, we'll generate index entries on stderr
60 .\" for titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and
61 .\" index entries marked with X<> in POD.  Of course, you'll have to process
62 .\" the output yourself in some meaningful fashion.
63 .if \nF \{\
64 .    de IX
65 .    tm Index:\\$1\t\\n%\t"\\$2"
66 ..
67 .    nr % 0
68 .    rr F
69 .\}
70 .\"
71 .\" For nroff, turn off justification.  Always turn off hyphenation; it
72 .\" makes way too many mistakes in technical documents.
73 .hy 0
74 .if n .na
75 .\"
76 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
77 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
78 .bd B 3
79 .    \" fudge factors for nroff and troff
80 .if n \{\
81 .    ds #H 0
82 .    ds #V .8m
83 .    ds #F .3m
84 .    ds #[ \f1
85 .    ds #] \fP
86 .\}
87 .if t \{\
88 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
89 .    ds #V .6m
90 .    ds #F 0
91 .    ds #[ \&
92 .    ds #] \&
93 .\}
94 .    \" simple accents for nroff and troff
95 .if n \{\
96 .    ds ' \&
97 .    ds ` \&
98 .    ds ^ \&
99 .    ds , \&
100 .    ds ~ ~
101 .    ds /
102 .\}
103 .if t \{\
104 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
105 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
106 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
107 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
108 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
109 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
110 .\}
111 .    \" troff and (daisy-wheel) nroff accents
112 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
113 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
114 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
115 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
116 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
117 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
118 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
119 .ds ae a\h'-(\w'a'u*4/10)'e
120 .ds Ae A\h'-(\w'A'u*4/10)'E
121 .    \" corrections for vroff
122 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
123 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
124 .    \" for low resolution devices (crt and lpr)
125 .if \n(.H>23 .if \n(.V>19 \
126 \{\
127 .    ds : e
128 .    ds 8 ss
129 .    ds o a
130 .    ds d- d\h'-1'\(ga
131 .    ds D- D\h'-1'\(hy
132 .    ds th \o'bp'
133 .    ds Th \o'LP'
134 .    ds ae ae
135 .    ds Ae AE
136 .\}
137 .rm #[ #] #H #V #F C
138 .\" ======================================================================
139 .\"
140 .IX Title "blowfish 3"
141 .TH blowfish 3 "0.9.7a" "2003-02-19" "OpenSSL"
142 .UC
143 .SH "NAME"
144 blowfish, BF_set_key, BF_encrypt, BF_decrypt, BF_ecb_encrypt, BF_cbc_encrypt,
145 BF_cfb64_encrypt, BF_ofb64_encrypt, BF_options \- Blowfish encryption
146 .SH "SYNOPSIS"
147 .IX Header "SYNOPSIS"
148 .Vb 1
149 \& #include <openssl/blowfish.h>
150 .Ve
151 .Vb 1
152 \& void BF_set_key(BF_KEY *key, int len, const unsigned char *data);
153 .Ve
154 .Vb 10
155 \& void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
156 \&         BF_KEY *key, int enc);
157 \& void BF_cbc_encrypt(const unsigned char *in, unsigned char *out,
158 \&         long length, BF_KEY *schedule, unsigned char *ivec, int enc);
159 \& void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out,
160 \&         long length, BF_KEY *schedule, unsigned char *ivec, int *num,
161 \&         int enc);
162 \& void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out,
163 \&         long length, BF_KEY *schedule, unsigned char *ivec, int *num);
164 \& const char *BF_options(void);
165 .Ve
166 .Vb 2
167 \& void BF_encrypt(BF_LONG *data,const BF_KEY *key);
168 \& void BF_decrypt(BF_LONG *data,const BF_KEY *key);
169 .Ve
170 .SH "DESCRIPTION"
171 .IX Header "DESCRIPTION"
172 This library implements the Blowfish cipher, which was invented and described
173 by Counterpane (see http://www.counterpane.com/blowfish.html ).
174 .PP
175 Blowfish is a block cipher that operates on 64 bit (8 byte) blocks of data.
176 It uses a variable size key, but typically, 128 bit (16 byte) keys are
177 a considered good for strong encryption.  Blowfish can be used in the same
178 modes as \s-1DES\s0 (see des_modes(7)).  Blowfish is currently one
179 of the faster block ciphers.  It is quite a bit faster than \s-1DES\s0, and much
180 faster than \s-1IDEA\s0 or \s-1RC2\s0.
181 .PP
182 Blowfish consists of a key setup phase and the actual encryption or decryption
183 phase.
184 .PP
185 \&\fIBF_set_key()\fR sets up the \fB\s-1BF_KEY\s0\fR \fBkey\fR using the \fBlen\fR bytes long key
186 at \fBdata\fR.
187 .PP
188 \&\fIBF_ecb_encrypt()\fR is the basic Blowfish encryption and decryption function.
189 It encrypts or decrypts the first 64 bits of \fBin\fR using the key \fBkey\fR,
190 putting the result in \fBout\fR.  \fBenc\fR decides if encryption (\fB\s-1BF_ENCRYPT\s0\fR)
191 or decryption (\fB\s-1BF_DECRYPT\s0\fR) shall be performed.  The vector pointed at by
192 \&\fBin\fR and \fBout\fR must be 64 bits in length, no less.  If they are larger,
193 everything after the first 64 bits is ignored.
194 .PP
195 The mode functions \fIBF_cbc_encrypt()\fR, \fIBF_cfb64_encrypt()\fR and \fIBF_ofb64_encrypt()\fR
196 all operate on variable length data.  They all take an initialization vector
197 \&\fBivec\fR which needs to be passed along into the next call of the same function 
198 for the same message.  \fBivec\fR may be initialized with anything, but the
199 recipient needs to know what it was initialized with, or it won't be able
200 to decrypt.  Some programs and protocols simplify this, like \s-1SSH\s0, where
201 \&\fBivec\fR is simply initialized to zero.
202 \&\fIBF_cbc_encrypt()\fR operates on data that is a multiple of 8 bytes long, while
203 \&\fIBF_cfb64_encrypt()\fR and \fIBF_ofb64_encrypt()\fR are used to encrypt an variable
204 number of bytes (the amount does not have to be an exact multiple of 8).  The
205 purpose of the latter two is to simulate stream ciphers, and therefore, they
206 need the parameter \fBnum\fR, which is a pointer to an integer where the current
207 offset in \fBivec\fR is stored between calls.  This integer must be initialized
208 to zero when \fBivec\fR is initialized.
209 .PP
210 \&\fIBF_cbc_encrypt()\fR is the Cipher Block Chaining function for Blowfish.  It
211 encrypts or decrypts the 64 bits chunks of \fBin\fR using the key \fBschedule\fR,
212 putting the result in \fBout\fR.  \fBenc\fR decides if encryption (\s-1BF_ENCRYPT\s0) or
213 decryption (\s-1BF_DECRYPT\s0) shall be performed.  \fBivec\fR must point at an 8 byte
214 long initialization vector.
215 .PP
216 \&\fIBF_cfb64_encrypt()\fR is the \s-1CFB\s0 mode for Blowfish with 64 bit feedback.
217 It encrypts or decrypts the bytes in \fBin\fR using the key \fBschedule\fR,
218 putting the result in \fBout\fR.  \fBenc\fR decides if encryption (\fB\s-1BF_ENCRYPT\s0\fR)
219 or decryption (\fB\s-1BF_DECRYPT\s0\fR) shall be performed.  \fBivec\fR must point at an
220 8 byte long initialization vector. \fBnum\fR must point at an integer which must
221 be initially zero.
222 .PP
223 \&\fIBF_ofb64_encrypt()\fR is the \s-1OFB\s0 mode for Blowfish with 64 bit feedback.
224 It uses the same parameters as \fIBF_cfb64_encrypt()\fR, which must be initialized
225 the same way.
226 .PP
227 \&\fIBF_encrypt()\fR and \fIBF_decrypt()\fR are the lowest level functions for Blowfish
228 encryption.  They encrypt/decrypt the first 64 bits of the vector pointed by
229 \&\fBdata\fR, using the key \fBkey\fR.  These functions should not be used unless you
230 implement 'modes' of Blowfish.  The alternative is to use \fIBF_ecb_encrypt()\fR.
231 If you still want to use these functions, you should be aware that they take
232 each 32\-bit chunk in host-byte order, which is little-endian on little-endian
233 platforms and big-endian on big-endian ones.
234 .SH "RETURN VALUES"
235 .IX Header "RETURN VALUES"
236 None of the functions presented here return any value.
237 .SH "NOTE"
238 .IX Header "NOTE"
239 Applications should use the higher level functions
240 EVP_EncryptInit(3) etc. instead of calling the
241 blowfish functions directly.
242 .SH "SEE ALSO"
243 .IX Header "SEE ALSO"
244 des_modes(7)
245 .SH "HISTORY"
246 .IX Header "HISTORY"
247 The Blowfish functions are available in all versions of SSLeay and OpenSSL.