Mbed OS Reference
Loading...
Searching...
No Matches
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
35extern "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*/
42 CRYS_ECPKI_UserPublKey_t pubKey;
43 CRYS_ECPKI_UserPrivKey_t privKey;
44 CRYS_ECPKI_KG_TempData_t kgTempData;
46
48 CRYS_ECPKI_UserPublKey_t pubKey;
49 CRYS_ECPKI_UserPrivKey_t privKey;
50 CRYS_ECDH_TempData_t ecdhTempData;
52
54 CRYS_ECPKI_UserPublKey_t pubKey;
55 CRYS_ECDSA_VerifyUserContext_t verifyContext;
57
58typedef struct cc_ecc_ws_sign_params{
59 CRYS_ECPKI_UserPrivKey_t privKey;
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 */
80CRYS_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*/
83typedef 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
117uint32_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 */
127int convert_CrysError_to_mbedtls_err( CRYSError_t Crys_err );
128
129#ifdef __cplusplus
130}
131#endif
132
133#endif /* __CC_INTERNAL_H__ */
mbedtls_ecp_group_id
Domain-parameter identifiers: curve, subgroup, and generator.
This file provides an API for Elliptic Curves over GF(P) (ECP).