00001
00027 #ifndef POLARSSL_BLOWFISH_H
00028 #define POLARSSL_BLOWFISH_H
00029
00030 #include "config.h"
00031
00032 #include <string.h>
00033
00034 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
00035 #include <basetsd.h>
00036 typedef UINT32 uint32_t;
00037 #else
00038 #include <inttypes.h>
00039 #endif
00040
00041 #define BLOWFISH_ENCRYPT 1
00042 #define BLOWFISH_DECRYPT 0
00043 #define BLOWFISH_MAX_KEY 448
00044 #define BLOWFISH_MIN_KEY 32
00045 #define BLOWFISH_ROUNDS 16
00046 #define BLOWFISH_BLOCKSIZE 8
00047
00048 #define POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016
00049 #define POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
00051 #if !defined(POLARSSL_BLOWFISH_ALT)
00052
00053
00054
00055 #ifdef __cplusplus
00056 extern "C" {
00057 #endif
00058
00062 typedef struct
00063 {
00064 uint32_t P[BLOWFISH_ROUNDS + 2];
00065 uint32_t S[4][256];
00066 }
00067 blowfish_context;
00068
00078 int blowfish_setkey( blowfish_context *ctx, const unsigned char *key, unsigned int keysize );
00079
00090 int blowfish_crypt_ecb( blowfish_context *ctx,
00091 int mode,
00092 const unsigned char input[BLOWFISH_BLOCKSIZE],
00093 unsigned char output[BLOWFISH_BLOCKSIZE] );
00094
00095 #if defined(POLARSSL_CIPHER_MODE_CBC)
00096
00110 int blowfish_crypt_cbc( blowfish_context *ctx,
00111 int mode,
00112 size_t length,
00113 unsigned char iv[BLOWFISH_BLOCKSIZE],
00114 const unsigned char *input,
00115 unsigned char *output );
00116 #endif
00117
00118 #if defined(POLARSSL_CIPHER_MODE_CFB)
00119
00132 int blowfish_crypt_cfb64( blowfish_context *ctx,
00133 int mode,
00134 size_t length,
00135 size_t *iv_off,
00136 unsigned char iv[BLOWFISH_BLOCKSIZE],
00137 const unsigned char *input,
00138 unsigned char *output );
00139 #endif
00140
00141 #if defined(POLARSSL_CIPHER_MODE_CTR)
00142
00160 int blowfish_crypt_ctr( blowfish_context *ctx,
00161 size_t length,
00162 size_t *nc_off,
00163 unsigned char nonce_counter[BLOWFISH_BLOCKSIZE],
00164 unsigned char stream_block[BLOWFISH_BLOCKSIZE],
00165 const unsigned char *input,
00166 unsigned char *output );
00167 #endif
00168
00169 #ifdef __cplusplus
00170 }
00171 #endif
00172
00173 #else
00174 #include "blowfish_alt.h"
00175 #endif
00176
00177 #endif