ec_curves.c
Go to the documentation of this file.
1 /**
2  * @file ec_curves.c
3  * @brief Elliptic curves
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/crypto.h"
36 #include "ecc/ec_curves.h"
37 #include "encoding/oid.h"
38 #include "debug.h"
39 
40 //Check crypto library configuration
41 #if (EC_SUPPORT == ENABLED)
42 
43 //Macro definition
44 #define CLEAR_WORD32(a, i, n) osMemset((a)->data + i, 0, n * MPI_INT_SIZE);
45 #define COPY_WORD32(a, i, b, j, n) osMemcpy((a)->data + i, (b)->data + j, n * MPI_INT_SIZE);
46 
47 //secp112r1 OID (1.3.132.0.6)
48 const uint8_t SECP112R1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x06};
49 //secp112r2 OID (1.3.132.0.7)
50 const uint8_t SECP112R2_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x07};
51 //secp128r1 OID (1.3.132.0.28)
52 const uint8_t SECP128R1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x1C};
53 //secp128r2 OID (1.3.132.0.29)
54 const uint8_t SECP128R2_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x1D};
55 //secp160k1 OID (1.3.132.0.9)
56 const uint8_t SECP160K1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x09};
57 //secp160r1 OID (1.3.132.0.8)
58 const uint8_t SECP160R1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x08};
59 //secp160r2 OID (1.3.132.0.30)
60 const uint8_t SECP160R2_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x1E};
61 //secp192k1 OID (1.3.132.0.31)
62 const uint8_t SECP192K1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x1F};
63 //secp192r1 OID (1.2.840.10045.3.1.1)
64 const uint8_t SECP192R1_OID[8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x01};
65 //secp224k1 OID (1.3.132.0.32)
66 const uint8_t SECP224K1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x20};
67 //secp224r1 OID (1.3.132.0.33)
68 const uint8_t SECP224R1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x21};
69 //secp256k1 OID (1.3.132.0.10)
70 const uint8_t SECP256K1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x0A};
71 //secp256r1 OID (1.2.840.10045.3.1.7)
72 const uint8_t SECP256R1_OID[8] = {0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07};
73 //secp384r1 OID (1.3.132.0.34)
74 const uint8_t SECP384R1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x22};
75 //secp521r1 OID (1.3.132.0.35)
76 const uint8_t SECP521R1_OID[5] = {0x2B, 0x81, 0x04, 0x00, 0x23};
77 //brainpoolP160r1 OID (1.3.36.3.3.2.8.1.1.1)
78 const uint8_t BRAINPOOLP160R1_OID[9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x01};
79 //brainpoolP192r1 OID (1.3.36.3.3.2.8.1.1.3)
80 const uint8_t BRAINPOOLP192R1_OID[9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x03};
81 //brainpoolP224r1 OID (1.3.36.3.3.2.8.1.1.5)
82 const uint8_t BRAINPOOLP224R1_OID[9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x05};
83 //brainpoolP256r1 OID (1.3.36.3.3.2.8.1.1.7)
84 const uint8_t BRAINPOOLP256R1_OID[9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x07};
85 //brainpoolP320r1 OID (1.3.36.3.3.2.8.1.1.9)
86 const uint8_t BRAINPOOLP320R1_OID[9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x09};
87 //brainpoolP384r1 OID (1.3.36.3.3.2.8.1.1.11)
88 const uint8_t BRAINPOOLP384R1_OID[9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0B};
89 //brainpoolP512r1 OID (1.3.36.3.3.2.8.1.1.13)
90 const uint8_t BRAINPOOLP512R1_OID[9] = {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0D};
91 //SM2 OID (1.2.156.10197.1.301)
92 const uint8_t SM2_OID[8] = {0x2A, 0x81, 0x1C, 0xCF, 0x55, 0x01, 0x82, 0x2D};
93 //X25519 OID (1.3.101.110)
94 const uint8_t X25519_OID[3] = {0x2B, 0x65, 0x6E};
95 //X448 OID (1.3.101.111)
96 const uint8_t X448_OID[3] = {0x2B, 0x65, 0x6F};
97 //Ed25519 OID (1.3.101.112)
98 const uint8_t ED25519_OID[3] = {0x2B, 0x65, 0x70};
99 //Ed448 OID (1.3.101.113)
100 const uint8_t ED448_OID[3] = {0x2B, 0x65, 0x71};
101 
102 
103 #if (SECP112R1_SUPPORT == ENABLED)
104 
105 /**
106  * @brief secp112r1 elliptic curve
107  **/
108 
110 {
111  //Curve name
112  "secp112r1",
113  //Object identifier
115  sizeof(SECP112R1_OID),
116  //Curve type
118  //Prime modulus p
119  {0xDB, 0x7C, 0x2A, 0xBF, 0x62, 0xE3, 0x5E, 0x66, 0x80, 0x76, 0xBE, 0xAD, 0x20, 0x8B},
120  14,
121  //Curve parameter a
122  {0xDB, 0x7C, 0x2A, 0xBF, 0x62, 0xE3, 0x5E, 0x66, 0x80, 0x76, 0xBE, 0xAD, 0x20, 0x88},
123  14,
124  //Curve parameter b
125  {0x65, 0x9E, 0xF8, 0xBA, 0x04, 0x39, 0x16, 0xEE, 0xDE, 0x89, 0x11, 0x70, 0x2B, 0x22},
126  14,
127  //x-coordinate of the base point G
128  {0x09, 0x48, 0x72, 0x39, 0x99, 0x5A, 0x5E, 0xE7, 0x6B, 0x55, 0xF9, 0xC2, 0xF0, 0x98},
129  14,
130  //y-coordinate of the base point G
131  {0xA8, 0x9C, 0xE5, 0xAF, 0x87, 0x24, 0xC0, 0xA2, 0x3E, 0x0E, 0x0F, 0xF7, 0x75, 0x00},
132  14,
133  //Base point order q
134  {0xDB, 0x7C, 0x2A, 0xBF, 0x62, 0xE3, 0x5E, 0x76, 0x28, 0xDF, 0xAC, 0x65, 0x61, 0xC5},
135  14,
136  //Cofactor
137  1,
138  //Fast modular reduction
139  NULL
140 };
141 
142 #endif
143 #if (SECP112R2_SUPPORT == ENABLED)
144 
145 /**
146  * @brief secp112r2 elliptic curve
147  **/
148 
150 {
151  //Curve name
152  "secp112r2",
153  //Object identifier
155  sizeof(SECP112R2_OID),
156  //Curve type
158  //Prime modulus p
159  {0xDB, 0x7C, 0x2A, 0xBF, 0x62, 0xE3, 0x5E, 0x66, 0x80, 0x76, 0xBE, 0xAD, 0x20, 0x8B},
160  14,
161  //Curve parameter a
162  {0x61, 0x27, 0xC2, 0x4C, 0x05, 0xF3, 0x8A, 0x0A, 0xAA, 0xF6, 0x5C, 0x0E, 0xF0, 0x2C},
163  14,
164  //Curve parameter b
165  {0x51, 0xDE, 0xF1, 0x81, 0x5D, 0xB5, 0xED, 0x74, 0xFC, 0xC3, 0x4C, 0x85, 0xD7, 0x09},
166  14,
167  //x-coordinate of the base point G
168  {0x4B, 0xA3, 0x0A, 0xB5, 0xE8, 0x92, 0xB4, 0xE1, 0x64, 0x9D, 0xD0, 0x92, 0x86, 0x43},
169  14,
170  //y-coordinate of the base point G
171  {0xAD, 0xCD, 0x46, 0xF5, 0x88, 0x2E, 0x37, 0x47, 0xDE, 0xF3, 0x6E, 0x95, 0x6E, 0x97},
172  14,
173  //Base point order q
174  {0x36, 0xDF, 0x0A, 0xAF, 0xD8, 0xB8, 0xD7, 0x59, 0x7C, 0xA1, 0x05, 0x20, 0xD0, 0x4B},
175  14,
176  //Cofactor
177  4,
178  //Fast modular reduction
179  NULL
180 };
181 
182 #endif
183 #if (SECP128R1_SUPPORT == ENABLED)
184 
185 /**
186  * @brief secp128r1 elliptic curve
187  **/
188 
190 {
191  //Curve name
192  "secp128r1",
193  //Object identifier
195  sizeof(SECP128R1_OID),
196  //Curve type
198  //Prime modulus p
199  {0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
200  16,
201  //Curve parameter a
202  {0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC},
203  16,
204  //Curve parameter b
205  {0xE8, 0x75, 0x79, 0xC1, 0x10, 0x79, 0xF4, 0x3D, 0xD8, 0x24, 0x99, 0x3C, 0x2C, 0xEE, 0x5E, 0xD3},
206  16,
207  //x-coordinate of the base point G
208  {0x16, 0x1F, 0xF7, 0x52, 0x8B, 0x89, 0x9B, 0x2D, 0x0C, 0x28, 0x60, 0x7C, 0xA5, 0x2C, 0x5B, 0x86},
209  16,
210  //y-coordinate of the base point G
211  {0xCF, 0x5A, 0xC8, 0x39, 0x5B, 0xAF, 0xEB, 0x13, 0xC0, 0x2D, 0xA2, 0x92, 0xDD, 0xED, 0x7A, 0x83},
212  16,
213  //Base point order q
214  {0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x75, 0xA3, 0x0D, 0x1B, 0x90, 0x38, 0xA1, 0x15},
215  16,
216  //Cofactor
217  1,
218  //Fast modular reduction
220 };
221 
222 #endif
223 #if (SECP128R2_SUPPORT == ENABLED)
224 
225 /**
226  * @brief secp128r2 elliptic curve
227  **/
228 
230 {
231  //Curve name
232  "secp128r2",
233  //Object identifier
235  sizeof(SECP128R2_OID),
236  //Curve type
238  //Prime modulus p
239  {0xFF, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
240  16,
241  //Curve parameter a
242  {0xD6, 0x03, 0x19, 0x98, 0xD1, 0xB3, 0xBB, 0xFE, 0xBF, 0x59, 0xCC, 0x9B, 0xBF, 0xF9, 0xAE, 0xE1},
243  16,
244  //Curve parameter b
245  {0x5E, 0xEE, 0xFC, 0xA3, 0x80, 0xD0, 0x29, 0x19, 0xDC, 0x2C, 0x65, 0x58, 0xBB, 0x6D, 0x8A, 0x5D},
246  16,
247  //x-coordinate of the base point G
248  {0x7B, 0x6A, 0xA5, 0xD8, 0x5E, 0x57, 0x29, 0x83, 0xE6, 0xFB, 0x32, 0xA7, 0xCD, 0xEB, 0xC1, 0x40},
249  16,
250  //y-coordinate of the base point G
251  {0x27, 0xB6, 0x91, 0x6A, 0x89, 0x4D, 0x3A, 0xEE, 0x71, 0x06, 0xFE, 0x80, 0x5F, 0xC3, 0x4B, 0x44},
252  16,
253  //Base point order q
254  {0x3F, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xBE, 0x00, 0x24, 0x72, 0x06, 0x13, 0xB5, 0xA3},
255  16,
256  //Cofactor
257  4,
258  //Fast modular reduction
260 };
261 
262 #endif
263 #if (SECP160K1_SUPPORT == ENABLED)
264 
265 /**
266  * @brief secp160k1 elliptic curve
267  **/
268 
270 {
271  //Curve name
272  "secp160k1",
273  //Object identifier
275  sizeof(SECP160K1_OID),
276  //Curve type
278  //Prime modulus p
279  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
280  0xFF, 0xFF, 0xAC, 0x73},
281  20,
282  //Curve parameter a
283  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
284  0x00, 0x00, 0x00, 0x00},
285  20,
286  //Curve parameter b
287  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
288  0x00, 0x00, 0x00, 0x07},
289  20,
290  //x-coordinate of the base point G
291  {0x3B, 0x4C, 0x38, 0x2C, 0xE3, 0x7A, 0xA1, 0x92, 0xA4, 0x01, 0x9E, 0x76, 0x30, 0x36, 0xF4, 0xF5,
292  0xDD, 0x4D, 0x7E, 0xBB},
293  20,
294  //y-coordinate of the base point G
295  {0x93, 0x8C, 0xF9, 0x35, 0x31, 0x8F, 0xDC, 0xED, 0x6B, 0xC2, 0x82, 0x86, 0x53, 0x17, 0x33, 0xC3,
296  0xF0, 0x3C, 0x4F, 0xEE},
297  20,
298  //Base point order q
299  {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xB8, 0xFA, 0x16, 0xDF, 0xAB,
300  0x9A, 0xCA, 0x16, 0xB6, 0xB3},
301  21,
302  //Cofactor
303  1,
304  //Fast modular reduction
306 };
307 
308 #endif
309 #if (SECP160R1_SUPPORT == ENABLED)
310 
311 /**
312  * @brief secp160r1 elliptic curve
313  **/
314 
316 {
317  //Curve name
318  "secp160r1",
319  //Object identifier
321  sizeof(SECP160R1_OID),
322  //Curve type
324  //Prime modulus p
325  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
326  0x7F, 0xFF, 0xFF, 0xFF},
327  20,
328  //Curve parameter a
329  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
330  0x7F, 0xFF, 0xFF, 0xFC},
331  20,
332  //Curve parameter b
333  {0x1C, 0x97, 0xBE, 0xFC, 0x54, 0xBD, 0x7A, 0x8B, 0x65, 0xAC, 0xF8, 0x9F, 0x81, 0xD4, 0xD4, 0xAD,
334  0xC5, 0x65, 0xFA, 0x45},
335  20,
336  //x-coordinate of the base point G
337  {0x4A, 0x96, 0xB5, 0x68, 0x8E, 0xF5, 0x73, 0x28, 0x46, 0x64, 0x69, 0x89, 0x68, 0xC3, 0x8B, 0xB9,
338  0x13, 0xCB, 0xFC, 0x82},
339  20,
340  //y-coordinate of the base point G
341  {0x23, 0xA6, 0x28, 0x55, 0x31, 0x68, 0x94, 0x7D, 0x59, 0xDC, 0xC9, 0x12, 0x04, 0x23, 0x51, 0x37,
342  0x7A, 0xC5, 0xFB, 0x32},
343  20,
344  //Base point order q
345  {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF4, 0xC8, 0xF9, 0x27, 0xAE,
346  0xD3, 0xCA, 0x75, 0x22, 0x57},
347  21,
348  //Cofactor
349  1,
350  //Fast modular reduction
352 };
353 
354 #endif
355 #if (SECP160R2_SUPPORT == ENABLED)
356 
357 /**
358  * @brief secp160r2 elliptic curve
359  **/
360 
362 {
363  //Curve name
364  "secp160r2",
365  //Object identifier
367  sizeof(SECP160R2_OID),
368  //Curve type
370  //Prime modulus p
371  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
372  0xFF, 0xFF, 0xAC, 0x73},
373  20,
374  //Curve parameter a
375  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
376  0xFF, 0xFF, 0xAC, 0x70},
377  20,
378  //Curve parameter b
379  {0xB4, 0xE1, 0x34, 0xD3, 0xFB, 0x59, 0xEB, 0x8B, 0xAB, 0x57, 0x27, 0x49, 0x04, 0x66, 0x4D, 0x5A,
380  0xF5, 0x03, 0x88, 0xBA},
381  20,
382  //x-coordinate of the base point G
383  {0x52, 0xDC, 0xB0, 0x34, 0x29, 0x3A, 0x11, 0x7E, 0x1F, 0x4F, 0xF1, 0x1B, 0x30, 0xF7, 0x19, 0x9D,
384  0x31, 0x44, 0xCE, 0x6D},
385  20,
386  //y-coordinate of the base point G
387  {0xFE, 0xAF, 0xFE, 0xF2, 0xE3, 0x31, 0xF2, 0x96, 0xE0, 0x71, 0xFA, 0x0D, 0xF9, 0x98, 0x2C, 0xFE,
388  0xA7, 0xD4, 0x3F, 0x2E},
389  20,
390  //Base point order q
391  {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35, 0x1E, 0xE7, 0x86, 0xA8,
392  0x18, 0xF3, 0xA1, 0xA1, 0x6B},
393  21,
394  //Cofactor
395  1,
396  //Fast modular reduction
398 };
399 
400 #endif
401 #if (SECP192K1_SUPPORT == ENABLED)
402 
403 /**
404  * @brief secp192k1 elliptic curve
405  **/
406 
408 {
409  //Curve name
410  "secp192k1",
411  //Object identifier
413  sizeof(SECP192K1_OID),
414  //Curve type
416  //Prime modulus p
417  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
418  0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xEE, 0x37},
419  24,
420  //Curve parameter a
421  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
422  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
423  24,
424  //Curve parameter b
425  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
426  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03},
427  24,
428  //x-coordinate of the base point G
429  {0xDB, 0x4F, 0xF1, 0x0E, 0xC0, 0x57, 0xE9, 0xAE, 0x26, 0xB0, 0x7D, 0x02, 0x80, 0xB7, 0xF4, 0x34,
430  0x1D, 0xA5, 0xD1, 0xB1, 0xEA, 0xE0, 0x6C, 0x7D},
431  24,
432  //y-coordinate of the base point G
433  {0x9B, 0x2F, 0x2F, 0x6D, 0x9C, 0x56, 0x28, 0xA7, 0x84, 0x41, 0x63, 0xD0, 0x15, 0xBE, 0x86, 0x34,
434  0x40, 0x82, 0xAA, 0x88, 0xD9, 0x5E, 0x2F, 0x9D},
435  24,
436  //Base point order q
437  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x26, 0xF2, 0xFC, 0x17,
438  0x0F, 0x69, 0x46, 0x6A, 0x74, 0xDE, 0xFD, 0x8D},
439  24,
440  //Cofactor
441  1,
442  //Fast modular reduction
444 };
445 
446 #endif
447 #if (SECP192R1_SUPPORT == ENABLED)
448 
449 /**
450  * @brief secp192r1 elliptic curve
451  **/
452 
454 {
455  //Curve name
456  "secp192r1",
457  //Object identifier
459  sizeof(SECP192R1_OID),
460  //Curve type
462  //Prime modulus p
463  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
464  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
465  24,
466  //Curve parameter a
467  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
468  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC},
469  24,
470  //Curve parameter b
471  {0x64, 0x21, 0x05, 0x19, 0xE5, 0x9C, 0x80, 0xE7, 0x0F, 0xA7, 0xE9, 0xAB, 0x72, 0x24, 0x30, 0x49,
472  0xFE, 0xB8, 0xDE, 0xEC, 0xC1, 0x46, 0xB9, 0xB1},
473  24,
474  //x-coordinate of the base point G
475  {0x18, 0x8D, 0xA8, 0x0E, 0xB0, 0x30, 0x90, 0xF6, 0x7C, 0xBF, 0x20, 0xEB, 0x43, 0xA1, 0x88, 0x00,
476  0xF4, 0xFF, 0x0A, 0xFD, 0x82, 0xFF, 0x10, 0x12},
477  24,
478  //y-coordinate of the base point G
479  {0x07, 0x19, 0x2B, 0x95, 0xFF, 0xC8, 0xDA, 0x78, 0x63, 0x10, 0x11, 0xED, 0x6B, 0x24, 0xCD, 0xD5,
480  0x73, 0xF9, 0x77, 0xA1, 0x1E, 0x79, 0x48, 0x11},
481  24,
482  //Base point order q
483  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x99, 0xDE, 0xF8, 0x36,
484  0x14, 0x6B, 0xC9, 0xB1, 0xB4, 0xD2, 0x28, 0x31},
485  24,
486  //Cofactor
487  1,
488  //Fast modular reduction
490 };
491 
492 #endif
493 #if (SECP224K1_SUPPORT == ENABLED)
494 
495 /**
496  * @brief secp224k1 elliptic curve
497  **/
498 
500 {
501  //Curve name
502  "secp224k1",
503  //Object identifier
505  sizeof(SECP224K1_OID),
506  //Curve type
508  //Prime modulus p
509  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
510  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xE5, 0x6D},
511  28,
512  //Curve parameter a
513  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
514  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
515  28,
516  //Curve parameter b
517  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
518  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05},
519  28,
520  //x-coordinate of the base point G
521  {0xA1, 0x45, 0x5B, 0x33, 0x4D, 0xF0, 0x99, 0xDF, 0x30, 0xFC, 0x28, 0xA1, 0x69, 0xA4, 0x67, 0xE9,
522  0xE4, 0x70, 0x75, 0xA9, 0x0F, 0x7E, 0x65, 0x0E, 0xB6, 0xB7, 0xA4, 0x5C},
523  28,
524  //y-coordinate of the base point G
525  {0x7E, 0x08, 0x9F, 0xED, 0x7F, 0xBA, 0x34, 0x42, 0x82, 0xCA, 0xFB, 0xD6, 0xF7, 0xE3, 0x19, 0xF7,
526  0xC0, 0xB0, 0xBD, 0x59, 0xE2, 0xCA, 0x4B, 0xDB, 0x55, 0x6D, 0x61, 0xA5},
527  28,
528  //Base point order q
529  {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xDC,
530  0xE8, 0xD2, 0xEC, 0x61, 0x84, 0xCA, 0xF0, 0xA9, 0x71, 0x76, 0x9F, 0xB1, 0xF7},
531  29,
532  //Cofactor
533  1,
534  //Fast modular reduction
536 };
537 
538 #endif
539 #if (SECP224R1_SUPPORT == ENABLED)
540 
541 /**
542  * @brief secp224r1 elliptic curve
543  **/
544 
546 {
547  //Curve name
548  "secp224r1",
549  //Object identifier
551  sizeof(SECP224R1_OID),
552  //Curve type
554  //Prime modulus p
555  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
556  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
557  28,
558  //Curve parameter a
559  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
560  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE},
561  28,
562  //Curve parameter b
563  {0xB4, 0x05, 0x0A, 0x85, 0x0C, 0x04, 0xB3, 0xAB, 0xF5, 0x41, 0x32, 0x56, 0x50, 0x44, 0xB0, 0xB7,
564  0xD7, 0xBF, 0xD8, 0xBA, 0x27, 0x0B, 0x39, 0x43, 0x23, 0x55, 0xFF, 0xB4},
565  28,
566  //x-coordinate of the base point G
567  {0xB7, 0x0E, 0x0C, 0xBD, 0x6B, 0xB4, 0xBF, 0x7F, 0x32, 0x13, 0x90, 0xB9, 0x4A, 0x03, 0xC1, 0xD3,
568  0x56, 0xC2, 0x11, 0x22, 0x34, 0x32, 0x80, 0xD6, 0x11, 0x5C, 0x1D, 0x21},
569  28,
570  //y-coordinate of the base point G
571  {0xBD, 0x37, 0x63, 0x88, 0xB5, 0xF7, 0x23, 0xFB, 0x4C, 0x22, 0xDF, 0xE6, 0xCD, 0x43, 0x75, 0xA0,
572  0x5A, 0x07, 0x47, 0x64, 0x44, 0xD5, 0x81, 0x99, 0x85, 0x00, 0x7E, 0x34},
573  28,
574  //Base point order q
575  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x16, 0xA2,
576  0xE0, 0xB8, 0xF0, 0x3E, 0x13, 0xDD, 0x29, 0x45, 0x5C, 0x5C, 0x2A, 0x3D},
577  28,
578  //Cofactor
579  1,
580  //Fast modular reduction
582 };
583 
584 #endif
585 #if (SECP256K1_SUPPORT == ENABLED)
586 
587 /**
588  * @brief secp256k1 elliptic curve
589  **/
590 
592 {
593  //Curve name
594  "secp256k1",
595  //Object identifier
597  sizeof(SECP256K1_OID),
598  //Curve type
600  //Prime modulus p
601  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
602  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFC, 0x2F},
603  32,
604  //Curve parameter a
605  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
606  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
607  32,
608  //Curve parameter b
609  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
610  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07},
611  32,
612  //x-coordinate of the base point G
613  {0x79, 0xBE, 0x66, 0x7E, 0xF9, 0xDC, 0xBB, 0xAC, 0x55, 0xA0, 0x62, 0x95, 0xCE, 0x87, 0x0B, 0x07,
614  0x02, 0x9B, 0xFC, 0xDB, 0x2D, 0xCE, 0x28, 0xD9, 0x59, 0xF2, 0x81, 0x5B, 0x16, 0xF8, 0x17, 0x98},
615  32,
616  //y-coordinate of the base point G
617  {0x48, 0x3A, 0xDA, 0x77, 0x26, 0xA3, 0xC4, 0x65, 0x5D, 0xA4, 0xFB, 0xFC, 0x0E, 0x11, 0x08, 0xA8,
618  0xFD, 0x17, 0xB4, 0x48, 0xA6, 0x85, 0x54, 0x19, 0x9C, 0x47, 0xD0, 0x8F, 0xFB, 0x10, 0xD4, 0xB8},
619  32,
620  //Base point order q
621  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
622  0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x41},
623  32,
624  //Cofactor
625  1,
626  //Fast modular reduction
628 };
629 
630 #endif
631 #if (SECP256R1_SUPPORT == ENABLED)
632 
633 /**
634  * @brief secp256r1 elliptic curve
635  **/
636 
638 {
639  //Curve name
640  "secp256r1",
641  //Object identifier
643  sizeof(SECP256R1_OID),
644  //Curve type
646  //Prime modulus p
647  {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
648  0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
649  32,
650  //Curve parameter a
651  {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
652  0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC},
653  32,
654  //Curve parameter b
655  {0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7, 0xB3, 0xEB, 0xBD, 0x55, 0x76, 0x98, 0x86, 0xBC,
656  0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, 0xB0, 0xF6, 0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B},
657  32,
658  //x-coordinate of the base point G
659  {0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, 0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2,
660  0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0, 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96},
661  32,
662  //y-coordinate of the base point G
663  {0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, 0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16,
664  0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE, 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5},
665  32,
666  //Base point order q
667  {0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
668  0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51},
669  32,
670  //Cofactor
671  1,
672  //Fast modular reduction
674 };
675 
676 #endif
677 #if (SECP384R1_SUPPORT == ENABLED)
678 
679 /**
680  * @brief secp384r1 elliptic curve
681  **/
682 
684 {
685  //Curve name
686  "secp384r1",
687  //Object identifier
689  sizeof(SECP384R1_OID),
690  //Curve type
692  //Prime modulus p
693  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
694  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
695  0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF},
696  48,
697  //Curve parameter a
698  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
699  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
700  0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFC},
701  48,
702  //Curve parameter b
703  {0xB3, 0x31, 0x2F, 0xA7, 0xE2, 0x3E, 0xE7, 0xE4, 0x98, 0x8E, 0x05, 0x6B, 0xE3, 0xF8, 0x2D, 0x19,
704  0x18, 0x1D, 0x9C, 0x6E, 0xFE, 0x81, 0x41, 0x12, 0x03, 0x14, 0x08, 0x8F, 0x50, 0x13, 0x87, 0x5A,
705  0xC6, 0x56, 0x39, 0x8D, 0x8A, 0x2E, 0xD1, 0x9D, 0x2A, 0x85, 0xC8, 0xED, 0xD3, 0xEC, 0x2A, 0xEF},
706  48,
707  //x-coordinate of the base point G
708  {0xAA, 0x87, 0xCA, 0x22, 0xBE, 0x8B, 0x05, 0x37, 0x8E, 0xB1, 0xC7, 0x1E, 0xF3, 0x20, 0xAD, 0x74,
709  0x6E, 0x1D, 0x3B, 0x62, 0x8B, 0xA7, 0x9B, 0x98, 0x59, 0xF7, 0x41, 0xE0, 0x82, 0x54, 0x2A, 0x38,
710  0x55, 0x02, 0xF2, 0x5D, 0xBF, 0x55, 0x29, 0x6C, 0x3A, 0x54, 0x5E, 0x38, 0x72, 0x76, 0x0A, 0xB7},
711  48,
712  //y-coordinate of the base point G
713  {0x36, 0x17, 0xDE, 0x4A, 0x96, 0x26, 0x2C, 0x6F, 0x5D, 0x9E, 0x98, 0xBF, 0x92, 0x92, 0xDC, 0x29,
714  0xF8, 0xF4, 0x1D, 0xBD, 0x28, 0x9A, 0x14, 0x7C, 0xE9, 0xDA, 0x31, 0x13, 0xB5, 0xF0, 0xB8, 0xC0,
715  0x0A, 0x60, 0xB1, 0xCE, 0x1D, 0x7E, 0x81, 0x9D, 0x7A, 0x43, 0x1D, 0x7C, 0x90, 0xEA, 0x0E, 0x5F},
716  48,
717  //Base point order q
718  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
719  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC7, 0x63, 0x4D, 0x81, 0xF4, 0x37, 0x2D, 0xDF,
720  0x58, 0x1A, 0x0D, 0xB2, 0x48, 0xB0, 0xA7, 0x7A, 0xEC, 0xEC, 0x19, 0x6A, 0xCC, 0xC5, 0x29, 0x73},
721  48,
722  //Cofactor
723  1,
724  //Fast modular reduction
726 };
727 
728 #endif
729 #if (SECP521R1_SUPPORT == ENABLED)
730 
731 /**
732  * @brief secp521r1 elliptic curve
733  **/
734 
736 {
737  //Curve name
738  "secp521r1",
739  //Object identifier
741  sizeof(SECP521R1_OID),
742  //Curve type
744  //Prime modulus p
745  {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
746  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
747  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
748  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
749  0xFF, 0xFF},
750  66,
751  //Curve parameter a
752  {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
753  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
754  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
755  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
756  0xFF, 0xFC},
757  66,
758  //Curve parameter b
759  {0x00, 0x51, 0x95, 0x3E, 0xB9, 0x61, 0x8E, 0x1C, 0x9A, 0x1F, 0x92, 0x9A, 0x21, 0xA0, 0xB6, 0x85,
760  0x40, 0xEE, 0xA2, 0xDA, 0x72, 0x5B, 0x99, 0xB3, 0x15, 0xF3, 0xB8, 0xB4, 0x89, 0x91, 0x8E, 0xF1,
761  0x09, 0xE1, 0x56, 0x19, 0x39, 0x51, 0xEC, 0x7E, 0x93, 0x7B, 0x16, 0x52, 0xC0, 0xBD, 0x3B, 0xB1,
762  0xBF, 0x07, 0x35, 0x73, 0xDF, 0x88, 0x3D, 0x2C, 0x34, 0xF1, 0xEF, 0x45, 0x1F, 0xD4, 0x6B, 0x50,
763  0x3F, 0x00},
764  66,
765  //x-coordinate of the base point G
766  {0x00, 0xC6, 0x85, 0x8E, 0x06, 0xB7, 0x04, 0x04, 0xE9, 0xCD, 0x9E, 0x3E, 0xCB, 0x66, 0x23, 0x95,
767  0xB4, 0x42, 0x9C, 0x64, 0x81, 0x39, 0x05, 0x3F, 0xB5, 0x21, 0xF8, 0x28, 0xAF, 0x60, 0x6B, 0x4D,
768  0x3D, 0xBA, 0xA1, 0x4B, 0x5E, 0x77, 0xEF, 0xE7, 0x59, 0x28, 0xFE, 0x1D, 0xC1, 0x27, 0xA2, 0xFF,
769  0xA8, 0xDE, 0x33, 0x48, 0xB3, 0xC1, 0x85, 0x6A, 0x42, 0x9B, 0xF9, 0x7E, 0x7E, 0x31, 0xC2, 0xE5,
770  0xBD, 0x66},
771  66,
772  //y-coordinate of the base point G
773  {0x01, 0x18, 0x39, 0x29, 0x6A, 0x78, 0x9A, 0x3B, 0xC0, 0x04, 0x5C, 0x8A, 0x5F, 0xB4, 0x2C, 0x7D,
774  0x1B, 0xD9, 0x98, 0xF5, 0x44, 0x49, 0x57, 0x9B, 0x44, 0x68, 0x17, 0xAF, 0xBD, 0x17, 0x27, 0x3E,
775  0x66, 0x2C, 0x97, 0xEE, 0x72, 0x99, 0x5E, 0xF4, 0x26, 0x40, 0xC5, 0x50, 0xB9, 0x01, 0x3F, 0xAD,
776  0x07, 0x61, 0x35, 0x3C, 0x70, 0x86, 0xA2, 0x72, 0xC2, 0x40, 0x88, 0xBE, 0x94, 0x76, 0x9F, 0xD1,
777  0x66, 0x50},
778  66,
779  //Base point order q
780  {0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
781  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
782  0xFF, 0xFA, 0x51, 0x86, 0x87, 0x83, 0xBF, 0x2F, 0x96, 0x6B, 0x7F, 0xCC, 0x01, 0x48, 0xF7, 0x09,
783  0xA5, 0xD0, 0x3B, 0xB5, 0xC9, 0xB8, 0x89, 0x9C, 0x47, 0xAE, 0xBB, 0x6F, 0xB7, 0x1E, 0x91, 0x38,
784  0x64, 0x09},
785  66,
786  //Cofactor
787  1,
788  //Fast modular reduction
790 };
791 
792 #endif
793 #if (BRAINPOOLP160R1_SUPPORT == ENABLED)
794 
795 /**
796  * @brief brainpoolP160r1 elliptic curve
797  **/
798 
800 {
801  //Curve name
802  "brainpoolP160r1",
803  //Object identifier
805  sizeof(BRAINPOOLP160R1_OID),
806  //Curve type
808  //Prime modulus p
809  {0xE9, 0x5E, 0x4A, 0x5F, 0x73, 0x70, 0x59, 0xDC, 0x60, 0xDF, 0xC7, 0xAD, 0x95, 0xB3, 0xD8, 0x13,
810  0x95, 0x15, 0x62, 0x0F},
811  20,
812  //Curve parameter a
813  {0x34, 0x0E, 0x7B, 0xE2, 0xA2, 0x80, 0xEB, 0x74, 0xE2, 0xBE, 0x61, 0xBA, 0xDA, 0x74, 0x5D, 0x97,
814  0xE8, 0xF7, 0xC3, 0x00},
815  20,
816  //Curve parameter b
817  {0x1E, 0x58, 0x9A, 0x85, 0x95, 0x42, 0x34, 0x12, 0x13, 0x4F, 0xAA, 0x2D, 0xBD, 0xEC, 0x95, 0xC8,
818  0xD8, 0x67, 0x5E, 0x58},
819  20,
820  //x-coordinate of the base point G
821  {0xBE, 0xD5, 0xAF, 0x16, 0xEA, 0x3F, 0x6A, 0x4F, 0x62, 0x93, 0x8C, 0x46, 0x31, 0xEB, 0x5A, 0xF7,
822  0xBD, 0xBC, 0xDB, 0xC3},
823  20,
824  //y-coordinate of the base point G
825  {0x16, 0x67, 0xCB, 0x47, 0x7A, 0x1A, 0x8E, 0xC3, 0x38, 0xF9, 0x47, 0x41, 0x66, 0x9C, 0x97, 0x63,
826  0x16, 0xDA, 0x63, 0x21},
827  20,
828  //Base point order q
829  {0xE9, 0x5E, 0x4A, 0x5F, 0x73, 0x70, 0x59, 0xDC, 0x60, 0xDF, 0x59, 0x91, 0xD4, 0x50, 0x29, 0x40,
830  0x9E, 0x60, 0xFC, 0x09},
831  20,
832  //Cofactor
833  1,
834  //Fast modular reduction
835  NULL
836 };
837 
838 #endif
839 #if (BRAINPOOLP192R1_SUPPORT == ENABLED)
840 
841 /**
842  * @brief brainpoolP192r1 elliptic curve
843  **/
844 
846 {
847  //Curve name
848  "brainpoolP192r1",
849  //Object identifier
851  sizeof(BRAINPOOLP192R1_OID),
852  //Curve type
854  //Prime modulus p
855  {0xC3, 0x02, 0xF4, 0x1D, 0x93, 0x2A, 0x36, 0xCD, 0xA7, 0xA3, 0x46, 0x30, 0x93, 0xD1, 0x8D, 0xB7,
856  0x8F, 0xCE, 0x47, 0x6D, 0xE1, 0xA8, 0x62, 0x97},
857  24,
858  //Curve parameter a
859  {0x6A, 0x91, 0x17, 0x40, 0x76, 0xB1, 0xE0, 0xE1, 0x9C, 0x39, 0xC0, 0x31, 0xFE, 0x86, 0x85, 0xC1,
860  0xCA, 0xE0, 0x40, 0xE5, 0xC6, 0x9A, 0x28, 0xEF},
861  24,
862  //Curve parameter b
863  {0x46, 0x9A, 0x28, 0xEF, 0x7C, 0x28, 0xCC, 0xA3, 0xDC, 0x72, 0x1D, 0x04, 0x4F, 0x44, 0x96, 0xBC,
864  0xCA, 0x7E, 0xF4, 0x14, 0x6F, 0xBF, 0x25, 0xC9},
865  24,
866  //x-coordinate of the base point G
867  {0xC0, 0xA0, 0x64, 0x7E, 0xAA, 0xB6, 0xA4, 0x87, 0x53, 0xB0, 0x33, 0xC5, 0x6C, 0xB0, 0xF0, 0x90,
868  0x0A, 0x2F, 0x5C, 0x48, 0x53, 0x37, 0x5F, 0xD6},
869  24,
870  //y-coordinate of the base point G
871  {0x14, 0xB6, 0x90, 0x86, 0x6A, 0xBD, 0x5B, 0xB8, 0x8B, 0x5F, 0x48, 0x28, 0xC1, 0x49, 0x00, 0x02,
872  0xE6, 0x77, 0x3F, 0xA2, 0xFA, 0x29, 0x9B, 0x8F},
873  24,
874  //Base point order q
875  {0xC3, 0x02, 0xF4, 0x1D, 0x93, 0x2A, 0x36, 0xCD, 0xA7, 0xA3, 0x46, 0x2F, 0x9E, 0x9E, 0x91, 0x6B,
876  0x5B, 0xE8, 0xF1, 0x02, 0x9A, 0xC4, 0xAC, 0xC1},
877  24,
878  //Cofactor
879  1,
880  //Fast modular reduction
881  NULL
882 };
883 
884 #endif
885 #if (BRAINPOOLP224R1_SUPPORT == ENABLED)
886 
887 /**
888  * @brief brainpoolP224r1 elliptic curve
889  **/
890 
892 {
893  //Curve name
894  "brainpoolP224r1",
895  //Object identifier
897  sizeof(BRAINPOOLP224R1_OID),
898  //Curve type
900  //Prime modulus p
901  {0xD7, 0xC1, 0x34, 0xAA, 0x26, 0x43, 0x66, 0x86, 0x2A, 0x18, 0x30, 0x25, 0x75, 0xD1, 0xD7, 0x87,
902  0xB0, 0x9F, 0x07, 0x57, 0x97, 0xDA, 0x89, 0xF5, 0x7E, 0xC8, 0xC0, 0xFF},
903  28,
904  //Curve parameter a
905  {0x68, 0xA5, 0xE6, 0x2C, 0xA9, 0xCE, 0x6C, 0x1C, 0x29, 0x98, 0x03, 0xA6, 0xC1, 0x53, 0x0B, 0x51,
906  0x4E, 0x18, 0x2A, 0xD8, 0xB0, 0x04, 0x2A, 0x59, 0xCA, 0xD2, 0x9F, 0x43},
907  28,
908  //Curve parameter b
909  {0x25, 0x80, 0xF6, 0x3C, 0xCF, 0xE4, 0x41, 0x38, 0x87, 0x07, 0x13, 0xB1, 0xA9, 0x23, 0x69, 0xE3,
910  0x3E, 0x21, 0x35, 0xD2, 0x66, 0xDB, 0xB3, 0x72, 0x38, 0x6C, 0x40, 0x0B},
911  28,
912  //x-coordinate of the base point G
913  {0x0D, 0x90, 0x29, 0xAD, 0x2C, 0x7E, 0x5C, 0xF4, 0x34, 0x08, 0x23, 0xB2, 0xA8, 0x7D, 0xC6, 0x8C,
914  0x9E, 0x4C, 0xE3, 0x17, 0x4C, 0x1E, 0x6E, 0xFD, 0xEE, 0x12, 0xC0, 0x7D},
915  28,
916  //y-coordinate of the base point G
917  {0x58, 0xAA, 0x56, 0xF7, 0x72, 0xC0, 0x72, 0x6F, 0x24, 0xC6, 0xB8, 0x9E, 0x4E, 0xCD, 0xAC, 0x24,
918  0x35, 0x4B, 0x9E, 0x99, 0xCA, 0xA3, 0xF6, 0xD3, 0x76, 0x14, 0x02, 0xCD},
919  28,
920  //Base point order q
921  {0xD7, 0xC1, 0x34, 0xAA, 0x26, 0x43, 0x66, 0x86, 0x2A, 0x18, 0x30, 0x25, 0x75, 0xD0, 0xFB, 0x98,
922  0xD1, 0x16, 0xBC, 0x4B, 0x6D, 0xDE, 0xBC, 0xA3, 0xA5, 0xA7, 0x93, 0x9F},
923  28,
924  //Cofactor
925  1,
926  //Fast modular reduction
927  NULL
928 };
929 
930 #endif
931 #if (BRAINPOOLP256R1_SUPPORT == ENABLED)
932 
933 /**
934  * @brief brainpoolP256r1 elliptic curve
935  **/
936 
938 {
939  //Curve name
940  "brainpoolP256r1",
941  //Object identifier
943  sizeof(BRAINPOOLP256R1_OID),
944  //Curve type
946  //Prime modulus p
947  {0xA9, 0xFB, 0x57, 0xDB, 0xA1, 0xEE, 0xA9, 0xBC, 0x3E, 0x66, 0x0A, 0x90, 0x9D, 0x83, 0x8D, 0x72,
948  0x6E, 0x3B, 0xF6, 0x23, 0xD5, 0x26, 0x20, 0x28, 0x20, 0x13, 0x48, 0x1D, 0x1F, 0x6E, 0x53, 0x77},
949  32,
950  //Curve parameter a
951  {0x7D, 0x5A, 0x09, 0x75, 0xFC, 0x2C, 0x30, 0x57, 0xEE, 0xF6, 0x75, 0x30, 0x41, 0x7A, 0xFF, 0xE7,
952  0xFB, 0x80, 0x55, 0xC1, 0x26, 0xDC, 0x5C, 0x6C, 0xE9, 0x4A, 0x4B, 0x44, 0xF3, 0x30, 0xB5, 0xD9},
953  32,
954  //Curve parameter b
955  {0x26, 0xDC, 0x5C, 0x6C, 0xE9, 0x4A, 0x4B, 0x44, 0xF3, 0x30, 0xB5, 0xD9, 0xBB, 0xD7, 0x7C, 0xBF,
956  0x95, 0x84, 0x16, 0x29, 0x5C, 0xF7, 0xE1, 0xCE, 0x6B, 0xCC, 0xDC, 0x18, 0xFF, 0x8C, 0x07, 0xB6},
957  32,
958  //x-coordinate of the base point G
959  {0x8B, 0xD2, 0xAE, 0xB9, 0xCB, 0x7E, 0x57, 0xCB, 0x2C, 0x4B, 0x48, 0x2F, 0xFC, 0x81, 0xB7, 0xAF,
960  0xB9, 0xDE, 0x27, 0xE1, 0xE3, 0xBD, 0x23, 0xC2, 0x3A, 0x44, 0x53, 0xBD, 0x9A, 0xCE, 0x32, 0x62},
961  32,
962  //y-coordinate of the base point G
963  {0x54, 0x7E, 0xF8, 0x35, 0xC3, 0xDA, 0xC4, 0xFD, 0x97, 0xF8, 0x46, 0x1A, 0x14, 0x61, 0x1D, 0xC9,
964  0xC2, 0x77, 0x45, 0x13, 0x2D, 0xED, 0x8E, 0x54, 0x5C, 0x1D, 0x54, 0xC7, 0x2F, 0x04, 0x69, 0x97},
965  32,
966  //Base point order q
967  {0xA9, 0xFB, 0x57, 0xDB, 0xA1, 0xEE, 0xA9, 0xBC, 0x3E, 0x66, 0x0A, 0x90, 0x9D, 0x83, 0x8D, 0x71,
968  0x8C, 0x39, 0x7A, 0xA3, 0xB5, 0x61, 0xA6, 0xF7, 0x90, 0x1E, 0x0E, 0x82, 0x97, 0x48, 0x56, 0xA7},
969  32,
970  //Cofactor
971  1,
972  //Fast modular reduction
973  NULL
974 };
975 
976 #endif
977 #if (BRAINPOOLP320R1_SUPPORT == ENABLED)
978 
979 /**
980  * @brief brainpoolP320r1 elliptic curve
981  **/
982 
984 {
985  //Curve name
986  "brainpoolP320r1",
987  //Object identifier
989  sizeof(BRAINPOOLP320R1_OID),
990  //Curve type
992  //Prime modulus p
993  {0xD3, 0x5E, 0x47, 0x20, 0x36, 0xBC, 0x4F, 0xB7, 0xE1, 0x3C, 0x78, 0x5E, 0xD2, 0x01, 0xE0, 0x65,
994  0xF9, 0x8F, 0xCF, 0xA6, 0xF6, 0xF4, 0x0D, 0xEF, 0x4F, 0x92, 0xB9, 0xEC, 0x78, 0x93, 0xEC, 0x28,
995  0xFC, 0xD4, 0x12, 0xB1, 0xF1, 0xB3, 0x2E, 0x27},
996  40,
997  //Curve parameter a
998  {0x3E, 0xE3, 0x0B, 0x56, 0x8F, 0xBA, 0xB0, 0xF8, 0x83, 0xCC, 0xEB, 0xD4, 0x6D, 0x3F, 0x3B, 0xB8,
999  0xA2, 0xA7, 0x35, 0x13, 0xF5, 0xEB, 0x79, 0xDA, 0x66, 0x19, 0x0E, 0xB0, 0x85, 0xFF, 0xA9, 0xF4,
1000  0x92, 0xF3, 0x75, 0xA9, 0x7D, 0x86, 0x0E, 0xB4},
1001  40,
1002  //Curve parameter b
1003  {0x52, 0x08, 0x83, 0x94, 0x9D, 0xFD, 0xBC, 0x42, 0xD3, 0xAD, 0x19, 0x86, 0x40, 0x68, 0x8A, 0x6F,
1004  0xE1, 0x3F, 0x41, 0x34, 0x95, 0x54, 0xB4, 0x9A, 0xCC, 0x31, 0xDC, 0xCD, 0x88, 0x45, 0x39, 0x81,
1005  0x6F, 0x5E, 0xB4, 0xAC, 0x8F, 0xB1, 0xF1, 0xA6},
1006  40,
1007  //x-coordinate of the base point G
1008  {0x43, 0xBD, 0x7E, 0x9A, 0xFB, 0x53, 0xD8, 0xB8, 0x52, 0x89, 0xBC, 0xC4, 0x8E, 0xE5, 0xBF, 0xE6,
1009  0xF2, 0x01, 0x37, 0xD1, 0x0A, 0x08, 0x7E, 0xB6, 0xE7, 0x87, 0x1E, 0x2A, 0x10, 0xA5, 0x99, 0xC7,
1010  0x10, 0xAF, 0x8D, 0x0D, 0x39, 0xE2, 0x06, 0x11},
1011  40,
1012  //y-coordinate of the base point G
1013  {0x14, 0xFD, 0xD0, 0x55, 0x45, 0xEC, 0x1C, 0xC8, 0xAB, 0x40, 0x93, 0x24, 0x7F, 0x77, 0x27, 0x5E,
1014  0x07, 0x43, 0xFF, 0xED, 0x11, 0x71, 0x82, 0xEA, 0xA9, 0xC7, 0x78, 0x77, 0xAA, 0xAC, 0x6A, 0xC7,
1015  0xD3, 0x52, 0x45, 0xD1, 0x69, 0x2E, 0x8E, 0xE1},
1016  40,
1017  //Base point order q
1018  {0xD3, 0x5E, 0x47, 0x20, 0x36, 0xBC, 0x4F, 0xB7, 0xE1, 0x3C, 0x78, 0x5E, 0xD2, 0x01, 0xE0, 0x65,
1019  0xF9, 0x8F, 0xCF, 0xA5, 0xB6, 0x8F, 0x12, 0xA3, 0x2D, 0x48, 0x2E, 0xC7, 0xEE, 0x86, 0x58, 0xE9,
1020  0x86, 0x91, 0x55, 0x5B, 0x44, 0xC5, 0x93, 0x11},
1021  40,
1022  //Cofactor
1023  1,
1024  //Fast modular reduction
1025  NULL
1026 };
1027 
1028 #endif
1029 #if (BRAINPOOLP384R1_SUPPORT == ENABLED)
1030 
1031 /**
1032  * @brief brainpoolP384r1 elliptic curve
1033  **/
1034 
1036 {
1037  //Curve name
1038  "brainpoolP384r1",
1039  //Object identifier
1041  sizeof(BRAINPOOLP384R1_OID),
1042  //Curve type
1044  //Prime modulus p
1045  {0x8C, 0xB9, 0x1E, 0x82, 0xA3, 0x38, 0x6D, 0x28, 0x0F, 0x5D, 0x6F, 0x7E, 0x50, 0xE6, 0x41, 0xDF,
1046  0x15, 0x2F, 0x71, 0x09, 0xED, 0x54, 0x56, 0xB4, 0x12, 0xB1, 0xDA, 0x19, 0x7F, 0xB7, 0x11, 0x23,
1047  0xAC, 0xD3, 0xA7, 0x29, 0x90, 0x1D, 0x1A, 0x71, 0x87, 0x47, 0x00, 0x13, 0x31, 0x07, 0xEC, 0x53},
1048  48,
1049  //Curve parameter a
1050  {0x7B, 0xC3, 0x82, 0xC6, 0x3D, 0x8C, 0x15, 0x0C, 0x3C, 0x72, 0x08, 0x0A, 0xCE, 0x05, 0xAF, 0xA0,
1051  0xC2, 0xBE, 0xA2, 0x8E, 0x4F, 0xB2, 0x27, 0x87, 0x13, 0x91, 0x65, 0xEF, 0xBA, 0x91, 0xF9, 0x0F,
1052  0x8A, 0xA5, 0x81, 0x4A, 0x50, 0x3A, 0xD4, 0xEB, 0x04, 0xA8, 0xC7, 0xDD, 0x22, 0xCE, 0x28, 0x26},
1053  48,
1054  //Curve parameter b
1055  {0x04, 0xA8, 0xC7, 0xDD, 0x22, 0xCE, 0x28, 0x26, 0x8B, 0x39, 0xB5, 0x54, 0x16, 0xF0, 0x44, 0x7C,
1056  0x2F, 0xB7, 0x7D, 0xE1, 0x07, 0xDC, 0xD2, 0xA6, 0x2E, 0x88, 0x0E, 0xA5, 0x3E, 0xEB, 0x62, 0xD5,
1057  0x7C, 0xB4, 0x39, 0x02, 0x95, 0xDB, 0xC9, 0x94, 0x3A, 0xB7, 0x86, 0x96, 0xFA, 0x50, 0x4C, 0x11},
1058  48,
1059  //x-coordinate of the base point G
1060  {0x1D, 0x1C, 0x64, 0xF0, 0x68, 0xCF, 0x45, 0xFF, 0xA2, 0xA6, 0x3A, 0x81, 0xB7, 0xC1, 0x3F, 0x6B,
1061  0x88, 0x47, 0xA3, 0xE7, 0x7E, 0xF1, 0x4F, 0xE3, 0xDB, 0x7F, 0xCA, 0xFE, 0x0C, 0xBD, 0x10, 0xE8,
1062  0xE8, 0x26, 0xE0, 0x34, 0x36, 0xD6, 0x46, 0xAA, 0xEF, 0x87, 0xB2, 0xE2, 0x47, 0xD4, 0xAF, 0x1E},
1063  48,
1064  //y-coordinate of the base point G
1065  {0x8A, 0xBE, 0x1D, 0x75, 0x20, 0xF9, 0xC2, 0xA4, 0x5C, 0xB1, 0xEB, 0x8E, 0x95, 0xCF, 0xD5, 0x52,
1066  0x62, 0xB7, 0x0B, 0x29, 0xFE, 0xEC, 0x58, 0x64, 0xE1, 0x9C, 0x05, 0x4F, 0xF9, 0x91, 0x29, 0x28,
1067  0x0E, 0x46, 0x46, 0x21, 0x77, 0x91, 0x81, 0x11, 0x42, 0x82, 0x03, 0x41, 0x26, 0x3C, 0x53, 0x15},
1068  48,
1069  //Base point order q
1070  {0x8C, 0xB9, 0x1E, 0x82, 0xA3, 0x38, 0x6D, 0x28, 0x0F, 0x5D, 0x6F, 0x7E, 0x50, 0xE6, 0x41, 0xDF,
1071  0x15, 0x2F, 0x71, 0x09, 0xED, 0x54, 0x56, 0xB3, 0x1F, 0x16, 0x6E, 0x6C, 0xAC, 0x04, 0x25, 0xA7,
1072  0xCF, 0x3A, 0xB6, 0xAF, 0x6B, 0x7F, 0xC3, 0x10, 0x3B, 0x88, 0x32, 0x02, 0xE9, 0x04, 0x65, 0x65},
1073  48,
1074  //Cofactor
1075  1,
1076  //Fast modular reduction
1077  NULL
1078 };
1079 
1080 #endif
1081 #if (BRAINPOOLP512R1_SUPPORT == ENABLED)
1082 
1083 /**
1084  * @brief brainpoolP512r1 elliptic curve
1085  **/
1086 
1088 {
1089  //Curve name
1090  "brainpoolP512r1",
1091  //Object identifier
1093  sizeof(BRAINPOOLP512R1_OID),
1094  //Curve type
1096  //Prime modulus p
1097  {0xAA, 0xDD, 0x9D, 0xB8, 0xDB, 0xE9, 0xC4, 0x8B, 0x3F, 0xD4, 0xE6, 0xAE, 0x33, 0xC9, 0xFC, 0x07,
1098  0xCB, 0x30, 0x8D, 0xB3, 0xB3, 0xC9, 0xD2, 0x0E, 0xD6, 0x63, 0x9C, 0xCA, 0x70, 0x33, 0x08, 0x71,
1099  0x7D, 0x4D, 0x9B, 0x00, 0x9B, 0xC6, 0x68, 0x42, 0xAE, 0xCD, 0xA1, 0x2A, 0xE6, 0xA3, 0x80, 0xE6,
1100  0x28, 0x81, 0xFF, 0x2F, 0x2D, 0x82, 0xC6, 0x85, 0x28, 0xAA, 0x60, 0x56, 0x58, 0x3A, 0x48, 0xF3},
1101  64,
1102  //Curve parameter a
1103  {0x78, 0x30, 0xA3, 0x31, 0x8B, 0x60, 0x3B, 0x89, 0xE2, 0x32, 0x71, 0x45, 0xAC, 0x23, 0x4C, 0xC5,
1104  0x94, 0xCB, 0xDD, 0x8D, 0x3D, 0xF9, 0x16, 0x10, 0xA8, 0x34, 0x41, 0xCA, 0xEA, 0x98, 0x63, 0xBC,
1105  0x2D, 0xED, 0x5D, 0x5A, 0xA8, 0x25, 0x3A, 0xA1, 0x0A, 0x2E, 0xF1, 0xC9, 0x8B, 0x9A, 0xC8, 0xB5,
1106  0x7F, 0x11, 0x17, 0xA7, 0x2B, 0xF2, 0xC7, 0xB9, 0xE7, 0xC1, 0xAC, 0x4D, 0x77, 0xFC, 0x94, 0xCA},
1107  64,
1108  //Curve parameter b
1109  {0x3D, 0xF9, 0x16, 0x10, 0xA8, 0x34, 0x41, 0xCA, 0xEA, 0x98, 0x63, 0xBC, 0x2D, 0xED, 0x5D, 0x5A,
1110  0xA8, 0x25, 0x3A, 0xA1, 0x0A, 0x2E, 0xF1, 0xC9, 0x8B, 0x9A, 0xC8, 0xB5, 0x7F, 0x11, 0x17, 0xA7,
1111  0x2B, 0xF2, 0xC7, 0xB9, 0xE7, 0xC1, 0xAC, 0x4D, 0x77, 0xFC, 0x94, 0xCA, 0xDC, 0x08, 0x3E, 0x67,
1112  0x98, 0x40, 0x50, 0xB7, 0x5E, 0xBA, 0xE5, 0xDD, 0x28, 0x09, 0xBD, 0x63, 0x80, 0x16, 0xF7, 0x23},
1113  64,
1114  //x-coordinate of the base point G
1115  {0x81, 0xAE, 0xE4, 0xBD, 0xD8, 0x2E, 0xD9, 0x64, 0x5A, 0x21, 0x32, 0x2E, 0x9C, 0x4C, 0x6A, 0x93,
1116  0x85, 0xED, 0x9F, 0x70, 0xB5, 0xD9, 0x16, 0xC1, 0xB4, 0x3B, 0x62, 0xEE, 0xF4, 0xD0, 0x09, 0x8E,
1117  0xFF, 0x3B, 0x1F, 0x78, 0xE2, 0xD0, 0xD4, 0x8D, 0x50, 0xD1, 0x68, 0x7B, 0x93, 0xB9, 0x7D, 0x5F,
1118  0x7C, 0x6D, 0x50, 0x47, 0x40, 0x6A, 0x5E, 0x68, 0x8B, 0x35, 0x22, 0x09, 0xBC, 0xB9, 0xF8, 0x22},
1119  64,
1120  //y-coordinate of the base point G
1121  {0x7D, 0xDE, 0x38, 0x5D, 0x56, 0x63, 0x32, 0xEC, 0xC0, 0xEA, 0xBF, 0xA9, 0xCF, 0x78, 0x22, 0xFD,
1122  0xF2, 0x09, 0xF7, 0x00, 0x24, 0xA5, 0x7B, 0x1A, 0xA0, 0x00, 0xC5, 0x5B, 0x88, 0x1F, 0x81, 0x11,
1123  0xB2, 0xDC, 0xDE, 0x49, 0x4A, 0x5F, 0x48, 0x5E, 0x5B, 0xCA, 0x4B, 0xD8, 0x8A, 0x27, 0x63, 0xAE,
1124  0xD1, 0xCA, 0x2B, 0x2F, 0xA8, 0xF0, 0x54, 0x06, 0x78, 0xCD, 0x1E, 0x0F, 0x3A, 0xD8, 0x08, 0x92},
1125  64,
1126  //Base point order q
1127  {0xAA, 0xDD, 0x9D, 0xB8, 0xDB, 0xE9, 0xC4, 0x8B, 0x3F, 0xD4, 0xE6, 0xAE, 0x33, 0xC9, 0xFC, 0x07,
1128  0xCB, 0x30, 0x8D, 0xB3, 0xB3, 0xC9, 0xD2, 0x0E, 0xD6, 0x63, 0x9C, 0xCA, 0x70, 0x33, 0x08, 0x70,
1129  0x55, 0x3E, 0x5C, 0x41, 0x4C, 0xA9, 0x26, 0x19, 0x41, 0x86, 0x61, 0x19, 0x7F, 0xAC, 0x10, 0x47,
1130  0x1D, 0xB1, 0xD3, 0x81, 0x08, 0x5D, 0xDA, 0xDD, 0xB5, 0x87, 0x96, 0x82, 0x9C, 0xA9, 0x00, 0x69},
1131  64,
1132  //Cofactor
1133  1,
1134  //Fast modular reduction
1135  NULL
1136 };
1137 
1138 #endif
1139 #if (SM2_SUPPORT == ENABLED)
1140 
1141 /**
1142  * @brief SM2 elliptic curve
1143  **/
1144 
1146 {
1147  //Curve name
1148  "curveSM2",
1149  //Object identifier
1150  SM2_OID,
1151  sizeof(SM2_OID),
1152  //Curve type
1154  //Prime modulus p
1155  {0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1156  0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1157  32,
1158  //Curve parameter a
1159  {0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1160  0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC},
1161  32,
1162  //Curve parameter b
1163  {0x28, 0xE9, 0xFA, 0x9E, 0x9D, 0x9F, 0x5E, 0x34, 0x4D, 0x5A, 0x9E, 0x4B, 0xCF, 0x65, 0x09, 0xA7,
1164  0xF3, 0x97, 0x89, 0xF5, 0x15, 0xAB, 0x8F, 0x92, 0xDD, 0xBC, 0xBD, 0x41, 0x4D, 0x94, 0x0E, 0x93},
1165  32,
1166  //x-coordinate of the base point G
1167  {0x32, 0xC4, 0xAE, 0x2C, 0x1F, 0x19, 0x81, 0x19, 0x5F, 0x99, 0x04, 0x46, 0x6A, 0x39, 0xC9, 0x94,
1168  0x8F, 0xE3, 0x0B, 0xBF, 0xF2, 0x66, 0x0B, 0xE1, 0x71, 0x5A, 0x45, 0x89, 0x33, 0x4C, 0x74, 0xC7},
1169  32,
1170  //y-coordinate of the base point G
1171  {0xBC, 0x37, 0x36, 0xA2, 0xF4, 0xF6, 0x77, 0x9C, 0x59, 0xBD, 0xCE, 0xE3, 0x6B, 0x69, 0x21, 0x53,
1172  0xD0, 0xA9, 0x87, 0x7C, 0xC6, 0x2A, 0x47, 0x40, 0x02, 0xDF, 0x32, 0xE5, 0x21, 0x39, 0xF0, 0xA0},
1173  32,
1174  //Base point order q
1175  {0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1176  0x72, 0x03, 0xDF, 0x6B, 0x21, 0xC6, 0x05, 0x2B, 0x53, 0xBB, 0xF4, 0x09, 0x39, 0xD5, 0x41, 0x23},
1177  32,
1178  //Cofactor
1179  1,
1180  //Fast modular reduction
1181  sm2Mod
1182 };
1183 
1184 #endif
1185 #if (X25519_SUPPORT == ENABLED)
1186 
1187 /**
1188  * @brief Curve25519 elliptic curve
1189  **/
1190 
1192 {
1193  //Curve name
1194  "curve25519",
1195  //Object identifier
1196  X25519_OID,
1197  sizeof(X25519_OID),
1198  //Curve type
1200  //Prime modulus p
1201  {0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1202  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xED},
1203  32,
1204  //Curve parameter a
1205  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1206  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x6D, 0x06},
1207  32,
1208  //Curve parameter b
1209  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1210  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1211  32,
1212  //u-coordinate of the base point G
1213  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1214  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09},
1215  32,
1216  //v-coordinate of the base point G
1217  {0x20, 0xAE, 0x19, 0xA1, 0xB8, 0xA0, 0x86, 0xB4, 0xE0, 0x1E, 0xDD, 0x2C, 0x77, 0x48, 0xD1, 0x4C,
1218  0x92, 0x3D, 0x4D, 0x7E, 0x6D, 0x7C, 0x61, 0xB2, 0x29, 0xE9, 0xC5, 0xA2, 0x7E, 0xCE, 0xD3, 0xD9},
1219  32,
1220  //Base point order q
1221  {0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1222  0x14, 0xDE, 0xF9, 0xDE, 0xA2, 0xF7, 0x9C, 0xD6, 0x58, 0x12, 0x63, 0x1A, 0x5C, 0xF5, 0xD3, 0xED},
1223  32,
1224  //Cofactor
1225  8,
1226  //Fast modular reduction
1227  NULL
1228 };
1229 
1230 #endif
1231 #if (X448_SUPPORT == ENABLED)
1232 
1233 /**
1234  * @brief Curve448 elliptic curve
1235  **/
1236 
1238 {
1239  //Curve name
1240  "curve448",
1241  //Object identifier
1242  X448_OID,
1243  sizeof(X448_OID),
1244  //Curve type
1246  //Prime modulus p
1247  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1248  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF,
1249  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1250  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1251  56,
1252  //Curve parameter a
1253  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1254  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1255  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1256  0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x62, 0xA6},
1257  56,
1258  //Curve parameter b
1259  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1260  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1261  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1262  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1263  56,
1264  //u-coordinate of the base point G
1265  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1266  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1267  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1268  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05},
1269  56,
1270  //v-coordinate of the base point G
1271  {0x7D, 0x23, 0x5D, 0x12, 0x95, 0xF5, 0xB1, 0xF6, 0x6C, 0x98, 0xAB, 0x6E, 0x58, 0x32, 0x6F, 0xCE,
1272  0xCB, 0xAE, 0x5D, 0x34, 0xF5, 0x55, 0x45, 0xD0, 0x60, 0xF7, 0x5D, 0xC2, 0x8D, 0xF3, 0xF6, 0xED,
1273  0xB8, 0x02, 0x7E, 0x23, 0x46, 0x43, 0x0D, 0x21, 0x13, 0x12, 0xC4, 0xB1, 0x50, 0x67, 0x7A, 0xF7,
1274  0x6F, 0xD7, 0x22, 0x3D, 0x45, 0x7B, 0x5B, 0x1A},
1275  56,
1276  //Base point order q
1277  {0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1278  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7C, 0xCA, 0x23, 0xE9,
1279  0xC4, 0x4E, 0xDB, 0x49, 0xAE, 0xD6, 0x36, 0x90, 0x21, 0x6C, 0xC2, 0x72, 0x8D, 0xC5, 0x8F, 0x55,
1280  0x23, 0x78, 0xC2, 0x92, 0xAB, 0x58, 0x44, 0xF3},
1281  56,
1282  //Cofactor
1283  4,
1284  //Fast modular reduction
1285  NULL
1286 };
1287 
1288 #endif
1289 #if (ED25519_SUPPORT == ENABLED)
1290 
1291 /**
1292  * @brief Ed25519 elliptic curve
1293  **/
1294 
1296 {
1297  //Curve name
1298  "Ed25519",
1299  //Object identifier
1300  ED25519_OID,
1301  sizeof(ED25519_OID),
1302  //Curve type
1304  //Prime modulus p
1305  {0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1306  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xED},
1307  32,
1308  //Curve parameter a
1309  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1310  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x6D, 0x06},
1311  32,
1312  //Curve parameter b
1313  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1314  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1315  32,
1316  //x-coordinate of the base point G
1317  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1318  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09},
1319  32,
1320  //y-coordinate of the base point G
1321  {0x20, 0xAE, 0x19, 0xA1, 0xB8, 0xA0, 0x86, 0xB4, 0xE0, 0x1E, 0xDD, 0x2C, 0x77, 0x48, 0xD1, 0x4C,
1322  0x92, 0x3D, 0x4D, 0x7E, 0x6D, 0x7C, 0x61, 0xB2, 0x29, 0xE9, 0xC5, 0xA2, 0x7E, 0xCE, 0xD3, 0xD9},
1323  32,
1324  //Base point order q
1325  {0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1326  0x14, 0xDE, 0xF9, 0xDE, 0xA2, 0xF7, 0x9C, 0xD6, 0x58, 0x12, 0x63, 0x1A, 0x5C, 0xF5, 0xD3, 0xED},
1327  32,
1328  //Cofactor
1329  8,
1330  //Fast modular reduction
1331  NULL
1332 };
1333 
1334 #endif
1335 #if (ED448_SUPPORT == ENABLED)
1336 
1337 /**
1338  * @brief Ed448 elliptic curve
1339  **/
1340 
1342 {
1343  //Curve name
1344  "Ed448",
1345  //Object identifier
1346  ED448_OID,
1347  sizeof(ED448_OID),
1348  //Curve type
1350  //Prime modulus p
1351  {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1352  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF,
1353  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1354  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
1355  56,
1356  //Curve parameter a
1357  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1358  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1359  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1360  0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x62, 0xA6},
1361  56,
1362  //Curve parameter b
1363  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1364  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1365  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1366  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
1367  56,
1368  //x-coordinate of the base point G
1369  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1370  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1371  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1372  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05},
1373  56,
1374  //y-coordinate of the base point G
1375  {0x7D, 0x23, 0x5D, 0x12, 0x95, 0xF5, 0xB1, 0xF6, 0x6C, 0x98, 0xAB, 0x6E, 0x58, 0x32, 0x6F, 0xCE,
1376  0xCB, 0xAE, 0x5D, 0x34, 0xF5, 0x55, 0x45, 0xD0, 0x60, 0xF7, 0x5D, 0xC2, 0x8D, 0xF3, 0xF6, 0xED,
1377  0xB8, 0x02, 0x7E, 0x23, 0x46, 0x43, 0x0D, 0x21, 0x13, 0x12, 0xC4, 0xB1, 0x50, 0x67, 0x7A, 0xF7,
1378  0x6F, 0xD7, 0x22, 0x3D, 0x45, 0x7B, 0x5B, 0x1A},
1379  56,
1380  //Base point order q
1381  {0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
1382  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7C, 0xCA, 0x23, 0xE9,
1383  0xC4, 0x4E, 0xDB, 0x49, 0xAE, 0xD6, 0x36, 0x90, 0x21, 0x6C, 0xC2, 0x72, 0x8D, 0xC5, 0x8F, 0x55,
1384  0x23, 0x78, 0xC2, 0x92, 0xAB, 0x58, 0x44, 0xF3},
1385  56,
1386  //Cofactor
1387  4,
1388  //Fast modular reduction
1389  NULL
1390 };
1391 
1392 #endif
1393 #if (SECP128R1_SUPPORT == ENABLED)
1394 
1395 /**
1396  * @brief Fast modular reduction (secp128r1 curve)
1397  * @param[in,out] a This function accept an integer less than p^2 as
1398  * input and return (a mod p) as output
1399  * @param[in] p Prime modulus
1400  **/
1401 
1403 {
1404  error_t error;
1405  Mpi t;
1406 
1407  //Initialize multiple precision integers
1408  mpiInit(&t);
1409 
1410  //Ajust the size of the integers
1411  MPI_CHECK(mpiGrow(a, 32 / MPI_INT_SIZE));
1412  MPI_CHECK(mpiGrow(&t, 32 / MPI_INT_SIZE));
1413 
1414  //Perform modular reduction
1415  do
1416  {
1417  //Compute T = 0 | 0 | 0 | 0 | A7 | A6 | A5 | A4
1418  COPY_WORD32(&t, 0, a, 4, 4);
1419  CLEAR_WORD32(&t, 4, 4);
1420 
1421  //Clear A7 | A6 | A5 | A4
1422  CLEAR_WORD32(a, 4, 4);
1423 
1424  //Compute A = A + T + (T << 97)
1425  MPI_CHECK(mpiAdd(a, a, &t));
1426  MPI_CHECK(mpiShiftLeft(&t, 97));
1427  MPI_CHECK(mpiAdd(a, a, &t));
1428 
1429  //Check for end condition
1430  } while(mpiComp(a, p) > 0);
1431 
1432 end:
1433  //Release multiple precision integers
1434  mpiFree(&t);
1435 
1436  //Return status code
1437  return error;
1438 }
1439 
1440 #endif
1441 #if (SECP128R2_SUPPORT == ENABLED)
1442 
1443 /**
1444  * @brief Fast modular reduction (secp128r2 curve)
1445  * @param[in,out] a This function accept an integer less than p^2 as
1446  * input and return (a mod p) as output
1447  * @param[in] p Prime modulus
1448  **/
1449 
1451 {
1452  error_t error;
1453  Mpi t;
1454 
1455  //Initialize multiple precision integers
1456  mpiInit(&t);
1457 
1458  //Ajust the size of the integers
1459  MPI_CHECK(mpiGrow(a, 32 / MPI_INT_SIZE));
1460  MPI_CHECK(mpiGrow(&t, 32 / MPI_INT_SIZE));
1461 
1462  //Perform modular reduction
1463  do
1464  {
1465  //Compute T = 0 | 0 | 0 | 0 | A7 | A6 | A5 | A4
1466  COPY_WORD32(&t, 0, a, 4, 4);
1467  CLEAR_WORD32(&t, 4, 4);
1468 
1469  //Clear A7 | A6 | A5 | A4
1470  CLEAR_WORD32(a, 4, 4);
1471 
1472  //Compute A = A + T + (T << 97)
1473  MPI_CHECK(mpiAdd(a, a, &t));
1474  MPI_CHECK(mpiShiftLeft(&t, 97));
1475  MPI_CHECK(mpiAdd(a, a, &t));
1476 
1477  //Check for end condition
1478  } while(mpiComp(a, p) > 0);
1479 
1480 end:
1481  //Release multiple precision integers
1482  mpiFree(&t);
1483 
1484  //Return status code
1485  return error;
1486 }
1487 
1488 #endif
1489 #if (SECP160K1_SUPPORT == ENABLED)
1490 
1491 /**
1492  * @brief Fast modular reduction (secp160k1 curve)
1493  * @param[in,out] a This function accept an integer less than p^2 as
1494  * input and return (a mod p) as output
1495  * @param[in] p Prime modulus
1496  **/
1497 
1499 {
1500  error_t error;
1501  Mpi t;
1502 
1503  //Initialize multiple precision integers
1504  mpiInit(&t);
1505 
1506  //Ajust the size of the integers
1507  MPI_CHECK(mpiGrow(a, 40 / MPI_INT_SIZE));
1508  MPI_CHECK(mpiGrow(&t, 24 / MPI_INT_SIZE));
1509 
1510  //Perform modular reduction
1511  do
1512  {
1513  //Compute T = A9 | A8 | A7 | A6 | A5 | 0
1514  CLEAR_WORD32(&t, 0, 1);
1515  COPY_WORD32(&t, 1, a, 5, 5);
1516 
1517  //Clear A9 | A8 | A7 | A6 | A5
1518  CLEAR_WORD32(a, 5, 5);
1519 
1520  //Compute A = A + T
1521  MPI_CHECK(mpiAdd(a, a, &t));
1522  //Compute T = T >> 32
1523  MPI_CHECK(mpiShiftRight(&t, 32));
1524  //Compute A = A + (21389 * T)
1525  MPI_CHECK(mpiMulInt(&t, &t, 21389));
1526  MPI_CHECK(mpiAdd(a, a, &t));
1527 
1528  //Check for end condition
1529  } while(mpiComp(a, p) > 0);
1530 
1531 end:
1532  //Release multiple precision integers
1533  mpiFree(&t);
1534 
1535  //Return status code
1536  return error;
1537 }
1538 
1539 #endif
1540 #if (SECP160R1_SUPPORT == ENABLED)
1541 
1542 /**
1543  * @brief Fast modular reduction (secp160r1 curve)
1544  * @param[in,out] a This function accept an integer less than p^2 as
1545  * input and return (a mod p) as output
1546  * @param[in] p Prime modulus
1547  **/
1548 
1550 {
1551  error_t error;
1552  Mpi t;
1553 
1554  //Initialize multiple precision integers
1555  mpiInit(&t);
1556 
1557  //Ajust the size of the integers
1558  MPI_CHECK(mpiGrow(a, 40 / MPI_INT_SIZE));
1559  MPI_CHECK(mpiGrow(&t, 24 / MPI_INT_SIZE));
1560 
1561  //Perform modular reduction
1562  do
1563  {
1564  //Compute T = 0 | A9 | A8 | A7 | A6 | A5
1565  COPY_WORD32(&t, 0, a, 5, 5);
1566  CLEAR_WORD32(&t, 5, 1);
1567 
1568  //Clear A9 | A8 | A7 | A6 | A5
1569  CLEAR_WORD32(a, 5, 5);
1570 
1571  //Compute A = A + T + (T << 31)
1572  MPI_CHECK(mpiAdd(a, a, &t));
1573  MPI_CHECK(mpiShiftLeft(&t, 31));
1574  MPI_CHECK(mpiAdd(a, a, &t));
1575 
1576  //Check for end condition
1577  } while(mpiComp(a, p) > 0);
1578 
1579 end:
1580  //Release multiple precision integers
1581  mpiFree(&t);
1582 
1583  //Return status code
1584  return error;
1585 }
1586 
1587 #endif
1588 #if (SECP160R2_SUPPORT == ENABLED)
1589 
1590 /**
1591  * @brief Fast modular reduction (secp160r2 curve)
1592  * @param[in,out] a This function accept an integer less than p^2 as
1593  * input and return (a mod p) as output
1594  * @param[in] p Prime modulus
1595  **/
1596 
1598 {
1599  error_t error;
1600  Mpi t;
1601 
1602  //Initialize multiple precision integers
1603  mpiInit(&t);
1604 
1605  //Ajust the size of the integers
1606  MPI_CHECK(mpiGrow(a, 40 / MPI_INT_SIZE));
1607  MPI_CHECK(mpiGrow(&t, 24 / MPI_INT_SIZE));
1608 
1609  //Perform modular reduction
1610  do
1611  {
1612  //Compute T = A9 | A8 | A7 | A6 | A5 | 0
1613  CLEAR_WORD32(&t, 0, 1);
1614  COPY_WORD32(&t, 1, a, 5, 5);
1615 
1616  //Clear A9 | A8 | A7 | A6 | A5
1617  CLEAR_WORD32(a, 5, 5);
1618 
1619  //Compute A = A + T
1620  MPI_CHECK(mpiAdd(a, a, &t));
1621  //Compute T = T >> 32
1622  MPI_CHECK(mpiShiftRight(&t, 32));
1623  //Compute A = A + (21389 * T)
1624  MPI_CHECK(mpiMulInt(&t, &t, 21389));
1625  MPI_CHECK(mpiAdd(a, a, &t));
1626 
1627  //Check for end condition
1628  } while(mpiComp(a, p) > 0);
1629 
1630 end:
1631  //Release multiple precision integers
1632  mpiFree(&t);
1633 
1634  //Return status code
1635  return error;
1636 }
1637 
1638 #endif
1639 #if (SECP192K1_SUPPORT == ENABLED)
1640 
1641 /**
1642  * @brief Fast modular reduction (secp192k1 curve)
1643  * @param[in,out] a This function accept an integer less than p^2 as
1644  * input and return (a mod p) as output
1645  * @param[in] p Prime modulus
1646  **/
1647 
1649 {
1650  error_t error;
1651  Mpi t;
1652 
1653  //Initialize multiple precision integers
1654  mpiInit(&t);
1655 
1656  //Ajust the size of the integers
1657  MPI_CHECK(mpiGrow(a, 48 / MPI_INT_SIZE));
1658  MPI_CHECK(mpiGrow(&t, 28 / MPI_INT_SIZE));
1659 
1660  //Perform modular reduction
1661  do
1662  {
1663  //Compute T = A11 | A10 | A9 | A8 | A7 | A6 | 0
1664  CLEAR_WORD32(&t, 0, 1);
1665  COPY_WORD32(&t, 1, a, 6, 6);
1666 
1667  //Clear A11 | A10 | A9 | A8 | A7 | A6
1668  CLEAR_WORD32(a, 6, 6);
1669 
1670  //Compute A = A + T
1671  MPI_CHECK(mpiAdd(a, a, &t));
1672  //Compute T = T >> 32
1673  MPI_CHECK(mpiShiftRight(&t, 32));
1674  //Compute A = A + (4553 * T)
1675  MPI_CHECK(mpiMulInt(&t, &t, 4553));
1676  MPI_CHECK(mpiAdd(a, a, &t));
1677 
1678  //Check for end condition
1679  } while(mpiComp(a, p) > 0);
1680 
1681 end:
1682  //Release multiple precision integers
1683  mpiFree(&t);
1684 
1685  //Return status code
1686  return error;
1687 }
1688 
1689 #endif
1690 #if (SECP192R1_SUPPORT == ENABLED)
1691 
1692 /**
1693  * @brief Fast modular reduction (secp192r1 curve)
1694  * @param[in,out] a This function accept an integer less than p^2 as
1695  * input and return (a mod p) as output
1696  * @param[in] p Prime modulus
1697  **/
1698 
1700 {
1701  error_t error;
1702  Mpi s;
1703  Mpi t;
1704 
1705  //Initialize multiple precision integers
1706  mpiInit(&s);
1707  mpiInit(&t);
1708 
1709  //Ajust the size of the integers
1710  MPI_CHECK(mpiGrow(a, 48 / MPI_INT_SIZE));
1711  MPI_CHECK(mpiGrow(&s, 24 / MPI_INT_SIZE));
1712  MPI_CHECK(mpiGrow(&t, 24 / MPI_INT_SIZE));
1713 
1714  //Compute T = A5 | A4 | A3 | A2 | A1 | A0
1715  COPY_WORD32(&t, 0, a, 0, 6);
1716 
1717  //Compute S1 = 0 | 0 | A7 | A6 | A7 | A6
1718  COPY_WORD32(&s, 0, a, 6, 2);
1719  COPY_WORD32(&s, 2, a, 6, 2);
1720  CLEAR_WORD32(&s, 4, 2);
1721  //Compute T = T + S1
1722  MPI_CHECK(mpiAdd(&t, &t, &s));
1723 
1724  //Compute S2 = A9 | A8 | A9 | A8 | 0 | 0
1725  CLEAR_WORD32(&s, 0, 2);
1726  COPY_WORD32(&s, 2, a, 8, 2);
1727  COPY_WORD32(&s, 4, a, 8, 2);
1728  //Compute T = T + S2
1729  MPI_CHECK(mpiAdd(&t, &t, &s));
1730 
1731  //Compute S3 = A11 | A10 | A11 | A10 | A11 | A10
1732  COPY_WORD32(&s, 0, a, 10, 2);
1733  COPY_WORD32(&s, 2, a, 10, 2);
1734  COPY_WORD32(&s, 4, a, 10, 2);
1735  //Compute T = T + S3
1736  MPI_CHECK(mpiAdd(&t, &t, &s));
1737 
1738  //Compute (T + S1 + S2 + S3) mod p
1739  while(mpiComp(&t, p) >= 0)
1740  {
1741  MPI_CHECK(mpiSub(&t, &t, p));
1742  }
1743 
1744  //Save result
1745  MPI_CHECK(mpiCopy(a, &t));
1746 
1747 end:
1748  //Release multiple precision integers
1749  mpiFree(&s);
1750  mpiFree(&t);
1751 
1752  //Return status code
1753  return error;
1754 }
1755 
1756 #endif
1757 #if (SECP224K1_SUPPORT == ENABLED)
1758 
1759 /**
1760  * @brief Fast modular reduction (secp224k1 curve)
1761  * @param[in,out] a This function accept an integer less than p^2 as
1762  * input and return (a mod p) as output
1763  * @param[in] p Prime modulus
1764  **/
1765 
1767 {
1768  error_t error;
1769  Mpi t;
1770 
1771  //Initialize multiple precision integers
1772  mpiInit(&t);
1773 
1774  //Ajust the size of the integers
1775  MPI_CHECK(mpiGrow(a, 56 / MPI_INT_SIZE));
1776  MPI_CHECK(mpiGrow(&t, 32 / MPI_INT_SIZE));
1777 
1778  //Perform modular reduction
1779  do
1780  {
1781  //Compute T = A13 | A12 | A11 | A10 | A9 | A8 | A7 | 0
1782  CLEAR_WORD32(&t, 0, 1);
1783  COPY_WORD32(&t, 1, a, 7, 7);
1784 
1785  //Clear A13 | A12 | A11 | A10 | A9 | A8 | A7
1786  CLEAR_WORD32(a, 7, 7);
1787 
1788  //Compute A = A + T
1789  MPI_CHECK(mpiAdd(a, a, &t));
1790  //Compute T = T >> 32
1791  MPI_CHECK(mpiShiftRight(&t, 32));
1792  //Compute A = A + (6803 * T)
1793  MPI_CHECK(mpiMulInt(&t, &t, 6803));
1794  MPI_CHECK(mpiAdd(a, a, &t));
1795 
1796  //Check for end condition
1797  } while(mpiComp(a, p) > 0);
1798 
1799 end:
1800  //Release multiple precision integers
1801  mpiFree(&t);
1802 
1803  //Return status code
1804  return error;
1805 }
1806 
1807 #endif
1808 #if (SECP224R1_SUPPORT == ENABLED)
1809 
1810 /**
1811  * @brief Fast modular reduction (secp224r1 curve)
1812  * @param[in,out] a This function accept an integer less than p^2 as
1813  * input and return (a mod p) as output
1814  * @param[in] p Prime modulus
1815  **/
1816 
1818 {
1819  error_t error;
1820  Mpi s;
1821  Mpi t;
1822 
1823  //Initialize multiple precision integers
1824  mpiInit(&s);
1825  mpiInit(&t);
1826 
1827  //Ajust the size of the integers
1828  MPI_CHECK(mpiGrow(a, 56 / MPI_INT_SIZE));
1829  MPI_CHECK(mpiGrow(&s, 28 / MPI_INT_SIZE));
1830  MPI_CHECK(mpiGrow(&t, 28 / MPI_INT_SIZE));
1831 
1832  //Compute T = A6 | A5 | A4 | A3 | A2 | A1 | A0
1833  COPY_WORD32(&t, 0, a, 0, 7);
1834 
1835  //Compute S1 = A10 | A9 | A8 | A7 | 0 | 0 | 0
1836  CLEAR_WORD32(&s, 0, 3);
1837  COPY_WORD32(&s, 3, a, 7, 4);
1838  //Compute T = T + S1
1839  MPI_CHECK(mpiAdd(&t, &t, &s));
1840 
1841  //Compute S2 = 0 | A13 | A12 | A11 | 0 | 0 | 0
1842  CLEAR_WORD32(&s, 0, 3);
1843  COPY_WORD32(&s, 3, a, 11, 3);
1844  CLEAR_WORD32(&s, 6, 1);
1845  //Compute T = T + S2
1846  MPI_CHECK(mpiAdd(&t, &t, &s));
1847 
1848  //Compute D1 = A13 | A12 | A11 | A10 | A9 | A8 | A7
1849  COPY_WORD32(&s, 0, a, 7, 7);
1850  //Compute T = T - D1
1851  MPI_CHECK(mpiSub(&t, &t, &s));
1852 
1853  //Compute D2 = 0 | 0 | 0 | 0 | A13 | A12 | A11
1854  COPY_WORD32(&s, 0, a, 11, 3);
1855  CLEAR_WORD32(&s, 3, 4);
1856  //Compute T = T - D2
1857  MPI_CHECK(mpiSub(&t, &t, &s));
1858 
1859  //Compute (T + S1 + S2 - D1 - D2) mod p
1860  while(mpiComp(&t, p) >= 0)
1861  {
1862  MPI_CHECK(mpiSub(&t, &t, p));
1863  }
1864 
1865  while(mpiCompInt(&t, 0) < 0)
1866  {
1867  MPI_CHECK(mpiAdd(&t, &t, p));
1868  }
1869 
1870  //Save result
1871  MPI_CHECK(mpiCopy(a, &t));
1872 
1873 end:
1874  //Release multiple precision integers
1875  mpiFree(&s);
1876  mpiFree(&t);
1877 
1878  //Return status code
1879  return error;
1880 }
1881 
1882 #endif
1883 #if (SECP256K1_SUPPORT == ENABLED)
1884 
1885 /**
1886  * @brief Fast modular reduction (secp256k1 curve)
1887  * @param[in,out] a This function accept an integer less than p^2 as
1888  * input and return (a mod p) as output
1889  * @param[in] p Prime modulus
1890  **/
1891 
1893 {
1894  error_t error;
1895  Mpi t;
1896 
1897  //Initialize multiple precision integers
1898  mpiInit(&t);
1899 
1900  //Ajust the size of the integers
1901  MPI_CHECK(mpiGrow(a, 64 / MPI_INT_SIZE));
1902  MPI_CHECK(mpiGrow(&t, 36 / MPI_INT_SIZE));
1903 
1904  //Perform modular reduction
1905  do
1906  {
1907  //Compute T = A15 | A14 | A13 | A12 | A11 | A10 | A9 | A8 | 0
1908  CLEAR_WORD32(&t, 0, 1);
1909  COPY_WORD32(&t, 1, a, 8, 8);
1910 
1911  //Clear A15 | A14 | A13 | A12 | A11 | A10 | A9 | A8
1912  CLEAR_WORD32(a, 8, 8);
1913 
1914  //Compute A = A + T
1915  MPI_CHECK(mpiAdd(a, a, &t));
1916  //Compute T = T >> 32
1917  MPI_CHECK(mpiShiftRight(&t, 32));
1918  //Compute A = A + (977 * T)
1919  MPI_CHECK(mpiMulInt(&t, &t, 977));
1920  MPI_CHECK(mpiAdd(a, a, &t));
1921 
1922  //Check for end condition
1923  } while(mpiComp(a, p) > 0);
1924 
1925 end:
1926  //Release multiple precision integers
1927  mpiFree(&t);
1928 
1929  //Return status code
1930  return error;
1931 }
1932 
1933 #endif
1934 #if (SECP256R1_SUPPORT == ENABLED)
1935 
1936 /**
1937  * @brief Fast modular reduction (secp256r1 curve)
1938  * @param[in,out] a This function accept an integer less than p^2 as
1939  * input and return (a mod p) as output
1940  * @param[in] p Prime modulus
1941  **/
1942 
1944 {
1945  error_t error;
1946  Mpi s;
1947  Mpi t;
1948  Mpi b;
1949 
1950  //Initialize multiple precision integers
1951  mpiInit(&s);
1952  mpiInit(&t);
1953  mpiInit(&b);
1954 
1955  //Ajust the size of the integers
1956  MPI_CHECK(mpiGrow(a, 64 / MPI_INT_SIZE));
1957  MPI_CHECK(mpiGrow(&s, 32 / MPI_INT_SIZE));
1958  MPI_CHECK(mpiGrow(&t, 32 / MPI_INT_SIZE));
1959 
1960  //Compute T = A7 | A6 | A5 | A4 | A3 | A2 | A1 | A0
1961  COPY_WORD32(&t, 0, a, 0, 8);
1962 
1963  //Compute S1 = A15 | A14 | A13 | A12 | A11 | 0 | 0 | 0
1964  CLEAR_WORD32(&s, 0, 3);
1965  COPY_WORD32(&s, 3, a, 11, 5);
1966  //Compute T = T + 2 * S1
1967  MPI_CHECK(mpiAdd(&t, &t, &s));
1968  MPI_CHECK(mpiAdd(&t, &t, &s));
1969 
1970  //Compute S2 = 0 | A15 | A14 | A13 | A12 | 0 | 0 | 0
1971  CLEAR_WORD32(&s, 0, 3);
1972  COPY_WORD32(&s, 3, a, 12, 4);
1973  CLEAR_WORD32(&s, 7, 1);
1974  //Compute T = T + 2 * S2
1975  MPI_CHECK(mpiAdd(&t, &t, &s));
1976  MPI_CHECK(mpiAdd(&t, &t, &s));
1977 
1978  //Compute S3 = A15 | A14 | 0 | 0 | 0 | A10 | A9 | A8
1979  COPY_WORD32(&s, 0, a, 8, 3);
1980  CLEAR_WORD32(&s, 3, 3);
1981  COPY_WORD32(&s, 6, a, 14, 2);
1982  //Compute T = T + S3
1983  MPI_CHECK(mpiAdd(&t, &t, &s));
1984 
1985  //Compute S4 = A8 | A13 | A15 | A14 | A13 | A11 | A10 | A9
1986  COPY_WORD32(&s, 0, a, 9, 3);
1987  COPY_WORD32(&s, 3, a, 13, 3);
1988  COPY_WORD32(&s, 6, a, 13, 1);
1989  COPY_WORD32(&s, 7, a, 8, 1);
1990  //Compute T = T + S4
1991  MPI_CHECK(mpiAdd(&t, &t, &s));
1992 
1993  //Compute D1 = A10 | A8 | 0 | 0 | 0 | A13 | A12 | A11
1994  COPY_WORD32(&s, 0, a, 11, 3);
1995  CLEAR_WORD32(&s, 3, 3);
1996  COPY_WORD32(&s, 6, a, 8, 1);
1997  COPY_WORD32(&s, 7, a, 10, 1);
1998  //Compute T = T - D1
1999  MPI_CHECK(mpiSub(&t, &t, &s));
2000 
2001  //Compute D2 = A11 | A9 | 0 | 0 | A15 | A14 | A13 | A12
2002  COPY_WORD32(&s, 0, a, 12, 4);
2003  CLEAR_WORD32(&s, 4, 2);
2004  COPY_WORD32(&s, 6, a, 9, 1);
2005  COPY_WORD32(&s, 7, a, 11, 1);
2006  //Compute T = T - D2
2007  MPI_CHECK(mpiSub(&t, &t, &s));
2008 
2009  //Compute D3 = A12 | 0 | A10 | A9 | A8 | A15 | A14 | A13
2010  COPY_WORD32(&s, 0, a, 13, 3);
2011  COPY_WORD32(&s, 3, a, 8, 3);
2012  CLEAR_WORD32(&s, 6, 1);
2013  COPY_WORD32(&s, 7, a, 12, 1);
2014  //Compute T = T - D3
2015  MPI_CHECK(mpiSub(&t, &t, &s));
2016 
2017  //Compute D4 = A13 | 0 | A11 | A10 | A9 | 0 | A15 | A14
2018  COPY_WORD32(&s, 0, a, 14, 2);
2019  CLEAR_WORD32(&s, 2, 1);
2020  COPY_WORD32(&s, 3, a, 9, 3);
2021  CLEAR_WORD32(&s, 6, 1);
2022  COPY_WORD32(&s, 7, a, 13, 1);
2023  //Compute T = T - D4
2024  MPI_CHECK(mpiSub(&t, &t, &s));
2025 
2026  //Compute (T + 2 * S1 + 2 * S2 + S3 + S4 - D1 - D2 - D3 - D4) mod p
2027  while(mpiComp(&t, p) >= 0)
2028  {
2029  MPI_CHECK(mpiSub(&t, &t, p));
2030  }
2031 
2032  while(mpiCompInt(&t, 0) < 0)
2033  {
2034  MPI_CHECK(mpiAdd(&t, &t, p));
2035  }
2036 
2037  //Save result
2038  MPI_CHECK(mpiCopy(a, &t));
2039 
2040 end:
2041  //Release multiple precision integers
2042  mpiFree(&s);
2043  mpiFree(&t);
2044 
2045  //Return status code
2046  return error;
2047 }
2048 
2049 #endif
2050 #if (SECP384R1_SUPPORT == ENABLED)
2051 
2052 /**
2053  * @brief Fast modular reduction (secp384r1 curve)
2054  * @param[in,out] a This function accept an integer less than p^2 as
2055  * input and return (a mod p) as output
2056  * @param[in] p Prime modulus
2057  **/
2058 
2060 {
2061  error_t error;
2062  Mpi s;
2063  Mpi t;
2064 
2065  //Initialize multiple precision integers
2066  mpiInit(&s);
2067  mpiInit(&t);
2068 
2069  //Ajust the size of the integers
2070  MPI_CHECK(mpiGrow(a, 96 / MPI_INT_SIZE));
2071  MPI_CHECK(mpiGrow(&s, 48 / MPI_INT_SIZE));
2072  MPI_CHECK(mpiGrow(&t, 48 / MPI_INT_SIZE));
2073 
2074  //Compute T = A11 | A10 | A9 | A8 | A7 | A6 | A5 | A4 | A3 | A2 | A1 | A0
2075  COPY_WORD32(&t, 0, a, 0, 12);
2076 
2077  //Compute S1 = 0 | 0 | 0 | 0 | 0 | A23 | A22 | A21 | 0 | 0 | 0 | 0
2078  CLEAR_WORD32(&s, 0, 4);
2079  COPY_WORD32(&s, 4, a, 21, 3);
2080  CLEAR_WORD32(&s, 7, 5);
2081  //Compute T = T + 2 * S1
2082  MPI_CHECK(mpiAdd(&t, &t, &s));
2083  MPI_CHECK(mpiAdd(&t, &t, &s));
2084 
2085  //Compute S2 = A23 | A22 | A21 | A20 | A19 | A18 | A17 | A16 | A15 | A14 | A13 | A12
2086  COPY_WORD32(&s, 0, a, 12, 12);
2087  //Compute T = T + S2
2088  MPI_CHECK(mpiAdd(&t, &t, &s));
2089 
2090  //Compute S3 = A20 | A19 | A18 | A17 | A16 | A15 | A14 | A13 | A12 | A23 | A22 | A21
2091  COPY_WORD32(&s, 0, a, 21, 3);
2092  COPY_WORD32(&s, 3, a, 12, 9);
2093  //Compute T = T + S3
2094  MPI_CHECK(mpiAdd(&t, &t, &s));
2095 
2096  //Compute S4 = A19 | A18 | A17 | A16 | A15 | A14 | A13 | A12 | A20 | 0 | A23 | 0
2097  CLEAR_WORD32(&s, 0, 1);
2098  COPY_WORD32(&s, 1, a, 23, 1);
2099  CLEAR_WORD32(&s, 2, 1);
2100  COPY_WORD32(&s, 3, a, 20, 1);
2101  COPY_WORD32(&s, 4, a, 12, 8);
2102  //Compute T = T + S4
2103  MPI_CHECK(mpiAdd(&t, &t, &s));
2104 
2105  //Compute S5 = 0 | 0 | 0 | 0 | A23 | A22 | A21 | A20 | 0 | 0 | 0 | 0
2106  CLEAR_WORD32(&s, 0, 4);
2107  COPY_WORD32(&s, 4, a, 20, 4);
2108  CLEAR_WORD32(&s, 8, 4);
2109  //Compute T = T + S5
2110  MPI_CHECK(mpiAdd(&t, &t, &s));
2111 
2112  //Compute S6 = 0 | 0 | 0 | 0 | 0 | 0 | A23 | A22 | A21 | 0 | 0 | A20
2113  COPY_WORD32(&s, 0, a, 20, 1);
2114  CLEAR_WORD32(&s, 1, 2);
2115  COPY_WORD32(&s, 3, a, 21, 3);
2116  CLEAR_WORD32(&s, 6, 6);
2117  //Compute T = T + S6
2118  MPI_CHECK(mpiAdd(&t, &t, &s));
2119 
2120  //Compute D1 = A22 | A21 | A20 | A19 | A18 | A17 | A16 | A15 | A14 | A13 | A12 | A23
2121  COPY_WORD32(&s, 0, a, 23, 1);
2122  COPY_WORD32(&s, 1, a, 12, 11);
2123  //Compute T = T - D1
2124  MPI_CHECK(mpiSub(&t, &t, &s));
2125 
2126  //Compute D2 = 0 | 0 | 0 | 0 | 0 | 0 | 0 | A23 | A22 | A21 | A20 | 0
2127  CLEAR_WORD32(&s, 0, 1);
2128  COPY_WORD32(&s, 1, a, 20, 4);
2129  CLEAR_WORD32(&s, 5, 7);
2130  //Compute T = T - D2
2131  MPI_CHECK(mpiSub(&t, &t, &s));
2132 
2133  //Compute D3 = 0 | 0 | 0 | 0 | 0 | 0 | 0 | A23 | A23 | 0 | 0 | 0
2134  CLEAR_WORD32(&s, 0, 3);
2135  COPY_WORD32(&s, 3, a, 23, 1);
2136  COPY_WORD32(&s, 4, a, 23, 1);
2137  CLEAR_WORD32(&s, 5, 7);
2138  //Compute T = T - D3
2139  MPI_CHECK(mpiSub(&t, &t, &s));
2140 
2141  //Compute (T + 2 * S1 + S2 + S3 + S4 + S5 + S6 - D1 - D2 - D3) mod p
2142  while(mpiComp(&t, p) >= 0)
2143  {
2144  MPI_CHECK(mpiSub(&t, &t, p));
2145  }
2146 
2147  while(mpiCompInt(&t, 0) < 0)
2148  {
2149  MPI_CHECK(mpiAdd(&t, &t, p));
2150  }
2151 
2152  //Save result
2153  MPI_CHECK(mpiCopy(a, &t));
2154 
2155 end:
2156  //Release multiple precision integers
2157  mpiFree(&s);
2158  mpiFree(&t);
2159 
2160  //Return status code
2161  return error;
2162 }
2163 
2164 #endif
2165 #if (SECP521R1_SUPPORT == ENABLED)
2166 
2167 /**
2168  * @brief Fast modular reduction (secp521r1 curve)
2169  * @param[in,out] a This function accept an integer less than p^2 as
2170  * input and return (a mod p) as output
2171  * @param[in] p Prime modulus
2172  **/
2173 
2175 {
2176  error_t error;
2177  Mpi t;
2178 
2179  //Initialize multiple precision integer
2180  mpiInit(&t);
2181 
2182  //Ajust the size of the integers
2183  MPI_CHECK(mpiGrow(a, 132 / MPI_INT_SIZE));
2184  MPI_CHECK(mpiGrow(&t, 68 / MPI_INT_SIZE));
2185 
2186  //Compute A0
2187  COPY_WORD32(&t, 0, a, 0, 17);
2188  t.data[16] &= 0x000001FF;
2189 
2190  //Compute A1
2191  MPI_CHECK(mpiShiftRight(a, 521));
2192 
2193  //Compute A0 + A1
2194  MPI_CHECK(mpiAdd(a, a, &t));
2195 
2196  //Compute (A0 + A1) mod p
2197  while(mpiComp(a, p) >= 0)
2198  {
2199  MPI_CHECK(mpiSub(a, a, p));
2200  }
2201 
2202 end:
2203  //Release multiple precision integer
2204  mpiFree(&t);
2205 
2206  //Return status code
2207  return error;
2208 }
2209 
2210 #endif
2211 #if (SM2_SUPPORT == ENABLED)
2212 
2213 /**
2214  * @brief Fast modular reduction (SM2 curve)
2215  * @param[in,out] a This function accept an integer less than p^2 as
2216  * input and return (a mod p) as output
2217  * @param[in] p Prime modulus
2218  **/
2219 
2221 {
2222  error_t error;
2223  Mpi s;
2224  Mpi t;
2225  Mpi b;
2226 
2227  //Initialize multiple precision integers
2228  mpiInit(&s);
2229  mpiInit(&t);
2230  mpiInit(&b);
2231 
2232  //Ajust the size of the integers
2233  MPI_CHECK(mpiGrow(a, 64 / MPI_INT_SIZE));
2234  MPI_CHECK(mpiGrow(&s, 32 / MPI_INT_SIZE));
2235  MPI_CHECK(mpiGrow(&t, 32 / MPI_INT_SIZE));
2236 
2237  //Compute T = A7 | A6 | A5 | A4 | A3 | A2 | A1 | A0
2238  COPY_WORD32(&t, 0, a, 0, 8);
2239 
2240  //Compute S1 = A15 | A14 | A13 | A12 | A11 | 0 | A9 | A8
2241  COPY_WORD32(&s, 0, a, 8, 2);
2242  CLEAR_WORD32(&s, 2, 1);
2243  COPY_WORD32(&s, 3, a, 11, 5);
2244  //Compute T = T + S1
2245  MPI_CHECK(mpiAdd(&t, &t, &s));
2246 
2247  //Compute S2 = A8 | A15 | A14 | A13 | A12 | 0 | A10 | A9
2248  COPY_WORD32(&s, 0, a, 9, 2);
2249  CLEAR_WORD32(&s, 2, 1);
2250  COPY_WORD32(&s, 3, a, 12, 4);
2251  COPY_WORD32(&s, 7, a, 8, 1);
2252  //Compute T = T + S2
2253  MPI_CHECK(mpiAdd(&t, &t, &s));
2254 
2255  //Compute S3 = A9 | A11 | A10 | A9 | A8 | 0 | A11 | A10
2256  COPY_WORD32(&s, 0, a, 10, 2);
2257  CLEAR_WORD32(&s, 2, 1);
2258  COPY_WORD32(&s, 3, a, 8, 4);
2259  COPY_WORD32(&s, 7, a, 9, 1);
2260  //Compute T = T + S3
2261  MPI_CHECK(mpiAdd(&t, &t, &s));
2262 
2263  //Compute S4 = A10 | 0 | 0 | A15 | A14 | 0 | A12 | A11
2264  COPY_WORD32(&s, 0, a, 11, 2);
2265  CLEAR_WORD32(&s, 2, 1);
2266  COPY_WORD32(&s, 3, a, 14, 2);
2267  CLEAR_WORD32(&s, 5, 2);
2268  COPY_WORD32(&s, 7, a, 10, 1);
2269  //Compute T = T + S4
2270  MPI_CHECK(mpiAdd(&t, &t, &s));
2271 
2272  //Compute S5 = A11 | 0 | 0 | 0 | A15 | 0 | A13 | A12
2273  COPY_WORD32(&s, 0, a, 12, 2);
2274  CLEAR_WORD32(&s, 2, 1);
2275  COPY_WORD32(&s, 3, a, 15, 1);
2276  CLEAR_WORD32(&s, 4, 3);
2277  COPY_WORD32(&s, 7, a, 11, 1);
2278  //Compute T = T + S5
2279  MPI_CHECK(mpiAdd(&t, &t, &s));
2280 
2281  //Compute S6 = A12 | 0 | A15 | A14 | A13 | 0 | A14 | A13
2282  COPY_WORD32(&s, 0, a, 13, 2);
2283  CLEAR_WORD32(&s, 2, 1);
2284  COPY_WORD32(&s, 3, a, 13, 3);
2285  CLEAR_WORD32(&s, 6, 1);
2286  COPY_WORD32(&s, 7, a, 12, 1);
2287  //Compute T = T + 2*S6
2288  MPI_CHECK(mpiAdd(&t, &t, &s));
2289  MPI_CHECK(mpiAdd(&t, &t, &s));
2290 
2291  //Compute S7 = A13 | 0 | 0 | 0 | 0 | 0 | A15 | A14
2292  COPY_WORD32(&s, 0, a, 14, 2);
2293  CLEAR_WORD32(&s, 2, 5);
2294  COPY_WORD32(&s, 7, a, 13, 1);
2295  //Compute T = T + 2*S7
2296  MPI_CHECK(mpiAdd(&t, &t, &s));
2297  MPI_CHECK(mpiAdd(&t, &t, &s));
2298 
2299  //Compute S8 = A14 | 0 | 0 | 0 | 0 | 0 | 0 | A15
2300  COPY_WORD32(&s, 0, a, 15, 1);
2301  CLEAR_WORD32(&s, 1, 6);
2302  COPY_WORD32(&s, 7, a, 14, 1);
2303  //Compute T = T + 2*S8
2304  MPI_CHECK(mpiAdd(&t, &t, &s));
2305  MPI_CHECK(mpiAdd(&t, &t, &s));
2306 
2307  //Compute S9 = A15 | 0 | 0 | 0 | 0 | 0 | 0 | 0
2308  CLEAR_WORD32(&s, 0, 7);
2309  COPY_WORD32(&s, 7, a, 15, 1);
2310  //Compute T = T + 2*S9
2311  MPI_CHECK(mpiAdd(&t, &t, &s));
2312  MPI_CHECK(mpiAdd(&t, &t, &s));
2313 
2314  //Compute D1 = 0 | 0 | 0 | 0 | 0 | A8 | 0 | 0
2315  CLEAR_WORD32(&s, 0, 2);
2316  COPY_WORD32(&s, 2, a, 8, 1);
2317  CLEAR_WORD32(&s, 3, 5);
2318  //Compute T = T - D1
2319  MPI_CHECK(mpiSub(&t, &t, &s));
2320 
2321  //Compute D2 = 0 | 0 | 0 | 0 | 0 | A9 | 0 | 0
2322  CLEAR_WORD32(&s, 0, 2);
2323  COPY_WORD32(&s, 2, a, 9, 1);
2324  CLEAR_WORD32(&s, 3, 5);
2325  //Compute T = T - D2
2326  MPI_CHECK(mpiSub(&t, &t, &s));
2327 
2328  //Compute D3 = 0 | 0 | 0 | 0 | 0 | A13 | 0 | 0
2329  CLEAR_WORD32(&s, 0, 2);
2330  COPY_WORD32(&s, 2, a, 13, 1);
2331  CLEAR_WORD32(&s, 3, 5);
2332  //Compute T = T - D3
2333  MPI_CHECK(mpiSub(&t, &t, &s));
2334 
2335  //Compute D4 = 0 | 0 | 0 | 0 | 0 | A14 | 0 | 0
2336  CLEAR_WORD32(&s, 0, 2);
2337  COPY_WORD32(&s, 2, a, 14, 1);
2338  CLEAR_WORD32(&s, 3, 5);
2339  //Compute T = T - D4
2340  MPI_CHECK(mpiSub(&t, &t, &s));
2341 
2342  //Compute (T + S1 + S2 + S3 + S4 + S5 + 2*S6 + 2*S7 + 2*S8 + 2*S9 - D1 - D2 - D3 - D4) mod p
2343  while(mpiComp(&t, p) >= 0)
2344  {
2345  MPI_CHECK(mpiSub(&t, &t, p));
2346  }
2347 
2348  while(mpiCompInt(&t, 0) < 0)
2349  {
2350  MPI_CHECK(mpiAdd(&t, &t, p));
2351  }
2352 
2353  //Save result
2354  MPI_CHECK(mpiCopy(a, &t));
2355 
2356 end:
2357  //Release multiple precision integers
2358  mpiFree(&s);
2359  mpiFree(&t);
2360 
2361  //Return status code
2362  return error;
2363 }
2364 
2365 #endif
2366 
2367 /**
2368  * @brief Get the elliptic curve that matches the specified OID
2369  * @param[in] oid Object identifier
2370  * @param[in] length OID length
2371  * @return Elliptic curve domain parameters
2372  **/
2373 
2374 const EcCurveInfo *ecGetCurveInfo(const uint8_t *oid, size_t length)
2375 {
2376  const EcCurveInfo *curveInfo;
2377 
2378  //Invalid parameters?
2379  if(oid == NULL || length == 0)
2380  {
2381  curveInfo = NULL;
2382  }
2383 #if (SECP112R1_SUPPORT == ENABLED)
2384  //secp112r1 elliptic curve?
2385  else if(!oidComp(oid, length, SECP112R1_OID, sizeof(SECP112R1_OID)))
2386  {
2387  curveInfo = SECP112R1_CURVE;
2388  }
2389 #endif
2390 #if (SECP112R2_SUPPORT == ENABLED)
2391  //secp112r2 elliptic curve?
2392  else if(!oidComp(oid, length, SECP112R2_OID, sizeof(SECP112R2_OID)))
2393  {
2394  curveInfo = SECP112R2_CURVE;
2395  }
2396 #endif
2397 #if (SECP128R1_SUPPORT == ENABLED)
2398  //secp128r1 elliptic curve?
2399  else if(!oidComp(oid, length, SECP128R1_OID, sizeof(SECP128R1_OID)))
2400  {
2401  curveInfo = SECP128R1_CURVE;
2402  }
2403 #endif
2404 #if (SECP128R2_SUPPORT == ENABLED)
2405  //secp128r2 elliptic curve?
2406  else if(!oidComp(oid, length, SECP128R2_OID, sizeof(SECP128R2_OID)))
2407  {
2408  curveInfo = SECP128R2_CURVE;
2409  }
2410 #endif
2411 #if (SECP160K1_SUPPORT == ENABLED)
2412  //secp160k1 elliptic curve?
2413  else if(!oidComp(oid, length, SECP160K1_OID, sizeof(SECP160K1_OID)))
2414  {
2415  curveInfo = SECP160K1_CURVE;
2416  }
2417 #endif
2418 #if (SECP160R1_SUPPORT == ENABLED)
2419  //secp160r1 elliptic curve?
2420  else if(!oidComp(oid, length, SECP160R1_OID, sizeof(SECP160R1_OID)))
2421  {
2422  curveInfo = SECP160R1_CURVE;
2423  }
2424 #endif
2425 #if (SECP160R2_SUPPORT == ENABLED)
2426  //secp160r2 elliptic curve?
2427  else if(!oidComp(oid, length, SECP160R2_OID, sizeof(SECP160R2_OID)))
2428  {
2429  curveInfo = SECP160R2_CURVE;
2430  }
2431 #endif
2432 #if (SECP192K1_SUPPORT == ENABLED)
2433  //secp192k1 elliptic curve?
2434  else if(!oidComp(oid, length, SECP192K1_OID, sizeof(SECP192K1_OID)))
2435  {
2436  curveInfo = SECP192K1_CURVE;
2437  }
2438 #endif
2439 #if (SECP192R1_SUPPORT == ENABLED)
2440  //secp192r1 elliptic curve?
2441  else if(!oidComp(oid, length, SECP192R1_OID, sizeof(SECP192R1_OID)))
2442  {
2443  curveInfo = SECP192R1_CURVE;
2444  }
2445 #endif
2446 #if (SECP224K1_SUPPORT == ENABLED)
2447  //secp224k1 elliptic curve?
2448  else if(!oidComp(oid, length, SECP224K1_OID, sizeof(SECP224K1_OID)))
2449  {
2450  curveInfo = SECP224K1_CURVE;
2451  }
2452 #endif
2453 #if (SECP224R1_SUPPORT == ENABLED)
2454  //secp224r1 elliptic curve?
2455  else if(!oidComp(oid, length, SECP224R1_OID, sizeof(SECP224R1_OID)))
2456  {
2457  curveInfo = SECP224R1_CURVE;
2458  }
2459 #endif
2460 #if (SECP256K1_SUPPORT == ENABLED)
2461  //secp256k1 elliptic curve?
2462  else if(!oidComp(oid, length, SECP256K1_OID, sizeof(SECP256K1_OID)))
2463  {
2464  curveInfo = SECP256K1_CURVE;
2465  }
2466 #endif
2467 #if (SECP256R1_SUPPORT == ENABLED)
2468  //secp256r1 elliptic curve?
2469  else if(!oidComp(oid, length, SECP256R1_OID, sizeof(SECP256R1_OID)))
2470  {
2471  curveInfo = SECP256R1_CURVE;
2472  }
2473 #endif
2474 #if (SECP384R1_SUPPORT == ENABLED)
2475  //secp384r1 elliptic curve?
2476  else if(!oidComp(oid, length, SECP384R1_OID, sizeof(SECP384R1_OID)))
2477  {
2478  curveInfo = SECP384R1_CURVE;
2479  }
2480 #endif
2481 #if (SECP521R1_SUPPORT == ENABLED)
2482  //secp521r1 elliptic curve?
2483  else if(!oidComp(oid, length, SECP521R1_OID, sizeof(SECP521R1_OID)))
2484  {
2485  curveInfo = SECP521R1_CURVE;
2486  }
2487 #endif
2488 #if (BRAINPOOLP160R1_SUPPORT == ENABLED)
2489  //brainpoolP160r1 elliptic curve?
2491  {
2492  curveInfo = BRAINPOOLP160R1_CURVE;
2493  }
2494 #endif
2495 #if (BRAINPOOLP192R1_SUPPORT == ENABLED)
2496  //brainpoolP192r1 elliptic curve?
2498  {
2499  curveInfo = BRAINPOOLP192R1_CURVE;
2500  }
2501 #endif
2502 #if (BRAINPOOLP224R1_SUPPORT == ENABLED)
2503  //brainpoolP224r1 elliptic curve?
2505  {
2506  curveInfo = BRAINPOOLP224R1_CURVE;
2507  }
2508 #endif
2509 #if (BRAINPOOLP256R1_SUPPORT == ENABLED)
2510  //brainpoolP256r1 elliptic curve?
2512  {
2513  curveInfo = BRAINPOOLP256R1_CURVE;
2514  }
2515 #endif
2516 #if (BRAINPOOLP320R1_SUPPORT == ENABLED)
2517  //brainpoolP320r1 elliptic curve?
2519  {
2520  curveInfo = BRAINPOOLP320R1_CURVE;
2521  }
2522 #endif
2523 #if (BRAINPOOLP384R1_SUPPORT == ENABLED)
2524  //brainpoolP384r1 elliptic curve?
2526  {
2527  curveInfo = BRAINPOOLP384R1_CURVE;
2528  }
2529 #endif
2530 #if (BRAINPOOLP512R1_SUPPORT == ENABLED)
2531  //brainpoolP512r1 elliptic curve?
2533  {
2534  curveInfo = BRAINPOOLP512R1_CURVE;
2535  }
2536 #endif
2537 #if (SM2_SUPPORT == ENABLED)
2538  //SM2 elliptic curve?
2539  else if(!oidComp(oid, length, SM2_OID, sizeof(SM2_OID)))
2540  {
2541  curveInfo = SM2_CURVE;
2542  }
2543 #endif
2544 #if (X25519_SUPPORT == ENABLED)
2545  //Curve25519 elliptic curve?
2546  else if(!oidComp(oid, length, X25519_OID, sizeof(X25519_OID)))
2547  {
2548  curveInfo = X25519_CURVE;
2549  }
2550 #endif
2551 #if (X448_SUPPORT == ENABLED)
2552  //Curve448 elliptic curve?
2553  else if(!oidComp(oid, length, X448_OID, sizeof(X448_OID)))
2554  {
2555  curveInfo = X448_CURVE;
2556  }
2557 #endif
2558 #if (ED25519_SUPPORT == ENABLED)
2559  //Ed25519 elliptic curve?
2560  else if(!oidComp(oid, length, ED25519_OID, sizeof(ED25519_OID)))
2561  {
2562  curveInfo = ED25519_CURVE;
2563  }
2564 #endif
2565 #if (ED448_SUPPORT == ENABLED)
2566  //Ed448 elliptic curve?
2567  else if(!oidComp(oid, length, ED448_OID, sizeof(ED448_OID)))
2568  {
2569  curveInfo = ED448_CURVE;
2570  }
2571 #endif
2572  //Unknown identifier?
2573  else
2574  {
2575  curveInfo = NULL;
2576  }
2577 
2578  //Return the elliptic curve domain parameters, if any
2579  return curveInfo;
2580 }
2581 
2582 #endif
General definitions for cryptographic algorithms.
Debugging facilities.
const EcCurveInfo secp112r1Curve
secp112r1 elliptic curve
Definition: ec_curves.c:109
const uint8_t SECP521R1_OID[5]
Definition: ec_curves.c:76
#define CLEAR_WORD32(a, i, n)
Definition: ec_curves.c:44
error_t secp224r1Mod(Mpi *a, const Mpi *p)
Fast modular reduction (secp224r1 curve)
Definition: ec_curves.c:1817
error_t secp256r1Mod(Mpi *a, const Mpi *p)
Fast modular reduction (secp256r1 curve)
Definition: ec_curves.c:1943
const uint8_t SECP160R1_OID[5]
Definition: ec_curves.c:58
const uint8_t ED25519_OID[3]
Definition: ec_curves.c:98
const EcCurveInfo * ecGetCurveInfo(const uint8_t *oid, size_t length)
Get the elliptic curve that matches the specified OID.
Definition: ec_curves.c:2374
error_t secp128r2Mod(Mpi *a, const Mpi *p)
Fast modular reduction (secp128r2 curve)
Definition: ec_curves.c:1450
const EcCurveInfo secp521r1Curve
secp521r1 elliptic curve
Definition: ec_curves.c:735
const uint8_t SECP160R2_OID[5]
Definition: ec_curves.c:60
const uint8_t SECP192K1_OID[5]
Definition: ec_curves.c:62
const EcCurveInfo brainpoolP192r1Curve
brainpoolP192r1 elliptic curve
Definition: ec_curves.c:845
error_t secp128r1Mod(Mpi *a, const Mpi *p)
Fast modular reduction (secp128r1 curve)
Definition: ec_curves.c:1402
const EcCurveInfo secp384r1Curve
secp384r1 elliptic curve
Definition: ec_curves.c:683
const EcCurveInfo brainpoolP320r1Curve
brainpoolP320r1 elliptic curve
Definition: ec_curves.c:983
const EcCurveInfo secp256k1Curve
secp256k1 elliptic curve
Definition: ec_curves.c:591
error_t sm2Mod(Mpi *a, const Mpi *p)
Fast modular reduction (SM2 curve)
Definition: ec_curves.c:2220
const uint8_t SECP192R1_OID[8]
Definition: ec_curves.c:64
error_t secp192k1Mod(Mpi *a, const Mpi *p)
Fast modular reduction (secp192k1 curve)
Definition: ec_curves.c:1648
error_t secp160r2Mod(Mpi *a, const Mpi *p)
Fast modular reduction (secp160r2 curve)
Definition: ec_curves.c:1597
const uint8_t BRAINPOOLP192R1_OID[9]
Definition: ec_curves.c:80
const EcCurveInfo brainpoolP160r1Curve
brainpoolP160r1 elliptic curve
Definition: ec_curves.c:799
const EcCurveInfo brainpoolP384r1Curve
brainpoolP384r1 elliptic curve
Definition: ec_curves.c:1035
error_t secp160k1Mod(Mpi *a, const Mpi *p)
Fast modular reduction (secp160k1 curve)
Definition: ec_curves.c:1498
const EcCurveInfo brainpoolP256r1Curve
brainpoolP256r1 elliptic curve
Definition: ec_curves.c:937
const EcCurveInfo ed25519Curve
Ed25519 elliptic curve.
Definition: ec_curves.c:1295
const uint8_t BRAINPOOLP320R1_OID[9]
Definition: ec_curves.c:86
const EcCurveInfo brainpoolP512r1Curve
brainpoolP512r1 elliptic curve
Definition: ec_curves.c:1087
const EcCurveInfo secp112r2Curve
secp112r2 elliptic curve
Definition: ec_curves.c:149
const EcCurveInfo x448Curve
Curve448 elliptic curve.
Definition: ec_curves.c:1237
const uint8_t BRAINPOOLP224R1_OID[9]
Definition: ec_curves.c:82
const uint8_t BRAINPOOLP512R1_OID[9]
Definition: ec_curves.c:90
const EcCurveInfo brainpoolP224r1Curve
brainpoolP224r1 elliptic curve
Definition: ec_curves.c:891
const uint8_t BRAINPOOLP256R1_OID[9]
Definition: ec_curves.c:84
const uint8_t X448_OID[3]
Definition: ec_curves.c:96
const uint8_t SECP112R2_OID[5]
Definition: ec_curves.c:50
const EcCurveInfo secp224k1Curve
secp224k1 elliptic curve
Definition: ec_curves.c:499
error_t secp384r1Mod(Mpi *a, const Mpi *p)
Fast modular reduction (secp384r1 curve)
Definition: ec_curves.c:2059
const uint8_t BRAINPOOLP160R1_OID[9]
Definition: ec_curves.c:78
error_t secp192r1Mod(Mpi *a, const Mpi *p)
Fast modular reduction (secp192r1 curve)
Definition: ec_curves.c:1699
const EcCurveInfo secp128r1Curve
secp128r1 elliptic curve
Definition: ec_curves.c:189
const EcCurveInfo secp256r1Curve
secp256r1 elliptic curve
Definition: ec_curves.c:637
const uint8_t SECP128R1_OID[5]
Definition: ec_curves.c:52
const EcCurveInfo secp192k1Curve
secp192k1 elliptic curve
Definition: ec_curves.c:407
error_t secp256k1Mod(Mpi *a, const Mpi *p)
Fast modular reduction (secp256k1 curve)
Definition: ec_curves.c:1892
const EcCurveInfo sm2Curve
SM2 elliptic curve.
Definition: ec_curves.c:1145
const uint8_t X25519_OID[3]
Definition: ec_curves.c:94
const uint8_t SM2_OID[8]
Definition: ec_curves.c:92
const uint8_t SECP256R1_OID[8]
Definition: ec_curves.c:72
const EcCurveInfo ed448Curve
Ed448 elliptic curve.
Definition: ec_curves.c:1341
const EcCurveInfo secp160r1Curve
secp160r1 elliptic curve
Definition: ec_curves.c:315
const EcCurveInfo secp160r2Curve
secp160r2 elliptic curve
Definition: ec_curves.c:361
error_t secp224k1Mod(Mpi *a, const Mpi *p)
Fast modular reduction (secp224k1 curve)
Definition: ec_curves.c:1766
const uint8_t ED448_OID[3]
Definition: ec_curves.c:100
const EcCurveInfo secp160k1Curve
secp160k1 elliptic curve
Definition: ec_curves.c:269
error_t secp521r1Mod(Mpi *a, const Mpi *p)
Fast modular reduction (secp521r1 curve)
Definition: ec_curves.c:2174
const uint8_t SECP112R1_OID[5]
Definition: ec_curves.c:48
const uint8_t SECP384R1_OID[5]
Definition: ec_curves.c:74
const uint8_t SECP224K1_OID[5]
Definition: ec_curves.c:66
error_t secp160r1Mod(Mpi *a, const Mpi *p)
Fast modular reduction (secp160r1 curve)
Definition: ec_curves.c:1549
const uint8_t SECP160K1_OID[5]
Definition: ec_curves.c:56
const uint8_t BRAINPOOLP384R1_OID[9]
Definition: ec_curves.c:88
const EcCurveInfo secp192r1Curve
secp192r1 elliptic curve
Definition: ec_curves.c:453
const EcCurveInfo x25519Curve
Curve25519 elliptic curve.
Definition: ec_curves.c:1191
const uint8_t SECP128R2_OID[5]
Definition: ec_curves.c:54
const EcCurveInfo secp128r2Curve
secp128r2 elliptic curve
Definition: ec_curves.c:229
const EcCurveInfo secp224r1Curve
secp224r1 elliptic curve
Definition: ec_curves.c:545
const uint8_t SECP224R1_OID[5]
Definition: ec_curves.c:68
const uint8_t SECP256K1_OID[5]
Definition: ec_curves.c:70
#define COPY_WORD32(a, i, b, j, n)
Definition: ec_curves.c:45
Elliptic curves.
#define BRAINPOOLP256R1_CURVE
Definition: ec_curves.h:246
#define X448_CURVE
Definition: ec_curves.h:252
#define X25519_CURVE
Definition: ec_curves.h:251
#define SM2_CURVE
Definition: ec_curves.h:250
#define SECP521R1_CURVE
Definition: ec_curves.h:242
#define BRAINPOOLP384R1_CURVE
Definition: ec_curves.h:248
#define SECP256R1_CURVE
Definition: ec_curves.h:240
#define ED448_CURVE
Definition: ec_curves.h:254
#define SECP160R1_CURVE
Definition: ec_curves.h:233
#define SECP224R1_CURVE
Definition: ec_curves.h:238
#define SECP128R2_CURVE
Definition: ec_curves.h:231
#define BRAINPOOLP192R1_CURVE
Definition: ec_curves.h:244
#define SECP160R2_CURVE
Definition: ec_curves.h:234
#define ED25519_CURVE
Definition: ec_curves.h:253
#define BRAINPOOLP160R1_CURVE
Definition: ec_curves.h:243
#define BRAINPOOLP320R1_CURVE
Definition: ec_curves.h:247
#define SECP192K1_CURVE
Definition: ec_curves.h:235
#define SECP384R1_CURVE
Definition: ec_curves.h:241
#define SECP256K1_CURVE
Definition: ec_curves.h:239
#define SECP128R1_CURVE
Definition: ec_curves.h:230
#define SECP112R2_CURVE
Definition: ec_curves.h:229
#define BRAINPOOLP224R1_CURVE
Definition: ec_curves.h:245
#define SECP192R1_CURVE
Definition: ec_curves.h:236
#define SECP160K1_CURVE
Definition: ec_curves.h:232
#define SECP224K1_CURVE
Definition: ec_curves.h:237
#define SECP112R1_CURVE
Definition: ec_curves.h:228
@ EC_CURVE_TYPE_X25519
Definition: ec_curves.h:276
@ EC_CURVE_TYPE_ED25519
Definition: ec_curves.h:278
@ EC_CURVE_TYPE_SECP_R1
Definition: ec_curves.h:273
@ EC_CURVE_TYPE_X448
Definition: ec_curves.h:277
@ EC_CURVE_TYPE_BRAINPOOLP_R1
Definition: ec_curves.h:275
@ EC_CURVE_TYPE_ED448
Definition: ec_curves.h:279
@ EC_CURVE_TYPE_SECP_K1
Definition: ec_curves.h:272
@ EC_CURVE_TYPE_SECP_R2
Definition: ec_curves.h:274
#define BRAINPOOLP512R1_CURVE
Definition: ec_curves.h:249
error_t
Error codes.
Definition: error.h:43
uint8_t t
Definition: lldp_ext_med.h:212
uint8_t oid[]
Definition: lldp_tlv.h:300
error_t mpiShiftLeft(Mpi *r, uint_t n)
Left shift operation.
Definition: mpi.c:1111
error_t mpiCopy(Mpi *r, const Mpi *a)
Copy a multiple precision integer.
Definition: mpi.c:447
error_t mpiSub(Mpi *r, const Mpi *a, const Mpi *b)
Multiple precision subtraction.
Definition: mpi.c:864
int_t mpiCompInt(const Mpi *a, int_t b)
Compare a multiple precision integer with an integer.
Definition: mpi.c:382
int_t mpiComp(const Mpi *a, const Mpi *b)
Compare two multiple precision integers.
Definition: mpi.c:338
error_t mpiShiftRight(Mpi *r, uint_t n)
Right shift operation.
Definition: mpi.c:1178
void mpiInit(Mpi *r)
Initialize a multiple precision integer.
Definition: mpi.c:48
error_t mpiMulInt(Mpi *r, const Mpi *a, int_t b)
Multiply a multiple precision integer by an integer.
Definition: mpi.c:1314
void mpiFree(Mpi *r)
Release a multiple precision integer.
Definition: mpi.c:64
error_t mpiAdd(Mpi *r, const Mpi *a, const Mpi *b)
Multiple precision addition.
Definition: mpi.c:787
error_t mpiGrow(Mpi *r, uint_t size)
Adjust the size of multiple precision integer.
Definition: mpi.c:94
#define MPI_CHECK(f)
Definition: mpi.h:52
#define MPI_INT_SIZE
Definition: mpi.h:46
uint8_t b
Definition: nbns_common.h:104
uint8_t s
Definition: ndp.h:345
uint8_t p
Definition: ndp.h:300
uint8_t a
Definition: ndp.h:411
int_t oidComp(const uint8_t *oid1, size_t oidLen1, const uint8_t *oid2, size_t oidLen2)
Compare object identifiers.
Definition: oid.c:103
OID (Object Identifier)
Elliptic curve parameters.
Definition: ec_curves.h:295
Arbitrary precision integer.
Definition: mpi.h:80
uint8_t length
Definition: tcp.h:368