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  *   Data base of CC_ECPKI_DomainID_secp224r1: structure of type  CCEcpkiDomain_t    *
50  *       All data is given in little endian order of words in arrays               *
51  ***********************************************************************************/
52 static const CCEcpkiDomain_t ecpki_domain_secp224r1 = {
53     /* Field modulus :  GF_Modulus =  FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001  - big end*/
54     {0x00000001,0x00000000,0x00000000,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF},
55     /* EC equation parameters a, b  */
56     /* a = -3 = FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE  - big end  from SEC2 */
57     {0xFFFFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF},
58     /* b = B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4 - big end  from SEC2 */
59     {0x2355FFB4,0x270B3943,0xD7BFD8BA,0x5044B0B7,0xF5413256,0x0C04B3AB,0xB4050A85},
60 
61     /* Order of generator: ord= FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D big end  from SEC2 */
62     {0x5C5C2A3D,0x13DD2945,0xE0B8F03E,0xFFFF16A2,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF},
63 
64     /* Generator  coordinates in affine form: EC_Gener_X, EC_Gener_Y (in ordinary representation) */
65     /* B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21   X - big end  from SEC2 */
66     {0x115C1D21,0x343280D6,0x56C21122,0x4A03C1D3,0x321390B9,0x6BB4BF7F,0xB70E0CBD},
67     /* BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34  Y - big end  from SEC2 */
68     {0x85007E34,0x44D58199,0x5A074764,0xCD4375A0,0x4C22DFE6,0xB5F723FB,0xBD376388},
69 
70     1, /* EC cofactor K */
71 
72     /* Barrett tags NP,RP */
73     #ifdef CC_SUPPORT_PKA_128_32
74     {0x0000007F,0x00000000,0x00000000,0x00000000,0x00000080,
75         0x0074AE8F,0x00000000,0x00000000,0x00000000,0x00000080},
76     #else  // CC_SUPPORT_PKA_64_16
77     {0x00000000,0x00000000,0x00000080,0x00000000, 0x00000000,
78         0x00000000,0x00000000,0x00000080,0x00000000,0x00000000},
79     #endif
80 
81     224, /* Size of field modulus in bits */
82     224, /* Size of order of generator in bits */
83     5,   /* Size of each inserted Barret tag in words; 0 - if not inserted */
84 
85     CC_ECPKI_DomainID_secp224r1,    /* EC Domain identifier - enum */
86     "SECG_PRIME_224R1" /*NIST_P224*/
87 };
88 
89 
90 
91 
92 /**
93  @brief    the function returns the domain pointer id the domain is supported for the product;
94         otherwise return NULL
95  @return   return domain pointer or NULL
96 
97 */
CC_EcpkiGetSecp224r1DomainP(void)98 const CCEcpkiDomain_t *CC_EcpkiGetSecp224r1DomainP(void)
99 {
100     return &ecpki_domain_secp224r1;
101 }
102 
103