Mbed OS Reference
Loading...
Searching...
No Matches
crypto_extra.h
Go to the documentation of this file.
1/**
2 * \file
3 *
4 * \brief PSA cryptography module: Mbed TLS vendor extensions
5 *
6 * \note This file may not be included directly. Applications must
7 * include psa/crypto.h.
8 *
9 * This file is reserved for vendor-specific definitions.
10 */
11/*
12 * Copyright The Mbed TLS Contributors
13 * SPDX-License-Identifier: Apache-2.0
14 *
15 * Licensed under the Apache License, Version 2.0 (the "License"); you may
16 * not use this file except in compliance with the License.
17 * You may obtain a copy of the License at
18 *
19 * http://www.apache.org/licenses/LICENSE-2.0
20 *
21 * Unless required by applicable law or agreed to in writing, software
22 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
23 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 * See the License for the specific language governing permissions and
25 * limitations under the License.
26 */
27
28#ifndef PSA_CRYPTO_EXTRA_H
29#define PSA_CRYPTO_EXTRA_H
30
32
33#include "crypto_compat.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/** UID for secure storage seed */
40#define PSA_CRYPTO_ITS_RANDOM_SEED_UID 0xFFFFFF52
41
42
43/** \addtogroup attributes
44 * @{
45 */
46
47/** \brief Declare the enrollment algorithm for a key.
48 *
49 * An operation on a key may indifferently use the algorithm set with
50 * psa_set_key_algorithm() or with this function.
51 *
52 * \param[out] attributes The attribute structure to write to.
53 * \param alg2 A second algorithm that the key may be used
54 * for, in addition to the algorithm set with
55 * psa_set_key_algorithm().
56 *
57 * \warning Setting an enrollment algorithm is not recommended, because
58 * using the same key with different algorithms can allow some
59 * attacks based on arithmetic relations between different
60 * computations made with the same key, or can escalate harmless
61 * side channels into exploitable ones. Use this function only
62 * if it is necessary to support a protocol for which it has been
63 * verified that the usage of the key with multiple algorithms
64 * is safe.
65 */
66static inline void psa_set_key_enrollment_algorithm(
67 psa_key_attributes_t *attributes,
68 psa_algorithm_t alg2)
69{
70 attributes->core.policy.alg2 = alg2;
71}
72
73/** Retrieve the enrollment algorithm policy from key attributes.
74 *
75 * \param[in] attributes The key attribute structure to query.
76 *
77 * \return The enrollment algorithm stored in the attribute structure.
78 */
79static inline psa_algorithm_t psa_get_key_enrollment_algorithm(
80 const psa_key_attributes_t *attributes)
81{
82 return( attributes->core.policy.alg2 );
83}
84
85#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
86
87/** Retrieve the slot number where a key is stored.
88 *
89 * A slot number is only defined for keys that are stored in a secure
90 * element.
91 *
92 * This information is only useful if the secure element is not entirely
93 * managed through the PSA Cryptography API. It is up to the secure
94 * element driver to decide how PSA slot numbers map to any other interface
95 * that the secure element may have.
96 *
97 * \param[in] attributes The key attribute structure to query.
98 * \param[out] slot_number On success, the slot number containing the key.
99 *
100 * \retval #PSA_SUCCESS
101 * The key is located in a secure element, and \p *slot_number
102 * indicates the slot number that contains it.
103 * \retval #PSA_ERROR_NOT_PERMITTED
104 * The caller is not permitted to query the slot number.
105 * Mbed Crypto currently does not return this error.
106 * \retval #PSA_ERROR_INVALID_ARGUMENT
107 * The key is not located in a secure element.
108 */
109psa_status_t psa_get_key_slot_number(
110 const psa_key_attributes_t *attributes,
111 psa_key_slot_number_t *slot_number );
112
113/** Choose the slot number where a key is stored.
114 *
115 * This function declares a slot number in the specified attribute
116 * structure.
117 *
118 * A slot number is only meaningful for keys that are stored in a secure
119 * element. It is up to the secure element driver to decide how PSA slot
120 * numbers map to any other interface that the secure element may have.
121 *
122 * \note Setting a slot number in key attributes for a key creation can
123 * cause the following errors when creating the key:
124 * - #PSA_ERROR_NOT_SUPPORTED if the selected secure element does
125 * not support choosing a specific slot number.
126 * - #PSA_ERROR_NOT_PERMITTED if the caller is not permitted to
127 * choose slot numbers in general or to choose this specific slot.
128 * - #PSA_ERROR_INVALID_ARGUMENT if the chosen slot number is not
129 * valid in general or not valid for this specific key.
130 * - #PSA_ERROR_ALREADY_EXISTS if there is already a key in the
131 * selected slot.
132 *
133 * \param[out] attributes The attribute structure to write to.
134 * \param slot_number The slot number to set.
135 */
136static inline void psa_set_key_slot_number(
137 psa_key_attributes_t *attributes,
138 psa_key_slot_number_t slot_number )
139{
140 attributes->core.flags |= MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER;
141 attributes->slot_number = slot_number;
142}
143
144/** Remove the slot number attribute from a key attribute structure.
145 *
146 * This function undoes the action of psa_set_key_slot_number().
147 *
148 * \param[out] attributes The attribute structure to write to.
149 */
150static inline void psa_clear_key_slot_number(
151 psa_key_attributes_t *attributes )
152{
153 attributes->core.flags &= ~MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER;
154}
155
156/** Register a key that is already present in a secure element.
157 *
158 * The key must be located in a secure element designated by the
159 * lifetime field in \p attributes, in the slot set with
160 * psa_set_key_slot_number() in the attribute structure.
161 * This function makes the key available through the key identifier
162 * specified in \p attributes.
163 *
164 * \param[in] attributes The attributes of the existing key.
165 *
166 * \retval #PSA_SUCCESS
167 * The key was successfully registered.
168 * Note that depending on the design of the driver, this may or may
169 * not guarantee that a key actually exists in the designated slot
170 * and is compatible with the specified attributes.
171 * \retval #PSA_ERROR_ALREADY_EXISTS
172 * There is already a key with the identifier specified in
173 * \p attributes.
174 * \retval #PSA_ERROR_NOT_SUPPORTED
175 * The secure element driver for the specified lifetime does not
176 * support registering a key.
177 * \retval #PSA_ERROR_INVALID_ARGUMENT
178 * \p attributes specifies a lifetime which is not located
179 * in a secure element.
180 * \retval #PSA_ERROR_INVALID_ARGUMENT
181 * No slot number is specified in \p attributes,
182 * or the specified slot number is not valid.
183 * \retval #PSA_ERROR_NOT_PERMITTED
184 * The caller is not authorized to register the specified key slot.
185 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
186 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
187 * \retval #PSA_ERROR_HARDWARE_FAILURE
188 * \retval #PSA_ERROR_CORRUPTION_DETECTED
189 * \retval #PSA_ERROR_BAD_STATE
190 * The library has not been previously initialized by psa_crypto_init().
191 * It is implementation-dependent whether a failure to initialize
192 * results in this error code.
193 */
194psa_status_t mbedtls_psa_register_se_key(
195 const psa_key_attributes_t *attributes);
196
197#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
198
199/**@}*/
200
201/**
202 * \brief Library deinitialization.
203 *
204 * This function clears all data associated with the PSA layer,
205 * including the whole key store.
206 *
207 * This is an Mbed TLS extension.
208 */
210
211/** \brief Statistics about
212 * resource consumption related to the PSA keystore.
213 *
214 * \note The content of this structure is not part of the stable API and ABI
215 * of Mbed Crypto and may change arbitrarily from version to version.
216 */
218{
219 /** Number of slots containing key material for a volatile key. */
221 /** Number of slots containing key material for a key which is in
222 * internal persistent storage. */
224 /** Number of slots containing a reference to a key in a
225 * secure element. */
227 /** Number of slots which are occupied, but do not contain
228 * key material yet. */
230 /** Number of slots that contain cache data. */
232 /** Number of slots that are not used for anything. */
234 /** Number of slots that are locked. */
236 /** Largest key id value among open keys in internal persistent storage. */
238 /** Largest key id value among open keys in secure elements. */
241
242/** \brief Get statistics about
243 * resource consumption related to the PSA keystore.
244 *
245 * \note When Mbed Crypto is built as part of a service, with isolation
246 * between the application and the keystore, the service may or
247 * may not expose this function.
248 */
250
251/**
252 * \brief Inject an initial entropy seed for the random generator into
253 * secure storage.
254 *
255 * This function injects data to be used as a seed for the random generator
256 * used by the PSA Crypto implementation. On devices that lack a trusted
257 * entropy source (preferably a hardware random number generator),
258 * the Mbed PSA Crypto implementation uses this value to seed its
259 * random generator.
260 *
261 * On devices without a trusted entropy source, this function must be
262 * called exactly once in the lifetime of the device. On devices with
263 * a trusted entropy source, calling this function is optional.
264 * In all cases, this function may only be called before calling any
265 * other function in the PSA Crypto API, including psa_crypto_init().
266 *
267 * When this function returns successfully, it populates a file in
268 * persistent storage. Once the file has been created, this function
269 * can no longer succeed.
270 *
271 * If any error occurs, this function does not change the system state.
272 * You can call this function again after correcting the reason for the
273 * error if possible.
274 *
275 * \warning This function **can** fail! Callers MUST check the return status.
276 *
277 * \warning If you use this function, you should use it as part of a
278 * factory provisioning process. The value of the injected seed
279 * is critical to the security of the device. It must be
280 * *secret*, *unpredictable* and (statistically) *unique per device*.
281 * You should be generate it randomly using a cryptographically
282 * secure random generator seeded from trusted entropy sources.
283 * You should transmit it securely to the device and ensure
284 * that its value is not leaked or stored anywhere beyond the
285 * needs of transmitting it from the point of generation to
286 * the call of this function, and erase all copies of the value
287 * once this function returns.
288 *
289 * This is an Mbed TLS extension.
290 *
291 * \note This function is only available on the following platforms:
292 * * If the compile-time option MBEDTLS_PSA_INJECT_ENTROPY is enabled.
293 * Note that you must provide compatible implementations of
294 * mbedtls_nv_seed_read and mbedtls_nv_seed_write.
295 * * In a client-server integration of PSA Cryptography, on the client side,
296 * if the server supports this feature.
297 * \param[in] seed Buffer containing the seed value to inject.
298 * \param[in] seed_size Size of the \p seed buffer.
299 * The size of the seed in bytes must be greater
300 * or equal to both #MBEDTLS_ENTROPY_MIN_PLATFORM
301 * and #MBEDTLS_ENTROPY_BLOCK_SIZE.
302 * It must be less or equal to
303 * #MBEDTLS_ENTROPY_MAX_SEED_SIZE.
304 *
305 * \retval #PSA_SUCCESS
306 * The seed value was injected successfully. The random generator
307 * of the PSA Crypto implementation is now ready for use.
308 * You may now call psa_crypto_init() and use the PSA Crypto
309 * implementation.
310 * \retval #PSA_ERROR_INVALID_ARGUMENT
311 * \p seed_size is out of range.
312 * \retval #PSA_ERROR_STORAGE_FAILURE
313 * There was a failure reading or writing from storage.
314 * \retval #PSA_ERROR_NOT_PERMITTED
315 * The library has already been initialized. It is no longer
316 * possible to call this function.
317 */
319 size_t seed_size);
320
321/** \addtogroup crypto_types
322 * \ingroup experimental-crypto-psa
323 * @{
324 */
325
326/** DSA public key.
327 *
328 * The import and export format is the
329 * representation of the public key `y = g^x mod p` as a big-endian byte
330 * string. The length of the byte string is the length of the base prime `p`
331 * in bytes.
332 */
333#define PSA_KEY_TYPE_DSA_PUBLIC_KEY ((psa_key_type_t)0x4002)
334
335/** DSA key pair (private and public key).
336 *
337 * The import and export format is the
338 * representation of the private key `x` as a big-endian byte string. The
339 * length of the byte string is the private key size in bytes (leading zeroes
340 * are not stripped).
341 *
342 * Determinstic DSA key derivation with psa_generate_derived_key follows
343 * FIPS 186-4 §B.1.2: interpret the byte string as integer
344 * in big-endian order. Discard it if it is not in the range
345 * [0, *N* - 2] where *N* is the boundary of the private key domain
346 * (the prime *p* for Diffie-Hellman, the subprime *q* for DSA,
347 * or the order of the curve's base point for ECC).
348 * Add 1 to the resulting integer and use this as the private key *x*.
349 *
350 */
351#define PSA_KEY_TYPE_DSA_KEY_PAIR ((psa_key_type_t)0x7002)
352
353/** Whether a key type is an DSA key (pair or public-only). */
354#define PSA_KEY_TYPE_IS_DSA(type) \
355 (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) == PSA_KEY_TYPE_DSA_PUBLIC_KEY)
356
357#define PSA_ALG_DSA_BASE ((psa_algorithm_t)0x06000400)
358/** DSA signature with hashing.
359 *
360 * This is the signature scheme defined by FIPS 186-4,
361 * with a random per-message secret number (*k*).
362 *
363 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
364 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
365 * This includes #PSA_ALG_ANY_HASH
366 * when specifying the algorithm in a usage policy.
367 *
368 * \return The corresponding DSA signature algorithm.
369 * \return Unspecified if \p hash_alg is not a supported
370 * hash algorithm.
371 */
372#define PSA_ALG_DSA(hash_alg) \
373 (PSA_ALG_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
374#define PSA_ALG_DETERMINISTIC_DSA_BASE ((psa_algorithm_t)0x06000500)
375#define PSA_ALG_DSA_DETERMINISTIC_FLAG PSA_ALG_ECDSA_DETERMINISTIC_FLAG
376/** Deterministic DSA signature with hashing.
377 *
378 * This is the deterministic variant defined by RFC 6979 of
379 * the signature scheme defined by FIPS 186-4.
380 *
381 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
382 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
383 * This includes #PSA_ALG_ANY_HASH
384 * when specifying the algorithm in a usage policy.
385 *
386 * \return The corresponding DSA signature algorithm.
387 * \return Unspecified if \p hash_alg is not a supported
388 * hash algorithm.
389 */
390#define PSA_ALG_DETERMINISTIC_DSA(hash_alg) \
391 (PSA_ALG_DETERMINISTIC_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
392#define PSA_ALG_IS_DSA(alg) \
393 (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_DSA_DETERMINISTIC_FLAG) == \
394 PSA_ALG_DSA_BASE)
395#define PSA_ALG_DSA_IS_DETERMINISTIC(alg) \
396 (((alg) & PSA_ALG_DSA_DETERMINISTIC_FLAG) != 0)
397#define PSA_ALG_IS_DETERMINISTIC_DSA(alg) \
398 (PSA_ALG_IS_DSA(alg) && PSA_ALG_DSA_IS_DETERMINISTIC(alg))
399#define PSA_ALG_IS_RANDOMIZED_DSA(alg) \
400 (PSA_ALG_IS_DSA(alg) && !PSA_ALG_DSA_IS_DETERMINISTIC(alg))
401
402
403/* We need to expand the sample definition of this macro from
404 * the API definition. */
405#undef PSA_ALG_IS_HASH_AND_SIGN
406#define PSA_ALG_IS_HASH_AND_SIGN(alg) \
407 (PSA_ALG_IS_RSA_PSS(alg) || PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || \
408 PSA_ALG_IS_DSA(alg) || PSA_ALG_IS_ECDSA(alg))
409
410/**@}*/
411
412/** \addtogroup attributes
413 * @{
414 */
415
416/** Custom Diffie-Hellman group.
417 *
418 * For keys of type #PSA_KEY_TYPE_DH_PUBLIC_KEY(#PSA_DH_FAMILY_CUSTOM) or
419 * #PSA_KEY_TYPE_DH_KEY_PAIR(#PSA_DH_FAMILY_CUSTOM), the group data comes
420 * from domain parameters set by psa_set_key_domain_parameters().
421 */
422#define PSA_DH_FAMILY_CUSTOM ((psa_dh_family_t) 0x7e)
423
424
425/**
426 * \brief Set domain parameters for a key.
427 *
428 * Some key types require additional domain parameters in addition to
429 * the key type identifier and the key size. Use this function instead
430 * of psa_set_key_type() when you need to specify domain parameters.
431 *
432 * The format for the required domain parameters varies based on the key type.
433 *
434 * - For RSA keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY or #PSA_KEY_TYPE_RSA_KEY_PAIR),
435 * the domain parameter data consists of the public exponent,
436 * represented as a big-endian integer with no leading zeros.
437 * This information is used when generating an RSA key pair.
438 * When importing a key, the public exponent is read from the imported
439 * key data and the exponent recorded in the attribute structure is ignored.
440 * As an exception, the public exponent 65537 is represented by an empty
441 * byte string.
442 * - For DSA keys (#PSA_KEY_TYPE_DSA_PUBLIC_KEY or #PSA_KEY_TYPE_DSA_KEY_PAIR),
443 * the `Dss-Parms` format as defined by RFC 3279 §2.3.2.
444 * ```
445 * Dss-Parms ::= SEQUENCE {
446 * p INTEGER,
447 * q INTEGER,
448 * g INTEGER
449 * }
450 * ```
451 * - For Diffie-Hellman key exchange keys
452 * (#PSA_KEY_TYPE_DH_PUBLIC_KEY(#PSA_DH_FAMILY_CUSTOM) or
453 * #PSA_KEY_TYPE_DH_KEY_PAIR(#PSA_DH_FAMILY_CUSTOM)), the
454 * `DomainParameters` format as defined by RFC 3279 §2.3.3.
455 * ```
456 * DomainParameters ::= SEQUENCE {
457 * p INTEGER, -- odd prime, p=jq +1
458 * g INTEGER, -- generator, g
459 * q INTEGER, -- factor of p-1
460 * j INTEGER OPTIONAL, -- subgroup factor
461 * validationParms ValidationParms OPTIONAL
462 * }
463 * ValidationParms ::= SEQUENCE {
464 * seed BIT STRING,
465 * pgenCounter INTEGER
466 * }
467 * ```
468 *
469 * \note This function may allocate memory or other resources.
470 * Once you have called this function on an attribute structure,
471 * you must call psa_reset_key_attributes() to free these resources.
472 *
473 * \note This is an experimental extension to the interface. It may change
474 * in future versions of the library.
475 *
476 * \param[in,out] attributes Attribute structure where the specified domain
477 * parameters will be stored.
478 * If this function fails, the content of
479 * \p attributes is not modified.
480 * \param type Key type (a \c PSA_KEY_TYPE_XXX value).
481 * \param[in] data Buffer containing the key domain parameters.
482 * The content of this buffer is interpreted
483 * according to \p type as described above.
484 * \param data_length Size of the \p data buffer in bytes.
485 *
486 * \retval #PSA_SUCCESS
487 * \retval #PSA_ERROR_INVALID_ARGUMENT
488 * \retval #PSA_ERROR_NOT_SUPPORTED
489 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
490 */
492 psa_key_type_t type,
493 const uint8_t *data,
494 size_t data_length);
495
496/**
497 * \brief Get domain parameters for a key.
498 *
499 * Get the domain parameters for a key with this function, if any. The format
500 * of the domain parameters written to \p data is specified in the
501 * documentation for psa_set_key_domain_parameters().
502 *
503 * \note This is an experimental extension to the interface. It may change
504 * in future versions of the library.
505 *
506 * \param[in] attributes The key attribute structure to query.
507 * \param[out] data On success, the key domain parameters.
508 * \param data_size Size of the \p data buffer in bytes.
509 * The buffer is guaranteed to be large
510 * enough if its size in bytes is at least
511 * the value given by
512 * PSA_KEY_DOMAIN_PARAMETERS_SIZE().
513 * \param[out] data_length On success, the number of bytes
514 * that make up the key domain parameters data.
515 *
516 * \retval #PSA_SUCCESS
517 * \retval #PSA_ERROR_BUFFER_TOO_SMALL
518 */
520 const psa_key_attributes_t *attributes,
521 uint8_t *data,
522 size_t data_size,
523 size_t *data_length);
524
525/** Safe output buffer size for psa_get_key_domain_parameters().
526 *
527 * This macro returns a compile-time constant if its arguments are
528 * compile-time constants.
529 *
530 * \warning This function may call its arguments multiple times or
531 * zero times, so you should not pass arguments that contain
532 * side effects.
533 *
534 * \note This is an experimental extension to the interface. It may change
535 * in future versions of the library.
536 *
537 * \param key_type A supported key type.
538 * \param key_bits The size of the key in bits.
539 *
540 * \return If the parameters are valid and supported, return
541 * a buffer size in bytes that guarantees that
542 * psa_get_key_domain_parameters() will not fail with
543 * #PSA_ERROR_BUFFER_TOO_SMALL.
544 * If the parameters are a valid combination that is not supported
545 * by the implementation, this macro shall return either a
546 * sensible size or 0.
547 * If the parameters are not valid, the
548 * return value is unspecified.
549 */
550#define PSA_KEY_DOMAIN_PARAMETERS_SIZE(key_type, key_bits) \
551 (PSA_KEY_TYPE_IS_RSA(key_type) ? sizeof(int) : \
552 PSA_KEY_TYPE_IS_DH(key_type) ? PSA_DH_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) : \
553 PSA_KEY_TYPE_IS_DSA(key_type) ? PSA_DSA_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) : \
554 0)
555#define PSA_DH_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) \
556 (4 + (PSA_BITS_TO_BYTES(key_bits) + 5) * 3 /*without optional parts*/)
557#define PSA_DSA_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) \
558 (4 + (PSA_BITS_TO_BYTES(key_bits) + 5) * 2 /*p, g*/ + 34 /*q*/)
559
560/**@}*/
561
562/** \defgroup psa_tls_helpers TLS helper functions
563 * \ingroup experimental-crypto-psa
564 * @{
565 */
566
567#if defined(MBEDTLS_ECP_C)
568#include <mbedtls/ecp.h>
569
570/** Convert an ECC curve identifier from the Mbed TLS encoding to PSA.
571 *
572 * \note This function is provided solely for the convenience of
573 * Mbed TLS and may be removed at any time without notice.
574 *
575 * \param grpid An Mbed TLS elliptic curve identifier
576 * (`MBEDTLS_ECP_DP_xxx`).
577 * \param[out] bits On success, the bit size of the curve.
578 *
579 * \return The corresponding PSA elliptic curve identifier
580 * (`PSA_ECC_FAMILY_xxx`).
581 * \return \c 0 on failure (\p grpid is not recognized).
582 */
583static inline psa_ecc_family_t mbedtls_ecc_group_to_psa( mbedtls_ecp_group_id grpid,
584 size_t *bits )
585{
586 switch( grpid )
587 {
589 *bits = 192;
590 return( PSA_ECC_FAMILY_SECP_R1 );
592 *bits = 224;
593 return( PSA_ECC_FAMILY_SECP_R1 );
595 *bits = 256;
596 return( PSA_ECC_FAMILY_SECP_R1 );
598 *bits = 384;
599 return( PSA_ECC_FAMILY_SECP_R1 );
601 *bits = 521;
602 return( PSA_ECC_FAMILY_SECP_R1 );
604 *bits = 256;
607 *bits = 384;
610 *bits = 512;
613 *bits = 255;
616 *bits = 192;
617 return( PSA_ECC_FAMILY_SECP_K1 );
619 *bits = 224;
620 return( PSA_ECC_FAMILY_SECP_K1 );
622 *bits = 256;
623 return( PSA_ECC_FAMILY_SECP_K1 );
625 *bits = 448;
627 default:
628 *bits = 0;
629 return( 0 );
630 }
631}
632
633/** Convert an ECC curve identifier from the PSA encoding to Mbed TLS.
634 *
635 * \note This function is provided solely for the convenience of
636 * Mbed TLS and may be removed at any time without notice.
637 *
638 * \param curve A PSA elliptic curve identifier
639 * (`PSA_ECC_FAMILY_xxx`).
640 * \param byte_length The byte-length of a private key on \p curve.
641 *
642 * \return The corresponding Mbed TLS elliptic curve identifier
643 * (`MBEDTLS_ECP_DP_xxx`).
644 * \return #MBEDTLS_ECP_DP_NONE if \c curve is not recognized.
645 * \return #MBEDTLS_ECP_DP_NONE if \p byte_length is not
646 * correct for \p curve.
647 */
648mbedtls_ecp_group_id mbedtls_ecc_group_of_psa( psa_ecc_family_t curve,
649 size_t byte_length );
650#endif /* MBEDTLS_ECP_C */
651
652/**@}*/
653
654#ifdef __cplusplus
655}
656#endif
657
658#endif /* PSA_CRYPTO_EXTRA_H */
PSA cryptography module: Backward compatibility aliases.
void mbedtls_psa_crypto_free(void)
Library deinitialization.
void mbedtls_psa_get_stats(mbedtls_psa_stats_t *stats)
Get statistics about resource consumption related to the PSA keystore.
struct mbedtls_psa_stats_s mbedtls_psa_stats_t
Statistics about resource consumption related to the PSA keystore.
psa_status_t mbedtls_psa_inject_entropy(const uint8_t *seed, size_t seed_size)
Inject an initial entropy seed for the random generator into secure storage.
psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t *attributes, psa_key_type_t type, const uint8_t *data, size_t data_length)
Set domain parameters for a key.
psa_status_t psa_get_key_domain_parameters(const psa_key_attributes_t *attributes, uint8_t *data, size_t data_size, size_t *data_length)
Get domain parameters for a key.
#define PSA_ECC_FAMILY_MONTGOMERY
Curve25519 and Curve448.
#define PSA_ECC_FAMILY_SECP_R1
SEC random curves over prime fields.
#define PSA_ECC_FAMILY_SECP_K1
SEC Koblitz curves over prime fields.
uint16_t psa_key_type_t
Encoding of a key type.
Definition: crypto_types.h:66
#define PSA_ECC_FAMILY_BRAINPOOL_P_R1
Brainpool P random curves.
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
Definition: crypto_types.h:98
uint8_t psa_ecc_family_t
The type of PSA elliptic curve family identifiers.
Definition: crypto_types.h:77
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:55
uint32_t psa_key_id_t
Encoding of identifiers of persistent keys.
Definition: crypto_types.h:231
mbedtls_ecp_group_id
Domain-parameter identifiers: curve, subgroup, and generator.
@ MBEDTLS_ECP_DP_SECP192K1
@ MBEDTLS_ECP_DP_SECP384R1
@ MBEDTLS_ECP_DP_CURVE25519
@ MBEDTLS_ECP_DP_SECP256K1
@ MBEDTLS_ECP_DP_SECP224R1
@ MBEDTLS_ECP_DP_SECP521R1
@ MBEDTLS_ECP_DP_SECP224K1
@ MBEDTLS_ECP_DP_SECP192R1
@ MBEDTLS_ECP_DP_SECP256R1
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 provides an API for Elliptic Curves over GF(P) (ECP).
Common and shared functions used by multiple modules in the Mbed TLS library.
Statistics about resource consumption related to the PSA keystore.
Definition: crypto_extra.h:218
size_t half_filled_slots
Number of slots which are occupied, but do not contain key material yet.
Definition: crypto_extra.h:229
size_t volatile_slots
Number of slots containing key material for a volatile key.
Definition: crypto_extra.h:220
size_t external_slots
Number of slots containing a reference to a key in a secure element.
Definition: crypto_extra.h:226
size_t locked_slots
Number of slots that are locked.
Definition: crypto_extra.h:235
psa_key_id_t max_open_internal_key_id
Largest key id value among open keys in internal persistent storage.
Definition: crypto_extra.h:237
psa_key_id_t max_open_external_key_id
Largest key id value among open keys in secure elements.
Definition: crypto_extra.h:239
size_t empty_slots
Number of slots that are not used for anything.
Definition: crypto_extra.h:233
size_t persistent_slots
Number of slots containing key material for a key which is in internal persistent storage.
Definition: crypto_extra.h:223
size_t cache_slots
Number of slots that contain cache data.
Definition: crypto_extra.h:231