mbed TLS v2.2.0
blowfish.h
Go to the documentation of this file.
1 
23 #ifndef MBEDTLS_BLOWFISH_H
24 #define MBEDTLS_BLOWFISH_H
25 
26 #if !defined(MBEDTLS_CONFIG_FILE)
27 #include "config.h"
28 #else
29 #include MBEDTLS_CONFIG_FILE
30 #endif
31 
32 #include <stddef.h>
33 #include <stdint.h>
34 
35 #define MBEDTLS_BLOWFISH_ENCRYPT 1
36 #define MBEDTLS_BLOWFISH_DECRYPT 0
37 #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
38 #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
39 #define MBEDTLS_BLOWFISH_ROUNDS 16
40 #define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
41 
42 #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016
43 #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
45 #if !defined(MBEDTLS_BLOWFISH_ALT)
46 // Regular implementation
47 //
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
56 typedef struct
57 {
58  uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2];
59  uint32_t S[4][256];
60 }
62 
69 
76 
86 int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
87  unsigned int keybits );
88 
100  int mode,
101  const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
102  unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
103 
104 #if defined(MBEDTLS_CIPHER_MODE_CBC)
105 
128 int mbedtls_blowfish_crypt_cbc( mbedtls_blowfish_context *ctx,
129  int mode,
130  size_t length,
131  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
132  const unsigned char *input,
133  unsigned char *output );
134 #endif /* MBEDTLS_CIPHER_MODE_CBC */
135 
136 #if defined(MBEDTLS_CIPHER_MODE_CFB)
137 
158 int mbedtls_blowfish_crypt_cfb64( mbedtls_blowfish_context *ctx,
159  int mode,
160  size_t length,
161  size_t *iv_off,
162  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
163  const unsigned char *input,
164  unsigned char *output );
165 #endif /*MBEDTLS_CIPHER_MODE_CFB */
166 
167 #if defined(MBEDTLS_CIPHER_MODE_CTR)
168 
186 int mbedtls_blowfish_crypt_ctr( mbedtls_blowfish_context *ctx,
187  size_t length,
188  size_t *nc_off,
189  unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
190  unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
191  const unsigned char *input,
192  unsigned char *output );
193 #endif /* MBEDTLS_CIPHER_MODE_CTR */
194 
195 #ifdef __cplusplus
196 }
197 #endif
198 
199 #else /* MBEDTLS_BLOWFISH_ALT */
200 #include "blowfish_alt.h"
201 #endif /* MBEDTLS_BLOWFISH_ALT */
202 
203 #endif /* blowfish.h */
#define MBEDTLS_BLOWFISH_BLOCKSIZE
Definition: blowfish.h:40
Compatibility names (set of defines)
Blowfish context structure.
Definition: blowfish.h:56
void mbedtls_blowfish_init(mbedtls_blowfish_context *ctx)
Initialize Blowfish context.
int mbedtls_blowfish_crypt_ecb(mbedtls_blowfish_context *ctx, int mode, const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE], unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE])
Blowfish-ECB block encryption/decryption.
int mbedtls_blowfish_setkey(mbedtls_blowfish_context *ctx, const unsigned char *key, unsigned int keybits)
Blowfish key schedule.
#define MBEDTLS_BLOWFISH_ROUNDS
Rounds to use.
Definition: blowfish.h:39
void mbedtls_blowfish_free(mbedtls_blowfish_context *ctx)
Clear Blowfish context.