AM64x MCU+ SDK  10.01.00
asym_crypt.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2024 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * 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
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
48 #ifndef ASYM_CRYPT_H_
49 #define ASYM_CRYPT_H_
50 
51 /* ========================================================================== */
52 /* Include Files */
53 /* ========================================================================== */
54 
55 #include <stdint.h>
56 #include <kernel/dpl/SystemP.h>
58 
59 #if defined (SOC_AM64X) || defined (SOC_AM243X)\
60  || defined(SOC_AM263X) || defined(SOC_AM263PX)\
61  || defined (SOC_AM273X) || defined (SOC_AWR294X)
62 #include <security_common/drivers/crypto/pka/pka.h>
63 #endif
64 
65 #if defined(SOC_F29H85X) || defined (SOC_AM261X)
66 #include <security_common/drivers/crypto/pke/hw_include/pke_hw/inc/pke.h>
67 #include <security_common/drivers/crypto/pke/hw_include/pke_hw/src/pke4_driver.h>
68 #include <security_common/drivers/crypto/pke/hw_include/pke_hw/inc/pke_dpasl.h>
69 #endif
70 
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74 
75 /* ========================================================================== */
76 /* Macros & Typedefs */
77 /* ========================================================================== */
78 
87 typedef enum AsymCrypt_Return_e
88 {
89  ASYM_CRYPT_RETURN_SUCCESS = 0xCEF6A572U,
90  ASYM_CRYPT_RETURN_FAILURE = 0xD20341DDU,
92 
94 typedef void *AsymCrypt_Handle;
95 
97 #define RSA_MAX_LENGTH (130U)
98 
100 #define ECDSA_MAX_LENGTH (18U)
101 
106 #define EC_PARAM_MAXLEN (68U)
107 
111 #define ASYM_CRYPT_LEN(bytelen) (((bytelen) / 4U) + 1U)
112 
114 #define RSA_KEY_E_MAXLEN (8U)
115 
116 #define RSA_KEY_N_MAXLEN (520U)
117 
118 #define RSA_KEY_PQ_MAXLEN ((RSA_KEY_N_MAXLEN / 2U) + 4U)
119 
120 #define RSA_SIG_MAXLEN RSA_KEY_N_MAXLEN
121 
122 /* ========================================================================== */
123 /* Structure Declarations */
124 /* ========================================================================== */
125 
138 };
139 
170 };
171 
183 };
184 
204  struct AsymCrypt_ECPoint g;
205 };
206 
218 };
219 
220 /* ========================================================================== */
221 /* Global Variables */
222 /* ========================================================================== */
223 
224 /* ========================================================================== */
225 /* Function Definitions */
226 /* ========================================================================== */
227 
235 
242 
258 
272 AsymCrypt_Return_t AsymCrypt_RSAPublic(AsymCrypt_Handle handle, const uint32_t m[RSA_MAX_LENGTH], const struct AsymCrypt_RSAPubkey *k, uint32_t result[RSA_MAX_LENGTH]);
273 
288  const struct AsymCrypt_ECPrimeCurveP *cp,
289  const uint32_t priv[ECDSA_MAX_LENGTH],
290  const uint32_t k[ECDSA_MAX_LENGTH],
291  const uint32_t h[ECDSA_MAX_LENGTH],
292  struct AsymCrypt_ECDSASig *sig);
293 
308  const struct AsymCrypt_ECPrimeCurveP *cp,
309  const struct AsymCrypt_ECPoint *pub,
310  const struct AsymCrypt_ECDSASig *sig,
311  const uint32_t h[ECDSA_MAX_LENGTH]);
312 
313 #ifdef __cplusplus
314 }
315 #endif
316 
317 #endif /* ASYM_CRYPT_H_ */
318 
AsymCrypt_RSAPrivkey::n
uint32_t n[ASYM_CRYPT_LEN(RSA_KEY_N_MAXLEN)]
Definition: asym_crypt.h:155
AsymCrypt_RSAPrivkey::e
uint32_t e[ASYM_CRYPT_LEN(RSA_KEY_E_MAXLEN)]
Definition: asym_crypt.h:157
AsymCrypt_ECPrimeCurveP::b
uint32_t b[ASYM_CRYPT_LEN(EC_PARAM_MAXLEN)]
Definition: asym_crypt.h:202
RSA_KEY_N_MAXLEN
#define RSA_KEY_N_MAXLEN
Definition: asym_crypt.h:116
AsymCrypt_close
AsymCrypt_Return_t AsymCrypt_close(AsymCrypt_Handle handle)
Function to close a AsymCrypt module specified by the AsymCrypt handle.
ASYM_CRYPT_RETURN_SUCCESS
@ ASYM_CRYPT_RETURN_SUCCESS
Definition: asym_crypt.h:89
AsymCrypt_RSAPubkey::n
uint32_t n[ASYM_CRYPT_LEN(RSA_KEY_N_MAXLEN)]
Definition: asym_crypt.h:135
AsymCrypt_ECDSASig::s
uint32_t s[ASYM_CRYPT_LEN(EC_PARAM_MAXLEN)]
Definition: asym_crypt.h:217
index
uint16_t index
Definition: tisci_rm_proxy.h:3
ECDSA_MAX_LENGTH
#define ECDSA_MAX_LENGTH
Definition: asym_crypt.h:100
SystemP.h
AsymCrypt_ECPrimeCurveP::prime
uint32_t prime[ASYM_CRYPT_LEN(EC_PARAM_MAXLEN)]
Definition: asym_crypt.h:196
AsymCrypt_ECPrimeCurveP::order
uint32_t order[ASYM_CRYPT_LEN(EC_PARAM_MAXLEN)]
Definition: asym_crypt.h:198
AsymCrypt_RSAPrivkey::coefficient
uint32_t coefficient[ASYM_CRYPT_LEN(RSA_KEY_PQ_MAXLEN)]
Definition: asym_crypt.h:169
crypto_util.h
This file contains the prototype of crypto_util driver APIs.
AsymCrypt_ECDSASig::r
uint32_t r[ASYM_CRYPT_LEN(EC_PARAM_MAXLEN)]
Definition: asym_crypt.h:215
AsymCrypt_ECPoint::x
uint32_t x[ASYM_CRYPT_LEN(EC_PARAM_MAXLEN)]
Definition: asym_crypt.h:180
RSA_KEY_E_MAXLEN
#define RSA_KEY_E_MAXLEN
Definition: asym_crypt.h:114
AsymCrypt_RSAPubkey
RSA public key. All values are in biginteger format (size followed by word value array,...
Definition: asym_crypt.h:133
AsymCrypt_ECPrimeCurveP::a
uint32_t a[ASYM_CRYPT_LEN(EC_PARAM_MAXLEN)]
Definition: asym_crypt.h:200
AsymCrypt_RSAPrivkey::q
uint32_t q[ASYM_CRYPT_LEN(RSA_KEY_PQ_MAXLEN)]
Definition: asym_crypt.h:163
AsymCrypt_ECDSASign
AsymCrypt_Return_t AsymCrypt_ECDSASign(AsymCrypt_Handle handle, const struct AsymCrypt_ECPrimeCurveP *cp, const uint32_t priv[ECDSA_MAX_LENGTH], const uint32_t k[ECDSA_MAX_LENGTH], const uint32_t h[ECDSA_MAX_LENGTH], struct AsymCrypt_ECDSASig *sig)
ECDSA sign primitive function.
RSA_KEY_PQ_MAXLEN
#define RSA_KEY_PQ_MAXLEN
Definition: asym_crypt.h:118
AsymCrypt_Handle
void * AsymCrypt_Handle
Handle to the AsymCrypt driver.
Definition: asym_crypt.h:94
AsymCrypt_RSAPrivkey::p
uint32_t p[ASYM_CRYPT_LEN(RSA_KEY_PQ_MAXLEN)]
Definition: asym_crypt.h:161
AsymCrypt_ECPoint
EC Point, also the public key.
Definition: asym_crypt.h:178
AsymCrypt_RSAPublic
AsymCrypt_Return_t AsymCrypt_RSAPublic(AsymCrypt_Handle handle, const uint32_t m[RSA_MAX_LENGTH], const struct AsymCrypt_RSAPubkey *k, uint32_t result[RSA_MAX_LENGTH])
This Function performs Encryption or Verification operations.
AsymCrypt_RSAPubkey::e
uint32_t e[ASYM_CRYPT_LEN(RSA_KEY_E_MAXLEN)]
Definition: asym_crypt.h:137
AsymCrypt_ECPoint::y
uint32_t y[ASYM_CRYPT_LEN(EC_PARAM_MAXLEN)]
Definition: asym_crypt.h:182
AsymCrypt_Return_t
AsymCrypt_Return_t
ASYM CRYPTO Driver Error code.
Definition: asym_crypt.h:88
AsymCrypt_ECPrimeCurveP::g
struct AsymCrypt_ECPoint g
Definition: asym_crypt.h:204
AsymCrypt_RSAPrivkey::dq
uint32_t dq[ASYM_CRYPT_LEN(RSA_KEY_PQ_MAXLEN)]
Definition: asym_crypt.h:167
AsymCrypt_RSAPrivkey
RSA private key. All values are in biginteger format (size followed by word value array,...
Definition: asym_crypt.h:153
AsymCrypt_open
AsymCrypt_Handle AsymCrypt_open(uint32_t index)
Function to Open AsymCrypt instance, enable AsymCrypt engine, Initialize clocks.
ASYM_CRYPT_LEN
#define ASYM_CRYPT_LEN(bytelen)
Definition: asym_crypt.h:111
AsymCrypt_ECDSAVerify
AsymCrypt_Return_t AsymCrypt_ECDSAVerify(AsymCrypt_Handle handle, const struct AsymCrypt_ECPrimeCurveP *cp, const struct AsymCrypt_ECPoint *pub, const struct AsymCrypt_ECDSASig *sig, const uint32_t h[ECDSA_MAX_LENGTH])
ECDSA verify primitive function.
AsymCrypt_ECPrimeCurveP
EC prime curve parameters.
Definition: asym_crypt.h:194
AsymCrypt_RSAPrivate
AsymCrypt_Return_t AsymCrypt_RSAPrivate(AsymCrypt_Handle handle, const uint32_t m[RSA_MAX_LENGTH], const struct AsymCrypt_RSAPrivkey *k, uint32_t result[RSA_MAX_LENGTH])
This Function performs Decryption or Signing operations.
AsymCrypt_RSAPrivkey::dp
uint32_t dp[ASYM_CRYPT_LEN(RSA_KEY_PQ_MAXLEN)]
Definition: asym_crypt.h:165
ASYM_CRYPT_RETURN_FAILURE
@ ASYM_CRYPT_RETURN_FAILURE
Definition: asym_crypt.h:90
RSA_MAX_LENGTH
#define RSA_MAX_LENGTH
Definition: asym_crypt.h:97
AsymCrypt_ECDSASig
ECDSA signature.
Definition: asym_crypt.h:213
EC_PARAM_MAXLEN
#define EC_PARAM_MAXLEN
Definition: asym_crypt.h:106
AsymCrypt_RSAPrivkey::d
uint32_t d[ASYM_CRYPT_LEN(RSA_KEY_N_MAXLEN)]
Definition: asym_crypt.h:159