mbed TLS v2.0.0
blowfish.h
Go to the documentation of this file.
1 
24 #ifndef MBEDTLS_BLOWFISH_H
25 #define MBEDTLS_BLOWFISH_H
26 
27 #if !defined(MBEDTLS_CONFIG_FILE)
28 #include "config.h"
29 #else
30 #include MBEDTLS_CONFIG_FILE
31 #endif
32 
33 #include <stddef.h>
34 #include <stdint.h>
35 
36 #define MBEDTLS_BLOWFISH_ENCRYPT 1
37 #define MBEDTLS_BLOWFISH_DECRYPT 0
38 #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
39 #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
40 #define MBEDTLS_BLOWFISH_ROUNDS 16
41 #define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
42 
43 #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016
44 #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
46 #if !defined(MBEDTLS_BLOWFISH_ALT)
47 // Regular implementation
48 //
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
57 typedef struct
58 {
59  uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2];
60  uint32_t S[4][256];
61 }
63 
70 
77 
87 int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
88  unsigned int keybits );
89 
101  int mode,
102  const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
103  unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
104 
105 #if defined(MBEDTLS_CIPHER_MODE_CBC)
106 
130  int mode,
131  size_t length,
132  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
133  const unsigned char *input,
134  unsigned char *output );
135 #endif /* MBEDTLS_CIPHER_MODE_CBC */
136 
137 #if defined(MBEDTLS_CIPHER_MODE_CFB)
138 
160  int mode,
161  size_t length,
162  size_t *iv_off,
163  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
164  const unsigned char *input,
165  unsigned char *output );
166 #endif /*MBEDTLS_CIPHER_MODE_CFB */
167 
168 #if defined(MBEDTLS_CIPHER_MODE_CTR)
169 
188  size_t length,
189  size_t *nc_off,
190  unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
191  unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
192  const unsigned char *input,
193  unsigned char *output );
194 #endif /* MBEDTLS_CIPHER_MODE_CTR */
195 
196 #ifdef __cplusplus
197 }
198 #endif
199 
200 #else /* MBEDTLS_BLOWFISH_ALT */
201 #include "blowfish_alt.h"
202 #endif /* MBEDTLS_BLOWFISH_ALT */
203 
204 #endif /* blowfish.h */
#define MBEDTLS_BLOWFISH_BLOCKSIZE
Definition: blowfish.h:41
int mbedtls_blowfish_crypt_ctr(mbedtls_blowfish_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE], unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Blowfish-CTR buffer encryption/decryption.
Compatibility names (set of defines)
Blowfish context structure.
Definition: blowfish.h:57
void mbedtls_blowfish_init(mbedtls_blowfish_context *ctx)
Initialize Blowfish context.
int mbedtls_blowfish_crypt_cfb64(mbedtls_blowfish_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Blowfish CFB buffer encryption/decryption.
int mbedtls_blowfish_crypt_cbc(mbedtls_blowfish_context *ctx, int mode, size_t length, unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Blowfish-CBC buffer encryption/decryption Length should be a multiple of the block size (8 bytes) ...
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:40
void mbedtls_blowfish_free(mbedtls_blowfish_context *ctx)
Clear Blowfish context.