Skip to content

Commit cfe2c48

Browse files
committed
Add missing definitions to TF-M PSA headers
1 parent 4a0fc4a commit cfe2c48

File tree

4 files changed

+168
-0
lines changed

4 files changed

+168
-0
lines changed

platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_types.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,34 @@
4343
typedef int32_t psa_status_t;
4444
#endif
4545

46+
/** Encoding of identifiers of persistent keys.
47+
*
48+
* - Applications may freely choose key identifiers in the range
49+
* #PSA_KEY_ID_USER_MIN to #PSA_KEY_ID_USER_MAX.
50+
* - Implementations may define additional key identifiers in the range
51+
* #PSA_KEY_ID_VENDOR_MIN to #PSA_KEY_ID_VENDOR_MAX.
52+
* - 0 is reserved as an invalid key identifier.
53+
* - Key identifiers outside these ranges are reserved for future use.
54+
*/
55+
typedef uint32_t psa_key_id_t;
56+
57+
#if !defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
58+
typedef psa_key_id_t mbedtls_svc_key_id_t;
59+
60+
#else /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
61+
/* Implementation-specific: The Mbed Cryptography library can be built as
62+
* part of a multi-client service that exposes the PSA Cryptograpy API in each
63+
* client and encodes the client identity in the key identifier argument of
64+
* functions such as psa_open_key().
65+
*/
66+
typedef struct
67+
{
68+
psa_key_id_t key_id;
69+
mbedtls_key_owner_id_t owner;
70+
} mbedtls_svc_key_id_t;
71+
72+
#endif /* !MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
73+
4674
/**@}*/
4775

4876
/** \defgroup crypto_types Key and algorithm types

platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/psa/crypto_values.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,4 +1782,56 @@
17821782

17831783
/**@}*/
17841784

1785+
1786+
#if !defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
1787+
1788+
#define MBEDTLS_SVC_KEY_ID_INIT ( (psa_key_id_t)0 )
1789+
#define MBEDTLS_SVC_KEY_ID_GET_KEY_ID( id ) ( id )
1790+
#define MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( id ) ( 0 )
1791+
1792+
/** Utility to initialize a key identifier at runtime.
1793+
*
1794+
* \param unused Unused parameter.
1795+
* \param key_id Identifier of the key.
1796+
*/
1797+
static inline mbedtls_svc_key_id_t mbedtls_svc_key_id_make(
1798+
unsigned int unused, psa_key_id_t key_id )
1799+
{
1800+
(void)unused;
1801+
1802+
return( key_id );
1803+
}
1804+
1805+
/** Compare two key identifiers.
1806+
*
1807+
* \param id1 First key identifier.
1808+
* \param id2 Second key identifier.
1809+
*
1810+
* \return Non-zero if the two key identifier are equal, zero otherwise.
1811+
*/
1812+
static inline int mbedtls_svc_key_id_equal( mbedtls_svc_key_id_t id1,
1813+
mbedtls_svc_key_id_t id2 )
1814+
{
1815+
return( id1 == id2 );
1816+
}
1817+
1818+
/** Check whether a key identifier is null.
1819+
*
1820+
* \param key Key identifier.
1821+
*
1822+
* \return Non-zero if the key identifier is null, zero otherwise.
1823+
*/
1824+
static inline int mbedtls_svc_key_id_is_null( mbedtls_svc_key_id_t key )
1825+
{
1826+
return( key == 0 );
1827+
}
1828+
1829+
#else /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
1830+
1831+
#define MBEDTLS_SVC_KEY_ID_INIT ( (mbedtls_svc_key_id_t){ 0, 0 } )
1832+
#define MBEDTLS_SVC_KEY_ID_GET_KEY_ID( id ) ( ( id ).key_id )
1833+
#define MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( id ) ( ( id ).owner )
1834+
1835+
#endif
1836+
17851837
#endif /* PSA_CRYPTO_VALUES_H */

platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_V1_0/include/psa/crypto_types.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,23 @@ typedef struct psa_key_attributes_s psa_key_attributes_t;
319319
/** \brief Encoding of the step of a key derivation. */
320320
typedef uint16_t psa_key_derivation_step_t;
321321

322+
#if !defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
323+
typedef psa_key_id_t mbedtls_svc_key_id_t;
324+
325+
#else /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
326+
/* Implementation-specific: The Mbed Cryptography library can be built as
327+
* part of a multi-client service that exposes the PSA Cryptograpy API in each
328+
* client and encodes the client identity in the key identifier argument of
329+
* functions such as psa_open_key().
330+
*/
331+
typedef struct
332+
{
333+
psa_key_id_t key_id;
334+
mbedtls_key_owner_id_t owner;
335+
} mbedtls_svc_key_id_t;
336+
337+
#endif /* !MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
338+
322339
/**@}*/
323340

324341
#endif /* PSA_CRYPTO_TYPES_H */

platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_V1_0/include/psa/crypto_values.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,26 @@
983983
*/
984984
#define PSA_ALG_CBC_NO_PADDING ((psa_algorithm_t)0x04600100)
985985

986+
/** The Electronic Code Book (ECB) mode of a block cipher, with no padding.
987+
*
988+
* \warning ECB mode does not protect the confidentiality of the encrypted data
989+
* except in extremely narrow circumstances. It is recommended that applications
990+
* only use ECB if they need to construct an operating mode that the
991+
* implementation does not provide. Implementations are encouraged to provide
992+
* the modes that applications need in preference to supporting direct access
993+
* to ECB.
994+
*
995+
* The underlying block cipher is determined by the key type.
996+
*
997+
* This symmetric cipher mode can only be used with messages whose lengths are a
998+
* multiple of the block size of the chosen block cipher.
999+
*
1000+
* ECB mode does not accept an initialization vector (IV). When using a
1001+
* multi-part cipher operation with this algorithm, psa_cipher_generate_iv()
1002+
* and psa_cipher_set_iv() must not be called.
1003+
*/
1004+
#define PSA_ALG_ECB_NO_PADDING ((psa_algorithm_t)0x04404400)
1005+
9861006
/** The CBC block cipher chaining mode with PKCS#7 padding.
9871007
*
9881008
* The underlying block cipher is determined by the key type.
@@ -1777,4 +1797,55 @@
17771797
*/
17781798
#define PSA_ECC_FAMILY_MONTGOMERY ((psa_ecc_family_t) 0x41)
17791799

1800+
#if !defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
1801+
1802+
#define MBEDTLS_SVC_KEY_ID_INIT ( (psa_key_id_t)0 )
1803+
#define MBEDTLS_SVC_KEY_ID_GET_KEY_ID( id ) ( id )
1804+
#define MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( id ) ( 0 )
1805+
1806+
/** Utility to initialize a key identifier at runtime.
1807+
*
1808+
* \param unused Unused parameter.
1809+
* \param key_id Identifier of the key.
1810+
*/
1811+
static inline mbedtls_svc_key_id_t mbedtls_svc_key_id_make(
1812+
unsigned int unused, psa_key_id_t key_id )
1813+
{
1814+
(void)unused;
1815+
1816+
return( key_id );
1817+
}
1818+
1819+
/** Compare two key identifiers.
1820+
*
1821+
* \param id1 First key identifier.
1822+
* \param id2 Second key identifier.
1823+
*
1824+
* \return Non-zero if the two key identifier are equal, zero otherwise.
1825+
*/
1826+
static inline int mbedtls_svc_key_id_equal( mbedtls_svc_key_id_t id1,
1827+
mbedtls_svc_key_id_t id2 )
1828+
{
1829+
return( id1 == id2 );
1830+
}
1831+
1832+
/** Check whether a key identifier is null.
1833+
*
1834+
* \param key Key identifier.
1835+
*
1836+
* \return Non-zero if the key identifier is null, zero otherwise.
1837+
*/
1838+
static inline int mbedtls_svc_key_id_is_null( mbedtls_svc_key_id_t key )
1839+
{
1840+
return( key == 0 );
1841+
}
1842+
1843+
#else /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
1844+
1845+
#define MBEDTLS_SVC_KEY_ID_INIT ( (mbedtls_svc_key_id_t){ 0, 0 } )
1846+
#define MBEDTLS_SVC_KEY_ID_GET_KEY_ID( id ) ( ( id ).key_id )
1847+
#define MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( id ) ( ( id ).owner )
1848+
1849+
#endif /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
1850+
17801851
#endif /* PSA_CRYPTO_VALUES_H */

0 commit comments

Comments
 (0)