blob: 9ace0cb283ccefc08a534647c9c116507b0afc80 [file] [log] [blame]
Steven Cooremancd84cb42020-07-16 20:28:36 +02001/*
2 * Functions to delegate cryptographic operations to an available
3 * and appropriate accelerator.
4 * Warning: auto-generated file.
5 */
6/* Copyright (C) 2020, ARM Limited, All Rights Reserved
7 * SPDX-License-Identifier: Apache-2.0
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
10 * not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 * This file is part of mbed TLS (https://tls.mbed.org)
22 */
23
24#include "psa_crypto_core.h"
25#include "psa_crypto_driver_wrappers.h"
26
27/* Include test driver definition when running tests */
28#if defined(MBEDTLS_TEST_HOOKS)
29#undef MBEDTLS_PSA_CRYPTO_DRIVER_PRESENT
30#define MBEDTLS_PSA_CRYPTO_DRIVER_PRESENT
31#include "drivers/test_driver.h"
32#endif
33
34/* Include driver definition file for each registered driver */
35
36/* Start delegation functions */
37psa_status_t psa_driver_wrapper_sign_hash( psa_key_slot_t *slot,
38 psa_algorithm_t alg,
39 const uint8_t *hash,
40 size_t hash_length,
41 uint8_t *signature,
42 size_t signature_size,
43 size_t *signature_length )
44{
45#if defined(MBEDTLS_PSA_CRYPTO_DRIVER_PRESENT)
46 psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
47 psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(slot->attr.lifetime);
48 psa_key_attributes_t attributes = {
49 .core = slot->attr
50 };
51
52 switch( location )
53 {
54 case PSA_KEY_LOCATION_LOCAL_STORAGE:
55 /* Key is stored in the slot in export representation, so
56 * cycle through all known transparent accelerators */
57#if defined(MBEDTLS_TEST_HOOKS)
58 status = test_transparent_signature_sign_hash( &attributes,
59 slot->data.key.data,
60 slot->data.key.bytes,
61 alg,
62 hash,
63 hash_length,
64 signature,
65 signature_size,
66 signature_length );
67 /* Declared with fallback == true */
68 if( status != PSA_ERROR_NOT_SUPPORTED )
69 return status;
70#endif /* MBEDTLS_TEST_HOOKS */
71 /* Fell through, meaning no accelerator supports this operation */
72 return PSA_ERROR_NOT_SUPPORTED;
73 /* Add cases for opaque driver here */
74#if defined(MBEDTLS_TEST_HOOKS)
75 case MBEDTLS_PSA_CRYPTO_TEST_DRIVER_LIFETIME:
76 return( test_opaque_signature_sign_hash( &attributes,
77 slot->data.key.data,
78 slot->data.key.bytes,
79 alg,
80 hash,
81 hash_length,
82 signature,
83 signature_size,
84 signature_length ) );
85#endif /* MBEDTLS_TEST_HOOKS */
86 default:
87 /* Key is declared with a lifetime not known to us */
88 return status;
89 }
90#else /* MBEDTLS_PSA_CRYPTO_DRIVER_PRESENT */
91 (void)slot;
92 (void)alg;
93 (void)hash;
94 (void)hash_length;
95 (void)signature;
96 (void)signature_size;
97 (void)signature_length;
98
99 return PSA_ERROR_NOT_SUPPORTED;
100#endif /* MBEDTLS_PSA_CRYPTO_DRIVER_PRESENT */
101}
102
103/* End of automatically generated file. */