1218885Sdim/* crypto/bf/blowfish.h */ 2218885Sdim/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3218885Sdim * All rights reserved. 4218885Sdim * 5218885Sdim * This package is an SSL implementation written 6218885Sdim * by Eric Young (eay@cryptsoft.com). 7218885Sdim * The implementation was written so as to conform with Netscapes SSL. 8218885Sdim * 9218885Sdim * This library is free for commercial and non-commercial use as long as 10218885Sdim * the following conditions are aheared to. The following conditions 11218885Sdim * apply to all code found in this distribution, be it the RC4, RSA, 12218885Sdim * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13218885Sdim * included with this distribution is covered by the same copyright terms 14218885Sdim * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15218885Sdim * 16218885Sdim * Copyright remains Eric Young's, and as such any Copyright notices in 17218885Sdim * the code are not to be removed. 18218885Sdim * If this package is used in a product, Eric Young should be given attribution 19218885Sdim * as the author of the parts of the library used. 20218885Sdim * This can be in the form of a textual message at program startup or 21218885Sdim * in documentation (online or textual) provided with the package. 22218885Sdim * 23218885Sdim * Redistribution and use in source and binary forms, with or without 24218885Sdim * modification, are permitted provided that the following conditions 25226633Sdim * are met: 26226633Sdim * 1. Redistributions of source code must retain the copyright 27218885Sdim * notice, this list of conditions and the following disclaimer. 28218885Sdim * 2. Redistributions in binary form must reproduce the above copyright 29218885Sdim * notice, this list of conditions and the following disclaimer in the 30218885Sdim * documentation and/or other materials provided with the distribution. 31221345Sdim * 3. All advertising materials mentioning features or use of this software 32218885Sdim * must display the following acknowledgement: 33249423Sdim * "This product includes cryptographic software written by 34249423Sdim * Eric Young (eay@cryptsoft.com)" 35249423Sdim * The word 'cryptographic' can be left out if the rouines from the library 36249423Sdim * being used are not cryptographic related :-). 37249423Sdim * 4. If you include any Windows specific code (or a derivative thereof) from 38218885Sdim * the apps directory (application code) you must include an acknowledgement: 39218885Sdim * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40218885Sdim * 41218885Sdim * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42218885Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43218885Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44218885Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45218885Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46218885Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47218885Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48218885Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49218885Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50226633Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51218885Sdim * SUCH DAMAGE. 52218885Sdim * 53218885Sdim * The licence and distribution terms for any publically available version or 54218885Sdim * derivative of this code cannot be changed. i.e. this code cannot simply be 55218885Sdim * copied and put under another distribution licence 56218885Sdim * [including the GNU Public Licence.] 57218885Sdim */ 58218885Sdim 59218885Sdim#ifndef HEADER_BLOWFISH_H 60218885Sdim# define HEADER_BLOWFISH_H 61218885Sdim 62218885Sdim# include <openssl/e_os2.h> 63218885Sdim 64218885Sdim#ifdef __cplusplus 65218885Sdimextern "C" { 66218885Sdim#endif 67218885Sdim 68218885Sdim# ifdef OPENSSL_NO_BF 69218885Sdim# error BF is disabled. 70218885Sdim# endif 71218885Sdim 72218885Sdim# define BF_ENCRYPT 1 73218885Sdim# define BF_DECRYPT 0 74226633Sdim 75226633Sdim/*- 76226633Sdim * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 77226633Sdim * ! BF_LONG has to be at least 32 bits wide. If it's wider, then ! 78226633Sdim * ! BF_LONG_LOG2 has to be defined along. ! 79226633Sdim * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 80226633Sdim */ 81226633Sdim 82226633Sdim# if defined(__LP32__) 83226633Sdim# define BF_LONG unsigned long 84226633Sdim# elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) 85226633Sdim# define BF_LONG unsigned long 86226633Sdim# define BF_LONG_LOG2 3 87226633Sdim/* 88226633Sdim * _CRAY note. I could declare short, but I have no idea what impact 89226633Sdim * does it have on performance on none-T3E machines. I could declare 90226633Sdim * int, but at least on C90 sizeof(int) can be chosen at compile time. 91226633Sdim * So I've chosen long... 92226633Sdim * <appro@fy.chalmers.se> 93226633Sdim */ 94226633Sdim# else 95226633Sdim# define BF_LONG unsigned int 96226633Sdim# endif 97218885Sdim 98218885Sdim# define BF_ROUNDS 16 99218885Sdim# define BF_BLOCK 8 100218885Sdim 101218885Sdimtypedef struct bf_key_st { 102218885Sdim BF_LONG P[BF_ROUNDS + 2]; 103218885Sdim BF_LONG S[4 * 256]; 104218885Sdim} BF_KEY; 105218885Sdim 106218885Sdim# ifdef OPENSSL_FIPS 107221345Sdimvoid private_BF_set_key(BF_KEY *key, int len, const unsigned char *data); 108218885Sdim# endif 109218885Sdimvoid BF_set_key(BF_KEY *key, int len, const unsigned char *data); 110218885Sdim 111263508Sdimvoid BF_encrypt(BF_LONG *data, const BF_KEY *key); 112218885Sdimvoid BF_decrypt(BF_LONG *data, const BF_KEY *key); 113218885Sdim 114218885Sdimvoid BF_ecb_encrypt(const unsigned char *in, unsigned char *out, 115218885Sdim const BF_KEY *key, int enc); 116218885Sdimvoid BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, 117218885Sdim const BF_KEY *schedule, unsigned char *ivec, int enc); 118218885Sdimvoid BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, 119218885Sdim long length, const BF_KEY *schedule, 120218885Sdim unsigned char *ivec, int *num, int enc); 121218885Sdimvoid BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, 122218885Sdim long length, const BF_KEY *schedule, 123218885Sdim unsigned char *ivec, int *num); 124218885Sdimconst char *BF_options(void); 125218885Sdim 126218885Sdim#ifdef __cplusplus 127218885Sdim} 128218885Sdim#endif 129218885Sdim 130218885Sdim#endif 131218885Sdim