AM64x MCU+ SDK  10.00.00
pka.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 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 PKA_H_
49 #define PKA_H_
50 
51 /* ========================================================================== */
52 /* Include Files */
53 /* ========================================================================== */
54 
55 #include <stdint.h>
56 #include <security_common/drivers/crypto/pka/eip29t2_firmware.h>
57 #include <security_common/drivers/crypto/pka/hw_include/cslr_cp_ace.h>
58 #include <kernel/dpl/SystemP.h>
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 /* ========================================================================== */
66 /* Macros & Typedefs */
67 /* ========================================================================== */
68 
77 typedef enum PKA_Return_e
78 {
79  PKA_RETURN_SUCCESS = 0xCEF6A572U,
80  PKA_RETURN_FAILURE = 0xD20341DDU,
82 
84 typedef void *PKA_Handle;
85 
87 #define PKA_BIGINT_MAX (130U)
88 
90 #define PKA_EC_BIGINT_MAX (18U)
91 
96 #define PKA_EC_PARAM_MAXLEN (68U)
97 
101 #define PKA_BIGINT_LEN(bytelen) (((bytelen) / 4U) + 1U)
102 
104 #define PKA_RSA_KEY_E_MAXLEN (8U)
105 
106 #define PKA_RSA_KEY_N_MAXLEN (520U)
107 
108 #define PKA_RSA_KEY_PQ_MAXLEN ((PKA_RSA_KEY_N_MAXLEN / 2U) + 4U)
109 
110 #define PKA_RSA_SIG_MAXLEN PKA_RSA_KEY_N_MAXLEN
111 
112 /* ========================================================================== */
113 /* Structure Declarations */
114 /* ========================================================================== */
115 
128 };
129 
160 };
161 
168 struct PKA_ECPoint {
173 };
174 
194  struct PKA_ECPoint g;
195 };
196 
203 struct PKA_ECDSASig {
208 };
209 
211 typedef struct
212 {
213  /*
214  * SOC configuration
215  */
216  uint32_t caBaseAddr;
218  uint32_t pkaBaseAddr;
220  uint32_t isOpen;
222 } PKA_Attrs;
223 
225 typedef struct
226 {
229 } PKA_Config;
230 
231 /* ========================================================================== */
232 /* Global Variables */
233 /* ========================================================================== */
234 
236 extern PKA_Config gPkaConfig[];
238 extern uint32_t gPkaConfigNum;
239 
240 /* ========================================================================== */
241 /* Function Definitions */
242 /* ========================================================================== */
243 
251 
258 
273 PKA_Return_t PKA_RSAPrivate(PKA_Handle handle, const uint32_t m[PKA_BIGINT_MAX], const struct PKA_RSAPrivkey *k, uint32_t result[PKA_BIGINT_MAX]);
274 
288 PKA_Return_t PKA_RSAPublic(PKA_Handle handle, const uint32_t m[PKA_BIGINT_MAX], const struct PKA_RSAPubkey *k, uint32_t result[PKA_BIGINT_MAX]);
289 
304  const struct PKA_ECPrimeCurveP *cp,
305  const uint32_t priv[PKA_EC_BIGINT_MAX],
306  const uint32_t k[PKA_EC_BIGINT_MAX],
307  const uint32_t h[PKA_EC_BIGINT_MAX],
308  struct PKA_ECDSASig *sig);
309 
324  const struct PKA_ECPrimeCurveP *cp,
325  const struct PKA_ECPoint *pub,
326  const struct PKA_ECDSASig *sig,
327  const uint32_t h[PKA_EC_BIGINT_MAX]);
328 
329 #ifdef __cplusplus
330 }
331 #endif
332 
333 #endif /* PKA_H_ */
334 
PKA_ECDSASign
PKA_Return_t PKA_ECDSASign(PKA_Handle handle, const struct PKA_ECPrimeCurveP *cp, const uint32_t priv[PKA_EC_BIGINT_MAX], const uint32_t k[PKA_EC_BIGINT_MAX], const uint32_t h[PKA_EC_BIGINT_MAX], struct PKA_ECDSASig *sig)
ECDSA sign primitive function.
PKA_RSA_KEY_N_MAXLEN
#define PKA_RSA_KEY_N_MAXLEN
Definition: pka.h:106
PKA_ECPrimeCurveP::prime
uint32_t prime[PKA_BIGINT_LEN(PKA_EC_PARAM_MAXLEN)]
Definition: pka.h:186
PKA_Handle
void * PKA_Handle
Handle to the PKA driver.
Definition: pka.h:84
PKA_RETURN_SUCCESS
@ PKA_RETURN_SUCCESS
Definition: pka.h:79
PKA_ECPrimeCurveP::a
uint32_t a[PKA_BIGINT_LEN(PKA_EC_PARAM_MAXLEN)]
Definition: pka.h:190
index
uint16_t index
Definition: tisci_rm_proxy.h:3
SystemP.h
PKA_EC_BIGINT_MAX
#define PKA_EC_BIGINT_MAX
Definition: pka.h:90
PKA_RSAPrivkey::n
uint32_t n[PKA_BIGINT_LEN(PKA_RSA_KEY_N_MAXLEN)]
Definition: pka.h:145
PKA_close
PKA_Return_t PKA_close(PKA_Handle handle)
Function to close a PKA module specified by the PKA handle.
PKA_BIGINT_MAX
#define PKA_BIGINT_MAX
Definition: pka.h:87
gPkaConfigNum
uint32_t gPkaConfigNum
Externally defined driver configuration Num.
PKA_ECPrimeCurveP::b
uint32_t b[PKA_BIGINT_LEN(PKA_EC_PARAM_MAXLEN)]
Definition: pka.h:192
PKA_RSAPubkey
RSA public key. All values are in biginteger format (size followed by word value array,...
Definition: pka.h:123
crypto_util.h
This file contains the prototype of crypto_util driver APIs.
PKA_RETURN_FAILURE
@ PKA_RETURN_FAILURE
Definition: pka.h:80
PKA_RSAPrivkey::p
uint32_t p[PKA_BIGINT_LEN(PKA_RSA_KEY_PQ_MAXLEN)]
Definition: pka.h:151
PKA_RSA_KEY_PQ_MAXLEN
#define PKA_RSA_KEY_PQ_MAXLEN
Definition: pka.h:108
PKA_RSAPrivkey::e
uint32_t e[PKA_BIGINT_LEN(PKA_RSA_KEY_E_MAXLEN)]
Definition: pka.h:147
PKA_RSAPrivkey::coefficient
uint32_t coefficient[PKA_BIGINT_LEN(PKA_RSA_KEY_PQ_MAXLEN)]
Definition: pka.h:159
PKA_Config
PKA driver context.
Definition: pka.h:226
PKA_ECDSASig
ECDSA signature.
Definition: pka.h:203
PKA_RSAPrivkey::q
uint32_t q[PKA_BIGINT_LEN(PKA_RSA_KEY_PQ_MAXLEN)]
Definition: pka.h:153
PKA_Return_t
PKA_Return_t
PKA Driver Error code.
Definition: pka.h:78
PKA_RSAPubkey::e
uint32_t e[PKA_BIGINT_LEN(PKA_RSA_KEY_E_MAXLEN)]
Definition: pka.h:127
PKA_Attrs::isOpen
uint32_t isOpen
Definition: pka.h:220
PKA_ECPoint::y
uint32_t y[PKA_BIGINT_LEN(PKA_EC_PARAM_MAXLEN)]
Definition: pka.h:172
PKA_ECDSAVerify
PKA_Return_t PKA_ECDSAVerify(PKA_Handle handle, const struct PKA_ECPrimeCurveP *cp, const struct PKA_ECPoint *pub, const struct PKA_ECDSASig *sig, const uint32_t h[PKA_EC_BIGINT_MAX])
ECDSA verify primitive function.
PKA_RSAPrivate
PKA_Return_t PKA_RSAPrivate(PKA_Handle handle, const uint32_t m[PKA_BIGINT_MAX], const struct PKA_RSAPrivkey *k, uint32_t result[PKA_BIGINT_MAX])
This Function performs Decryption or Signing operations.
PKA_RSAPrivkey::d
uint32_t d[PKA_BIGINT_LEN(PKA_RSA_KEY_N_MAXLEN)]
Definition: pka.h:149
PKA_RSAPubkey::n
uint32_t n[PKA_BIGINT_LEN(PKA_RSA_KEY_N_MAXLEN)]
Definition: pka.h:125
PKA_ECPoint
EC Point, also the public key.
Definition: pka.h:168
PKA_Config::attrs
PKA_Attrs * attrs
Definition: pka.h:227
PKA_RSAPrivkey::dp
uint32_t dp[PKA_BIGINT_LEN(PKA_RSA_KEY_PQ_MAXLEN)]
Definition: pka.h:155
PKA_EC_PARAM_MAXLEN
#define PKA_EC_PARAM_MAXLEN
Definition: pka.h:96
PKA_ECPoint::x
uint32_t x[PKA_BIGINT_LEN(PKA_EC_PARAM_MAXLEN)]
Definition: pka.h:170
PKA_Attrs::caBaseAddr
uint32_t caBaseAddr
Definition: pka.h:216
gPkaConfig
PKA_Config gPkaConfig[]
Externally defined driver configuration array.
PKA_RSAPublic
PKA_Return_t PKA_RSAPublic(PKA_Handle handle, const uint32_t m[PKA_BIGINT_MAX], const struct PKA_RSAPubkey *k, uint32_t result[PKA_BIGINT_MAX])
This Function performs Encryption or Verification operations.
PKA_RSAPrivkey
RSA private key. All values are in biginteger format (size followed by word value array,...
Definition: pka.h:143
PKA_BIGINT_LEN
#define PKA_BIGINT_LEN(bytelen)
Definition: pka.h:101
PKA_Attrs
PKA attributes.
Definition: pka.h:212
PKA_ECPrimeCurveP
EC prime curve parameters.
Definition: pka.h:184
PKA_Attrs::pkaBaseAddr
uint32_t pkaBaseAddr
Definition: pka.h:218
PKA_ECDSASig::s
uint32_t s[PKA_BIGINT_LEN(PKA_EC_PARAM_MAXLEN)]
Definition: pka.h:207
PKA_RSA_KEY_E_MAXLEN
#define PKA_RSA_KEY_E_MAXLEN
Definition: pka.h:104
PKA_ECPrimeCurveP::g
struct PKA_ECPoint g
Definition: pka.h:194
PKA_ECPrimeCurveP::order
uint32_t order[PKA_BIGINT_LEN(PKA_EC_PARAM_MAXLEN)]
Definition: pka.h:188
PKA_RSAPrivkey::dq
uint32_t dq[PKA_BIGINT_LEN(PKA_RSA_KEY_PQ_MAXLEN)]
Definition: pka.h:157
PKA_ECDSASig::r
uint32_t r[PKA_BIGINT_LEN(PKA_EC_PARAM_MAXLEN)]
Definition: pka.h:205
PKA_open
PKA_Handle PKA_open(uint32_t index)
Function to Open PKA instance, enable PKA engine, Initialize clocks and Load PKA Fw.