mbed TLS v2.16.1
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: GPL-2.0
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  *
24  * This file is part of mbed TLS (https://tls.mbed.org)
25  */
26 #ifndef MBEDTLS_BLOWFISH_H
27 #define MBEDTLS_BLOWFISH_H
28 
29 #if !defined(MBEDTLS_CONFIG_FILE)
30 #include "config.h"
31 #else
32 #include MBEDTLS_CONFIG_FILE
33 #endif
34 
35 #include <stddef.h>
36 #include <stdint.h>
37 
38 #include "platform_util.h"
39 
40 #define MBEDTLS_BLOWFISH_ENCRYPT 1
41 #define MBEDTLS_BLOWFISH_DECRYPT 0
42 #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
43 #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
44 #define MBEDTLS_BLOWFISH_ROUNDS 16
45 #define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
46 
47 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
48 #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0016 )
49 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
50 #define MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA -0x0016
52 #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
54 /* MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED is deprecated and should not be used.
55  */
56 #define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 #if !defined(MBEDTLS_BLOWFISH_ALT)
63 // Regular implementation
64 //
65 
70 {
71  uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2];
72  uint32_t S[4][256];
73 }
75 
76 #else /* MBEDTLS_BLOWFISH_ALT */
77 #include "blowfish_alt.h"
78 #endif /* MBEDTLS_BLOWFISH_ALT */
79 
87 
97 
110 int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
111  unsigned int keybits );
112 
130  int mode,
131  const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
132  unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
133 
134 #if defined(MBEDTLS_CIPHER_MODE_CBC)
135 
164  int mode,
165  size_t length,
166  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
167  const unsigned char *input,
168  unsigned char *output );
169 #endif /* MBEDTLS_CIPHER_MODE_CBC */
170 
171 #if defined(MBEDTLS_CIPHER_MODE_CFB)
172 
204  int mode,
205  size_t length,
206  size_t *iv_off,
207  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
208  const unsigned char *input,
209  unsigned char *output );
210 #endif /*MBEDTLS_CIPHER_MODE_CFB */
211 
212 #if defined(MBEDTLS_CIPHER_MODE_CTR)
213 
277  size_t length,
278  size_t *nc_off,
279  unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
280  unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
281  const unsigned char *input,
282  unsigned char *output );
283 #endif /* MBEDTLS_CIPHER_MODE_CTR */
284 
285 #ifdef __cplusplus
286 }
287 #endif
288 
289 #endif /* blowfish.h */
#define MBEDTLS_BLOWFISH_BLOCKSIZE
Definition: blowfish.h:45
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:69
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:72
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:44
uint32_t P[MBEDTLS_BLOWFISH_ROUNDS+2]
Definition: blowfish.h:71
void mbedtls_blowfish_free(mbedtls_blowfish_context *ctx)
Clear a Blowfish context.