xref: /freebsd/secure/lib/libcrypt/blowfish.h (revision c8fa8e25d77016f36e63790f2ceccb90613ccb2e)
15c129616SMark Murray /*
25c129616SMark Murray  * Blowfish - a fast block cipher designed by Bruce Schneier
35c129616SMark Murray  *
45c129616SMark Murray  * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
55c129616SMark Murray  * All rights reserved.
65c129616SMark Murray  *
75c129616SMark Murray  * Redistribution and use in source and binary forms, with or without
85c129616SMark Murray  * modification, are permitted provided that the following conditions
95c129616SMark Murray  * are met:
105c129616SMark Murray  * 1. Redistributions of source code must retain the above copyright
115c129616SMark Murray  *    notice, this list of conditions and the following disclaimer.
125c129616SMark Murray  * 2. Redistributions in binary form must reproduce the above copyright
135c129616SMark Murray  *    notice, this list of conditions and the following disclaimer in the
145c129616SMark Murray  *    documentation and/or other materials provided with the distribution.
155c129616SMark Murray  * 3. All advertising materials mentioning features or use of this software
165c129616SMark Murray  *    must display the following acknowledgement:
175c129616SMark Murray  *      This product includes software developed by Niels Provos.
185c129616SMark Murray  * 4. The name of the author may not be used to endorse or promote products
195c129616SMark Murray  *    derived from this software without specific prior written permission.
205c129616SMark Murray  *
215c129616SMark Murray  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
225c129616SMark Murray  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
235c129616SMark Murray  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
245c129616SMark Murray  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
255c129616SMark Murray  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
265c129616SMark Murray  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
275c129616SMark Murray  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
285c129616SMark Murray  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
295c129616SMark Murray  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
305c129616SMark Murray  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
315c129616SMark Murray  *
325c129616SMark Murray  * $FreeBSD$
335c129616SMark Murray  */
345c129616SMark Murray 
355c129616SMark Murray /*
365c129616SMark Murray  * FreeBSD implementation by Paul Herman <pherman@frenchfries.net>
375c129616SMark Murray  */
385c129616SMark Murray 
395c129616SMark Murray #ifndef _BLF_H_
405c129616SMark Murray #define _BLF_H_
415c129616SMark Murray 
425c129616SMark Murray /* Schneier states the maximum key length to be 56 bytes.
435c129616SMark Murray  * The way how the subkeys are initalized by the key up
445c129616SMark Murray  * to (N+2)*4 i.e. 72 bytes are utilized.
455c129616SMark Murray  * Warning: For normal blowfish encryption only 56 bytes
465c129616SMark Murray  * of the key affect all cipherbits.
475c129616SMark Murray  */
485c129616SMark Murray 
495c129616SMark Murray #define BLF_N	16			/* Number of Subkeys */
505c129616SMark Murray 
515c129616SMark Murray /* Blowfish context */
525c129616SMark Murray typedef struct BlowfishContext {
535c129616SMark Murray 	u_int32_t S[4][256];	/* S-Boxes */
545c129616SMark Murray 	u_int32_t P[BLF_N + 2];	/* Subkeys */
555c129616SMark Murray } blf_ctx;
565c129616SMark Murray 
575c129616SMark Murray /* Raw access to customized Blowfish
585c129616SMark Murray  *	blf_key is just:
595c129616SMark Murray  *	Blowfish_initstate( state )
605c129616SMark Murray  *	Blowfish_expand0state( state, key, keylen )
615c129616SMark Murray  */
625c129616SMark Murray 
63f2ac424aSMark Murray void Blowfish_initstate(blf_ctx *);
64f2ac424aSMark Murray void Blowfish_expand0state(blf_ctx *, const u_int8_t *, u_int16_t);
655c129616SMark Murray void Blowfish_expandstate
66f2ac424aSMark Murray    (blf_ctx *, const u_int8_t *, u_int16_t, const u_int8_t *, u_int16_t);
67f2ac424aSMark Murray u_int32_t Blowfish_stream2word(const u_int8_t *, u_int16_t, u_int16_t *);
685c129616SMark Murray 
69c8fa8e25SMark Murray void blf_enc(blf_ctx *, u_int32_t *, u_int16_t);
70c8fa8e25SMark Murray 
71c8fa8e25SMark Murray #endif /* _BLF_H_ */
72