PolarSSL v1.3.8
blowfish.h
Go to the documentation of this file.
1 
27 #ifndef POLARSSL_BLOWFISH_H
28 #define POLARSSL_BLOWFISH_H
29 
30 #if !defined(POLARSSL_CONFIG_FILE)
31 #include "config.h"
32 #else
33 #include POLARSSL_CONFIG_FILE
34 #endif
35 
36 #include <string.h>
37 
38 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
39 #include <basetsd.h>
40 typedef UINT32 uint32_t;
41 #else
42 #include <inttypes.h>
43 #endif
44 
45 #define BLOWFISH_ENCRYPT 1
46 #define BLOWFISH_DECRYPT 0
47 #define BLOWFISH_MAX_KEY 448
48 #define BLOWFISH_MIN_KEY 32
49 #define BLOWFISH_ROUNDS 16
50 #define BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
51 
52 #define POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016
53 #define POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
55 #if !defined(POLARSSL_BLOWFISH_ALT)
56 // Regular implementation
57 //
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
66 typedef struct
67 {
68  uint32_t P[BLOWFISH_ROUNDS + 2];
69  uint32_t S[4][256];
70 }
72 
78 void blowfish_init( blowfish_context *ctx );
79 
85 void blowfish_free( blowfish_context *ctx );
86 
96 int blowfish_setkey( blowfish_context *ctx, const unsigned char *key,
97  unsigned int keysize );
98 
110  int mode,
111  const unsigned char input[BLOWFISH_BLOCKSIZE],
112  unsigned char output[BLOWFISH_BLOCKSIZE] );
113 
114 #if defined(POLARSSL_CIPHER_MODE_CBC)
115 
131  int mode,
132  size_t length,
133  unsigned char iv[BLOWFISH_BLOCKSIZE],
134  const unsigned char *input,
135  unsigned char *output );
136 #endif /* POLARSSL_CIPHER_MODE_CBC */
137 
138 #if defined(POLARSSL_CIPHER_MODE_CFB)
139 
153  int mode,
154  size_t length,
155  size_t *iv_off,
156  unsigned char iv[BLOWFISH_BLOCKSIZE],
157  const unsigned char *input,
158  unsigned char *output );
159 #endif /*POLARSSL_CIPHER_MODE_CFB */
160 
161 #if defined(POLARSSL_CIPHER_MODE_CTR)
162 
181  size_t length,
182  size_t *nc_off,
183  unsigned char nonce_counter[BLOWFISH_BLOCKSIZE],
184  unsigned char stream_block[BLOWFISH_BLOCKSIZE],
185  const unsigned char *input,
186  unsigned char *output );
187 #endif /* POLARSSL_CIPHER_MODE_CTR */
188 
189 #ifdef __cplusplus
190 }
191 #endif
192 
193 #else /* POLARSSL_BLOWFISH_ALT */
194 #include "blowfish_alt.h"
195 #endif /* POLARSSL_BLOWFISH_ALT */
196 
197 #endif /* blowfish.h */