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