1 /*
2  * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /*
8  * All the includes that are needed for code using this module to
9  * compile correctly should be #included here.
10  */
11 #include "cc_pal_types.h"
12 #include "cc_ecpki_types.h"
13 
14 
15 /**************** The domain structure describing *************/
16 /**
17 // The structure containing EC domain parameters in little-endian form.
18 // Elliptic curve: Y^2 = X^3 + A*X + B over prime fild GFp
19 
20 typedef  struct {
21 
22     // Field modulus:  GF_Modulus = P
23     uint32_t    ecP [CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS];
24     // EC equation parameters a, b
25     uint32_t    ecA [CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS];
26     uint32_t    ecB [CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS];
27     // Order of generator: EC_GenerOrder
28     uint32_t    ecOrd [CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS + 1];
29     // Generator (EC base point) coordinates in projective form
30     uint32_t    ecGx [CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS];
31     uint32_t    ecGy [CC_ECPKI_MODUL_MAX_LENGTH_IN_WORDS];
32     // EC cofactor EC_Cofactor_K
33     uint32_t    ecH;
34     // include the specific fields that are used by the low level
35     uint32_t      barrTagBuff[CC_PKA_DOMAIN_BUFF_SIZE_IN_WORDS];
36     // Size of fields in bits
37     uint32_t    modSizeInBits;
38     uint32_t    ordSizeInBits;
39     // Size of each inserted Barret tag in words; 0 - if not inserted
40     uint32_t    barrTagSizeInWords;
41     CCEcpkiDomainID_t   DomainID;
42     int8_t  name[20];
43 
44 } CCEcpkiDomain_t;
45 
46 */
47 
48 
49 /***********************************************************************************
50  *   Data base of CC_ECPKI_DomainID_secp521r1: structure of type  CCEcpkiDomain_t    *
51  *       All data is given in little endian order of words in arrays               *
52  ***********************************************************************************/
53 static const CCEcpkiDomain_t ecpki_domain_secp521r1 = {
54     /* Field modulus :                            *
55     *  GF_Modulus =  P= 1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF */
56     {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
57      0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0x000001FF},
58     /* EC equation parameters a, b  */
59     /* a = 1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC  - big end  from SEC2 */
60     {0xFFFFFFFC,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
61      0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0x000001FF},
62     /* b = Bec= 51953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00  */
63     {0x6B503F00,0xEF451FD4,0x3D2C34F1,0x3573DF88,0x3BB1BF07,0x1652C0BD,0xEC7E937B,0x56193951,
64      0x8EF109E1,0xB8B48991,0x99B315F3,0xA2DA725B,0xB68540EE,0x929A21A0,0x8E1C9A1F,0x953EB961,0x00000051},
65 
66     /* Order of generator: 1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409 big end  from SEC2 */
67     {0x91386409,0xBB6FB71E,0x899C47AE,0x3BB5C9B8,0xF709A5D0,0x7FCC0148,0xBF2F966B,0x51868783,
68      0xFFFFFFFA,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0x000001FF},
69 
70     /* Generator  coordinates in affine form: EC_Gener_X, EC_Gener_Y (in ordinary representation) */
71     /* Gx= C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66  */
72     {0xC2E5BD66,0xF97E7E31,0x856A429B,0x3348B3C1,0xA2FFA8DE,0xFE1DC127,0xEFE75928,0xA14B5E77,
73      0x6B4D3DBA,0xF828AF60,0x053FB521,0x9C648139,0x2395B442,0x9E3ECB66,0x0404E9CD,0x858E06B7,0x000000C6},
74     /* Gy= 11839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650  Y - big end  from SEC2 */
75     {0x9FD16650,0x88BE9476,0xA272C240,0x353C7086,0x3FAD0761,0xC550B901,0x5EF42640,0x97EE7299,
76      0x273E662C,0x17AFBD17,0x579B4468,0x98F54449,0x2C7D1BD9,0x5C8A5FB4,0x9A3BC004,0x39296A78,0x00000118},
77     1, /* EC cofactor K */
78 
79     /* Barrett tags NP,RP */
80     #ifdef CC_SUPPORT_PKA_128_32
81     {0x00000000,0x00000000,0x00000000,0x00000000,0x00000080,
82         0x00000000,0x00000000,0x00000000,0x00000000,0x00000080},
83     #else  // CC_SUPPORT_PKA_64_16
84     {0x00000000,0x00000000,0x00000080,0x00000000, 0x00000000,
85         0x00000000,0x00000000,0x00000080,0x00000000,0x00000000},
86     #endif
87 
88     521, /* Size of field modulus in bits */
89     521, /* Size of order of generator in bits */
90     5,   /* Size of each inserted Barret tag in words; 0 - if not inserted */
91 
92     CC_ECPKI_DomainID_secp521r1,    /* EC Domain identifier - enum */
93     "SECG_PRIME_521R1" /*NIST_P521*/
94 };
95 
96 
97 
98 
99 /**
100  @brief    the function returns the domain pointer id the domain is supported for the product;
101         otherwise return NULL
102  @return   return domain pointer or NULL
103 
104 */
CC_EcpkiGetSecp521r1DomainP(void)105 const CCEcpkiDomain_t *CC_EcpkiGetSecp521r1DomainP(void)
106 {
107     return &ecpki_domain_secp521r1;
108 }
109 
110