mbed-os5 only for TYBLE16
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
features/cryptocell/FEATURE_CRYPTOCELL310/cc_internal.h@1:9db0e321a9f4, 2019-12-31 (annotated)
- Committer:
- kenjiArai
- Date:
- Tue Dec 31 06:02:27 2019 +0000
- Revision:
- 1:9db0e321a9f4
- Parent:
- 0:5b88d5760320
updated based on mbed-os5.15.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:5b88d5760320 | 1 | /* |
kenjiArai | 0:5b88d5760320 | 2 | * cc_internal.h |
kenjiArai | 0:5b88d5760320 | 3 | * |
kenjiArai | 0:5b88d5760320 | 4 | * Internal utility functions and definitions, |
kenjiArai | 0:5b88d5760320 | 5 | * used for converting mbedtls types to CC types, and vice versa |
kenjiArai | 0:5b88d5760320 | 6 | * |
kenjiArai | 0:5b88d5760320 | 7 | * Copyright (C) 2018, Arm Limited, All Rights Reserved |
kenjiArai | 0:5b88d5760320 | 8 | * SPDX-License-Identifier: Apache-2.0 |
kenjiArai | 0:5b88d5760320 | 9 | * |
kenjiArai | 0:5b88d5760320 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
kenjiArai | 0:5b88d5760320 | 11 | * not use this file except in compliance with the License. |
kenjiArai | 0:5b88d5760320 | 12 | * You may obtain a copy of the License at |
kenjiArai | 0:5b88d5760320 | 13 | * |
kenjiArai | 0:5b88d5760320 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
kenjiArai | 0:5b88d5760320 | 15 | * |
kenjiArai | 0:5b88d5760320 | 16 | * Unless required by applicable law or agreed to in writing, software |
kenjiArai | 0:5b88d5760320 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
kenjiArai | 0:5b88d5760320 | 18 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kenjiArai | 0:5b88d5760320 | 19 | * See the License for the specific language governing permissions and |
kenjiArai | 0:5b88d5760320 | 20 | * limitations under the License. |
kenjiArai | 0:5b88d5760320 | 21 | * |
kenjiArai | 0:5b88d5760320 | 22 | */ |
kenjiArai | 0:5b88d5760320 | 23 | |
kenjiArai | 0:5b88d5760320 | 24 | #ifndef __CC_INTERNAL_H__ |
kenjiArai | 0:5b88d5760320 | 25 | #define __CC_INTERNAL_H__ |
kenjiArai | 0:5b88d5760320 | 26 | #include "crys_ecpki_types.h" |
kenjiArai | 0:5b88d5760320 | 27 | #include "crys_ec_mont_api.h" |
kenjiArai | 0:5b88d5760320 | 28 | #include "mbedtls/ecp.h" |
kenjiArai | 0:5b88d5760320 | 29 | #include <stddef.h> |
kenjiArai | 0:5b88d5760320 | 30 | #include <stdint.h> |
kenjiArai | 0:5b88d5760320 | 31 | |
kenjiArai | 0:5b88d5760320 | 32 | #define CURVE_25519_KEY_SIZE 32 |
kenjiArai | 0:5b88d5760320 | 33 | |
kenjiArai | 0:5b88d5760320 | 34 | #ifdef __cplusplus |
kenjiArai | 0:5b88d5760320 | 35 | extern "C" { |
kenjiArai | 0:5b88d5760320 | 36 | #endif |
kenjiArai | 0:5b88d5760320 | 37 | |
kenjiArai | 0:5b88d5760320 | 38 | #define MAX_KEY_SIZE_IN_BYTES ( ( CRYS_ECPKI_MODUL_MAX_LENGTH_IN_WORDS ) * SASI_32BIT_WORD_SIZE) |
kenjiArai | 0:5b88d5760320 | 39 | |
kenjiArai | 0:5b88d5760320 | 40 | /* ECC utility functions and structures*/ |
kenjiArai | 0:5b88d5760320 | 41 | typedef struct cc_ecc_ws_keygen_params{ |
kenjiArai | 0:5b88d5760320 | 42 | CRYS_ECPKI_UserPublKey_t pubKey; |
kenjiArai | 0:5b88d5760320 | 43 | CRYS_ECPKI_UserPrivKey_t privKey; |
kenjiArai | 0:5b88d5760320 | 44 | CRYS_ECPKI_KG_TempData_t kgTempData; |
kenjiArai | 0:5b88d5760320 | 45 | } cc_ecc_ws_keygen_params_t; |
kenjiArai | 0:5b88d5760320 | 46 | |
kenjiArai | 0:5b88d5760320 | 47 | typedef struct cc_ecc_ws_comp_shared_params{ |
kenjiArai | 0:5b88d5760320 | 48 | CRYS_ECPKI_UserPublKey_t pubKey; |
kenjiArai | 0:5b88d5760320 | 49 | CRYS_ECPKI_UserPrivKey_t privKey; |
kenjiArai | 0:5b88d5760320 | 50 | CRYS_ECDH_TempData_t ecdhTempData; |
kenjiArai | 0:5b88d5760320 | 51 | } cc_ecc_ws_comp_shared_params_t; |
kenjiArai | 0:5b88d5760320 | 52 | |
kenjiArai | 0:5b88d5760320 | 53 | typedef struct cc_ecc_ws_verify_params{ |
kenjiArai | 0:5b88d5760320 | 54 | CRYS_ECPKI_UserPublKey_t pubKey; |
kenjiArai | 0:5b88d5760320 | 55 | CRYS_ECDSA_VerifyUserContext_t verifyContext; |
kenjiArai | 0:5b88d5760320 | 56 | } cc_ecc_ws_verify_params_t; |
kenjiArai | 0:5b88d5760320 | 57 | |
kenjiArai | 0:5b88d5760320 | 58 | typedef struct cc_ecc_ws_sign_params{ |
kenjiArai | 0:5b88d5760320 | 59 | CRYS_ECPKI_UserPrivKey_t privKey; |
kenjiArai | 0:5b88d5760320 | 60 | CRYS_ECDSA_SignUserContext_t signContext; |
kenjiArai | 0:5b88d5760320 | 61 | } cc_ecc_ws_sign_params_t; |
kenjiArai | 0:5b88d5760320 | 62 | |
kenjiArai | 0:5b88d5760320 | 63 | typedef struct cc_ecc_25519_keygen_params{ |
kenjiArai | 0:5b88d5760320 | 64 | uint8_t pubKey[CURVE_25519_KEY_SIZE]; |
kenjiArai | 0:5b88d5760320 | 65 | uint8_t privKey[CURVE_25519_KEY_SIZE]; |
kenjiArai | 0:5b88d5760320 | 66 | CRYS_ECMONT_TempBuff_t kgTempData; |
kenjiArai | 0:5b88d5760320 | 67 | } cc_ecc_25519_keygen_params_t; |
kenjiArai | 0:5b88d5760320 | 68 | |
kenjiArai | 0:5b88d5760320 | 69 | typedef cc_ecc_25519_keygen_params_t cc_ecc_25519_comp_shared_params_t; |
kenjiArai | 0:5b88d5760320 | 70 | |
kenjiArai | 0:5b88d5760320 | 71 | /** |
kenjiArai | 0:5b88d5760320 | 72 | * \brief This function converts mbedtls type mbedtls_ecp_group_id |
kenjiArai | 0:5b88d5760320 | 73 | * to Cryptocell type CRYS_ECPKI_DomainID_t |
kenjiArai | 0:5b88d5760320 | 74 | * |
kenjiArai | 0:5b88d5760320 | 75 | * \param grp_id The mbedtls mbedtls_ecp_group_id to convert |
kenjiArai | 0:5b88d5760320 | 76 | * |
kenjiArai | 0:5b88d5760320 | 77 | * \return \c The corresponding CRYS_ECPKI_DomainID_t. |
kenjiArai | 0:5b88d5760320 | 78 | * CRYS_ECPKI_DomainID_OffMode if not recognized. |
kenjiArai | 0:5b88d5760320 | 79 | */ |
kenjiArai | 0:5b88d5760320 | 80 | CRYS_ECPKI_DomainID_t convert_mbedtls_grp_id_to_crys_domain_id( mbedtls_ecp_group_id grp_id ); |
kenjiArai | 0:5b88d5760320 | 81 | |
kenjiArai | 0:5b88d5760320 | 82 | /* f_rng conversion from mbedtls type to cc type*/ |
kenjiArai | 0:5b88d5760320 | 83 | typedef struct |
kenjiArai | 0:5b88d5760320 | 84 | { |
kenjiArai | 0:5b88d5760320 | 85 | int (*f_rng)( void* ctx, unsigned char* output, size_t outSizeBytes ); |
kenjiArai | 0:5b88d5760320 | 86 | void* ctx; |
kenjiArai | 0:5b88d5760320 | 87 | |
kenjiArai | 0:5b88d5760320 | 88 | }mbedtls_rand_func_container; |
kenjiArai | 0:5b88d5760320 | 89 | |
kenjiArai | 0:5b88d5760320 | 90 | /** |
kenjiArai | 0:5b88d5760320 | 91 | * \brief This function converts mbedtls f_rng type to |
kenjiArai | 0:5b88d5760320 | 92 | * Cryptocell f_rng type(SaSiRndGenerateVectWorkFunc_t) |
kenjiArai | 0:5b88d5760320 | 93 | * |
kenjiArai | 0:5b88d5760320 | 94 | * Note: The Mbed TLS type f_rng signature is: |
kenjiArai | 0:5b88d5760320 | 95 | * int (*f_rng)( void* ctx, unsigned char* output, size_t outSizeBytes ); |
kenjiArai | 0:5b88d5760320 | 96 | * while CC f_rng signature is: |
kenjiArai | 0:5b88d5760320 | 97 | * uint32_t (*SaSiRndGenerateVectWorkFunc_t)( |
kenjiArai | 0:5b88d5760320 | 98 | * void *rndState_ptr, |
kenjiArai | 0:5b88d5760320 | 99 | * uint16_t outSizeBytes, |
kenjiArai | 0:5b88d5760320 | 100 | * uint8_t *out_ptr) |
kenjiArai | 0:5b88d5760320 | 101 | * |
kenjiArai | 0:5b88d5760320 | 102 | * so the Mbed TLS f_rng can't be sent as is to the CC API. |
kenjiArai | 0:5b88d5760320 | 103 | * |
kenjiArai | 0:5b88d5760320 | 104 | * In addition, this function manipulates the different random data, |
kenjiArai | 0:5b88d5760320 | 105 | * to adjust between the way Cryptocell reads the random data. This is done for |
kenjiArai | 0:5b88d5760320 | 106 | * different standard tests to pass. |
kenjiArai | 0:5b88d5760320 | 107 | * |
kenjiArai | 0:5b88d5760320 | 108 | * |
kenjiArai | 0:5b88d5760320 | 109 | * \param mbedtls_rand The mbedtls rnd context pointer |
kenjiArai | 0:5b88d5760320 | 110 | * \param outSizeBytes The size of the output buffer |
kenjiArai | 0:5b88d5760320 | 111 | * \param out_ptr Pointer to the output buffer |
kenjiArai | 0:5b88d5760320 | 112 | * |
kenjiArai | 0:5b88d5760320 | 113 | * \return \c The corresponding CRYS_ECPKI_DomainID_t. |
kenjiArai | 0:5b88d5760320 | 114 | * CRYS_ECPKI_DomainID_OffMode if not recognized. |
kenjiArai | 0:5b88d5760320 | 115 | */ |
kenjiArai | 0:5b88d5760320 | 116 | |
kenjiArai | 0:5b88d5760320 | 117 | uint32_t convert_mbedtls_to_cc_rand( void* mbedtls_rand, uint16_t outSizeBytes, uint8_t* out_ptr ); |
kenjiArai | 0:5b88d5760320 | 118 | |
kenjiArai | 0:5b88d5760320 | 119 | /** |
kenjiArai | 0:5b88d5760320 | 120 | * \brief This function convertsCryptocell error |
kenjiArai | 0:5b88d5760320 | 121 | * Mbed TLS related error. |
kenjiArai | 0:5b88d5760320 | 122 | * |
kenjiArai | 0:5b88d5760320 | 123 | * |
kenjiArai | 0:5b88d5760320 | 124 | * \return \c The corresponding Mbed TLS error, |
kenjiArai | 0:5b88d5760320 | 125 | * MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED as default, if none found |
kenjiArai | 0:5b88d5760320 | 126 | */ |
kenjiArai | 0:5b88d5760320 | 127 | int convert_CrysError_to_mbedtls_err( CRYSError_t Crys_err ); |
kenjiArai | 0:5b88d5760320 | 128 | |
kenjiArai | 0:5b88d5760320 | 129 | #ifdef __cplusplus |
kenjiArai | 0:5b88d5760320 | 130 | } |
kenjiArai | 0:5b88d5760320 | 131 | #endif |
kenjiArai | 0:5b88d5760320 | 132 | |
kenjiArai | 0:5b88d5760320 | 133 | #endif /* __CC_INTERNAL_H__ */ |