POK
|
00001 /* 00002 * POK header 00003 * 00004 * The following file is a part of the POK project. Any modification should 00005 * made according to the POK licence. You CANNOT use this file or a part of 00006 * this file is this part of a file for your own project 00007 * 00008 * For more information on the POK licence, please see our LICENCE FILE 00009 * 00010 * Please follow the coding guidelines described in doc/CODING_GUIDELINES 00011 * 00012 * Copyright (c) 2007-2009 POK team 00013 * 00014 * Created by julien on Fri Dec 11 16:32:31 2009 00015 */ 00016 00017 /* crypto/bf/blowfish.h */ 00018 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 00019 * All rights reserved. 00020 * 00021 * This package is an SSL implementation written 00022 * by Eric Young (eay@cryptsoft.com). 00023 * The implementation was written so as to conform with Netscapes SSL. 00024 * 00025 * This library is free for commercial and non-commercial use as long as 00026 * the following conditions are aheared to. The following conditions 00027 * apply to all code found in this distribution, be it the RC4, RSA, 00028 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 00029 * included with this distribution is covered by the same copyright terms 00030 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 00031 * 00032 * Copyright remains Eric Young's, and as such any Copyright notices in 00033 * the code are not to be removed. 00034 * If this package is used in a product, Eric Young should be given attribution 00035 * as the author of the parts of the library used. 00036 * This can be in the form of a textual message at program startup or 00037 * in documentation (online or textual) provided with the package. 00038 * 00039 * Redistribution and use in source and binary forms, with or without 00040 * modification, are permitted provided that the following conditions 00041 * are met: 00042 * 1. Redistributions of source code must retain the copyright 00043 * notice, this list of conditions and the following disclaimer. 00044 * 2. Redistributions in binary form must reproduce the above copyright 00045 * notice, this list of conditions and the following disclaimer in the 00046 * documentation and/or other materials provided with the distribution. 00047 * 3. All advertising materials mentioning features or use of this software 00048 * must display the following acknowledgement: 00049 * "This product includes cryptographic software written by 00050 * Eric Young (eay@cryptsoft.com)" 00051 * The word 'cryptographic' can be left out if the rouines from the library 00052 * being used are not cryptographic related :-). 00053 * 4. If you include any Windows specific code (or a derivative thereof) from 00054 * the apps directory (application code) you must include an acknowledgement: 00055 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 00056 * 00057 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 00058 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00059 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00060 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 00061 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00062 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00063 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00064 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00065 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00066 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00067 * SUCH DAMAGE. 00068 * 00069 * The licence and distribution terms for any publically available version or 00070 * derivative of this code cannot be changed. i.e. this code cannot simply be 00071 * copied and put under another distribution licence 00072 * [including the GNU Public Licence.] 00073 */ 00074 00075 #ifdef POK_NEEDS_PROTOCOLS_BLOWFISH 00076 00077 #ifndef HEADER_BLOWFISH_H 00078 #define HEADER_BLOWFISH_H 00079 00080 //#include <openssl/e_os2.h> 00081 #include <types.h> 00082 00083 #define BF_ENCRYPT 1 00084 #define BF_DECRYPT 0 00085 00086 /* 00087 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 00088 * ! BF_LONG has to be at least 32 bits wide. If it's wider, then ! 00089 * ! BF_LONG_LOG2 has to be defined along. ! 00090 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 00091 */ 00092 00093 #define BF_LONG uint32_t 00094 00095 #define BF_PTR2 00096 00097 #define BF_ROUNDS 16 00098 #define BF_BLOCK 8 00099 00100 typedef struct bf_key_st 00101 { 00102 BF_LONG P[BF_ROUNDS+2]; 00103 BF_LONG S[4*256]; 00104 } BF_KEY; 00105 00106 #ifdef OPENSSL_FIPS 00107 void private_BF_set_key(BF_KEY *key, int len, const unsigned char *data); 00108 #endif 00109 void BF_set_key(BF_KEY *key, int len, const unsigned char *data); 00110 00111 void BF_encrypt(BF_LONG *data,const BF_KEY *key); 00112 void BF_decrypt(BF_LONG *data,const BF_KEY *key); 00113 00114 void BF_ecb_encrypt(const unsigned char *in, unsigned char *out, 00115 const BF_KEY *key, int enc); 00116 void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, 00117 const BF_KEY *schedule, unsigned char *ivec, int enc); 00118 void BF_cfb64_encrypt(const unsigned char *in, unsigned char *out, long length, 00119 const BF_KEY *schedule, unsigned char *ivec, int *num, int enc); 00120 void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, long length, 00121 const BF_KEY *schedule, unsigned char *ivec, int *num); 00122 const char *BF_options(void); 00123 00124 #ifdef __cplusplus 00125 } 00126 #endif 00127 00128 #endif 00129 00130 #endif /* POK_NEEDS_PROTOCOLS */