xref: /titanic_52/usr/src/lib/crypt_modules/bsdbf/blf.h (revision 554ff184129088135ad2643c1c9832174a17be88)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /* $OpenBSD: blf.h,v 1.6 2002/02/16 21:27:17 millert Exp $ */
23 /*
24  * Blowfish - a fast block cipher designed by Bruce Schneier
25  *
26  * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without
30  * modification, are permitted provided that the following conditions
31  * are met:
32  * 1. Redistributions of source code must retain the above copyright
33  *    notice, this list of conditions and the following disclaimer.
34  * 2. Redistributions in binary form must reproduce the above copyright
35  *    notice, this list of conditions and the following disclaimer in the
36  *    documentation and/or other materials provided with the distribution.
37  * 3. All advertising materials mentioning features or use of this software
38  *    must display the following acknowledgement:
39  *      This product includes software developed by Niels Provos.
40  * 4. The name of the author may not be used to endorse or promote products
41  *    derived from this software without specific prior written permission.
42  *
43  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
44  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
45  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
46  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
47  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
52  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53  */
54 
55 #ifndef _BLF_H_
56 #define _BLF_H_
57 
58 /* Schneier specifies a maximum key length of 56 bytes.
59  * This ensures that every key bit affects every cipher
60  * bit.  However, the subkeys can hold up to 72 bytes.
61  * Warning: For normal blowfish encryption only 56 bytes
62  * of the key affect all cipherbits.
63  */
64 
65 #define BLF_N	16			/* Number of Subkeys */
66 #define BLF_MAXKEYLEN ((BLF_N-2)*4)	/* 448 bits */
67 
68 /* Blowfish context */
69 typedef struct BlowfishContext {
70 	uint32_t S[4][256];	/* S-Boxes */
71 	uint32_t P[BLF_N + 2];	/* Subkeys */
72 } blf_ctx;
73 
74 /* Raw access to customized Blowfish
75  *	blf_key is just:
76  *	Blowfish_initstate( state )
77  *	Blowfish_expand0state( state, key, keylen )
78  */
79 
80 void Blowfish_encipher(blf_ctx *, uint32_t *, uint32_t *);
81 void Blowfish_decipher(blf_ctx *, uint32_t *, uint32_t *);
82 void Blowfish_initstate(blf_ctx *);
83 void Blowfish_expand0state(blf_ctx *, const uint8_t *, uint16_t);
84 void Blowfish_expandstate
85 (blf_ctx *, const uint8_t *, uint16_t, const uint8_t *, uint16_t);
86 
87 /* Standard Blowfish */
88 
89 void blf_key(blf_ctx *, const uint8_t *, uint16_t);
90 void blf_enc(blf_ctx *, uint32_t *, uint16_t);
91 void blf_dec(blf_ctx *, uint32_t *, uint16_t);
92 
93 void blf_ecb_encrypt(blf_ctx *, uint8_t *, uint32_t);
94 void blf_ecb_decrypt(blf_ctx *, uint8_t *, uint32_t);
95 
96 void blf_cbc_encrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t);
97 void blf_cbc_decrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t);
98 
99 /* Converts uint8_t to uint32_t */
100 uint32_t Blowfish_stream2word(const uint8_t *, uint16_t , uint16_t *);
101 
102 #endif
103