2N/A/* $OpenBSD: blf.h,v 1.6 2002/02/16 21:27:17 millert Exp $ */
2N/A/*
2N/A * Blowfish - a fast block cipher designed by Bruce Schneier
2N/A *
2N/A * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
2N/A * All rights reserved.
2N/A *
2N/A * Redistribution and use in source and binary forms, with or without
2N/A * modification, are permitted provided that the following conditions
2N/A * are met:
2N/A * 1. Redistributions of source code must retain the above copyright
2N/A * notice, this list of conditions and the following disclaimer.
2N/A * 2. Redistributions in binary form must reproduce the above copyright
2N/A * notice, this list of conditions and the following disclaimer in the
2N/A * documentation and/or other materials provided with the distribution.
2N/A * 3. All advertising materials mentioning features or use of this software
2N/A * must display the following acknowledgement:
2N/A * This product includes software developed by Niels Provos.
2N/A * 4. The name of the author may not be used to endorse or promote products
2N/A * derived from this software without specific prior written permission.
2N/A *
2N/A * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2N/A * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2N/A * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2N/A * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2N/A * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2N/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2N/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2N/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2N/A * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2N/A */
2N/A
2N/A#ifndef _BLF_H_
2N/A#define _BLF_H_
2N/A
2N/A/* Schneier specifies a maximum key length of 56 bytes.
2N/A * This ensures that every key bit affects every cipher
2N/A * bit. However, the subkeys can hold up to 72 bytes.
2N/A * Warning: For normal blowfish encryption only 56 bytes
2N/A * of the key affect all cipherbits.
2N/A */
2N/A
2N/A#define BLF_N 16 /* Number of Subkeys */
2N/A#define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */
2N/A
2N/A/* Blowfish context */
2N/Atypedef struct BlowfishContext {
2N/A uint32_t S[4][256]; /* S-Boxes */
2N/A uint32_t P[BLF_N + 2]; /* Subkeys */
2N/A} blf_ctx;
2N/A
2N/A/* Raw access to customized Blowfish
2N/A * blf_key is just:
2N/A * Blowfish_initstate( state )
2N/A * Blowfish_expand0state( state, key, keylen )
2N/A */
2N/A
2N/Avoid Blowfish_encipher(blf_ctx *, uint32_t *, uint32_t *);
2N/Avoid Blowfish_decipher(blf_ctx *, uint32_t *, uint32_t *);
2N/Avoid Blowfish_initstate(blf_ctx *);
2N/Avoid Blowfish_expand0state(blf_ctx *, const uint8_t *, uint16_t);
2N/Avoid Blowfish_expandstate
2N/A(blf_ctx *, const uint8_t *, uint16_t, const uint8_t *, uint16_t);
2N/A
2N/A/* Standard Blowfish */
2N/A
2N/Avoid blf_key(blf_ctx *, const uint8_t *, uint16_t);
2N/Avoid blf_enc(blf_ctx *, uint32_t *, uint16_t);
2N/Avoid blf_dec(blf_ctx *, uint32_t *, uint16_t);
2N/A
2N/Avoid blf_ecb_encrypt(blf_ctx *, uint8_t *, uint32_t);
2N/Avoid blf_ecb_decrypt(blf_ctx *, uint8_t *, uint32_t);
2N/A
2N/Avoid blf_cbc_encrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t);
2N/Avoid blf_cbc_decrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t);
2N/A
2N/A/* Converts uint8_t to uint32_t */
2N/Auint32_t Blowfish_stream2word(const uint8_t *, uint16_t , uint16_t *);
2N/A
2N/A#endif