PolarSSL v1.3.3
blowfish.h
Go to the documentation of this file.
1 
27 #ifndef POLARSSL_BLOWFISH_H
28 #define POLARSSL_BLOWFISH_H
29 
30 #include "config.h"
31 
32 #include <string.h>
33 
34 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
35 #include <basetsd.h>
36 typedef UINT32 uint32_t;
37 #else
38 #include <inttypes.h>
39 #endif
40 
41 #define BLOWFISH_ENCRYPT 1
42 #define BLOWFISH_DECRYPT 0
43 #define BLOWFISH_MAX_KEY 448
44 #define BLOWFISH_MIN_KEY 32
45 #define BLOWFISH_ROUNDS 16 /* when increasing this value, make sure to extend the initialisation vectors */
46 #define BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
47 
48 #define POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016
49 #define POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
51 #if !defined(POLARSSL_BLOWFISH_ALT)
52 // Regular implementation
53 //
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
62 typedef struct
63 {
64  uint32_t P[BLOWFISH_ROUNDS + 2];
65  uint32_t S[4][256];
66 }
68 
78 int blowfish_setkey( blowfish_context *ctx, const unsigned char *key, unsigned int keysize );
79 
91  int mode,
92  const unsigned char input[BLOWFISH_BLOCKSIZE],
93  unsigned char output[BLOWFISH_BLOCKSIZE] );
94 
95 #if defined(POLARSSL_CIPHER_MODE_CBC)
96 
111  int mode,
112  size_t length,
113  unsigned char iv[BLOWFISH_BLOCKSIZE],
114  const unsigned char *input,
115  unsigned char *output );
116 #endif /* POLARSSL_CIPHER_MODE_CBC */
117 
118 #if defined(POLARSSL_CIPHER_MODE_CFB)
119 
133  int mode,
134  size_t length,
135  size_t *iv_off,
136  unsigned char iv[BLOWFISH_BLOCKSIZE],
137  const unsigned char *input,
138  unsigned char *output );
139 #endif /*POLARSSL_CIPHER_MODE_CFB */
140 
141 #if defined(POLARSSL_CIPHER_MODE_CTR)
142 
161  size_t length,
162  size_t *nc_off,
163  unsigned char nonce_counter[BLOWFISH_BLOCKSIZE],
164  unsigned char stream_block[BLOWFISH_BLOCKSIZE],
165  const unsigned char *input,
166  unsigned char *output );
167 #endif /* POLARSSL_CIPHER_MODE_CTR */
168 
169 #ifdef __cplusplus
170 }
171 #endif
172 
173 #else /* POLARSSL_BLOWFISH_ALT */
174 #include "blowfish_alt.h"
175 #endif /* POLARSSL_BLOWFISH_ALT */
176 
177 #endif /* blowfish.h */
int blowfish_setkey(blowfish_context *ctx, const unsigned char *key, unsigned int keysize)
Blowfish key schedule.
Configuration options (set of defines)
int blowfish_crypt_ecb(blowfish_context *ctx, int mode, const unsigned char input[BLOWFISH_BLOCKSIZE], unsigned char output[BLOWFISH_BLOCKSIZE])
Blowfish-ECB block encryption/decryption.
#define BLOWFISH_ROUNDS
Definition: blowfish.h:45
#define BLOWFISH_BLOCKSIZE
Definition: blowfish.h:46
int blowfish_crypt_ctr(blowfish_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[BLOWFISH_BLOCKSIZE], unsigned char stream_block[BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Blowfish-CTR buffer encryption/decryption.
int blowfish_crypt_cfb64(blowfish_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Blowfish CFB buffer encryption/decryption.
Blowfish context structure.
Definition: blowfish.h:62
int blowfish_crypt_cbc(blowfish_context *ctx, int mode, size_t length, unsigned char iv[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) ...