Skip to content

Commit f97bc88

Browse files
author
Jaykumar Pitambarbhai Patel
committed
v0.9 PSA APIs test suite update
This release includes the following major enhancements: 1. Enhanced Crypto and IPC suites for new tests 2. Added TFM-MUSCA_B support 3. Bug fixes, feature enhancement and documentation update
1 parent 6d7f6d5 commit f97bc88

File tree

485 files changed

+22490
-4819
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

485 files changed

+22490
-4819
lines changed

api-specs/include/psa/crypto.h

Lines changed: 159 additions & 1118 deletions
Large diffs are not rendered by default.

api-specs/include/psa/crypto_extra.h

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* \file psa/crypto_extra.h
33
*
4-
* \brief PSA cryptography module: vendor extensions
4+
* \brief PSA cryptography module: Mbed TLS vendor extensions
55
*
66
* \note This file may not be included directly. Applications must
77
* include psa/crypto.h.
@@ -30,11 +30,120 @@
3030
#ifndef PSA_CRYPTO_EXTRA_H
3131
#define PSA_CRYPTO_EXTRA_H
3232

33+
#include "mbedtls/platform_util.h"
34+
3335
#ifdef __cplusplus
3436
extern "C" {
3537
#endif
3638

37-
/* Add vendor extensions here. */
39+
/* UID for secure storage seed */
40+
#define PSA_CRYPTO_ITS_RANDOM_SEED_UID 0xFFFFFF52
41+
42+
/*
43+
* Deprecated PSA Crypto error code definitions
44+
*/
45+
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
46+
#define PSA_ERROR_UNKNOWN_ERROR \
47+
MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_GENERIC_ERROR )
48+
#endif
49+
50+
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
51+
#define PSA_ERROR_OCCUPIED_SLOT \
52+
MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_ALREADY_EXISTS )
53+
#endif
54+
55+
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
56+
#define PSA_ERROR_EMPTY_SLOT \
57+
MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_DOES_NOT_EXIST )
58+
#endif
59+
60+
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
61+
#define PSA_ERROR_INSUFFICIENT_CAPACITY \
62+
MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_INSUFFICIENT_DATA )
63+
#endif
64+
65+
/**
66+
* \brief Library deinitialization.
67+
*
68+
* This function clears all data associated with the PSA layer,
69+
* including the whole key store.
70+
*
71+
* This is an Mbed TLS extension.
72+
*/
73+
void mbedtls_psa_crypto_free( void );
74+
75+
76+
/**
77+
* \brief Inject an initial entropy seed for the random generator into
78+
* secure storage.
79+
*
80+
* This function injects data to be used as a seed for the random generator
81+
* used by the PSA Crypto implementation. On devices that lack a trusted
82+
* entropy source (preferably a hardware random number generator),
83+
* the Mbed PSA Crypto implementation uses this value to seed its
84+
* random generator.
85+
*
86+
* On devices without a trusted entropy source, this function must be
87+
* called exactly once in the lifetime of the device. On devices with
88+
* a trusted entropy source, calling this function is optional.
89+
* In all cases, this function may only be called before calling any
90+
* other function in the PSA Crypto API, including psa_crypto_init().
91+
*
92+
* When this function returns successfully, it populates a file in
93+
* persistent storage. Once the file has been created, this function
94+
* can no longer succeed.
95+
*
96+
* If any error occurs, this function does not change the system state.
97+
* You can call this function again after correcting the reason for the
98+
* error if possible.
99+
*
100+
* \warning This function **can** fail! Callers MUST check the return status.
101+
*
102+
* \warning If you use this function, you should use it as part of a
103+
* factory provisioning process. The value of the injected seed
104+
* is critical to the security of the device. It must be
105+
* *secret*, *unpredictable* and (statistically) *unique per device*.
106+
* You should be generate it randomly using a cryptographically
107+
* secure random generator seeded from trusted entropy sources.
108+
* You should transmit it securely to the device and ensure
109+
* that its value is not leaked or stored anywhere beyond the
110+
* needs of transmitting it from the point of generation to
111+
* the call of this function, and erase all copies of the value
112+
* once this function returns.
113+
*
114+
* This is an Mbed TLS extension.
115+
*
116+
* \note This function is only available on the following platforms:
117+
* * If the compile-time options MBEDTLS_ENTROPY_NV_SEED and
118+
* MBEDTLS_PSA_HAS_ITS_IO are both enabled. Note that you
119+
* must provide compatible implementations of mbedtls_nv_seed_read
120+
* and mbedtls_nv_seed_write.
121+
* * In a client-server integration of PSA Cryptography, on the client side,
122+
* if the server supports this feature.
123+
* \param[in] seed Buffer containing the seed value to inject.
124+
* \param[in] seed_size Size of the \p seed buffer.
125+
* The size of the seed in bytes must be greater
126+
* or equal to both #MBEDTLS_ENTROPY_MIN_PLATFORM
127+
* and #MBEDTLS_ENTROPY_BLOCK_SIZE.
128+
* It must be less or equal to
129+
* #MBEDTLS_ENTROPY_MAX_SEED_SIZE.
130+
*
131+
* \retval #PSA_SUCCESS
132+
* The seed value was injected successfully. The random generator
133+
* of the PSA Crypto implementation is now ready for use.
134+
* You may now call psa_crypto_init() and use the PSA Crypto
135+
* implementation.
136+
* \retval #PSA_ERROR_INVALID_ARGUMENT
137+
* \p seed_size is out of range.
138+
* \retval #PSA_ERROR_STORAGE_FAILURE
139+
* There was a failure reading or writing from storage.
140+
* \retval #PSA_ERROR_NOT_PERMITTED
141+
* The library has already been initialized. It is no longer
142+
* possible to call this function.
143+
*/
144+
psa_status_t mbedtls_psa_inject_entropy(const unsigned char *seed,
145+
size_t seed_size);
146+
38147

39148
#ifdef __cplusplus
40149
}

api-specs/include/psa/crypto_platform.h

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* \file psa/crypto_platform.h
33
*
4-
* \brief PSA cryptography module: Platfom-specific definitions
4+
* \brief PSA cryptography module: Mbed TLS platfom definitions
55
*
66
* \note This file may not be included directly. Applications must
77
* include psa/crypto.h.
@@ -35,11 +35,67 @@
3535
#ifndef PSA_CRYPTO_PLATFORM_H
3636
#define PSA_CRYPTO_PLATFORM_H
3737

38+
/* Include the Mbed TLS configuration file, the way Mbed TLS does it
39+
* in each of its header files. */
40+
#if !defined(MBEDTLS_CONFIG_FILE)
41+
#include "../mbedtls/config.h"
42+
#else
43+
#include MBEDTLS_CONFIG_FILE
44+
#endif
45+
3846
/* PSA requires several types which C99 provides in stdint.h. */
3947
#include <stdint.h>
4048

41-
/* Integral type representing a key handle. The choice of integral
42-
* type is implementation-dependent. */
49+
/* Integral type representing a key handle. */
4350
typedef uint16_t psa_key_handle_t;
4451

52+
/* This implementation distinguishes *application key identifiers*, which
53+
* are the key identifiers specified by the application, from
54+
* *key file identifiers*, which are the key identifiers that the library
55+
* sees internally. The two types can be different if there is a remote
56+
* call layer between the application and the library which supports
57+
* multiple client applications that do not have access to each others'
58+
* keys. The point of having different types is that the key file
59+
* identifier may encode not only the key identifier specified by the
60+
* application, but also the the identity of the application.
61+
*
62+
* Note that this is an internal concept of the library and the remote
63+
* call layer. The application itself never sees anything other than
64+
* #psa_app_key_id_t with its standard definition.
65+
*/
66+
67+
/* The application key identifier is always what the application sees as
68+
* #psa_key_id_t. */
69+
typedef uint32_t psa_app_key_id_t;
70+
71+
#if defined(MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER)
72+
73+
#if defined(PSA_CRYPTO_SECURE)
74+
/* Building for the PSA Crypto service on a PSA platform. */
75+
/* A key owner is a PSA partition identifier. */
76+
typedef int32_t psa_key_owner_id_t;
77+
#endif
78+
79+
typedef struct
80+
{
81+
uint32_t key_id;
82+
psa_key_owner_id_t owner;
83+
} psa_key_file_id_t;
84+
#define PSA_KEY_FILE_GET_KEY_ID( file_id ) ( ( file_id ).key_id )
85+
86+
/* Since crypto.h is used as part of the PSA Cryptography API specification,
87+
* it must use standard types for things like the argument of psa_open_key().
88+
* If it wasn't for that constraint, psa_open_key() would take a
89+
* `psa_key_file_id_t` argument. As a workaround, make `psa_key_id_t` an
90+
* alias for `psa_key_file_id_t` when building for a multi-client service. */
91+
typedef psa_key_file_id_t psa_key_id_t;
92+
93+
#else /* !MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER */
94+
95+
/* By default, a key file identifier is just the application key identifier. */
96+
typedef psa_app_key_id_t psa_key_file_id_t;
97+
#define PSA_KEY_FILE_GET_KEY_ID( id ) ( id )
98+
99+
#endif /* !MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER */
100+
45101
#endif /* PSA_CRYPTO_PLATFORM_H */

api-specs/include/psa/crypto_sizes.h

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -268,27 +268,6 @@
268268
(plaintext_length) + PSA_AEAD_TAG_LENGTH(alg) : \
269269
0)
270270

271-
/** The maximum size of the output of psa_aead_finish(), in bytes.
272-
*
273-
* If the size of the ciphertext buffer is at least this large, it is
274-
* guaranteed that psa_aead_finish() will not fail due to an
275-
* insufficient buffer size. Depending on the algorithm, the actual size of
276-
* the ciphertext may be smaller.
277-
*
278-
* \param alg An AEAD algorithm
279-
* (\c PSA_ALG_XXX value such that
280-
* #PSA_ALG_IS_AEAD(alg) is true).
281-
*
282-
* \return The maximum trailing ciphertext size for the
283-
* specified algorithm.
284-
* If the AEAD algorithm is not recognized, return 0.
285-
* An implementation may return either 0 or a
286-
* correct size for an AEAD algorithm that it
287-
* recognizes, but does not support.
288-
*/
289-
#define PSA_AEAD_FINISH_OUTPUT_SIZE(alg, plaintext_length) \
290-
((size_t)0)
291-
292271
/** The maximum size of the output of psa_aead_decrypt(), in bytes.
293272
*
294273
* If the size of the plaintext buffer is at least this large, it is
@@ -313,9 +292,9 @@
313292
(plaintext_length) - PSA_AEAD_TAG_LENGTH(alg) : \
314293
0)
315294

316-
#define PSA_RSA_MINIMUM_PADDING_SIZE(alg) \
317-
(PSA_ALG_IS_RSA_OAEP(alg) ? \
318-
2 * PSA_HASH_FINAL_SIZE(PSA_ALG_RSA_OAEP_GET_HASH(alg)) + 1 : \
295+
#define PSA_RSA_MINIMUM_PADDING_SIZE(alg) \
296+
(PSA_ALG_IS_RSA_OAEP(alg) ? \
297+
2 * PSA_HASH_SIZE(PSA_ALG_RSA_OAEP_GET_HASH(alg)) + 1 : \
319298
11 /*PKCS#1v1.5*/)
320299

321300
/**
@@ -438,25 +417,16 @@
438417
/* Maximum size of the export encoding of an RSA public key.
439418
* Assumes that the public exponent is less than 2^32.
440419
*
441-
* SubjectPublicKeyInfo ::= SEQUENCE {
442-
* algorithm AlgorithmIdentifier,
443-
* subjectPublicKey BIT STRING } -- contains RSAPublicKey
444-
* AlgorithmIdentifier ::= SEQUENCE {
445-
* algorithm OBJECT IDENTIFIER,
446-
* parameters NULL }
447420
* RSAPublicKey ::= SEQUENCE {
448421
* modulus INTEGER, -- n
449422
* publicExponent INTEGER } -- e
450423
*
451-
* - 3 * 4 bytes of SEQUENCE overhead;
452-
* - 1 + 1 + 9 bytes of algorithm (RSA OID);
453-
* - 2 bytes of NULL;
454-
* - 4 bytes of BIT STRING overhead;
424+
* - 4 bytes of SEQUENCE overhead;
455425
* - n : INTEGER;
456426
* - 7 bytes for the public exponent.
457427
*/
458428
#define PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits) \
459-
(PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) + 36)
429+
(PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) + 11)
460430

461431
/* Maximum size of the export encoding of an RSA key pair.
462432
* Assumes thatthe public exponent is less than 2^32 and that the size
@@ -523,26 +493,16 @@
523493

524494
/* Maximum size of the export encoding of an ECC public key.
525495
*
526-
* SubjectPublicKeyInfo ::= SEQUENCE {
527-
* algorithm AlgorithmIdentifier,
528-
* subjectPublicKey BIT STRING } -- contains ECPoint
529-
* AlgorithmIdentifier ::= SEQUENCE {
530-
* algorithm OBJECT IDENTIFIER,
531-
* parameters OBJECT IDENTIFIER } -- namedCurve
532-
* ECPoint ::= ...
533-
* -- first 8 bits: 0x04;
534-
* -- then x_P as a `ceiling(m/8)`-byte string, big endian;
535-
* -- then y_P as a `ceiling(m/8)`-byte string, big endian;
536-
* -- where `m` is the bit size associated with the curve.
537-
*
538-
* - 2 * 4 bytes of SEQUENCE overhead;
539-
* - 1 + 1 + 7 bytes of algorithm (id-ecPublicKey OID);
540-
* - 1 + 1 + 12 bytes of namedCurve OID;
541-
* - 4 bytes of BIT STRING overhead;
542-
* - 1 byte + 2 * point size in ECPoint.
496+
* The representation of an ECC public key is:
497+
* - The byte 0x04;
498+
* - `x_P` as a `ceiling(m/8)`-byte string, big-endian;
499+
* - `y_P` as a `ceiling(m/8)`-byte string, big-endian;
500+
* - where m is the bit size associated with the curve.
501+
*
502+
* - 1 byte + 2 * point size.
543503
*/
544504
#define PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits) \
545-
(2 * PSA_BITS_TO_BYTES(key_bits) + 36)
505+
(2 * PSA_BITS_TO_BYTES(key_bits) + 1)
546506

547507
/* Maximum size of the export encoding of an ECC key pair.
548508
*

0 commit comments

Comments
 (0)