PolarSSL v1.3.9
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 */
int blowfish_setkey(blowfish_context *ctx, const unsigned char *key, unsigned int keysize)
Blowfish key schedule.
void blowfish_init(blowfish_context *ctx)
Initialize Blowfish context.
Configuration options (set of defines)
void blowfish_free(blowfish_context *ctx)
Clear Blowfish context.
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
Rounds to use.
Definition: blowfish.h:49
#define BLOWFISH_BLOCKSIZE
Definition: blowfish.h:50
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:66
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) ...