blob: e5eca216bdd7564aa153bb31289fb32cbdfdbdae [file] [log] [blame]
Aditya Deshpandee41f7e42023-01-12 16:29:02 +00001#ifndef P256M_DRIVER_ENTRYPOINTS_H
2#define P256M_DRIVER_ENTRYPOINTS_H
3
4#if defined(MBEDTLS_P256M_EXAMPLE_DRIVER_ENABLED)
5#ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
6#define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
7#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
8#endif /* MBEDTLS_P256M_EXAMPLE_DRIVER_ENABLED */
9
10#include "psa/crypto_types.h"
11
12/** Convert an internal p256-m error code to a PSA error code
13 *
14 * \param ret An error code thrown by p256-m
15 *
16 * \return The corresponding PSA error code
17 */
Aditya Deshpande695e44b2023-01-23 14:59:29 +000018psa_status_t p256_to_psa_error( int ret );
Aditya Deshpandee41f7e42023-01-12 16:29:02 +000019
20
21/** Generate SECP256R1 ECC Key Pair.
22 * Interface function which calls the p256-m key generation function and
23 * places it in the key buffer provided by the caller (mbed TLS) in the
24 * correct format. For a SECP256R1 curve this is the 32 bit private key.
25 *
26 * \param[in] attributes The attributes of the key to use for the
27 * operation.
28 * \param[out] key_buffer The buffer to contain the key data in
29 * output format upon successful return.
30 * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
31 * \param[out] key_buffer_length The length of the data written in \p
32 * key_buffer in bytes.
33 *
34 * \retval #PSA_SUCCESS
35 * Success. Keypair generated and stored in buffer.
36 * \retval #PSA_ERROR_NOT_SUPPORTED
37 * \retval #PSA_ERROR_GENERIC_ERROR
38 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
39 */
Aditya Deshpande695e44b2023-01-23 14:59:29 +000040psa_status_t p256_transparent_generate_key(
Aditya Deshpandee41f7e42023-01-12 16:29:02 +000041 const psa_key_attributes_t *attributes,
42 uint8_t *key_buffer,
43 size_t key_buffer_size,
44 size_t *key_buffer_length );
45
46/** Perform raw key agreement using p256-m's ECDH implementation
47 * \param[in] attributes The attributes of the key to use for the
48 * operation.
49 * \param[in] key_buffer The buffer containing the private key
50 * in the format specified by PSA.
51 * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
52 * \param[in] alg A key agreement algorithm that is
53 * compatible with the type of the key.
54 * \param[in] peer_key The buffer containing the peer's public
55 * key in format specified by PSA.
56 * \param[in] peer_key_length Size of the \p peer_key buffer in
57 * bytes.
58 * \param[out] shared_secret The buffer to which the shared secret
59 * is to be written.
60 * \param[in] shared_secret_size Size of the \p shared_secret buffer in
61 * bytes.
62 * \param[out] shared_secret_length On success, the number of bytes that
63 * make up the returned shared secret.
64 * \retval #PSA_SUCCESS
65 * Success. Shared secret successfully calculated.
66 * \retval #PSA_ERROR_NOT_SUPPORTED
67 */
Aditya Deshpande695e44b2023-01-23 14:59:29 +000068psa_status_t p256_transparent_key_agreement(
Aditya Deshpandee41f7e42023-01-12 16:29:02 +000069 const psa_key_attributes_t *attributes,
70 const uint8_t *key_buffer,
71 size_t key_buffer_size,
72 psa_algorithm_t alg,
73 const uint8_t *peer_key,
74 size_t peer_key_length,
75 uint8_t *shared_secret,
76 size_t shared_secret_size,
77 size_t *shared_secret_length );
78
79/** Sign an already-calculated hash with a private key using p256-m's ECDSA
80 * implementation
81 * \param[in] attributes The attributes of the key to use for the
82 * operation.
83 * \param[in] key_buffer The buffer containing the private key
84 * in the format specified by PSA.
85 * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
86 * \param[in] alg A signature algorithm that is compatible
87 * with the type of the key.
88 * \param[in] hash The hash to sign.
89 * \param[in] hash_length Size of the \p hash buffer in bytes.
90 * \param[out] signature Buffer where signature is to be written.
91 * \param[in] signature_size Size of the \p signature buffer in bytes.
92 * \param[out] signature_length On success, the number of bytes
93 * that make up the returned signature value.
94 *
95 * \retval #PSA_SUCCESS
96 * Success. Hash was signed successfully.
97 * respectively of the key.
98 * \retval #PSA_ERROR_NOT_SUPPORTED
99 */
Aditya Deshpande695e44b2023-01-23 14:59:29 +0000100psa_status_t p256_transparent_sign_hash(
Aditya Deshpandee41f7e42023-01-12 16:29:02 +0000101 const psa_key_attributes_t *attributes,
102 const uint8_t *key_buffer,
103 size_t key_buffer_size,
104 psa_algorithm_t alg,
105 const uint8_t *hash,
106 size_t hash_length,
107 uint8_t *signature,
108 size_t signature_size,
109 size_t *signature_length );
110
111/** Verify the signature of a hash using a SECP256R1 public key using p256-m's
112 * ECDSA implementation.
113 *
114 * \note p256-m expects a 64 byte public key, but the contents of the key
115 buffer may be the 32 byte keypair representation or the 65 byte
116 public key representation. As a result, this function calls
117 psa_driver_wrapper_export_public_key() to ensure the public key
118 can be passed to p256-m.
119 *
120 * \param[in] attributes The attributes of the key to use for the
121 * operation.
122 *
123 * \param[in] key_buffer The buffer containing the key
124 * in the format specified by PSA.
125 * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
126 * \param[in] alg A signature algorithm that is compatible with
127 * the type of the key.
128 * \param[in] hash The hash whose signature is to be
129 * verified.
130 * \param[in] hash_length Size of the \p hash buffer in bytes.
131 * \param[in] signature Buffer containing the signature to verify.
132 * \param[in] signature_length Size of the \p signature buffer in bytes.
133 *
134 * \retval #PSA_SUCCESS
135 * The signature is valid.
136 * \retval #PSA_ERROR_INVALID_SIGNATURE
137 * The calculation was performed successfully, but the passed
138 * signature is not a valid signature.
139 * \retval #PSA_ERROR_NOT_SUPPORTED
140 */
Aditya Deshpande695e44b2023-01-23 14:59:29 +0000141psa_status_t p256_transparent_verify_hash(
Aditya Deshpandee41f7e42023-01-12 16:29:02 +0000142 const psa_key_attributes_t *attributes,
143 const uint8_t *key_buffer,
144 size_t key_buffer_size,
145 psa_algorithm_t alg,
146 const uint8_t *hash,
147 size_t hash_length,
148 const uint8_t *signature,
149 size_t signature_length );
150
151#endif /* P256M_DRIVER_ENTRYPOINTS_H */