text
[RRG-proxmark3.git] / common / mbedtls / cipher_internal.h
blobdc8f4f244f85335193d26db7bef38844fb97a24d
1 /**
2 * \file cipher_internal.h
4 * \brief Cipher wrappers.
6 * \author Adriaan de Jong <dejong@fox-it.com>
7 */
8 /*
9 * Copyright The Mbed TLS Contributors
10 * SPDX-License-Identifier: Apache-2.0
12 * Licensed under the Apache License, Version 2.0 (the "License"); you may
13 * not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
16 * http://www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 #ifndef MBEDTLS_CIPHER_WRAP_H
25 #define MBEDTLS_CIPHER_WRAP_H
27 #if !defined(MBEDTLS_CONFIG_FILE)
28 #include "mbedtls/config.h"
29 #else
30 #include MBEDTLS_CONFIG_FILE
31 #endif
33 #include "mbedtls/cipher.h"
35 #if defined(MBEDTLS_USE_PSA_CRYPTO)
36 #include "psa/crypto.h"
37 #endif /* MBEDTLS_USE_PSA_CRYPTO */
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
43 /**
44 * Base cipher information. The non-mode specific functions and values.
46 struct mbedtls_cipher_base_t {
47 /** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */
48 mbedtls_cipher_id_t cipher;
50 /** Encrypt using ECB */
51 int (*ecb_func)(void *ctx, mbedtls_operation_t mode,
52 const unsigned char *input, unsigned char *output);
54 #if defined(MBEDTLS_CIPHER_MODE_CBC)
55 /** Encrypt using CBC */
56 int (*cbc_func)(void *ctx, mbedtls_operation_t mode, size_t length,
57 unsigned char *iv, const unsigned char *input,
58 unsigned char *output);
59 #endif
61 #if defined(MBEDTLS_CIPHER_MODE_CFB)
62 /** Encrypt using CFB (Full length) */
63 int (*cfb_func)(void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off,
64 unsigned char *iv, const unsigned char *input,
65 unsigned char *output);
66 #endif
68 #if defined(MBEDTLS_CIPHER_MODE_OFB)
69 /** Encrypt using OFB (Full length) */
70 int (*ofb_func)(void *ctx, size_t length, size_t *iv_off,
71 unsigned char *iv,
72 const unsigned char *input,
73 unsigned char *output);
74 #endif
76 #if defined(MBEDTLS_CIPHER_MODE_CTR)
77 /** Encrypt using CTR */
78 int (*ctr_func)(void *ctx, size_t length, size_t *nc_off,
79 unsigned char *nonce_counter, unsigned char *stream_block,
80 const unsigned char *input, unsigned char *output);
81 #endif
83 #if defined(MBEDTLS_CIPHER_MODE_XTS)
84 /** Encrypt or decrypt using XTS. */
85 int (*xts_func)(void *ctx, mbedtls_operation_t mode, size_t length,
86 const unsigned char data_unit[16],
87 const unsigned char *input, unsigned char *output);
88 #endif
90 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
91 /** Encrypt using STREAM */
92 int (*stream_func)(void *ctx, size_t length,
93 const unsigned char *input, unsigned char *output);
94 #endif
96 /** Set key for encryption purposes */
97 int (*setkey_enc_func)(void *ctx, const unsigned char *key,
98 unsigned int key_bitlen);
100 /** Set key for decryption purposes */
101 int (*setkey_dec_func)(void *ctx, const unsigned char *key,
102 unsigned int key_bitlen);
104 /** Allocate a new context */
105 void *(*ctx_alloc_func)(void);
107 /** Free the given context */
108 void (*ctx_free_func)(void *ctx);
112 typedef struct {
113 mbedtls_cipher_type_t type;
114 const mbedtls_cipher_info_t *info;
115 } mbedtls_cipher_definition_t;
117 #if defined(MBEDTLS_USE_PSA_CRYPTO)
118 typedef enum {
119 MBEDTLS_CIPHER_PSA_KEY_UNSET = 0,
120 MBEDTLS_CIPHER_PSA_KEY_OWNED, /* Used for PSA-based cipher contexts which */
121 /* use raw key material internally imported */
122 /* as a volatile key, and which hence need */
123 /* to destroy that key when the context is */
124 /* freed. */
125 MBEDTLS_CIPHER_PSA_KEY_NOT_OWNED, /* Used for PSA-based cipher contexts */
126 /* which use a key provided by the */
127 /* user, and which hence will not be */
128 /* destroyed when the context is freed. */
129 } mbedtls_cipher_psa_key_ownership;
131 typedef struct {
132 psa_algorithm_t alg;
133 psa_key_id_t slot;
134 mbedtls_cipher_psa_key_ownership slot_state;
135 } mbedtls_cipher_context_psa;
136 #endif /* MBEDTLS_USE_PSA_CRYPTO */
138 extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
140 extern int mbedtls_cipher_supported[];
142 #ifdef __cplusplus
144 #endif
146 #endif /* MBEDTLS_CIPHER_WRAP_H */