ECCParams.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2025, 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 #if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX) || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC35XX)
51 #endif
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 /* Error status codes for the utility functions */
58 
65 #define ECCParams_STATUS_SUCCESS (0)
66 
73 #define ECCParams_STATUS_ERROR (-1)
74 
101 typedef uint32_t ECCParams_CurveType;
102 
103 #define ECCParams_CURVE_TYPE_NONE 0U
104 #define ECCParams_CURVE_TYPE_SHORT_WEIERSTRASS_AN3 1U
105 #define ECCParams_CURVE_TYPE_SHORT_WEIERSTRASS_GEN 2U
106 #define ECCParams_CURVE_TYPE_MONTGOMERY 3U
107 #define ECCParams_CURVE_TYPE_EDWARDS 4U
108 
112 typedef enum
113 {
114  /*
115  * WARNING: Do not alter the order or contents of this enum without updating
116  * the corresponding curveParamTable array in ECCParam<Device_Family>_s.c
117  */
127 #if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X4_CC26X3_CC26X4)
129 #endif
130  ECCParams_SecureCurve_COUNT /* This element denotes the max enum value and is not a valid curve */
132 
133 /*
134  * ECCParams_CurveParams have different struct members depending on the context
135  * of the build (Secure-only, Non-secure, or Secure)
136  */
137 #if (TFM_ENABLED == 0) || defined(TFM_BUILD) /* TFM_BUILD indicates this is a TF-M build */
138 
145 typedef struct ECCParams_CurveParams
146 {
147  const ECCParams_CurveType curveType;
148  const uint8_t *prime;
149  const uint8_t *a;
150  const uint8_t *b;
151  const uint8_t *order;
152  const uint8_t cofactor;
153  const size_t length;
154  const uint8_t *generatorX;
155  const uint8_t *generatorY;
157 
158 #else
159 
164 typedef struct ECCParams_CurveParams
165 {
166  ECCParams_SecureCurve secureCurve;
168 
169 #endif /* (TFM_ENABLED == 0) || defined(TFM_BUILD) */
170 
171 #if defined(TFM_BUILD) /* TFM_BUILD indicates this is a TF-M build */
172 
177 /* This must match the ECCParams_CurveParams struct definition directly above */
178 typedef struct ECCParams_ns_CurveParams
179 {
180  ECCParams_SecureCurve secureCurve;
181 } ECCParams_ns_CurveParams;
182 
183 #endif /* defined(TFM_BUILD) */
184 
185 /* Short Weierstrass curves */
186 
193 
200 
207 
214 
221 
228 
235 
242 
247 
248 /* Montgomery curves */
249 
254 
255 /* Edwards curves */
256 
261 
266 #define ECC_LENGTH_PREFIX_BYTES 4
267 
268 #if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC23X0) || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX) || \
269  (DeviceFamily_PARENT == DeviceFamily_PARENT_CC35XX)
270 
280  #define ECCParams_NISTP256_LENGTH 32
281 
286  #define ECC_NISTP256_PARAM_LENGTH_WITH_PREFIX_BYTES (ECCParams_NISTP256_LENGTH + ECC_LENGTH_PREFIX_BYTES)
287 
291 typedef union
292 {
294  uint32_t word[ECC_NISTP256_PARAM_LENGTH_WITH_PREFIX_BYTES / sizeof(uint32_t)];
296 
300 extern const ECC_NISTP256_Param ECC_NISTP256_generatorX;
301 
305 extern const ECC_NISTP256_Param ECC_NISTP256_generatorY;
306 
310 extern const ECC_NISTP256_Param ECC_NISTP256_prime;
311 
316 extern const ECC_NISTP256_Param ECC_NISTP256_a;
317 
322 extern const ECC_NISTP256_Param ECC_NISTP256_b;
323 
327 extern const ECC_NISTP256_Param ECC_NISTP256_order;
328 
332 extern const ECC_NISTP256_Param ECC_NISTP256_k_mont;
333 
337 extern const ECC_NISTP256_Param ECC_NISTP256_a_mont;
338 
342 extern const ECC_NISTP256_Param ECC_NISTP256_b_mont;
343  /* end of nistp256_params */
345 
354  #define ECCParams_NISTP224_LENGTH 28
355 
360  #define ECC_NISTP224_PARAM_LENGTH_WITH_PREFIX_BYTES (ECCParams_NISTP224_LENGTH + ECC_LENGTH_PREFIX_BYTES)
361 
365 typedef union
366 {
368  uint32_t word[ECC_NISTP224_PARAM_LENGTH_WITH_PREFIX_BYTES / sizeof(uint32_t)];
370 
374 extern const ECC_NISTP224_Param ECC_NISTP224_generatorX;
375 
379 extern const ECC_NISTP224_Param ECC_NISTP224_generatorY;
380 
384 extern const ECC_NISTP224_Param ECC_NISTP224_prime;
385 
390 extern const ECC_NISTP224_Param ECC_NISTP224_a;
391 
396 extern const ECC_NISTP224_Param ECC_NISTP224_b;
397 
401 extern const ECC_NISTP224_Param ECC_NISTP224_order;
402 
406 extern const ECC_NISTP224_Param ECC_NISTP224_k_mont;
407 
411 extern const ECC_NISTP224_Param ECC_NISTP224_a_mont;
412 
416 extern const ECC_NISTP224_Param ECC_NISTP224_b_mont;
417  /* end of nistp224_params */
419 
420  /* Octet string format requires an extra byte at the start of the public key */
421  #define OCTET_STRING_OFFSET 1
422 
423  /* Octet string format requires this value in the first byte of the public key */
424  #define OCTET_STRING_PREFIX 0x04
425 
426  /* Length of offset in bytes */
427  #define ECC_LENGTH_OFFSET_BYTES 4
428 
429  /* Param length needs to be equal to the length of the largest curve supported plus length offset bytes */
430  #define ECC_PARAM_LENGTH_WITH_OFFSET_BYTES (ECCParams_NISTP256_LENGTH + ECC_LENGTH_OFFSET_BYTES)
431 
435 typedef union
436 {
437  uint32_t word[ECC_PARAM_LENGTH_WITH_OFFSET_BYTES / sizeof(uint32_t)];
439 } ECC_Param;
440 
441 #endif /* (DeviceFamily_PARENT == DeviceFamily_PARENT_CC23X0) || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC27XX) \
442  || (DeviceFamily_PARENT == DeviceFamily_PARENT_CC35XX) */
443 
447 #define ECCParams_CURVE25519_LENGTH 32
448 
458 #define ECC_CURVE25519_LENGTH_WITH_PREFIX_BYTES (ECCParams_CURVE25519_LENGTH + ECC_LENGTH_PREFIX_BYTES)
459 
463 typedef union
464 {
466  uint32_t word[ECC_CURVE25519_LENGTH_WITH_PREFIX_BYTES / sizeof(uint32_t)];
468 
472 extern const ECC_Curve25519_Param ECC_Curve25519_generatorX;
473 
477 extern const ECC_Curve25519_Param ECC_Curve25519_generatorY;
478 
482 extern const ECC_Curve25519_Param ECC_Curve25519_prime;
483 
488 extern const ECC_Curve25519_Param ECC_Curve25519_a;
489 
494 extern const ECC_Curve25519_Param ECC_Curve25519_b;
495 
499 extern const ECC_Curve25519_Param ECC_Curve25519_order;
500  /* end of curve25519_params */
502 
503 /* Utility functions */
504 
505 /* #define used for backwards compatibility */
506 #define ECCParams_FormatCurve25519PrivateKey ECCParams_formatCurve25519PrivateKey
507 
523 int_fast16_t ECCParams_formatCurve25519PrivateKey(CryptoKey *myPrivateKey);
524 
549 int_fast16_t ECCParams_getUncompressedGeneratorPoint(const ECCParams_CurveParams *curveParams,
550  uint8_t *buffer,
551  size_t length);
552 
553 #ifdef __cplusplus
554 }
555 #endif
556 
557 #endif /* ti_drivers_cryptoutils_ecc_ECCParams__include */
Union to access ECC_NISTP256 curve params in bytes or words.
Definition: ECCParams.h:291
uint32_t ECCParams_CurveType
Enumeration of curve equations supported.
Definition: ECCParams.h:101
The CryptoKey type is an opaque representation of a cryptographic key.
const uint8_t cofactor
Definition: ECCParams.h:152
ECCParams_SecureCurve
Enumeration of ECC curve names supported by TF-M.
Definition: ECCParams.h:112
Union to access ECC_NISTP256 curve params in bytes or words.
Definition: ECCParams.h:365
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:148
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:123
const ECCParams_CurveType curveType
Definition: ECCParams.h:147
Definition: ECCParams.h:128
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:211
const uint8_t * order
Definition: ECCParams.h:151
const ECCParams_CurveParams ECCParams_NISTP192
The NISTP192 curve in short Weierstrass form.
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:150
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:430
const ECC_NISTP256_Param ECC_NISTP256_prime
Prime of the generator point of the ECC_NISTP256 curve.
Definition: ECCParams.h:119
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:154
const ECC_NISTP256_Param ECC_NISTP256_order
Order of the generator point of the ECC_NISTP256 curve.
Definition: ECCParams.h:126
Definition: ECCParams.h:121
Definition: ECCParams.h:118
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:149
Definition: ECCParams.h:130
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:463
const ECCParams_CurveParams ECCParams_Curve25519
The Curve25519 curve in Montgomery form.
Union to format inputs to ECC library.
Definition: ECCParams.h:435
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:360
const size_t length
Definition: ECCParams.h:153
A structure containing the parameters of an elliptic curve.
Definition: ECCParams.h:145
Definition: ECCParams.h:125
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:120
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:458
Definition: ECCParams.h:122
Definition: ECCParams.h:124
#define ECC_NISTP256_PARAM_LENGTH_WITH_PREFIX_BYTES
Length in bytes of NISTP256 curve parameters including the prepended length word. ...
Definition: ECCParams.h:286
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:155
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-2026, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale