• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************/
18 #ifndef HW_ECC_H_
19 #define HW_ECC_H_
20 
21 #include "algorithm/ecc/ecc_curve.h"
22 #include "algorithm/ecc/hw_ecc.h"
23 
24 #if ((MCU_CORE_TYPE == MCU_CORE_827x) || (MCU_CORE_TYPE == MCU_CORE_9518))
25 
26 /* hECC_RNG_Function type
27 The RNG function should fill 'size' random bytes into 'dest'. It should return 1 if
28 'dest' was filled with random data, or 0 if the random data could not be generated.
29 The filled-in values should be either truly random, or from a cryptographically-secure PRNG.
30 A correctly functioning RNG function must be set (using hECC_set_rng()) before calling
31 hECC_make_key(). */
32 
33 typedef int (*hECC_rng_func)(unsigned char *dest, unsigned size);
34 
35 /**
36  * @brief		The function that will be used to generate random bytes.
37  * @param[in]	resister predefined TRNG function
38  * @return		none
39  */
40 void hwECC_set_rng(hECC_rng_func rng_func);
41 
42 /**
43  * @brief		get ECCP key pair(the key pair could be used in ECDH).
44  * @param[out]	public_key	- public key, big--endian.
45  * @param[out]	private_key	- private key, big--endian.
46  * @param[in]	curve_sel	- ecc_curve select, e.g.: p-256r1.
47  * @return		1(success), 0(error).
48  */
49 unsigned char hwECC_make_key(unsigned char *public_key, unsigned char *private_key, ecc_curve_t curve_sel);
50 
51 /**
52  * @brief		ECDH compute key.
53  * @param[in]	local_prikey	- local private key, big--endian.
54  * @param[in]	public_key		- peer public key, big--endian.
55  * @param[out]	dhkey			- output dhkey, big--endian.
56  * @param[in]	curve_sel		- ecc_curve select, e.g.: p-256r1.
57  * @Return		1(success); 0(error).
58  */
59 unsigned char hwECC_shared_secret(const unsigned char *public_key, const unsigned char *private_key,
60                                   unsigned char *secret, ecc_curve_t curve_sel);
61 
62 #endif /* HW_ECC_H_ */
63 
64 #endif /* The end of #if((MCU_CORE_TYPE == MCU_CORE_827x) || (MCU_CORE_TYPE == MCU_CORE_9518)) */
65