blob: 18c677a89108f6127c96d8e1b70a98b0753c96b1 [file] [log] [blame]
Aditya Deshpande045b3702023-02-20 17:08:30 +00001/*
2 * Driver entry points for p256-m
3 */
4/*
5 * Copyright The Mbed TLS Contributors
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may
9 * not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
Aditya Deshpandee41f7e42023-01-12 16:29:02 +000021#ifndef P256M_DRIVER_ENTRYPOINTS_H
22#define P256M_DRIVER_ENTRYPOINTS_H
23
24#if defined(MBEDTLS_P256M_EXAMPLE_DRIVER_ENABLED)
25#ifndef PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
26#define PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT
27#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
28#endif /* MBEDTLS_P256M_EXAMPLE_DRIVER_ENABLED */
29
30#include "psa/crypto_types.h"
31
Aditya Deshpandee41f7e42023-01-12 16:29:02 +000032/** Generate SECP256R1 ECC Key Pair.
33 * Interface function which calls the p256-m key generation function and
34 * places it in the key buffer provided by the caller (mbed TLS) in the
35 * correct format. For a SECP256R1 curve this is the 32 bit private key.
36 *
37 * \param[in] attributes The attributes of the key to use for the
38 * operation.
39 * \param[out] key_buffer The buffer to contain the key data in
40 * output format upon successful return.
41 * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
42 * \param[out] key_buffer_length The length of the data written in \p
43 * key_buffer in bytes.
44 *
45 * \retval #PSA_SUCCESS
46 * Success. Keypair generated and stored in buffer.
47 * \retval #PSA_ERROR_NOT_SUPPORTED
48 * \retval #PSA_ERROR_GENERIC_ERROR
49 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
50 */
Aditya Deshpande695e44b2023-01-23 14:59:29 +000051psa_status_t p256_transparent_generate_key(
Aditya Deshpandee41f7e42023-01-12 16:29:02 +000052 const psa_key_attributes_t *attributes,
53 uint8_t *key_buffer,
54 size_t key_buffer_size,
Aditya Deshpandeac363d82023-03-21 18:56:31 +000055 size_t *key_buffer_length);
Aditya Deshpandee41f7e42023-01-12 16:29:02 +000056
57/** Perform raw key agreement using p256-m's ECDH implementation
58 * \param[in] attributes The attributes of the key to use for the
59 * operation.
60 * \param[in] key_buffer The buffer containing the private key
61 * in the format specified by PSA.
62 * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
63 * \param[in] alg A key agreement algorithm that is
64 * compatible with the type of the key.
65 * \param[in] peer_key The buffer containing the peer's public
66 * key in format specified by PSA.
67 * \param[in] peer_key_length Size of the \p peer_key buffer in
68 * bytes.
69 * \param[out] shared_secret The buffer to which the shared secret
70 * is to be written.
71 * \param[in] shared_secret_size Size of the \p shared_secret buffer in
72 * bytes.
73 * \param[out] shared_secret_length On success, the number of bytes that
74 * make up the returned shared secret.
75 * \retval #PSA_SUCCESS
76 * Success. Shared secret successfully calculated.
77 * \retval #PSA_ERROR_NOT_SUPPORTED
78 */
Aditya Deshpande695e44b2023-01-23 14:59:29 +000079psa_status_t p256_transparent_key_agreement(
Aditya Deshpandee41f7e42023-01-12 16:29:02 +000080 const psa_key_attributes_t *attributes,
81 const uint8_t *key_buffer,
82 size_t key_buffer_size,
83 psa_algorithm_t alg,
84 const uint8_t *peer_key,
85 size_t peer_key_length,
86 uint8_t *shared_secret,
87 size_t shared_secret_size,
Aditya Deshpandeac363d82023-03-21 18:56:31 +000088 size_t *shared_secret_length);
Aditya Deshpandee41f7e42023-01-12 16:29:02 +000089
90/** Sign an already-calculated hash with a private key using p256-m's ECDSA
91 * implementation
92 * \param[in] attributes The attributes of the key to use for the
93 * operation.
94 * \param[in] key_buffer The buffer containing the private key
95 * in the format specified by PSA.
96 * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
97 * \param[in] alg A signature algorithm that is compatible
98 * with the type of the key.
99 * \param[in] hash The hash to sign.
100 * \param[in] hash_length Size of the \p hash buffer in bytes.
101 * \param[out] signature Buffer where signature is to be written.
102 * \param[in] signature_size Size of the \p signature buffer in bytes.
103 * \param[out] signature_length On success, the number of bytes
104 * that make up the returned signature value.
105 *
106 * \retval #PSA_SUCCESS
107 * Success. Hash was signed successfully.
108 * respectively of the key.
109 * \retval #PSA_ERROR_NOT_SUPPORTED
110 */
Aditya Deshpande695e44b2023-01-23 14:59:29 +0000111psa_status_t p256_transparent_sign_hash(
Aditya Deshpandee41f7e42023-01-12 16:29:02 +0000112 const psa_key_attributes_t *attributes,
113 const uint8_t *key_buffer,
114 size_t key_buffer_size,
115 psa_algorithm_t alg,
116 const uint8_t *hash,
117 size_t hash_length,
118 uint8_t *signature,
119 size_t signature_size,
Aditya Deshpandeac363d82023-03-21 18:56:31 +0000120 size_t *signature_length);
Aditya Deshpandee41f7e42023-01-12 16:29:02 +0000121
122/** Verify the signature of a hash using a SECP256R1 public key using p256-m's
123 * ECDSA implementation.
124 *
125 * \note p256-m expects a 64 byte public key, but the contents of the key
126 buffer may be the 32 byte keypair representation or the 65 byte
127 public key representation. As a result, this function calls
128 psa_driver_wrapper_export_public_key() to ensure the public key
129 can be passed to p256-m.
130 *
131 * \param[in] attributes The attributes of the key to use for the
132 * operation.
133 *
134 * \param[in] key_buffer The buffer containing the key
135 * in the format specified by PSA.
136 * \param[in] key_buffer_size Size of the \p key_buffer buffer in bytes.
137 * \param[in] alg A signature algorithm that is compatible with
138 * the type of the key.
139 * \param[in] hash The hash whose signature is to be
140 * verified.
141 * \param[in] hash_length Size of the \p hash buffer in bytes.
142 * \param[in] signature Buffer containing the signature to verify.
143 * \param[in] signature_length Size of the \p signature buffer in bytes.
144 *
145 * \retval #PSA_SUCCESS
146 * The signature is valid.
147 * \retval #PSA_ERROR_INVALID_SIGNATURE
148 * The calculation was performed successfully, but the passed
149 * signature is not a valid signature.
150 * \retval #PSA_ERROR_NOT_SUPPORTED
151 */
Aditya Deshpande695e44b2023-01-23 14:59:29 +0000152psa_status_t p256_transparent_verify_hash(
Aditya Deshpandee41f7e42023-01-12 16:29:02 +0000153 const psa_key_attributes_t *attributes,
154 const uint8_t *key_buffer,
155 size_t key_buffer_size,
156 psa_algorithm_t alg,
157 const uint8_t *hash,
158 size_t hash_length,
159 const uint8_t *signature,
Aditya Deshpandeac363d82023-03-21 18:56:31 +0000160 size_t signature_length);
Aditya Deshpandee41f7e42023-01-12 16:29:02 +0000161
162#endif /* P256M_DRIVER_ENTRYPOINTS_H */