forked from ARMmbed/mbed-os
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cc_internal.h
133 lines (115 loc) · 4.3 KB
/
cc_internal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* cc_internal.h
*
* Internal utility functions and definitions,
* used for converting mbedtls types to CC types, and vice versa
*
* Copyright (C) 2018, Arm Limited, All Rights Reserved
* 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.
*
*/
#ifndef __CC_INTERNAL_H__
#define __CC_INTERNAL_H__
#include "crys_ecpki_types.h"
#include "crys_ec_mont_api.h"
#include "mbedtls/ecp.h"
#include <stddef.h>
#include <stdint.h>
#define CURVE_25519_KEY_SIZE 32
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_KEY_SIZE_IN_BYTES ( ( CRYS_ECPKI_MODUL_MAX_LENGTH_IN_WORDS ) * SASI_32BIT_WORD_SIZE)
/* ECC utility functions and structures*/
typedef struct cc_ecc_ws_keygen_params{
CRYS_ECPKI_UserPublKey_t pubKey;
CRYS_ECPKI_UserPrivKey_t privKey;
CRYS_ECPKI_KG_TempData_t kgTempData;
} cc_ecc_ws_keygen_params_t;
typedef struct cc_ecc_ws_comp_shared_params{
CRYS_ECPKI_UserPublKey_t pubKey;
CRYS_ECPKI_UserPrivKey_t privKey;
CRYS_ECDH_TempData_t ecdhTempData;
} cc_ecc_ws_comp_shared_params_t;
typedef struct cc_ecc_ws_verify_params{
CRYS_ECPKI_UserPublKey_t pubKey;
CRYS_ECDSA_VerifyUserContext_t verifyContext;
} cc_ecc_ws_verify_params_t;
typedef struct cc_ecc_ws_sign_params{
CRYS_ECPKI_UserPrivKey_t privKey;
CRYS_ECDSA_SignUserContext_t signContext;
} cc_ecc_ws_sign_params_t;
typedef struct cc_ecc_25519_keygen_params{
uint8_t pubKey[CURVE_25519_KEY_SIZE];
uint8_t privKey[CURVE_25519_KEY_SIZE];
CRYS_ECMONT_TempBuff_t kgTempData;
} cc_ecc_25519_keygen_params_t;
typedef cc_ecc_25519_keygen_params_t cc_ecc_25519_comp_shared_params_t;
/**
* \brief This function converts mbedtls type mbedtls_ecp_group_id
* to Cryptocell type CRYS_ECPKI_DomainID_t
*
* \param grp_id The mbedtls mbedtls_ecp_group_id to convert
*
* \return \c The corresponding CRYS_ECPKI_DomainID_t.
* CRYS_ECPKI_DomainID_OffMode if not recognized.
*/
CRYS_ECPKI_DomainID_t convert_mbedtls_grp_id_to_crys_domain_id( mbedtls_ecp_group_id grp_id );
/* f_rng conversion from mbedtls type to cc type*/
typedef struct
{
int (*f_rng)( void* ctx, unsigned char* output, size_t outSizeBytes );
void* ctx;
}mbedtls_rand_func_container;
/**
* \brief This function converts mbedtls f_rng type to
* Cryptocell f_rng type(SaSiRndGenerateVectWorkFunc_t)
*
* Note: The Mbed TLS type f_rng signature is:
* int (*f_rng)( void* ctx, unsigned char* output, size_t outSizeBytes );
* while CC f_rng signature is:
* uint32_t (*SaSiRndGenerateVectWorkFunc_t)(
* void *rndState_ptr,
* uint16_t outSizeBytes,
* uint8_t *out_ptr)
*
* so the Mbed TLS f_rng can't be sent as is to the CC API.
*
* In addition, this function manipulates the different random data,
* to adjust between the way Cryptocell reads the random data. This is done for
* different standard tests to pass.
*
*
* \param mbedtls_rand The mbedtls rnd context pointer
* \param outSizeBytes The size of the output buffer
* \param out_ptr Pointer to the output buffer
*
* \return \c The corresponding CRYS_ECPKI_DomainID_t.
* CRYS_ECPKI_DomainID_OffMode if not recognized.
*/
uint32_t convert_mbedtls_to_cc_rand( void* mbedtls_rand, uint16_t outSizeBytes, uint8_t* out_ptr );
/**
* \brief This function convertsCryptocell error
* Mbed TLS related error.
*
*
* \return \c The corresponding Mbed TLS error,
* MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED as default, if none found
*/
int convert_CrysError_to_mbedtls_err( CRYSError_t Crys_err );
#ifdef __cplusplus
}
#endif
#endif /* __CC_INTERNAL_H__ */