Mistake on this page?
Report an issue in GitHub or email us
cc_internal.h
1 /*
2  * cc_internal.h
3  *
4  * Internal utility functions and definitions,
5  * used for converting mbedtls types to CC types, and vice versa
6  *
7  * Copyright (C) 2018, Arm Limited, All Rights Reserved
8  * SPDX-License-Identifier: Apache-2.0
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License"); you may
11  * not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */
23 
24 #ifndef __CC_INTERNAL_H__
25 #define __CC_INTERNAL_H__
26 #include "crys_ecpki_types.h"
27 #include "crys_ec_mont_api.h"
28 #include "mbedtls/ecp.h"
29 #include <stddef.h>
30 #include <stdint.h>
31 
32 #define CURVE_25519_KEY_SIZE 32
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #define MAX_KEY_SIZE_IN_BYTES ( ( CRYS_ECPKI_MODUL_MAX_LENGTH_IN_WORDS ) * SASI_32BIT_WORD_SIZE)
39 
40 /* ECC utility functions and structures*/
41 typedef struct cc_ecc_ws_keygen_params{
44  CRYS_ECPKI_KG_TempData_t kgTempData;
46 
50  CRYS_ECDH_TempData_t ecdhTempData;
52 
53 typedef struct cc_ecc_ws_verify_params{
55  CRYS_ECDSA_VerifyUserContext_t verifyContext;
57 
58 typedef struct cc_ecc_ws_sign_params{
60  CRYS_ECDSA_SignUserContext_t signContext;
62 
64  uint8_t pubKey[CURVE_25519_KEY_SIZE];
65  uint8_t privKey[CURVE_25519_KEY_SIZE];
66  CRYS_ECMONT_TempBuff_t kgTempData;
68 
70 
71 /**
72  * \brief This function converts mbedtls type mbedtls_ecp_group_id
73  * to Cryptocell type CRYS_ECPKI_DomainID_t
74  *
75  * \param grp_id The mbedtls mbedtls_ecp_group_id to convert
76  *
77  * \return \c The corresponding CRYS_ECPKI_DomainID_t.
78  * CRYS_ECPKI_DomainID_OffMode if not recognized.
79  */
80 CRYS_ECPKI_DomainID_t convert_mbedtls_grp_id_to_crys_domain_id( mbedtls_ecp_group_id grp_id );
81 
82 /* f_rng conversion from mbedtls type to cc type*/
83 typedef struct
84 {
85  int (*f_rng)( void* ctx, unsigned char* output, size_t outSizeBytes );
86  void* ctx;
87 
89 
90 /**
91  * \brief This function converts mbedtls f_rng type to
92  * Cryptocell f_rng type(SaSiRndGenerateVectWorkFunc_t)
93  *
94  * Note: The Mbed TLS type f_rng signature is:
95  * int (*f_rng)( void* ctx, unsigned char* output, size_t outSizeBytes );
96  * while CC f_rng signature is:
97  * uint32_t (*SaSiRndGenerateVectWorkFunc_t)(
98  * void *rndState_ptr,
99  * uint16_t outSizeBytes,
100  * uint8_t *out_ptr)
101  *
102  * so the Mbed TLS f_rng can't be sent as is to the CC API.
103  *
104  * In addition, this function manipulates the different random data,
105  * to adjust between the way Cryptocell reads the random data. This is done for
106  * different standard tests to pass.
107  *
108  *
109  * \param mbedtls_rand The mbedtls rnd context pointer
110  * \param outSizeBytes The size of the output buffer
111  * \param out_ptr Pointer to the output buffer
112  *
113  * \return \c The corresponding CRYS_ECPKI_DomainID_t.
114  * CRYS_ECPKI_DomainID_OffMode if not recognized.
115  */
116 
117 uint32_t convert_mbedtls_to_cc_rand( void* mbedtls_rand, uint16_t outSizeBytes, uint8_t* out_ptr );
118 
119 /**
120  * \brief This function convertsCryptocell error
121  * Mbed TLS related error.
122  *
123  *
124  * \return \c The corresponding Mbed TLS error,
125  * MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED as default, if none found
126  */
127 int convert_CrysError_to_mbedtls_err( CRYSError_t Crys_err );
128 
129 #ifdef __cplusplus
130 }
131 #endif
132 
133 #endif /* __CC_INTERNAL_H__ */
CRYS_ECPKI_DomainID_t
Contains all of the enums and definitions that are used for the CRYS ECPKI APIs.
This file contains the CRYS APIs used for EC MONT (Montgomery Curve25519) algorithms.
uint32_t CRYSError_t
Definition: crys_error.h:253
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.