2 * \file cipher_internal.h
4 * \brief Cipher wrappers.
6 * \author Adriaan de Jong <dejong@fox-it.com>
9 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
10 * SPDX-License-Identifier: GPL-2.0
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * This file is part of mbed TLS (https://tls.mbed.org)
28 #ifndef MBEDTLS_CIPHER_WRAP_H
29 #define MBEDTLS_CIPHER_WRAP_H
31 #if !defined(MBEDTLS_CONFIG_FILE)
34 #include MBEDTLS_CONFIG_FILE
44 * Base cipher information. The non-mode specific functions and values.
46 struct mbedtls_cipher_base_t
48 /** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */
49 mbedtls_cipher_id_t cipher
;
51 /** Encrypt using ECB */
52 int (*ecb_func
)( void *ctx
, mbedtls_operation_t mode
,
53 const unsigned char *input
, unsigned char *output
);
55 #if defined(MBEDTLS_CIPHER_MODE_CBC)
56 /** Encrypt using CBC */
57 int (*cbc_func
)( void *ctx
, mbedtls_operation_t mode
, size_t length
,
58 unsigned char *iv
, const unsigned char *input
,
59 unsigned char *output
);
62 #if defined(MBEDTLS_CIPHER_MODE_CFB)
63 /** Encrypt using CFB (Full length) */
64 int (*cfb_func
)( void *ctx
, mbedtls_operation_t mode
, size_t length
, size_t *iv_off
,
65 unsigned char *iv
, const unsigned char *input
,
66 unsigned char *output
);
69 #if defined(MBEDTLS_CIPHER_MODE_OFB)
70 /** Encrypt using OFB (Full length) */
71 int (*ofb_func
)( void *ctx
, size_t length
, size_t *iv_off
,
73 const unsigned char *input
,
74 unsigned char *output
);
77 #if defined(MBEDTLS_CIPHER_MODE_CTR)
78 /** Encrypt using CTR */
79 int (*ctr_func
)( void *ctx
, size_t length
, size_t *nc_off
,
80 unsigned char *nonce_counter
, unsigned char *stream_block
,
81 const unsigned char *input
, unsigned char *output
);
84 #if defined(MBEDTLS_CIPHER_MODE_XTS)
85 /** Encrypt or decrypt using XTS. */
86 int (*xts_func
)( void *ctx
, mbedtls_operation_t mode
, size_t length
,
87 const unsigned char data_unit
[16],
88 const unsigned char *input
, unsigned char *output
);
91 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
92 /** Encrypt using STREAM */
93 int (*stream_func
)( void *ctx
, size_t length
,
94 const unsigned char *input
, unsigned char *output
);
97 /** Set key for encryption purposes */
98 int (*setkey_enc_func
)( void *ctx
, const unsigned char *key
,
99 unsigned int key_bitlen
);
101 /** Set key for decryption purposes */
102 int (*setkey_dec_func
)( void *ctx
, const unsigned char *key
,
103 unsigned int key_bitlen
);
105 /** Allocate a new context */
106 void * (*ctx_alloc_func
)( void );
108 /** Free the given context */
109 void (*ctx_free_func
)( void *ctx
);
115 mbedtls_cipher_type_t type
;
116 const mbedtls_cipher_info_t
*info
;
117 } mbedtls_cipher_definition_t
;
119 extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions
[];
121 extern int mbedtls_cipher_supported
[];
127 #endif /* MBEDTLS_CIPHER_WRAP_H */