mbed TLS v2.7.17
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 #define MBEDTLS_BLOWFISH_ENCRYPT 1
62 #define MBEDTLS_BLOWFISH_DECRYPT 0
63 #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
64 #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
65 #define MBEDTLS_BLOWFISH_ROUNDS 16
66 #define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
67 
68 #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016
69 #define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
70 #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
72 #if !defined(MBEDTLS_BLOWFISH_ALT)
73 // Regular implementation
74 //
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79 
83 typedef struct
84 {
85  uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2];
86  uint32_t S[4][256];
87 }
89 
96 
103 
113 int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
114  unsigned int keybits );
115 
127  int mode,
128  const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
129  unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
130 
131 #if defined(MBEDTLS_CIPHER_MODE_CBC)
132 
156  int mode,
157  size_t length,
158  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
159  const unsigned char *input,
160  unsigned char *output );
161 #endif /* MBEDTLS_CIPHER_MODE_CBC */
162 
163 #if defined(MBEDTLS_CIPHER_MODE_CFB)
164 
186  int mode,
187  size_t length,
188  size_t *iv_off,
189  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
190  const unsigned char *input,
191  unsigned char *output );
192 #endif /*MBEDTLS_CIPHER_MODE_CFB */
193 
194 #if defined(MBEDTLS_CIPHER_MODE_CTR)
195 
214  size_t length,
215  size_t *nc_off,
216  unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
217  unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
218  const unsigned char *input,
219  unsigned char *output );
220 #endif /* MBEDTLS_CIPHER_MODE_CTR */
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #else /* MBEDTLS_BLOWFISH_ALT */
227 #include "blowfish_alt.h"
228 #endif /* MBEDTLS_BLOWFISH_ALT */
229 
230 #endif /* blowfish.h */
#define MBEDTLS_BLOWFISH_BLOCKSIZE
Definition: blowfish.h:66
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)
Blowfish-CTR buffer encryption/decryption.
Configuration options (set of defines)
Blowfish context structure.
Definition: blowfish.h:83
void mbedtls_blowfish_init(mbedtls_blowfish_context *ctx)
Initialize 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)
Blowfish CFB buffer encryption/decryption.
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)
Blowfish-CBC buffer encryption/decryption Length should be a multiple of the block size (8 bytes) ...
int mbedtls_blowfish_crypt_ecb(mbedtls_blowfish_context *ctx, int mode, const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE], unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE])
Blowfish-ECB block encryption/decryption.
int mbedtls_blowfish_setkey(mbedtls_blowfish_context *ctx, const unsigned char *key, unsigned int keybits)
Blowfish key schedule.
#define MBEDTLS_BLOWFISH_ROUNDS
Definition: blowfish.h:65
void mbedtls_blowfish_free(mbedtls_blowfish_context *ctx)
Clear Blowfish context.