[Feature][T106]ZXW P56U09 code
Only Configure: Yes
Affected branch: master
Affected module: unknow
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: No
Doc Update: No
Change-Id: I3cbd8b420271eb20c2b40ebe5c78f83059cd42f3
diff --git a/boot/common/src/uboot/drivers/rsa/Makefile b/boot/common/src/uboot/drivers/rsa/Makefile
new file mode 100644
index 0000000..15adb47
--- /dev/null
+++ b/boot/common/src/uboot/drivers/rsa/Makefile
@@ -0,0 +1,47 @@
+#
+# Copyright 2000-2008
+# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
+include $(TOPDIR)/config.mk
+
+LIB := $(obj)libdrv_rsa.o
+
+COBJS-y += drv_rsa.o
+
+COBJS := $(COBJS-y)
+SRCS := $(COBJS:.o=.c)
+OBJS := $(addprefix $(obj),$(COBJS))
+
+all: $(LIB)
+
+$(LIB): $(obj).depend $(OBJS)
+ $(call cmd_link_o_target, $(OBJS))
+
+
+#########################################################################
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+########################################################################
diff --git a/boot/common/src/uboot/drivers/rsa/drv_rsa.c b/boot/common/src/uboot/drivers/rsa/drv_rsa.c
new file mode 100644
index 0000000..702cb53
--- /dev/null
+++ b/boot/common/src/uboot/drivers/rsa/drv_rsa.c
@@ -0,0 +1,469 @@
+
+#include "drv_rsa.h"
+#include <sdio.h>
+
+/* º¯Êý¹¦ÄÜ: ʵÏÖ- N^-1 mod 2^32 µÄËã·¨*/
+static u32 get_N_inv(u32 N0)
+{
+ u32 N_inv=1;
+ u32 i,a,b;
+
+ for(i=1; i<32; i++)
+ {
+ a = 1<<i;
+ b = (N0*N_inv)&((2<<i)-1);
+ if(a<b)
+ {
+ N_inv = N_inv+ a;
+ }
+ }
+
+ return (0xffffffff-N_inv+1);
+}
+
+static void rsa_WriteDataToReg(u32* pudAddr, u32 udReg, u32 Len)
+{
+ u32 udI;
+ for(udI=0;udI<Len;udI++)
+ {
+ //Ä£¿éµÍµØÖ·¼Ä´æÆ÷´æ·ÅµÍµØÖ·Êý¾Ý£¬Êý¾Ý´æ·ÅÊǵ͵ØÖ··Å¸ßλÊý¾Ý
+ REG32(udReg + udI*4) = *(pudAddr+Len-1-udI);
+ }
+}
+
+static void rsa_ReadDataFromReg(u32* pudAddr, u32 udReg, u32 Len)
+{
+ u32 udI;
+ for(udI=0;udI<Len;udI++)
+ {
+ //Ä£¿éµÍµØÖ·¼Ä´æÆ÷´æ·ÅµÍµØÖ·Êý¾Ý£¬Êý¾Ý´æ·ÅÊǵ͵ØÖ··Å¸ßλÊý¾Ý
+ *(pudAddr+Len-1-udI) = REG32(udReg + udI*4);
+ }
+}
+
+#ifdef RSA_CODE_SUPPORT_ALL
+/**-------------------------------------------------------------------------------------------------------------------@n
+ * @brief ´óÊý³Ë·¨¼ÆËã
+ *
+ * ¹¦ÄÜÏêÊö:
+ * - Rsa_BigNumMultipleº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
+ * - ¼ÆËãÁ½¸ö´óÊýÏà³Ë
+ *
+ * ²ÎÊý¸ÅÊö:
+ *
+ *
+ * ·µ »Ø Öµ: ÎÞ
+ *
+ *--------------------------------------------------------------------------------------------------------------------*/
+static u32 rsa_BigNumMultiple(u32 udNbitLen, u32* pudInputM, u32* pudInputE, u32* pudOutputP)
+{
+ u32 Nlen_word, Elen_word;
+ //input M, E, udNbitLen
+ if(udNbitLen>2048||udNbitLen==0\
+ ||pudInputM==NULL||pudInputE==NULL||pudOutputP==NULL)
+ {
+ return 1;
+ }
+
+ REG32(RSA_INT_MASK) = 0; /*unmask interrupt*/
+ REG32(RSA_INT_ENABLE) = 0; /*disable interrupt*/
+ REG32(RSA_CALC_MODE) = RSA_BIG_NUM_MULTIPLE; /* set computemode*/
+
+ //ÅäÖÃM,E µ½RAM¼Ä´æÆ÷ÖÐ
+ Nlen_word = (udNbitLen+31)/32;
+ rsa_WriteDataToReg(pudInputM, RSA_M_RAM, Nlen_word);
+ rsa_WriteDataToReg(pudInputE, RSA_E_RAM, Nlen_word);
+ //ÅäÖÃN µÄbit ³¤¶È
+ REG32(RSA_MODULAR_LENGTH) = udNbitLen-1;/*set modelength, µ¥Î»bit*/
+
+ //enable compute
+ REG32(RSA_MODULE_ENABLE) = 1;
+
+ /*check interrupt status, waiting for calculating finished*/
+ while(!(REG32(RSA_INT_STATUS)& 0x01));
+
+ /* clear the interrupt,input any */
+ REG32(RSA_INT_STATUS) = 1;
+
+ /* read the result */
+ rsa_ReadDataFromReg(pudOutputP, RSA_RESULT_RAM, Nlen_word);
+
+ /*close mode enable*/
+ REG32(RSA_MODULE_ENABLE) = 0;
+
+ return 0;
+
+}
+
+/**-------------------------------------------------------------------------------------------------------------------@n
+ * @brief ³õʼ»¯¼ÆËã
+ *
+ * ¹¦ÄÜÏêÊö:
+ * - Rsa_InitComputeº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
+ * - ³õʼ»¯¼ÆËã c= r*r mod N
+ *
+ * ²ÎÊý¸ÅÊö:
+ *
+ *
+ * ·µ »Ø Öµ: ÎÞ
+ *
+ *--------------------------------------------------------------------------------------------------------------------*/
+static u32 rsa_InitCompute(u32 udNbitLen, u32* pudInputN, u32* pudOutputP)
+{
+ u32 Nlen_word;
+ //input N, udNbitLen
+ if(udNbitLen>2048||udNbitLen==0\
+ ||pudInputN==NULL||pudOutputP==NULL)
+ {
+ return 1;
+ }
+
+ REG32(RSA_INT_MASK) = 0; /*unmask interrupt*/
+ REG32(RSA_INT_ENABLE) = 0; /*disable interrupt*/
+ REG32(RSA_CALC_MODE) = RSA_INIT_COMPUTE; /* set computemode*/
+
+ //ÅäÖÃN µ½RAM¼Ä´æÆ÷ÖÐ
+ Nlen_word = (udNbitLen+31)/32;
+ rsa_WriteDataToReg(pudInputN, RSA_N_RAM, Nlen_word);
+
+ //ÅäÖÃN µÄbit ³¤¶È
+ if((pudInputN[0]&0x80000000) == 0)
+ {
+ REG32(RSA_MODULAR_LENGTH) = udNbitLen-2;/*set modelength, µ¥Î»bit*/
+ }
+ else
+ {
+ REG32(RSA_MODULAR_LENGTH) = udNbitLen-1;/*set modelength, µ¥Î»bit*/
+ }
+
+ //enable compute
+ REG32(RSA_MODULE_ENABLE) = 1;
+
+ /*check interrupt status, waiting for calculating finished*/
+ while(!(REG32(RSA_INT_STATUS)& 0x01));
+
+ /* clear the interrupt,input any */
+ REG32(RSA_INT_STATUS) = 1;
+
+ /* read the result */
+ rsa_ReadDataFromReg(pudOutputP, RSA_INIT_CALC_RAM, Nlen_word);
+
+ /*close mode enable*/
+ REG32(RSA_MODULE_ENABLE) = 0;
+
+ return 0;
+
+}
+
+/**-------------------------------------------------------------------------------------------------------------------@n
+ * @brief ²»´ø³õʼ»¯¼ÆËãµÄÄ£³Ë
+ *
+ * ¹¦ÄÜÏêÊö:
+ * - Rsa_ModMultipleNoInitº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
+ * - ÔÚÄ£³ËÖУ¬²»½øÐгõʼ»¯¼ÆËã
+ *
+ * ²ÎÊý¸ÅÊö:
+ *
+ *
+ * ·µ »Ø Öµ: ÎÞ
+ *
+ *--------------------------------------------------------------------------------------------------------------------*/
+static void rsa_ModMultipleNoInit(u32 udNbitLen, u32 udEbitLen, u32* pudInputM, u32* pudInputE, u32* pudInputN, u32* pudInputC, u32* pudOutputP)
+{
+ u32 Nlen_word, Elen_word;
+ //input M, E, N, C, udNbitLen, udEbitLen
+ if(udNbitLen>2048||udNbitLen==0||udEbitLen>2048||udEbitLen==0\
+ ||pudInputM==NULL||pudInputE==NULL||pudInputN==NULL||pudInputC==NULL||pudOutputP==NULL)
+ {
+ return 1;
+ }
+
+ REG32(RSA_INT_MASK) = 0; /*unmask interrupt*/
+ REG32(RSA_INT_ENABLE) = 0; /*disable interrupt*/
+ REG32(RSA_CALC_MODE) = RSA_MOD_MULTIPLE_NO_INIT; /* set computemode*/
+
+ Nlen_word = (udNbitLen+31)/32;
+ Elen_word = (udEbitLen+31)/32;
+
+ //ÉèÖòÎÊýN0, µÈÓÚ²ÎÊýN µÄ×îµÍλ
+ REG32(RSA_NZORE) = pudInputN[Nlen_word-1];
+ // ÉèÖòÎÊýN0' , µÈÓÚ- N^-1 mod 2^32
+ REG32(RSA_NZORE_INV) = get_N_inv(pudInputN[Nlen_word-1]);
+
+ //ÅäÖÃM,E,N µ½RAM¼Ä´æÆ÷ÖÐ
+ rsa_WriteDataToReg(pudInputM, RSA_M_RAM, Nlen_word);
+ rsa_WriteDataToReg(pudInputE, RSA_E_RAM, Elen_word);
+ rsa_WriteDataToReg(pudInputN, RSA_N_RAM, Nlen_word);
+ rsa_WriteDataToReg(pudInputC, RSA_INIT_CALC_RAM, Nlen_word);
+
+ //ÅäÖÃN,E µÄbit ³¤¶È
+ if((pudInputN[0]&0x80000000) == 0)
+ {
+ REG32(RSA_MODULAR_LENGTH) = udNbitLen-2;/*set modelength, µ¥Î»bit*/
+ }
+ else
+ {
+ REG32(RSA_MODULAR_LENGTH) = udNbitLen-1;/*set modelength, µ¥Î»bit*/
+ }
+ REG32(RSA_EXP_LENGTH) = (Elen_word-1)<<5; /*set expolength, µ¥Î»word*/
+
+ //enable compute
+ REG32(RSA_MODULE_ENABLE) = 1;
+
+ /*check interrupt status, waiting for calculating finished*/
+ while(!(REG32(RSA_INT_STATUS)& 0x01));
+
+ /* clear the interrupt,input any */
+ REG32(RSA_INT_STATUS) = 1;
+
+ /* read the result */
+ rsa_ReadDataFromReg(pudOutputP, RSA_RESULT_RAM, Nlen_word);
+
+ /*close mode enable*/
+ REG32(RSA_MODULE_ENABLE) = 0;
+
+ return 0;
+}
+
+/**-------------------------------------------------------------------------------------------------------------------@n
+ * @brief ´ø³õʼ»¯¼ÆËãµÄÄ£³Ë
+ *
+ * ¹¦ÄÜÏêÊö:
+ * - Rsa_ModMultipleWithInitº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
+ * - ÔÚÄ£³ËÖУ¬½øÐгõʼ»¯¼ÆËã
+ *
+ * ²ÎÊý¸ÅÊö:
+ *
+ *
+ * ·µ »Ø Öµ: ÎÞ
+ *
+ *--------------------------------------------------------------------------------------------------------------------*/
+static u32 rsa_ModMultipleWithInit(u32 udNbitLen, u32 udEbitLen, u32* pudInputM, u32* pudInputE, u32* pudInputN, u32* pudOutputP)
+{
+ u32 Nlen_word, Elen_word;
+ //input M, E, N, udNbitLen, udEbitLen
+ if(udNbitLen>2048||udNbitLen==0||udEbitLen>2048||udEbitLen==0\
+ ||pudInputM==NULL||pudInputE==NULL||pudInputN==NULL||pudOutputP==NULL)
+ {
+ return 1;
+ }
+
+ REG32(RSA_INT_MASK) = 0; /*unmask interrupt*/
+ REG32(RSA_INT_ENABLE) = 0; /*disable interrupt*/
+ REG32(RSA_CALC_MODE) = RSA_MOD_MULTIPLE_WITH_INIT; /* set computemode*/
+
+ Nlen_word = (udNbitLen+31)/32;
+ Elen_word = (udEbitLen+31)/32;
+
+ //ÉèÖòÎÊýN0, µÈÓÚ²ÎÊýN µÄ×îµÍλ
+ REG32(RSA_NZORE) = pudInputN[Nlen_word-1];
+ // ÉèÖòÎÊýN0' , µÈÓÚ- N^-1 mod 2^32
+ REG32(RSA_NZORE_INV) = get_N_inv(pudInputN[Nlen_word-1]);
+
+ //ÅäÖÃM,E,N µ½RAM¼Ä´æÆ÷ÖÐ
+ rsa_WriteDataToReg(pudInputM, RSA_M_RAM, Nlen_word);
+ rsa_WriteDataToReg(pudInputE, RSA_E_RAM, Elen_word);
+ rsa_WriteDataToReg(pudInputN, RSA_N_RAM, Nlen_word);
+
+ //ÅäÖÃN,E µÄbit ³¤¶È
+ if((pudInputN[0]&0x80000000) == 0)
+ {
+ REG32(RSA_MODULAR_LENGTH) = udNbitLen-2;/*set modelength, µ¥Î»bit*/
+ }
+ else
+ {
+ REG32(RSA_MODULAR_LENGTH) = udNbitLen-1;/*set modelength, µ¥Î»bit*/
+ }
+ REG32(RSA_EXP_LENGTH) = (Elen_word-1)<<5; /*set expolength, µ¥Î»word*/
+
+ //enable compute
+ REG32(RSA_MODULE_ENABLE) = 1;
+
+ /*check interrupt status, waiting for calculating finished*/
+ while(!(REG32(RSA_INT_STATUS)& 0x01));
+
+ /* clear the interrupt,input any */
+ REG32(RSA_INT_STATUS) = 1;
+
+ /* read the result */
+ rsa_ReadDataFromReg(pudOutputP, RSA_RESULT_RAM, Nlen_word);
+
+ /*close mode enable*/
+ REG32(RSA_MODULE_ENABLE) = 0;
+
+ return 0;
+}
+
+
+/**-------------------------------------------------------------------------------------------------------------------@n
+ * @brief ²»´ø³õʼ»¯¼ÆËãµÄÄ£ÃÝÔËËã
+ *
+ * ¹¦ÄÜÏêÊö:
+ * - Rsa_ModExpoNoInitº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
+ * - ÔÚÄ£ÃÝÔËËãÖУ¬²»½øÐгõʼ»¯¼ÆËã
+ *
+ * ²ÎÊý¸ÅÊö:
+ *
+ *
+ * ·µ »Ø Öµ: ÎÞ
+ *
+ *--------------------------------------------------------------------------------------------------------------------*/
+static u32 rsa_ModExpoNoInit(u32 udNbitLen, u32 udEbitLen, u32* pudInputM, u32* pudInputE, u32* pudInputN, u32* pudInputC, u32* pudOutputP)
+{
+ u32 Nlen_word, Elen_word;
+ //input M, E, N, C, udNbitLen, udEbitLen
+ if(udNbitLen>2048||udNbitLen==0||udEbitLen>2048||udEbitLen==0\
+ ||pudInputM==NULL||pudInputE==NULL||pudInputN==NULL||pudInputC==NULL||pudOutputP==NULL)
+ {
+ return 1;
+ }
+
+ REG32(RSA_INT_MASK) = 0; /*unmask interrupt*/
+ REG32(RSA_INT_ENABLE) = 0; /*disable interrupt*/
+ REG32(RSA_CALC_MODE) = RSA_MOD_EXPO_NO_INIT; /* set computemode*/
+
+ Nlen_word = (udNbitLen+31)/32;
+ Elen_word = (udEbitLen+31)/32;
+
+ //ÉèÖòÎÊýN0, µÈÓÚ²ÎÊýN µÄ×îµÍλ
+ REG32(RSA_NZORE) = pudInputN[Nlen_word-1];
+ // ÉèÖòÎÊýN0' , µÈÓÚ- N^-1 mod 2^32
+ REG32(RSA_NZORE_INV) = get_N_inv(pudInputN[Nlen_word-1]);
+
+ //ÅäÖÃM,E,N µ½RAM¼Ä´æÆ÷ÖÐ
+ rsa_WriteDataToReg(pudInputM, RSA_M_RAM, Nlen_word);
+ rsa_WriteDataToReg(pudInputE, RSA_E_RAM, Elen_word);
+ rsa_WriteDataToReg(pudInputN, RSA_N_RAM, Nlen_word);
+ rsa_WriteDataToReg(pudInputC, RSA_INIT_CALC_RAM, Nlen_word);
+
+ //ÅäÖÃN,E µÄbit ³¤¶È
+ if((pudInputN[0]&0x80000000) == 0)
+ {
+ REG32(RSA_MODULAR_LENGTH) = udNbitLen-2;/*set modelength, µ¥Î»bit*/
+ }
+ else
+ {
+ REG32(RSA_MODULAR_LENGTH) = udNbitLen-1;/*set modelength, µ¥Î»bit*/
+ }
+ REG32(RSA_EXP_LENGTH) = (Elen_word-1)<<5; /*set expolength, µ¥Î»word*/
+
+ //enable compute
+ REG32(RSA_MODULE_ENABLE) = 1;
+
+ /*check interrupt status, waiting for calculating finished*/
+ while(!(REG32(RSA_INT_STATUS)& 0x01));
+
+ /* clear the interrupt,input any */
+ REG32(RSA_INT_STATUS) = 1;
+
+ /* read the result */
+ rsa_ReadDataFromReg(pudOutputP, RSA_RESULT_RAM, Nlen_word);
+
+ /*close mode enable*/
+ REG32(RSA_MODULE_ENABLE) = 0;
+
+ return 0;
+}
+#endif
+
+/**-------------------------------------------------------------------------------------------------------------------@n
+ * @brief ´ø³õʼ»¯¼ÆËãµÄÄ£ÃÝÔËËã
+ *
+ * ¹¦ÄÜÏêÊö:
+ * - Rsa_ModExpoWithInitº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
+ * - ÔÚÄ£ÃÝÔËËãÖУ¬½øÐгõʼ»¯¼ÆËã
+ *
+ * ²ÎÊý¸ÅÊö:
+ *
+ *
+ * ·µ »Ø Öµ: ÎÞ
+ *
+ *--------------------------------------------------------------------------------------------------------------------*/
+static u32 rsa_ModExpoWithInit(u32 udNbitLen, u32 udEbitLen, u32* pudInputM, u32* pudInputE, u32* pudInputN, u32* pudOutputP)
+{
+ u32 Nlen_word, Elen_word;
+ //input M, E, N, udNbitLen, udEbitLen
+ if(udNbitLen>2048 || udNbitLen==0 || udEbitLen>2048 || udEbitLen==0\
+ || pudInputM==NULL || pudInputE==NULL || pudInputN==NULL || pudOutputP==NULL)
+ {
+ return 1;
+ }
+
+ REG32(RSA_INT_MASK) = 0; /*unmask interrupt*/
+ REG32(RSA_INT_ENABLE) = 0; /*disable interrupt*/
+ REG32(RSA_CALC_MODE) = RSA_MOD_EXPO_WITH_INIT; /* set computemode*/
+
+ Nlen_word = (udNbitLen+31)/32;
+ Elen_word = (udEbitLen+31)/32;
+
+ //ÉèÖòÎÊýN0, µÈÓÚ²ÎÊýN µÄ×îµÍλ
+ REG32(RSA_NZORE) = pudInputN[Nlen_word-1];
+ // ÉèÖòÎÊýN0' , µÈÓÚ- N^-1 mod 2^32
+ REG32(RSA_NZORE_INV) = get_N_inv(pudInputN[Nlen_word-1]);
+
+ //ÅäÖÃM,E,N µ½RAM¼Ä´æÆ÷ÖÐ
+ rsa_WriteDataToReg(pudInputM, RSA_M_RAM, Nlen_word);
+ rsa_WriteDataToReg(pudInputE, RSA_E_RAM, Elen_word);
+ rsa_WriteDataToReg(pudInputN, RSA_N_RAM, Nlen_word);
+
+ //ÅäÖÃN,E µÄbit ³¤¶È
+ if((pudInputN[0] & 0x80000000) == 0)
+ {
+ REG32(RSA_MODULAR_LENGTH) = udNbitLen - 2;/*set modelength, µ¥Î»bit*/
+ }
+ else
+ {
+ REG32(RSA_MODULAR_LENGTH) = udNbitLen - 1;/*set modelength, µ¥Î»bit*/
+ }
+ REG32(RSA_EXP_LENGTH) = (Elen_word - 1) << 5; /*set expolength, µ¥Î»word*/
+
+ //enable compute
+ REG32(RSA_MODULE_ENABLE) = 1;
+
+ /*check interrupt status, waiting for calculating finished*/
+ while(!(REG32(RSA_INT_STATUS) & 0x01));
+
+ /* clear the interrupt,input any */
+ REG32(RSA_INT_STATUS) = 1;
+
+ /* read the result */
+ rsa_ReadDataFromReg(pudOutputP, RSA_RESULT_RAM, Nlen_word);
+
+ /*close mode enable*/
+ REG32(RSA_MODULE_ENABLE) = 0;
+
+ return 0;
+}
+/*
+¹¦ÄÜÏêÊö:RSA ¸÷ÖÖ¼ÆËãµÄ½Ó¿Úº¯Êý
+¸÷²ÎÊý:
+ ptInput Ïê¼û½á¹¹Ìå˵Ã÷
+*/
+u32 Rsa_Calculate(T_Rsa_Paramter ptInput)
+{
+ switch(ptInput.udCalMode)
+ {
+#ifdef RSA_CODE_SUPPORT_ALL
+ case RSA_BIG_NUM_MULTIPLE: //input M, E, udNbitLen
+ return rsa_BigNumMultiple(ptInput.udNbitLen, ptInput.pudInputM, ptInput.pudInputE, ptInput.pudOutputP);
+
+ case RSA_INIT_COMPUTE: //input N, udNbitLen
+ return rsa_InitCompute(ptInput.udNbitLen, ptInput.pudInputN, ptInput.pudOutputP);
+
+ case RSA_MOD_MULTIPLE_NO_INIT: //input M, E, N, C, udNbitLen, udEbitLen
+ return rsa_ModMultipleNoInit(ptInput.udNbitLen, ptInput.udEbitLen, ptInput.pudInputM, ptInput.pudInputE, ptInput.pudInputN, ptInput.pudInputC, ptInput.pudOutputP);
+
+ case RSA_MOD_EXPO_NO_INIT: //input M, E, N, C, udNbitLen, udEbitLen
+ return rsa_ModExpoNoInit(ptInput.udNbitLen, ptInput.udEbitLen, ptInput.pudInputM, ptInput.pudInputE, ptInput.pudInputN, ptInput.pudInputC, ptInput.pudOutputP);
+
+ case RSA_MOD_MULTIPLE_WITH_INIT: //input M, E, N, udNbitLen, udEbitLen
+ return rsa_ModMultipleWithInit(ptInput.udNbitLen, ptInput.udEbitLen, ptInput.pudInputM, ptInput.pudInputE, ptInput.pudInputN, ptInput.pudOutputP);
+#endif
+ case RSA_MOD_EXPO_WITH_INIT: //input M, E, N, udNbitLen, udEbitLen
+ return rsa_ModExpoWithInit(ptInput.udNbitLen, ptInput.udEbitLen, ptInput.pudInputM, ptInput.pudInputE, ptInput.pudInputN, ptInput.pudOutputP);
+
+ default:
+ return 1;
+ }
+}
+
diff --git a/boot/common/src/uboot/drivers/rsa/drv_rsa.h b/boot/common/src/uboot/drivers/rsa/drv_rsa.h
new file mode 100644
index 0000000..fa41dbf
--- /dev/null
+++ b/boot/common/src/uboot/drivers/rsa/drv_rsa.h
@@ -0,0 +1,68 @@
+
+#ifndef RSA_DRV_H
+#define RSA_DRV_H
+
+/**< offset:000 RW °æ±¾ÐÅÏ¢¼Ä´æÆ÷ */
+/**< offset:004 RW Ä£¿éʹÄܼĴæÆ÷ */
+/**< offset:008 RW Ä£³¤¼Ä´æÆ÷ */
+/**< offset:00C RW Ãݳ¤¼Ä´æÆ÷ */
+/**< offset:010 RW ÖжÏ״̬¼Ä´æÆ÷ */
+/**< offset:014 RW ÖжÏʹÄܼĴæÆ÷ */
+/**< offset:018 RW ÖÐ¶ÏÆÁ±Î¼Ä´æÆ÷ */
+/**< offset:01C RW N0¼Ä´æÆ÷ */
+/**< offset:020 RW N0¡¯¼Ä´æÆ÷ */
+/**< offset:024 RW ¼ÆËãģʽ */
+/**< offset:028 RW ռλ·û */
+/**< offset:100 RW M data RAM¼Ä´æÆ÷0x100~0x1FF */
+/**< offset:200 RW E data RAM¼Ä´æÆ÷0x200~0x2FF */
+/**< offset:300 RW N data RAM¼Ä´æÆ÷0x300~0x3FF */
+/**< offset:400 RW ³õʼ»¯¼ÆËãRAM¼Ä´æÆ÷0x400~0x4FF*/
+/**< offset:500 RW ½á¹ûRAM¼Ä´æÆ÷0x500~0x5FF */
+
+#include <common.h>
+#include <secure_verify.h>
+
+#define RSA_REV_INFO (SYS_RSA_BASE)
+#define RSA_MODULE_ENABLE (SYS_RSA_BASE+0x4)
+#define RSA_MODULAR_LENGTH (SYS_RSA_BASE+0x8)
+#define RSA_EXP_LENGTH (SYS_RSA_BASE+0xc)
+#define RSA_INT_STATUS (SYS_RSA_BASE+0x10)
+#define RSA_INT_ENABLE (SYS_RSA_BASE+0x14)
+#define RSA_INT_MASK (SYS_RSA_BASE+0x18)
+#define RSA_NZORE (SYS_RSA_BASE+0x1c)
+#define RSA_NZORE_INV (SYS_RSA_BASE+0x20)
+#define RSA_CALC_MODE (SYS_RSA_BASE+0x24)
+#define RSA_M_RAM (SYS_RSA_BASE+0x100)
+#define RSA_E_RAM (SYS_RSA_BASE+0x200)
+#define RSA_N_RAM (SYS_RSA_BASE+0x300)
+#define RSA_INIT_CALC_RAM (SYS_RSA_BASE+0x400)
+#define RSA_RESULT_RAM (SYS_RSA_BASE+0x500)
+
+//Çý¶¯ÊÇ·ñÖ§³ÖËùÓеÄģʽ£¬ÓÃÓÚ¼ò»¯´úÂëÁ¿
+//#define RSA_CODE_SUPPORT_ALL
+
+#ifdef RSA_CODE_SUPPORT_ALL
+#define RSA_BIG_NUM_MULTIPLE 9 //input M, E, udNbitLen
+#define RSA_INIT_COMPUTE 2 //input N, udNbitLen
+#define RSA_MOD_MULTIPLE_NO_INIT 8 //input M, E, N, C, udNbitLen, udEbitLen
+#define RSA_MOD_EXPO_NO_INIT 4 //input M, E, N, C, udNbitLen, udEbitLen
+#define RSA_MOD_MULTIPLE_WITH_INIT 10 //input M, E, N, udNbitLen, udEbitLen
+#endif
+#define RSA_MOD_EXPO_WITH_INIT 6 //input M, E, N, udNbitLen, udEbitLen
+
+/** RSAÇý¶¯¼ÆËã½Ó¿Ú´«Èë²ÎÊý*/
+typedef struct
+{
+ u32 udCalMode; /**< RSA¼ÆËãģʽ */
+ u32 udNbitLen; /**< Ä£ÊýN µÄλÊý»òÕßM µÄλÊý , ¿ÉÑ¡512, 1024, 1536, 2048 */
+ u32 udEbitLen; /**< ÃÝÊýE µÄλÊý, СÓÚ64 */
+ u32 *pudInputM; /**< ÊäÈëM»º´æÇø --ÏûÏ¢M */
+ u32 *pudInputE; /**< ÊäÈëE»º´æÇø --ÃÝÊýE */
+ u32 *pudInputN; /**< ÊäÈëÄ£»º´æÇø --Ä£ÊýN (Á½ËØÊýµÄ³Ë»ý) */
+ u32 *pudInputC; /**< ÊäÈëÔ¤¼ÆËãÖµ»º´æÇø,µÈÓÚr^2 mod N */
+ u32 *pudOutputP; /**< Êä³ö½á¹û»º´æÇø */
+}T_Rsa_Paramter;
+
+u32 Rsa_Calculate(T_Rsa_Paramter ptInput);
+#endif
+