MCUX CLNS
MCUX Crypto Library Normal Secure
Loading...
Searching...
No Matches
mcuxClEls_Ecc.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/* Copyright 2020-2023 NXP */
3/* */
4/* SPDX-License-Identifier: BSD-3-Clause */
5/* */
6/* Redistribution and use in source and binary forms, with or without */
7/* modification, are permitted provided that the following conditions are */
8/* met: */
9/* */
10/* 1. Redistributions of source code must retain the above copyright */
11/* notice, this list of conditions and the following disclaimer. */
12/* */
13/* 2. Redistributions in binary form must reproduce the above copyright */
14/* notice, this list of conditions and the following disclaimer in the */
15/* documentation and/or other materials provided with the distribution. */
16/* */
17/* 3. Neither the name of the copyright holder nor the names of its */
18/* contributors may be used to endorse or promote products derived from */
19/* this software without specific prior written permission. */
20/* */
21/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS */
22/* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */
23/* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A */
24/* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
25/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
26/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
27/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR */
28/* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
29/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
30/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
31/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
32/*--------------------------------------------------------------------------*/
33
44
45
46#ifndef MCUXCLELS_ECC_H_
47#define MCUXCLELS_ECC_H_
48
49#include <mcuxClConfig.h> // Exported features flags header
50#include <mcuxClEls_Common.h> // Common types & functionality
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
62
63
64/**********************************************
65 * CONSTANTS
66 **********************************************/
73
80#define MCUXCLELS_ECC_VALUE_HASHED ((uint32_t) 0u<< 0u)
81#define MCUXCLELS_ECC_VALUE_NOT_HASHED ((uint32_t) 1u<< 0u)
82#define MCUXCLELS_ECC_VALUE_RTF ((uint32_t) 1u<< 1u)
83#define MCUXCLELS_ECC_VALUE_NO_RTF ((uint32_t) 0u<< 1u)
87
94#define MCUXCLELS_KEYGEN_VALUE_SIGN_PUBLICKEY ((uint32_t) 1u<< 0u)
95#define MCUXCLELS_KEYGEN_VALUE_TYPE_SIGN ((uint32_t) 0u<< 1u)
96#define MCUXCLELS_KEYGEN_VALUE_TYPE_KEYEXCHANGE ((uint32_t) 1u<< 1u)
97#define MCUXCLELS_KEYGEN_VALUE_DETERMINISTIC ((uint32_t) 0u<< 2u)
98#define MCUXCLELS_KEYGEN_VALUE_RANDOM ((uint32_t) 1u<< 2u)
99#define MCUXCLELS_KEYGEN_VALUE_GEN_PUB_KEY ((uint32_t) 0u<< 3u)
100#define MCUXCLELS_KEYGEN_VALUE_NO_PUB_KEY ((uint32_t) 1u<< 3u)
101#define MCUXCLELS_KEYGEN_VALUE_NO_RANDOM_DATA ((uint32_t) 0u<< 5u)
102#define MCUXCLELS_KEYGEN_VALUE_USE_RANDOM_DATA ((uint32_t) 1u<< 5u)
106
113#define MCUXCLELS_ECC_HASHED (0U)
114#define MCUXCLELS_ECC_NOT_HASHED (1U)
115
116#define MCUXCLELS_ECC_RTF (1U)
117#define MCUXCLELS_ECC_NO_RTF (0U)
121
128#define MCUXCLELS_ECC_PUBLICKEY_SIGN_ENABLE (1U)
129#define MCUXCLELS_ECC_PUBLICKEY_SIGN_DISABLE (0U)
130
131#define MCUXCLELS_ECC_OUTPUTKEY_SIGN (0U)
132#define MCUXCLELS_ECC_OUTPUTKEY_KEYEXCHANGE (1U)
133
134#define MCUXCLELS_ECC_OUTPUTKEY_DETERMINISTIC (0U)
135#define MCUXCLELS_ECC_OUTPUTKEY_RANDOM (1U)
136
137#define MCUXCLELS_ECC_GEN_PUBLIC_KEY (0U)
138#define MCUXCLELS_ECC_SKIP_PUBLIC_KEY (1U)
140
141#define MCUXCLELS_ECC_NO_RANDOM_DATA (0U)
142#define MCUXCLELS_ECC_INCLUDE_RANDOM_DATA (1U)
144
147
154#define MCUXCLELS_ECC_REVERSEFETCH_ENABLE (0x01U)
155#define MCUXCLELS_ECC_REVERSEFETCH_DISABLE (0x00U)
156
157#ifdef MCUXCL_FEATURE_ELS_PUK_INTERNAL_BIT
158#define MCUXCLELS_ECC_EXTKEY_EXTERNAL (0x01U)
159#define MCUXCLELS_ECC_EXTKEY_INTERNAL (0x00U)
160#endif /* MCUXCL_FEATURE_ELS_PUK_INTERNAL_BIT */
164
171#define MCUXCLELS_ECC_PUBLICKEY_SIZE ((size_t) 64U)
172#define MCUXCLELS_ECC_SIGNATURE_SIZE ((size_t) 64U)
173#define MCUXCLELS_ECC_SIGNATURE_R_SIZE ((size_t) 32U)
177 /* mcuxClEls_Ecc_Macros */
181
182
183/**********************************************
184 * TYPEDEFS
185 **********************************************/
192
197typedef uint8_t mcuxClEls_EccByte_t;
198
203typedef union
204{
205 struct
206 {
207 uint32_t value;
208 } word;
209 struct
210 {
211 uint32_t echashchl :1;
212 uint32_t signrtf :1;
213 uint32_t :2;
214 uint32_t revf :1;
215 uint32_t :27;
216 } bits;
218
223typedef union
224{
225 struct
226 {
227 uint32_t value;
228 } word;
229 struct
230 {
231 uint32_t echashchl :1;
232 uint32_t :3;
233 uint32_t revf :1;
234#ifdef MCUXCL_FEATURE_ELS_PUK_INTERNAL_BIT
235 uint32_t :8;
236 uint32_t extkey :1;
237 uint32_t :18;
238#else
239 uint32_t :27;
240#endif /* MCUXCL_FEATURE_ELS_PUK_INTERNAL_BIT */
241 } bits;
243
248typedef union
249{
250 struct
251 {
252 uint32_t value;
253 } word;
254 struct
255 {
256 uint32_t kgsign :1;
257 uint32_t kgtypedh :1;
258 uint32_t kgsrc :1;
259 uint32_t skip_pbk :1;
260 uint32_t revf :1;
261 uint32_t kgsign_rnd :1;
262 uint32_t :26;
263 } bits;
265
270typedef union
271{
272 struct
273 {
274 uint32_t value;
275 } word;
276 struct
277 {
278 uint32_t :4;
279 uint32_t revf :1;
280 uint32_t :8;
281 uint32_t extkey :1;
282 uint32_t :18;
283 } bits;
285 /* mcuxClEls_Ecc_Types */
289
290
291/**********************************************
292 * FUNCTIONS
293 **********************************************/
300
342 mcuxClEls_KeyIndex_t signingKeyIdx,
343 mcuxClEls_KeyIndex_t privateKeyIdx,
344 mcuxClEls_KeyProp_t generatedKeyProperties,
345 uint8_t const * pRandomData,
346 uint8_t * pPublicKey
347 );
348
382 mcuxClEls_KeyIndex_t privateKeyIdx,
383 uint8_t const * pPublicKey,
384 mcuxClEls_KeyIndex_t sharedSecretIdx,
385 mcuxClEls_KeyProp_t sharedSecretProperties
386 );
387
388#ifdef MCUXCL_FEATURE_ELS_PUK_INTERNAL
410MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEls_EccKeyExchangeInt_Async)
411MCUXCLELS_API MCUX_CSSL_FP_PROTECTED_TYPE(mcuxClEls_Status_t) mcuxClEls_EccKeyExchangeInt_Async(
412 mcuxClEls_KeyIndex_t privateKeyIdx,
413 mcuxClEls_KeyIndex_t publicKeyIdx,
414 mcuxClEls_KeyIndex_t sharedSecretIdx,
415 mcuxClEls_KeyProp_t sharedSecretProperties
416 );
417#endif /* MCUXCL_FEATURE_ELS_PUK_INTERNAL */
418
467 uint8_t const * pInputHash,
468 uint8_t const * pInputMessage,
469 size_t inputMessageLength,
470 uint8_t * pOutput
471 );
472
528 uint8_t const * pInputHash,
529 uint8_t const * pInputMessage,
530 size_t inputMessageLength,
531 uint8_t const * pSignatureAndPubKey,
532 uint8_t * pOutput
533 );
534
535#ifdef MCUXCL_FEATURE_ELS_PUK_INTERNAL
588MCUX_CSSL_FP_FUNCTION_DECL(mcuxClEls_EccVerifyInt_Async)
591 mcuxClEls_KeyIndex_t publicKeyIdx,
592 uint8_t const * pInputHash,
593 uint8_t const * pInputMessage,
594 size_t inputMessageLength,
595 uint8_t const * pSignature,
596 uint8_t * pOutput
597 );
598
599#endif /* MCUXCL_FEATURE_ELS_PUK_INTERNAL */
600 /* mcuxClEls_Ecc_Functions */
604 /* mcuxClEls_Ecc */
608
609#ifdef __cplusplus
610} /* extern "C" */
611#endif
612
613#endif /* MCUXCLELS_ECC_H_ */
ELS header for common functionality.
#define MCUXCLELS_API
Marks a function as a public API function of the mcuxClEls component.
Definition mcuxClEls_Common.h:66
uint8_t mcuxClEls_EccByte_t
Data type for ECC parameters in ELS format.
Definition mcuxClEls_Ecc.h:197
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_EccVerify_Async(mcuxClEls_EccVerifyOption_t options, uint8_t const *pInputHash, uint8_t const *pInputMessage, size_t inputMessageLength, uint8_t const *pSignatureAndPubKey, uint8_t *pOutput)
Verifies an ECDSA signature of a given message.
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_EccKeyGen_Async(mcuxClEls_EccKeyGenOption_t options, mcuxClEls_KeyIndex_t signingKeyIdx, mcuxClEls_KeyIndex_t privateKeyIdx, mcuxClEls_KeyProp_t generatedKeyProperties, uint8_t const *pRandomData, uint8_t *pPublicKey)
Generates an ECC key pair on the NIST P-256 curve.
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_EccKeyExchange_Async(mcuxClEls_KeyIndex_t privateKeyIdx, uint8_t const *pPublicKey, mcuxClEls_KeyIndex_t sharedSecretIdx, mcuxClEls_KeyProp_t sharedSecretProperties)
Performs a Diffie-Hellman key exchange with an internal ECC private key and an external ECC public ke...
MCUXCLELS_API mcuxClEls_Status_t mcuxClEls_EccSign_Async(mcuxClEls_EccSignOption_t options, mcuxClEls_KeyIndex_t keyIdx, uint8_t const *pInputHash, uint8_t const *pInputMessage, size_t inputMessageLength, uint8_t *pOutput)
Generates an ECDSA signature of a given message.
uint32_t mcuxClEls_Status_t
Type for ELS driver status codes.
Definition mcuxClEls_Types.h:232
uint32_t mcuxClEls_KeyIndex_t
Type for ELS keystore indices.
Definition mcuxClEls_Types.h:242
#define MCUX_CSSL_FP_FUNCTION_DECL(...)
Declaration of a flow protected function.
Definition mcuxCsslFlowProtection.h:145
#define MCUX_CSSL_FP_PROTECTED_TYPE(resultType)
Based on a given base type, builds a return type with flow protection.
Definition mcuxCsslFlowProtection.h:101
Command option bit field for mcuxClEls_EccSign_Async Bit field to configure mcuxClEls_EccSign_Async.
Definition mcuxClEls_Ecc.h:204
uint32_t value
Access the bit field as a full word; initialize with a combination of constants from MCUXCLELS_ECC (S...
Definition mcuxClEls_Ecc.h:207
uint32_t signrtf
Define if signing the Run-Time Fingerprint.
Definition mcuxClEls_Ecc.h:212
uint32_t revf
This field is managed internally.
Definition mcuxClEls_Ecc.h:214
uint32_t echashchl
Define type of input, plain message or hash of message.
Definition mcuxClEls_Ecc.h:211
Command option bit field for mcuxClEls_EccVerify_Async Bit field to configure mcuxClEls_EccVerifyOpti...
Definition mcuxClEls_Ecc.h:224
uint32_t echashchl
Define type of input, plain message or hash of message.
Definition mcuxClEls_Ecc.h:231
uint32_t value
Access the bit field as a full word; initialize with a combination of constants from MCUXCLELS_ECC (S...
Definition mcuxClEls_Ecc.h:227
uint32_t revf
This field is managed internally.
Definition mcuxClEls_Ecc.h:233
Command option bit field for mcuxClEls_EccKeyGen_Async Bit field to configure mcuxClEls_EccKeyGenOpti...
Definition mcuxClEls_Ecc.h:249
uint32_t value
Accesses the bit field as a full word; initialize with a combination of constants from MCUXCLELS_KEYG...
Definition mcuxClEls_Ecc.h:252
uint32_t revf
This field is managed internally.
Definition mcuxClEls_Ecc.h:260
uint32_t kgsign
Define if signing the output public key.
Definition mcuxClEls_Ecc.h:256
uint32_t kgsrc
Define if the output key is deterministic or random.
Definition mcuxClEls_Ecc.h:258
uint32_t kgsign_rnd
Define if using user provided random data for the signature.
Definition mcuxClEls_Ecc.h:261
uint32_t kgtypedh
Define the usage of the output key.
Definition mcuxClEls_Ecc.h:257
uint32_t skip_pbk
Define if generating a public key.
Definition mcuxClEls_Ecc.h:259
Command option bit field for mcuxClEls_EccKeyExchange_Async, for internal use only.
Definition mcuxClEls_Ecc.h:271
uint32_t revf
This field is managed internally.
Definition mcuxClEls_Ecc.h:279
uint32_t value
Accesses the bit field as a full word.
Definition mcuxClEls_Ecc.h:274
uint32_t extkey
This field is managed internally.
Definition mcuxClEls_Ecc.h:281
Type for ELS key store key properties.
Definition mcuxClEls_Types.h:246