Skip to content

Commit 12b2c89

Browse files
committed
PSA/TF-M: support key enrollment algorithm
Add `psa_set_key_enrollment_algorithm()` and `psa_get_key_enrollment_algorithm()` for TF-M targets. Note: This is deprecated and for backward compatibility only. Setting an enrollment algorithm is not recommended, because using the same key with different algorithms can allow some attacks based on arithmetic relations between different computations made with the same key, or can escalate harmless side channels into exploitable ones. Use this function only if it is necessary to support a protocol for which it has been verified that the usage of the key with multiple algorithms is safe.
1 parent 88a38c2 commit 12b2c89

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ struct psa_client_key_attributes_s
3434
uint32_t lifetime;
3535
uint32_t id;
3636
uint32_t alg;
37+
uint32_t alg2;
3738
uint32_t usage;
3839
size_t bits;
3940
uint16_t type;
4041
};
4142

42-
#define PSA_CLIENT_KEY_ATTRIBUTES_INIT {0, 0, 0, 0, 0, 0}
43+
#define PSA_CLIENT_KEY_ATTRIBUTES_INIT {0, 0, 0, 0, 0, 0, 0}
4344

4445
#ifdef __cplusplus
4546
}

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,48 @@ static inline psa_ecc_family_t mbedtls_ecc_group_to_psa( mbedtls_ecp_group_id gr
125125

126126
#endif /* MBEDTLS_ECP_C */
127127

128+
/** \brief Declare the enrollment algorithm for a key.
129+
*
130+
* An operation on a key may indifferently use the algorithm set with
131+
* psa_set_key_algorithm() or with this function.
132+
*
133+
* \param[out] attributes The attribute structure to write to.
134+
* \param alg2 A second algorithm that the key may be used
135+
* for, in addition to the algorithm set with
136+
* psa_set_key_algorithm().
137+
*
138+
* \deprecated This is for backward compatibility only.
139+
* Setting an enrollment algorithm is not recommended, because
140+
* using the same key with different algorithms can allow some
141+
* attacks based on arithmetic relations between different
142+
* computations made with the same key, or can escalate harmless
143+
* side channels into exploitable ones. Use this function only
144+
* if it is necessary to support a protocol for which it has been
145+
* verified that the usage of the key with multiple algorithms
146+
* is safe.
147+
*/
148+
static inline void psa_set_key_enrollment_algorithm(
149+
psa_key_attributes_t *attributes,
150+
psa_algorithm_t alg2)
151+
{
152+
attributes->alg2 = alg2;
153+
}
154+
155+
/** Retrieve the enrollment algorithm policy from key attributes.
156+
*
157+
* \param[in] attributes The key attribute structure to query.
158+
*
159+
* \return The enrollment algorithm stored in the attribute structure.
160+
161+
* \deprecated This is for backward compatibility only.
162+
* Deprecated along with psa_set_key_enrollment_algorithm().
163+
*/
164+
static inline psa_algorithm_t psa_get_key_enrollment_algorithm(
165+
const psa_key_attributes_t *attributes)
166+
{
167+
return attributes->alg2;
168+
}
169+
128170
#ifdef __cplusplus
129171
}
130172
#endif

platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/include/tfm_crypto_defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct tfm_crypto_pack_iovec {
4040
uint16_t step; /*!< Key derivation step */
4141
psa_key_handle_t key_handle; /*!< Key handle */
4242
psa_algorithm_t alg; /*!< Algorithm */
43+
psa_algorithm_t alg2; /*!< Enrollment Algorithm */
4344
uint32_t op_handle; /*!< Frontend context handle associated to a
4445
* multipart operation
4546
*/

0 commit comments

Comments
 (0)