ECCParams.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2023, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
39 #ifndef ti_drivers_cryptoutils_ecc_ECCParams__include
40 #define ti_drivers_cryptoutils_ecc_ECCParams__include
41 
42 #include <stdint.h>
43 #include <stddef.h>
44 #include <stdbool.h>
45 
47 #include <ti/devices/DeviceFamily.h>
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 /* Error status codes for the utility functions */
54 
61 #define ECCParams_STATUS_SUCCESS (0)
62 
69 #define ECCParams_STATUS_ERROR (-1)
70 
97 typedef uint32_t ECCParams_CurveType;
98 
99 #define ECCParams_CURVE_TYPE_NONE 0U
100 #define ECCParams_CURVE_TYPE_SHORT_WEIERSTRASS_AN3 1U
101 #define ECCParams_CURVE_TYPE_SHORT_WEIERSTRASS_GEN 2U
102 #define ECCParams_CURVE_TYPE_MONTGOMERY 3U
103 #define ECCParams_CURVE_TYPE_EDWARDS 4U
104 
108 typedef enum
109 {
110  /*
111  * WARNING: Do not alter the order or contents of this enum without updating
112  * the corresponding curveParamTable array in ECCParamCC26X4_s.c
113  */
124  ECCParams_SecureCurve_COUNT /* This element denotes the max enum value and is not a valid curve */
126 
127 /*
128  * ECCParams_CurveParams have different struct members depending on the context
129  * of the build (Secure-only, Non-secure, or Secure)
130  */
131 #if (TFM_ENABLED == 0) || defined(TFM_BUILD) /* TFM_BUILD indicates this is a TF-M build */
132 
139 typedef struct ECCParams_CurveParams
140 {
141  const ECCParams_CurveType curveType;
142  const uint8_t *prime;
143  const uint8_t *a;
144  const uint8_t *b;
145  const uint8_t *order;
146  const uint8_t cofactor;
147  const size_t length;
148  const uint8_t *generatorX;
149  const uint8_t *generatorY;
151 
152 #else
153 
158 typedef struct ECCParams_CurveParams
159 {
160  ECCParams_SecureCurve secureCurve;
162 
163 #endif /* (TFM_ENABLED == 0) || defined(TFM_BUILD) */
164 
165 #if defined(TFM_BUILD) /* TFM_BUILD indicates this is a TF-M build */
166 
171 /* This must match the ECCParams_CurveParams struct definition directly above */
172 typedef struct ECCParams_ns_CurveParams
173 {
174  ECCParams_SecureCurve secureCurve;
175 } ECCParams_ns_CurveParams;
176 
177 #endif /* defined(TFM_BUILD) */
178 
179 /* Short Weierstrass curves */
180 
187 
194 
201 
208 
215 
222 
229 
234 
235 /* Montgomery curves */
236 
241 
242 /* Edwards curves */
243 
248 
253 #define ECC_LENGTH_PREFIX_BYTES 4
254 
255 #if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC23X0) || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX)
256 
266  #define ECCParams_NISTP256_LENGTH 32
267 
272  #define ECC_NISTP256_PARAM_LENGTH_WITH_PREFIX_BYTES (ECCParams_NISTP256_LENGTH + ECC_LENGTH_PREFIX_BYTES)
273 
277 typedef union
278 {
280  uint32_t word[ECC_NISTP256_PARAM_LENGTH_WITH_PREFIX_BYTES / sizeof(uint32_t)];
282 
286 extern const ECC_NISTP256_Param ECC_NISTP256_generatorX;
287 
291 extern const ECC_NISTP256_Param ECC_NISTP256_generatorY;
292 
296 extern const ECC_NISTP256_Param ECC_NISTP256_prime;
297 
302 extern const ECC_NISTP256_Param ECC_NISTP256_a;
303 
308 extern const ECC_NISTP256_Param ECC_NISTP256_b;
309 
313 extern const ECC_NISTP256_Param ECC_NISTP256_order;
314 
318 extern const ECC_NISTP256_Param ECC_NISTP256_k_mont;
319 
323 extern const ECC_NISTP256_Param ECC_NISTP256_a_mont;
324 
328 extern const ECC_NISTP256_Param ECC_NISTP256_b_mont;
329  /* end of nistp256_params */
331 
340  #define ECCParams_NISTP224_LENGTH 28
341 
346  #define ECC_NISTP224_PARAM_LENGTH_WITH_PREFIX_BYTES (ECCParams_NISTP224_LENGTH + ECC_LENGTH_PREFIX_BYTES)
347 
351 typedef union
352 {
354  uint32_t word[ECC_NISTP224_PARAM_LENGTH_WITH_PREFIX_BYTES / sizeof(uint32_t)];
356 
360 extern const ECC_NISTP224_Param ECC_NISTP224_generatorX;
361 
365 extern const ECC_NISTP224_Param ECC_NISTP224_generatorY;
366 
370 extern const ECC_NISTP224_Param ECC_NISTP224_prime;
371 
376 extern const ECC_NISTP224_Param ECC_NISTP224_a;
377 
382 extern const ECC_NISTP224_Param ECC_NISTP224_b;
383 
387 extern const ECC_NISTP224_Param ECC_NISTP224_order;
388 
392 extern const ECC_NISTP224_Param ECC_NISTP224_k_mont;
393 
397 extern const ECC_NISTP224_Param ECC_NISTP224_a_mont;
398 
402 extern const ECC_NISTP224_Param ECC_NISTP224_b_mont;
403  /* end of nistp224_params */
405 
406  /* Octet string format requires an extra byte at the start of the public key */
407  #define OCTET_STRING_OFFSET 1
408 
409  /* Length of offset in bytes */
410  #define ECC_LENGTH_OFFSET_BYTES 4
411 
412  /* Param length needs to be equal to the length of the largest curve supported plus length offset bytes */
413  #define ECC_PARAM_LENGTH_WITH_OFFSET_BYTES (ECCParams_NISTP256_LENGTH + ECC_LENGTH_OFFSET_BYTES)
414 
418 typedef union
419 {
420  uint32_t word[ECC_PARAM_LENGTH_WITH_OFFSET_BYTES / sizeof(uint32_t)];
422 } ECC_Param;
423 
424 #endif /* DeviceFamily_PARENT == DeviceFamily_PARENT_CC23X0 */
425 
429 #define ECCParams_CURVE25519_LENGTH 32
430 
440 #define ECC_CURVE25519_LENGTH_WITH_PREFIX_BYTES (ECCParams_CURVE25519_LENGTH + ECC_LENGTH_PREFIX_BYTES)
441 
445 typedef union
446 {
448  uint32_t word[ECC_CURVE25519_LENGTH_WITH_PREFIX_BYTES / sizeof(uint32_t)];
450 
454 extern const ECC_Curve25519_Param ECC_Curve25519_generatorX;
455 
459 extern const ECC_Curve25519_Param ECC_Curve25519_generatorY;
460 
464 extern const ECC_Curve25519_Param ECC_Curve25519_prime;
465 
470 extern const ECC_Curve25519_Param ECC_Curve25519_a;
471 
476 extern const ECC_Curve25519_Param ECC_Curve25519_b;
477 
481 extern const ECC_Curve25519_Param ECC_Curve25519_order;
482  /* end of curve25519_params */
484 
485 /* Utility functions */
486 
487 /* #define used for backwards compatibility */
488 #define ECCParams_FormatCurve25519PrivateKey ECCParams_formatCurve25519PrivateKey
489 
505 int_fast16_t ECCParams_formatCurve25519PrivateKey(CryptoKey *myPrivateKey);
506 
531 int_fast16_t ECCParams_getUncompressedGeneratorPoint(const ECCParams_CurveParams *curveParams,
532  uint8_t *buffer,
533  size_t length);
534 
535 #ifdef __cplusplus
536 }
537 #endif
538 
539 #endif /* ti_drivers_cryptoutils_ecc_ECCParams__include */
Union to access ECC_NISTP256 curve params in bytes or words.
Definition: ECCParams.h:277
uint32_t ECCParams_CurveType
Enumeration of curve equations supported.
Definition: ECCParams.h:97
The CryptoKey type is an opaque representation of a cryptographic key.
const uint8_t cofactor
Definition: ECCParams.h:146
ECCParams_SecureCurve
Enumeration of ECC curve names supported by TF-M.
Definition: ECCParams.h:108
Union to access ECC_NISTP256 curve params in bytes or words.
Definition: ECCParams.h:351
const ECC_NISTP224_Param ECC_NISTP224_b_mont
&#39;b&#39; in Montgomery domain of the ECC_NISTP224 curve.
const uint8_t * prime
Definition: ECCParams.h:142
const ECC_NISTP224_Param ECC_NISTP224_a
&#39;a&#39; constant of the ECC_NISTP224 curve when expressed in short Weierstrass form (y^2 = x^3 + a*x + b)...
Definition: ECCParams.h:119
const ECCParams_CurveType curveType
Definition: ECCParams.h:141
Definition: ECCParams.h:123
const ECC_NISTP256_Param ECC_NISTP256_generatorY
Y coordinate of the generator point of the ECC_NISTP256 curve.
const ECCParams_CurveParams ECCParams_BrainpoolP512R1
The BrainpoolP512R1 curve in short Weierstrass form.
const ECCParams_CurveParams ECCParams_Wei25519
A short Weierstrass equivalent representation of Ed25519.
const ECCParams_CurveParams ECCParams_NISTP384
The NISTP384 curve in short Weierstrass form.
CryptoKey datastructure.
Definition: CryptoKey.h:196
const uint8_t * order
Definition: ECCParams.h:145
const ECC_Curve25519_Param ECC_Curve25519_generatorX
X coordinate of the generator point of the ECC_Curve25519 curve.
const ECCParams_CurveParams ECCParams_BrainpoolP256R1
The BrainpoolP256R1 curve in short Weierstrass form.
const uint8_t * b
Definition: ECCParams.h:144
const ECC_NISTP256_Param ECC_NISTP256_a
&#39;a&#39; constant of the ECC_NISTP256 curve when expressed in short Weierstrass form (y^2 = x^3 + a*x + b)...
const ECCParams_CurveParams ECCParams_NISTP256
The NISTP256 curve in short Weierstrass form.
const ECC_NISTP256_Param ECC_NISTP256_generatorX
X coordinate of the generator point of the ECC_NISTP256 curve.
const ECC_Curve25519_Param ECC_Curve25519_prime
Prime of the generator point of the ECC_Curve25519 curve.
const ECC_Curve25519_Param ECC_Curve25519_b
&#39;b&#39; constant of the ECC_Curve25519 curve when expressed in short Weierstrass form (y^2 = x^3 + a*x + ...
const ECC_NISTP224_Param ECC_NISTP224_prime
Prime of the generator point of the ECC_NISTP224 curve.
#define ECC_PARAM_LENGTH_WITH_OFFSET_BYTES
Definition: ECCParams.h:413
const ECC_NISTP256_Param ECC_NISTP256_prime
Prime of the generator point of the ECC_NISTP256 curve.
Definition: ECCParams.h:115
const ECC_NISTP224_Param ECC_NISTP224_a_mont
&#39;a&#39; in Montgomery domain of the ECC_NISTP224 curve.
int_fast16_t ECCParams_getUncompressedGeneratorPoint(const ECCParams_CurveParams *curveParams, uint8_t *buffer, size_t length)
Extracts the curve generator point from an ecliptic curve description.
int_fast16_t ECCParams_formatCurve25519PrivateKey(CryptoKey *myPrivateKey)
Formats a CryptoKey to conform to Curve25519 private key requirements.
const uint8_t * generatorX
Definition: ECCParams.h:148
const ECC_NISTP256_Param ECC_NISTP256_order
Order of the generator point of the ECC_NISTP256 curve.
Definition: ECCParams.h:122
Definition: ECCParams.h:117
Definition: ECCParams.h:114
const ECC_NISTP224_Param ECC_NISTP224_b
&#39;b&#39; constant of the ECC_NISTP224 curve when expressed in short Weierstrass form (y^2 = x^3 + a*x + b)...
const uint8_t * a
Definition: ECCParams.h:143
Definition: ECCParams.h:124
const ECC_Curve25519_Param ECC_Curve25519_order
Order of the generator point of the ECC_Curve25519 curve.
Union to access ECC_Curve25519 curve params in bytes or words.
Definition: ECCParams.h:445
const ECCParams_CurveParams ECCParams_Curve25519
The Curve25519 curve in Montgomery form.
Union to format inputs to ECC library.
Definition: ECCParams.h:418
const ECC_NISTP224_Param ECC_NISTP224_k_mont
&#39;k&#39; in Montgomery domain of the ECC_NISTP224 curve.
const ECC_NISTP256_Param ECC_NISTP256_k_mont
&#39;k&#39; in Montgomery domain of the ECC_NISTP256 curve.
#define ECC_NISTP224_PARAM_LENGTH_WITH_PREFIX_BYTES
Length in bytes of NISTP256 curve parameters including the prepended length word. ...
Definition: ECCParams.h:346
const size_t length
Definition: ECCParams.h:147
A structure containing the parameters of an elliptic curve.
Definition: ECCParams.h:139
Definition: ECCParams.h:121
const ECC_NISTP256_Param ECC_NISTP256_b
&#39;b&#39; constant of the ECC_NISTP256 curve when expressed in short Weierstrass form (y^2 = x^3 + a*x + b)...
const ECCParams_CurveParams ECCParams_BrainpoolP384R1
The BrainpoolP384R1 curve in short Weierstrass form.
const ECC_NISTP224_Param ECC_NISTP224_generatorX
X coordinate of the generator point of the ECC_NISTP224 curve.
Definition: ECCParams.h:116
const ECC_Curve25519_Param ECC_Curve25519_a
&#39;a&#39; constant of the ECC_Curve25519 curve when expressed in short Weierstrass form (y^2 = x^3 + a*x + ...
const ECCParams_CurveParams ECCParams_NISTP224
The NISTP224 curve in short Weierstrass form.
const ECCParams_CurveParams ECCParams_Ed25519
The Ed25519 curve in Edwards form.
struct ECCParams_CurveParams ECCParams_CurveParams
A structure containing the parameters of an elliptic curve.
#define ECC_CURVE25519_LENGTH_WITH_PREFIX_BYTES
Length in bytes of Curve25519 curve parameters including the prepended length word.
Definition: ECCParams.h:440
Definition: ECCParams.h:118
Definition: ECCParams.h:120
#define ECC_NISTP256_PARAM_LENGTH_WITH_PREFIX_BYTES
Length in bytes of NISTP256 curve parameters including the prepended length word. ...
Definition: ECCParams.h:272
const ECC_NISTP256_Param ECC_NISTP256_b_mont
&#39;b&#39; in Montgomery domain of the ECC_NISTP256 curve.
const ECC_NISTP224_Param ECC_NISTP224_generatorY
Y coordinate of the generator point of the ECC_NISTP224 curve.
const uint8_t * generatorY
Definition: ECCParams.h:149
const ECC_NISTP224_Param ECC_NISTP224_order
Order of the generator point of the ECC_NISTP224 curve.
const ECC_Curve25519_Param ECC_Curve25519_generatorY
Y coordinate of the generator point of the ECC_Curve25519 curve.
const ECC_NISTP256_Param ECC_NISTP256_a_mont
&#39;a&#39; in Montgomery domain of the ECC_NISTP256 curve.
const ECCParams_CurveParams ECCParams_NISTP521
The NISTP521 curve in short Weierstrass form.
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale