Mbed TLS v2.28.7
blowfish.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright The Mbed TLS Contributors
8  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9  */
10 #ifndef MBEDTLS_BLOWFISH_H
11 #define MBEDTLS_BLOWFISH_H
12 
13 #if !defined(MBEDTLS_CONFIG_FILE)
14 #include "mbedtls/config.h"
15 #else
16 #include MBEDTLS_CONFIG_FILE
17 #endif
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 #include "mbedtls/platform_util.h"
23 
24 #define MBEDTLS_BLOWFISH_ENCRYPT 1
25 #define MBEDTLS_BLOWFISH_DECRYPT 0
26 #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
27 #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
28 #define MBEDTLS_BLOWFISH_ROUNDS 16
29 #define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
30 
31 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
32 #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT(-0x0016)
33 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
35 #define MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA -0x0016
36 
38 #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
39 
40 /* MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED is deprecated and should not be used.
41  */
43 #define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #if !defined(MBEDTLS_BLOWFISH_ALT)
50 // Regular implementation
51 //
52 
56 typedef struct mbedtls_blowfish_context {
57  uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2];
58  uint32_t S[4][256];
59 }
61 
62 #else /* MBEDTLS_BLOWFISH_ALT */
63 #include "blowfish_alt.h"
64 #endif /* MBEDTLS_BLOWFISH_ALT */
65 
73 
83 
96 int mbedtls_blowfish_setkey(mbedtls_blowfish_context *ctx, const unsigned char *key,
97  unsigned int keybits);
98 
116  int mode,
117  const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
118  unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE]);
119 
120 #if defined(MBEDTLS_CIPHER_MODE_CBC)
150  int mode,
151  size_t length,
152  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
153  const unsigned char *input,
154  unsigned char *output);
155 #endif /* MBEDTLS_CIPHER_MODE_CBC */
156 
157 #if defined(MBEDTLS_CIPHER_MODE_CFB)
190  int mode,
191  size_t length,
192  size_t *iv_off,
193  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
194  const unsigned char *input,
195  unsigned char *output);
196 #endif /*MBEDTLS_CIPHER_MODE_CFB */
197 
198 #if defined(MBEDTLS_CIPHER_MODE_CTR)
263  size_t length,
264  size_t *nc_off,
265  unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
266  unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
267  const unsigned char *input,
268  unsigned char *output);
269 #endif /* MBEDTLS_CIPHER_MODE_CTR */
270 
271 #ifdef __cplusplus
272 }
273 #endif
274 
275 #endif /* blowfish.h */
int mbedtls_blowfish_crypt_cbc(mbedtls_blowfish_context *ctx, int mode, size_t length, unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Perform a Blowfish-CBC buffer encryption/decryption operation.
int mbedtls_blowfish_setkey(mbedtls_blowfish_context *ctx, const unsigned char *key, unsigned int keybits)
Perform a Blowfish key schedule operation.
int mbedtls_blowfish_crypt_ctr(mbedtls_blowfish_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE], unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Perform a Blowfish-CTR buffer encryption/decryption operation.
#define MBEDTLS_BLOWFISH_ROUNDS
Definition: blowfish.h:28
void mbedtls_blowfish_init(mbedtls_blowfish_context *ctx)
Initialize a Blowfish context.
void mbedtls_blowfish_free(mbedtls_blowfish_context *ctx)
Clear a Blowfish context.
#define MBEDTLS_BLOWFISH_BLOCKSIZE
Definition: blowfish.h:29
int mbedtls_blowfish_crypt_cfb64(mbedtls_blowfish_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Perform a Blowfish CFB buffer encryption/decryption operation.
struct mbedtls_blowfish_context mbedtls_blowfish_context
Blowfish context structure.
int mbedtls_blowfish_crypt_ecb(mbedtls_blowfish_context *ctx, int mode, const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE], unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE])
Perform a Blowfish-ECB block encryption/decryption operation.
Configuration options (set of defines)
Common and shared functions used by multiple modules in the Mbed TLS library.
Blowfish context structure.
Definition: blowfish.h:56
uint32_t P[MBEDTLS_BLOWFISH_ROUNDS+2]
Definition: blowfish.h:57
uint32_t S[4][256]
Definition: blowfish.h:58