00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #ifndef MBEDTLS_BLOWFISH_H
00052 #define MBEDTLS_BLOWFISH_H
00053
00054 #if !defined(MBEDTLS_CONFIG_FILE)
00055 #include "config.h"
00056 #else
00057 #include MBEDTLS_CONFIG_FILE
00058 #endif
00059
00060 #include <stddef.h>
00061 #include <stdint.h>
00062
00063 #define MBEDTLS_BLOWFISH_ENCRYPT 1
00064 #define MBEDTLS_BLOWFISH_DECRYPT 0
00065 #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
00066 #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
00067 #define MBEDTLS_BLOWFISH_ROUNDS 16
00068 #define MBEDTLS_BLOWFISH_BLOCKSIZE 8
00069
00070 #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016
00071 #define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
00072 #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
00074 #if !defined(MBEDTLS_BLOWFISH_ALT)
00075
00076
00077
00078 #ifdef __cplusplus
00079 extern "C" {
00080 #endif
00081
00085 typedef struct
00086 {
00087 uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2];
00088 uint32_t S[4][256];
00089 }
00090 mbedtls_blowfish_context;
00091
00097 void mbedtls_blowfish_init( mbedtls_blowfish_context *ctx );
00098
00104 void mbedtls_blowfish_free( mbedtls_blowfish_context *ctx );
00105
00115 int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
00116 unsigned int keybits );
00117
00128 int mbedtls_blowfish_crypt_ecb( mbedtls_blowfish_context *ctx,
00129 int mode,
00130 const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
00131 unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
00132
00133 #if defined(MBEDTLS_CIPHER_MODE_CBC)
00134
00157 int mbedtls_blowfish_crypt_cbc( mbedtls_blowfish_context *ctx,
00158 int mode,
00159 size_t length,
00160 unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
00161 const unsigned char *input,
00162 unsigned char *output );
00163 #endif
00164
00165 #if defined(MBEDTLS_CIPHER_MODE_CFB)
00166
00187 int mbedtls_blowfish_crypt_cfb64( mbedtls_blowfish_context *ctx,
00188 int mode,
00189 size_t length,
00190 size_t *iv_off,
00191 unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
00192 const unsigned char *input,
00193 unsigned char *output );
00194 #endif
00195
00196 #if defined(MBEDTLS_CIPHER_MODE_CTR)
00197
00215 int mbedtls_blowfish_crypt_ctr( mbedtls_blowfish_context *ctx,
00216 size_t length,
00217 size_t *nc_off,
00218 unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
00219 unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
00220 const unsigned char *input,
00221 unsigned char *output );
00222 #endif
00223
00224 #ifdef __cplusplus
00225 }
00226 #endif
00227
00228 #else
00229 #include "blowfish_alt.h"
00230 #endif
00231
00232 #endif