初始版本
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
* Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sdk_config.h"
|
||||
#include "nordic_common.h"
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "nrf_crypto_mem.h"
|
||||
#include "nrf_crypto_ecc.h"
|
||||
#include "nrf_crypto_shared.h"
|
||||
#include "cc310_bl_backend_ecc.h"
|
||||
|
||||
|
||||
#if defined(NRF_CRYPTO_BACKEND_CC310_BL_ECC_LITTLE_ENDIAN_ENABLED)
|
||||
|
||||
#error The configuration NRF_CRYPTO_BACKEND_CC310_BL_ECC_LITTLE_ENDIAN_ENABLED was removed in SDK 15.1.0. Please see release notes for details on removing this error message.
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP224R1)
|
||||
|
||||
|
||||
ret_code_t nrf_crypto_backend_secp224r1_public_key_from_raw(
|
||||
void * p_public_key,
|
||||
uint8_t const * p_raw_data)
|
||||
{
|
||||
nrf_crypto_backend_secp224r1_public_key_t * p_pub =
|
||||
(nrf_crypto_backend_secp224r1_public_key_t *)p_public_key;
|
||||
|
||||
memcpy(&p_pub->public_key.x[0],
|
||||
&p_raw_data[0],
|
||||
NRF_CRYPTO_ECC_SECP224R1_RAW_PRIVATE_KEY_SIZE);
|
||||
memcpy(&p_pub->public_key.y[0],
|
||||
&p_raw_data[NRF_CRYPTO_ECC_SECP224R1_RAW_PRIVATE_KEY_SIZE],
|
||||
NRF_CRYPTO_ECC_SECP224R1_RAW_PRIVATE_KEY_SIZE);
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t nrf_crypto_backend_secp224r1_public_key_to_raw(
|
||||
void const * p_public_key,
|
||||
uint8_t * p_raw_data)
|
||||
{
|
||||
nrf_crypto_backend_secp224r1_public_key_t const * p_pub =
|
||||
(nrf_crypto_backend_secp224r1_public_key_t const *)p_public_key;
|
||||
|
||||
memcpy(&p_raw_data[0],
|
||||
&p_pub->public_key.x[0],
|
||||
NRF_CRYPTO_ECC_SECP224R1_RAW_PRIVATE_KEY_SIZE);
|
||||
memcpy(&p_raw_data[NRF_CRYPTO_ECC_SECP224R1_RAW_PRIVATE_KEY_SIZE],
|
||||
&p_pub->public_key.y[0],
|
||||
NRF_CRYPTO_ECC_SECP224R1_RAW_PRIVATE_KEY_SIZE);
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
nrf_crypto_ecc_curve_info_t const g_nrf_crypto_ecc_secp224r1_curve_info =
|
||||
{
|
||||
.public_key_size = sizeof(nrf_crypto_backend_secp224r1_public_key_t),
|
||||
.private_key_size = 0,
|
||||
.curve_type = NRF_CRYPTO_ECC_SECP224R1_CURVE_TYPE,
|
||||
.raw_private_key_size = NRF_CRYPTO_ECC_SECP224R1_RAW_PRIVATE_KEY_SIZE,
|
||||
.raw_public_key_size = NRF_CRYPTO_ECC_SECP224R1_RAW_PUBLIC_KEY_SIZE,
|
||||
};
|
||||
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP224R1)
|
||||
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP256R1)
|
||||
|
||||
|
||||
ret_code_t nrf_crypto_backend_secp256r1_public_key_from_raw(
|
||||
void * p_public_key,
|
||||
uint8_t const * p_raw_data)
|
||||
{
|
||||
nrf_crypto_backend_secp256r1_public_key_t * p_pub =
|
||||
(nrf_crypto_backend_secp256r1_public_key_t *)p_public_key;
|
||||
|
||||
memcpy(&p_pub->public_key.x[0],
|
||||
&p_raw_data[0],
|
||||
NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE);
|
||||
memcpy(&p_pub->public_key.y[0],
|
||||
&p_raw_data[NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE],
|
||||
NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE);
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t nrf_crypto_backend_secp256r1_public_key_to_raw(
|
||||
void const * p_public_key,
|
||||
uint8_t * p_raw_data)
|
||||
{
|
||||
nrf_crypto_backend_secp256r1_public_key_t const * p_pub =
|
||||
(nrf_crypto_backend_secp256r1_public_key_t const *)p_public_key;
|
||||
|
||||
memcpy(&p_raw_data[0],
|
||||
&p_pub->public_key.x[0],
|
||||
NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE);
|
||||
memcpy(&p_raw_data[NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE],
|
||||
&p_pub->public_key.y[0],
|
||||
NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE);
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
nrf_crypto_ecc_curve_info_t const g_nrf_crypto_ecc_secp256r1_curve_info =
|
||||
{
|
||||
.public_key_size = sizeof(nrf_crypto_backend_secp256r1_public_key_t),
|
||||
.private_key_size = 0,
|
||||
.curve_type = NRF_CRYPTO_ECC_SECP256R1_CURVE_TYPE,
|
||||
.raw_private_key_size = NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE,
|
||||
.raw_public_key_size = NRF_CRYPTO_ECC_SECP256R1_RAW_PUBLIC_KEY_SIZE,
|
||||
};
|
||||
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP256R1)
|
||||
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CC310_BL_BACKEND_ECC_H__
|
||||
#define CC310_BL_BACKEND_ECC_H__
|
||||
|
||||
#include "sdk_config.h"
|
||||
#include "nordic_common.h"
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
#include "nrf_crypto_ecc_shared.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP224R1)
|
||||
#include "nrf_cc310_bl_ecdsa_verify_secp224r1.h"
|
||||
#endif
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP256R1)
|
||||
#include "nrf_cc310_bl_ecdsa_verify_secp256r1.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP224R1)
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_ECC_SECP224R1)
|
||||
#error "More than one backend enabled for secp224r1 (NIST 224-bit).");
|
||||
#endif
|
||||
#define NRF_CRYPTO_ECC_SECP224R1_ENABLED 1
|
||||
|
||||
typedef struct
|
||||
{
|
||||
nrf_crypto_internal_ecc_key_header_t header; /**< @internal @brief Common ECC key header */
|
||||
nrf_cc310_bl_ecc_public_key_secp224r1_t public_key; /**< @internal @brief CC310_BL specific key representation */
|
||||
} nrf_crypto_backend_secp224r1_public_key_t;
|
||||
|
||||
/** @internal See @ref nrf_crypto_backend_ecc_public_key_from_raw_fn_t.
|
||||
*/
|
||||
ret_code_t nrf_crypto_backend_secp224r1_public_key_from_raw(
|
||||
void * p_public_key,
|
||||
uint8_t const * p_raw_data);
|
||||
|
||||
/** @internal See @ref nrf_crypto_backend_ecc_public_key_to_raw_fn_t.
|
||||
*/
|
||||
ret_code_t nrf_crypto_backend_secp224r1_public_key_to_raw(
|
||||
void const * p_public_key,
|
||||
uint8_t * p_raw_data);
|
||||
|
||||
// Dummy and empty definitions for unused symbols
|
||||
#define nrf_crypto_backend_secp224r1_key_pair_generate NULL
|
||||
#define nrf_crypto_backend_secp224r1_public_key_calculate NULL
|
||||
#define nrf_crypto_backend_secp224r1_private_key_from_raw NULL
|
||||
#define nrf_crypto_backend_secp224r1_private_key_to_raw NULL
|
||||
#define nrf_crypto_backend_secp224r1_private_key_free NULL
|
||||
#define nrf_crypto_backend_secp224r1_public_key_free NULL
|
||||
|
||||
#define NRF_CRYPTO_BACKEND_SECP224R1_KEY_PAIR_GENERATE_CONTEXT_SIZE 0
|
||||
#define NRF_CRYPTO_BACKEND_SECP224R1_PUBLIC_KEY_CALCULATE_CONTEXT_SIZE 0
|
||||
|
||||
typedef uint32_t nrf_crypto_backend_secp224r1_private_key_t;
|
||||
typedef uint32_t nrf_crypto_backend_secp224r1_key_pair_generate_context_t;
|
||||
typedef uint32_t nrf_crypto_backend_secp224r1_public_key_calculate_context_t;
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP224R1)
|
||||
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP256R1)
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_ECC_SECP256R1)
|
||||
#error "More than one backend enabled for secp256r1 (NIST 256-bit).");
|
||||
#endif
|
||||
#define NRF_CRYPTO_ECC_SECP256R1_ENABLED 1
|
||||
|
||||
typedef struct
|
||||
{
|
||||
nrf_crypto_internal_ecc_key_header_t header; /**< @internal @brief Common ECC key header */
|
||||
nrf_cc310_bl_ecc_public_key_secp256r1_t public_key; /**< @internal @brief CC310_BL specific key representation */
|
||||
} nrf_crypto_backend_secp256r1_public_key_t;
|
||||
|
||||
/** @internal See @ref nrf_crypto_backend_ecc_public_key_from_raw_fn_t.
|
||||
*/
|
||||
ret_code_t nrf_crypto_backend_secp256r1_public_key_from_raw(
|
||||
void * p_public_key,
|
||||
uint8_t const * p_raw_data);
|
||||
|
||||
/** @internal See @ref nrf_crypto_backend_ecc_public_key_to_raw_fn_t.
|
||||
*/
|
||||
ret_code_t nrf_crypto_backend_secp256r1_public_key_to_raw(
|
||||
void const * p_public_key,
|
||||
uint8_t * p_raw_data);
|
||||
|
||||
// Dummy and empty definitions for unused symbols
|
||||
#define nrf_crypto_backend_secp256r1_key_pair_generate NULL
|
||||
#define nrf_crypto_backend_secp256r1_public_key_calculate NULL
|
||||
#define nrf_crypto_backend_secp256r1_private_key_from_raw NULL
|
||||
#define nrf_crypto_backend_secp256r1_private_key_to_raw NULL
|
||||
#define nrf_crypto_backend_secp256r1_private_key_free NULL
|
||||
#define nrf_crypto_backend_secp256r1_public_key_free NULL
|
||||
|
||||
#define NRF_CRYPTO_BACKEND_SECP256R1_KEY_PAIR_GENERATE_CONTEXT_SIZE 0
|
||||
#define NRF_CRYPTO_BACKEND_SECP256R1_PUBLIC_KEY_CALCULATE_CONTEXT_SIZE 0
|
||||
|
||||
typedef uint32_t nrf_crypto_backend_secp256r1_private_key_t;
|
||||
typedef uint32_t nrf_crypto_backend_secp256r1_key_pair_generate_context_t;
|
||||
typedef uint32_t nrf_crypto_backend_secp256r1_public_key_calculate_context_t;
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP256R1)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
#endif // CC310_BL_BACKEND_ECC_H__
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CC310_BL_BACKEND_ECDH_H__
|
||||
#define CC310_BL_BACKEND_ECDH_H__
|
||||
|
||||
#include "sdk_config.h"
|
||||
#include "nordic_common.h"
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
#include "nrf_crypto_ecc.h"
|
||||
#include "nrf_crypto_ecdh_shared.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP224R1)
|
||||
#define nrf_crypto_backend_secp224r1_ecdh_compute NULL
|
||||
typedef uint32_t nrf_crypto_backend_secp224r1_ecdh_context_t;
|
||||
#define NRF_CRYPTO_BACKEND_SECP224R1_ECDH_CONTEXT_SIZE 0
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP224R1)
|
||||
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP256R1)
|
||||
#define nrf_crypto_backend_secp256r1_ecdh_compute NULL
|
||||
typedef uint32_t nrf_crypto_backend_secp256r1_ecdh_context_t;
|
||||
#define NRF_CRYPTO_BACKEND_SECP256R1_ECDH_CONTEXT_SIZE 0
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP256R1)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
#endif // CC310_BL_BACKEND_ECDH_H__
|
||||
@@ -0,0 +1,197 @@
|
||||
/**
|
||||
* Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sdk_config.h"
|
||||
#include "nordic_common.h"
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
|
||||
#if defined(NRF_CRYPTO_BACKEND_CC310_BL_ECC_LITTLE_ENDIAN_ENABLED)
|
||||
|
||||
#error The configuration NRF_CRYPTO_BACKEND_CC310_BL_ECC_LITTLE_ENDIAN_ENABLED was removed in SDK 15.1.0. Please see release notes for details on removing this error message.
|
||||
|
||||
#endif // defined(NRF_CRYPTO_BACKEND_CC310_BL_ECC_LITTLE_ENDIAN_ENABLED)
|
||||
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include "app_util.h"
|
||||
#include "nrf_crypto_error.h"
|
||||
#include "nrf_crypto_mem.h"
|
||||
#include "nrf_crypto_shared.h"
|
||||
#include "cc310_bl_backend_ecdsa.h"
|
||||
#include "cc310_bl_backend_shared.h"
|
||||
#include "cc310_backend_mutex.h"
|
||||
#include "crys_ecpki_error.h"
|
||||
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP224R1) || \
|
||||
NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP256R1)
|
||||
|
||||
static ret_code_t crys_error_to_ret_code(CRYSError_t crys_error)
|
||||
{
|
||||
switch (crys_error)
|
||||
{
|
||||
case CRYS_OK:
|
||||
return NRF_SUCCESS;
|
||||
|
||||
case CRYS_ECDSA_VERIFY_INCONSISTENT_VERIFY_ERROR:
|
||||
return NRF_ERROR_CRYPTO_ECDSA_INVALID_SIGNATURE;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return NRF_ERROR_CRYPTO_INTERNAL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP224R1)
|
||||
|
||||
STATIC_ASSERT(offsetof(nrf_cc310_bl_ecc_signature_secp224r1_t, r) == 0,
|
||||
"Offset of r in nrf_cc310_bl_ecc_signature_secp224r1_t is unexpected");
|
||||
STATIC_ASSERT(offsetof(nrf_cc310_bl_ecc_signature_secp224r1_t, s) ==
|
||||
NRF_CRYPTO_ECC_SECP224R1_RAW_PRIVATE_KEY_SIZE,
|
||||
"Offset of s in nrf_cc310_bl_ecc_signature_secp224r1_t is unexpected");
|
||||
|
||||
|
||||
ret_code_t nrf_crypto_backend_secp224r1_verify(
|
||||
void * p_context,
|
||||
void const * p_public_key,
|
||||
uint8_t const * p_data,
|
||||
size_t data_size,
|
||||
uint8_t const * p_signature)
|
||||
{
|
||||
ret_code_t result;
|
||||
CRYSError_t crys_error;
|
||||
bool mutex_locked;
|
||||
|
||||
nrf_crypto_backend_secp224r1_verify_context_t * p_ctx =
|
||||
(nrf_crypto_backend_secp224r1_verify_context_t *)p_context;
|
||||
|
||||
nrf_crypto_backend_secp224r1_public_key_t * p_pub =
|
||||
(nrf_crypto_backend_secp224r1_public_key_t *)p_public_key;
|
||||
|
||||
p_ctx->user_context.init_val = NRF_CC310_BL_ECDSA_CONTEXT_INITIALIZED;
|
||||
|
||||
mutex_locked = cc310_backend_mutex_trylock();
|
||||
VERIFY_TRUE(mutex_locked, NRF_ERROR_CRYPTO_BUSY);
|
||||
|
||||
cc310_bl_backend_enable();
|
||||
|
||||
crys_error = nrf_cc310_bl_ecdsa_verify_secp224r1(
|
||||
&p_ctx->user_context,
|
||||
&p_pub->public_key,
|
||||
(nrf_cc310_bl_ecc_signature_secp224r1_t const *)p_signature,
|
||||
p_data,
|
||||
data_size);
|
||||
|
||||
cc310_bl_backend_disable();
|
||||
|
||||
cc310_backend_mutex_unlock();
|
||||
|
||||
result = crys_error_to_ret_code(crys_error);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP224R1)
|
||||
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP256R1)
|
||||
|
||||
|
||||
STATIC_ASSERT(offsetof(nrf_cc310_bl_ecc_signature_secp256r1_t, r) == 0,
|
||||
"Offset of r in nrf_cc310_bl_ecc_signature_secp256r1_t is unexpected");
|
||||
|
||||
STATIC_ASSERT(offsetof(nrf_cc310_bl_ecc_signature_secp256r1_t, s) ==
|
||||
NRF_CRYPTO_ECC_SECP256R1_RAW_PRIVATE_KEY_SIZE,
|
||||
"Offset of s in nrf_cc310_bl_ecc_signature_secp256r1_t is unexpected");
|
||||
|
||||
|
||||
ret_code_t nrf_crypto_backend_secp256r1_verify(
|
||||
void * p_context,
|
||||
void const * p_public_key,
|
||||
uint8_t const * p_data,
|
||||
size_t data_size,
|
||||
uint8_t const * p_signature)
|
||||
{
|
||||
ret_code_t result;
|
||||
CRYSError_t crys_error;
|
||||
bool mutex_locked;
|
||||
|
||||
|
||||
nrf_crypto_backend_secp256r1_verify_context_t * p_ctx =
|
||||
(nrf_crypto_backend_secp256r1_verify_context_t *)p_context;
|
||||
|
||||
nrf_crypto_backend_secp256r1_public_key_t * p_pub =
|
||||
(nrf_crypto_backend_secp256r1_public_key_t *)p_public_key;
|
||||
|
||||
p_ctx->user_context.init_val = NRF_CC310_BL_ECDSA_CONTEXT_INITIALIZED;
|
||||
|
||||
mutex_locked = cc310_backend_mutex_trylock();
|
||||
VERIFY_TRUE(mutex_locked, NRF_ERROR_CRYPTO_BUSY);
|
||||
|
||||
cc310_bl_backend_enable();
|
||||
|
||||
crys_error = nrf_cc310_bl_ecdsa_verify_secp256r1(
|
||||
&p_ctx->user_context,
|
||||
&p_pub->public_key,
|
||||
(nrf_cc310_bl_ecc_signature_secp256r1_t const *)p_signature,
|
||||
p_data,
|
||||
data_size);
|
||||
|
||||
cc310_bl_backend_disable();
|
||||
|
||||
cc310_backend_mutex_unlock();
|
||||
|
||||
result = crys_error_to_ret_code(crys_error);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP256R1)
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
@@ -0,0 +1,124 @@
|
||||
/**
|
||||
* Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CC310_BL_BACKEND_ECDSA_H__
|
||||
#define CC310_BL_BACKEND_ECDSA_H__
|
||||
|
||||
#include "sdk_config.h"
|
||||
#include "nordic_common.h"
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
#include "nrf_crypto_ecc_shared.h"
|
||||
#include "nrf_crypto_ecdsa_shared.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP224R1)
|
||||
#include "nrf_cc310_bl_ecdsa_verify_secp224r1.h"
|
||||
#endif
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP256R1)
|
||||
#include "nrf_cc310_bl_ecdsa_verify_secp256r1.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP224R1)
|
||||
|
||||
/** @internal @brief Common structure holding context for ECDSA verify.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrf_cc310_bl_ecdsa_verify_context_secp224r1_t user_context; /**< @internal @brief Temporary buffer for CC310_BL internal storage */
|
||||
} nrf_crypto_backend_secp224r1_verify_context_t;
|
||||
|
||||
#define NRF_CRYPTO_BACKEND_SECP224R1_VERIFY_CONTEXT_SIZE \
|
||||
sizeof(nrf_crypto_backend_secp224r1_verify_context_t)
|
||||
|
||||
ret_code_t nrf_crypto_backend_secp224r1_verify(
|
||||
void * p_context,
|
||||
void const * p_public_key,
|
||||
uint8_t const * p_data,
|
||||
size_t data_size,
|
||||
uint8_t const * p_signature);
|
||||
|
||||
// Dummy and empty definitions for unused symbols
|
||||
#define NRF_CRYPTO_BACKEND_SECP224R1_SIGN_CONTEXT_SIZE 0
|
||||
typedef uint32_t nrf_crypto_backend_secp224r1_sign_context_t;
|
||||
#define nrf_crypto_backend_secp224r1_sign NULL
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP224R1)
|
||||
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP256R1)
|
||||
|
||||
/** @internal @brief Common structure holding context for ECDSA verify.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrf_cc310_bl_ecdsa_verify_context_secp256r1_t user_context; /**< @internal @brief Temporary buffer for CC310_BL internal storage */
|
||||
} nrf_crypto_backend_secp256r1_verify_context_t;
|
||||
|
||||
#define NRF_CRYPTO_BACKEND_SECP256R1_VERIFY_CONTEXT_SIZE \
|
||||
sizeof(nrf_crypto_backend_secp256r1_verify_context_t)
|
||||
|
||||
ret_code_t nrf_crypto_backend_secp256r1_verify(
|
||||
void * p_context,
|
||||
void const * p_public_key,
|
||||
uint8_t const * p_data,
|
||||
size_t data_size,
|
||||
uint8_t const * p_signature);
|
||||
|
||||
// Dummy and empty definitions for unused symbols
|
||||
#define NRF_CRYPTO_BACKEND_SECP256R1_SIGN_CONTEXT_SIZE 0
|
||||
typedef uint32_t nrf_crypto_backend_secp256r1_sign_context_t;
|
||||
#define nrf_crypto_backend_secp256r1_sign NULL
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP256R1)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
#endif // CC310_BL_BACKEND_ECDSA_H__
|
||||
@@ -0,0 +1,276 @@
|
||||
/**
|
||||
* Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
#include "nrf.h"
|
||||
#include "cc310_bl_backend_hash.h"
|
||||
#include "cc310_bl_backend_shared.h"
|
||||
#include "cc310_backend_mutex.h"
|
||||
#include "cc310_backend_shared.h"
|
||||
#include "nrf_cc310_bl_hash_sha256.h"
|
||||
#include "crys_hash_error.h"
|
||||
#include "nrf_crypto_init.h"
|
||||
#include "nrf_crypto_types.h"
|
||||
#include "nrf_crypto_error.h"
|
||||
#include "nrf_crypto_shared.h"
|
||||
#include "nrf_crypto_hash_shared.h"
|
||||
#include "sdk_macros.h"
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_assert.h"
|
||||
#include <drivers/nrfx_common.h>
|
||||
|
||||
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_HASH_SHA256)
|
||||
|
||||
|
||||
#if defined(NRF_CRYPTO_BACKEND_CC310_BL_HASH_LITTLE_ENDIAN_DIGEST_ENABLED)
|
||||
|
||||
#error The configuration NRF_CRYPTO_BACKEND_CC310_BL_HASH_LITTLE_ENDIAN_DIGEST_ENABLED was removed in SDK 15.1.0. Please see release notes for details on removing this error message.
|
||||
|
||||
#endif // defined(NRF_CRYPTO_BACKEND_CC310_BL_HASH_LITTLE_ENDIAN_DIGEST_ENABLED)
|
||||
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_HASH_AUTOMATIC_RAM_BUFFER)
|
||||
|
||||
__ALIGN(4) static uint8_t m_hash_buffer[NRF_CRYPTO_BACKEND_CC310_BL_HASH_AUTOMATIC_RAM_BUFFER_SIZE];
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_HASH_AUTOMATIC_RAM_BUFFER)
|
||||
|
||||
|
||||
static ret_code_t hash_result_get(CRYSError_t error)
|
||||
{
|
||||
ret_code_t ret_val;
|
||||
|
||||
switch (error)
|
||||
{
|
||||
case CRYS_OK:
|
||||
ret_val = NRF_SUCCESS;
|
||||
break;
|
||||
|
||||
case CRYS_HASH_INVALID_USER_CONTEXT_POINTER_ERROR:
|
||||
ret_val = NRF_ERROR_CRYPTO_CONTEXT_NULL;
|
||||
break;
|
||||
|
||||
case CRYS_HASH_ILLEGAL_OPERATION_MODE_ERROR:
|
||||
ret_val = NRF_ERROR_CRYPTO_FEATURE_UNAVAILABLE;
|
||||
break;
|
||||
|
||||
case CRYS_HASH_USER_CONTEXT_CORRUPTED_ERROR:
|
||||
ret_val = NRF_ERROR_CRYPTO_CONTEXT_NOT_INITIALIZED;
|
||||
break;
|
||||
|
||||
// May be added to specialized errors for hash.
|
||||
case CRYS_HASH_LAST_BLOCK_ALREADY_PROCESSED_ERROR:
|
||||
ret_val = NRF_ERROR_CRYPTO_INTERNAL;
|
||||
break;
|
||||
|
||||
case CRYS_HASH_IS_NOT_SUPPORTED:
|
||||
ret_val = NRF_ERROR_CRYPTO_FEATURE_UNAVAILABLE;
|
||||
break;
|
||||
|
||||
default:
|
||||
ret_val = NRF_ERROR_CRYPTO_INTERNAL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
static ret_code_t cc310_bl_backend_hash_sha256_init(void * const p_context)
|
||||
{
|
||||
uint32_t ret_val;
|
||||
CRYSError_t crys_error;
|
||||
|
||||
// Limited parameter testing on this level.
|
||||
// This has been done on upper level.
|
||||
|
||||
nrf_cc310_bl_hash_context_sha256_t * const p_backend_context
|
||||
= &(((nrf_crypto_backend_hash_sha256_context_t *)p_context)->context);
|
||||
|
||||
crys_error = nrf_cc310_bl_hash_sha256_init(p_backend_context);
|
||||
|
||||
ret_val = hash_result_get(crys_error);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
static uint32_t cc310_bl_backend_hash_sha256_update(void * const p_context,
|
||||
uint8_t const * p_data,
|
||||
size_t size)
|
||||
{
|
||||
ret_code_t ret_val;
|
||||
CRYSError_t crys_error;
|
||||
uint32_t cur_size;
|
||||
uint32_t size_left;
|
||||
uint8_t * p_cur;
|
||||
bool mutex_locked;
|
||||
|
||||
// Limited parameter testing on this level.
|
||||
// This has been done on upper level.
|
||||
|
||||
nrf_cc310_bl_hash_context_sha256_t * const p_backend_context
|
||||
= &(((nrf_crypto_backend_hash_sha256_context_t *)p_context)->context);
|
||||
|
||||
p_cur = (uint8_t *)p_data;
|
||||
size_left = size;
|
||||
|
||||
mutex_locked = cc310_backend_mutex_trylock();
|
||||
VERIFY_TRUE(mutex_locked, NRF_ERROR_CRYPTO_BUSY);
|
||||
|
||||
cc310_bl_backend_enable();
|
||||
|
||||
#if defined (NRF_CRYPTO_BACKEND_CC310_BL_HASH_AUTOMATIC_RAM_BUFFER_ENABLED) && (NRF_CRYPTO_BACKEND_CC310_BL_HASH_AUTOMATIC_RAM_BUFFER_ENABLED == 1)
|
||||
|
||||
do
|
||||
{
|
||||
// Copy a block from FLASH to RAM for use in CC310
|
||||
cur_size = (size_left > NRF_CRYPTO_BACKEND_CC310_BL_HASH_AUTOMATIC_RAM_BUFFER_SIZE) ?
|
||||
NRF_CRYPTO_BACKEND_CC310_BL_HASH_AUTOMATIC_RAM_BUFFER_SIZE : size_left;
|
||||
|
||||
// Copy from FLASH to ram
|
||||
memcpy(m_hash_buffer, p_cur, cur_size);
|
||||
|
||||
// Update the hash with current input.
|
||||
crys_error = nrf_cc310_bl_hash_sha256_update(p_backend_context, m_hash_buffer, cur_size);
|
||||
|
||||
size_left -= cur_size;
|
||||
p_cur += cur_size;
|
||||
|
||||
} while(crys_error == SASI_OK && size_left > 0);
|
||||
|
||||
#elif defined(NRF_CRYPTO_BACKEND_CC310_BL_HASH_AUTOMATIC_RAM_BUFFER_ENABLED) && (NRF_CRYPTO_BACKEND_CC310_BL_HASH_AUTOMATIC_RAM_BUFFER_ENABLED == 0)
|
||||
|
||||
// Verify that the data is in RAM (required for CC310 hashing)
|
||||
VERIFY_TRUE(nrfx_is_in_ram(p_data), NRF_ERROR_CRYPTO_INPUT_LOCATION);
|
||||
|
||||
do
|
||||
{
|
||||
// Get the largest block that can sent to the CC310 through DMA
|
||||
cur_size = (size_left > CC310_MAX_LENGTH_DMA_OPERATIONS) ?
|
||||
CC310_MAX_LENGTH_DMA_OPERATIONS : size_left;
|
||||
|
||||
crys_error = nrf_cc310_bl_hash_sha256_update(p_backend_context, p_cur, cur_size);
|
||||
|
||||
size_left -= cur_size;
|
||||
p_cur += cur_size;
|
||||
} while(crys_error == SASI_OK && size_left > 0);
|
||||
|
||||
#else
|
||||
|
||||
UNUSED_PARAMETER(p_backend_context);
|
||||
UNUSED_PARAMETER(cur_size);
|
||||
UNUSED_PARAMETER(size_left);
|
||||
UNUSED_PARAMETER(p_cur);
|
||||
|
||||
#warning NRF_CRYPTO_BACKEND_CC310_BL_HASH_AUTOMATIC_RAM_BUFFER_ENABLED define not found in sdk_config.h (Is the sdk_config.h valid?).
|
||||
|
||||
#endif
|
||||
|
||||
cc310_bl_backend_disable();
|
||||
|
||||
cc310_backend_mutex_unlock();
|
||||
|
||||
ret_val = hash_result_get(crys_error);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
static uint32_t cc310_bl_backend_hash_sha256_finalize(void * const p_context,
|
||||
uint8_t * p_digest,
|
||||
size_t * const p_digest_size)
|
||||
{
|
||||
ret_code_t ret_val;
|
||||
CRYSError_t crys_error;
|
||||
bool mutex_locked;
|
||||
|
||||
// Limited parameter testing on this level.
|
||||
// This has been done on upper level.
|
||||
|
||||
nrf_cc310_bl_hash_context_sha256_t * const p_backend_context
|
||||
= &(((nrf_crypto_backend_hash_sha256_context_t * )p_context)->context);
|
||||
|
||||
nrf_cc310_bl_hash_digest_sha256_t * p_int_digest
|
||||
= (nrf_cc310_bl_hash_digest_sha256_t *)p_digest;
|
||||
|
||||
if (NRF_CRYPTO_HASH_SIZE_SHA256 > *p_digest_size)
|
||||
{
|
||||
return NRF_ERROR_CRYPTO_OUTPUT_LENGTH;
|
||||
}
|
||||
|
||||
mutex_locked = cc310_backend_mutex_trylock();
|
||||
VERIFY_TRUE(mutex_locked, NRF_ERROR_CRYPTO_BUSY);
|
||||
|
||||
cc310_bl_backend_enable();
|
||||
|
||||
// Do the hash finalize calculation
|
||||
crys_error = nrf_cc310_bl_hash_sha256_finalize(p_backend_context, p_int_digest);
|
||||
|
||||
cc310_bl_backend_disable();
|
||||
|
||||
cc310_backend_mutex_unlock();
|
||||
|
||||
ret_val = hash_result_get(crys_error);
|
||||
|
||||
if (ret_val == NRF_SUCCESS)
|
||||
{
|
||||
*p_digest_size = NRF_CRYPTO_HASH_SIZE_SHA256;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
const nrf_crypto_hash_info_t g_nrf_crypto_hash_sha256_info =
|
||||
{
|
||||
.init_fn = cc310_bl_backend_hash_sha256_init,
|
||||
.update_fn = cc310_bl_backend_hash_sha256_update,
|
||||
.finalize_fn = cc310_bl_backend_hash_sha256_finalize,
|
||||
.digest_size = NRF_CRYPTO_HASH_SIZE_SHA256,
|
||||
.hash_mode = NRF_CRYPTO_HASH_MODE_SHA256
|
||||
};
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_HASH_SHA256)
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO) && #if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CC310_BL_BACKEND_HASH_H__
|
||||
#define CC310_BL_BACKEND_HASH_H__
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup nrf_crypto_cc310_bl_backend_hash nrf_crypto CC310_BL backend hash
|
||||
* @{
|
||||
* @ingroup nrf_crypto_cc310_bl_backend
|
||||
*
|
||||
* @brief Hash functionality provided by the nrf_crypto CC310_BL backend.
|
||||
*/
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
#include "sdk_errors.h"
|
||||
#include "nrf_crypto_hash_shared.h"
|
||||
#include "nrf_cc310_bl_hash_sha256.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_HASH_SHA256)
|
||||
|
||||
// Flag that nrf_crypto_hash frontend can be compiled
|
||||
#undef NRF_CRYPTO_HASH_ENABLED
|
||||
#define NRF_CRYPTO_HASH_ENABLED 1
|
||||
|
||||
// Flag that SHA-256 is enabled in backend
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO_HASH_SHA256)
|
||||
#error "Duplicate definition of SHA-256. More than one backend enabled");
|
||||
#endif
|
||||
#define NRF_CRYPTO_HASH_SHA256_ENABLED 1
|
||||
|
||||
|
||||
/**@internal @brief nrf_crypto_hash context for SHA-256 in nrf_crypto CC310_BL backend. */
|
||||
typedef struct
|
||||
{
|
||||
nrf_crypto_hash_internal_context_t header; /**< Common header for context. */
|
||||
nrf_cc310_bl_hash_context_sha256_t context; /**< Hash context internal to CC310_BL. */
|
||||
} nrf_crypto_backend_hash_sha256_context_t;
|
||||
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL_HASH_SHA256)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
/**@} */
|
||||
|
||||
#endif // CC310_BL_BACKEND_HASH_H__
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
#include "nrf.h"
|
||||
#include "nrf_crypto_init.h"
|
||||
#include "nrf_crypto_error.h"
|
||||
|
||||
#include "cc310_bl_backend_shared.h"
|
||||
#include "cc310_backend_mutex.h"
|
||||
#include "sns_silib.h"
|
||||
#include "nrf_cc310_bl_init.h"
|
||||
|
||||
/**@brief Mutex to ensure single access to nrf_cc310_bl resources */
|
||||
nrf_mtx_t g_cc310_mutex;
|
||||
|
||||
static uint32_t init_result_get(uint32_t crys_error)
|
||||
{
|
||||
uint32_t ret_val = NRF_ERROR_INTERNAL;
|
||||
switch (crys_error)
|
||||
{
|
||||
case SA_SILIB_RET_OK:
|
||||
ret_val = NRF_SUCCESS;
|
||||
break;
|
||||
|
||||
case SA_SILIB_RET_EINVAL_HW_VERSION:
|
||||
ret_val = NRF_ERROR_CRYPTO_FEATURE_UNAVAILABLE;
|
||||
break;
|
||||
|
||||
default:
|
||||
ret_val = NRF_ERROR_INTERNAL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
static ret_code_t cc310_bl_backend_init(void)
|
||||
{
|
||||
uint32_t ret_val;
|
||||
CRYSError_t crys_error;
|
||||
|
||||
cc310_backend_mutex_init();
|
||||
|
||||
// Enable the CC310 HW.
|
||||
NRF_CRYPTOCELL->ENABLE = 1;
|
||||
|
||||
// Initialize the CC310_BL run-time library
|
||||
crys_error = nrf_cc310_bl_init();
|
||||
|
||||
// Disable the CC310 HW after initialization.
|
||||
NRF_CRYPTOCELL->ENABLE = 0;
|
||||
|
||||
ret_val = init_result_get(crys_error);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
static ret_code_t cc310_bl_backend_uninit(void)
|
||||
{
|
||||
// Disable the CC310 HW.
|
||||
NRF_CRYPTOCELL->ENABLE = 0;
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
CRYPTO_BACKEND_REGISTER(nrf_crypto_backend_info_t const cc310_bl_backend) =
|
||||
{
|
||||
.init_fn = cc310_bl_backend_init,
|
||||
.uninit_fn = cc310_bl_backend_uninit
|
||||
};
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
#include "nrf.h"
|
||||
#include "cc310_bl_backend_shared.h"
|
||||
#include "nrf_crypto_error.h"
|
||||
|
||||
|
||||
void cc310_bl_backend_enable(void)
|
||||
{
|
||||
// Enable the cryptocell hardware
|
||||
NRF_CRYPTOCELL->ENABLE = 1;
|
||||
|
||||
#if defined(NRF_CRYPTO_BACKEND_CC310_BL_INTERRUPTS_ENABLED) && (NRF_CRYPTO_BACKEND_CC310_BL_INTERRUPTS_ENABLED == 1)
|
||||
|
||||
// Enable the CryptoCell IRQ
|
||||
NVIC_EnableIRQ(CRYPTOCELL_IRQn);
|
||||
|
||||
#elif defined(NRF_CRYPTO_BACKEND_CC310_BL_INTERRUPTS_ENABLED) && (NRF_CRYPTO_BACKEND_CC310_BL_INTERRUPTS_ENABLED == 0)
|
||||
|
||||
// Do nothing
|
||||
|
||||
#else
|
||||
|
||||
#warning NRF_CRYPTO_BACKEND_CC310_BL_INTERRUPTS_ENABLED define not found in sdk_config.h (Is the sdk_config.h valid?).
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
void cc310_bl_backend_disable(void)
|
||||
{
|
||||
// Enable the cryptocell hardware
|
||||
NRF_CRYPTOCELL->ENABLE = 0;
|
||||
|
||||
#if defined(NRF_CRYPTO_BACKEND_CC310_BL_INTERRUPTS_ENABLED) && (NRF_CRYPTO_BACKEND_CC310_BL_INTERRUPTS_ENABLED == 1)
|
||||
|
||||
// Disable the CryptoCell IRQ
|
||||
NVIC_DisableIRQ(CRYPTOCELL_IRQn);
|
||||
|
||||
#elif defined(NRF_CRYPTO_BACKEND_CC310_BL_INTERRUPTS_ENABLED) && (NRF_CRYPTO_BACKEND_CC310_BL_INTERRUPTS_ENABLED == 0)
|
||||
|
||||
// Do nothing
|
||||
|
||||
#else
|
||||
|
||||
#warning NRF_CRYPTO_BACKEND_CC310_BL_INTERRUPTS_ENABLED define not found in sdk_config.h (Is the sdk_config.h valid?).
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form, except as embedded into a Nordic
|
||||
* Semiconductor ASA integrated circuit in a product or a software update for
|
||||
* such product, must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* 4. This software, with or without modification, must only be used with a
|
||||
* Nordic Semiconductor ASA integrated circuit.
|
||||
*
|
||||
* 5. Any software provided in binary form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CC310_BL_BACKEND_SHARED_H__
|
||||
#define CC310_BL_BACKEND_SHARED_H__
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @defgroup nrf_crypto_cc310_bl_backend_shared nrf_crypto CC310_BL backend shared
|
||||
* @{
|
||||
* @ingroup nrf_crypto_cc310_bl_backend
|
||||
*
|
||||
* @brief Shared functionality for the nrf_crypto CC310_BL backend.
|
||||
*/
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#if NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
#include "sdk_errors.h"
|
||||
#include "nrf_crypto_hash_shared.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**@internal @brief Function to enable CC310 (in HW)
|
||||
*/
|
||||
void cc310_bl_backend_enable(void);
|
||||
|
||||
|
||||
/**@internal @brief Function to disable CC310 (in HW)
|
||||
*/
|
||||
void cc310_bl_backend_disable(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_MODULE_ENABLED(NRF_CRYPTO) && NRF_MODULE_ENABLED(NRF_CRYPTO_BACKEND_CC310_BL)
|
||||
|
||||
/**@} */
|
||||
|
||||
#endif // CC310_BL_BACKEND_SHARED_H__
|
||||
Reference in New Issue
Block a user