xref: /netbsd-src/crypto/external/bsd/openssl/dist/doc/man3/BF_encrypt.pod (revision b0d1725196a7921d003d2c66a14f186abda4176b)
113d40330Schristos=pod
213d40330Schristos
313d40330Schristos=head1 NAME
413d40330Schristos
513d40330SchristosBF_set_key, BF_encrypt, BF_decrypt, BF_ecb_encrypt, BF_cbc_encrypt,
613d40330SchristosBF_cfb64_encrypt, BF_ofb64_encrypt, BF_options - Blowfish encryption
713d40330Schristos
813d40330Schristos=head1 SYNOPSIS
913d40330Schristos
1013d40330Schristos #include <openssl/blowfish.h>
1113d40330Schristos
12*b0d17251SchristosThe following functions have been deprecated since OpenSSL 3.0, and can be
13*b0d17251Schristoshidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
14*b0d17251Schristossee L<openssl_user_macros(7)>:
15*b0d17251Schristos
1613d40330Schristos void BF_set_key(BF_KEY *key, int len, const unsigned char *data);
1713d40330Schristos
1813d40330Schristos void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
1913d40330Schristos                     BF_KEY *key, int enc);
2013d40330Schristos void BF_cbc_encrypt(const unsigned char *in, unsigned char *out,
2113d40330Schristos                     long length, BF_KEY *schedule,
2213d40330Schristos                     unsigned char *ivec, int enc);
2313d40330Schristos void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out,
2413d40330Schristos                       long length, BF_KEY *schedule,
2513d40330Schristos                       unsigned char *ivec, int *num, int enc);
2613d40330Schristos void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out,
2713d40330Schristos                       long length, BF_KEY *schedule,
2813d40330Schristos                       unsigned char *ivec, int *num);
2913d40330Schristos const char *BF_options(void);
3013d40330Schristos
3113d40330Schristos void BF_encrypt(BF_LONG *data, const BF_KEY *key);
3213d40330Schristos void BF_decrypt(BF_LONG *data, const BF_KEY *key);
3313d40330Schristos
3413d40330Schristos=head1 DESCRIPTION
3513d40330Schristos
36*b0d17251SchristosAll of the functions described on this page are deprecated. Applications should
37*b0d17251Schristosinstead use L<EVP_EncryptInit_ex(3)>, L<EVP_EncryptUpdate(3)> and
38*b0d17251SchristosL<EVP_EncryptFinal_ex(3)> or the equivalently named decrypt functions.
39*b0d17251Schristos
4013d40330SchristosThis library implements the Blowfish cipher, which was invented and described
4113d40330Schristosby Counterpane (see http://www.counterpane.com/blowfish.html ).
4213d40330Schristos
4313d40330SchristosBlowfish is a block cipher that operates on 64 bit (8 byte) blocks of data.
4413d40330SchristosIt uses a variable size key, but typically, 128 bit (16 byte) keys are
4513d40330Schristosconsidered good for strong encryption.  Blowfish can be used in the same
4613d40330Schristosmodes as DES (see L<des_modes(7)>).  Blowfish is currently one
4713d40330Schristosof the faster block ciphers.  It is quite a bit faster than DES, and much
4813d40330Schristosfaster than IDEA or RC2.
4913d40330Schristos
5013d40330SchristosBlowfish consists of a key setup phase and the actual encryption or decryption
5113d40330Schristosphase.
5213d40330Schristos
5313d40330SchristosBF_set_key() sets up the B<BF_KEY> B<key> using the B<len> bytes long key
5413d40330Schristosat B<data>.
5513d40330Schristos
5613d40330SchristosBF_ecb_encrypt() is the basic Blowfish encryption and decryption function.
5713d40330SchristosIt encrypts or decrypts the first 64 bits of B<in> using the key B<key>,
5813d40330Schristosputting the result in B<out>.  B<enc> decides if encryption (B<BF_ENCRYPT>)
5913d40330Schristosor decryption (B<BF_DECRYPT>) shall be performed.  The vector pointed at by
6013d40330SchristosB<in> and B<out> must be 64 bits in length, no less.  If they are larger,
6113d40330Schristoseverything after the first 64 bits is ignored.
6213d40330Schristos
6313d40330SchristosThe mode functions BF_cbc_encrypt(), BF_cfb64_encrypt() and BF_ofb64_encrypt()
6413d40330Schristosall operate on variable length data.  They all take an initialization vector
6513d40330SchristosB<ivec> which needs to be passed along into the next call of the same function
6613d40330Schristosfor the same message.  B<ivec> may be initialized with anything, but the
6713d40330Schristosrecipient needs to know what it was initialized with, or it won't be able
6813d40330Schristosto decrypt.  Some programs and protocols simplify this, like SSH, where
6913d40330SchristosB<ivec> is simply initialized to zero.
7013d40330SchristosBF_cbc_encrypt() operates on data that is a multiple of 8 bytes long, while
71f30e0929SchristosBF_cfb64_encrypt() and BF_ofb64_encrypt() are used to encrypt a variable
7213d40330Schristosnumber of bytes (the amount does not have to be an exact multiple of 8).  The
7313d40330Schristospurpose of the latter two is to simulate stream ciphers, and therefore, they
7413d40330Schristosneed the parameter B<num>, which is a pointer to an integer where the current
7513d40330Schristosoffset in B<ivec> is stored between calls.  This integer must be initialized
7613d40330Schristosto zero when B<ivec> is initialized.
7713d40330Schristos
7813d40330SchristosBF_cbc_encrypt() is the Cipher Block Chaining function for Blowfish.  It
7913d40330Schristosencrypts or decrypts the 64 bits chunks of B<in> using the key B<schedule>,
8013d40330Schristosputting the result in B<out>.  B<enc> decides if encryption (BF_ENCRYPT) or
8113d40330Schristosdecryption (BF_DECRYPT) shall be performed.  B<ivec> must point at an 8 byte
8213d40330Schristoslong initialization vector.
8313d40330Schristos
8413d40330SchristosBF_cfb64_encrypt() is the CFB mode for Blowfish with 64 bit feedback.
8513d40330SchristosIt encrypts or decrypts the bytes in B<in> using the key B<schedule>,
8613d40330Schristosputting the result in B<out>.  B<enc> decides if encryption (B<BF_ENCRYPT>)
8713d40330Schristosor decryption (B<BF_DECRYPT>) shall be performed.  B<ivec> must point at an
8813d40330Schristos8 byte long initialization vector. B<num> must point at an integer which must
8913d40330Schristosbe initially zero.
9013d40330Schristos
9113d40330SchristosBF_ofb64_encrypt() is the OFB mode for Blowfish with 64 bit feedback.
9213d40330SchristosIt uses the same parameters as BF_cfb64_encrypt(), which must be initialized
9313d40330Schristosthe same way.
9413d40330Schristos
9513d40330SchristosBF_encrypt() and BF_decrypt() are the lowest level functions for Blowfish
9613d40330Schristosencryption.  They encrypt/decrypt the first 64 bits of the vector pointed by
9713d40330SchristosB<data>, using the key B<key>.  These functions should not be used unless you
9813d40330Schristosimplement 'modes' of Blowfish.  The alternative is to use BF_ecb_encrypt().
9913d40330SchristosIf you still want to use these functions, you should be aware that they take
10013d40330Schristoseach 32-bit chunk in host-byte order, which is little-endian on little-endian
10113d40330Schristosplatforms and big-endian on big-endian ones.
10213d40330Schristos
10313d40330Schristos=head1 RETURN VALUES
10413d40330Schristos
10513d40330SchristosNone of the functions presented here return any value.
10613d40330Schristos
10713d40330Schristos=head1 NOTE
10813d40330Schristos
10913d40330SchristosApplications should use the higher level functions
11013d40330SchristosL<EVP_EncryptInit(3)> etc. instead of calling these
11113d40330Schristosfunctions directly.
11213d40330Schristos
11313d40330Schristos=head1 SEE ALSO
11413d40330Schristos
11513d40330SchristosL<EVP_EncryptInit(3)>,
11613d40330SchristosL<des_modes(7)>
11713d40330Schristos
118*b0d17251Schristos=head1 HISTORY
119*b0d17251Schristos
120*b0d17251SchristosAll of these functions were deprecated in OpenSSL 3.0.
121*b0d17251Schristos
12213d40330Schristos=head1 COPYRIGHT
12313d40330Schristos
124*b0d17251SchristosCopyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
12513d40330Schristos
126*b0d17251SchristosLicensed under the Apache License 2.0 (the "License").  You may not use
12713d40330Schristosthis file except in compliance with the License.  You can obtain a copy
12813d40330Schristosin the file LICENSE in the source distribution or at
12913d40330SchristosL<https://www.openssl.org/source/license.html>.
13013d40330Schristos
13113d40330Schristos=cut
132