mbed TLS v2.26.0
blowfish.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright The Mbed TLS Contributors
8  * SPDX-License-Identifier: Apache-2.0
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License"); you may
11  * not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 #ifndef MBEDTLS_BLOWFISH_H
23 #define MBEDTLS_BLOWFISH_H
24 
25 #if !defined(MBEDTLS_CONFIG_FILE)
26 #include "mbedtls/config.h"
27 #else
28 #include MBEDTLS_CONFIG_FILE
29 #endif
30 
31 #include <stddef.h>
32 #include <stdint.h>
33 
34 #include "mbedtls/platform_util.h"
35 
36 #define MBEDTLS_BLOWFISH_ENCRYPT 1
37 #define MBEDTLS_BLOWFISH_DECRYPT 0
38 #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
39 #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
40 #define MBEDTLS_BLOWFISH_ROUNDS 16
41 #define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
42 
43 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
44 #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0016 )
45 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
46 #define MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA -0x0016
48 #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
50 /* MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED is deprecated and should not be used.
51  */
52 #define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 #if !defined(MBEDTLS_BLOWFISH_ALT)
59 // Regular implementation
60 //
61 
66 {
67  uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2];
68  uint32_t S[4][256];
69 }
71 
72 #else /* MBEDTLS_BLOWFISH_ALT */
73 #include "blowfish_alt.h"
74 #endif /* MBEDTLS_BLOWFISH_ALT */
75 
83 
93 
106 int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
107  unsigned int keybits );
108 
126  int mode,
127  const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
128  unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
129 
130 #if defined(MBEDTLS_CIPHER_MODE_CBC)
131 
160  int mode,
161  size_t length,
162  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
163  const unsigned char *input,
164  unsigned char *output );
165 #endif /* MBEDTLS_CIPHER_MODE_CBC */
166 
167 #if defined(MBEDTLS_CIPHER_MODE_CFB)
168 
200  int mode,
201  size_t length,
202  size_t *iv_off,
203  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
204  const unsigned char *input,
205  unsigned char *output );
206 #endif /*MBEDTLS_CIPHER_MODE_CFB */
207 
208 #if defined(MBEDTLS_CIPHER_MODE_CTR)
209 
273  size_t length,
274  size_t *nc_off,
275  unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
276  unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
277  const unsigned char *input,
278  unsigned char *output );
279 #endif /* MBEDTLS_CIPHER_MODE_CTR */
280 
281 #ifdef __cplusplus
282 }
283 #endif
284 
285 #endif /* blowfish.h */
#define MBEDTLS_BLOWFISH_BLOCKSIZE
Definition: blowfish.h:41
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.
Configuration options (set of defines)
Common and shared functions used by multiple modules in the Mbed TLS library.
struct mbedtls_blowfish_context mbedtls_blowfish_context
Blowfish context structure.
Blowfish context structure.
Definition: blowfish.h:65
void mbedtls_blowfish_init(mbedtls_blowfish_context *ctx)
Initialize a Blowfish context.
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.
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_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.
uint32_t S[4][256]
Definition: blowfish.h:68
int mbedtls_blowfish_setkey(mbedtls_blowfish_context *ctx, const unsigned char *key, unsigned int keybits)
Perform a Blowfish key schedule operation.
#define MBEDTLS_BLOWFISH_ROUNDS
Definition: blowfish.h:40
uint32_t P[MBEDTLS_BLOWFISH_ROUNDS+2]
Definition: blowfish.h:67
void mbedtls_blowfish_free(mbedtls_blowfish_context *ctx)
Clear a Blowfish context.