mbed TLS v2.13.0
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
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License"); you may
11  * not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  * This file is part of mbed TLS (https://tls.mbed.org)
23  */
24 #ifndef MBEDTLS_BLOWFISH_H
25 #define MBEDTLS_BLOWFISH_H
26 
27 #if !defined(MBEDTLS_CONFIG_FILE)
28 #include "config.h"
29 #else
30 #include MBEDTLS_CONFIG_FILE
31 #endif
32 
33 #include <stddef.h>
34 #include <stdint.h>
35 
36 #define MBEDTLS_BLOWFISH_ENCRYPT 1
37 #define MBEDTLS_BLOWFISH_DECRYPT 0
38 #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
39 #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
40 #define MBEDTLS_BLOWFISH_ROUNDS 16
41 #define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
42 
43 #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016
44 #define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
45 #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 #if !defined(MBEDTLS_BLOWFISH_ALT)
52 // Regular implementation
53 //
54 
59 {
60  uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2];
61  uint32_t S[4][256];
62 }
64 
65 #else /* MBEDTLS_BLOWFISH_ALT */
66 #include "blowfish_alt.h"
67 #endif /* MBEDTLS_BLOWFISH_ALT */
68 
75 
82 
92 int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
93  unsigned int keybits );
94 
106  int mode,
107  const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
108  unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
109 
110 #if defined(MBEDTLS_CIPHER_MODE_CBC)
111 
135  int mode,
136  size_t length,
137  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
138  const unsigned char *input,
139  unsigned char *output );
140 #endif /* MBEDTLS_CIPHER_MODE_CBC */
141 
142 #if defined(MBEDTLS_CIPHER_MODE_CFB)
143 
165  int mode,
166  size_t length,
167  size_t *iv_off,
168  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
169  const unsigned char *input,
170  unsigned char *output );
171 #endif /*MBEDTLS_CIPHER_MODE_CFB */
172 
173 #if defined(MBEDTLS_CIPHER_MODE_CTR)
174 
232  size_t length,
233  size_t *nc_off,
234  unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
235  unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
236  const unsigned char *input,
237  unsigned char *output );
238 #endif /* MBEDTLS_CIPHER_MODE_CTR */
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 
244 #endif /* blowfish.h */
#define MBEDTLS_BLOWFISH_BLOCKSIZE
Definition: blowfish.h:41
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)
struct mbedtls_blowfish_context mbedtls_blowfish_context
Blowfish context structure.
Blowfish context structure.
Definition: blowfish.h:58
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.
uint32_t S[4][256]
Definition: blowfish.h:61
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:40
uint32_t P[MBEDTLS_BLOWFISH_ROUNDS+2]
Definition: blowfish.h:60
void mbedtls_blowfish_free(mbedtls_blowfish_context *ctx)
Clear Blowfish context.