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_secp256r1: 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_secp256r1 = {
54     /* Field modulus :  GF_Modulus =  FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF - big end*/
55     {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0x00000000,0x00000000,0x00000000,0x00000001,0xFFFFFFFF},
56     /* EC equation parameters a, b  */
57     /* a = FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC  - big end  from SEC2 */
58     {0xFFFFFFFC,0xFFFFFFFF,0xFFFFFFFF,0x00000000,0x00000000,0x00000000,0x00000001,0xFFFFFFFF},
59     /* b = 5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B - big end  from SEC2 */
60     {0x27D2604B,0x3BCE3C3E,0xCC53B0F6,0x651D06B0,0x769886BC,0xB3EBBD55,0xAA3A93E7,0x5AC635D8},
61 
62     /* Order of generator: FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551 big end  from SEC2 */
63     {0xFC632551,0xF3B9CAC2,0xA7179E84,0xBCE6FAAD,0xFFFFFFFF,0xFFFFFFFF,0x00000000,0xFFFFFFFF},
64 
65     /* Generator  coordinates in affine form: EC_Gener_X, EC_Gener_Y (in ordinary representation) */
66     /* 6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296   X - big end  from SEC2 */
67     {0xD898C296,0xF4A13945,0x2DEB33A0,0x77037D81,0x63A440F2,0xF8BCE6E5,0xE12C4247,0x6B17D1F2},
68     /* 4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5  Y - big end  from SEC2 */
69     {0x37BF51F5,0xCBB64068,0x6B315ECE,0x2BCE3357,0x7C0F9E16,0x8EE7EB4A,0xFE1A7F9B,0x4FE342E2},
70 
71     1, /* EC cofactor K */
72 
73     /* Barrett tags NP,RP */
74     #ifdef CC_SUPPORT_PKA_128_32
75     {0xFFFFFF7F,0xFFFFFF7F,0xFFFFFFFF,0x0000007F,0x00000080,
76         0xFFFFFFA1,0xFFFFFF7F,0xFFFFFFFF,0x0000007F,0x00000080},
77     #else  // CC_SUPPORT_PKA_64_16
78     {0xFFFFFFFF,0x0000007F,0x00000080,0x00000000, 0x00000000,
79         0xFFFFFFFF,0x0000007F,0x00000080,0x00000000,0x00000000},
80     #endif
81 
82     256, /* Size of field modulus in bits */
83     256, /* Size of order of generator in bits */
84     5,   /* Size of each inserted Barret tag in words; 0 - if not inserted */
85 
86     CC_ECPKI_DomainID_secp256r1,    /* EC Domain identifier - enum */
87     "SECG_PRIME_256R1" /*NIST_P256*/
88 
89 };
90 
91 
92 
93 
94 /**
95  @brief    the function returns the domain pointer id the domain is supported for the product;
96         otherwise return NULL
97  @return   return domain pointer or NULL
98 
99 */
CC_EcpkiGetSecp256r1DomainP(void)100 const CCEcpkiDomain_t *CC_EcpkiGetSecp256r1DomainP(void)
101 {
102     return &ecpki_domain_secp256r1;
103 }
104 
105