removed unused weak functions
Updated code to use lifetime value for vendor instead of vendor keytype
diff --git a/include/psa/crypto_extra.h b/include/psa/crypto_extra.h
index 23d7c8a..a469959 100644
--- a/include/psa/crypto_extra.h
+++ b/include/psa/crypto_extra.h
@@ -29,114 +29,45 @@
*/
#ifndef PSA_CRYPTO_EXTRA_H
-#define PSA_CRYPTO_EXTRA_H
+ #define PSA_CRYPTO_EXTRA_H
-#include "mbedtls/platform_util.h"
+ #include "mbedtls/platform_util.h"
-#ifdef __cplusplus
+ #ifdef __cplusplus
extern "C" {
-#endif
+ #endif
/* UID for secure storage seed */
-#define PSA_CRYPTO_ITS_RANDOM_SEED_UID 0xFFFFFF52
+ #define PSA_CRYPTO_ITS_RANDOM_SEED_UID 0xFFFFFF52
/*
* Deprecated PSA Crypto error code definitions
*/
-#if !defined(MBEDTLS_DEPRECATED_REMOVED)
-#define PSA_ERROR_UNKNOWN_ERROR \
- MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_GENERIC_ERROR )
-#endif
+ #if !defined(MBEDTLS_DEPRECATED_REMOVED)
+ #define PSA_ERROR_UNKNOWN_ERROR \
+ MBEDTLS_DEPRECATED_NUMERIC_CONSTANT(PSA_ERROR_GENERIC_ERROR)
+ #endif
-#if !defined(MBEDTLS_DEPRECATED_REMOVED)
-#define PSA_ERROR_OCCUPIED_SLOT \
- MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_ALREADY_EXISTS )
-#endif
+ #if !defined(MBEDTLS_DEPRECATED_REMOVED)
+ #define PSA_ERROR_OCCUPIED_SLOT \
+ MBEDTLS_DEPRECATED_NUMERIC_CONSTANT(PSA_ERROR_ALREADY_EXISTS)
+ #endif
-#if !defined(MBEDTLS_DEPRECATED_REMOVED)
-#define PSA_ERROR_EMPTY_SLOT \
- MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_DOES_NOT_EXIST )
-#endif
+ #if !defined(MBEDTLS_DEPRECATED_REMOVED)
+ #define PSA_ERROR_EMPTY_SLOT \
+ MBEDTLS_DEPRECATED_NUMERIC_CONSTANT(PSA_ERROR_DOES_NOT_EXIST)
+ #endif
-#if !defined(MBEDTLS_DEPRECATED_REMOVED)
-#define PSA_ERROR_INSUFFICIENT_CAPACITY \
- MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_INSUFFICIENT_DATA )
-#endif
+ #if !defined(MBEDTLS_DEPRECATED_REMOVED)
+ #define PSA_ERROR_INSUFFICIENT_CAPACITY \
+ MBEDTLS_DEPRECATED_NUMERIC_CONSTANT(PSA_ERROR_INSUFFICIENT_DATA)
+ #endif
/** \addtogroup attributes
* @{
*/
/**
- * \brief Sign a hash or short message with a vendor defined private key.
- *
- * Note that to perform a hash-and-sign signature algorithm, you must
- * first calculate the hash by calling psa_hash_setup(), psa_hash_update()
- * and psa_hash_finish(). Then pass the resulting hash as the \p hash
- * parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg)
- * to determine the hash algorithm to use.
- *
- * \param handle Handle to the key to use for the operation.
- * It must be an asymmetric key pair.
- * \param alg A signature algorithm that is compatible with
- * the type of \p handle.
- * \param[in] hash The hash or message to sign.
- * \param hash_length Size of the \p hash buffer in bytes.
- * \param[out] signature Buffer where the signature is to be written.
- * \param signature_size Size of the \p signature buffer in bytes.
- * \param[out] signature_length On success, the number of bytes
- * that make up the returned signature value.
- *
- * \retval #PSA_SUCCESS
- * \retval #PSA_ERROR_BUFFER_TOO_SMALL
- * The size of the \p signature buffer is too small. You can
- * determine a sufficient buffer size by calling
- * #PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg)
- * where \c key_type and \c key_bits are the type and bit-size
- * respectively of \p handle.
- * \retval #PSA_ERROR_NOT_SUPPORTED
- * \retval Implementation dependent
- */
-psa_status_t psa_asymmetric_sign_vendor(psa_key_handle_t handle,
- psa_algorithm_t alg,
- const uint8_t * hash,
- size_t hash_length,
- uint8_t * signature,
- size_t signature_size,
- size_t * signature_length);
-
-/**
- * \brief Verify the signature a hash or short message using a vendor defined public key.
- *
- * Note that to perform a hash-and-sign signature algorithm, you must
- * first calculate the hash by calling psa_hash_setup(), psa_hash_update()
- * and psa_hash_finish(). Then pass the resulting hash as the \p hash
- * parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg)
- * to determine the hash algorithm to use.
- *
- * \param handle Handle to the key to use for the operation.
- * It must be a public key or an asymmetric key pair.
- * \param alg A signature algorithm that is compatible with
- * the type of \p handle.
- * \param[in] hash The hash or message whose signature is to be
- * verified.
- * \param hash_length Size of the \p hash buffer in bytes.
- * \param[in] signature Buffer containing the signature to verify.
- * \param signature_length Size of the \p signature buffer in bytes.
- *
- * \retval #PSA_SUCCESS
- * The signature is valid.
- * \retval #PSA_ERROR_INVALID_SIGNATURE
- * \retval Implementation dependent
- */
-psa_status_t psa_asymmetric_verify_vendor(psa_key_handle_t handle,
- psa_algorithm_t alg,
- const uint8_t * hash,
- size_t hash_length,
- uint8_t * signature,
- size_t * signature_length);
-
-/**
* \brief Generate symmetric key of vendor defined format.
*
* \warning This function **can** fail! Callers MUST check the return status
@@ -237,7 +168,7 @@
return( attributes->core.policy.alg2 );
}
-#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
+ #if defined(MBEDTLS_PSA_CRYPTO_SE_C)
/** Retrieve the slot number where a key is stored.
*
@@ -358,7 +289,7 @@
*
* This is an Mbed TLS extension.
*/
-void mbedtls_psa_crypto_free( void );
+void mbedtls_psa_crypto_free(void);
/** \brief Statistics about
* resource consumption related to the PSA keystore.
@@ -396,7 +327,7 @@
* between the application and the keystore, the service may or
* may not expose this function.
*/
-void mbedtls_psa_get_stats( mbedtls_psa_stats_t *stats );
+void mbedtls_psa_get_stats(mbedtls_psa_stats_t * stats);
/**
* \brief Inject an initial entropy seed for the random generator into
@@ -479,7 +410,7 @@
* string. The length of the byte string is the length of the base prime `p`
* in bytes.
*/
-#define PSA_KEY_TYPE_DSA_PUBLIC_KEY ((psa_key_type_t)0x60020000)
+ #define PSA_KEY_TYPE_DSA_PUBLIC_KEY ((psa_key_type_t) 0x60020000)
/** DSA key pair (private and public key).
*
@@ -497,10 +428,10 @@
* Add 1 to the resulting integer and use this as the private key *x*.
*
*/
-#define PSA_KEY_TYPE_DSA_KEY_PAIR ((psa_key_type_t)0x70020000)
+ #define PSA_KEY_TYPE_DSA_KEY_PAIR ((psa_key_type_t) 0x70020000)
/** Whether a key type is an DSA key (pair or public-only). */
-#define PSA_KEY_TYPE_IS_DSA(type) \
+ #define PSA_KEY_TYPE_IS_DSA(type) \
(PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) == PSA_KEY_TYPE_DSA_PUBLIC_KEY)
#define PSA_ALG_DSA_BASE ((psa_algorithm_t)0x10040000)
@@ -518,7 +449,7 @@
* \return Unspecified if \p hash_alg is not a supported
* hash algorithm.
*/
-#define PSA_ALG_DSA(hash_alg) \
+ #define PSA_ALG_DSA(hash_alg) \
(PSA_ALG_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
#define PSA_ALG_DETERMINISTIC_DSA_BASE ((psa_algorithm_t)0x10050000)
#define PSA_ALG_DSA_DETERMINISTIC_FLAG ((psa_algorithm_t)0x00010000)
@@ -536,14 +467,14 @@
* \return Unspecified if \p hash_alg is not a supported
* hash algorithm.
*/
-#define PSA_ALG_DETERMINISTIC_DSA(hash_alg) \
+ #define PSA_ALG_DETERMINISTIC_DSA(hash_alg) \
(PSA_ALG_DETERMINISTIC_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
-#define PSA_ALG_IS_DSA(alg) \
- (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_DSA_DETERMINISTIC_FLAG) == \
+ #define PSA_ALG_IS_DSA(alg) \
+ (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_DSA_DETERMINISTIC_FLAG) == \
PSA_ALG_DSA_BASE)
-#define PSA_ALG_DSA_IS_DETERMINISTIC(alg) \
+ #define PSA_ALG_DSA_IS_DETERMINISTIC(alg) \
(((alg) & PSA_ALG_DSA_DETERMINISTIC_FLAG) != 0)
-#define PSA_ALG_IS_DETERMINISTIC_DSA(alg) \
+ #define PSA_ALG_IS_DETERMINISTIC_DSA(alg) \
(PSA_ALG_IS_DSA(alg) && PSA_ALG_DSA_IS_DETERMINISTIC(alg))
#define PSA_ALG_IS_RANDOMIZED_DSA(alg) \
(PSA_ALG_IS_DSA(alg) && !PSA_ALG_DSA_IS_DETERMINISTIC(alg))
@@ -551,9 +482,9 @@
/* We need to expand the sample definition of this macro from
* the API definition. */
-#undef PSA_ALG_IS_HASH_AND_SIGN
-#define PSA_ALG_IS_HASH_AND_SIGN(alg) \
- (PSA_ALG_IS_RSA_PSS(alg) || PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || \
+ #undef PSA_ALG_IS_HASH_AND_SIGN
+ #define PSA_ALG_IS_HASH_AND_SIGN(alg) \
+ (PSA_ALG_IS_RSA_PSS(alg) || PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || \
PSA_ALG_IS_DSA(alg) || PSA_ALG_IS_ECDSA(alg))
/**@}*/
@@ -638,10 +569,10 @@
* \retval #PSA_ERROR_NOT_SUPPORTED
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
*/
-psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t *attributes,
- psa_key_type_t type,
- const uint8_t *data,
- size_t data_length);
+psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t * attributes,
+ psa_key_type_t type,
+ const uint8_t * data,
+ size_t data_length);
/**
* \brief Get domain parameters for a key.
@@ -670,7 +601,7 @@
const psa_key_attributes_t *attributes,
uint8_t *data,
size_t data_size,
- size_t *data_length);
+ size_t * data_length);
/** Safe output buffer size for psa_get_key_domain_parameters().
*
@@ -697,20 +628,20 @@
* If the parameters are not valid, the
* return value is unspecified.
*/
-#define PSA_KEY_DOMAIN_PARAMETERS_SIZE(key_type, key_bits) \
- (PSA_KEY_TYPE_IS_RSA(key_type) ? sizeof(int) : \
- PSA_KEY_TYPE_IS_DH(key_type) ? PSA_DH_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) : \
+ #define PSA_KEY_DOMAIN_PARAMETERS_SIZE(key_type, key_bits) \
+ (PSA_KEY_TYPE_IS_RSA(key_type) ? sizeof(int) : \
+ PSA_KEY_TYPE_IS_DH(key_type) ? PSA_DH_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) : \
PSA_KEY_TYPE_IS_DSA(key_type) ? PSA_DSA_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) : \
0)
-#define PSA_DH_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) \
+ #define PSA_DH_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) \
(4 + (PSA_BITS_TO_BYTES(key_bits) + 5) * 3 /*without optional parts*/)
-#define PSA_DSA_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) \
+ #define PSA_DSA_KEY_DOMAIN_PARAMETERS_SIZE(key_bits) \
(4 + (PSA_BITS_TO_BYTES(key_bits) + 5) * 2 /*p, g*/ + 34 /*q*/)
/**@}*/
-#ifdef __cplusplus
+ #ifdef __cplusplus
}
-#endif
+ #endif
-#endif /* PSA_CRYPTO_EXTRA_H */
+#endif /* PSA_CRYPTO_EXTRA_H */
diff --git a/include/psa/crypto_struct.h b/include/psa/crypto_struct.h
index f177d5d..48803a3 100644
--- a/include/psa/crypto_struct.h
+++ b/include/psa/crypto_struct.h
@@ -86,25 +86,25 @@
{
unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
#if defined(MBEDTLS_MD2_C)
- mbedtls_md2_context md2;
+ mbedtls_md2_context md2;
#endif
#if defined(MBEDTLS_MD4_C)
- mbedtls_md4_context md4;
+ mbedtls_md4_context md4;
#endif
#if defined(MBEDTLS_MD5_C)
- mbedtls_md5_context md5;
+ mbedtls_md5_context md5;
#endif
#if defined(MBEDTLS_RIPEMD160_C)
- mbedtls_ripemd160_context ripemd160;
+ mbedtls_ripemd160_context ripemd160;
#endif
#if defined(MBEDTLS_SHA1_C)
- mbedtls_sha1_context sha1;
+ mbedtls_sha1_context sha1;
#endif
#if defined(MBEDTLS_SHA256_C)
- mbedtls_sha256_context sha256;
+ mbedtls_sha256_context sha256;
#endif
#if defined(MBEDTLS_SHA512_C)
- mbedtls_sha512_context sha512;
+ mbedtls_sha512_context sha512;
#endif
} ctx;
};
@@ -112,26 +112,26 @@
#define PSA_HASH_OPERATION_INIT {0, {0}}
static inline struct psa_hash_operation_s psa_hash_operation_init( void )
{
- const struct psa_hash_operation_s v = PSA_HASH_OPERATION_INIT;
- return( v );
-}
+ const struct psa_hash_operation_s v = PSA_HASH_OPERATION_INIT;
+ return (v);
+ }
#if defined(MBEDTLS_MD_C)
-typedef struct
-{
+ typedef struct
+ {
/** The hash context. */
struct psa_hash_operation_s hash_ctx;
/** The HMAC part of the context. */
uint8_t opad[PSA_HMAC_MAX_HASH_BLOCK_SIZE];
-} psa_hmac_internal_data;
+ } psa_hmac_internal_data;
#endif /* MBEDTLS_MD_C */
-struct psa_mac_operation_s
-{
- psa_algorithm_t alg;
- unsigned int key_set : 1;
- unsigned int iv_required : 1;
- unsigned int iv_set : 1;
+ struct psa_mac_operation_s
+ {
+ psa_algorithm_t alg;
+ unsigned int key_set : 1;
+ unsigned int iv_required : 1;
+ unsigned int iv_set : 1;
unsigned int has_input : 1;
unsigned int is_sign : 1;
uint8_t mac_size;
@@ -139,10 +139,10 @@
{
unsigned dummy; /* Make the union non-empty even with no supported algorithms. */
#if defined(MBEDTLS_MD_C)
- psa_hmac_internal_data hmac;
+ psa_hmac_internal_data hmac;
#endif
#if defined(MBEDTLS_CMAC_C)
- mbedtls_cipher_context_t cmac;
+ mbedtls_cipher_context_t cmac;
#endif
} ctx;
};
@@ -150,15 +150,15 @@
#define PSA_MAC_OPERATION_INIT {0, 0, 0, 0, 0, 0, 0, {0}}
static inline struct psa_mac_operation_s psa_mac_operation_init( void )
{
- const struct psa_mac_operation_s v = PSA_MAC_OPERATION_INIT;
- return( v );
-}
+ const struct psa_mac_operation_s v = PSA_MAC_OPERATION_INIT;
+ return (v);
+ }
-struct psa_cipher_operation_s
-{
- psa_algorithm_t alg;
- unsigned int key_set : 1;
- unsigned int iv_required : 1;
+ struct psa_cipher_operation_s
+ {
+ psa_algorithm_t alg;
+ unsigned int key_set : 1;
+ unsigned int iv_required : 1;
unsigned int iv_set : 1;
uint8_t iv_size;
uint8_t block_size;
@@ -172,14 +172,14 @@
#define PSA_CIPHER_OPERATION_INIT {0, 0, 0, 0, 0, 0, {0}}
static inline struct psa_cipher_operation_s psa_cipher_operation_init( void )
{
- const struct psa_cipher_operation_s v = PSA_CIPHER_OPERATION_INIT;
- return( v );
-}
+ const struct psa_cipher_operation_s v = PSA_CIPHER_OPERATION_INIT;
+ return (v);
+ }
-struct psa_aead_operation_s
-{
- psa_algorithm_t alg;
- unsigned int key_set : 1;
+ struct psa_aead_operation_s
+ {
+ psa_algorithm_t alg;
+ unsigned int key_set : 1;
unsigned int iv_set : 1;
uint8_t iv_size;
uint8_t block_size;
@@ -193,66 +193,66 @@
#define PSA_AEAD_OPERATION_INIT {0, 0, 0, 0, 0, {0}}
static inline struct psa_aead_operation_s psa_aead_operation_init( void )
{
- const struct psa_aead_operation_s v = PSA_AEAD_OPERATION_INIT;
- return( v );
-}
+ const struct psa_aead_operation_s v = PSA_AEAD_OPERATION_INIT;
+ return (v);
+ }
#if defined(MBEDTLS_MD_C)
-typedef struct
-{
- uint8_t *info;
- size_t info_length;
- psa_hmac_internal_data hmac;
- uint8_t prk[PSA_HASH_MAX_SIZE];
- uint8_t output_block[PSA_HASH_MAX_SIZE];
+ typedef struct
+ {
+ uint8_t *info;
+ size_t info_length;
+ psa_hmac_internal_data hmac;
+ uint8_t prk[PSA_HASH_MAX_SIZE];
+ uint8_t output_block[PSA_HASH_MAX_SIZE];
#if PSA_HASH_MAX_SIZE > 0xff
#error "PSA_HASH_MAX_SIZE does not fit in uint8_t"
#endif
- uint8_t offset_in_block;
- uint8_t block_number;
- unsigned int state : 2;
- unsigned int info_set : 1;
-} psa_hkdf_key_derivation_t;
+ uint8_t offset_in_block;
+ uint8_t block_number;
+ unsigned int state : 2;
+ unsigned int info_set : 1;
+ } psa_hkdf_key_derivation_t;
#endif /* MBEDTLS_MD_C */
#if defined(MBEDTLS_MD_C)
-typedef enum
-{
- TLS12_PRF_STATE_INIT, /* no input provided */
- TLS12_PRF_STATE_SEED_SET, /* seed has been set */
- TLS12_PRF_STATE_KEY_SET, /* key has been set */
- TLS12_PRF_STATE_LABEL_SET, /* label has been set */
- TLS12_PRF_STATE_OUTPUT /* output has been started */
-} psa_tls12_prf_key_derivation_state_t;
+ typedef enum
+ {
+ TLS12_PRF_STATE_INIT, /* no input provided */
+ TLS12_PRF_STATE_SEED_SET, /* seed has been set */
+ TLS12_PRF_STATE_KEY_SET, /* key has been set */
+ TLS12_PRF_STATE_LABEL_SET, /* label has been set */
+ TLS12_PRF_STATE_OUTPUT /* output has been started */
+ } psa_tls12_prf_key_derivation_state_t;
-typedef struct psa_tls12_prf_key_derivation_s
-{
+ typedef struct psa_tls12_prf_key_derivation_s
+ {
#if PSA_HASH_MAX_SIZE > 0xff
#error "PSA_HASH_MAX_SIZE does not fit in uint8_t"
#endif
- /* Indicates how many bytes in the current HMAC block have
+ /* Indicates how many bytes in the current HMAC block have
* not yet been read by the user. */
- uint8_t left_in_block;
+ uint8_t left_in_block;
- /* The 1-based number of the block. */
- uint8_t block_number;
+ /* The 1-based number of the block. */
+ uint8_t block_number;
- psa_tls12_prf_key_derivation_state_t state;
+ psa_tls12_prf_key_derivation_state_t state;
- uint8_t *seed;
- size_t seed_length;
- uint8_t *label;
- size_t label_length;
- psa_hmac_internal_data hmac;
- uint8_t Ai[PSA_HASH_MAX_SIZE];
+ uint8_t *seed;
+ size_t seed_length;
+ uint8_t *label;
+ size_t label_length;
+ psa_hmac_internal_data hmac;
+ uint8_t Ai[PSA_HASH_MAX_SIZE];
- /* `HMAC_hash( prk, A(i) + seed )` in the notation of RFC 5246, Sect. 5. */
- uint8_t output_block[PSA_HASH_MAX_SIZE];
-} psa_tls12_prf_key_derivation_t;
+ /* `HMAC_hash( prk, A(i) + seed )` in the notation of RFC 5246, Sect. 5. */
+ uint8_t output_block[PSA_HASH_MAX_SIZE];
+ } psa_tls12_prf_key_derivation_t;
#endif /* MBEDTLS_MD_C */
-struct psa_key_derivation_s
+ struct psa_key_derivation_s
{
psa_algorithm_t alg;
size_t capacity;
@@ -261,41 +261,41 @@
/* Make the union non-empty even with no supported algorithms. */
uint8_t dummy;
#if defined(MBEDTLS_MD_C)
- psa_hkdf_key_derivation_t hkdf;
- psa_tls12_prf_key_derivation_t tls12_prf;
+ psa_hkdf_key_derivation_t hkdf;
+ psa_tls12_prf_key_derivation_t tls12_prf;
#endif
- } ctx;
+ } ctx;
};
/* This only zeroes out the first byte in the union, the rest is unspecified. */
#define PSA_KEY_DERIVATION_OPERATION_INIT {0, 0, {0}}
static inline struct psa_key_derivation_s psa_key_derivation_operation_init( void )
{
- const struct psa_key_derivation_s v = PSA_KEY_DERIVATION_OPERATION_INIT;
- return( v );
-}
+ const struct psa_key_derivation_s v = PSA_KEY_DERIVATION_OPERATION_INIT;
+ return (v);
+ }
-struct psa_key_policy_s
-{
- psa_key_usage_t usage;
- psa_algorithm_t alg;
- psa_algorithm_t alg2;
+ struct psa_key_policy_s
+ {
+ psa_key_usage_t usage;
+ psa_algorithm_t alg;
+ psa_algorithm_t alg2;
};
typedef struct psa_key_policy_s psa_key_policy_t;
#define PSA_KEY_POLICY_INIT {0, 0, 0}
static inline struct psa_key_policy_s psa_key_policy_init( void )
{
- const struct psa_key_policy_s v = PSA_KEY_POLICY_INIT;
- return( v );
-}
+ const struct psa_key_policy_s v = PSA_KEY_POLICY_INIT;
+ return (v);
+ }
-/* The type used internally for key sizes.
+ /* The type used internally for key sizes.
* Public interfaces use size_t, but internally we use a smaller type. */
-typedef uint16_t psa_key_bits_t;
+ typedef uint16_t psa_key_bits_t;
/* The maximum value of the type used to represent bit-sizes.
* This is used to mark an invalid key size. */
-#define PSA_KEY_BITS_TOO_LARGE ( (psa_key_bits_t) ( -1 ) )
+#define PSA_KEY_BITS_TOO_LARGE ((psa_key_bits_t)(-1))
/* The maximum size of a key in bits.
* Currently defined as the maximum that can be represented, rounded down
* to a whole number of bytes.
@@ -303,49 +303,49 @@
* conditionals. */
#define PSA_MAX_KEY_BITS 0xfff8
-/** A mask of flags that can be stored in key attributes.
+ /** 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;
+ typedef uint16_t psa_key_attributes_flag_t;
-#define MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER \
- ( (psa_key_attributes_flag_t) 0x0001 )
+#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 | \
- 0 )
+#define MBEDTLS_PSA_KA_MASK_EXTERNAL_ONLY ( \
+ MBEDTLS_PSA_KA_FLAG_HAS_SLOT_NUMBER | \
+ 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 )
+#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;
+ 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;
psa_key_attributes_flag_t flags;
} psa_core_key_attributes_t;
#define PSA_CORE_KEY_ATTRIBUTES_INIT {0, 0, PSA_KEY_ID_INIT, PSA_KEY_POLICY_INIT, 0, 0}
struct psa_key_attributes_s
-{
- psa_core_key_attributes_t core;
+ {
+ psa_core_key_attributes_t core;
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
- psa_key_slot_number_t slot_number;
+ psa_key_slot_number_t slot_number;
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
- void *domain_parameters;
- size_t domain_parameters_size;
+ void *domain_parameters;
+ size_t domain_parameters_size;
};
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
@@ -354,116 +354,116 @@
#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;
- return( v );
-}
-
-static inline void psa_set_key_id(psa_key_attributes_t *attributes,
- psa_key_id_t id)
-{
- attributes->core.id = id;
- if( attributes->core.lifetime == PSA_KEY_LIFETIME_VOLATILE )
- attributes->core.lifetime = PSA_KEY_LIFETIME_PERSISTENT;
-}
-
-static inline psa_key_id_t psa_get_key_id(
- const psa_key_attributes_t *attributes)
-{
- return( attributes->core.id );
-}
-
-static inline void psa_set_key_lifetime(psa_key_attributes_t *attributes,
- psa_key_lifetime_t lifetime)
-{
- attributes->core.lifetime = lifetime;
- if( lifetime == PSA_KEY_LIFETIME_VOLATILE )
+ static inline struct psa_key_attributes_s psa_key_attributes_init(void)
{
+ const struct psa_key_attributes_s v = PSA_KEY_ATTRIBUTES_INIT;
+ return (v);
+ }
+
+ static inline void psa_set_key_id(psa_key_attributes_t *attributes,
+ psa_key_id_t id)
+ {
+ attributes->core.id = id;
+ if (attributes->core.lifetime == PSA_KEY_LIFETIME_VOLATILE)
+ attributes->core.lifetime = PSA_KEY_LIFETIME_PERSISTENT;
+ }
+
+ static inline psa_key_id_t psa_get_key_id(
+ const psa_key_attributes_t *attributes)
+ {
+ return (attributes->core.id);
+ }
+
+ static inline void psa_set_key_lifetime(psa_key_attributes_t *attributes,
+ psa_key_lifetime_t lifetime)
+ {
+ attributes->core.lifetime = lifetime;
+ if (PSA_KEY_LIFETIME_IS_VOLATILE(lifetime))
+ {
#ifdef MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER
- attributes->core.id.key_id = 0;
- attributes->core.id.owner = 0;
+ attributes->core.id.key_id = 0;
+ attributes->core.id.owner = 0;
#else
attributes->core.id = 0;
#endif
+ }
}
-}
-static inline psa_key_lifetime_t psa_get_key_lifetime(
- const psa_key_attributes_t *attributes)
-{
- return( attributes->core.lifetime );
-}
+ static inline psa_key_lifetime_t psa_get_key_lifetime(
+ const psa_key_attributes_t *attributes)
+ {
+ return (attributes->core.lifetime);
+ }
-static inline void psa_set_key_usage_flags(psa_key_attributes_t *attributes,
- psa_key_usage_t usage_flags)
-{
- attributes->core.policy.usage = usage_flags;
-}
+ static inline void psa_set_key_usage_flags(psa_key_attributes_t *attributes,
+ psa_key_usage_t usage_flags)
+ {
+ attributes->core.policy.usage = usage_flags;
+ }
-static inline psa_key_usage_t psa_get_key_usage_flags(
- const psa_key_attributes_t *attributes)
-{
- return( attributes->core.policy.usage );
-}
+ static inline psa_key_usage_t psa_get_key_usage_flags(
+ const psa_key_attributes_t *attributes)
+ {
+ return (attributes->core.policy.usage);
+ }
-static inline void psa_set_key_algorithm(psa_key_attributes_t *attributes,
- psa_algorithm_t alg)
-{
- attributes->core.policy.alg = alg;
-}
+ static inline void psa_set_key_algorithm(psa_key_attributes_t *attributes,
+ psa_algorithm_t alg)
+ {
+ attributes->core.policy.alg = alg;
+ }
-static inline psa_algorithm_t psa_get_key_algorithm(
- const psa_key_attributes_t *attributes)
-{
- return( attributes->core.policy.alg );
-}
+ static inline psa_algorithm_t psa_get_key_algorithm(
+ const psa_key_attributes_t *attributes)
+ {
+ return (attributes->core.policy.alg);
+ }
-/* This function is declared in crypto_extra.h, which comes after this
+ /* This function is declared in crypto_extra.h, which comes after this
* header file, but we need the function here, so repeat the declaration. */
-psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t *attributes,
- psa_key_type_t type,
- const uint8_t *data,
- size_t data_length);
+ psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t *attributes,
+ psa_key_type_t type,
+ const uint8_t *data,
+ size_t data_length);
-static inline void psa_set_key_type(psa_key_attributes_t *attributes,
- psa_key_type_t type)
-{
- if( attributes->domain_parameters == NULL )
+ static inline void psa_set_key_type(psa_key_attributes_t *attributes,
+ psa_key_type_t type)
{
- /* Common case: quick path */
- attributes->core.type = type;
- }
- else
- {
- /* Call the bigger function to free the old domain paramteres.
+ if (attributes->domain_parameters == NULL)
+ {
+ /* Common case: quick path */
+ attributes->core.type = type;
+ }
+ else
+ {
+ /* Call the bigger function to free the old domain paramteres.
* Ignore any errors which may arise due to type requiring
* non-default domain parameters, since this function can't
* report errors. */
- (void) psa_set_key_domain_parameters( attributes, type, NULL, 0 );
+ (void)psa_set_key_domain_parameters(attributes, type, NULL, 0);
+ }
}
-}
-static inline psa_key_type_t psa_get_key_type(
- const psa_key_attributes_t *attributes)
-{
- return( attributes->core.type );
-}
+ static inline psa_key_type_t psa_get_key_type(
+ const psa_key_attributes_t *attributes)
+ {
+ return (attributes->core.type);
+ }
-static inline void psa_set_key_bits(psa_key_attributes_t *attributes,
- size_t bits)
-{
- if( bits > PSA_MAX_KEY_BITS )
- attributes->core.bits = PSA_KEY_BITS_TOO_LARGE;
- else
- attributes->core.bits = (psa_key_bits_t) bits;
-}
+ static inline void psa_set_key_bits(psa_key_attributes_t *attributes,
+ size_t bits)
+ {
+ if (bits > PSA_MAX_KEY_BITS)
+ attributes->core.bits = PSA_KEY_BITS_TOO_LARGE;
+ else
+ attributes->core.bits = (psa_key_bits_t)bits;
+ }
-static inline size_t psa_get_key_bits(
- const psa_key_attributes_t *attributes)
-{
- return( attributes->core.bits );
-}
+ static inline size_t psa_get_key_bits(
+ const psa_key_attributes_t *attributes)
+ {
+ return (attributes->core.bits);
+ }
#ifdef __cplusplus
}
diff --git a/include/psa/crypto_values.h b/include/psa/crypto_values.h
index 5b4a310..24b2277 100644
--- a/include/psa/crypto_values.h
+++ b/include/psa/crypto_values.h
@@ -438,12 +438,6 @@
/** Elliptic curve public key. */
#define PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve) \
(PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE | (curve))
-/** Elliptic curve key pair (Vendor defined format). */
-#define PSA_KEY_TYPE_ECC_KEY_PAIR_VENDOR(curve) \
- (PSA_KEY_TYPE_VENDOR_FLAG | PSA_KEY_TYPE_ECC_KEY_PAIR_BASE | (curve))
-/** Elliptic curve public key (Vendor defined format). */
-#define PSA_KEY_TYPE_ECC_PUBLIC_KEY_VENDOR(curve) \
- (PSA_KEY_TYPE_VENDOR_FLAG | PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE | (curve))
/** Whether a key type is an elliptic curve key (pair or public-only). */
#define PSA_KEY_TYPE_IS_ECC(type) \
@@ -458,24 +452,10 @@
(((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \
PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE)
-/** Whether a key type is an elliptic curve key (pair or public-only). */
-#define PSA_KEY_TYPE_IS_ECC_VENDOR(type) \
- ((PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) & \
- ~PSA_KEY_TYPE_ECC_CURVE_MASK) == (PSA_KEY_TYPE_VENDOR_FLAG | PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE))
-/** Whether a key type is an elliptic curve key pair. */
-#define PSA_KEY_TYPE_IS_ECC_KEY_PAIR_VENDOR(type) \
- (((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \
- (PSA_KEY_TYPE_VENDOR_FLAG | PSA_KEY_TYPE_ECC_KEY_PAIR_BASE))
-/** Whether a key type is an elliptic curve public key. */
-#define PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY_VENDOR(type) \
- (((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \
- (PSA_KEY_TYPE_VENDOR_FLAG | PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE))
/** Extract the curve from an elliptic curve key type. */
#define PSA_KEY_TYPE_GET_CURVE(type) \
((psa_ecc_curve_t)(PSA_KEY_TYPE_IS_ECC(type) ? ((type)&PSA_KEY_TYPE_ECC_CURVE_MASK) : 0))
/** Extract the curve from an elliptic curve key type. */
-#define PSA_KEY_TYPE_GET_CURVE_VENDOR(type) \
- ((psa_ecc_curve_t)(PSA_KEY_TYPE_IS_ECC_VENDOR(type) ? ((type)&PSA_KEY_TYPE_ECC_CURVE_MASK) : 0))
/* The encoding of curve identifiers is currently aligned with the
* TLS Supported Groups Registry (formerly known as the
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index a9c265c..aa4ab73 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -1493,7 +1493,7 @@
{
psa_status_t status;
- if( attributes->core.lifetime != PSA_KEY_LIFETIME_VOLATILE )
+ if( PSA_KEY_LIFETIME_IS_PERSISTENT (attributes->core.lifetime))
{
status = psa_validate_persistent_key_parameters(
attributes->core.lifetime, attributes->core.id,
@@ -3336,21 +3336,21 @@
// The weakly linked function "psa_asymmetric_sign_vendor_weak" which returns "PSA_ERROR_NOT_SUPPORTED" will be linked if
// the vendor does not provide a definition for "psa_asymmetric_sign_vendor"
-psa_status_t psa_asymmetric_sign_vendor( psa_key_handle_t handle,
+psa_status_t psa_asymmetric_sign_vendor( psa_key_slot_t * slot,
psa_algorithm_t alg,
const uint8_t *hash,
size_t hash_length,
uint8_t *signature,
size_t signature_size,
size_t *signature_length ) __attribute__ ((weak, alias("psa_asymmetric_sign_vendor_weak")));
-psa_status_t psa_asymmetric_sign_vendor_weak( psa_key_handle_t handle,
+psa_status_t psa_asymmetric_sign_vendor_weak( psa_key_slot_t * slot,
psa_algorithm_t alg,
const uint8_t *hash,
size_t hash_length,
uint8_t *signature,
size_t signature_size,
size_t *signature_length );
-psa_status_t psa_asymmetric_sign_vendor_weak( psa_key_handle_t handle,
+psa_status_t psa_asymmetric_sign_vendor_weak( psa_key_slot_t * slot,
psa_algorithm_t alg,
const uint8_t *hash,
size_t hash_length,
@@ -3358,7 +3358,7 @@
size_t signature_size,
size_t *signature_length )
{
- (void) handle;
+ (void) slot ;
(void) alg;
(void)hash;
(void)hash_length;
@@ -3413,11 +3413,11 @@
}
else
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
-if (PSA_KEY_TYPE_IS_VENDOR_DEFINED(slot->attr.type))
+ if (PSA_KEY_LIFETIME_IS_VENDOR_DEFINED(slot->attr.lifetime))
{
- status = psa_asymmetric_sign_vendor(handle,alg,
- hash, hash_length,
- signature, signature_size,
+ status = psa_asymmetric_sign_vendor(slot,alg,
+ hash, hash_length,
+ signature, signature_size,
signature_length );
}
else
@@ -3476,26 +3476,26 @@
}
// The weakly linked function "psa_asymmetric_verify_vendor_weak" which returns "PSA_ERROR_NOT_SUPPORTED" will be linked if
// the vendor does not provide a definition for "psa_asymmetric_verify_vendor"
-psa_status_t psa_asymmetric_verify_vendor( psa_key_handle_t handle,
+psa_status_t psa_asymmetric_verify_vendor( psa_key_slot_t * slot,
psa_algorithm_t alg,
const uint8_t *hash,
size_t hash_length,
uint8_t *signature,
- size_t *signature_length ) __attribute__ ((weak, alias("psa_asymmetric_verify_vendor_weak")));
-psa_status_t psa_asymmetric_verify_vendor_weak( psa_key_handle_t handle,
+ size_t signature_length ) __attribute__ ((weak, alias("psa_asymmetric_verify_vendor_weak")));
+psa_status_t psa_asymmetric_verify_vendor_weak( psa_key_slot_t * slot,
psa_algorithm_t alg,
const uint8_t *hash,
size_t hash_length,
uint8_t *signature,
- size_t *signature_length );
-psa_status_t psa_asymmetric_verify_vendor_weak( psa_key_handle_t handle,
+ size_t signature_length );
+psa_status_t psa_asymmetric_verify_vendor_weak( psa_key_slot_t * slot,
psa_algorithm_t alg,
const uint8_t *hash,
size_t hash_length,
uint8_t *signature,
- size_t *signature_length )
+ size_t signature_length )
{
- (void) handle;
+ (void) slot;
(void) alg;
(void)hash;
(void)hash_length;
@@ -3537,11 +3537,11 @@
}
else
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
-if (PSA_KEY_TYPE_IS_VENDOR_DEFINED(slot->attr.type))
+if (PSA_KEY_LIFETIME_IS_VENDOR_DEFINED(slot->attr.lifetime))
{
- status = psa_asymmetric_verify_vendor(handle,alg,
+ return( psa_asymmetric_verify_vendor(slot,alg,
hash, hash_length,
- signature, signature_length );
+ signature, signature_length ) );
}
else
#if defined(MBEDTLS_RSA_C)
@@ -3826,7 +3826,7 @@
if( ret != 0 )
goto exit;
- if (PSA_KEY_TYPE_IS_VENDOR_DEFINED(slot->attr.type))
+ if (PSA_KEY_LIFETIME_IS_VENDOR_DEFINED(slot->attr.lifetime))
{
status = psa_cipher_setup_vendor(operation, handle, alg);
}
@@ -3885,7 +3885,7 @@
operation->iv_size = 12;
#endif
- if (PSA_KEY_TYPE_IS_VENDOR_DEFINED(slot->attr.type))
+ if (PSA_KEY_LIFETIME_IS_VENDOR_DEFINED(slot->attr.lifetime))
{
status = psa_cipher_setup_vendor(operation, handle, alg);
}
@@ -5660,7 +5660,7 @@
}
else
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
- if (PSA_KEY_TYPE_IS_VENDOR_DEFINED(slot->attr.type))
+ if (PSA_KEY_LIFETIME_IS_VENDOR_DEFINED(slot->attr.lifetime))
{
status = psa_generate_key_vendor(slot, attributes->core.bits,
attributes->domain_parameters, attributes->domain_parameters_size);
diff --git a/library/psa_crypto_core.h b/library/psa_crypto_core.h
index fd09ffb..d587549 100644
--- a/library/psa_crypto_core.h
+++ b/library/psa_crypto_core.h
@@ -165,36 +165,6 @@
const uint8_t * domain_parameters,
size_t domain_parameters_size);
-/**
- * \brief Prepare a slot for vendor defined key type.
- *
- * \warning This function **can** fail! Callers MUST check the return status
- * and MUST NOT use the content of the output buffer if the return
- * status is not #PSA_SUCCESS.
- *
- * \note This function has to be defined by the vendor.
- * A weakly linked version is provided by default and returns
- * PSA_ERROR_NOT_SUPPORTED. Do not use this function directly;
- * to generate a key, use psa_generate_key() instead.
- *
- * \param[in] type Type of symmetric key to be generated.
- * \param[out] output Output buffer for the generated data.
- * \param[out] output_size Number of bytes to generate and output.
- *
- * \retval #PSA_SUCCESS
- * \retval #PSA_ERROR_NOT_SUPPORTED
- * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY
- * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
- * \retval #PSA_ERROR_COMMUNICATION_FAILURE
- * \retval #PSA_ERROR_HARDWARE_FAILURE
- * \retval #PSA_ERROR_CORRUPTION_DETECTED
- * \retval #PSA_ERROR_BAD_STATE
- * The library has not been previously initialized by psa_crypto_init().
- * It is implementation-dependent whether a failure to initialize
- * results in this error code.
- */
-psa_status_t prepare_raw_data_slot_vendor(psa_key_type_t type, size_t bits, struct raw_data *raw);
-
/** Completely wipe a slot in memory, including its policy.
*
* Persistent storage is not affected.
@@ -206,7 +176,77 @@
* already fully wiped.
* \retval PSA_ERROR_CORRUPTION_DETECTED
*/
-psa_status_t psa_wipe_key_slot( psa_key_slot_t *slot );
+
+/**
+ * \brief Sign a hash or short message with a vendor defined private key.
+ *
+ * Note that to perform a hash-and-sign signature algorithm, you must
+ * first calculate the hash by calling psa_hash_setup(), psa_hash_update()
+ * and psa_hash_finish(). Then pass the resulting hash as the \p hash
+ * parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg)
+ * to determine the hash algorithm to use.
+ *
+ * \param slot Key slot to use for the operation.
+ * It must be an asymmetric key pair.
+ * \param alg A signature algorithm that is compatible with
+ * the type of \p handle.
+ * \param[in] hash The hash or message to sign.
+ * \param hash_length Size of the \p hash buffer in bytes.
+ * \param[out] signature Buffer where the signature is to be written.
+ * \param signature_size Size of the \p signature buffer in bytes.
+ * \param[out] signature_length On success, the number of bytes
+ * that make up the returned signature value.
+ *
+ * \retval #PSA_SUCCESS
+ * \retval #PSA_ERROR_BUFFER_TOO_SMALL
+ * The size of the \p signature buffer is too small. You can
+ * determine a sufficient buffer size by calling
+ * #PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg)
+ * where \c key_type and \c key_bits are the type and bit-size
+ * respectively of \p handle.
+ * \retval #PSA_ERROR_NOT_SUPPORTED
+ * \retval Implementation dependent
+ */
+psa_status_t psa_asymmetric_sign_vendor(psa_key_slot_t * slot,
+ psa_algorithm_t alg,
+ const uint8_t * hash,
+ size_t hash_length,
+ uint8_t * signature,
+ size_t signature_size,
+ size_t * signature_length);
+
+/**
+ * \brief Verify the signature a hash or short message using a vendor defined public key.
+ *
+ * Note that to perform a hash-and-sign signature algorithm, you must
+ * first calculate the hash by calling psa_hash_setup(), psa_hash_update()
+ * and psa_hash_finish(). Then pass the resulting hash as the \p hash
+ * parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg)
+ * to determine the hash algorithm to use.
+ *
+ * \param handle Key slot to use for the operation.
+ * It must be a public key or an asymmetric key pair.
+ * \param alg A signature algorithm that is compatible with
+ * the type of \p handle.
+ * \param[in] hash The hash or message whose signature is to be
+ * verified.
+ * \param hash_length Size of the \p hash buffer in bytes.
+ * \param[in] signature Buffer containing the signature to verify.
+ * \param signature_length Size of the \p signature buffer in bytes.
+ *
+ * \retval #PSA_SUCCESS
+ * The signature is valid.
+ * \retval #PSA_ERROR_INVALID_SIGNATURE
+ * \retval Implementation dependent
+ */
+psa_status_t psa_asymmetric_verify_vendor(psa_key_slot_t * slot,
+ psa_algorithm_t alg,
+ const uint8_t * hash,
+ size_t hash_length,
+ uint8_t * signature,
+ size_t signature_length);
+
+psa_status_t psa_wipe_key_slot(psa_key_slot_t * slot);
/** Import key data into a slot.
*