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_secp256k1: 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_secp256k1 = {
54     /* Field modulus :  GF_Modulus =  FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F - big end*/
55     {0xFFFFFC2F,0xFFFFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF},
56     /* EC equation parameters a, b  */
57     /* a = 0  - big end  from SEC2 */
58     {0x00000000},
59     /* b = 7 - big end  from SEC2 */
60     {0x00000007},
61 
62     /* Order of generator: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 big end  from SEC2 */
63     {0xD0364141,0xBFD25E8C,0xAF48A03B,0xBAAEDCE6,0xFFFFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF},
64 
65     /* Generator  coordinates in affine form: EC_Gener_X, EC_Gener_Y (in ordinary representation) */
66     /* 79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798   X - big end  from SEC2 */
67     {0x16F81798,0x59F2815B,0x2DCE28D9,0x029BFCDB,0xCE870B07,0x55A06295,0xF9DCBBAC,0x79BE667E},
68     /* 483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8  Y - big end  from SEC2 */
69     {0xFB10D4B8,0x9C47D08F,0xA6855419,0xFD17B448,0x0E1108A8,0x5DA4FBFC,0x26A3C465,0x483ADA77},
70 
71     1, /* EC cofactor K */
72 
73     /* Barrett tags NP,RP */
74     #ifdef CC_SUPPORT_PKA_128_32
75     {0x00000000,0x00000000,0x00000000,0x00000000,0x00000080,
76         0x000000A2,0x00000000,0x00000000,0x00000000,0x00000080},
77     #else  // CC_SUPPORT_PKA_64_16
78     {0x00000000,0x00000000,0x00000080,0x00000000, 0x00000000,
79         0x00000000,0x00000000,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_secp256k1,    /* EC Domain identifier - enum */
87     "SECG_PRIME_256K1"
88 };
89 
90 
91 
92 
93 /**
94  @brief    the function returns the domain pointer id the domain is supported for the product;
95         otherwise return NULL
96  @return   return domain pointer or NULL
97 
98 */
CC_EcpkiGetSecp256k1DomainP(void)99 const CCEcpkiDomain_t *CC_EcpkiGetSecp256k1DomainP(void)
100 {
101     return &ecpki_domain_secp256k1;
102 }
103 
104