mbed TLS v2.28.1
Loading...
Searching...
No Matches
crypto_extra.h
Go to the documentation of this file.
1
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_types.h"
34#include "crypto_compat.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/* UID for secure storage seed */
41#define PSA_CRYPTO_ITS_RANDOM_SEED_UID 0xFFFFFF52
42
43/* See config.h for definition */
44#if !defined(MBEDTLS_PSA_KEY_SLOT_COUNT)
45#define MBEDTLS_PSA_KEY_SLOT_COUNT 32
46#endif
47
72 psa_key_attributes_t *attributes,
73 psa_algorithm_t alg2)
74{
75 attributes->core.policy.alg2 = alg2;
76}
77
85 const psa_key_attributes_t *attributes)
86{
87 return( attributes->core.policy.alg2 );
88}
89
90#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
91
114psa_status_t psa_get_key_slot_number(
115 const psa_key_attributes_t *attributes,
116 psa_key_slot_number_t *slot_number );
117
141static inline void psa_set_key_slot_number(
142 psa_key_attributes_t *attributes,
143 psa_key_slot_number_t slot_number )
144{
146 attributes->slot_number = slot_number;
147}
148
155static inline void psa_clear_key_slot_number(
156 psa_key_attributes_t *attributes )
157{
158 attributes->core.flags &= ~MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER;
159}
160
201psa_status_t mbedtls_psa_register_se_key(
202 const psa_key_attributes_t *attributes);
203
204#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
205
217
225{
248
257
326 size_t seed_size);
327
339#define PSA_KEY_TYPE_DSA_PUBLIC_KEY ((psa_key_type_t)0x4002)
340
357#define PSA_KEY_TYPE_DSA_KEY_PAIR ((psa_key_type_t)0x7002)
358
360#define PSA_KEY_TYPE_IS_DSA(type) \
361 (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) == PSA_KEY_TYPE_DSA_PUBLIC_KEY)
362
363#define PSA_ALG_DSA_BASE ((psa_algorithm_t)0x06000400)
378#define PSA_ALG_DSA(hash_alg) \
379 (PSA_ALG_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
380#define PSA_ALG_DETERMINISTIC_DSA_BASE ((psa_algorithm_t)0x06000500)
381#define PSA_ALG_DSA_DETERMINISTIC_FLAG PSA_ALG_ECDSA_DETERMINISTIC_FLAG
396#define PSA_ALG_DETERMINISTIC_DSA(hash_alg) \
397 (PSA_ALG_DETERMINISTIC_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
398#define PSA_ALG_IS_DSA(alg) \
399 (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_DSA_DETERMINISTIC_FLAG) == \
400 PSA_ALG_DSA_BASE)
401#define PSA_ALG_DSA_IS_DETERMINISTIC(alg) \
402 (((alg) & PSA_ALG_DSA_DETERMINISTIC_FLAG) != 0)
403#define PSA_ALG_IS_DETERMINISTIC_DSA(alg) \
404 (PSA_ALG_IS_DSA(alg) && PSA_ALG_DSA_IS_DETERMINISTIC(alg))
405#define PSA_ALG_IS_RANDOMIZED_DSA(alg) \
406 (PSA_ALG_IS_DSA(alg) && !PSA_ALG_DSA_IS_DETERMINISTIC(alg))
407
408
409/* We need to expand the sample definition of this macro from
410 * the API definition. */
411#undef PSA_ALG_IS_VENDOR_HASH_AND_SIGN
412#define PSA_ALG_IS_VENDOR_HASH_AND_SIGN(alg) \
413 PSA_ALG_IS_DSA(alg)
414
427#define PSA_DH_FAMILY_CUSTOM ((psa_dh_family_t) 0x7e)
428
429
497 psa_key_type_t type,
498 const uint8_t *data,
499 size_t data_length);
500
525 const psa_key_attributes_t *attributes,
526 uint8_t *data,
527 size_t data_size,
528 size_t *data_length);
529
555#define PSA_KEY_DOMAIN_PARAMETERS_SIZE(key_type, key_bits) \
556 (PSA_KEY_TYPE_IS_RSA(key_type) ? sizeof(int) : \
557 PSA_KEY_TYPE_IS_DH(key_type) ? PSA_DH_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) : \
558 PSA_KEY_TYPE_IS_DSA(key_type) ? PSA_DSA_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) : \
559 0)
560#define PSA_DH_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) \
561 (4 + (PSA_BITS_TO_BYTES(key_bits) + 5) * 3 /*without optional parts*/)
562#define PSA_DSA_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) \
563 (4 + (PSA_BITS_TO_BYTES(key_bits) + 5) * 2 /*p, g*/ + 34 /*q*/)
564
571#if defined(MBEDTLS_ECP_C)
572#include <mbedtls/ecp.h>
573
588 size_t *bits )
589{
590 switch( grpid )
591 {
593 *bits = 192;
594 return( PSA_ECC_FAMILY_SECP_R1 );
596 *bits = 224;
597 return( PSA_ECC_FAMILY_SECP_R1 );
599 *bits = 256;
600 return( PSA_ECC_FAMILY_SECP_R1 );
602 *bits = 384;
603 return( PSA_ECC_FAMILY_SECP_R1 );
605 *bits = 521;
606 return( PSA_ECC_FAMILY_SECP_R1 );
608 *bits = 256;
611 *bits = 384;
614 *bits = 512;
617 *bits = 255;
620 *bits = 192;
621 return( PSA_ECC_FAMILY_SECP_K1 );
623 *bits = 224;
624 return( PSA_ECC_FAMILY_SECP_K1 );
626 *bits = 256;
627 return( PSA_ECC_FAMILY_SECP_K1 );
629 *bits = 448;
631 default:
632 *bits = 0;
633 return( 0 );
634 }
635}
636
657 size_t bits,
658 int bits_is_sloppy );
659#endif /* MBEDTLS_ECP_C */
660
667#if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG)
707psa_status_t mbedtls_psa_external_get_random(
708 mbedtls_psa_external_random_context_t *context,
709 uint8_t *output, size_t output_size, size_t *output_length );
710#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
711
729#define MBEDTLS_PSA_KEY_ID_BUILTIN_MIN ((psa_key_id_t)0x7fff0000)
730
736#define MBEDTLS_PSA_KEY_ID_BUILTIN_MAX ((psa_key_id_t)0x7fffefff)
737
742typedef uint64_t psa_drv_slot_number_t;
743
744#if defined(MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS)
754static inline int psa_key_id_is_builtin( psa_key_id_t key_id )
755{
756 return( ( key_id >= MBEDTLS_PSA_KEY_ID_BUILTIN_MIN ) &&
757 ( key_id <= MBEDTLS_PSA_KEY_ID_BUILTIN_MAX ) );
758}
759
804psa_status_t mbedtls_psa_platform_get_builtin_key(
806 psa_key_lifetime_t *lifetime,
807 psa_drv_slot_number_t *slot_number );
808#endif /* MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
809
812#ifdef __cplusplus
813}
814#endif
815
816#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.
#define MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER
PSA cryptography module: type aliases.
This file provides an API for Elliptic Curves over GF(P) (ECP).
mbedtls_ecp_group_id
Definition: ecp.h:121
@ MBEDTLS_ECP_DP_SECP192K1
Definition: ecp.h:132
@ MBEDTLS_ECP_DP_SECP384R1
Definition: ecp.h:126
@ MBEDTLS_ECP_DP_CURVE448
Definition: ecp.h:135
@ MBEDTLS_ECP_DP_CURVE25519
Definition: ecp.h:131
@ MBEDTLS_ECP_DP_SECP256K1
Definition: ecp.h:134
@ MBEDTLS_ECP_DP_BP512R1
Definition: ecp.h:130
@ MBEDTLS_ECP_DP_SECP224R1
Definition: ecp.h:124
@ MBEDTLS_ECP_DP_SECP521R1
Definition: ecp.h:127
@ MBEDTLS_ECP_DP_BP384R1
Definition: ecp.h:129
@ MBEDTLS_ECP_DP_SECP224K1
Definition: ecp.h:133
@ MBEDTLS_ECP_DP_BP256R1
Definition: ecp.h:128
@ MBEDTLS_ECP_DP_SECP192R1
Definition: ecp.h:123
@ MBEDTLS_ECP_DP_SECP256R1
Definition: ecp.h:125
static psa_algorithm_t psa_get_key_enrollment_algorithm(const psa_key_attributes_t *attributes)
Definition: crypto_extra.h:84
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.
static void psa_set_key_enrollment_algorithm(psa_key_attributes_t *attributes, psa_algorithm_t alg2)
Declare the enrollment algorithm for a key.
Definition: crypto_extra.h:71
#define PSA_ECC_FAMILY_MONTGOMERY
#define PSA_ECC_FAMILY_SECP_R1
#define PSA_ECC_FAMILY_SECP_K1
uint16_t psa_key_type_t
Encoding of a key type.
Definition: crypto_types.h:81
#define PSA_ECC_FAMILY_BRAINPOOL_P_R1
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
Definition: crypto_types.h:137
uint8_t psa_ecc_family_t
Definition: crypto_types.h:100
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:62
uint32_t psa_key_id_t
Definition: crypto_types.h:278
uint32_t psa_key_lifetime_t
Definition: crypto_types.h:186
psa_key_id_t mbedtls_svc_key_id_t
Definition: crypto_types.h:295
#define MBEDTLS_PSA_KEY_ID_BUILTIN_MAX
Definition: crypto_extra.h:736
uint64_t psa_drv_slot_number_t
Definition: crypto_extra.h:742
#define MBEDTLS_PSA_KEY_ID_BUILTIN_MIN
Definition: crypto_extra.h:729
static psa_ecc_family_t mbedtls_ecc_group_to_psa(mbedtls_ecp_group_id grpid, size_t *bits)
Definition: crypto_extra.h:587
mbedtls_ecp_group_id mbedtls_ecc_group_of_psa(psa_ecc_family_t curve, size_t bits, int bits_is_sloppy)
uint64_t psa_key_slot_number_t
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:225
psa_key_id_t max_open_internal_key_id
Definition: crypto_extra.h:244
psa_key_id_t max_open_external_key_id
Definition: crypto_extra.h:246
psa_key_policy_t policy
psa_key_attributes_flag_t flags
psa_core_key_attributes_t core
psa_algorithm_t alg2