160 lines
5.1 KiB
C
160 lines
5.1 KiB
C
/*
|
|
* Functions to delegate cryptographic operations to an available
|
|
* and appropriate accelerator.
|
|
* Warning: This file is now auto-generated.
|
|
*/
|
|
/* Copyright The Mbed TLS Contributors
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
* not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
|
|
/* BEGIN-common headers */
|
|
#include "common.h"
|
|
#include "psa_crypto_aead.h"
|
|
#include "psa_crypto_cipher.h"
|
|
#include "psa_crypto_core.h"
|
|
#include "psa_crypto_driver_wrappers.h"
|
|
#include "psa_crypto_hash.h"
|
|
#include "psa_crypto_mac.h"
|
|
#include "psa_crypto_pake.h"
|
|
#include "psa_crypto_rsa.h"
|
|
|
|
#include "mbedtls/platform.h"
|
|
/* END-common headers */
|
|
|
|
#if defined(MBEDTLS_PSA_CRYPTO_C)
|
|
|
|
/* BEGIN-driver headers */
|
|
/* Headers for mbedtls_test opaque driver */
|
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
#include "test/drivers/test_driver.h"
|
|
|
|
#endif
|
|
/* Headers for mbedtls_test transparent driver */
|
|
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
|
#include "test/drivers/test_driver.h"
|
|
|
|
#endif
|
|
|
|
/* END-driver headers */
|
|
|
|
/* Auto-generated values depending on which drivers are registered.
|
|
* ID 0 is reserved for unallocated operations.
|
|
* ID 1 is reserved for the Mbed TLS software driver. */
|
|
/* BEGIN-driver id definition */
|
|
#define PSA_CRYPTO_MBED_TLS_DRIVER_ID (1)
|
|
#define MBEDTLS_TEST_OPAQUE_DRIVER_ID (2)
|
|
#define MBEDTLS_TEST_TRANSPARENT_DRIVER_ID (3)
|
|
|
|
/* END-driver id */
|
|
|
|
/* BEGIN-Common Macro definitions */
|
|
|
|
/* END-Common Macro definitions */
|
|
|
|
/* Support the 'old' SE interface when asked to */
|
|
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
|
/* PSA_CRYPTO_DRIVER_PRESENT is defined when either a new-style or old-style
|
|
* SE driver is present, to avoid unused argument errors at compile time. */
|
|
#ifndef PSA_CRYPTO_DRIVER_PRESENT
|
|
#define PSA_CRYPTO_DRIVER_PRESENT
|
|
#endif
|
|
#include "psa_crypto_se.h"
|
|
#endif
|
|
|
|
|
|
psa_status_t psa_driver_wrapper_export_public_key(
|
|
const psa_key_attributes_t *attributes,
|
|
const uint8_t *key_buffer, size_t key_buffer_size,
|
|
uint8_t *data, size_t data_size, size_t *data_length)
|
|
|
|
{
|
|
|
|
psa_status_t status = PSA_ERROR_INVALID_ARGUMENT;
|
|
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION(
|
|
psa_get_key_lifetime(attributes));
|
|
|
|
/* Try dynamically-registered SE interface first */
|
|
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
|
const psa_drv_se_t *drv;
|
|
psa_drv_se_context_t *drv_context;
|
|
|
|
if (psa_get_se_driver(attributes->core.lifetime, &drv, &drv_context)) {
|
|
if ((drv->key_management == NULL) ||
|
|
(drv->key_management->p_export_public == NULL)) {
|
|
return PSA_ERROR_NOT_SUPPORTED;
|
|
}
|
|
|
|
return drv->key_management->p_export_public(
|
|
drv_context,
|
|
*((psa_key_slot_number_t *) key_buffer),
|
|
data, data_size, data_length);
|
|
}
|
|
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
|
|
|
|
switch (location) {
|
|
case PSA_KEY_LOCATION_LOCAL_STORAGE:
|
|
/* Key is stored in the slot in export representation, so
|
|
* cycle through all known transparent accelerators */
|
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
|
|
|
#if (defined(PSA_CRYPTO_DRIVER_TEST))
|
|
status = mbedtls_test_transparent_export_public_key(
|
|
attributes,
|
|
key_buffer,
|
|
key_buffer_size,
|
|
data,
|
|
data_size,
|
|
data_length);
|
|
|
|
if (status != PSA_ERROR_NOT_SUPPORTED) {
|
|
return status;
|
|
}
|
|
#endif
|
|
|
|
|
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
|
/* Fell through, meaning no accelerator supports this operation */
|
|
return psa_export_public_key_internal(attributes,
|
|
key_buffer,
|
|
key_buffer_size,
|
|
data,
|
|
data_size,
|
|
data_length);
|
|
|
|
/* Add cases for opaque driver here */
|
|
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
|
|
|
|
#if (defined(PSA_CRYPTO_DRIVER_TEST))
|
|
case 0x7fffff:
|
|
return mbedtls_test_opaque_export_public_key(attributes,
|
|
key_buffer,
|
|
key_buffer_size,
|
|
data,
|
|
data_size,
|
|
data_length);
|
|
#endif
|
|
|
|
|
|
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
|
|
default:
|
|
/* Key is declared with a lifetime not known to us */
|
|
return status;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
#endif /* MBEDTLS_PSA_CRYPTO_C */
|