1 /**************************************************************************//**
2  * @file     crypto.h
3  * @version  V3.00
4  * @brief    Cryptographic Accelerator driver header file
5  *
6  * @copyright SPDX-License-Identifier: Apache-2.0
7  * @copyright Copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
8  ******************************************************************************/
9 #ifndef __CRYPTO_H__
10 #define __CRYPTO_H__
11 
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16 
17 /** @addtogroup Standard_Driver Standard Driver
18   @{
19 */
20 
21 /** @addtogroup CRYPTO_Driver CRYPTO Driver
22   @{
23 */
24 
25 
26 /** @addtogroup CRYPTO_EXPORTED_CONSTANTS CRYPTO Exported Constants
27   @{
28 */
29 
30 
31 #define PRNG_KEY_SIZE_128       ( 0UL)     /*!< Select to generate 128-bit random key   \hideinitializer */
32 #define PRNG_KEY_SIZE_163       ( 1UL)     /*!< Select to generate 163-bit random key   \hideinitializer */
33 #define PRNG_KEY_SIZE_192       ( 2UL)     /*!< Select to generate 192-bit random key   \hideinitializer */
34 #define PRNG_KEY_SIZE_224       ( 3UL)     /*!< Select to generate 224-bit random key   \hideinitializer */
35 #define PRNG_KEY_SIZE_255       ( 4UL)     /*!< Select to generate 255-bit random key   \hideinitializer */
36 #define PRNG_KEY_SIZE_256       ( 6UL)     /*!< Select to generate 256-bit random key   \hideinitializer */
37 #define PRNG_KEY_SIZE_283       ( 7UL)     /*!< Select to generate 283-bit random key (Key Store Only)  \hideinitializer */
38 #define PRNG_KEY_SIZE_384       ( 8UL)     /*!< Select to generate 384-bit random key (Key Store Only)  \hideinitializer */
39 #define PRNG_KEY_SIZE_409       ( 9UL)     /*!< Select to generate 409-bit random key (Key Store Only)  \hideinitializer */
40 #define PRNG_KEY_SIZE_512       (10UL)     /*!< Select to generate 512-bit random key (Key Store Only)  \hideinitializer */
41 #define PRNG_KEY_SIZE_521       (11UL)     /*!< Select to generate 521-bit random key (Key Store Only)  \hideinitializer */
42 #define PRNG_KEY_SIZE_571       (12UL)     /*!< Select to generate 571-bit random key (Key Store Only)  \hideinitializer */
43 
44 #define PRNG_SEED_CONT          (0UL)     /*!< PRNG using current seed                 \hideinitializer */
45 #define PRNG_SEED_RELOAD        (1UL)     /*!< PRNG reload new seed                    \hideinitializer */
46 
47 #define PRNG_CTL_SEEDSRC_TRNG      (0UL)                       /*!< PRNG seed from TRNG                    \hideinitializer */
48 #define PRNG_CTL_SEEDSRC_SEEDREG   (CRPT_PRNG_CTL_SEEDSRC_Msk) /*!< PRNG seed from PRNG seed register      \hideinitializer */
49 
50 
51 #define AES_KEY_SIZE_128        (0UL)     /*!< AES select 128-bit key length           \hideinitializer */
52 #define AES_KEY_SIZE_192        (1UL)     /*!< AES select 192-bit key length           \hideinitializer */
53 #define AES_KEY_SIZE_256        (2UL)     /*!< AES select 256-bit key length           \hideinitializer */
54 
55 #define AES_MODE_ECB            (0UL)     /*!< AES select ECB mode                     \hideinitializer */
56 #define AES_MODE_CBC            (1UL)     /*!< AES select CBC mode                     \hideinitializer */
57 #define AES_MODE_CFB            (2UL)     /*!< AES select CFB mode                     \hideinitializer */
58 #define AES_MODE_OFB            (3UL)     /*!< AES select OFB mode                     \hideinitializer */
59 #define AES_MODE_CTR            (4UL)     /*!< AES select CTR mode                     \hideinitializer */
60 #define AES_MODE_CBC_CS1        (0x10UL)  /*!< AES select CBC CS1 mode                 \hideinitializer */
61 #define AES_MODE_CBC_CS2        (0x11UL)  /*!< AES select CBC CS2 mode                 \hideinitializer */
62 #define AES_MODE_CBC_CS3        (0x12UL)  /*!< AES select CBC CS3 mode                 \hideinitializer */
63 #define AES_MODE_GCM            (0x20UL)
64 #define AES_MODE_GHASH          (0x21UL)
65 #define AES_MODE_CCM            (0x22UL)
66 
67 #define SM4_MODE_ECB            (0x200UL)     /*!< SM4 select ECB mode                     \hideinitializer */
68 #define SM4_MODE_CBC            (0x201UL)     /*!< SM4 select CBC mode                     \hideinitializer */
69 #define SM4_MODE_CFB            (0x202UL)     /*!< SM4 select CFB mode                     \hideinitializer */
70 #define SM4_MODE_OFB            (0x203UL)     /*!< SM4 select OFB mode                     \hideinitializer */
71 #define SM4_MODE_CTR            (0x204UL)     /*!< SM4 select CTR mode                     \hideinitializer */
72 #define SM4_MODE_CBC_CS1        (0x210UL)     /*!< SM4 select CBC CS1 mode                 \hideinitializer */
73 #define SM4_MODE_CBC_CS2        (0x211UL)     /*!< SM4 select CBC CS2 mode                 \hideinitializer */
74 #define SM4_MODE_CBC_CS3        (0x212UL)     /*!< SM4 select CBC CS3 mode                 \hideinitializer */
75 #define SM4_MODE_GCM            (0x220UL)
76 #define SM4_MODE_GHASH          (0x221UL)
77 #define SM4_MODE_CCM            (0x222UL)
78 
79 #define AES_NO_SWAP             (0UL)     /*!< AES do not swap input and output data   \hideinitializer */
80 #define AES_OUT_SWAP            (1UL)     /*!< AES swap output data                    \hideinitializer */
81 #define AES_IN_SWAP             (2UL)     /*!< AES swap input data                     \hideinitializer */
82 #define AES_IN_OUT_SWAP         (3UL)     /*!< AES swap both input and output data     \hideinitializer */
83 
84 #define SHA_MODE_SHA1           (0UL)     /*!< SHA select SHA-1 160-bit                \hideinitializer */
85 #define SHA_MODE_SHA224         (5UL)     /*!< SHA select SHA-224 224-bit              \hideinitializer */
86 #define SHA_MODE_SHA256         (4UL)     /*!< SHA select SHA-256 256-bit              \hideinitializer */
87 #define SHA_MODE_SHA384         (7UL)     /*!< SHA select SHA-384 384-bit              \hideinitializer */
88 #define SHA_MODE_SHA512         (6UL)     /*!< SHA select SHA-512 512-bit              \hideinitializer */
89 
90 #define HMAC_MODE_SHA1          (8UL)     /*!< HMAC select SHA-1 160-bit                \hideinitializer */
91 #define HMAC_MODE_SHA224        (13UL)    /*!< HMAC select SHA-224 224-bit              \hideinitializer */
92 #define HMAC_MODE_SHA256        (12UL)    /*!< HMAC select SHA-256 256-bit              \hideinitializer */
93 #define HMAC_MODE_SHA384        (15UL)    /*!< HMAC select SHA-384 384-bit              \hideinitializer */
94 #define HMAC_MODE_SHA512        (14UL)    /*!< HMAC select SHA-512 512-bit              \hideinitializer */
95 
96 
97 #define SHA_NO_SWAP             (0UL)     /*!< SHA do not swap input and output data   \hideinitializer */
98 #define SHA_OUT_SWAP            (1UL)     /*!< SHA swap output data                    \hideinitializer */
99 #define SHA_IN_SWAP             (2UL)     /*!< SHA swap input data                     \hideinitializer */
100 #define SHA_IN_OUT_SWAP         (3UL)     /*!< SHA swap both input and output data     \hideinitializer */
101 
102 #define CRYPTO_DMA_FIRST        (0x4UL)   /*!< Do first encrypt/decrypt in DMA cascade \hideinitializer */
103 #define CRYPTO_DMA_ONE_SHOT     (0x5UL)   /*!< Do one shot encrypt/decrypt with DMA      \hideinitializer */
104 #define CRYPTO_DMA_CONTINUE     (0x6UL)   /*!< Do continuous encrypt/decrypt in DMA cascade \hideinitializer */
105 #define CRYPTO_DMA_LAST         (0x7UL)   /*!< Do last encrypt/decrypt in DMA cascade          \hideinitializer */
106 
107 //---------------------------------------------------
108 
109 #define RSA_MAX_KLEN            (4096)
110 #define RSA_KBUF_HLEN           (RSA_MAX_KLEN/4 + 8)
111 #define RSA_KBUF_BLEN           (RSA_MAX_KLEN + 32)
112 
113 #define RSA_KEY_SIZE_1024       (0UL)     /*!< RSA select 1024-bit key length           \hideinitializer */
114 #define RSA_KEY_SIZE_2048       (1UL)     /*!< RSA select 2048-bit key length           \hideinitializer */
115 #define RSA_KEY_SIZE_3072       (2UL)     /*!< RSA select 3072-bit key length           \hideinitializer */
116 #define RSA_KEY_SIZE_4096       (3UL)     /*!< RSA select 4096-bit key length           \hideinitializer */
117 
118 #define RSA_MODE_NORMAL         (0x000UL)     /*!< RSA select normal mode                \hideinitializer */
119 #define RSA_MODE_CRT            (0x004UL)     /*!< RSA select CRT mode                   \hideinitializer */
120 #define RSA_MODE_CRTBYPASS      (0x00CUL)     /*!< RSA select CRT bypass mode            \hideinitializer */
121 
122 
123 typedef enum
124 {
125     /*!< ECC curve                \hideinitializer */
126     CURVE_P_192,                        /*!< ECC curve P-192          \hideinitializer */
127     CURVE_P_224,                        /*!< ECC curve P-224          \hideinitializer */
128     CURVE_P_256,                        /*!< ECC curve P-256          \hideinitializer */
129     CURVE_P_384,                        /*!< ECC curve P-384          \hideinitializer */
130     CURVE_P_521,                        /*!< ECC curve P-521          \hideinitializer */
131     CURVE_K_163,                        /*!< ECC curve K-163          \hideinitializer */
132     CURVE_K_233,                        /*!< ECC curve K-233          \hideinitializer */
133     CURVE_K_283,                        /*!< ECC curve K-283          \hideinitializer */
134     CURVE_K_409,                        /*!< ECC curve K-409          \hideinitializer */
135     CURVE_K_571,                        /*!< ECC curve K-571          \hideinitializer */
136     CURVE_B_163,                        /*!< ECC curve B-163          \hideinitializer */
137     CURVE_B_233,                        /*!< ECC curve B-233          \hideinitializer */
138     CURVE_B_283,                        /*!< ECC curve B-283          \hideinitializer */
139     CURVE_B_409,                        /*!< ECC curve B-409          \hideinitializer */
140     CURVE_B_571,                        /*!< ECC curve K-571          \hideinitializer */
141     CURVE_KO_192,                       /*!< ECC 192-bits "Koblitz" curve   \hideinitializer */
142     CURVE_KO_224,                       /*!< ECC 224-bits "Koblitz" curve   \hideinitializer */
143     CURVE_KO_256,                       /*!< ECC 256-bits "Koblitz" curve   \hideinitializer */
144     CURVE_BP_256,                       /*!< ECC Brainpool 256-bits curve   \hideinitializer */
145     CURVE_BP_384,                       /*!< ECC Brainpool 256-bits curve   \hideinitializer */
146     CURVE_BP_512,                       /*!< ECC Brainpool 256-bits curve   \hideinitializer */
147     CURVE_25519,                        /*!< ECC curve-25519          \hideinitializer */
148     CURVE_SM2_256,                      /*!< SM2                      \hideinitializer */
149     CURVE_UNDEF = -0x7fffffff,                        /*!< Invalid curve            \hideinitializer */
150 }
151 E_ECC_CURVE;
152 
153 
154 
155 typedef struct e_curve_t
156 {
157     E_ECC_CURVE curve_id;
158     int32_t     Echar;
159     char        Ea[144];
160     char        Eb[144];
161     char        Px[144];
162     char        Py[144];
163     int32_t     Epl;
164     char        Pp[176];
165     int32_t     Eol;
166     char        Eorder[176];
167     int32_t     key_len;
168     int32_t     irreducible_k1;
169     int32_t     irreducible_k2;
170     int32_t     irreducible_k3;
171     int32_t     GF;
172 }  ECC_CURVE;
173 
174 
175 /* RSA working buffer for normal mode */
176 typedef struct
177 {
178     uint32_t au32RsaOutput[128]; /* The RSA answer. */
179     uint32_t au32RsaN[128]; /* The base of modulus operation word. */
180     uint32_t au32RsaM[128]; /* The base of exponentiation words. */
181     uint32_t au32RsaE[128]; /* The exponent of exponentiation words. */
182 } RSA_BUF_NORMAL_T;
183 
184 /* RSA working buffer for CRT ( + CRT bypass) mode */
185 typedef struct
186 {
187     uint32_t au32RsaOutput[128]; /* The RSA answer. */
188     uint32_t au32RsaN[128]; /* The base of modulus operation word. */
189     uint32_t au32RsaM[128]; /* The base of exponentiation words. */
190     uint32_t au32RsaE[128]; /* The exponent of exponentiation words. */
191     uint32_t au32RsaP[128]; /* The Factor of Modulus Operation. */
192     uint32_t au32RsaQ[128]; /* The Factor of Modulus Operation. */
193     uint32_t au32RsaTmpCp[128]; /* The Temporary Value(Cp) of RSA CRT. */
194     uint32_t au32RsaTmpCq[128]; /* The Temporary Value(Cq) of RSA CRT. */
195     uint32_t au32RsaTmpDp[128]; /* The Temporary Value(Dp) of RSA CRT. */
196     uint32_t au32RsaTmpDq[128]; /* The Temporary Value(Dq) of RSA CRT. */
197     uint32_t au32RsaTmpRp[128]; /* The Temporary Value(Rp) of RSA CRT. */
198     uint32_t au32RsaTmpRq[128]; /* The Temporary Value(Rq) of RSA CRT. */
199 } RSA_BUF_CRT_T;
200 
201 /* RSA working buffer for using key store */
202 typedef struct
203 {
204     uint32_t au32RsaOutput[128]; /* The RSA answer. */
205     uint32_t au32RsaN[128]; /* The base of modulus operation word. */
206     uint32_t au32RsaM[128]; /* The base of exponentiation words. */
207 } RSA_BUF_KS_T;
208 
209 /**@}*/ /* end of group CRYPTO_EXPORTED_CONSTANTS */
210 
211 
212 /** @addtogroup CRYPTO_EXPORTED_MACROS CRYPTO Exported Macros
213   @{
214 */
215 
216 /*----------------------------------------------------------------------------------------------*/
217 /*  Macros                                                                                      */
218 /*----------------------------------------------------------------------------------------------*/
219 
220 /**
221   * @brief This macro enables PRNG interrupt.
222   * @param crpt     Specified crypto module
223   * @return None
224   * \hideinitializer
225   */
226 #define PRNG_ENABLE_INT(crpt)       ((crpt)->INTEN |= CRPT_INTEN_PRNGIEN_Msk)
227 
228 /**
229   * @brief This macro disables PRNG interrupt.
230   * @param crpt     Specified crypto module
231   * @return None
232   * \hideinitializer
233   */
234 #define PRNG_DISABLE_INT(crpt)      ((crpt)->INTEN &= ~CRPT_INTEN_PRNGIEN_Msk)
235 
236 /**
237   * @brief This macro gets PRNG interrupt flag.
238   * @param crpt     Specified crypto module
239   * @return PRNG interrupt flag.
240   * \hideinitializer
241   */
242 #define PRNG_GET_INT_FLAG(crpt)     ((crpt)->INTSTS & CRPT_INTSTS_PRNGIF_Msk)
243 
244 /**
245   * @brief This macro clears PRNG interrupt flag.
246   * @param crpt     Specified crypto module
247   * @return None
248   * \hideinitializer
249   */
250 #define PRNG_CLR_INT_FLAG(crpt)     ((crpt)->INTSTS = CRPT_INTSTS_PRNGIF_Msk)
251 
252 /**
253   * @brief This macro enables AES interrupt.
254   * @param crpt     Specified crypto module
255   * @return None
256   * \hideinitializer
257   */
258 #define AES_ENABLE_INT(crpt)        ((crpt)->INTEN |= (CRPT_INTEN_AESIEN_Msk|CRPT_INTEN_AESEIEN_Msk))
259 
260 /**
261   * @brief This macro disables AES interrupt.
262   * @param crpt     Specified crypto module
263   * @return None
264   * \hideinitializer
265   */
266 #define AES_DISABLE_INT(crpt)       ((crpt)->INTEN &= ~(CRPT_INTEN_AESIEN_Msk|CRPT_INTEN_AESEIEN_Msk))
267 
268 /**
269   * @brief This macro gets AES interrupt flag.
270   * @param crpt     Specified crypto module
271   * @return AES interrupt flag.
272   * \hideinitializer
273   */
274 #define AES_GET_INT_FLAG(crpt)      ((crpt)->INTSTS & (CRPT_INTSTS_AESIF_Msk|CRPT_INTSTS_AESEIF_Msk))
275 
276 /**
277   * @brief This macro clears AES interrupt flag.
278   * @param crpt     Specified crypto module
279   * @return None
280   * \hideinitializer
281   */
282 #define AES_CLR_INT_FLAG(crpt)      ((crpt)->INTSTS = (CRPT_INTSTS_AESIF_Msk|CRPT_INTSTS_AESEIF_Msk))
283 
284 /**
285   * @brief This macro enables AES key protection.
286   * @param crpt     Specified crypto module
287   * @return None
288   * \hideinitializer
289   */
290 #define AES_ENABLE_KEY_PROTECT(crpt)  ((crpt)->AES_CTL |= CRPT_AES_CTL_KEYPRT_Msk)
291 
292 /**
293   * @brief This macro disables AES key protection.
294   * @param crpt     Specified crypto module
295   * @return None
296   * \hideinitializer
297   */
298 #define AES_DISABLE_KEY_PROTECT(crpt) ((crpt)->AES_CTL = ((crpt)->AES_CTL & ~CRPT_AES_CTL_KEYPRT_Msk) | (0x16UL<<CRPT_AES_CTL_KEYUNPRT_Pos)); \
299                                       ((crpt)->AES_CTL &= ~CRPT_AES_CTL_KEYPRT_Msk)
300 /**
301   * @brief This macro enables SHA interrupt.
302   * @param crpt     Specified crypto module
303   * @return None
304   * \hideinitializer
305   */
306 #define SHA_ENABLE_INT(crpt)        ((crpt)->INTEN |= (CRPT_INTEN_HMACIEN_Msk|CRPT_INTEN_HMACEIEN_Msk))
307 
308 /**
309   * @brief This macro disables SHA interrupt.
310   * @param crpt     Specified crypto module
311   * @return None
312   * \hideinitializer
313   */
314 #define SHA_DISABLE_INT(crpt)       ((crpt)->INTEN &= ~(CRPT_INTEN_HMACIEN_Msk|CRPT_INTEN_HMACEIEN_Msk))
315 
316 /**
317   * @brief This macro gets SHA interrupt flag.
318   * @param crpt     Specified crypto module
319   * @return SHA interrupt flag.
320   * \hideinitializer
321   */
322 #define SHA_GET_INT_FLAG(crpt)      ((crpt)->INTSTS & (CRPT_INTSTS_HMACIF_Msk|CRPT_INTSTS_HMACEIF_Msk))
323 
324 /**
325   * @brief This macro clears SHA interrupt flag.
326   * @param crpt     Specified crypto module
327   * @return None
328   * \hideinitializer
329   */
330 #define SHA_CLR_INT_FLAG(crpt)      ((crpt)->INTSTS = (CRPT_INTSTS_HMACIF_Msk|CRPT_INTSTS_HMACEIF_Msk))
331 
332 /**
333   * @brief This macro enables ECC interrupt.
334   * @param crpt     Specified crypto module
335   * @return None
336   * \hideinitializer
337   */
338 #define ECC_ENABLE_INT(crpt)        ((crpt)->INTEN |= (CRPT_INTEN_ECCIEN_Msk|CRPT_INTEN_ECCEIEN_Msk))
339 
340 /**
341   * @brief This macro disables ECC interrupt.
342   * @param crpt     Specified crypto module
343   * @return None
344   * \hideinitializer
345   */
346 #define ECC_DISABLE_INT(crpt)       ((crpt)->INTEN &= ~(CRPT_INTEN_ECCIEN_Msk|CRPT_INTEN_ECCEIEN_Msk))
347 
348 /**
349   * @brief This macro gets ECC interrupt flag.
350   * @param crpt     Specified crypto module
351   * @return ECC interrupt flag.
352   * \hideinitializer
353   */
354 #define ECC_GET_INT_FLAG(crpt)      ((crpt)->INTSTS & (CRPT_INTSTS_ECCIF_Msk|CRPT_INTSTS_ECCEIF_Msk))
355 
356 /**
357   * @brief This macro clears ECC interrupt flag.
358   * @param crpt     Specified crypto module
359   * @return None
360   * \hideinitializer
361   */
362 #define ECC_CLR_INT_FLAG(crpt)      ((crpt)->INTSTS = (CRPT_INTSTS_ECCIF_Msk|CRPT_INTSTS_ECCEIF_Msk))
363 
364 /**
365   * @brief This macro enables RSA interrupt.
366   * @param crpt     Specified crypto module
367   * @return None
368   * \hideinitializer
369   */
370 #define RSA_ENABLE_INT(crpt)        ((crpt)->INTEN |= (CRPT_INTEN_RSAIEN_Msk|CRPT_INTEN_RSAEIEN_Msk))
371 
372 /**
373   * @brief This macro disables RSA interrupt.
374   * @param crpt     Specified crypto module
375   * @return None
376   * \hideinitializer
377   */
378 #define RSA_DISABLE_INT(crpt)       ((crpt)->INTEN &= ~(CRPT_INTEN_RSAIEN_Msk|CRPT_INTEN_RSAEIEN_Msk))
379 
380 /**
381   * @brief This macro gets RSA interrupt flag.
382   * @param crpt     Specified crypto module
383   * @return ECC interrupt flag.
384   * \hideinitializer
385   */
386 #define RSA_GET_INT_FLAG(crpt)      ((crpt)->INTSTS & (CRPT_INTSTS_RSAIF_Msk|CRPT_INTSTS_RSAEIF_Msk))
387 
388 /**
389   * @brief This macro clears RSA interrupt flag.
390   * @param crpt     Specified crypto module
391   * @return None
392   * \hideinitializer
393   */
394 #define RSA_CLR_INT_FLAG(crpt)      ((crpt)->INTSTS = (CRPT_INTSTS_RSAIF_Msk|CRPT_INTSTS_RSAEIF_Msk))
395 
396 
397 /**@}*/ /* end of group CRYPTO_EXPORTED_MACROS */
398 
399 
400 
401 /** @addtogroup CRYPTO_EXPORTED_FUNCTIONS CRYPTO Exported Functions
402   @{
403 */
404 
405 /*---------------------------------------------------------------------------------------------------------*/
406 /*  Functions                                                                                      */
407 /*---------------------------------------------------------------------------------------------------------*/
408 
409 void PRNG_Open(CRPT_T *crpt, uint32_t u32KeySize, uint32_t u32SeedReload, uint32_t u32Seed);
410 int32_t PRNG_Start(CRPT_T *crpt);
411 void PRNG_Read(CRPT_T *crpt, uint32_t u32RandKey[]);
412 void AES_Open(CRPT_T *crpt, uint32_t u32Channel, uint32_t u32EncDec, uint32_t u32OpMode, uint32_t u32KeySize, uint32_t u32SwapType);
413 void AES_Start(CRPT_T *crpt, int32_t u32Channel, uint32_t u32DMAMode);
414 void AES_SetKey(CRPT_T *crpt, uint32_t u32Channel, uint32_t au32Keys[], uint32_t u32KeySize);
415 void AES_SetKey_KS(CRPT_T *crpt, KS_MEM_Type mem, int32_t i32KeyIdx);
416 void AES_SetInitVect(CRPT_T *crpt, uint32_t u32Channel, uint32_t au32IV[]);
417 void AES_SetDMATransfer(CRPT_T *crpt, uint32_t u32Channel, uint32_t u32SrcAddr, uint32_t u32DstAddr, uint32_t u32TransCnt);
418 void SHA_Open(CRPT_T *crpt, uint32_t u32OpMode, uint32_t u32SwapType, uint32_t hmac_key_len);
419 void SHA_Start(CRPT_T *crpt, uint32_t u32DMAMode);
420 void SHA_SetDMATransfer(CRPT_T *crpt, uint32_t u32SrcAddr, uint32_t u32TransCnt);
421 void SHA_Read(CRPT_T *crpt, uint32_t u32Digest[]);
422 void ECC_DriverISR(CRPT_T *crpt);
423 int  ECC_IsPrivateKeyValid(CRPT_T *crpt, E_ECC_CURVE ecc_curve,  char private_k[]);
424 int32_t  ECC_GenerateSecretZ(CRPT_T *crpt, E_ECC_CURVE ecc_curve, char *private_k, char public_k1[], char public_k2[], char secret_z[]);
425 int32_t  ECC_GeneratePublicKey(CRPT_T *crpt, E_ECC_CURVE ecc_curve, char *private_k, char public_k1[], char public_k2[]);
426 int32_t  ECC_GenerateSignature(CRPT_T *crpt, E_ECC_CURVE ecc_curve, char *message, char *d, char *k, char *R, char *S);
427 int32_t  ECC_VerifySignature(CRPT_T *crpt, E_ECC_CURVE ecc_curve, char *message, char *public_k1, char *public_k2, char *R, char *S);
428 
429 
430 int32_t RSA_Open(CRPT_T *crpt, uint32_t u32OpMode, uint32_t u32KeySize, void *psRSA_Buf, uint32_t u32BufSize, uint32_t u32UseKS);
431 int32_t RSA_SetKey(CRPT_T *crpt, char *Key);
432 int32_t RSA_SetDMATransfer(CRPT_T *crpt, char *Src, char *n, char *P, char *Q);
433 void RSA_Start(CRPT_T *crpt);
434 int32_t RSA_Read(CRPT_T *crpt, char * Output);
435 int32_t RSA_SetKey_KS(CRPT_T *crpt, uint32_t u32KeyNum, uint32_t u32KSMemType, uint32_t u32BlindKeyNum);
436 int32_t RSA_SetDMATransfer_KS(CRPT_T *crpt, char *Src, char *n, uint32_t u32PNum,
437                               uint32_t u32QNum, uint32_t u32CpNum, uint32_t u32CqNum, uint32_t u32DpNum,
438                               uint32_t u32DqNum, uint32_t u32RpNum, uint32_t u32RqNum);
439 int32_t  ECC_GeneratePublicKey_KS(CRPT_T *crpt, E_ECC_CURVE ecc_curve, KS_MEM_Type mem, int32_t i32KeyIdx, char public_k1[], char public_k2[], uint32_t u32ExtraOp);
440 int32_t  ECC_GenerateSignature_KS(CRPT_T *crpt, E_ECC_CURVE ecc_curve, char *message, KS_MEM_Type mem_d, int32_t i32KeyIdx_d, KS_MEM_Type mem_k, int32_t i32KeyIdx_k, char *R, char *S);
441 int32_t  ECC_VerifySignature_KS(CRPT_T *crpt, E_ECC_CURVE ecc_curve, char *message, KS_MEM_Type mem_pk1, int32_t i32KeyIdx_pk1, KS_MEM_Type mem_pk2, int32_t i32KeyIdx_pk2, char *R, char *S);
442 int32_t  ECC_GenerateSecretZ_KS(CRPT_T *crpt, E_ECC_CURVE ecc_curve, KS_MEM_Type mem, int32_t i32KeyIdx, char public_k1[], char public_k2[]);
443 
444 void CRPT_Reg2Hex(int32_t count, uint32_t volatile reg[], char output[]);
445 void CRPT_Hex2Reg(char input[], uint32_t volatile reg[]);
446 int32_t ECC_GetCurve(CRPT_T *crpt, E_ECC_CURVE ecc_curve, ECC_CURVE *curve);
447 
448 /**@}*/ /* end of group CRYPTO_EXPORTED_FUNCTIONS */
449 
450 /**@}*/ /* end of group CRYPTO_Driver */
451 
452 /**@}*/ /* end of group Standard_Driver */
453 
454 #ifdef __cplusplus
455 }
456 #endif
457 
458 #endif  /* __CRYPTO_H__ */
459 
460