1 /***************************************************************************//**
2 * \file cy_crypto_core_ecc.h
3 * \version 2.40
4 *
5 * \brief
6 *  This file provides constant and parameters for the API for the ECC
7 *  in the Crypto driver.
8 *
9 ********************************************************************************
10 * Copyright 2016-2020 Cypress Semiconductor Corporation
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 *    http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *******************************************************************************/
25 
26 
27 #if !defined (CY_CRYPTO_CORE_ECC_H)
28 #define CY_CRYPTO_CORE_ECC_H
29 
30 #include "cy_device.h"
31 
32 #if defined (CY_IP_MXCRYPTO)
33 
34 #include "cy_crypto_common.h"
35 
36 #if defined(__cplusplus)
37 extern "C" {
38 #endif
39 
40 #if (CPUSS_CRYPTO_VU == 1)
41 
42 typedef enum cy_en_red_mul_algs {
43     CY_CRYPTO_NIST_P_CURVE_SPECIFIC_RED_ALG = 0,
44     CY_CRYPTO_NIST_P_SHIFT_MUL_RED_ALG,
45     CY_CRYPTO_NIST_P_BARRETT_RED_ALG
46 } cy_en_crypto_ecc_red_mul_algs_t;
47 
48 /** Structure defines a NIST GF(p) curve */
49 typedef struct {
50     /**  The curve ID */
51     cy_en_crypto_ecc_curve_id_t id;
52     /** The size of the curve in bits */
53     uint32_t size;
54     /** name of curve */
55     const char_t *name;
56     /** ECC calculation default algorithm */
57     cy_en_crypto_ecc_red_mul_algs_t algo;
58     /** The prime that defines the field the curve is in (encoded in hex) */
59     const uint8_t *prime;
60     /** Barrett coefficient for reduction modulo ECC prime (hex) */
61     const uint8_t *barrett_p;
62     /** The order of the curve (hex) */
63     const uint8_t *order;
64     /** Barrett coefficient for reduction modulo ECC order (hex) */
65     const uint8_t *barrett_o;
66     /** The x co-ordinate of the base point on the curve (hex) */
67     const uint8_t *Gx;
68     /** The y co-ordinate of the base point on the curve (hex) */
69     const uint8_t *Gy;
70 } cy_stc_crypto_ecc_dp_type;
71 
72 
73 cy_stc_crypto_ecc_dp_type *Cy_Crypto_Core_ECC_GetCurveParams(cy_en_crypto_ecc_curve_id_t curveId);
74 
75 /**
76 * \addtogroup group_crypto_lld_asymmetric_functions
77 * \{
78 */
79 
80 /** Pointer to a random number supplier function */
81 typedef int (*cy_func_get_random_data_t)(void *rndInfo, uint8_t *rndData, size_t rndSize);
82 
83 cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakeKeyPair(CRYPTO_Type *base,
84                                    cy_en_crypto_ecc_curve_id_t curveID,
85                                    cy_stc_crypto_ecc_key *key,
86                                    cy_func_get_random_data_t GetRandomDataFunc, void *randomDataInfo);
87 cy_en_crypto_status_t Cy_Crypto_Core_ECC_SignHash(CRYPTO_Type *base,
88                                     const uint8_t *hash,
89                                     uint32_t hashlen,
90                                     uint8_t *sig,
91                                     const cy_stc_crypto_ecc_key *key,
92                                     const uint8_t *messageKey);
93 cy_en_crypto_status_t Cy_Crypto_Core_ECC_VerifyHash(CRYPTO_Type *base,
94                                     const uint8_t *sig,
95                                     const uint8_t *hash,
96                                     uint32_t hashlen,
97                                     uint8_t *stat,
98                                     const cy_stc_crypto_ecc_key *key);
99 
100 cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakePrivateKey(CRYPTO_Type *base,
101         cy_en_crypto_ecc_curve_id_t curveID, uint8_t *key,
102         cy_func_get_random_data_t GetRandomDataFunc, void *randomDataInfo);
103 cy_en_crypto_status_t Cy_Crypto_Core_ECC_MakePublicKey(CRYPTO_Type *base,
104         cy_en_crypto_ecc_curve_id_t curveID,
105         const uint8_t *privateKey, cy_stc_crypto_ecc_key *publicKey);
106 
107 /** \} group_crypto_lld_asymmetric_functions */
108 
109 /* Sizes for NIST P-curves */
110 #define CY_CRYPTO_ECC_P192_SIZE            (192u)      /* 2^192 - 2^64 - 1 */
111 #define CY_CRYPTO_ECC_P192_BYTE_SIZE       CY_CRYPTO_BYTE_SIZE_OF_BITS(CY_CRYPTO_ECC_P192_SIZE)
112 
113 #define CY_CRYPTO_ECC_P224_SIZE            (224u)      /* 2^224 - 2^96  + 1 */
114 #define CY_CRYPTO_ECC_P224_BYTE_SIZE       CY_CRYPTO_BYTE_SIZE_OF_BITS(CY_CRYPTO_ECC_P224_SIZE)
115 
116 #define CY_CRYPTO_ECC_P256_SIZE            (256u)      /* 2^256 - 2^224 + 2^192 + 2^96 - 1 */
117 #define CY_CRYPTO_ECC_P256_BYTE_SIZE       CY_CRYPTO_BYTE_SIZE_OF_BITS(CY_CRYPTO_ECC_P256_SIZE)
118 
119 #define CY_CRYPTO_ECC_P384_SIZE            (384u)      /* 2^384 - 2^128 - 2^96 + 2^32 - 1 */
120 #define CY_CRYPTO_ECC_P384_BYTE_SIZE       CY_CRYPTO_BYTE_SIZE_OF_BITS(CY_CRYPTO_ECC_P384_SIZE)
121 
122 #define CY_CRYPTO_ECC_P521_SIZE            (521u)      /* 2^521 - 1 */
123 #define CY_CRYPTO_ECC_P521_BYTE_SIZE       CY_CRYPTO_BYTE_SIZE_OF_BITS(CY_CRYPTO_ECC_P521_SIZE)
124 
125 #define CY_CRYPTO_ECC_MAX_SIZE             (CY_CRYPTO_ECC_P521_SIZE)
126 #define CY_CRYPTO_ECC_MAX_BYTE_SIZE        (CY_CRYPTO_ECC_P521_BYTE_SIZE)
127 
128 /* "Global" vector unit registers. */
129 #define VR_D                               10u
130 #define VR_S_X                             11u
131 #define VR_S_Y                             12u
132 #define VR_BARRETT                         13u
133 #define VR_P                               14u         /* polynomial */
134 
135 
136 #endif /* #if (CPUSS_CRYPTO_VU == 1) */
137 
138 #if defined(__cplusplus)
139 }
140 #endif
141 
142 #endif /* #if defined (CY_IP_MXCRYPTO) */
143 
144 #endif /* CY_CRYPTO_CORE_ECC_H  */
145 
146 
147 /* [] END OF FILE */
148