mbed TLS v2.16.12
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  * This file is provided under the Apache License 2.0, or the
11  * GNU General Public License v2.0 or later.
12  *
13  * **********
14  * Apache License 2.0:
15  *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may
17  * not use this file except in compliance with the License.
18  * You may obtain a copy of the License at
19  *
20  * http://www.apache.org/licenses/LICENSE-2.0
21  *
22  * Unless required by applicable law or agreed to in writing, software
23  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25  * See the License for the specific language governing permissions and
26  * limitations under the License.
27  *
28  * **********
29  *
30  * **********
31  * GNU General Public License v2.0 or later:
32  *
33  * This program is free software; you can redistribute it and/or modify
34  * it under the terms of the GNU General Public License as published by
35  * the Free Software Foundation; either version 2 of the License, or
36  * (at your option) any later version.
37  *
38  * This program is distributed in the hope that it will be useful,
39  * but WITHOUT ANY WARRANTY; without even the implied warranty of
40  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41  * GNU General Public License for more details.
42  *
43  * You should have received a copy of the GNU General Public License along
44  * with this program; if not, write to the Free Software Foundation, Inc.,
45  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
46  *
47  * **********
48  */
49 #ifndef MBEDTLS_BLOWFISH_H
50 #define MBEDTLS_BLOWFISH_H
51 
52 #if !defined(MBEDTLS_CONFIG_FILE)
53 #include "config.h"
54 #else
55 #include MBEDTLS_CONFIG_FILE
56 #endif
57 
58 #include <stddef.h>
59 #include <stdint.h>
60 
61 #include "platform_util.h"
62 
63 #define MBEDTLS_BLOWFISH_ENCRYPT 1
64 #define MBEDTLS_BLOWFISH_DECRYPT 0
65 #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
66 #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
67 #define MBEDTLS_BLOWFISH_ROUNDS 16
68 #define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
69 
70 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
71 #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0016 )
72 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
73 
74 #define MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA -0x0016
75 
77 #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
78 
79 /* MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED is deprecated and should not be used.
80  */
82 #define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
83 
84 #ifdef __cplusplus
85 extern "C" {
86 #endif
87 
88 #if !defined(MBEDTLS_BLOWFISH_ALT)
89 // Regular implementation
90 //
91 
96 {
97  uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2];
98  uint32_t S[4][256];
99 }
101 
102 #else /* MBEDTLS_BLOWFISH_ALT */
103 #include "blowfish_alt.h"
104 #endif /* MBEDTLS_BLOWFISH_ALT */
105 
113 
123 
136 int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
137  unsigned int keybits );
138 
156  int mode,
157  const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
158  unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
159 
160 #if defined(MBEDTLS_CIPHER_MODE_CBC)
161 
190  int mode,
191  size_t length,
192  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
193  const unsigned char *input,
194  unsigned char *output );
195 #endif /* MBEDTLS_CIPHER_MODE_CBC */
196 
197 #if defined(MBEDTLS_CIPHER_MODE_CFB)
198 
230  int mode,
231  size_t length,
232  size_t *iv_off,
233  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
234  const unsigned char *input,
235  unsigned char *output );
236 #endif /*MBEDTLS_CIPHER_MODE_CFB */
237 
238 #if defined(MBEDTLS_CIPHER_MODE_CTR)
239 
303  size_t length,
304  size_t *nc_off,
305  unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
306  unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
307  const unsigned char *input,
308  unsigned char *output );
309 #endif /* MBEDTLS_CIPHER_MODE_CTR */
310 
311 #ifdef __cplusplus
312 }
313 #endif
314 
315 #endif /* blowfish.h */
#define MBEDTLS_BLOWFISH_BLOCKSIZE
Definition: blowfish.h:68
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:95
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:98
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:67
uint32_t P[MBEDTLS_BLOWFISH_ROUNDS+2]
Definition: blowfish.h:97
void mbedtls_blowfish_free(mbedtls_blowfish_context *ctx)
Clear a Blowfish context.