1 /*
2  * Blowfish - a fast block cipher designed by Bruce Schneier
3  *
4  * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef _BLF_H_
31 #define _BLF_H_
32 
33 /* Schneier states the maximum key length to be 56 bytes.
34  * The way how the subkeys are initialized by the key up
35  * to (N+2)*4 i.e. 72 bytes are utilized.
36  * Warning: For normal blowfish encryption only 56 bytes
37  * of the key affect all cipherbits.
38  */
39 
40 #define BLF_N	16			/* Number of Subkeys */
41 #define BLF_MAXKEYLEN ((BLF_N-2)*4)	/* 448 bits */
42 #define BLF_MAXUTILIZED ((BLF_N+2)*4)	/* 576 bits */
43 
44 /* Blowfish context */
45 typedef struct BlowfishContext {
46 	u_int32_t S[4][256];	/* S-Boxes */
47 	u_int32_t P[BLF_N + 2];	/* Subkeys */
48 } blf_ctx;
49 
50 /* Raw access to customized Blowfish
51  *	blf_key is just:
52  *	Blowfish_initstate( state )
53  *	Blowfish_expand0state( state, key, keylen )
54  */
55 
56 void Blowfish_encipher(blf_ctx *, u_int32_t *);
57 void Blowfish_decipher(blf_ctx *, u_int32_t *);
58 void Blowfish_initstate(blf_ctx *);
59 void Blowfish_expand0state(blf_ctx *, const u_int8_t *, u_int16_t);
60 void Blowfish_expandstate(blf_ctx *, const u_int8_t *, u_int16_t, const u_int8_t *, u_int16_t);
61 
62 /* Standard Blowfish */
63 
64 void blf_key(blf_ctx *, const u_int8_t *, u_int16_t);
65 void blf_enc(blf_ctx *, u_int32_t *, u_int16_t);
66 void blf_dec(blf_ctx *, u_int32_t *, u_int16_t);
67 
68 /* Converts u_int8_t to u_int32_t */
69 u_int32_t Blowfish_stream2word(const u_int8_t *, u_int16_t ,
70 				    u_int16_t *);
71 
72 int bcrypt_hashpass(const char *, const char *, char *, size_t);
73 
74 #endif
75