mbed TLS v2.16.7
blowfish.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
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  * This file is part of mbed TLS (https://tls.mbed.org)
50  */
51 #ifndef MBEDTLS_BLOWFISH_H
52 #define MBEDTLS_BLOWFISH_H
53 
54 #if !defined(MBEDTLS_CONFIG_FILE)
55 #include "config.h"
56 #else
57 #include MBEDTLS_CONFIG_FILE
58 #endif
59 
60 #include <stddef.h>
61 #include <stdint.h>
62 
63 #include "platform_util.h"
64 
65 #define MBEDTLS_BLOWFISH_ENCRYPT 1
66 #define MBEDTLS_BLOWFISH_DECRYPT 0
67 #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
68 #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
69 #define MBEDTLS_BLOWFISH_ROUNDS 16
70 #define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
71 
72 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
73 #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0016 )
74 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
75 #define MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA -0x0016
77 #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
79 /* MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED is deprecated and should not be used.
80  */
81 #define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86 
87 #if !defined(MBEDTLS_BLOWFISH_ALT)
88 // Regular implementation
89 //
90 
95 {
96  uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2];
97  uint32_t S[4][256];
98 }
100 
101 #else /* MBEDTLS_BLOWFISH_ALT */
102 #include "blowfish_alt.h"
103 #endif /* MBEDTLS_BLOWFISH_ALT */
104 
112 
122 
135 int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
136  unsigned int keybits );
137 
155  int mode,
156  const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
157  unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
158 
159 #if defined(MBEDTLS_CIPHER_MODE_CBC)
160 
189  int mode,
190  size_t length,
191  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
192  const unsigned char *input,
193  unsigned char *output );
194 #endif /* MBEDTLS_CIPHER_MODE_CBC */
195 
196 #if defined(MBEDTLS_CIPHER_MODE_CFB)
197 
229  int mode,
230  size_t length,
231  size_t *iv_off,
232  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
233  const unsigned char *input,
234  unsigned char *output );
235 #endif /*MBEDTLS_CIPHER_MODE_CFB */
236 
237 #if defined(MBEDTLS_CIPHER_MODE_CTR)
238 
302  size_t length,
303  size_t *nc_off,
304  unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
305  unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
306  const unsigned char *input,
307  unsigned char *output );
308 #endif /* MBEDTLS_CIPHER_MODE_CTR */
309 
310 #ifdef __cplusplus
311 }
312 #endif
313 
314 #endif /* blowfish.h */
mbedtls_blowfish_context
struct mbedtls_blowfish_context mbedtls_blowfish_context
Blowfish context structure.
mbedtls_blowfish_setkey
int mbedtls_blowfish_setkey(mbedtls_blowfish_context *ctx, const unsigned char *key, unsigned int keybits)
Perform a Blowfish key schedule operation.
mbedtls_blowfish_crypt_cbc
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.
mbedtls_blowfish_context
Blowfish context structure.
Definition: blowfish.h:95
MBEDTLS_BLOWFISH_ROUNDS
#define MBEDTLS_BLOWFISH_ROUNDS
Definition: blowfish.h:69
MBEDTLS_BLOWFISH_BLOCKSIZE
#define MBEDTLS_BLOWFISH_BLOCKSIZE
Definition: blowfish.h:70
mbedtls_blowfish_context::S
uint32_t S[4][256]
Definition: blowfish.h:97
mbedtls_blowfish_context::P
uint32_t P[MBEDTLS_BLOWFISH_ROUNDS+2]
Definition: blowfish.h:96
mbedtls_blowfish_free
void mbedtls_blowfish_free(mbedtls_blowfish_context *ctx)
Clear a Blowfish context.
mbedtls_blowfish_crypt_cfb64
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.
config.h
Configuration options (set of defines)
platform_util.h
Common and shared functions used by multiple modules in the Mbed TLS library.
mbedtls_blowfish_crypt_ecb
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.
mbedtls_blowfish_init
void mbedtls_blowfish_init(mbedtls_blowfish_context *ctx)
Initialize a Blowfish context.
mbedtls_blowfish_crypt_ctr
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.