1 /*
2  * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef PKA_ECC_H_H
8 #define PKA_ECC_H_H
9 
10 
11 #ifdef __cplusplus
12 extern "C"
13 {
14 #endif
15 
16 #include "cc_pal_types.h"
17 #include "cc_ecpki_types.h"
18 #include "pka_hw_defs.h"
19 #include "pka.h"
20 #include "ec_wrst.h"
21 
22 
23 #define PKA_ECC_MAX_OPERATION_SIZE_BITS        640  /*for EC 521-bit*/
24 
25 /* maximal size of extended register in "big PKA words" and in 32-bit words:  *
26    the size defined according to RSA as more large, and used to define some   *
27 *  auxiliary buffers sizes                                */
28 #define PKA_ECC_MAX_REGISTER_SIZE_IN_PKA_WORDS ((PKA_ECC_MAX_OPERATION_SIZE_BITS+PKA_EXTRA_BITS+CC_PKA_WORD_SIZE_IN_BITS-1)/CC_PKA_WORD_SIZE_IN_BITS)
29 #define PKA_ECC_MAX_REGISTER_SIZE_WORDS  (PKA_ECC_MAX_REGISTER_SIZE_IN_PKA_WORDS*(CC_PKA_WORD_SIZE_IN_BITS/32))
30 
31 
32 /* affine ec-point (in PKA format) */
33 typedef struct{
34   uint32_t x;
35   uint32_t y;
36 } PkaRegAffPoint_t;
37 
38 /* jacobian ec-point: X:x/z^2, Y:y/z^3, t:a*z^4 (in PKA format) */
39 typedef struct{
40   uint32_t x;
41   uint32_t y;
42   uint32_t z;
43 } PkaRegJcbPoint_t;
44 
45 
46 /* modified jacobian ec-point: X:x/z^2, Y:y/z^3, t:a*z^4 (in PKA format) */
47 typedef struct{
48   uint32_t x;
49   uint32_t y;
50   uint32_t z;
51   uint32_t t;
52 } PkaRegMdfPoint_t;
53 
54 
55 /* EC double: modified-modified */
56 void PkaDoubleMdf2Mdf(
57     const uint32_t x,  const uint32_t y,  const uint32_t z,  const uint32_t t,
58     const uint32_t x1, const uint32_t y1, const uint32_t z1, const uint32_t t1);
59 
60 /* EC double: modified-jacobi */
61 void PkaDoubleMdf2Jcb(
62     const uint32_t x,  const uint32_t y,  const uint32_t z,
63     const uint32_t x1, const uint32_t y1, const uint32_t z1, const uint32_t t1);
64 
65 /* EC add: affine-jacobi-modified */
66 void PkaAddJcbAfn2Mdf(
67     const uint32_t x,  const uint32_t y,  const uint32_t z, const uint32_t t,
68     const uint32_t x1, const uint32_t y1, const uint32_t z1,
69     const uint32_t x2, const uint32_t y2);
70 
71 /* convert to affine */
72 void PkaJcb2Afn(
73     CCEcpkiScaProtection_t fr,
74     const uint32_t x, const uint32_t y, const uint32_t z);
75 
76 /* EC add: affine-affine-affine */
77 void PkaAddAff(
78     const uint32_t x,  const uint32_t y,
79     const uint32_t x1, const uint32_t y1,
80     const uint32_t x2, const uint32_t y2);
81 
82 /* double EC scalar multiplication: R = a*p + b*q */
83 uint32_t PkaSum2ScalarMullt(
84     const uint32_t xr, const uint32_t yr, const uint32_t a,
85     const uint32_t xp, const uint32_t yp, const uint32_t b,
86     const uint32_t xq, const uint32_t yq);
87 
88 
89 CCError_t PkaEcWrstScalarMult(const CCEcpkiDomain_t *pDomain,
90                              const uint32_t       *scalar,
91                              uint32_t             scalSizeInWords,
92                              const uint32_t       *inPointX,
93                              const uint32_t       *inPointY,
94                              uint32_t             *outPointX,
95                              uint32_t             *outPointY,
96                              uint32_t             *tmpBuff);
97 
98 CCError_t PkaEcdsaVerify(void);
99 
100 
101 #ifdef __cplusplus
102 }
103 
104 #endif
105 
106 #endif
107 
108 
109