OPTIGA Trust M  1.1.0
C++ library for Optiga Trust M Chip Security Controller
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 #include "platform_util.h"
37 
38 #define MBEDTLS_BLOWFISH_ENCRYPT 1
39 #define MBEDTLS_BLOWFISH_DECRYPT 0
40 #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448
41 #define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32
42 #define MBEDTLS_BLOWFISH_ROUNDS 16
43 #define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */
44 
45 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
46 #define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0016 )
47 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
48 #define MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA -0x0016
50 #define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018
52 /* MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED is deprecated and should not be used.
53  */
54 #define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 #if !defined(MBEDTLS_BLOWFISH_ALT)
61 // Regular implementation
62 //
63 
68 {
69  uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2];
70  uint32_t S[4][256];
71 }
73 
74 #else /* MBEDTLS_BLOWFISH_ALT */
75 #include "blowfish_alt.h"
76 #endif /* MBEDTLS_BLOWFISH_ALT */
77 
85 
95 
108 int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key,
109  unsigned int keybits );
110 
128  int mode,
129  const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE],
130  unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE] );
131 
132 #if defined(MBEDTLS_CIPHER_MODE_CBC)
133 
161 int mbedtls_blowfish_crypt_cbc( mbedtls_blowfish_context *ctx,
162  int mode,
163  size_t length,
164  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
165  const unsigned char *input,
166  unsigned char *output );
167 #endif /* MBEDTLS_CIPHER_MODE_CBC */
168 
169 #if defined(MBEDTLS_CIPHER_MODE_CFB)
170 
201 int mbedtls_blowfish_crypt_cfb64( mbedtls_blowfish_context *ctx,
202  int mode,
203  size_t length,
204  size_t *iv_off,
205  unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE],
206  const unsigned char *input,
207  unsigned char *output );
208 #endif /*MBEDTLS_CIPHER_MODE_CFB */
209 
210 #if defined(MBEDTLS_CIPHER_MODE_CTR)
211 
274 int mbedtls_blowfish_crypt_ctr( mbedtls_blowfish_context *ctx,
275  size_t length,
276  size_t *nc_off,
277  unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE],
278  unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],
279  const unsigned char *input,
280  unsigned char *output );
281 #endif /* MBEDTLS_CIPHER_MODE_CTR */
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 
287 #endif /* blowfish.h */
#define MBEDTLS_BLOWFISH_BLOCKSIZE
Definition: blowfish.h:43
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:67
void mbedtls_blowfish_init(mbedtls_blowfish_context *ctx)
Initialize a Blowfish context.
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:70
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:42
uint32_t P[MBEDTLS_BLOWFISH_ROUNDS+2]
Definition: blowfish.h:69
void mbedtls_blowfish_free(mbedtls_blowfish_context *ctx)
Clear a Blowfish context.