00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef MBEDTLS_BLOWFISH_H
00025 #define MBEDTLS_BLOWFISH_H
00026
00027 #if !defined(MBEDTLS_CONFIG_FILE)
00028 #include "config.h"
00029 #else
00030 #include MBEDTLS_CONFIG_FILE
00031 #endif
00032
00033 #include <stddef.h>
00034 #include <stdint.h>
00035
00036 #define MBEDTLS_BLOWFISH_ENCRYPT 1
00037 #define MBEDTLS_BLOWFISH_DECRYPT 0
00038 #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
00039 #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
00040 #define MBEDTLS_BLOWFISH_ROUNDS 16
00041 #define MBEDTLS_BLOWFISH_BLOCKSIZE 8
00042
00043 #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016
00044 #define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
00045 #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
00047 #if !defined(MBEDTLS_BLOWFISH_ALT)
00048
00049
00050
00051 #ifdef __cplusplus
00052 extern "C" {
00053 #endif
00054
00058 typedef struct
00059 {
00060 uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2];
00061 uint32_t S[4][256];
00062 }
00063 mbedtls_blowfish_context;
00064
00070 void mbedtls_blowfish_init( mbedtls_blowfish_context *ctx );
00071
00077 void mbedtls_blowfish_free( mbedtls_blowfish_context *ctx );
00078
00088 int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
00089 unsigned int keybits );
00090
00101 int mbedtls_blowfish_crypt_ecb( mbedtls_blowfish_context *ctx,
00102 int mode,
00103 const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
00104 unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
00105
00106 #if defined(MBEDTLS_CIPHER_MODE_CBC)
00107
00130 int mbedtls_blowfish_crypt_cbc( mbedtls_blowfish_context *ctx,
00131 int mode,
00132 size_t length,
00133 unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
00134 const unsigned char *input,
00135 unsigned char *output );
00136 #endif
00137
00138 #if defined(MBEDTLS_CIPHER_MODE_CFB)
00139
00160 int mbedtls_blowfish_crypt_cfb64( mbedtls_blowfish_context *ctx,
00161 int mode,
00162 size_t length,
00163 size_t *iv_off,
00164 unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
00165 const unsigned char *input,
00166 unsigned char *output );
00167 #endif
00168
00169 #if defined(MBEDTLS_CIPHER_MODE_CTR)
00170
00188 int mbedtls_blowfish_crypt_ctr( mbedtls_blowfish_context *ctx,
00189 size_t length,
00190 size_t *nc_off,
00191 unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
00192 unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
00193 const unsigned char *input,
00194 unsigned char *output );
00195 #endif
00196
00197 #ifdef __cplusplus
00198 }
00199 #endif
00200
00201 #else
00202 #include "blowfish_alt.h"
00203 #endif
00204
00205 #endif