-
Notifications
You must be signed in to change notification settings - Fork 96
Add slot number attribute #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
91e8c33
74f3352
c8000c0
5fe5e27
5a68056
013f547
094dac1
edbed56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,26 +322,57 @@ typedef uint16_t psa_key_bits_t; | |
* conditionals. */ | ||
#define PSA_MAX_KEY_BITS 0xfff8 | ||
|
||
/** A mask of flags that can be stored in key attributes. | ||
* | ||
* This type is also used internally to store flags in slots. Internal | ||
* flags are defined in library/psa_crypto_core.h. Internal flags may have | ||
* the same value as external flags if they are properly handled during | ||
* key creation and in psa_get_key_attributes. | ||
*/ | ||
typedef uint16_t psa_key_attributes_flag_t; | ||
|
||
#define MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER \ | ||
( (psa_key_attributes_flag_t) 0x0001 ) | ||
|
||
/* A mask of key attribute flags used externally only. | ||
* Only meant for internal checks inside the library. */ | ||
#define MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY ( \ | ||
MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER | \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why or it with zero? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we can add/remove flags just by editing their line and not have to modify the surrounding punctuation. |
||
0 ) | ||
|
||
/* A mask of key attribute flags used both internally and externally. | ||
* Currently there aren't any. */ | ||
#define MBEDTLS_PSA_KA_MASK_DUAL_USE ( \ | ||
0 ) | ||
|
||
typedef struct | ||
{ | ||
psa_key_type_t type; | ||
psa_key_lifetime_t lifetime; | ||
psa_key_id_t id; | ||
psa_key_policy_t policy; | ||
psa_key_bits_t bits; | ||
uint16_t flags; | ||
psa_key_attributes_flag_t flags; | ||
} psa_core_key_attributes_t; | ||
|
||
#define PSA_CORE_KEY_ATTRIBUTES_INIT {0, 0, 0, {0, 0, 0}, 0, 0} | ||
|
||
struct psa_key_attributes_s | ||
{ | ||
psa_core_key_attributes_t core; | ||
#if defined(MBEDTLS_PSA_CRYPTO_SE_C) | ||
psa_key_slot_number_t slot_number; | ||
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */ | ||
void *domain_parameters; | ||
size_t domain_parameters_size; | ||
}; | ||
|
||
#if defined(MBEDTLS_PSA_CRYPTO_SE_C) | ||
#define PSA_KEY_ATTRIBUTES_INIT {PSA_CORE_KEY_ATTRIBUTES_INIT, 0, NULL, 0} | ||
#else | ||
#define PSA_KEY_ATTRIBUTES_INIT {PSA_CORE_KEY_ATTRIBUTES_INIT, NULL, 0} | ||
#endif | ||
|
||
static inline struct psa_key_attributes_s psa_key_attributes_init( void ) | ||
{ | ||
const struct psa_key_attributes_s v = PSA_KEY_ATTRIBUTES_INIT; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,14 +56,21 @@ typedef struct | |
/* EC public key or key pair */ | ||
mbedtls_ecp_keypair *ecp; | ||
#endif /* MBEDTLS_ECP_C */ | ||
#if defined(MBEDTLS_PSA_CRYPTO_SE_C) | ||
/* Any key type in a secure element */ | ||
struct se | ||
{ | ||
psa_key_slot_number_t slot_number; | ||
} se; | ||
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */ | ||
} data; | ||
} psa_key_slot_t; | ||
|
||
/* A mask of key attribute flags used only internally. | ||
* Currently there aren't any. */ | ||
#define PSA_KA_MASK_INTERNAL_ONLY ( \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any policy for PSA macros similar to this one with MbedTLS ones? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. Mbed TLS had no internal headers ( |
||
0 ) | ||
|
||
/** Test whether a key slot is occupied. | ||
* | ||
* A key slot is occupied iff the key type is nonzero. This works because | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. Iff = “if and only if” There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, right - Chris has reminded me of this acronym - if and only if. I really don't have it memorized. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be good to reset the slot number to an invalid number here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but there's no invalid slot number at the moment. I'm considering introducing some though, if only to be future-proof. A slot number is 64 bits, maybe we should say that a slot number is 62 bits, reserve values 0xc000000000000000..0xfffffffffffffffe and declare 0xffffffffffffffff to be permanently invalid? This would not remove the need for the HAS_SLOT_NUMBER flag, because 0 is valid.