PolarSSL v1.3.7
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 
82 int blowfish_setkey( blowfish_context *ctx, const unsigned char *key,
83  unsigned int keysize );
84 
96  int mode,
97  const unsigned char input[BLOWFISH_BLOCKSIZE],
98  unsigned char output[BLOWFISH_BLOCKSIZE] );
99 
100 #if defined(POLARSSL_CIPHER_MODE_CBC)
101 
117  int mode,
118  size_t length,
119  unsigned char iv[BLOWFISH_BLOCKSIZE],
120  const unsigned char *input,
121  unsigned char *output );
122 #endif /* POLARSSL_CIPHER_MODE_CBC */
123 
124 #if defined(POLARSSL_CIPHER_MODE_CFB)
125 
139  int mode,
140  size_t length,
141  size_t *iv_off,
142  unsigned char iv[BLOWFISH_BLOCKSIZE],
143  const unsigned char *input,
144  unsigned char *output );
145 #endif /*POLARSSL_CIPHER_MODE_CFB */
146 
147 #if defined(POLARSSL_CIPHER_MODE_CTR)
148 
167  size_t length,
168  size_t *nc_off,
169  unsigned char nonce_counter[BLOWFISH_BLOCKSIZE],
170  unsigned char stream_block[BLOWFISH_BLOCKSIZE],
171  const unsigned char *input,
172  unsigned char *output );
173 #endif /* POLARSSL_CIPHER_MODE_CTR */
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 #else /* POLARSSL_BLOWFISH_ALT */
180 #include "blowfish_alt.h"
181 #endif /* POLARSSL_BLOWFISH_ALT */
182 
183 #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
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) ...