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 #ifndef MBEDTLS_BLOWFISH_H
00050 #define MBEDTLS_BLOWFISH_H
00051
00052 #if !defined(MBEDTLS_CONFIG_FILE)
00053 #include "config.h"
00054 #else
00055 #include MBEDTLS_CONFIG_FILE
00056 #endif
00057
00058 #include <stddef.h>
00059 #include <stdint.h>
00060
00061 #define MBEDTLS_BLOWFISH_ENCRYPT 1
00062 #define MBEDTLS_BLOWFISH_DECRYPT 0
00063 #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
00064 #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
00065 #define MBEDTLS_BLOWFISH_ROUNDS 16
00066 #define MBEDTLS_BLOWFISH_BLOCKSIZE 8
00067
00068 #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016
00069 #define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
00070 #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
00072 #if !defined(MBEDTLS_BLOWFISH_ALT)
00073
00074
00075
00076 #ifdef __cplusplus
00077 extern "C" {
00078 #endif
00079
00083 typedef struct
00084 {
00085 uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2];
00086 uint32_t S[4][256];
00087 }
00088 mbedtls_blowfish_context;
00089
00095 void mbedtls_blowfish_init( mbedtls_blowfish_context *ctx );
00096
00102 void mbedtls_blowfish_free( mbedtls_blowfish_context *ctx );
00103
00113 int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
00114 unsigned int keybits );
00115
00126 int mbedtls_blowfish_crypt_ecb( mbedtls_blowfish_context *ctx,
00127 int mode,
00128 const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
00129 unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
00130
00131 #if defined(MBEDTLS_CIPHER_MODE_CBC)
00132
00155 int mbedtls_blowfish_crypt_cbc( mbedtls_blowfish_context *ctx,
00156 int mode,
00157 size_t length,
00158 unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
00159 const unsigned char *input,
00160 unsigned char *output );
00161 #endif
00162
00163 #if defined(MBEDTLS_CIPHER_MODE_CFB)
00164
00185 int mbedtls_blowfish_crypt_cfb64( mbedtls_blowfish_context *ctx,
00186 int mode,
00187 size_t length,
00188 size_t *iv_off,
00189 unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
00190 const unsigned char *input,
00191 unsigned char *output );
00192 #endif
00193
00194 #if defined(MBEDTLS_CIPHER_MODE_CTR)
00195
00213 int mbedtls_blowfish_crypt_ctr( mbedtls_blowfish_context *ctx,
00214 size_t length,
00215 size_t *nc_off,
00216 unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
00217 unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
00218 const unsigned char *input,
00219 unsigned char *output );
00220 #endif
00221
00222 #ifdef __cplusplus
00223 }
00224 #endif
00225
00226 #else
00227 #include "blowfish_alt.h"
00228 #endif
00229
00230 #endif