New macro PSA_KEY_LIFETIME_IS_READ_ONLY
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
90dfc35643
commit
d133bb2909
3 changed files with 28 additions and 0 deletions
|
@ -2020,6 +2020,26 @@
|
||||||
(PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) == \
|
(PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) == \
|
||||||
PSA_KEY_PERSISTENCE_VOLATILE)
|
PSA_KEY_PERSISTENCE_VOLATILE)
|
||||||
|
|
||||||
|
/** Whether a key lifetime indicates that the key is read-only.
|
||||||
|
*
|
||||||
|
* Read-only keys cannot be created or destroyed through the PSA Crypto API.
|
||||||
|
* They must be created through platform-specific means that bypass the API.
|
||||||
|
*
|
||||||
|
* Some platforms may offer ways to destroy read-only keys. For example,
|
||||||
|
* a platform with multiple levels of privilege may expose a key to an
|
||||||
|
* application without allowing that application to destroy the key, in
|
||||||
|
* which case it may show the key a view of the key metadata where the
|
||||||
|
* lifetime is read-only.
|
||||||
|
*
|
||||||
|
* \param lifetime The lifetime value to query (value of type
|
||||||
|
* ::psa_key_lifetime_t).
|
||||||
|
*
|
||||||
|
* \return \c 1 if the key is read-only, otherwise \c 0.
|
||||||
|
*/
|
||||||
|
#define PSA_KEY_LIFETIME_IS_READ_ONLY(lifetime) \
|
||||||
|
(PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) == \
|
||||||
|
PSA_KEY_PERSISTENCE_READ_ONLY)
|
||||||
|
|
||||||
/** Construct a lifetime from a persistence level and a location.
|
/** Construct a lifetime from a persistence level and a location.
|
||||||
*
|
*
|
||||||
* \param persistence The persistence level
|
* \param persistence The persistence level
|
||||||
|
|
|
@ -363,6 +363,9 @@ lifetime:PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(2, PSA_KEY_LOCATION_LOCA
|
||||||
Lifetime: 254, local storage
|
Lifetime: 254, local storage
|
||||||
lifetime:PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(254, PSA_KEY_LOCATION_LOCAL_STORAGE):0:254:PSA_KEY_LOCATION_LOCAL_STORAGE
|
lifetime:PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(254, PSA_KEY_LOCATION_LOCAL_STORAGE):0:254:PSA_KEY_LOCATION_LOCAL_STORAGE
|
||||||
|
|
||||||
|
Lifetime: read-only, local storage
|
||||||
|
lifetime:PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_PERSISTENCE_READ_ONLY, PSA_KEY_LOCATION_LOCAL_STORAGE):KEY_LIFETIME_IS_READ_ONLY:PSA_KEY_PERSISTENCE_READ_ONLY:PSA_KEY_LOCATION_LOCAL_STORAGE
|
||||||
|
|
||||||
Lifetime: volatile, 0x123456
|
Lifetime: volatile, 0x123456
|
||||||
lifetime:PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_PERSISTENCE_VOLATILE, 0x123456):KEY_LIFETIME_IS_VOLATILE:PSA_KEY_PERSISTENCE_VOLATILE:0x123456
|
lifetime:PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_PERSISTENCE_VOLATILE, 0x123456):KEY_LIFETIME_IS_VOLATILE:PSA_KEY_PERSISTENCE_VOLATILE:0x123456
|
||||||
|
|
||||||
|
@ -374,3 +377,6 @@ lifetime:PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(2, 0x123456):0:2:0x12345
|
||||||
|
|
||||||
Lifetime: 254, 0x123456
|
Lifetime: 254, 0x123456
|
||||||
lifetime:PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(254, 0x123456):0:254:0x123456
|
lifetime:PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(254, 0x123456):0:254:0x123456
|
||||||
|
|
||||||
|
Lifetime: read-only, 0x123456
|
||||||
|
lifetime:PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(PSA_KEY_PERSISTENCE_READ_ONLY, 0x123456):KEY_LIFETIME_IS_READ_ONLY:PSA_KEY_PERSISTENCE_READ_ONLY:0x123456
|
||||||
|
|
|
@ -59,6 +59,7 @@
|
||||||
* lifetime classification macro PSA_KEY_LIFETIME_IS_xxx. The name of the
|
* lifetime classification macro PSA_KEY_LIFETIME_IS_xxx. The name of the
|
||||||
* flag is the name of the classification macro without the PSA_ prefix. */
|
* flag is the name of the classification macro without the PSA_ prefix. */
|
||||||
#define KEY_LIFETIME_IS_VOLATILE ( 1u << 0 )
|
#define KEY_LIFETIME_IS_VOLATILE ( 1u << 0 )
|
||||||
|
#define KEY_LIFETIME_IS_READ_ONLY ( 1u << 1 )
|
||||||
|
|
||||||
#define TEST_CLASSIFICATION_MACRO( flag, alg, flags ) \
|
#define TEST_CLASSIFICATION_MACRO( flag, alg, flags ) \
|
||||||
do \
|
do \
|
||||||
|
@ -688,6 +689,7 @@ void lifetime( int lifetime_arg, int classification_flags,
|
||||||
unsigned flags = classification_flags;
|
unsigned flags = classification_flags;
|
||||||
|
|
||||||
TEST_CLASSIFICATION_MACRO( KEY_LIFETIME_IS_VOLATILE, lifetime, flags );
|
TEST_CLASSIFICATION_MACRO( KEY_LIFETIME_IS_VOLATILE, lifetime, flags );
|
||||||
|
TEST_CLASSIFICATION_MACRO( KEY_LIFETIME_IS_READ_ONLY, lifetime, flags );
|
||||||
|
|
||||||
TEST_EQUAL( PSA_KEY_LIFETIME_GET_PERSISTENCE( lifetime ), persistence );
|
TEST_EQUAL( PSA_KEY_LIFETIME_GET_PERSISTENCE( lifetime ), persistence );
|
||||||
TEST_EQUAL( PSA_KEY_LIFETIME_GET_LOCATION( lifetime ), location );
|
TEST_EQUAL( PSA_KEY_LIFETIME_GET_LOCATION( lifetime ), location );
|
||||||
|
|
Loading…
Reference in a new issue