blob: bd40f2ea9ef59df3e9741fbf6017a428c48deff3 [file] [log] [blame]
Ronald Cron00b7bfc2020-11-25 15:25:26 +01001/*
2 * PSA ECP layer on top of Mbed TLS crypto
3 */
4/*
5 * Copyright The Mbed TLS Contributors
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may
9 * not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#include "common.h"
22
23#if defined(MBEDTLS_PSA_CRYPTO_C)
24
25#include <psa/crypto.h>
26#include "psa_crypto_core.h"
27#include "psa_crypto_ecp.h"
Ronald Crone5ca3d82020-11-26 16:36:16 +010028#include "psa_crypto_random_impl.h"
Ronald Cron00b7bfc2020-11-25 15:25:26 +010029
30#include <stdlib.h>
31#include <string.h>
32#include "mbedtls/platform.h"
33#if !defined(MBEDTLS_PLATFORM_C)
34#define mbedtls_calloc calloc
35#define mbedtls_free free
36#endif
37
Ronald Cron072722c2020-12-09 16:36:19 +010038#include <mbedtls/ecdsa.h>
Ronald Cron00b7bfc2020-11-25 15:25:26 +010039#include <mbedtls/ecp.h>
40#include <mbedtls/error.h>
41
Ronald Cronf1057d32020-11-26 19:19:10 +010042#if ( defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
43 ( defined(PSA_CRYPTO_DRIVER_TEST) && \
44 defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) ) )
45#define BUILTIN_KEY_TYPE_ECC_KEY_PAIR 1
46#endif
47
48#if ( defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) || \
49 ( defined(PSA_CRYPTO_DRIVER_TEST) && \
50 defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) ) )
51#define BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY 1
52#endif
53
54#if defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
55 defined(BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) || \
Ronald Cron00b7bfc2020-11-25 15:25:26 +010056 defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
57 defined(MBEDTLS_PSA_BUILTIN_ALG_ECDH) || \
58 defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
59psa_status_t mbedtls_psa_ecp_load_representation(
Gilles Peskine2fa6b5f2021-01-27 15:44:45 +010060 psa_key_type_t type, size_t curve_bits,
61 const uint8_t *data, size_t data_length,
Ronald Cron00b7bfc2020-11-25 15:25:26 +010062 mbedtls_ecp_keypair **p_ecp )
63{
64 mbedtls_ecp_group_id grp_id = MBEDTLS_ECP_DP_NONE;
65 psa_status_t status;
66 mbedtls_ecp_keypair *ecp = NULL;
Gilles Peskine2fa6b5f2021-01-27 15:44:45 +010067 size_t curve_bytes = data_length;
68 int explicit_bits = ( curve_bits != 0 );
Ronald Cron00b7bfc2020-11-25 15:25:26 +010069
70 if( PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) &&
71 PSA_KEY_TYPE_ECC_GET_FAMILY( type ) != PSA_ECC_FAMILY_MONTGOMERY )
72 {
73 /* A Weierstrass public key is represented as:
74 * - The byte 0x04;
75 * - `x_P` as a `ceiling(m/8)`-byte string, big-endian;
76 * - `y_P` as a `ceiling(m/8)`-byte string, big-endian.
77 * So its data length is 2m+1 where m is the curve size in bits.
78 */
79 if( ( data_length & 1 ) == 0 )
80 return( PSA_ERROR_INVALID_ARGUMENT );
Gilles Peskine2fa6b5f2021-01-27 15:44:45 +010081 curve_bytes = data_length / 2;
Ronald Cron00b7bfc2020-11-25 15:25:26 +010082
83 /* Montgomery public keys are represented in compressed format, meaning
Gilles Peskined88ccae2021-02-08 18:39:18 +010084 * their curve_bytes is equal to the amount of input. */
Ronald Cron00b7bfc2020-11-25 15:25:26 +010085
86 /* Private keys are represented in uncompressed private random integer
Gilles Peskined88ccae2021-02-08 18:39:18 +010087 * format, meaning their curve_bytes is equal to the amount of input. */
Ronald Cron00b7bfc2020-11-25 15:25:26 +010088 }
89
Gilles Peskine2fa6b5f2021-01-27 15:44:45 +010090 if( explicit_bits )
91 {
92 /* With an explicit bit-size, the data must have the matching length. */
93 if( curve_bytes != PSA_BITS_TO_BYTES( curve_bits ) )
94 return( PSA_ERROR_INVALID_ARGUMENT );
95 }
96 else
97 {
98 /* We need to infer the bit-size from the data. Since the only
99 * information we have is the length in bytes, the value of curve_bits
100 * at this stage is rounded up to the nearest multiple of 8. */
101 curve_bits = PSA_BYTES_TO_BITS( curve_bytes );
102 }
103
Ronald Cron00b7bfc2020-11-25 15:25:26 +0100104 /* Allocate and initialize a key representation. */
105 ecp = mbedtls_calloc( 1, sizeof( mbedtls_ecp_keypair ) );
106 if( ecp == NULL )
107 return( PSA_ERROR_INSUFFICIENT_MEMORY );
108 mbedtls_ecp_keypair_init( ecp );
109
110 /* Load the group. */
111 grp_id = mbedtls_ecc_group_of_psa( PSA_KEY_TYPE_ECC_GET_FAMILY( type ),
Gilles Peskine2fa6b5f2021-01-27 15:44:45 +0100112 curve_bits, !explicit_bits );
Ronald Cron00b7bfc2020-11-25 15:25:26 +0100113 if( grp_id == MBEDTLS_ECP_DP_NONE )
114 {
Gilles Peskine2fa6b5f2021-01-27 15:44:45 +0100115 /* We can't distinguish between a nonsensical family/size combination
116 * (which would warrant PSA_ERROR_INVALID_ARGUMENT) and a
117 * well-regarded curve that Mbed TLS just doesn't know about (which
118 * would warrant PSA_ERROR_NOT_SUPPORTED). For uniformity with how
119 * curves that Mbed TLS knows about but for which support is disabled
120 * at build time, return NOT_SUPPORTED. */
121 status = PSA_ERROR_NOT_SUPPORTED;
Ronald Cron00b7bfc2020-11-25 15:25:26 +0100122 goto exit;
123 }
124
125 status = mbedtls_to_psa_error(
126 mbedtls_ecp_group_load( &ecp->grp, grp_id ) );
127 if( status != PSA_SUCCESS )
128 goto exit;
129
130 /* Load the key material. */
131 if( PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) )
132 {
133 /* Load the public value. */
134 status = mbedtls_to_psa_error(
135 mbedtls_ecp_point_read_binary( &ecp->grp, &ecp->Q,
136 data,
137 data_length ) );
138 if( status != PSA_SUCCESS )
139 goto exit;
140
141 /* Check that the point is on the curve. */
142 status = mbedtls_to_psa_error(
143 mbedtls_ecp_check_pubkey( &ecp->grp, &ecp->Q ) );
144 if( status != PSA_SUCCESS )
145 goto exit;
146 }
147 else
148 {
149 /* Load and validate the secret value. */
150 status = mbedtls_to_psa_error(
151 mbedtls_ecp_read_key( ecp->grp.id,
152 ecp,
153 data,
154 data_length ) );
155 if( status != PSA_SUCCESS )
156 goto exit;
157 }
158
159 *p_ecp = ecp;
160exit:
161 if( status != PSA_SUCCESS )
162 {
163 mbedtls_ecp_keypair_free( ecp );
164 mbedtls_free( ecp );
165 }
166
167 return( status );
168}
Ronald Cronf1057d32020-11-26 19:19:10 +0100169#endif /* defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR) ||
170 * defined(BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) ||
Ronald Cron00b7bfc2020-11-25 15:25:26 +0100171 * defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) ||
172 * defined(MBEDTLS_PSA_BUILTIN_ALG_ECDH) ||
173 * defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) */
174
Ronald Cronf1057d32020-11-26 19:19:10 +0100175#if defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
176 defined(BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
Ronald Crond6ec3032020-11-27 18:54:57 +0100177
Ronald Cron784fb322020-11-30 13:55:05 +0100178static psa_status_t ecp_import_key(
Ronald Crond6ec3032020-11-27 18:54:57 +0100179 const psa_key_attributes_t *attributes,
180 const uint8_t *data, size_t data_length,
181 uint8_t *key_buffer, size_t key_buffer_size,
182 size_t *key_buffer_length, size_t *bits )
183{
184 psa_status_t status;
185 mbedtls_ecp_keypair *ecp = NULL;
186
187 /* Parse input */
188 status = mbedtls_psa_ecp_load_representation( attributes->core.type,
Gilles Peskine2fa6b5f2021-01-27 15:44:45 +0100189 attributes->core.bits,
Ronald Crond6ec3032020-11-27 18:54:57 +0100190 data,
191 data_length,
192 &ecp );
193 if( status != PSA_SUCCESS )
194 goto exit;
195
196 if( PSA_KEY_TYPE_ECC_GET_FAMILY( attributes->core.type ) ==
197 PSA_ECC_FAMILY_MONTGOMERY )
198 *bits = ecp->grp.nbits + 1;
199 else
200 *bits = ecp->grp.nbits;
201
202 /* Re-export the data to PSA export format. There is currently no support
203 * for other input formats then the export format, so this is a 1-1
204 * copy operation. */
205 status = mbedtls_psa_ecp_export_key( attributes->core.type,
206 ecp,
207 key_buffer,
208 key_buffer_size,
209 key_buffer_length );
210exit:
211 /* Always free the PK object (will also free contained ECP context) */
212 mbedtls_ecp_keypair_free( ecp );
213 mbedtls_free( ecp );
214
215 return( status );
216}
217
Ronald Crone5ca3d82020-11-26 16:36:16 +0100218psa_status_t mbedtls_psa_ecp_export_key( psa_key_type_t type,
219 mbedtls_ecp_keypair *ecp,
220 uint8_t *data,
221 size_t data_size,
222 size_t *data_length )
223{
224 psa_status_t status;
225
226 if( PSA_KEY_TYPE_IS_PUBLIC_KEY( type ) )
227 {
228 /* Check whether the public part is loaded */
229 if( mbedtls_ecp_is_zero( &ecp->Q ) )
230 {
231 /* Calculate the public key */
232 status = mbedtls_to_psa_error(
233 mbedtls_ecp_mul( &ecp->grp, &ecp->Q, &ecp->d, &ecp->grp.G,
234 mbedtls_psa_get_random,
235 MBEDTLS_PSA_RANDOM_STATE ) );
236 if( status != PSA_SUCCESS )
237 return( status );
238 }
239
240 status = mbedtls_to_psa_error(
241 mbedtls_ecp_point_write_binary( &ecp->grp, &ecp->Q,
242 MBEDTLS_ECP_PF_UNCOMPRESSED,
243 data_length,
244 data,
245 data_size ) );
246 if( status != PSA_SUCCESS )
247 memset( data, 0, data_size );
248
249 return( status );
250 }
251 else
252 {
253 if( data_size < PSA_BITS_TO_BYTES( ecp->grp.nbits ) )
254 return( PSA_ERROR_BUFFER_TOO_SMALL );
255
256 status = mbedtls_to_psa_error(
257 mbedtls_ecp_write_key( ecp,
258 data,
259 PSA_BITS_TO_BYTES( ecp->grp.nbits ) ) );
260 if( status == PSA_SUCCESS )
261 *data_length = PSA_BITS_TO_BYTES( ecp->grp.nbits );
262 else
263 memset( data, 0, data_size );
264
265 return( status );
266 }
267}
268
Ronald Cronf1057d32020-11-26 19:19:10 +0100269static psa_status_t ecp_export_public_key(
Ronald Crone5ca3d82020-11-26 16:36:16 +0100270 const psa_key_attributes_t *attributes,
271 const uint8_t *key_buffer, size_t key_buffer_size,
272 uint8_t *data, size_t data_size, size_t *data_length )
273{
274 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
275 mbedtls_ecp_keypair *ecp = NULL;
276
277 status = mbedtls_psa_ecp_load_representation(
Gilles Peskine2fa6b5f2021-01-27 15:44:45 +0100278 attributes->core.type, attributes->core.bits,
279 key_buffer, key_buffer_size, &ecp );
Ronald Crone5ca3d82020-11-26 16:36:16 +0100280 if( status != PSA_SUCCESS )
281 return( status );
282
283 status = mbedtls_psa_ecp_export_key(
284 PSA_KEY_TYPE_ECC_PUBLIC_KEY(
285 PSA_KEY_TYPE_ECC_GET_FAMILY( attributes->core.type ) ),
286 ecp, data, data_size, data_length );
287
288 mbedtls_ecp_keypair_free( ecp );
289 mbedtls_free( ecp );
290
291 return( status );
292}
Ronald Cronf1057d32020-11-26 19:19:10 +0100293#endif /* defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR) ||
294 * defined(BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) */
295
Ronald Cron7023db52020-11-20 18:17:42 +0100296#if defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR)
Ronald Cronbbe5cbb2020-11-20 19:42:24 +0100297static psa_status_t ecp_generate_key(
Ronald Cron7023db52020-11-20 18:17:42 +0100298 const psa_key_attributes_t *attributes,
299 uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
300{
301 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
302 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
303
304 psa_ecc_family_t curve = PSA_KEY_TYPE_ECC_GET_FAMILY(
305 attributes->core.type );
306 mbedtls_ecp_group_id grp_id =
307 mbedtls_ecc_group_of_psa( curve, attributes->core.bits, 0 );
308
309 const mbedtls_ecp_curve_info *curve_info =
310 mbedtls_ecp_curve_info_from_grp_id( grp_id );
311 mbedtls_ecp_keypair ecp;
312
313 if( attributes->domain_parameters_size != 0 )
314 return( PSA_ERROR_NOT_SUPPORTED );
315
316 if( grp_id == MBEDTLS_ECP_DP_NONE || curve_info == NULL )
317 return( PSA_ERROR_NOT_SUPPORTED );
318
319 mbedtls_ecp_keypair_init( &ecp );
320 ret = mbedtls_ecp_gen_key( grp_id, &ecp,
321 mbedtls_psa_get_random,
322 MBEDTLS_PSA_RANDOM_STATE );
323 if( ret != 0 )
324 {
325 mbedtls_ecp_keypair_free( &ecp );
326 return( mbedtls_to_psa_error( ret ) );
327 }
328
329 status = mbedtls_to_psa_error(
330 mbedtls_ecp_write_key( &ecp, key_buffer, key_buffer_size ) );
331
332 mbedtls_ecp_keypair_free( &ecp );
333
334 if( status == PSA_SUCCESS )
335 *key_buffer_length = key_buffer_size;
336
337 return( status );
338}
339#endif /* defined(BUILTIN_KEY_TYPE_ECC_KEY_PAIR) */
340
Ronald Cron072722c2020-12-09 16:36:19 +0100341/****************************************************************/
342/* ECDSA sign/verify */
343/****************************************************************/
344
345#if defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
346 defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
347psa_status_t mbedtls_psa_ecdsa_sign_hash(
348 const psa_key_attributes_t *attributes,
349 const uint8_t *key_buffer, size_t key_buffer_size,
350 psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
351 uint8_t *signature, size_t signature_size, size_t *signature_length )
352{
353 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
354 mbedtls_ecp_keypair *ecp = NULL;
355 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
356 size_t curve_bytes;
357 mbedtls_mpi r, s;
358
359 status = mbedtls_psa_ecp_load_representation( attributes->core.type,
360 attributes->core.bits,
361 key_buffer,
362 key_buffer_size,
363 &ecp );
364 if( status != PSA_SUCCESS )
365 return( status );
366
367 curve_bytes = PSA_BITS_TO_BYTES( ecp->grp.pbits );
368 mbedtls_mpi_init( &r );
369 mbedtls_mpi_init( &s );
370
371 if( signature_size < 2 * curve_bytes )
372 {
373 ret = MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL;
374 goto cleanup;
375 }
376
377#if defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
378 if( PSA_ALG_DSA_IS_DETERMINISTIC( alg ) )
379 {
380 psa_algorithm_t hash_alg = PSA_ALG_SIGN_GET_HASH( alg );
381 const mbedtls_md_info_t *md_info = mbedtls_md_info_from_psa( hash_alg );
382 mbedtls_md_type_t md_alg = mbedtls_md_get_type( md_info );
383 MBEDTLS_MPI_CHK( mbedtls_ecdsa_sign_det_ext(
384 &ecp->grp, &r, &s,
385 &ecp->d, hash,
386 hash_length, md_alg,
387 mbedtls_psa_get_random,
388 MBEDTLS_PSA_RANDOM_STATE ) );
389 }
390 else
391#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) */
392 {
393 (void) alg;
394 MBEDTLS_MPI_CHK( mbedtls_ecdsa_sign( &ecp->grp, &r, &s, &ecp->d,
395 hash, hash_length,
396 mbedtls_psa_get_random,
397 MBEDTLS_PSA_RANDOM_STATE ) );
398 }
399
400 MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &r,
401 signature,
402 curve_bytes ) );
403 MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &s,
404 signature + curve_bytes,
405 curve_bytes ) );
406cleanup:
407 mbedtls_mpi_free( &r );
408 mbedtls_mpi_free( &s );
409 if( ret == 0 )
410 *signature_length = 2 * curve_bytes;
411
412 mbedtls_ecp_keypair_free( ecp );
413 mbedtls_free( ecp );
414
415 return( mbedtls_to_psa_error( ret ) );
416}
417
418psa_status_t mbedtls_psa_ecdsa_verify_hash(
419 const psa_key_attributes_t *attributes,
420 const uint8_t *key_buffer, size_t key_buffer_size,
421 psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
422 const uint8_t *signature, size_t signature_length )
423{
424 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
425 mbedtls_ecp_keypair *ecp = NULL;
426 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
427 size_t curve_bytes;
428 mbedtls_mpi r, s;
429
430 (void)alg;
431
432 status = mbedtls_psa_ecp_load_representation( attributes->core.type,
433 attributes->core.bits,
434 key_buffer,
435 key_buffer_size,
436 &ecp );
437 if( status != PSA_SUCCESS )
438 return( status );
439
440 curve_bytes = PSA_BITS_TO_BYTES( ecp->grp.pbits );
441 mbedtls_mpi_init( &r );
442 mbedtls_mpi_init( &s );
443
444 if( signature_length != 2 * curve_bytes )
445 {
446 ret = MBEDTLS_ERR_ECP_VERIFY_FAILED;
447 goto cleanup;
448 }
449
450 MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &r,
451 signature,
452 curve_bytes ) );
453 MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &s,
454 signature + curve_bytes,
455 curve_bytes ) );
456
457 /* Check whether the public part is loaded. If not, load it. */
458 if( mbedtls_ecp_is_zero( &ecp->Q ) )
459 {
460 MBEDTLS_MPI_CHK(
461 mbedtls_ecp_mul( &ecp->grp, &ecp->Q, &ecp->d, &ecp->grp.G,
462 mbedtls_psa_get_random, MBEDTLS_PSA_RANDOM_STATE ) );
463 }
464
465 ret = mbedtls_ecdsa_verify( &ecp->grp, hash, hash_length,
466 &ecp->Q, &r, &s );
467
468cleanup:
469 mbedtls_mpi_free( &r );
470 mbedtls_mpi_free( &s );
471 mbedtls_ecp_keypair_free( ecp );
472 mbedtls_free( ecp );
473
474 return( mbedtls_to_psa_error( ret ) );
475}
476
477#endif /* defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
478 * defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) */
479
Ronald Cronf1057d32020-11-26 19:19:10 +0100480#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
481 defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
482
Ronald Cron784fb322020-11-30 13:55:05 +0100483psa_status_t mbedtls_psa_ecp_import_key(
484 const psa_key_attributes_t *attributes,
485 const uint8_t *data, size_t data_length,
486 uint8_t *key_buffer, size_t key_buffer_size,
487 size_t *key_buffer_length, size_t *bits )
488{
489 return( ecp_import_key( attributes, data, data_length,
490 key_buffer, key_buffer_size,
491 key_buffer_length, bits ) );
492}
493
Ronald Cronf1057d32020-11-26 19:19:10 +0100494psa_status_t mbedtls_psa_ecp_export_public_key(
495 const psa_key_attributes_t *attributes,
496 const uint8_t *key_buffer, size_t key_buffer_size,
497 uint8_t *data, size_t data_size, size_t *data_length )
498{
499 return( ecp_export_public_key( attributes, key_buffer, key_buffer_size,
500 data, data_size, data_length ) );
501}
502
Ronald Crone5ca3d82020-11-26 16:36:16 +0100503#endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) ||
504 * defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) */
505
Ronald Cronbbe5cbb2020-11-20 19:42:24 +0100506#if defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR)
507psa_status_t mbedtls_psa_ecp_generate_key(
508 const psa_key_attributes_t *attributes,
509 uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
510{
511 return( ecp_generate_key( attributes, key_buffer, key_buffer_size,
512 key_buffer_length ) );
513}
514#endif /* defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) */
515
Ronald Cronf1057d32020-11-26 19:19:10 +0100516/*
517 * BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
518 */
519
520#if defined(PSA_CRYPTO_DRIVER_TEST)
521
522#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
523 defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY)
Ronald Cron784fb322020-11-30 13:55:05 +0100524
525psa_status_t mbedtls_transparent_test_driver_ecp_import_key(
526 const psa_key_attributes_t *attributes,
527 const uint8_t *data, size_t data_length,
528 uint8_t *key_buffer, size_t key_buffer_size,
529 size_t *key_buffer_length, size_t *bits )
530{
531 return( ecp_import_key( attributes, data, data_length,
532 key_buffer, key_buffer_size,
533 key_buffer_length, bits ) );
534}
535
Ronald Cronf1057d32020-11-26 19:19:10 +0100536psa_status_t mbedtls_transparent_test_driver_ecp_export_public_key(
537 const psa_key_attributes_t *attributes,
538 const uint8_t *key_buffer, size_t key_buffer_size,
539 uint8_t *data, size_t data_size, size_t *data_length )
540{
541 return( ecp_export_public_key( attributes, key_buffer, key_buffer_size,
542 data, data_size, data_length ) );
543}
Ronald Cron784fb322020-11-30 13:55:05 +0100544
Ronald Cronf1057d32020-11-26 19:19:10 +0100545#endif /* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) ||
546 defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) */
547
Ronald Cron95391262021-02-08 09:54:03 +0100548#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) && \
549 defined(MBEDTLS_GENPRIME)
Ronald Cronbbe5cbb2020-11-20 19:42:24 +0100550psa_status_t mbedtls_transparent_test_driver_ecp_generate_key(
551 const psa_key_attributes_t *attributes,
552 uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
553{
554 return( ecp_generate_key( attributes, key_buffer, key_buffer_size,
555 key_buffer_length ) );
556}
Ronald Cron95391262021-02-08 09:54:03 +0100557#endif /* defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) &&
Ronald Cronbbe5cbb2020-11-20 19:42:24 +0100558 defined(MBEDTLS_GENPRIME) */
559
Ronald Cronf1057d32020-11-26 19:19:10 +0100560#endif /* PSA_CRYPTO_DRIVER_TEST */
561
Ronald Cron00b7bfc2020-11-25 15:25:26 +0100562#endif /* MBEDTLS_PSA_CRYPTO_C */