blob: 379f155e648a9d215926a3b25e7d384bf1cd1ed8 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001
2#ifndef RSA_DRV_H
3#define RSA_DRV_H
4
5#include <common.h>
6
7
8#define SYS_RSA_BASE 0x0121c000
9
10
11/**< offset:000 RW °æ±¾ÐÅÏ¢¼Ä´æÆ÷ */
12/**< offset:004 RW Ä£¿éʹÄܼĴæÆ÷ */
13/**< offset:008 RW Ä£³¤¼Ä´æÆ÷ */
14/**< offset:00C RW Ãݳ¤¼Ä´æÆ÷ */
15/**< offset:010 RW ÖжÏ״̬¼Ä´æÆ÷ */
16/**< offset:014 RW ÖжÏʹÄܼĴæÆ÷ */
17/**< offset:018 RW ÖÐ¶ÏÆÁ±Î¼Ä´æÆ÷ */
18/**< offset:01C RW N0¼Ä´æÆ÷ */
19/**< offset:020 RW N0¡¯¼Ä´æÆ÷ */
20/**< offset:024 RW ¼ÆËãģʽ */
21/**< offset:028 RW ռλ·û */
22/**< offset:100 RW M data RAM¼Ä´æÆ÷0x100~0x1FF */
23/**< offset:200 RW E data RAM¼Ä´æÆ÷0x200~0x2FF */
24/**< offset:300 RW N data RAM¼Ä´æÆ÷0x300~0x3FF */
25/**< offset:400 RW ³õʼ»¯¼ÆËãRAM¼Ä´æÆ÷0x400~0x4FF*/
26/**< offset:500 RW ½á¹ûRAM¼Ä´æÆ÷0x500~0x5FF */
27
28
29#define RSA_REV_INFO (SYS_RSA_BASE)
30#define RSA_MODULE_ENABLE (SYS_RSA_BASE+0x4)
31#define RSA_MODULAR_LENGTH (SYS_RSA_BASE+0x8)
32#define RSA_EXP_LENGTH (SYS_RSA_BASE+0xc)
33#define RSA_INT_STATUS (SYS_RSA_BASE+0x10)
34#define RSA_INT_ENABLE (SYS_RSA_BASE+0x14)
35#define RSA_INT_MASK (SYS_RSA_BASE+0x18)
36#define RSA_NZORE (SYS_RSA_BASE+0x1c)
37#define RSA_NZORE_INV (SYS_RSA_BASE+0x20)
38#define RSA_CALC_MODE (SYS_RSA_BASE+0x24)
39#define RSA_M_RAM (SYS_RSA_BASE+0x100)
40#define RSA_E_RAM (SYS_RSA_BASE+0x200)
41#define RSA_N_RAM (SYS_RSA_BASE+0x300)
42#define RSA_INIT_CALC_RAM (SYS_RSA_BASE+0x400)
43#define RSA_RESULT_RAM (SYS_RSA_BASE+0x500)
44
45//Çý¶¯ÊÇ·ñÖ§³ÖËùÓеÄģʽ£¬ÓÃÓÚ¼ò»¯´úÂëÁ¿
46//#define RSA_CODE_SUPPORT_ALL
47
48#ifdef RSA_CODE_SUPPORT_ALL
49#define RSA_BIG_NUM_MULTIPLE 9 //input M, E, udNbitLen
50#define RSA_INIT_COMPUTE 2 //input N, udNbitLen
51#define RSA_MOD_MULTIPLE_NO_INIT 8 //input M, E, N, C, udNbitLen, udEbitLen
52#define RSA_MOD_EXPO_NO_INIT 4 //input M, E, N, C, udNbitLen, udEbitLen
53#define RSA_MOD_MULTIPLE_WITH_INIT 10 //input M, E, N, udNbitLen, udEbitLen
54#endif
55#define RSA_MOD_EXPO_WITH_INIT 6 //input M, E, N, udNbitLen, udEbitLen
56
57/** RSAÇý¶¯¼ÆËã½Ó¿Ú´«Èë²ÎÊý*/
58typedef struct
59{
60 u32 udCalMode; /**< RSA¼ÆËãģʽ */
61 u32 udNbitLen; /**< Ä£ÊýN µÄλÊý»òÕßM µÄλÊý , ¿ÉÑ¡512, 1024, 1536, 2048 */
62 u32 udEbitLen; /**< ÃÝÊýE µÄλÊý, СÓÚ64 */
63 u32 *pudInputM; /**< ÊäÈëM»º´æÇø --ÏûÏ¢M */
64 u32 *pudInputE; /**< ÊäÈëE»º´æÇø --ÃÝÊýE */
65 u32 *pudInputN; /**< ÊäÈëÄ£»º´æÇø --Ä£ÊýN (Á½ËØÊýµÄ³Ë»ý) */
66 u32 *pudInputC; /**< ÊäÈëÔ¤¼ÆËãÖµ»º´æÇø,µÈÓÚr^2 mod N */
67 u32 *pudOutputP; /**< Êä³ö½á¹û»º´æÇø */
68}T_Rsa_Paramter;
69
70u32 Rsa_Calculate(T_Rsa_Paramter ptInput);
71#endif
72