xref: /netbsd-src/sys/crypto/blowfish/blowfish.h (revision 02cdf4d2c869ecfa1ae5484cf77eefe2fbcc6d94)
1*02cdf4d2Sdsl /*	$NetBSD: blowfish.h,v 1.8 2009/03/14 14:46:08 dsl Exp $	*/
27236276cSitojun /*	$KAME: blowfish.h,v 1.10 2000/09/18 21:21:20 itojun Exp $	*/
3599c8087Sthorpej 
4599c8087Sthorpej /* crypto/bf/blowfish.h */
5599c8087Sthorpej /* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
6599c8087Sthorpej  * All rights reserved.
7599c8087Sthorpej  *
8599c8087Sthorpej  * This package is an SSL implementation written
9599c8087Sthorpej  * by Eric Young (eay@mincom.oz.au).
10599c8087Sthorpej  * The implementation was written so as to conform with Netscapes SSL.
11599c8087Sthorpej  *
12599c8087Sthorpej  * This library is free for commercial and non-commercial use as long as
13599c8087Sthorpej  * the following conditions are aheared to.  The following conditions
14599c8087Sthorpej  * apply to all code found in this distribution, be it the RC4, RSA,
15599c8087Sthorpej  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
16599c8087Sthorpej  * included with this distribution is covered by the same copyright terms
17599c8087Sthorpej  * except that the holder is Tim Hudson (tjh@mincom.oz.au).
18599c8087Sthorpej  *
19599c8087Sthorpej  * Copyright remains Eric Young's, and as such any Copyright notices in
20599c8087Sthorpej  * the code are not to be removed.
21599c8087Sthorpej  * If this package is used in a product, Eric Young should be given attribution
22599c8087Sthorpej  * as the author of the parts of the library used.
23599c8087Sthorpej  * This can be in the form of a textual message at program startup or
24599c8087Sthorpej  * in documentation (online or textual) provided with the package.
25599c8087Sthorpej  *
26599c8087Sthorpej  * Redistribution and use in source and binary forms, with or without
27599c8087Sthorpej  * modification, are permitted provided that the following conditions
28599c8087Sthorpej  * are met:
29599c8087Sthorpej  * 1. Redistributions of source code must retain the copyright
30599c8087Sthorpej  *    notice, this list of conditions and the following disclaimer.
31599c8087Sthorpej  * 2. Redistributions in binary form must reproduce the above copyright
32599c8087Sthorpej  *    notice, this list of conditions and the following disclaimer in the
33599c8087Sthorpej  *    documentation and/or other materials provided with the distribution.
34599c8087Sthorpej  * 3. All advertising materials mentioning features or use of this software
35599c8087Sthorpej  *    must display the following acknowledgement:
36599c8087Sthorpej  *    "This product includes cryptographic software written by
37599c8087Sthorpej  *     Eric Young (eay@mincom.oz.au)"
38599c8087Sthorpej  *    The word 'cryptographic' can be left out if the rouines from the library
39599c8087Sthorpej  *    being used are not cryptographic related :-).
40599c8087Sthorpej  * 4. If you include any Windows specific code (or a derivative thereof) from
41599c8087Sthorpej  *    the apps directory (application code) you must include an acknowledgement:
42599c8087Sthorpej  *    "This product includes software written by Tim Hudson (tjh@mincom.oz.au)"
43599c8087Sthorpej  *
44599c8087Sthorpej  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
45599c8087Sthorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46599c8087Sthorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47599c8087Sthorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
48599c8087Sthorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49599c8087Sthorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50599c8087Sthorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51599c8087Sthorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52599c8087Sthorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53599c8087Sthorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54599c8087Sthorpej  * SUCH DAMAGE.
55599c8087Sthorpej  *
56599c8087Sthorpej  * The licence and distribution terms for any publically available version or
57599c8087Sthorpej  * derivative of this code cannot be changed.  i.e. this code cannot simply be
58599c8087Sthorpej  * copied and put under another distribution licence
59599c8087Sthorpej  * [including the GNU Public Licence.]
60599c8087Sthorpej  */
61599c8087Sthorpej 
62599c8087Sthorpej #ifndef HEADER_BLOWFISH_H
63599c8087Sthorpej #define HEADER_BLOWFISH_H
64599c8087Sthorpej 
65599c8087Sthorpej #ifdef  __cplusplus
66599c8087Sthorpej extern "C" {
67599c8087Sthorpej #endif
68599c8087Sthorpej 
69599c8087Sthorpej #define BF_ENCRYPT	1
70599c8087Sthorpej #define BF_DECRYPT	0
71599c8087Sthorpej 
720f164915Sitojun /* must be 32bit quantity */
730f164915Sitojun #define BF_LONG u_int32_t
74599c8087Sthorpej 
75599c8087Sthorpej #define BF_ROUNDS	16
76599c8087Sthorpej #define BF_BLOCK	8
77599c8087Sthorpej 
787236276cSitojun typedef struct bf_key_st {
79599c8087Sthorpej 	BF_LONG P[BF_ROUNDS+2];
80599c8087Sthorpej 	BF_LONG S[4*256];
81599c8087Sthorpej } BF_KEY;
82599c8087Sthorpej 
83*02cdf4d2Sdsl void BF_set_key(BF_KEY *, int, const unsigned char *);
84*02cdf4d2Sdsl void BF_encrypt(BF_LONG *, const BF_KEY *);
85*02cdf4d2Sdsl void BF_decrypt(BF_LONG *, const BF_KEY *);
863d4146e2Stls void BF_cbc_encrypt(const unsigned char *, unsigned char *, long,
873d4146e2Stls 		    const BF_KEY *, unsigned char *, int);
88e77423d9Sthorpej void BF_ecb_encrypt(const unsigned char *, unsigned char *,
89e77423d9Sthorpej 		    const BF_KEY *, int);
903d4146e2Stls 
91599c8087Sthorpej #ifdef  __cplusplus
92599c8087Sthorpej }
93599c8087Sthorpej #endif
94599c8087Sthorpej 
95599c8087Sthorpej #endif
96