1a8e1175bSopenharmony_ci/*
2a8e1175bSopenharmony_ci * Test driver for signature functions.
3a8e1175bSopenharmony_ci * Currently supports signing and verifying precalculated hashes, using
4a8e1175bSopenharmony_ci * only deterministic ECDSA on curves secp256r1, secp384r1 and secp521r1.
5a8e1175bSopenharmony_ci */
6a8e1175bSopenharmony_ci/*  Copyright The Mbed TLS Contributors
7a8e1175bSopenharmony_ci *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
8a8e1175bSopenharmony_ci */
9a8e1175bSopenharmony_ci
10a8e1175bSopenharmony_ci#include <test/helpers.h>
11a8e1175bSopenharmony_ci
12a8e1175bSopenharmony_ci#if defined(PSA_CRYPTO_DRIVER_TEST)
13a8e1175bSopenharmony_ci#include "psa/crypto.h"
14a8e1175bSopenharmony_ci#include "psa_crypto_core.h"
15a8e1175bSopenharmony_ci#include "psa_crypto_ecp.h"
16a8e1175bSopenharmony_ci#include "psa_crypto_hash.h"
17a8e1175bSopenharmony_ci#include "psa_crypto_rsa.h"
18a8e1175bSopenharmony_ci#include "mbedtls/ecp.h"
19a8e1175bSopenharmony_ci
20a8e1175bSopenharmony_ci#include "test/drivers/hash.h"
21a8e1175bSopenharmony_ci#include "test/drivers/signature.h"
22a8e1175bSopenharmony_ci#include "test/drivers/hash.h"
23a8e1175bSopenharmony_ci
24a8e1175bSopenharmony_ci#include "mbedtls/ecdsa.h"
25a8e1175bSopenharmony_ci
26a8e1175bSopenharmony_ci#include "test/random.h"
27a8e1175bSopenharmony_ci
28a8e1175bSopenharmony_ci#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
29a8e1175bSopenharmony_ci#include "libtestdriver1/library/psa_crypto_ecp.h"
30a8e1175bSopenharmony_ci#include "libtestdriver1/library/psa_crypto_hash.h"
31a8e1175bSopenharmony_ci#include "libtestdriver1/library/psa_crypto_rsa.h"
32a8e1175bSopenharmony_ci#endif
33a8e1175bSopenharmony_ci
34a8e1175bSopenharmony_ci#include <string.h>
35a8e1175bSopenharmony_ci
36a8e1175bSopenharmony_cimbedtls_test_driver_signature_hooks_t
37a8e1175bSopenharmony_ci    mbedtls_test_driver_signature_sign_hooks = MBEDTLS_TEST_DRIVER_SIGNATURE_INIT;
38a8e1175bSopenharmony_cimbedtls_test_driver_signature_hooks_t
39a8e1175bSopenharmony_ci    mbedtls_test_driver_signature_verify_hooks = MBEDTLS_TEST_DRIVER_SIGNATURE_INIT;
40a8e1175bSopenharmony_ci
41a8e1175bSopenharmony_cipsa_status_t sign_hash(
42a8e1175bSopenharmony_ci    const psa_key_attributes_t *attributes,
43a8e1175bSopenharmony_ci    const uint8_t *key_buffer,
44a8e1175bSopenharmony_ci    size_t key_buffer_size,
45a8e1175bSopenharmony_ci    psa_algorithm_t alg,
46a8e1175bSopenharmony_ci    const uint8_t *hash,
47a8e1175bSopenharmony_ci    size_t hash_length,
48a8e1175bSopenharmony_ci    uint8_t *signature,
49a8e1175bSopenharmony_ci    size_t signature_size,
50a8e1175bSopenharmony_ci    size_t *signature_length)
51a8e1175bSopenharmony_ci{
52a8e1175bSopenharmony_ci    if (attributes->type == PSA_KEY_TYPE_RSA_KEY_PAIR) {
53a8e1175bSopenharmony_ci        if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) ||
54a8e1175bSopenharmony_ci            PSA_ALG_IS_RSA_PSS(alg)) {
55a8e1175bSopenharmony_ci#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
56a8e1175bSopenharmony_ci            (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
57a8e1175bSopenharmony_ci            defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS))
58a8e1175bSopenharmony_ci            return libtestdriver1_mbedtls_psa_rsa_sign_hash(
59a8e1175bSopenharmony_ci                (const libtestdriver1_psa_key_attributes_t *) attributes,
60a8e1175bSopenharmony_ci                key_buffer, key_buffer_size,
61a8e1175bSopenharmony_ci                alg, hash, hash_length,
62a8e1175bSopenharmony_ci                signature, signature_size, signature_length);
63a8e1175bSopenharmony_ci#elif defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
64a8e1175bSopenharmony_ci            defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
65a8e1175bSopenharmony_ci            return mbedtls_psa_rsa_sign_hash(
66a8e1175bSopenharmony_ci                attributes,
67a8e1175bSopenharmony_ci                key_buffer, key_buffer_size,
68a8e1175bSopenharmony_ci                alg, hash, hash_length,
69a8e1175bSopenharmony_ci                signature, signature_size, signature_length);
70a8e1175bSopenharmony_ci#endif
71a8e1175bSopenharmony_ci        } else {
72a8e1175bSopenharmony_ci            return PSA_ERROR_INVALID_ARGUMENT;
73a8e1175bSopenharmony_ci        }
74a8e1175bSopenharmony_ci    } else if (PSA_KEY_TYPE_IS_ECC(attributes->type)) {
75a8e1175bSopenharmony_ci        if (PSA_ALG_IS_ECDSA(alg)) {
76a8e1175bSopenharmony_ci#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
77a8e1175bSopenharmony_ci            (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
78a8e1175bSopenharmony_ci            defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA))
79a8e1175bSopenharmony_ci            return libtestdriver1_mbedtls_psa_ecdsa_sign_hash(
80a8e1175bSopenharmony_ci                (const libtestdriver1_psa_key_attributes_t *) attributes,
81a8e1175bSopenharmony_ci                key_buffer, key_buffer_size,
82a8e1175bSopenharmony_ci                alg, hash, hash_length,
83a8e1175bSopenharmony_ci                signature, signature_size, signature_length);
84a8e1175bSopenharmony_ci#elif defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
85a8e1175bSopenharmony_ci            defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
86a8e1175bSopenharmony_ci            return mbedtls_psa_ecdsa_sign_hash(
87a8e1175bSopenharmony_ci                attributes,
88a8e1175bSopenharmony_ci                key_buffer, key_buffer_size,
89a8e1175bSopenharmony_ci                alg, hash, hash_length,
90a8e1175bSopenharmony_ci                signature, signature_size, signature_length);
91a8e1175bSopenharmony_ci#endif
92a8e1175bSopenharmony_ci        } else {
93a8e1175bSopenharmony_ci            return PSA_ERROR_INVALID_ARGUMENT;
94a8e1175bSopenharmony_ci        }
95a8e1175bSopenharmony_ci    }
96a8e1175bSopenharmony_ci
97a8e1175bSopenharmony_ci    (void) attributes;
98a8e1175bSopenharmony_ci    (void) key_buffer;
99a8e1175bSopenharmony_ci    (void) key_buffer_size;
100a8e1175bSopenharmony_ci    (void) alg;
101a8e1175bSopenharmony_ci    (void) hash;
102a8e1175bSopenharmony_ci    (void) hash_length;
103a8e1175bSopenharmony_ci    (void) signature;
104a8e1175bSopenharmony_ci    (void) signature_size;
105a8e1175bSopenharmony_ci    (void) signature_length;
106a8e1175bSopenharmony_ci    return PSA_ERROR_NOT_SUPPORTED;
107a8e1175bSopenharmony_ci}
108a8e1175bSopenharmony_ci
109a8e1175bSopenharmony_cipsa_status_t verify_hash(
110a8e1175bSopenharmony_ci    const psa_key_attributes_t *attributes,
111a8e1175bSopenharmony_ci    const uint8_t *key_buffer,
112a8e1175bSopenharmony_ci    size_t key_buffer_size,
113a8e1175bSopenharmony_ci    psa_algorithm_t alg,
114a8e1175bSopenharmony_ci    const uint8_t *hash,
115a8e1175bSopenharmony_ci    size_t hash_length,
116a8e1175bSopenharmony_ci    const uint8_t *signature,
117a8e1175bSopenharmony_ci    size_t signature_length)
118a8e1175bSopenharmony_ci{
119a8e1175bSopenharmony_ci    if (PSA_KEY_TYPE_IS_RSA(attributes->type)) {
120a8e1175bSopenharmony_ci        if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) ||
121a8e1175bSopenharmony_ci            PSA_ALG_IS_RSA_PSS(alg)) {
122a8e1175bSopenharmony_ci#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
123a8e1175bSopenharmony_ci            (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
124a8e1175bSopenharmony_ci            defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS))
125a8e1175bSopenharmony_ci            return libtestdriver1_mbedtls_psa_rsa_verify_hash(
126a8e1175bSopenharmony_ci                (const libtestdriver1_psa_key_attributes_t *) attributes,
127a8e1175bSopenharmony_ci                key_buffer, key_buffer_size,
128a8e1175bSopenharmony_ci                alg, hash, hash_length,
129a8e1175bSopenharmony_ci                signature, signature_length);
130a8e1175bSopenharmony_ci#elif defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
131a8e1175bSopenharmony_ci            defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
132a8e1175bSopenharmony_ci            return mbedtls_psa_rsa_verify_hash(
133a8e1175bSopenharmony_ci                attributes,
134a8e1175bSopenharmony_ci                key_buffer, key_buffer_size,
135a8e1175bSopenharmony_ci                alg, hash, hash_length,
136a8e1175bSopenharmony_ci                signature, signature_length);
137a8e1175bSopenharmony_ci#endif
138a8e1175bSopenharmony_ci        } else {
139a8e1175bSopenharmony_ci            return PSA_ERROR_INVALID_ARGUMENT;
140a8e1175bSopenharmony_ci        }
141a8e1175bSopenharmony_ci    } else if (PSA_KEY_TYPE_IS_ECC(attributes->type)) {
142a8e1175bSopenharmony_ci        if (PSA_ALG_IS_ECDSA(alg)) {
143a8e1175bSopenharmony_ci#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
144a8e1175bSopenharmony_ci            (defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
145a8e1175bSopenharmony_ci            defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA))
146a8e1175bSopenharmony_ci            return libtestdriver1_mbedtls_psa_ecdsa_verify_hash(
147a8e1175bSopenharmony_ci                (const libtestdriver1_psa_key_attributes_t *) attributes,
148a8e1175bSopenharmony_ci                key_buffer, key_buffer_size,
149a8e1175bSopenharmony_ci                alg, hash, hash_length,
150a8e1175bSopenharmony_ci                signature, signature_length);
151a8e1175bSopenharmony_ci#elif defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
152a8e1175bSopenharmony_ci            defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
153a8e1175bSopenharmony_ci            return mbedtls_psa_ecdsa_verify_hash(
154a8e1175bSopenharmony_ci                attributes,
155a8e1175bSopenharmony_ci                key_buffer, key_buffer_size,
156a8e1175bSopenharmony_ci                alg, hash, hash_length,
157a8e1175bSopenharmony_ci                signature, signature_length);
158a8e1175bSopenharmony_ci#endif
159a8e1175bSopenharmony_ci        } else {
160a8e1175bSopenharmony_ci            return PSA_ERROR_INVALID_ARGUMENT;
161a8e1175bSopenharmony_ci        }
162a8e1175bSopenharmony_ci    }
163a8e1175bSopenharmony_ci
164a8e1175bSopenharmony_ci    (void) attributes;
165a8e1175bSopenharmony_ci    (void) key_buffer;
166a8e1175bSopenharmony_ci    (void) key_buffer_size;
167a8e1175bSopenharmony_ci    (void) alg;
168a8e1175bSopenharmony_ci    (void) hash;
169a8e1175bSopenharmony_ci    (void) hash_length;
170a8e1175bSopenharmony_ci    (void) signature;
171a8e1175bSopenharmony_ci    (void) signature_length;
172a8e1175bSopenharmony_ci    return PSA_ERROR_NOT_SUPPORTED;
173a8e1175bSopenharmony_ci}
174a8e1175bSopenharmony_ci
175a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_signature_sign_message(
176a8e1175bSopenharmony_ci    const psa_key_attributes_t *attributes,
177a8e1175bSopenharmony_ci    const uint8_t *key_buffer,
178a8e1175bSopenharmony_ci    size_t key_buffer_size,
179a8e1175bSopenharmony_ci    psa_algorithm_t alg,
180a8e1175bSopenharmony_ci    const uint8_t *input,
181a8e1175bSopenharmony_ci    size_t input_length,
182a8e1175bSopenharmony_ci    uint8_t *signature,
183a8e1175bSopenharmony_ci    size_t signature_size,
184a8e1175bSopenharmony_ci    size_t *signature_length)
185a8e1175bSopenharmony_ci{
186a8e1175bSopenharmony_ci    psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
187a8e1175bSopenharmony_ci    size_t hash_length;
188a8e1175bSopenharmony_ci    uint8_t hash[PSA_HASH_MAX_SIZE];
189a8e1175bSopenharmony_ci
190a8e1175bSopenharmony_ci    ++mbedtls_test_driver_signature_sign_hooks.hits;
191a8e1175bSopenharmony_ci
192a8e1175bSopenharmony_ci    if (mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS) {
193a8e1175bSopenharmony_ci        return mbedtls_test_driver_signature_sign_hooks.forced_status;
194a8e1175bSopenharmony_ci    }
195a8e1175bSopenharmony_ci
196a8e1175bSopenharmony_ci    if (mbedtls_test_driver_signature_sign_hooks.forced_output != NULL) {
197a8e1175bSopenharmony_ci        if (mbedtls_test_driver_signature_sign_hooks.forced_output_length > signature_size) {
198a8e1175bSopenharmony_ci            return PSA_ERROR_BUFFER_TOO_SMALL;
199a8e1175bSopenharmony_ci        }
200a8e1175bSopenharmony_ci
201a8e1175bSopenharmony_ci        memcpy(signature, mbedtls_test_driver_signature_sign_hooks.forced_output,
202a8e1175bSopenharmony_ci               mbedtls_test_driver_signature_sign_hooks.forced_output_length);
203a8e1175bSopenharmony_ci        *signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length;
204a8e1175bSopenharmony_ci
205a8e1175bSopenharmony_ci        return PSA_SUCCESS;
206a8e1175bSopenharmony_ci    }
207a8e1175bSopenharmony_ci
208a8e1175bSopenharmony_ci#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
209a8e1175bSopenharmony_ci    defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
210a8e1175bSopenharmony_ci    status = libtestdriver1_mbedtls_psa_hash_compute(
211a8e1175bSopenharmony_ci        PSA_ALG_SIGN_GET_HASH(alg), input, input_length,
212a8e1175bSopenharmony_ci        hash, sizeof(hash), &hash_length);
213a8e1175bSopenharmony_ci#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
214a8e1175bSopenharmony_ci    status = mbedtls_psa_hash_compute(
215a8e1175bSopenharmony_ci        PSA_ALG_SIGN_GET_HASH(alg), input, input_length,
216a8e1175bSopenharmony_ci        hash, sizeof(hash), &hash_length);
217a8e1175bSopenharmony_ci#else
218a8e1175bSopenharmony_ci    (void) input;
219a8e1175bSopenharmony_ci    (void) input_length;
220a8e1175bSopenharmony_ci    status = PSA_ERROR_NOT_SUPPORTED;
221a8e1175bSopenharmony_ci#endif
222a8e1175bSopenharmony_ci    if (status != PSA_SUCCESS) {
223a8e1175bSopenharmony_ci        return status;
224a8e1175bSopenharmony_ci    }
225a8e1175bSopenharmony_ci
226a8e1175bSopenharmony_ci    return sign_hash(attributes, key_buffer, key_buffer_size,
227a8e1175bSopenharmony_ci                     alg, hash, hash_length,
228a8e1175bSopenharmony_ci                     signature, signature_size, signature_length);
229a8e1175bSopenharmony_ci}
230a8e1175bSopenharmony_ci
231a8e1175bSopenharmony_cipsa_status_t mbedtls_test_opaque_signature_sign_message(
232a8e1175bSopenharmony_ci    const psa_key_attributes_t *attributes,
233a8e1175bSopenharmony_ci    const uint8_t *key,
234a8e1175bSopenharmony_ci    size_t key_length,
235a8e1175bSopenharmony_ci    psa_algorithm_t alg,
236a8e1175bSopenharmony_ci    const uint8_t *input,
237a8e1175bSopenharmony_ci    size_t input_length,
238a8e1175bSopenharmony_ci    uint8_t *signature,
239a8e1175bSopenharmony_ci    size_t signature_size,
240a8e1175bSopenharmony_ci    size_t *signature_length)
241a8e1175bSopenharmony_ci{
242a8e1175bSopenharmony_ci    (void) attributes;
243a8e1175bSopenharmony_ci    (void) key;
244a8e1175bSopenharmony_ci    (void) key_length;
245a8e1175bSopenharmony_ci    (void) alg;
246a8e1175bSopenharmony_ci    (void) input;
247a8e1175bSopenharmony_ci    (void) input_length;
248a8e1175bSopenharmony_ci    (void) signature;
249a8e1175bSopenharmony_ci    (void) signature_size;
250a8e1175bSopenharmony_ci    (void) signature_length;
251a8e1175bSopenharmony_ci
252a8e1175bSopenharmony_ci    return PSA_ERROR_NOT_SUPPORTED;
253a8e1175bSopenharmony_ci}
254a8e1175bSopenharmony_ci
255a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_signature_verify_message(
256a8e1175bSopenharmony_ci    const psa_key_attributes_t *attributes,
257a8e1175bSopenharmony_ci    const uint8_t *key_buffer,
258a8e1175bSopenharmony_ci    size_t key_buffer_size,
259a8e1175bSopenharmony_ci    psa_algorithm_t alg,
260a8e1175bSopenharmony_ci    const uint8_t *input,
261a8e1175bSopenharmony_ci    size_t input_length,
262a8e1175bSopenharmony_ci    const uint8_t *signature,
263a8e1175bSopenharmony_ci    size_t signature_length)
264a8e1175bSopenharmony_ci{
265a8e1175bSopenharmony_ci    psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
266a8e1175bSopenharmony_ci    size_t hash_length;
267a8e1175bSopenharmony_ci    uint8_t hash[PSA_HASH_MAX_SIZE];
268a8e1175bSopenharmony_ci
269a8e1175bSopenharmony_ci    ++mbedtls_test_driver_signature_verify_hooks.hits;
270a8e1175bSopenharmony_ci
271a8e1175bSopenharmony_ci    if (mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS) {
272a8e1175bSopenharmony_ci        return mbedtls_test_driver_signature_verify_hooks.forced_status;
273a8e1175bSopenharmony_ci    }
274a8e1175bSopenharmony_ci
275a8e1175bSopenharmony_ci#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
276a8e1175bSopenharmony_ci    defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
277a8e1175bSopenharmony_ci    status = libtestdriver1_mbedtls_psa_hash_compute(
278a8e1175bSopenharmony_ci        PSA_ALG_SIGN_GET_HASH(alg), input, input_length,
279a8e1175bSopenharmony_ci        hash, sizeof(hash), &hash_length);
280a8e1175bSopenharmony_ci#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
281a8e1175bSopenharmony_ci    status = mbedtls_psa_hash_compute(
282a8e1175bSopenharmony_ci        PSA_ALG_SIGN_GET_HASH(alg), input, input_length,
283a8e1175bSopenharmony_ci        hash, sizeof(hash), &hash_length);
284a8e1175bSopenharmony_ci#else
285a8e1175bSopenharmony_ci    (void) input;
286a8e1175bSopenharmony_ci    (void) input_length;
287a8e1175bSopenharmony_ci    status = PSA_ERROR_NOT_SUPPORTED;
288a8e1175bSopenharmony_ci#endif
289a8e1175bSopenharmony_ci    if (status != PSA_SUCCESS) {
290a8e1175bSopenharmony_ci        return status;
291a8e1175bSopenharmony_ci    }
292a8e1175bSopenharmony_ci
293a8e1175bSopenharmony_ci    return verify_hash(attributes, key_buffer, key_buffer_size,
294a8e1175bSopenharmony_ci                       alg, hash, hash_length,
295a8e1175bSopenharmony_ci                       signature, signature_length);
296a8e1175bSopenharmony_ci}
297a8e1175bSopenharmony_ci
298a8e1175bSopenharmony_cipsa_status_t mbedtls_test_opaque_signature_verify_message(
299a8e1175bSopenharmony_ci    const psa_key_attributes_t *attributes,
300a8e1175bSopenharmony_ci    const uint8_t *key,
301a8e1175bSopenharmony_ci    size_t key_length,
302a8e1175bSopenharmony_ci    psa_algorithm_t alg,
303a8e1175bSopenharmony_ci    const uint8_t *input,
304a8e1175bSopenharmony_ci    size_t input_length,
305a8e1175bSopenharmony_ci    const uint8_t *signature,
306a8e1175bSopenharmony_ci    size_t signature_length)
307a8e1175bSopenharmony_ci{
308a8e1175bSopenharmony_ci    (void) attributes;
309a8e1175bSopenharmony_ci    (void) key;
310a8e1175bSopenharmony_ci    (void) key_length;
311a8e1175bSopenharmony_ci    (void) alg;
312a8e1175bSopenharmony_ci    (void) input;
313a8e1175bSopenharmony_ci    (void) input_length;
314a8e1175bSopenharmony_ci    (void) signature;
315a8e1175bSopenharmony_ci    (void) signature_length;
316a8e1175bSopenharmony_ci
317a8e1175bSopenharmony_ci    return PSA_ERROR_NOT_SUPPORTED;
318a8e1175bSopenharmony_ci}
319a8e1175bSopenharmony_ci
320a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_signature_sign_hash(
321a8e1175bSopenharmony_ci    const psa_key_attributes_t *attributes,
322a8e1175bSopenharmony_ci    const uint8_t *key_buffer, size_t key_buffer_size,
323a8e1175bSopenharmony_ci    psa_algorithm_t alg,
324a8e1175bSopenharmony_ci    const uint8_t *hash, size_t hash_length,
325a8e1175bSopenharmony_ci    uint8_t *signature, size_t signature_size, size_t *signature_length)
326a8e1175bSopenharmony_ci{
327a8e1175bSopenharmony_ci    ++mbedtls_test_driver_signature_sign_hooks.hits;
328a8e1175bSopenharmony_ci
329a8e1175bSopenharmony_ci    if (mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS) {
330a8e1175bSopenharmony_ci        return mbedtls_test_driver_signature_sign_hooks.forced_status;
331a8e1175bSopenharmony_ci    }
332a8e1175bSopenharmony_ci
333a8e1175bSopenharmony_ci    if (mbedtls_test_driver_signature_sign_hooks.forced_output != NULL) {
334a8e1175bSopenharmony_ci        if (mbedtls_test_driver_signature_sign_hooks.forced_output_length > signature_size) {
335a8e1175bSopenharmony_ci            return PSA_ERROR_BUFFER_TOO_SMALL;
336a8e1175bSopenharmony_ci        }
337a8e1175bSopenharmony_ci        memcpy(signature, mbedtls_test_driver_signature_sign_hooks.forced_output,
338a8e1175bSopenharmony_ci               mbedtls_test_driver_signature_sign_hooks.forced_output_length);
339a8e1175bSopenharmony_ci        *signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length;
340a8e1175bSopenharmony_ci        return PSA_SUCCESS;
341a8e1175bSopenharmony_ci    }
342a8e1175bSopenharmony_ci
343a8e1175bSopenharmony_ci    return sign_hash(attributes, key_buffer, key_buffer_size,
344a8e1175bSopenharmony_ci                     alg, hash, hash_length,
345a8e1175bSopenharmony_ci                     signature, signature_size, signature_length);
346a8e1175bSopenharmony_ci}
347a8e1175bSopenharmony_ci
348a8e1175bSopenharmony_cipsa_status_t mbedtls_test_opaque_signature_sign_hash(
349a8e1175bSopenharmony_ci    const psa_key_attributes_t *attributes,
350a8e1175bSopenharmony_ci    const uint8_t *key, size_t key_length,
351a8e1175bSopenharmony_ci    psa_algorithm_t alg,
352a8e1175bSopenharmony_ci    const uint8_t *hash, size_t hash_length,
353a8e1175bSopenharmony_ci    uint8_t *signature, size_t signature_size, size_t *signature_length)
354a8e1175bSopenharmony_ci{
355a8e1175bSopenharmony_ci    (void) attributes;
356a8e1175bSopenharmony_ci    (void) key;
357a8e1175bSopenharmony_ci    (void) key_length;
358a8e1175bSopenharmony_ci    (void) alg;
359a8e1175bSopenharmony_ci    (void) hash;
360a8e1175bSopenharmony_ci    (void) hash_length;
361a8e1175bSopenharmony_ci    (void) signature;
362a8e1175bSopenharmony_ci    (void) signature_size;
363a8e1175bSopenharmony_ci    (void) signature_length;
364a8e1175bSopenharmony_ci
365a8e1175bSopenharmony_ci    return PSA_ERROR_NOT_SUPPORTED;
366a8e1175bSopenharmony_ci}
367a8e1175bSopenharmony_ci
368a8e1175bSopenharmony_cipsa_status_t mbedtls_test_transparent_signature_verify_hash(
369a8e1175bSopenharmony_ci    const psa_key_attributes_t *attributes,
370a8e1175bSopenharmony_ci    const uint8_t *key_buffer, size_t key_buffer_size,
371a8e1175bSopenharmony_ci    psa_algorithm_t alg,
372a8e1175bSopenharmony_ci    const uint8_t *hash, size_t hash_length,
373a8e1175bSopenharmony_ci    const uint8_t *signature, size_t signature_length)
374a8e1175bSopenharmony_ci{
375a8e1175bSopenharmony_ci    ++mbedtls_test_driver_signature_verify_hooks.hits;
376a8e1175bSopenharmony_ci
377a8e1175bSopenharmony_ci    if (mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS) {
378a8e1175bSopenharmony_ci        return mbedtls_test_driver_signature_verify_hooks.forced_status;
379a8e1175bSopenharmony_ci    }
380a8e1175bSopenharmony_ci
381a8e1175bSopenharmony_ci    return verify_hash(attributes, key_buffer, key_buffer_size,
382a8e1175bSopenharmony_ci                       alg, hash, hash_length,
383a8e1175bSopenharmony_ci                       signature, signature_length);
384a8e1175bSopenharmony_ci}
385a8e1175bSopenharmony_ci
386a8e1175bSopenharmony_cipsa_status_t mbedtls_test_opaque_signature_verify_hash(
387a8e1175bSopenharmony_ci    const psa_key_attributes_t *attributes,
388a8e1175bSopenharmony_ci    const uint8_t *key, size_t key_length,
389a8e1175bSopenharmony_ci    psa_algorithm_t alg,
390a8e1175bSopenharmony_ci    const uint8_t *hash, size_t hash_length,
391a8e1175bSopenharmony_ci    const uint8_t *signature, size_t signature_length)
392a8e1175bSopenharmony_ci{
393a8e1175bSopenharmony_ci    (void) attributes;
394a8e1175bSopenharmony_ci    (void) key;
395a8e1175bSopenharmony_ci    (void) key_length;
396a8e1175bSopenharmony_ci    (void) alg;
397a8e1175bSopenharmony_ci    (void) hash;
398a8e1175bSopenharmony_ci    (void) hash_length;
399a8e1175bSopenharmony_ci    (void) signature;
400a8e1175bSopenharmony_ci    (void) signature_length;
401a8e1175bSopenharmony_ci    return PSA_ERROR_NOT_SUPPORTED;
402a8e1175bSopenharmony_ci}
403a8e1175bSopenharmony_ci
404a8e1175bSopenharmony_ci#endif /* PSA_CRYPTO_DRIVER_TEST */
405