mbed TLS v1.3.19
blowfish.h
Go to the documentation of this file.
1 
24 #ifndef POLARSSL_BLOWFISH_H
25 #define POLARSSL_BLOWFISH_H
26 
27 #if !defined(POLARSSL_CONFIG_FILE)
28 #include "config.h"
29 #else
30 #include POLARSSL_CONFIG_FILE
31 #endif
32 
33 #include <stddef.h>
34 
35 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
36 #include <basetsd.h>
37 typedef UINT32 uint32_t;
38 #else
39 #include <inttypes.h>
40 #endif
41 
42 #define BLOWFISH_ENCRYPT 1
43 #define BLOWFISH_DECRYPT 0
44 #define BLOWFISH_MAX_KEY 448
45 #define BLOWFISH_MIN_KEY 32
46 #define BLOWFISH_ROUNDS 16
47 #define BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
48 
49 #define POLARSSL_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016
50 #define POLARSSL_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
52 #if !defined(POLARSSL_BLOWFISH_ALT)
53 // Regular implementation
54 //
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
63 typedef struct
64 {
65  uint32_t P[BLOWFISH_ROUNDS + 2];
66  uint32_t S[4][256];
67 }
69 
75 void blowfish_init( blowfish_context *ctx );
76 
82 void blowfish_free( blowfish_context *ctx );
83 
93 int blowfish_setkey( blowfish_context *ctx, const unsigned char *key,
94  unsigned int keysize );
95 
107  int mode,
108  const unsigned char input[BLOWFISH_BLOCKSIZE],
109  unsigned char output[BLOWFISH_BLOCKSIZE] );
110 
111 #if defined(POLARSSL_CIPHER_MODE_CBC)
112 
136  int mode,
137  size_t length,
138  unsigned char iv[BLOWFISH_BLOCKSIZE],
139  const unsigned char *input,
140  unsigned char *output );
141 #endif /* POLARSSL_CIPHER_MODE_CBC */
142 
143 #if defined(POLARSSL_CIPHER_MODE_CFB)
144 
166  int mode,
167  size_t length,
168  size_t *iv_off,
169  unsigned char iv[BLOWFISH_BLOCKSIZE],
170  const unsigned char *input,
171  unsigned char *output );
172 #endif /*POLARSSL_CIPHER_MODE_CFB */
173 
174 #if defined(POLARSSL_CIPHER_MODE_CTR)
175 
194  size_t length,
195  size_t *nc_off,
196  unsigned char nonce_counter[BLOWFISH_BLOCKSIZE],
197  unsigned char stream_block[BLOWFISH_BLOCKSIZE],
198  const unsigned char *input,
199  unsigned char *output );
200 #endif /* POLARSSL_CIPHER_MODE_CTR */
201 
202 #ifdef __cplusplus
203 }
204 #endif
205 
206 #else /* POLARSSL_BLOWFISH_ALT */
207 #include "blowfish_alt.h"
208 #endif /* POLARSSL_BLOWFISH_ALT */
209 
210 #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:46
#define BLOWFISH_BLOCKSIZE
Definition: blowfish.h:47
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:63
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) ...