xref: /netbsd-src/crypto/external/bsd/openssl.old/dist/doc/man3/BF_encrypt.pod (revision 4724848cf0da353df257f730694b7882798e5daf)
1*4724848cSchristos=pod
2*4724848cSchristos
3*4724848cSchristos=head1 NAME
4*4724848cSchristos
5*4724848cSchristosBF_set_key, BF_encrypt, BF_decrypt, BF_ecb_encrypt, BF_cbc_encrypt,
6*4724848cSchristosBF_cfb64_encrypt, BF_ofb64_encrypt, BF_options - Blowfish encryption
7*4724848cSchristos
8*4724848cSchristos=head1 SYNOPSIS
9*4724848cSchristos
10*4724848cSchristos #include <openssl/blowfish.h>
11*4724848cSchristos
12*4724848cSchristos void BF_set_key(BF_KEY *key, int len, const unsigned char *data);
13*4724848cSchristos
14*4724848cSchristos void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
15*4724848cSchristos                     BF_KEY *key, int enc);
16*4724848cSchristos void BF_cbc_encrypt(const unsigned char *in, unsigned char *out,
17*4724848cSchristos                     long length, BF_KEY *schedule,
18*4724848cSchristos                     unsigned char *ivec, int enc);
19*4724848cSchristos void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out,
20*4724848cSchristos                       long length, BF_KEY *schedule,
21*4724848cSchristos                       unsigned char *ivec, int *num, int enc);
22*4724848cSchristos void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out,
23*4724848cSchristos                       long length, BF_KEY *schedule,
24*4724848cSchristos                       unsigned char *ivec, int *num);
25*4724848cSchristos const char *BF_options(void);
26*4724848cSchristos
27*4724848cSchristos void BF_encrypt(BF_LONG *data, const BF_KEY *key);
28*4724848cSchristos void BF_decrypt(BF_LONG *data, const BF_KEY *key);
29*4724848cSchristos
30*4724848cSchristos=head1 DESCRIPTION
31*4724848cSchristos
32*4724848cSchristosThis library implements the Blowfish cipher, which was invented and described
33*4724848cSchristosby Counterpane (see http://www.counterpane.com/blowfish.html ).
34*4724848cSchristos
35*4724848cSchristosBlowfish is a block cipher that operates on 64 bit (8 byte) blocks of data.
36*4724848cSchristosIt uses a variable size key, but typically, 128 bit (16 byte) keys are
37*4724848cSchristosconsidered good for strong encryption.  Blowfish can be used in the same
38*4724848cSchristosmodes as DES (see L<des_modes(7)>).  Blowfish is currently one
39*4724848cSchristosof the faster block ciphers.  It is quite a bit faster than DES, and much
40*4724848cSchristosfaster than IDEA or RC2.
41*4724848cSchristos
42*4724848cSchristosBlowfish consists of a key setup phase and the actual encryption or decryption
43*4724848cSchristosphase.
44*4724848cSchristos
45*4724848cSchristosBF_set_key() sets up the B<BF_KEY> B<key> using the B<len> bytes long key
46*4724848cSchristosat B<data>.
47*4724848cSchristos
48*4724848cSchristosBF_ecb_encrypt() is the basic Blowfish encryption and decryption function.
49*4724848cSchristosIt encrypts or decrypts the first 64 bits of B<in> using the key B<key>,
50*4724848cSchristosputting the result in B<out>.  B<enc> decides if encryption (B<BF_ENCRYPT>)
51*4724848cSchristosor decryption (B<BF_DECRYPT>) shall be performed.  The vector pointed at by
52*4724848cSchristosB<in> and B<out> must be 64 bits in length, no less.  If they are larger,
53*4724848cSchristoseverything after the first 64 bits is ignored.
54*4724848cSchristos
55*4724848cSchristosThe mode functions BF_cbc_encrypt(), BF_cfb64_encrypt() and BF_ofb64_encrypt()
56*4724848cSchristosall operate on variable length data.  They all take an initialization vector
57*4724848cSchristosB<ivec> which needs to be passed along into the next call of the same function
58*4724848cSchristosfor the same message.  B<ivec> may be initialized with anything, but the
59*4724848cSchristosrecipient needs to know what it was initialized with, or it won't be able
60*4724848cSchristosto decrypt.  Some programs and protocols simplify this, like SSH, where
61*4724848cSchristosB<ivec> is simply initialized to zero.
62*4724848cSchristosBF_cbc_encrypt() operates on data that is a multiple of 8 bytes long, while
63*4724848cSchristosBF_cfb64_encrypt() and BF_ofb64_encrypt() are used to encrypt a variable
64*4724848cSchristosnumber of bytes (the amount does not have to be an exact multiple of 8).  The
65*4724848cSchristospurpose of the latter two is to simulate stream ciphers, and therefore, they
66*4724848cSchristosneed the parameter B<num>, which is a pointer to an integer where the current
67*4724848cSchristosoffset in B<ivec> is stored between calls.  This integer must be initialized
68*4724848cSchristosto zero when B<ivec> is initialized.
69*4724848cSchristos
70*4724848cSchristosBF_cbc_encrypt() is the Cipher Block Chaining function for Blowfish.  It
71*4724848cSchristosencrypts or decrypts the 64 bits chunks of B<in> using the key B<schedule>,
72*4724848cSchristosputting the result in B<out>.  B<enc> decides if encryption (BF_ENCRYPT) or
73*4724848cSchristosdecryption (BF_DECRYPT) shall be performed.  B<ivec> must point at an 8 byte
74*4724848cSchristoslong initialization vector.
75*4724848cSchristos
76*4724848cSchristosBF_cfb64_encrypt() is the CFB mode for Blowfish with 64 bit feedback.
77*4724848cSchristosIt encrypts or decrypts the bytes in B<in> using the key B<schedule>,
78*4724848cSchristosputting the result in B<out>.  B<enc> decides if encryption (B<BF_ENCRYPT>)
79*4724848cSchristosor decryption (B<BF_DECRYPT>) shall be performed.  B<ivec> must point at an
80*4724848cSchristos8 byte long initialization vector. B<num> must point at an integer which must
81*4724848cSchristosbe initially zero.
82*4724848cSchristos
83*4724848cSchristosBF_ofb64_encrypt() is the OFB mode for Blowfish with 64 bit feedback.
84*4724848cSchristosIt uses the same parameters as BF_cfb64_encrypt(), which must be initialized
85*4724848cSchristosthe same way.
86*4724848cSchristos
87*4724848cSchristosBF_encrypt() and BF_decrypt() are the lowest level functions for Blowfish
88*4724848cSchristosencryption.  They encrypt/decrypt the first 64 bits of the vector pointed by
89*4724848cSchristosB<data>, using the key B<key>.  These functions should not be used unless you
90*4724848cSchristosimplement 'modes' of Blowfish.  The alternative is to use BF_ecb_encrypt().
91*4724848cSchristosIf you still want to use these functions, you should be aware that they take
92*4724848cSchristoseach 32-bit chunk in host-byte order, which is little-endian on little-endian
93*4724848cSchristosplatforms and big-endian on big-endian ones.
94*4724848cSchristos
95*4724848cSchristos=head1 RETURN VALUES
96*4724848cSchristos
97*4724848cSchristosNone of the functions presented here return any value.
98*4724848cSchristos
99*4724848cSchristos=head1 NOTE
100*4724848cSchristos
101*4724848cSchristosApplications should use the higher level functions
102*4724848cSchristosL<EVP_EncryptInit(3)> etc. instead of calling these
103*4724848cSchristosfunctions directly.
104*4724848cSchristos
105*4724848cSchristos=head1 SEE ALSO
106*4724848cSchristos
107*4724848cSchristosL<EVP_EncryptInit(3)>,
108*4724848cSchristosL<des_modes(7)>
109*4724848cSchristos
110*4724848cSchristos=head1 COPYRIGHT
111*4724848cSchristos
112*4724848cSchristosCopyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
113*4724848cSchristos
114*4724848cSchristosLicensed under the OpenSSL license (the "License").  You may not use
115*4724848cSchristosthis file except in compliance with the License.  You can obtain a copy
116*4724848cSchristosin the file LICENSE in the source distribution or at
117*4724848cSchristosL<https://www.openssl.org/source/license.html>.
118*4724848cSchristos
119*4724848cSchristos=cut
120