mbed TLS v2.7.16
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 #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 #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016
71 #define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
72 #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
74 #if !defined(MBEDTLS_BLOWFISH_ALT)
75 // Regular implementation
76 //
77 
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81 
85 typedef struct
86 {
87  uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2];
88  uint32_t S[4][256];
89 }
91 
98 
105 
115 int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
116  unsigned int keybits );
117 
129  int mode,
130  const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
131  unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
132 
133 #if defined(MBEDTLS_CIPHER_MODE_CBC)
134 
158  int mode,
159  size_t length,
160  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
161  const unsigned char *input,
162  unsigned char *output );
163 #endif /* MBEDTLS_CIPHER_MODE_CBC */
164 
165 #if defined(MBEDTLS_CIPHER_MODE_CFB)
166 
188  int mode,
189  size_t length,
190  size_t *iv_off,
191  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
192  const unsigned char *input,
193  unsigned char *output );
194 #endif /*MBEDTLS_CIPHER_MODE_CFB */
195 
196 #if defined(MBEDTLS_CIPHER_MODE_CTR)
197 
216  size_t length,
217  size_t *nc_off,
218  unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
219  unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
220  const unsigned char *input,
221  unsigned char *output );
222 #endif /* MBEDTLS_CIPHER_MODE_CTR */
223 
224 #ifdef __cplusplus
225 }
226 #endif
227 
228 #else /* MBEDTLS_BLOWFISH_ALT */
229 #include "blowfish_alt.h"
230 #endif /* MBEDTLS_BLOWFISH_ALT */
231 
232 #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)
Blowfish-CTR buffer encryption/decryption.
Configuration options (set of defines)
Blowfish context structure.
Definition: blowfish.h:85
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:67
void mbedtls_blowfish_free(mbedtls_blowfish_context *ctx)
Clear Blowfish context.