1.\" $OpenBSD: blowfish.3,v 1.20 2007/05/31 19:19:27 jmc Exp $ 2.\" 3.\" Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by Niels Provos. 17.\" 4. The name of the author may not be used to endorse or promote products 18.\" derived from this software without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30.\" 31.\" Manual page, using -mandoc macros 32.\" 33.Dd $Mdocdate: May 31 2007 $ 34.Dt BLOWFISH 3 35.Os 36.Sh NAME 37.Nm blf_key , 38.Nm blf_enc , 39.Nm blf_dec , 40.Nm blf_ecb_encrypt , 41.Nm blf_ecb_decrypt , 42.Nm blf_cbc_encrypt , 43.Nm blf_cbc_decrypt 44.Nd Blowfish encryption 45.Sh SYNOPSIS 46.Fd #include <blf.h> 47.Ft void 48.Fn blf_key "blf_ctx *state" "const u_int8_t *key" "u_int16_t keylen" 49.Ft void 50.Fn blf_enc "blf_ctx *state" "u_int32_t *data" "u_int16_t blocks" 51.Ft void 52.Fn blf_dec "blf_ctx *state" "u_int32_t *data" "u_int16_t blocks" 53.Ft void 54.Fn blf_ecb_encrypt "blf_ctx *state" "u_int8_t *data" "u_int32_t datalen" 55.Ft void 56.Fn blf_ecb_decrypt "blf_ctx *state" "u_int8_t *data" "u_int32_t datalen" 57.Ft void 58.Fn blf_cbc_encrypt "blf_ctx *state" "u_int8_t *iv" "u_int8_t *data" "u_int32_t datalen" 59.Ft void 60.Fn blf_cbc_decrypt "blf_ctx *state" "u_int8_t *iv" "u_int8_t *data" "u_int32_t datalen" 61.Sh DESCRIPTION 62.Em Blowfish 63is a fast unpatented block cipher designed by Bruce Schneier. 64It basically consists of a 16-round Feistel network. 65The block size is 64 bits and the maximum key size is 448 bits. 66.Pp 67The 68.Fn blf_key 69function initializes the 4 8-bit S-boxes and the 18 Subkeys with 70the hexadecimal digits of Pi. 71The key is used for further randomization. 72The first argument to 73.Fn blf_enc 74is the initialized state derived from 75.Fn blf_key . 76The stream of 32-bit words is encrypted in Electronic Codebook 77Mode (ECB) and 78.Fa blocks 79is the number of 64-bit blocks in the stream. 80.Fn blf_dec 81is used for decrypting Blowfish encrypted blocks. 82.Pp 83The functions 84.Fn blf_ecb_encrypt 85and 86.Fn blf_ecb_decrypt 87are used for encrypting and decrypting octet streams in ECB mode. 88The functions 89.Fn blf_cbc_encrypt 90and 91.Fn blf_cbc_decrypt 92are used for encrypting and decrypting octet streams in 93Cipherblock Chaining Mode (CBC). 94For these functions 95.Fa datalen 96specifies the number of octets of data to encrypt or decrypt. 97It must be a multiple of 8 (64-bit block). 98The initialisation vector 99.Fa iv 100points to an 8-byte buffer. 101.Sh SEE ALSO 102.Xr passwd 1 , 103.Xr crypt 3 , 104.Xr passwd 5 105.Sh AUTHORS 106.An Niels Provos Aq provos@physnet.uni-hamburg.de 107