1
1
/**
2
- * \file crypto_struct .h
2
+ * \file crypto_struct_impl .h
3
3
*
4
- * \brief PSA cryptography module: Mbed TLS structured type implementations
5
- *
6
- * \note This file may not be included directly. Applications must
7
- * include psa/crypto.h.
4
+ * \brief Mbed Crypto structured type implementations
8
5
*
9
6
* This file contains the definitions of some data structures with
10
7
* implementation-specific definitions.
11
8
*
12
- * In implementations with isolation between the application and the
13
- * cryptography module, it is expected that the front-end and the back-end
14
- * would have different versions of this file.
9
+ * The definitions in this file provide the implementation-specific detail of
10
+ * the structs defined in psa/crypto_struct.h for use by the library itself
11
+ * (not users of the library). The implementation-specific detail here is free
12
+ * to change between versions of the library, so long as the size of the
13
+ * structs never decreases (unless an ABI break is tolerable). The size of the
14
+ * structs in psa/crypto_struct.h must be at least as big as those in this file
15
+ * in order for users of the library to be able to allocate sufficient memory
16
+ * for these structs.
15
17
*/
16
18
/*
17
19
* Copyright (C) 2018, ARM Limited, All Rights Reserved
32
34
* This file is part of mbed TLS (https://tls.mbed.org)
33
35
*/
34
36
35
- #ifndef PSA_CRYPTO_STRUCT_H
36
- #define PSA_CRYPTO_STRUCT_H
37
+ #ifndef MC_CRYPTO_STRUCT_IMPL_H
38
+ #define MC_CRYPTO_STRUCT_IMPL_H
37
39
38
40
/* Include the Mbed TLS configuration file, the way Mbed TLS does it
39
41
* in each of its header files. */
43
45
#include MBEDTLS_CONFIG_FILE
44
46
#endif
45
47
48
+ #include "utils.h"
49
+
46
50
#include "mbedtls/cipher.h"
47
51
#include "mbedtls/cmac.h"
48
52
#include "mbedtls/gcm.h"
55
59
#include "mbedtls/sha256.h"
56
60
#include "mbedtls/sha512.h"
57
61
58
- struct psa_hash_operation_s
62
+ typedef struct psa_hash_operation_impl_s
59
63
{
60
64
psa_algorithm_t alg ;
61
65
union
@@ -83,7 +87,11 @@ struct psa_hash_operation_s
83
87
mbedtls_sha512_context sha512 ;
84
88
#endif
85
89
} ctx ;
86
- };
90
+ } psa_hash_operation_impl_t ;
91
+
92
+ STATIC_ASSERT (
93
+ sizeof (psa_hash_operation_t ) >= sizeof (psa_hash_operation_impl_t ),
94
+ psa_hash_operation_t_too_small );
87
95
88
96
#if defined(MBEDTLS_MD_C )
89
97
typedef struct
@@ -95,7 +103,7 @@ typedef struct
95
103
} psa_hmac_internal_data ;
96
104
#endif /* MBEDTLS_MD_C */
97
105
98
- struct psa_mac_operation_s
106
+ typedef struct psa_mac_operation_impl_s
99
107
{
100
108
psa_algorithm_t alg ;
101
109
unsigned int key_set : 1 ;
@@ -114,9 +122,13 @@ struct psa_mac_operation_s
114
122
mbedtls_cipher_context_t cmac ;
115
123
#endif
116
124
} ctx ;
117
- };
125
+ } psa_mac_operation_impl_t ;
118
126
119
- struct psa_cipher_operation_s
127
+ STATIC_ASSERT (
128
+ sizeof (psa_mac_operation_t ) >= sizeof (psa_mac_operation_impl_t ),
129
+ psa_mac_operation_t_too_small );
130
+
131
+ typedef struct psa_cipher_operation_impl_s
120
132
{
121
133
psa_algorithm_t alg ;
122
134
unsigned int key_set : 1 ;
@@ -128,7 +140,11 @@ struct psa_cipher_operation_s
128
140
{
129
141
mbedtls_cipher_context_t cipher ;
130
142
} ctx ;
131
- };
143
+ } psa_cipher_operation_impl_t ;
144
+
145
+ STATIC_ASSERT (
146
+ sizeof (psa_cipher_operation_t ) >= sizeof (psa_cipher_operation_impl_t ),
147
+ psa_cipher_operation_t_too_small );
132
148
133
149
#if defined(MBEDTLS_MD_C )
134
150
typedef struct
@@ -177,7 +193,7 @@ typedef struct psa_tls12_prf_generator_s
177
193
} psa_tls12_prf_generator_t ;
178
194
#endif /* MBEDTLS_MD_C */
179
195
180
- struct psa_crypto_generator_s
196
+ typedef struct psa_crypto_generator_impl_s
181
197
{
182
198
psa_algorithm_t alg ;
183
199
size_t capacity ;
@@ -193,19 +209,10 @@ struct psa_crypto_generator_s
193
209
psa_tls12_prf_generator_t tls12_prf ;
194
210
#endif
195
211
} ctx ;
196
- };
212
+ } psa_crypto_generator_impl_t ;
197
213
198
- #define PSA_CRYPTO_GENERATOR_INIT {0, 0, {{0, 0}}}
199
- static inline struct psa_crypto_generator_s psa_crypto_generator_init ( void )
200
- {
201
- const struct psa_crypto_generator_s v = PSA_CRYPTO_GENERATOR_INIT ;
202
- return ( v );
203
- }
204
-
205
- struct psa_key_policy_s
206
- {
207
- psa_key_usage_t usage ;
208
- psa_algorithm_t alg ;
209
- };
214
+ STATIC_ASSERT (
215
+ sizeof (psa_crypto_generator_t ) >= sizeof (psa_crypto_generator_impl_t ),
216
+ psa_crypto_generator_t_too_small );
210
217
211
- #endif /* PSA_CRYPTO_STRUCT_H */
218
+ #endif /* MC_CRYPTO_STRUCT_IMPL_H */
0 commit comments