blob: bf6b18ded9524fc13363ae9cf513370f7b3985c5 [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 */
18 //no-check-names
19psa_status_t p256m_to_psa_error( int ret );
20
21
22/** Generate SECP256R1 ECC Key Pair.
23 * Interface function which calls the p256-m key generation function and
24 * places it in the key buffer provided by the caller (mbed TLS) in the
25 * correct format. For a SECP256R1 curve this is the 32 bit private key.
26 *
27 * \param[in] attributes The attributes of the key to use for the
28 * operation.
29 * \param[out] key_buffer The buffer to contain the key data in
30 * output format upon successful return.
31 * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
32 * \param[out] key_buffer_length The length of the data written in \p
33 * key_buffer in bytes.
34 *
35 * \retval #PSA_SUCCESS
36 * Success. Keypair generated and stored in buffer.
37 * \retval #PSA_ERROR_NOT_SUPPORTED
38 * \retval #PSA_ERROR_GENERIC_ERROR
39 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
40 */
41 //no-check-names
42psa_status_t p256m_transparent_generate_key(
43 const psa_key_attributes_t *attributes,
44 uint8_t *key_buffer,
45 size_t key_buffer_size,
46 size_t *key_buffer_length );
47
48/** Perform raw key agreement using p256-m's ECDH implementation
49 * \param[in] attributes The attributes of the key to use for the
50 * operation.
51 * \param[in] key_buffer The buffer containing the private key
52 * in the format specified by PSA.
53 * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
54 * \param[in] alg A key agreement algorithm that is
55 * compatible with the type of the key.
56 * \param[in] peer_key The buffer containing the peer's public
57 * key in format specified by PSA.
58 * \param[in] peer_key_length Size of the \p peer_key buffer in
59 * bytes.
60 * \param[out] shared_secret The buffer to which the shared secret
61 * is to be written.
62 * \param[in] shared_secret_size Size of the \p shared_secret buffer in
63 * bytes.
64 * \param[out] shared_secret_length On success, the number of bytes that
65 * make up the returned shared secret.
66 * \retval #PSA_SUCCESS
67 * Success. Shared secret successfully calculated.
68 * \retval #PSA_ERROR_NOT_SUPPORTED
69 */
70 //no-check-names
71psa_status_t p256m_transparent_key_agreement(
72 const psa_key_attributes_t *attributes,
73 const uint8_t *key_buffer,
74 size_t key_buffer_size,
75 psa_algorithm_t alg,
76 const uint8_t *peer_key,
77 size_t peer_key_length,
78 uint8_t *shared_secret,
79 size_t shared_secret_size,
80 size_t *shared_secret_length );
81
82/** Sign an already-calculated hash with a private key using p256-m's ECDSA
83 * implementation
84 * \param[in] attributes The attributes of the key to use for the
85 * operation.
86 * \param[in] key_buffer The buffer containing the private key
87 * in the format specified by PSA.
88 * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
89 * \param[in] alg A signature algorithm that is compatible
90 * with the type of the key.
91 * \param[in] hash The hash to sign.
92 * \param[in] hash_length Size of the \p hash buffer in bytes.
93 * \param[out] signature Buffer where signature is to be written.
94 * \param[in] signature_size Size of the \p signature buffer in bytes.
95 * \param[out] signature_length On success, the number of bytes
96 * that make up the returned signature value.
97 *
98 * \retval #PSA_SUCCESS
99 * Success. Hash was signed successfully.
100 * respectively of the key.
101 * \retval #PSA_ERROR_NOT_SUPPORTED
102 */
103//no-check-names
104psa_status_t p256m_transparent_sign_hash(
105 const psa_key_attributes_t *attributes,
106 const uint8_t *key_buffer,
107 size_t key_buffer_size,
108 psa_algorithm_t alg,
109 const uint8_t *hash,
110 size_t hash_length,
111 uint8_t *signature,
112 size_t signature_size,
113 size_t *signature_length );
114
115/** Verify the signature of a hash using a SECP256R1 public key using p256-m's
116 * ECDSA implementation.
117 *
118 * \note p256-m expects a 64 byte public key, but the contents of the key
119 buffer may be the 32 byte keypair representation or the 65 byte
120 public key representation. As a result, this function calls
121 psa_driver_wrapper_export_public_key() to ensure the public key
122 can be passed to p256-m.
123 *
124 * \param[in] attributes The attributes of the key to use for the
125 * operation.
126 *
127 * \param[in] key_buffer The buffer containing the key
128 * in the format specified by PSA.
129 * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
130 * \param[in] alg A signature algorithm that is compatible with
131 * the type of the key.
132 * \param[in] hash The hash whose signature is to be
133 * verified.
134 * \param[in] hash_length Size of the \p hash buffer in bytes.
135 * \param[in] signature Buffer containing the signature to verify.
136 * \param[in] signature_length Size of the \p signature buffer in bytes.
137 *
138 * \retval #PSA_SUCCESS
139 * The signature is valid.
140 * \retval #PSA_ERROR_INVALID_SIGNATURE
141 * The calculation was performed successfully, but the passed
142 * signature is not a valid signature.
143 * \retval #PSA_ERROR_NOT_SUPPORTED
144 */
145psa_status_t p256m_transparent_verify_hash(
146 const psa_key_attributes_t *attributes,
147 const uint8_t *key_buffer,
148 size_t key_buffer_size,
149 psa_algorithm_t alg,
150 const uint8_t *hash,
151 size_t hash_length,
152 const uint8_t *signature,
153 size_t signature_length );
154
155#endif /* P256M_DRIVER_ENTRYPOINTS_H */