NCBI C++ ToolKit
psa_crypto_driver_wrappers_no_static.c
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /*
2  * Functions to delegate cryptographic operations to an available
3  * and appropriate accelerator.
4  * Warning: This file is now auto-generated.
5  */
6 /* Copyright The Mbed TLS Contributors
7  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
8  */
9 
10 
11 /* BEGIN-common headers */
12 #include "common.h"
13 #include "psa_crypto_aead.h"
14 #include "psa_crypto_cipher.h"
15 #include "psa_crypto_core.h"
17 #include "psa_crypto_hash.h"
18 #include "psa_crypto_mac.h"
19 #include "psa_crypto_pake.h"
20 #include "psa_crypto_rsa.h"
21 
22 #include "mbedtls/platform.h"
23 /* END-common headers */
24 
25 #if defined(MBEDTLS_PSA_CRYPTO_C)
26 
27 /* BEGIN-driver headers */
28 /* Headers for mbedtls_test opaque driver */
29 #if defined(PSA_CRYPTO_DRIVER_TEST)
30 #include "test/drivers/test_driver.h"
31 
32 #endif
33 /* Headers for mbedtls_test transparent driver */
34 #if defined(PSA_CRYPTO_DRIVER_TEST)
35 #include "test/drivers/test_driver.h"
36 
37 #endif
38 /* Headers for p256 transparent driver */
39 #if defined(MBEDTLS_PSA_P256M_DRIVER_ENABLED)
40 #include "../3rdparty/p256-m/p256-m_driver_entrypoints.h"
41 
42 #endif
43 
44 /* END-driver headers */
45 
46 /* Auto-generated values depending on which drivers are registered.
47  * ID 0 is reserved for unallocated operations.
48  * ID 1 is reserved for the Mbed TLS software driver. */
49 /* BEGIN-driver id definition */
50 #define PSA_CRYPTO_MBED_TLS_DRIVER_ID (1)
51 #define MBEDTLS_TEST_OPAQUE_DRIVER_ID (2)
52 #define MBEDTLS_TEST_TRANSPARENT_DRIVER_ID (3)
53 #define P256_TRANSPARENT_DRIVER_ID (4)
54 
55 /* END-driver id */
56 
57 /* BEGIN-Common Macro definitions */
58 
59 /* END-Common Macro definitions */
60 
61 /* Support the 'old' SE interface when asked to */
62 #if defined(MBEDTLS_PSA_CRYPTO_SE_C)
63 /* PSA_CRYPTO_DRIVER_PRESENT is defined when either a new-style or old-style
64  * SE driver is present, to avoid unused argument errors at compile time. */
65 #ifndef PSA_CRYPTO_DRIVER_PRESENT
66 #define PSA_CRYPTO_DRIVER_PRESENT
67 #endif
68 #include "psa_crypto_se.h"
69 #endif
70 
71 /** Get the key buffer size required to store the key material of a key
72  * associated with an opaque driver.
73  *
74  * \param[in] attributes The key attributes.
75  * \param[out] key_buffer_size Minimum buffer size to contain the key material
76  *
77  * \retval #PSA_SUCCESS
78  * The minimum size for a buffer to contain the key material has been
79  * returned successfully.
80  * \retval #PSA_ERROR_NOT_SUPPORTED
81  * The type and/or the size in bits of the key or the combination of
82  * the two is not supported.
83  * \retval #PSA_ERROR_INVALID_ARGUMENT
84  * The key is declared with a lifetime not known to us.
85  */
88  size_t *key_buffer_size )
89 {
92  size_t key_bits = psa_get_key_bits(attributes);
93 
94  *key_buffer_size = 0;
95  switch( location )
96  {
97 #if defined(PSA_CRYPTO_DRIVER_TEST)
98  case PSA_CRYPTO_TEST_DRIVER_LOCATION:
99 #if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)
100  /* Emulate property 'builtin_key_size' */
101  if( psa_key_id_is_builtin(
103  psa_get_key_id( attributes ) ) ) )
104  {
105  *key_buffer_size = sizeof( psa_drv_slot_number_t );
106  return( PSA_SUCCESS );
107  }
108 #endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
109  *key_buffer_size = mbedtls_test_opaque_size_function( key_type,
110  key_bits );
111  return( ( *key_buffer_size != 0 ) ?
113 #endif /* PSA_CRYPTO_DRIVER_TEST */
114 
115  default:
116  (void)key_type;
117  (void)key_bits;
118  return( PSA_ERROR_INVALID_ARGUMENT );
119  }
120 }
121 
124  const uint8_t *key_buffer, size_t key_buffer_size,
125  uint8_t *data, size_t data_size, size_t *data_length )
126 
127 {
128 
132 
133  /* Try dynamically-registered SE interface first */
134 #if defined(MBEDTLS_PSA_CRYPTO_SE_C)
135  const psa_drv_se_t *drv;
136  psa_drv_se_context_t *drv_context;
137 
138  if( psa_get_se_driver( psa_get_key_lifetime(attributes), &drv, &drv_context ) )
139  {
140  if( ( drv->key_management == NULL ) ||
141  ( drv->key_management->p_export_public == NULL ) )
142  {
143  return( PSA_ERROR_NOT_SUPPORTED );
144  }
145 
146  return( drv->key_management->p_export_public(
147  drv_context,
148  *( (psa_key_slot_number_t *)key_buffer ),
149  data, data_size, data_length ) );
150  }
151 #endif /* MBEDTLS_PSA_CRYPTO_SE_C */
152 
153  switch( location )
154  {
156  /* Key is stored in the slot in export representation, so
157  * cycle through all known transparent accelerators */
158 #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
159 
160 #if (defined(PSA_CRYPTO_DRIVER_TEST) )
161  status = mbedtls_test_transparent_export_public_key
162  (attributes,
163  key_buffer,
164  key_buffer_size,
165  data,
166  data_size,
167  data_length
168  );
169 
170  if( status != PSA_ERROR_NOT_SUPPORTED )
171  return( status );
172 #endif
173 
174 #if (defined(MBEDTLS_PSA_P256M_DRIVER_ENABLED) )
175  status = p256_transparent_export_public_key
176  (attributes,
177  key_buffer,
178  key_buffer_size,
179  data,
180  data_size,
181  data_length
182  );
183 
184  if( status != PSA_ERROR_NOT_SUPPORTED )
185  return( status );
186 #endif
187 
188 
189 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
190  /* Fell through, meaning no accelerator supports this operation */
192  key_buffer,
193  key_buffer_size,
194  data,
195  data_size,
196  data_length ) );
197 
198  /* Add cases for opaque driver here */
199 #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
200 
201 #if (defined(PSA_CRYPTO_DRIVER_TEST) )
202  case 0x7fffff:
203  return( mbedtls_test_opaque_export_public_key
204  (attributes,
205  key_buffer,
206  key_buffer_size,
207  data,
208  data_size,
209  data_length
210  ));
211 #endif
212 
213 
214 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
215  default:
216  /* Key is declared with a lifetime not known to us */
217  return( status );
218  }
219 
220 }
221 
223  psa_drv_slot_number_t slot_number,
225  uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
226 {
227 
229  switch( location )
230  {
231 #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
232 
233 #if (defined(PSA_CRYPTO_DRIVER_TEST) )
234  case 0x7fffff:
235  return( mbedtls_test_opaque_get_builtin_key
236  (slot_number,
237  attributes,
238  key_buffer,
239  key_buffer_size,
240  key_buffer_length
241  ));
242 #endif
243 
244 
245 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
246  default:
247  (void) slot_number;
248  (void) key_buffer;
249  (void) key_buffer_size;
250  (void) key_buffer_length;
251  return( PSA_ERROR_DOES_NOT_EXIST );
252  }
253 
254 }
255 
256 #endif /* MBEDTLS_PSA_CRYPTO_C */
static const struct attribute attributes[]
Definition: attributes.c:165
static const char location[]
Definition: config.c:97
char data[12]
Definition: iconv.c:80
unsigned char uint8_t
#define NULL
Definition: ncbistd.hpp:225
static size_t psa_get_key_bits(const psa_key_attributes_t *attributes)
Retrieve the key size from key attributes.
static psa_key_lifetime_t psa_get_key_lifetime(const psa_key_attributes_t *attributes)
Retrieve the lifetime from key attributes.
static psa_key_type_t psa_get_key_type(const psa_key_attributes_t *attributes)
Retrieve the key type from key attributes.
static mbedtls_svc_key_id_t psa_get_key_id(const psa_key_attributes_t *attributes)
Retrieve the key identifier from key attributes.
uint16_t psa_key_type_t
Encoding of a key type.
Definition: crypto_types.h:78
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:59
#define PSA_ERROR_DOES_NOT_EXIST
Asking for an item that doesn't exist.
#define PSA_ERROR_NOT_SUPPORTED
The requested operation or a parameter is not supported by this implementation.
Definition: crypto_values.h:73
#define PSA_SUCCESS
The action was completed successfully.
Definition: crypto_values.h:57
#define PSA_ERROR_INVALID_ARGUMENT
The parameters passed to the function are invalid.
#define PSA_KEY_LOCATION_LOCAL_STORAGE
The local storage area for persistent keys.
#define PSA_KEY_LIFETIME_GET_LOCATION(lifetime)
uint32_t psa_key_location_t
Encoding of key location indicators.
Definition: crypto_types.h:260
#define MBEDTLS_SVC_KEY_ID_GET_KEY_ID(id)
uint64_t psa_drv_slot_number_t
A slot number identifying a key in a driver.
Definition: crypto_extra.h:498
uint64_t psa_key_slot_number_t
An internal designation of a key slot between the core part of the PSA Crypto implementation and the ...
This file contains the definitions and functions of the Mbed TLS platform abstraction layer.
psa_status_t psa_export_public_key_internal(const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, uint8_t *data, size_t data_size, size_t *data_length)
Export a public key or the public part of a key pair in binary format.
psa_status_t psa_driver_wrapper_get_builtin_key(psa_drv_slot_number_t slot_number, psa_key_attributes_t *attributes, uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length)
psa_status_t psa_driver_wrapper_get_key_buffer_size(const psa_key_attributes_t *attributes, size_t *key_buffer_size)
psa_status_t psa_driver_wrapper_export_public_key(const psa_key_attributes_t *attributes, const uint8_t *key_buffer, size_t key_buffer_size, uint8_t *data, size_t data_size, size_t *data_length)
int psa_get_se_driver(psa_key_lifetime_t lifetime, const psa_drv_se_t **p_methods, psa_drv_se_context_t **p_drv_context)
Return the secure element driver information for a lifetime value.
Driver context structure.
A structure containing pointers to all the entry points of a secure element driver.
Modified on Sun Jul 14 04:57:21 2024 by modify_doxy.py rev. 669887