Index: yc_7816/yc_7816.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_7816/yc_7816.h	(revision 569)
+++ /YC3121_SDK/fw/sdk/yc_7816/yc_7816.h	(working copy)
@@ -9,10 +9,11 @@
 #ifndef __YC_ISO7816_H__
 #define __YC_ISO7816_H__
 
-#include "..\..\core\yc3121.h"
+#include "yc3121.h"
+#include "yc_gpio.h"
 
-//#define DEBUG_7816_EMV
-//#define DEBUG_7816
+#define DEBUG_7816_EMV
+#define DEBUG_7816
 
 
 typedef struct 
@@ -27,7 +28,7 @@
 	GPIO_DEF io;
 	GPIO_DEF reset;
 	GPIO_DEF detect;
-	uint8_t detect_state;		//未插卡时，卡到位IO电平状态，高为1、低为0
+	uint8_t detect_state;		//鏈彃鍗℃椂锛屽崱鍒颁綅IO鐢靛钩鐘舵侊紝楂樹负1銆佷綆涓0
 }SCI_PIN_Def;
 
 extern SCI_PIN_Def sci_pin;
@@ -40,9 +41,10 @@
 #define 	CONTACT_CLK		    4
 #define 	SYS_CLK			    48
 
-#define 	CONTACT_RESET_L_CNT				42000*SYS_CLK/CONTACT_CLK	//(40000-45000) 复位引脚保持低电平持续时间
-#define 	CONTACT_ATR_RFB_TIME_CNT		47000*SYS_CLK/CONTACT_CLK	//42019(400-40000)	等待IC回应第一个ATR字节的最大时间
-#define 	CONTACT_ATR_RAB_TIME_CNT		(20164*SYS_CLK/CONTACT_CLK)*372	//19200etu内复位信息应答完成(TS - LAST)
+#define 	CONTACT_RESET_L_CNT				42000*SYS_CLK/CONTACT_CLK          //(40000-45000) 澶嶄綅寮曡剼淇濇寔浣庣數骞虫寔缁椂闂
+#define 	CONTACT_ATR_RFB_TIME_CNT		47000*SYS_CLK/CONTACT_CLK	       //42019(400-40000)	绛夊緟IC鍥炲簲绗竴涓狝TR瀛楄妭鐨勬渶澶ф椂闂
+#define 	CONTACT_ATR_RAB_TIME_CNT		(20164*SYS_CLK/CONTACT_CLK)*372  //19200etu鍐呭浣嶄俊鎭簲绛斿畬鎴(TS - LAST)
+
 
 #define 	ATR_SIZE_MAX                0x33
 #define	 	REC_SIZE_MAX                0x107 //5+256+2
@@ -52,7 +54,7 @@
 #define 	PROTOCOL_T0                 0
 #define 	PROTOCOL_T1                 1
 
-//错误码定义
+//閿欒鐮佸畾涔
 #define 	OK                          0
 #define 	NOK                         1
 
@@ -124,37 +126,37 @@
 #define     GET_4_BITS_H(a)            (((a) >>4)& 0x0F)
 #define     GET_4_BITS_L(a)            ((a)& 0x0F)
 
-#define  R_BLK                                 0x80      /*R-BLK的高2位*/
-#define  S_BLK                                 0xC0      /*S-BLK的高2位*/
-#define  S_RQS_MSK                             0x3F      /*S-BLK request  低6位mask*/
-#define  S_RSP_MSK                             0x23      /*S-BLK response 低6位mask*/
-#define  IFSC                                  0xFE      /*信息域size*/
-#define  HALF_FIFO                             8         /*半空*/
-#define  M_BIT                                 0x20      /*表示chain状态*/
-#define  NS_BIT                                0x40      /*I-BLK序列号位*/
-#define  NR_BIT                                0x10      /*R-BLK序列号位*/
-
-#define  ERR_PARITY                            1         /*奇偶校验错*/
-#define  ERR_CHKSUM                            2         /*校验出错*/
-#define  ERR_PCB                               4         /*协议控制字节错*/
-#define  ERR_LEN                               8         /*长度字节错*/
-#define  ERR_RELVNT_S                          16        /*有S request, 无s response*/
-#define  ERR_FF								   32		/*接收到数据长度为FF*/
-/*7816发送接收*/
+#define  R_BLK                                 0x80       /*R-BLK鐨勯珮2浣*/
+#define  S_BLK                                 0xC0      /*S-BLK鐨勯珮2浣*/
+#define  S_RQS_MSK                             0x3F      /*S-BLK request  浣6浣峬ask*/
+#define  S_RSP_MSK                             0x23      /*S-BLK response 浣6浣峬ask*/
+#define  IFSC                                  0xFE      /*淇℃伅鍩焥ize*/
+#define  HALF_FIFO                             8         /*鍗婄┖*/
+#define  M_BIT                                 0x20      /*琛ㄧずchain鐘舵*/
+#define  NS_BIT                                0x40      /*I-BLK搴忓垪鍙蜂綅*/
+#define  NR_BIT                                0x10      /*R-BLK搴忓垪鍙蜂綅*/
+
+#define  ERR_PARITY                            1         /*濂囧伓鏍￠獙閿*/
+#define  ERR_CHKSUM                            2         /*鏍￠獙鍑洪敊*/
+#define  ERR_PCB                               4         /*鍗忚鎺у埗瀛楄妭閿*/
+#define  ERR_LEN                               8         /*闀垮害瀛楄妭閿*/
+#define  ERR_RELVNT_S                          16        /*鏈塖 request, 鏃爏 response*/
+#define  ERR_FF								                 32		/*鎺ユ敹鍒版暟鎹暱搴︿负FF*/
+/*7816鍙戦佹帴鏀*/
 #define RECV                                  1
 #define SEND                                  0
 #define I_BLOCK                                 0
 #define R_BLOCK                                 1
 #define S_BLOCK                                 2
-#define T_S_IFS                                 2          /*调整信息域的S-BLK*/
-#define T_S_ABORT                               3          /*打断CHAIN的S-BLK*/
-#define T_S_WTS                                 4          /*请求延长等待时的S-BLK*/
+#define T_S_IFS                                 2          /*璋冩暣淇℃伅鍩熺殑S-BLK*/
+#define T_S_ABORT                               3          /*鎵撴柇CHAIN鐨凷-BLK*/
+#define T_S_WTS                                 4          /*璇锋眰寤堕暱绛夊緟鏃剁殑S-BLK*/
 														   
-#define T1_HEAD_LEN                             3		   /*帧头长度*/
-#define ERR_SEND_CNT                            3		   /*错误重发次数*/
+#define T1_HEAD_LEN                             3		   /*甯уご闀垮害*/
+#define ERR_SEND_CNT                            3		   /*閿欒閲嶅彂娆℃暟*/
 
 
-//相关全局变量参数
+//鐩稿叧鍏ㄥ眬鍙橀噺鍙傛暟
 typedef struct
 {
     uint8_t   bIFSC;
@@ -174,22 +176,22 @@
 	uint8_t 	aRBlk[5];
 }st_T1_Parameters;
 
-//ATR等7816需要用的参数
+//ATR绛7816闇瑕佺敤鐨勫弬鏁
 typedef struct
 {
 	uint8_t bFlag;
-	uint8_t bTA1;		 						//TA1的值
-	uint8_t bTA2;								//TA2的值
-	uint8_t bTA2Flag;							//TA2是否存在标志
-	uint8_t bProlType;						//协议类型标志 0为T0  1为T1
-	uint8_t aAtr[ATR_SIZE_MAX];				//ATR缓存区
-    uint8_t aRecBuff[REC_SIZE_MAX];			//接收数据缓存区
+	uint8_t bTA1;		 						//TA1鐨勫
+	uint8_t bTA2;								//TA2鐨勫
+	uint8_t bTA2Flag;							//TA2鏄惁瀛樺湪鏍囧織
+	uint8_t bProlType;						//鍗忚绫诲瀷鏍囧織 0涓篢0  1涓篢1
+	uint8_t aAtr[ATR_SIZE_MAX];				//ATR缂撳瓨鍖
+    uint8_t aRecBuff[REC_SIZE_MAX];			//鎺ユ敹鏁版嵁缂撳瓨鍖
 }st_7816_Para;
 
 
-//跟T1有关的参数
+//璺烼1鏈夊叧鐨勫弬鏁
 extern st_T1_Parameters g_T1;
-//跟7816协议参数有关的参数
+//璺7816鍗忚鍙傛暟鏈夊叧鐨勫弬鏁
 extern st_7816_Para g_7816Para;
 
 extern unsigned int terminal_send_cwt;
@@ -203,8 +205,21 @@
 extern unsigned int terminal_rec_bwt_atr;
 extern unsigned int terminal_change_rec_bwt_num;
 
-uint16_t ISO7816_LoopBack(void);
+void atr_time_start(void);
+uint16_t ISO7816_OperateSelect(uint8_t OperateMode);
+uint16_t ISO7816_GetAtr(uint8_t *pAtr, uint8_t *pLength);
+void iso7816_deactive(void);
+uint16_t ISO7816_DisposeATR(uint8_t *pATR, uint8_t ATRLen);
+void ISO7816_config_mode_fun(void);
+uint16_t ISO7816_DisposePPS(uint8_t TA1);
+uint16_t ISO7816_TPDU_T1Send(uint8_t *pCommand, uint16_t CommandLength, uint8_t Type);
+uint16_t ISO7816_Dispose_CMD(uint8_t *pCmd, uint16_t CmdLen, uint8_t *pResp,  uint16_t *pRespLen);
+//state 0-vcard off  1-3.3 vcard   2-1.8 vcard
+void ISO7816_cold_reset(uint8_t state);
+void ISO7816_warm_reset(void);
+//鍗℃娴
 uint8_t detect_io_state(void);
+uint16_t ISO7816_LoopBack(void);
 
 #endif	/* __YC_ISO7816_H__ */
 
Index: yc_7816/yc_7816.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_7816/yc_7816.c	(revision 569)
+++ /YC3121_SDK/fw/sdk/yc_7816/yc_7816.c	(working copy)
@@ -9,9 +9,9 @@
 #include"string.h"
 
 #include "yc_7816.h"
-#include"..\..\core\system.h"
-#include "..\yc_timer.h"
-#include "..\yc_exti.h"
+#include "system.h"
+#include "yc_timer.h"
+#include "yc_exti.h"
 #include "yc_7816_T1.h"
 #include "yc_7816_T0.h"
 
@@ -68,7 +68,7 @@
 
 uint8_t detect_io_state(void)
 {
-	return GPIO_ReadInputDataBit(sci_pin.detect.gpio_group, sci_pin.detect.gpio_pin);
+	return GPIO_ReadInputDataBit((GPIO_TypeDef)sci_pin.detect.gpio_group, sci_pin.detect.gpio_pin);
 }
 
 unsigned char crad_in_io_filter(void)
@@ -127,9 +127,9 @@
 	enable_clock(CLKCLS_TIM);
 	
 	TIM_struct.period=num;
-	TIM_struct.TIMx=0;
+	TIM_struct.TIMx=(TIM_NumTypeDef)0;
 	TIM_Init(&TIM_struct);
-	TIM_Cmd(0,ENABLE);
+	TIM_Cmd((TIM_NumTypeDef)0,ENABLE);
 }
 
 void atr_time_start(void)
@@ -210,7 +210,7 @@
 	return OK;
 }
 
-void ISO7816_cold_reset(void)
+void ISO7816_cold_reset(uint8_t state)
 {
 	PWM_InitTypeDef PWM_struct;
 	uint32_t period;
@@ -252,7 +252,7 @@
 	vcard_control(ISO7816_VCC_0V);
 
 	//enable power
-	vcard_control(ISO7816_VCC_3_3V);
+	vcard_control(state);
 
 	//enable clk
 	period=5;	//clk 4mhz 2
@@ -868,7 +868,7 @@
                 return ISO7816_CARD_STUTES_ERROR;
             }
 			
-            ISO7816_cold_reset();
+            ISO7816_cold_reset(1);
 
             //表示冷复位
             g_7816Para.bFlag &= (~BIT1);
@@ -1251,7 +1251,5 @@
 
     memcpy(ApduCmd,SELECT_PSE,20);
     SendLen= 20;
-    goto TOSendCMD ;
-    
+    goto TOSendCMD ;    
 }
-
Index: yc_7816/yc_7816_T0.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_7816/yc_7816_T0.c	(revision 569)
+++ /YC3121_SDK/fw/sdk/yc_7816/yc_7816_T0.c	(working copy)
@@ -1,7 +1,7 @@
-#include"string.h"
-#include "..\..\core\yc3121.h"
+#include "string.h"
+#include "yc3121.h"
 #include "yc_7816.h"
-
+#include "yc_timer.h"
 
 uint16_t ISO7816_RecBytes(uint8_t *RxBuf, uint16_t RxLen)
 {
Index: yc_7816/yc_7816_T1.c
===================================================================
--- /YC3121_SDK/fw/sdk/yc_7816/yc_7816_T1.c	(revision 569)
+++ /YC3121_SDK/fw/sdk/yc_7816/yc_7816_T1.c	(working copy)
@@ -1,8 +1,8 @@
-#include"string.h"
-#include "..\..\core\yc3121.h"
+#include "string.h"
+#include "yc3121.h"
 #include "yc_7816.h"
 #include "yc_7816_t0.h"
-
+#include "yc_timer.h"
 
 uint16_t ISO7816_CalcLRC(uint8_t *pBuff, uint16_t I_Len, uint8_t *pLRC)
 {
Index: yc_crypt/Yc_aes.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_crypt/Yc_aes.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_crypt/Yc_aes.h	(working copy)
@@ -0,0 +1,73 @@
+#ifndef __YC_AES_H__
+#define __YC_AES_H__
+
+#include "yc3121.h"
+#include "yc_crypt.h"
+#include "yc_calc.h"
+
+#define RET_AES_SUCCESS          (('R'<<24)|('A'<<16)|('S'<<8)|('C'))  //鍔犲瘑鎴愬姛
+#define RET_AES_FAILURE          (('R'<<24)|('A'<<16)|('F'<<8)|('A'))  //鍔犲瘑澶辫触
+#define RET_AES_KEY_IS_NULL      (('R'<<24)|('A'<<16)|('K'<<8)|('N'))  //瀵嗛挜涓虹┖
+#define RET_AES_KEY_IS_OK        (('R'<<24)|('A'<<16)|('K'<<8)|('O'))  //瀵嗛挜姝ｇ‘
+#define RET_AES_KEY_SIZE_ERROR   (('R'<<24)|('A'<<16)|('K'<<8)|('S'))  //瀵嗛挜闀垮害閿欒
+#define RET_AES_PACK_MODE_ERROR  (('R'<<24)|('A'<<16)|('P'<<8)|('E'))  //鍒嗙粍妯″紡閿欒
+#define RET_AES_OUTBUF_TOO_SMALL (('R'<<24)|('A'<<16)|('O'<<8)|('S'))  //杈撳嚭缂撳啿鍖轰笉瓒
+#define RET_AES_INPUT_SIZE_ERROR (('R'<<24)|('A'<<16)|('I'<<8)|('S'))  //杈撳叆鏁版嵁闀垮害閿欒
+
+#define AES_IV_SIZE	(16)
+
+typedef enum
+{
+	AES_128	= 128,
+	AES_192 = 192,
+	AES_256 = 256
+}AES_KeySizeTypeDef;
+	
+typedef uint8_t AES_IvKeyTypeDef[AES_IV_SIZE];
+
+/**
+  * @method	AES_Enc
+  * @brief	AES encrypt function
+  * @param	pack_mode :block encryption mode ECB or CBC
+  * @param	output    :the pointer of output data buffer
+  * @param	oBytes    :the size of output data buffer
+	*                   ("oBytes" must be bigger or equal then "iBytes")
+  * @param	input     :the pointer of input data buffer
+  * @param	iBytes    :the size of input data buffer
+  *                   ("iBytes" must be an integer multiple of key length)
+  * @param	key       :AES key
+  * @param	kSize     :the size of AES key: AES_128 AES_192 or AES_256
+  * @param	iv        :initialization vector
+  * @retval AES return value
+  */
+
+uint32_t AES_Enc(PACK_ModeTypeDef pack_mode,
+                 uint8_t *output, uint32_t obytes,
+                 uint8_t *input, uint32_t ibytes,
+                 uint8_t *key, AES_KeySizeTypeDef ksize, 
+                 AES_IvKeyTypeDef iv,
+                 rng_callback f_rng, void *p_rng);
+
+/**
+  * @method	AES_Decrypt
+  * @brief	AES decrypt function
+  * @param	pack_mode :block encryption mode ECB or CBC
+  * @param	output    :the pointer of output data buffer
+  * @param	oBytes    :the size of output data buffer
+  *                    ("oBytes" must be bigger or equal then "iBytes")
+  * @param	input     :the pointer of input data buffer
+  * @param	iBytes    :the size of input data buffer
+  *                    ("iBytes" must be an integer multiple of key length)
+  * @param	key       :AES key
+  * @param	kSize     :the size of AES key: AES_128 AES_192 or AES_256
+  * @param	iv        :initialization vector
+  * @retval AES return value
+  */
+uint32_t AES_Dec(PACK_ModeTypeDef pack_mode,
+                 uint8_t *output, uint32_t obytes,
+                 uint8_t *input, uint32_t ibytes,
+                 uint8_t *key, AES_KeySizeTypeDef ksize, 
+                 AES_IvKeyTypeDef iv,
+                 rng_callback f_rng, void *p_rng);
+ 
+#endif
Index: yc_crypt/yc_calc.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_crypt/yc_calc.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_crypt/yc_calc.h	(working copy)
@@ -0,0 +1,104 @@
+#ifndef __YC_CALC_H__
+#define __YC_CALC_H__
+
+
+#include "yc3121.h"
+#include "yc_crypt.h"
+
+#define SET_GENKEY     0x0
+#define SET_ENC_DATA1  0x1
+#define SET_ENC_DATA2  0x2
+
+#define GET_E_LEN      0x0
+#define GET_FifoBuffer 0x1
+
+//struct
+typedef struct
+{
+	uint32_t *a;    //operand a
+	uint32_t *b;    //operand b
+	uint32_t *p;    //modulus p
+	uint32_t *c;    //factor  c
+	uint32_t q;     //factor  q
+} calc_operand;
+
+//the values of the parameter config in function calc_config()
+#define CALC_POLL  0
+#define CALC_IDLE  1
+
+//the values of the parameter index in function  calc_run() 
+#define FUNC_MUL           0   //multiplication
+#define FUNC_DIV           1   //division
+#define FUNC_MODEXP        2   //modular exponentiation
+#define FUNC_MODEXP2_PRIME 3   //modular exponentiation in prime field, 2^(2*32*(Cb+1)) % B
+#define FUNC_MODMUL_PRIME  4   //modular multiplication in prime field
+#define FUNC_MODINV_PRIME  5   //modular inversion in prime field
+#define FUNC_MODEXP2_BIN   6   //modular exponentiation in binary field, 2^(2*32*(Cb+1)) % B
+#define FUNC_MODMUL_BIN    7   //modular multiplication in binary field
+#define FUNC_MODINV_BIN    8   //modular inversion in binary field
+#define FUNC_PM_BIN        9   //point multiplication in binary field
+#define FUNC_PM_PRIME      10  //point multiplication in prime field
+#define FUNC_PA_PRIME      11  //point addition in prime field
+#define FUNC_PD_PRIME      12  //point double in prime field
+
+//return value definition
+#define RET_CALC_FUNCTION_ID_ERROR       (('R'<<24)|('F'<<16)|('I'<<8)|('E'))
+#define RET_CALC_OPERAND_LENGTH_ERROR    (('R'<<24)|('O'<<16)|('L'<<8)|('E'))
+#define RET_CALC_IMPLEMENT_SUCCESS       (('R'<<24)|('E'<<16)|('I'<<8)|('S'))  //0x52454953
+#define RET_CALC_GCD_NOT_ONE             (('R'<<24)|('G'<<16)|('N'<<8)|('O'))
+
+#define CMPOK        0xA55AA55A 
+#define CMPERROR     0x5AA55AA5 
+
+//function
+void calc_interrupt(void);
+void calc_config(uint32_t config);
+void calc_setsecurity(uint8_t config);
+uint32_t calc_run(uint8_t index);
+uint32_t calc_add(volatile uint32_t *result,volatile uint32_t *a,volatile uint32_t *b,uint32_t len);
+uint32_t calc_sub(uint32_t *result,uint32_t *a,uint32_t *b,uint32_t len);
+void calc_modadd(uint32_t *result,uint32_t *a,uint32_t *b,uint32_t *p,uint32_t len);
+void calc_modsub(uint32_t *result,uint32_t *a,uint32_t *b,uint32_t *p,uint32_t len);
+void calc_xor(uint32_t *result,uint32_t *a,uint32_t *b,uint32_t len);
+uint32_t calc_mul(uint32_t *result,uint32_t *a,uint32_t *b,uint32_t len_a,uint32_t len_b);
+uint32_t calc_div(uint32_t *result_q,uint32_t *result_r,uint32_t *a,uint32_t *b,uint32_t len_a,uint32_t len_b);
+uint32_t calc_mod(uint32_t *result, uint32_t *a, uint32_t *b, uint32_t len_a, uint32_t len_b);
+uint32_t calc_modexp(uint32_t *result,calc_operand *operand,uint32_t len_a,uint32_t len_b);
+uint32_t calc_modexp2(uint32_t *result, uint32_t *a, uint32_t *b, uint32_t *c, uint32_t len_a, uint32_t len_b);
+uint32_t calc_const_c(uint32_t *result, uint32_t *p, uint32_t len);
+uint32_t calc_const_c_f2m(uint32_t *result, uint32_t *p, uint32_t len);
+uint32_t calc_modmul(uint32_t *result, calc_operand *operand, uint32_t len);
+uint32_t calc_modmul2(uint32_t *result, uint32_t *a,volatile uint32_t *b, uint32_t *c, uint32_t len);
+uint32_t calc_modmul_f2m(uint32_t *result, calc_operand *operand, uint32_t len);
+uint32_t calc_modmul2_f2m(uint32_t *result, uint32_t *a, uint32_t *b, uint32_t *c, uint32_t len);
+uint32_t calc_modinv(uint32_t *result, uint32_t *a, uint32_t *p, uint32_t len);
+uint32_t calc_modinv_f2m(uint32_t *result, uint32_t *a, uint32_t *p , uint32_t len);
+uint32_t calc_gcd(uint32_t *a, uint32_t *p, uint32_t len);
+uint32_t calc_const_q(uint32_t *result, uint32_t *a);
+uint32_t calc_const_q_f2m(uint32_t *result, uint32_t *a);
+void calc_sr(uint32_t *result, uint32_t *a, uint32_t len, uint32_t sf_len);
+uint32_t calc_bitlen(uint32_t *a, uint32_t len);
+void calc_modinv2048(uint32_t *result, uint32_t *a, uint32_t *b, uint32_t len_a, uint32_t len_b);
+uint32_t calc_gcd2048(uint32_t a, uint32_t *b, uint32_t len);
+uint32_t calc_gcd2048_l(uint32_t *result,uint32_t *a, uint32_t *b, uint32_t len_a);
+uint32_t calc_rolladd(uint32_t *result,uint32_t *a,uint32_t *b,uint32_t wlen, uint32_t startflag);
+uint32_t calc_modmul_base(uint32_t *result, calc_operand *operand, uint32_t len, uint32_t config);
+
+void uint32touint8(uint8_t *dst,uint32_t *src);
+void uint8touint32(uint32_t *dst,uint8_t *src);
+void mem_cpy(volatile unsigned int *dst,volatile unsigned int *src,unsigned int s)  ;
+int mem_cmp(volatile unsigned int *str1,volatile unsigned int *str2,int len)  ;
+int mem_cmp2(volatile unsigned int *str1,unsigned int str2,int len)  ;
+void mem_set(volatile unsigned int *s, unsigned int c, unsigned int n);
+//void revstr(char *str, size_t len);
+int mem_rollcmp(volatile uint32_t *indata1,uint32_t *indata2,uint32_t wlen, uint32_t startflag);
+int mem_rollcmp_char(uint8_t *indata1,uint8_t *indata2,uint32_t wlen, uint32_t startflag);
+unsigned int calculatexor(unsigned int *data,unsigned int initdata,int len);
+ void memcpy_r(uint8_t *a,uint8_t *b,uint32_t len);
+uint32_t mem_rollcpy(volatile uint32_t *result,uint32_t *content,uint32_t wlen, uint32_t startflag);
+void mem_rollcpy_r_char( uint8_t *result,uint8_t *content,uint32_t wlen, uint32_t startflag);
+uint32_t mem_rollcpy_char( uint8_t *result,uint8_t *content,uint32_t wlen, uint32_t startflag);
+uint32_t calc_modmul_f2m_2(uint32_t *result, uint32_t *a, uint32_t *b, uint32_t *p, uint32_t *c, uint32_t len, uint32_t config);
+void calc_modadd_1(uint32_t *result,uint32_t *a,uint32_t *b,uint32_t *p,uint32_t len);
+
+#endif
Index: yc_crypt/yc_crc16.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_crypt/yc_crc16.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_crypt/yc_crc16.h	(working copy)
@@ -0,0 +1,11 @@
+#ifndef __YC_CRC16_H__
+#define __YC_CRC16_H__
+
+#include "..\core\yc3121.h"
+#include "..\core\system.h"
+
+uint16_t crc16_calc(uint16_t iv, uint32_t mask, uint8_t *data, uint16_t data_len);
+
+#define CRC16_TEST
+
+#endif
Index: yc_crypt/yc_crypt.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_crypt/yc_crypt.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_crypt/yc_crypt.h	(working copy)
@@ -0,0 +1,28 @@
+#ifndef __YC_CRYPT_H__
+#define __YC_CRYPT_H__
+
+#define CMPERR      (('C'<<24)|('M'<<16)|('P'<<8)|('E'))
+#define EQUAL       (('E'<<24)|('Q'<<16)|('U'<<8)|('A'))
+#define UNEQUAL     (('U'<<24)|('E'<<16)|('Q'<<8)|('U'))
+#define BIGGER      (('B'<<24)|('I'<<16)|('G'<<8)|('G'))
+#define SMALLER     (('S'<<24)|('M'<<16)|('A'<<8)|('L'))
+
+typedef enum 
+{
+	ECB = (('P'<<24)|('E'<<16)|('C'<<8)|('B')), 
+	CBC = (('P'<<24)|('C'<<16)|('B'<<8)|('C'))
+}PACK_ModeTypeDef;
+
+typedef enum
+{
+	ENC = (('C'<<24)|('E'<<16)|('N'<<8)|('C')),
+	DEC = (('C'<<24)|('D'<<16)|('E'<<8)|('C'))
+}CRYPT_ModeTypeDef;
+
+typedef uint32_t (*rng_callback)(void *rand, uint32_t size, void *p_rng);
+
+void crypt_reset(void);
+void crypt_it_clear(void);
+void crypt_data_rand(rng_callback f_rng, void *p_rng);
+
+#endif 
Index: yc_crypt/yc_crypt.lib
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: yc_crypt/yc_crypt.lib
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: yc_crypt/yc_des.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_crypt/yc_des.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_crypt/yc_des.h	(working copy)
@@ -0,0 +1,144 @@
+#ifndef __YC_DES_H__
+#define __YC_DES_H__
+
+#include "yc3121.h"
+#include "yc_crypt.h"
+#include "yc_calc.h"
+
+#define RET_DES_SUCCESS            (('R'<<24)|('D'<<16)|('S'<<8)|('C'))  //鍔犲瘑鎴愬姛
+#define RET_DES_FAILURE            (('R'<<24)|('D'<<16)|('F'<<8)|('A'))  //鍔犲瘑澶辫触
+#define RET_DES_KEY_IS_OK          (('R'<<24)|('D'<<16)|('K'<<8)|('O'))  //瀵嗛挜姝ｇ‘
+#define RET_DES_KEY_IS_NULL        (('R'<<24)|('D'<<16)|('K'<<8)|('N'))  //瀵嗛挜鎸囬拡涓虹┖
+#define RET_DES_KEY_CRC_ERROR      (('R'<<24)|('D'<<16)|('K'<<8)|('C'))  //瀵嗛挜 CRC 閿欒
+#define RET_DES_KEY_READBACK_ERROR (('R'<<24)|('D'<<16)|('K'<<8)|('R'))  //瀵嗛挜鍥炶閿欒
+#define RET_DES_IV_CRC_ERROR       (('R'<<24)|('D'<<16)|('I'<<8)|('C'))  //IVCRC 閿欒
+#define RET_DES_PACK_MODE_ERROR    (('R'<<24)|('D'<<16)|('P'<<8)|('E'))  //鍒嗙粍妯″紡閿欒
+#define RET_DES_OUTBUF_TOO_SMALL   (('R'<<24)|('D'<<16)|('O'<<8)|('S'))  //杈撳嚭缂撳啿涓嶈冻
+#define RET_DES_INPUT_SIZE_ERROR   (('R'<<24)|('D'<<16)|('I'<<8)|('S'))  //杈撳叆鏁版嵁 len 閿欒
+#define RET_DES_RESULT_CHECK_ERROR (('R'<<24)|('D'<<16)|('R'<<8)|('C'))  //杈撳嚭缁撴灉閿欒
+
+#define DES_KEY_SIZE 8  
+#define DES_IV_SIZE  8
+                                               
+typedef uint8_t DES_KeyTypeDef[DES_KEY_SIZE];
+typedef uint8_t DES_IvTypeDef[DES_IV_SIZE]; 
+
+typedef uint8_t DES_RandTypeDef[4]; 
+typedef uint8_t DES_FakeTypeDef[8]; 
+
+#define DES_TYPE_DES_ENC  (('D'<<24)|('T'<<16)|('D'<<8)|('E'))  //DES 鍔犲瘑妯″紡
+#define DES_TYPE_DES_DEC  (('D'<<24)|('T'<<16)|('D'<<8)|('D'))  //DES 瑙ｅ瘑妯″紡
+#define DES_TYPE_TDES_ENC (('D'<<24)|('T'<<16)|('T'<<8)|('E'))  //TDES 鍔犲瘑妯″紡
+#define DES_TYPE_TDES_DEC (('D'<<24)|('T'<<16)|('T'<<8)|('D'))  //TDES 瑙ｅ瘑妯″紡
+
+typedef struct         
+{                      
+	DES_KeyTypeDef k1;   
+	DES_KeyTypeDef k2;   
+	DES_KeyTypeDef k3;   
+}TDES_KeyTypeDef;      
+
+//struct
+typedef struct
+{
+	uint8_t  *result;  //
+	uint8_t  *content; //
+	uint8_t  *key1;    //
+	uint8_t  *key2;    //
+	uint8_t  *key3;    //
+	uint8_t  *iv;      //
+	uint8_t  *rand;    //
+	uint8_t  *fakekey; //
+	uint8_t  config;   //
+	uint32_t length;   //
+}des_para;
+
+/**
+  * @method	mh_des_enc
+  * @brief	DES encrypt function
+  * @param	pack_mode : block encryption mode ECB or CBC
+  * @param	output    : the pointer of output data buffer
+  * @param	obytes    : the size of output data buffer
+  *                     ("oBytes" must be bigger or equal then "iBytes")
+  * @param	input     : the pointer of input data buffer
+  * @param	ibytes    : the size of input data buffer
+  *                     ("iBytes" must be an integer multiple of key length)
+  * @param	key       : DES key
+  * @param	iv        : initialization vector
+  * @param	f_rng     : true random number generation function point
+  * @param	p_rng     : true random number generation para
+  * @retval	DES return value
+  */
+uint32_t DES_Enc(PACK_ModeTypeDef pack_mode,
+                 uint8_t *output, uint32_t obytes,
+                 uint8_t *input, uint32_t ibytes,
+                 DES_KeyTypeDef key,	DES_IvTypeDef iv,
+                 rng_callback f_rng, void *p_rng);
+					
+/**
+  * @method	DES_Decrypt
+  * @brief	DES decrypt function
+  * @param	pack_mode		: block encryption mode ECB or CBC
+  * @param	output			: the pointer of output data buffer
+  * @param	oBytes			: the size of output data buffer
+  *                       ("oBytes" must be bigger or equal then "iBytes")
+  * @param	input       : the pointer of input data buffer
+  * @param	iBytes      : the size of input data buffer
+  *                       ("iBytes" must be an integer multiple of key length)
+  * @param	key         : DES key
+  * @param	iv          : initialization vector
+  * @param	f_rng       : true random number generation function point
+  * @param	p_rng       : true random number generation para
+  * @retval DES return value
+  */
+uint32_t DES_Dec(PACK_ModeTypeDef pack_mode,
+                 uint8_t *output, uint32_t obytes,
+                 uint8_t *input, uint32_t ibytes,
+                 DES_KeyTypeDef key,	DES_IvTypeDef iv,
+                 rng_callback f_rng, void *p_rng);
+
+/**
+  * @method	TDES_Encrypt
+  * @brief	TDES encrypt function
+  * @param	pack_mode : block encryption mode ECB or CBC
+  * @param	output    : the pointer of output data buffer
+  * @param	oBytes    : the size of output data buffer
+  *                     ("oBytes" must be bigger or equal then "iBytes")
+  * @param	input     : the pointer of input data buffer
+  * @param	iBytes    : the size of input data buffer
+  *                     ("iBytes" must be an integer multiple of key length)
+  * @param	key       : DES key
+  * @param	iv        : initialization vector
+  * @param	f_rng     : true random number generation function point
+  * @param	p_rng     : true random number generation para
+  * @retval TDES return value
+  */
+uint32_t TDES_Enc(PACK_ModeTypeDef pack_mode,
+                  uint8_t *output, uint32_t obytes,
+                  uint8_t *input, uint32_t ibytes,
+                  TDES_KeyTypeDef *key, DES_IvTypeDef iv,
+                  rng_callback f_rng, void *p_rng);
+								 
+/**
+  * @method	TDES_Decrypt
+  * @brief	TDES decrypt function
+  * @param	pack_mode : block encryption mode ECB or CBC
+  * @param	output    : the pointer of output data buffer
+  * @param	oBytes    : the size of output data buffer
+  *                     ("oBytes" must be bigger or equal then "iBytes")
+  * @param	input     : the pointer of input data buffer
+  * @param	iBytes    : the size of input data buffer
+  *                     ("iBytes" must be an integer multiple of key length)
+  * @param	key       : DES key
+  * @param	iv        : initialization vector
+  * @param	f_rng     : true random number generation function point
+  * @param	p_rng     : true random number generation para
+  * @retval TDES return value
+  */
+uint32_t TDES_Dec(PACK_ModeTypeDef pack_mode,
+                  uint8_t *output, uint32_t obytes,
+                  uint8_t *input, uint32_t ibytes,
+                  TDES_KeyTypeDef *key, DES_IvTypeDef iv,
+                  rng_callback f_rng, void *p_rng);
+
+#endif
Index: yc_crypt/yc_ecc.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_crypt/yc_ecc.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_crypt/yc_ecc.h	(working copy)
@@ -0,0 +1,116 @@
+#ifndef _CALC_ECC_H_
+#define _CALC_ECC_H_
+
+#include "yc_rsa.h"
+
+#define PLATFORM8 0xffffee
+#define PLATFORM  0xffffee11
+
+
+#if PLATFORM == PLATFORM8
+#else
+
+typedef struct
+{
+	uint32_t *x;  //x锟斤拷锟斤拷锟斤拷
+	uint32_t *y;  //y锟斤拷锟斤拷锟斤拷
+}ecc_point_a;//锟斤拷锟斤拷锟斤拷锟斤拷
+
+typedef struct
+{
+	uint32_t *x;  //x锟斤拷锟斤拷锟斤拷
+	uint32_t *y;  //y锟斤拷锟斤拷锟斤拷
+	uint32_t *z;  //z锟斤拷锟斤拷锟斤拷
+}ecc_point_j;//锟脚可憋拷锟斤拷锟斤拷
+
+typedef struct
+{
+	uint32_t *x;  //x锟斤拷锟斤拷锟斤拷
+	uint32_t *y;  //y锟斤拷锟斤拷锟斤拷
+	uint32_t *z;  //z锟斤拷锟斤拷锟斤拷
+	uint32_t *t;  //t锟斤拷锟斤拷锟斤拷
+}ecc_point_mj;//锟斤拷锟斤拷锟脚可憋拷锟斤拷锟斤拷
+typedef struct
+{
+	uint32_t *p;        //模锟斤拷--锟斤拷锟解部锟斤拷锟斤拷
+	uint32_t *a;        //锟斤拷圆锟斤拷锟竭筹拷锟斤拷a--锟斤拷锟解部锟斤拷锟斤拷
+	uint32_t *b;        //锟斤拷圆锟斤拷锟竭筹拷锟斤拷b--锟斤拷锟解部锟斤拷锟斤拷
+	ecc_point_a g;    //锟斤拷锟斤拷--锟斤拷锟解部锟斤拷锟斤拷
+	uint32_t *n;        //锟斤拷锟斤拷慕锟--锟斤拷锟解部锟斤拷锟斤拷
+	uint32_t len_bits;    //bitlen锟斤拷锟斤拷位锟斤拷,锟斤拷锟斤拷 
+	uint32_t len_words;      //len锟斤拷锟竭筹拷锟斤拷,锟斤拷 
+	uint32_t field;     //锟斤拷
+	uint32_t a_type;      //flag锟叫讹拷a锟角凤拷锟斤拷锟-3bit0锟斤拷0-锟斤拷龋锟1-锟斤拷锟斤拷--锟斤拷锟解部锟斤拷锟斤拷
+	uint32_t *p_c;      //锟斤拷p为取模锟侥筹拷锟斤拷c
+	uint32_t p_q;       //锟斤拷p为取模锟侥碉拷锟斤拷锟斤拷锟斤拷q
+	uint32_t *n_c;      //锟斤拷p为取模锟侥筹拷锟斤拷c
+	uint32_t n_q;       //锟斤拷p为取模锟侥碉拷锟斤拷锟斤拷锟斤拷q
+	uint32_t *n1_c;
+	uint32_t n1_q;
+}ecc_para;//ecc锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷萁峁
+typedef struct
+{
+	uint32_t *d;        //ecc私钥
+	ecc_point_a e;    //ecc锟斤拷钥
+}ecc_key;//ecc锟斤拷钥锟斤拷锟斤拷锟捷结构
+typedef struct
+{
+	uint32_t mask;//锟斤拷锟斤拷盲锟斤拷(锟斤拷锟斤拷锟斤拷锟斤拷)
+	uint32_t verify;//指锟斤拷盲锟斤拷(指锟斤拷锟斤拷锟斤拷)
+}ecc_security;
+//macro define
+#define ECC_P192 0
+#define ECC_P224 1
+#define ECC_P256 2
+#define ECC_B163 3
+#define ECC_B193 4
+#define ECC_B233 5
+#define ECC_B257 6
+
+#define ECC_PRIME  (('E'<<8)|('P'))
+#define ECC_BINARY (('E'<<8)|('B'))
+#define ECC_A_IS_NEGATIVE_3 (('A'<<24)|('I'<<16)|('N'<<8)|('3'))
+#define ECC_A_NOT_NEGATIVE_3 (('A'<<24)|('N'<<16)|('N'<<8)|('3'))
+#define INT_MASK_OPEN (('I'<<16)|('M'<<8)|('O'))
+#define INT_MASK_CLOSE (('I'<<16)|('M'<<8)|('C'))
+#define EC_PARA_VERIFY_OPEN (('E'<<24)|('P'<<16)|('V'<<8)|('O'))
+#define EC_PARA_VERIFY_CLOSE (('E'<<24)|('P'<<16)|('V'<<8)|('C'))
+#define SCALAR_IS_EVEN  (('S'<<16)|('I'<<8)|('E'))
+#define SCALAR_NOT_EVEN (('S'<<16)|('N'<<8)|('E'))
+#define EMBEDED_PUBLIC_KEY_VERIFY (('E'<<24)|('P'<<16)|('K'<<8)|('V'))
+#define COMMON_PUBLIC_KEY_VERIFY  (('C'<<24)|('P'<<16)|('K'<<8)|('V'))
+
+#define RET_POINT_INFINITE_FAR         (('E'<<24)|('P'<<16)|('F'<<8)|('F'))
+#define RET_ECC_POINT_SUCCESS          (('E'<<24)|('P'<<16)|('S'<<8)|('U'))
+#define RET_ECC_POINT_FAILED           (('E'<<24)|('P'<<16)|('F'<<8)|('A'))
+#define RET_ECC_POINT_ADD_ERROR        (('E'<<24)|('P'<<16)|('A'<<8)|('E'))
+#define RET_ECC_POINT_MULT_ERROR       (('E'<<24)|('P'<<16)|('M'<<8)|('E'))
+#define RET_ECC_POINT_INFINITE_FAR     (('E'<<24)|('P'<<16)|('I'<<8)|('F'))
+#define RET_ECC_PUBLIC_KEY_FAILED      (('E'<<24)|('P'<<16)|('K'<<8)|('F'))
+#define RET_ECC_PUBLIC_KEY_PASS        (('E'<<24)|('P'<<16)|('K'<<8)|('P'))
+#define RET_ECC_KEY_GENERATION_SUCCESS (('E'<<24)|('K'<<16)|('G'<<8)|('S'))
+#define RET_ECC_KEY_GENERATION_FAILED  (('E'<<24)|('K'<<16)|('G'<<8)|('F'))
+
+//function
+extern const  unsigned int  CONST_LONG_ONE[64]  ;
+extern const  unsigned int  CONST_LONG_FFFFFFFF[64]  ;
+
+extern uint32_t sm2_rand_val[9];
+extern uint8_t sm2_rand_index;
+
+void ecc_config(ecc_para *para,uint32_t config);
+uint32_t ecc_genkey(ecc_key *key,ecc_para *para,ecc_security *security,uint32_t *rand_key,uint32_t *rand_mask);
+uint32_t ecc_verifykey(ecc_key *key,ecc_para *para,uint32_t config);
+uint32_t ecc_pmul(ecc_point_a *result,ecc_point_a *a,uint32_t *b,ecc_para *para,ecc_security *security,uint32_t *rand, uint32_t rand_len);
+uint32_t ecc_pmul_calc(ecc_point_a *result,ecc_point_a *a, uint32_t *k,uint32_t k_len,ecc_para *para);
+uint32_t ecc_verifypoint(ecc_point_a *a,ecc_para *para);
+uint32_t ecc_pdbl_a(ecc_point_a *result,ecc_point_a *a,ecc_para *para);
+uint32_t ecc_padd_ja(ecc_point_j *result,ecc_point_j *a,ecc_point_a *b,ecc_para *para);
+void sm2_bin_padd_1(ecc_point_a *result, ecc_point_j *a, ecc_point_j *b, ecc_para *para);
+void sm2_bin_padd_2(ecc_point_a *result, ecc_point_j *a, ecc_point_j *b, ecc_para *para);
+
+void sm2_rand_init(void);
+
+#endif
+
+#endif
Index: yc_crypt/yc_rsa.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_crypt/yc_rsa.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_crypt/yc_rsa.h	(working copy)
@@ -0,0 +1,167 @@
+#ifndef __YC_RSA_H__
+#define __YC_RSA_H__
+
+#include "yc_calc.h"
+
+#define MIN_RSA_MODULUS_BITS  1024
+#define MAX_RSA_MODULUS_BITS  2048
+#define MAX_RSA_MODULUS_BYTES ((MAX_RSA_MODULUS_BITS + 7) / 8)
+#define MAX_RSA_PRIME_BITS    ((MAX_RSA_MODULUS_BITS + 1) / 2)
+#define MAX_RSA_PRIME_BYTES   ((MAX_RSA_PRIME_BITS + 7) / 8)
+
+typedef struct
+{
+	uint32_t bytes;                       // RSA瀵嗛挜闀垮害瀛楄妭鏁帮紝鍗 RSA 瀵嗛挜涓 bytes * 8bits 锛岀敱浜庡浐瀹氬弬鏁 MAX_RSA_MODULUS_BYTES 鐨勯檺瀹氾紝bytes 鏈澶у间负 256
+	uint8_t  e[4];                        // RSA 鍏挜鎸囨暟
+	uint8_t  p[MAX_RSA_PRIME_BYTES];	    // RSA 绱犳暟 p
+	uint32_t p_xor;                       // p 寮傛垨鏍￠獙鍊
+	uint8_t  q[MAX_RSA_PRIME_BYTES];      // RSA 绱犳暟 q
+	uint32_t q_xor;                       // q 寮傛垨鏍￠獙鍊
+	uint8_t  n[MAX_RSA_MODULUS_BYTES];    // RSA 妯℃暟 n
+	uint8_t  d[MAX_RSA_MODULUS_BYTES];    // RSA 绉侀挜鎸囨暟
+	uint8_t  dp[MAX_RSA_PRIME_BYTES];     // d mod (p-1)
+	uint8_t  dq[MAX_RSA_PRIME_BYTES];     // d mod (q-1)
+	uint8_t  qp[MAX_RSA_PRIME_BYTES];     // q^-1 mod p 
+	uint8_t  n_c[MAX_RSA_MODULUS_BYTES];  // 妯℃暟 n 鍙傛暟 C锛岀敤浜 n 鐨勬ā骞傝繍绠
+	uint8_t  n_q[4];                      // 妯℃暟 n 鍙傛暟 Q锛岀敤浜 n 鐨勬ā骞傝繍绠
+	uint8_t  p_c[MAX_RSA_PRIME_BYTES];    // 妯℃暟 p 鍙傛暟 C锛岀敤浜 p 鐨勬ā骞傝繍绠
+	uint8_t  p_q[4];                      // 妯℃暟 p 鍙傛暟 Q锛岀敤浜 p 鐨勬ā骞傝繍绠
+	uint8_t  q_c[MAX_RSA_PRIME_BYTES];    // 妯℃暟 q 鍙傛暟 C锛岀敤浜 q 鐨勬ā骞傝繍绠
+	uint8_t  q_q[4];                      // 妯℃暟 q 鍙傛暟 Q锛岀敤浜 q 鐨勬ā骞傝繍绠
+}RSA_PrivateKeyTypeDef;
+
+ 
+typedef struct
+{
+	uint32_t bytes;                       //RSA瀵嗛挜闀垮害瀛楄妭鏁帮紝鍗 RSA 瀵嗛挜涓 bytes * 8bits 锛岀敱浜庡浐瀹氬弬鏁 MAX_RSA_MODULUS_BYTES 鐨勯檺瀹氾紝bytes 鏈澶у间负 256
+	uint8_t  e[4];                        //RSA 鍏挜鎸囨暟
+	uint8_t  n[MAX_RSA_MODULUS_BYTES];    //RSA 妯℃暟 n
+	uint8_t  n_c[MAX_RSA_MODULUS_BYTES];  //妯℃暟 n 鍙傛暟 C锛岀敤浜 n 鐨勬ā骞傝繍绠
+	uint8_t  n_q[4];                      //妯℃暟 n 鍙傛暟 Q锛岀敤浜 n 鐨勬ā骞傝繍绠
+}RSA_PublicKeyTypeDef;
+
+typedef enum
+{
+	RSA_1024	= 1024,
+	RSA_2048	= 2048,
+}RSA_KeyBitsTypedef;
+
+typedef struct
+{
+	uint32_t *eta;
+	uint32_t *pi;
+	uint32_t *ro;
+} rsa_prime;
+
+//return value
+#define RET_RSA_RANDNUM_NOT_ACCEPT          (('R'<<24)|('R'<<16)|('N'<<8)|('A'))  //闅忔満鏁颁笉琚帴鍙
+#define RET_RSA_KEYGEN_SUCCESS              (('R'<<24)|('K'<<16)|('G'<<8)|('S'))  //RSA 瀵嗛挜鐢熸垚鎴愬姛
+#define RET_RSA_IMPLEMENT_SUCCESS           (('R'<<24)|('R'<<16)|('I'<<8)|('S'))  //鎵ц鎴愬姛
+#define RET_RSA_IMPLEMENT_ERROR             (('R'<<24)|('R'<<16)|('A'<<8)|('E'))  //鎵ц澶辫触
+#define RET_PRIME_CHECK_PASS                (('R'<<24)|('P'<<16)|('C'<<8)|('P'))  //绱犳暟妫鏌ユ垚鍔
+#define RET_PRIME_CHECK_FAIL                (('R'<<24)|('P'<<16)|('C'<<8)|('F'))  //绱犳暟妫鏌ュけ璐
+#define RET_RSA_SUCCESS                     (('R'<<24)|('E'<<16)|('R'<<8)|('S'))  //RSA 璁＄畻鎴愬姛
+#define RET_RSA_FAILURE                     (('R'<<24)|('E'<<16)|('R'<<8)|('E'))  //RSA 璁＄畻澶辫触
+
+/**
+  * @method	RSA_Private
+  * @brief	Raw RSA private-key operation. Useing CRT Algorithm
+  * @param	output : output data buffer
+  * @param	input  : input data buffer
+  * @param	key    : RSA private key
+  * @param	f_rng  : true random number generation function point
+  * @param	p_rng  : true random number generation para
+  * @retval	RET_RSA_SUCCESS or RET_RSA_FAILURE
+  */
+uint32_t  RSA_Private_crt(uint8_t *output, uint8_t *input, RSA_PrivateKeyTypeDef *para,rng_callback f_rng, void *p_rng);
+
+/**
+  * @method	RSA_Public
+  * @brief	Raw RSA public-key operation. 
+  * @param	output : output data buffer
+  * @param	input  : input data buffer
+  * @param	key    : RSA public key
+  * @param	f_rng  : true random number generation function point
+  * @param	p_rng  : true random number generation para
+  * @retval RET_RSA_SUCCESS or RET_RSA_FAILURE
+  */
+//RSA_Private_Standard standard not crt;
+uint32_t RSA_Private_Standard(uint8_t *output,uint8_t *input, RSA_PrivateKeyTypeDef *para,rng_callback f_rng, void *p_rng);
+
+uint32_t RSA_Public(uint8_t *output, uint8_t *input, RSA_PublicKeyTypeDef *key, rng_callback f_rng, void *p_rng);
+							
+/**
+  * @method	RSA_GenerateKey
+  * @brief	Generate a RSA private key
+  * @param	key      : rsa private key point
+  * @param	exponent : public exponent
+  * @param	nbits    : rsa module bits
+  * @param	f_rng    : true random number generation function point
+  * @param	p_rng    : true random number generation para
+  * @retval RET_RSA_KEYGEN_SUCCESS or RET_RSA_RANDNUM_NOT_ACCEPT
+  */
+uint32_t RSA_GenerateKey(RSA_PrivateKeyTypeDef *key, uint32_t exponent, uint32_t nbits, rng_callback f_rng, void *p_rng);
+
+/**
+  * @method	RSA_CompleteKey
+  * @brief	complete the private key by the rsa key paras p q d. 
+  * @param	key   : rsa private key point
+  * @param	f_rng : true random number generation function point
+  * @param	p_rng : true random number generation para
+  * @retval RET_RSA_KEYGEN_SUCCESS or RET_RSA_RANDNUM_NOT_ACCEPT
+  */
+uint32_t RSA_CompleteKey(RSA_PrivateKeyTypeDef *key, rng_callback f_rng, void *p_rng);
+
+/**
+  * @method	RSA_CompleteKey_e
+  * @brief	complete the private key by the rsa key paras p q e. 
+  * @param	key   : rsa private key point
+  * @param	f_rng : true random number generation function point
+  * @param	p_rng : true random number generation para
+  * @retval RET_RSA_KEYGEN_SUCCESS or RET_RSA_RANDNUM_NOT_ACCEPT
+  */
+uint32_t RSA_CompleteKey_e(RSA_PrivateKeyTypeDef *key, rng_callback f_rng, void *p_rng);
+
+/**
+  * @method	RSA_GetPrativeKey_C_Q
+  * @brief	
+  * @param	key   : rsa private key point
+  * @param	f_rng : true random number generation function point
+  * @param	p_rng : true random number generation para
+  * @retval RET_RSA_IMPLEMENT_SUCCESS or RET_RSA_IMPLEMENT_ERROR
+  */
+uint32_t RSA_GetPrativeKey_C_Q(RSA_PrivateKeyTypeDef *key, rng_callback f_rng, void *p_rng);
+
+/**
+  * @method	RSA_GetPublicKey_C_Q
+  * @brief	
+  * @param	key   : rsa private key point
+  * @param	f_rng : true random number generation function point
+  * @param	p_rng : true random number generation para
+  * @retval RET_RSA_IMPLEMENT_SUCCESS or RET_RSA_IMPLEMENT_ERROR
+  */
+uint32_t RSA_GetPublicKey_C_Q(RSA_PublicKeyTypeDef *key, rng_callback f_rng, void *p_rng);
+/**
+  * @method	RSA_IsPrime
+  * @brief	
+  * @param	X     : big number array
+  * @param	size  : the big number len (32bit)
+  * @param	f_rng : true random number generation function point
+  * @param	p_rng : true random number generation para
+  * @retval RET_PRIME_CHECK_PASS or RET_PRIME_CHECK_FAIL
+  */
+uint32_t RSA_IsPrime( uint32_t *X, uint32_t size, rng_callback f_rng, void *p_rng);
+
+/**
+  * @method	RSA_GeneratePrime
+  * @brief	
+  * @param	X     : big number array
+  * @param	size  : the big number bits (192/256/512/1024)
+  * @param	f_rng : true random number generation function point
+  * @param	p_rng : true random number generation para
+  * @retval RET_CALC_IMPLEMENT_SUCCESS or RET_RSA_IMPLEMENT_ERROR
+  */
+uint32_t RSA_GeneratePrime( uint32_t *result, uint32_t nbits, rng_callback f_rng, void *p_rng);
+							
+#endif
+
Index: yc_crypt/yc_sha.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_crypt/yc_sha.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_crypt/yc_sha.h	(working copy)
@@ -0,0 +1,60 @@
+#ifndef __YC_SHA_H__
+#define __YC_SHA_H__
+
+#include "yc3121.h"
+#include "yc_crypt.h"
+
+typedef enum
+{
+	SHATYPE_1	  = 0,
+	SHATYPE_224 = 1,
+	SHATYPE_256 = 2,
+	SHATYPE_384 = 3,
+	SHATYPE_512 = 4,
+	SHATYPE_SM3 = 5
+}SHA_ModeTypeDef;
+
+#define RET_SHA_BUSY        (('R'<<24)|('S'<<16)|('B'<<8)|('U'))  //纭欢鍗曞厓澶勪簬蹇欑姸鎬
+#define RET_SHA_MODE_ERR    (('R'<<24)|('S'<<16)|('M'<<8)|('E'))  //杈撳叆璁＄畻绫诲瀷閿欒
+#define RET_SHA_SUCCESS     (('R'<<24)|('S'<<16)|('S'<<8)|('U'))  //璁＄畻鎴愬姛
+
+/**
+  * @method	sha
+  * @brief	Secure Hash Alogrithm
+  * @param	mode   : SHA mode: SHA_1/SHA_224/SHA_256/SHA_384/SHA_512
+  * @param	output : output data buffer
+  * @param	input  : input data buffer
+  * @param	ibytes : size of input data
+  * @retval SHA_TYPE_ERR or SHA_CRYPT_BUSY
+  */
+uint32_t SHA(SHA_ModeTypeDef mode, uint8_t *output, uint8_t *input,uint32_t ibytes);
+
+/**
+  * @method	sha_sec
+  * @brief	Secure Hash Alogrithm Rand Copy
+  * @param	mode   : SHA mode: SHA_256/SHA_384/SHA_512
+  * @param	output : output data buffer
+  * @param	input  : input data buffer
+  * @param	ibytes : size of input data
+  * @param	f_rng  : true random number generation function point
+  * @param	p_rng  : true random number generation para
+  * @retval SHA_TYPE_ERR or SHA_CRYPT_BUSY
+  */
+uint32_t SHA_Sec(SHA_ModeTypeDef mode,  uint8_t *output, uint8_t *input,uint32_t ibytes,
+							rng_callback f_rng, void *p_rng);
+
+/**
+  * @method	SHA_Enhance
+  * @brief	Secure Hash Alogrithm
+  * @param	mode		:SHA mode: SHA_1/SHA_224/SHA_256/SHA_384/SHA_512
+  * @param	output		:output data buffer
+  * @param	input		:input data buffer
+  * @param	ibytes		:size of input data
+  * @param     totallen		:size of totallen
+  * @param     step               :step = 0 head,  step = 1 middle,  step = 2 tail 
+  * @retval 			:SHA_TYPE_ERR or SHA_CRYPT_BUSY
+  */
+uint32_t SHA_Enhance(SHA_ModeTypeDef mode,  uint8_t *output, uint8_t *input,uint32_t ibytes, uint32_t totallen,
+						uint8_t step);
+
+#endif
Index: yc_crypt/yc_sm2.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_crypt/yc_sm2.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_crypt/yc_sm2.h	(working copy)
@@ -0,0 +1,167 @@
+#ifndef __YC_SM2_H__
+#define __YC_SM2_H__
+
+#include "yc3121.h"
+#include "yc_crypt.h"
+#include "system.h"
+#include "yc_sm3.h"
+#include "yc_trng.h"
+
+#define SM2_FLOW_CONTROL
+
+#define SM2_KEY_BITS 		257
+#define SM2_KEY_BYTES		((SM2_KEY_BITS + 7) / 8)
+#define SM2_KEY_WORDS		((SM2_KEY_BYTES + 3) / 4)
+
+typedef struct 
+{
+	uint32_t r[SM2_KEY_WORDS];
+	uint32_t s[SM2_KEY_WORDS];
+}SM2_SignTypeDef;
+
+typedef struct
+{
+	uint32_t x[SM2_KEY_WORDS];
+	uint32_t y[SM2_KEY_WORDS];
+}SM2_PointTypeDef;
+
+typedef struct
+{
+	uint32_t p[SM2_KEY_WORDS];  //妯℃暟
+	uint32_t a[SM2_KEY_WORDS];  //妞渾鏇茬嚎甯告暟 a
+	uint32_t b[SM2_KEY_WORDS];  //妞渾鏇茬嚎甯告暟 b
+	SM2_PointTypeDef g;         //鍩虹偣
+	uint32_t n[SM2_KEY_WORDS];  //鍩虹偣鐨勯樁
+}SM2_EllipseParaTypeDef;
+
+typedef SM2_PointTypeDef SM2_PublicKeyTypeDef;
+
+typedef struct
+{
+	uint32_t d[SM2_KEY_WORDS];
+	SM2_PublicKeyTypeDef e;
+}SM2_PrivateKeyTypeDef;
+
+
+#define RET_SM2_ENC_SUCCESS       (('R'<<24)|('S'<<16)|('E'<<8)|('S'))  //鍔犲瘑鎴愬姛
+#define RET_SM2_ENC_FAILURE       (('R'<<24)|('S'<<16)|('E'<<8)|('F'))  //鍔犲瘑澶辫触
+#define RET_SM2_DEC_SUCCESS       (('R'<<24)|('S'<<16)|('D'<<8)|('S'))  //瑙ｅ瘑鎴愬姛
+#define RET_SM2_DEC_FAILURE       (('R'<<24)|('S'<<16)|('D'<<8)|('F'))  //瑙ｅ瘑澶辫触
+#define RET_SM2_KDF_SUCCESS       (('R'<<24)|('S'<<16)|('K'<<8)|('S'))  //瀵嗛挜娲剧敓鎴愬姛
+#define RET_SM2_KDF_FAILURE       (('R'<<24)|('S'<<16)|('K'<<8)|('F'))  //瀵嗛挜娲剧敓澶辫触
+#define RET_SM2_SIGN_SUCCESS      (('R'<<24)|('S'<<16)|('S'<<8)|('S'))  //鏁板瓧绛惧悕鎴愬姛
+#define RET_SM2_SIGN_FAILURE      (('R'<<24)|('S'<<16)|('S'<<8)|('F'))  //鏁板瓧绛惧悕閿欒
+#define RET_SM2_SIGN_ERROR        (('R'<<24)|('S'<<16)|('S'<<8)|('E'))  //鏁板瓧绛惧悕閿欒
+#define RET_SM2_VERIFY_SUCCESS    (('R'<<24)|('S'<<16)|('V'<<8)|('S'))  //鏁板瓧绛惧悕楠岃瘉鎴愬姛
+#define RET_SM2_VERIFY_FAILURE    (('R'<<24)|('S'<<16)|('V'<<8)|('F'))  //鏁板瓧绛惧悕楠岃瘉澶辫触
+#define RET_SM2_VERIFY_ERROR      (('R'<<24)|('S'<<16)|('V'<<8)|('E'))  //鏁板瓧绛惧悕楠岃瘉閿欒
+
+
+/**
+  * @method	SM2_Genkey
+  * @brief	SM2 瀵嗛挜鐢熸垚鍑芥暟锛岀敤浜庣敓鎴 SM2 瀵嗛挜
+  * @param	key   : SM2 绉侀挜锛堣緭鍑哄弬鏁帮級
+  * @param	para  : 妞渾鏇茬嚎鍙傛暟锛堣緭鍏ュ弬鏁帮級
+  * @param	f_rng : 闅忔満鏁板嚱鏁帮紙杈撳叆鍙傛暟锛
+  * @param	p_rng : 闅忔満鏁板嚱鏁板弬鏁帮紙杈撳叆鍙傛暟锛
+  * @retval RET_ECC_KEY_GEN_SUCCESS or RET_SM2_KEY_GEN_ERROR
+  */
+uint32_t SM2_Genkey(SM2_PrivateKeyTypeDef *key, const SM2_EllipseParaTypeDef *para, 
+                    rng_callback f_rng, void *p_rng);
+
+/**
+  * @method	SM2_Hash_z
+  * @brief	get sm2 sign para Za
+  * @param	Za     : the Za para of sm2 sign
+  * @param	IDa    : user id
+  * @param	IDalen : the bits of user id (8 * (number of bytes))
+  * @param	para   : sm2 paras
+  * @param	key    : sm2 public key
+  * @retval nil
+  */
+uint32_t SM2_Hash_Za(uint8_t *Za, uint8_t *IDa, uint16_t IDalen, SM2_EllipseParaTypeDef *para, SM2_PublicKeyTypeDef *key, uint16_t block_size);
+uint32_t SM2_Hash_z(uint8_t *Za, uint8_t *IDa, uint16_t IDalen, SM2_EllipseParaTypeDef *para, SM2_PublicKeyTypeDef *key);
+
+/**
+  * @method	SM2_Hash_e
+  * @brief	get sm2 sign para e
+  * @param	e    : the e para of sm2 sign (e is already cover bytes to integer)
+  * @param	Za   : the Za para of sm2 sign
+  * @param	m    : message
+  * @param	mlen : bytes of message
+  * @retval nil
+  */
+uint32_t SM2_Hash_e(uint32_t *e, uint8_t *Za, uint8_t *m, uint32_t mlen);
+
+/**
+  * @method	SM2_Enc
+  * @brief	SM2 鍏挜鍔犺В瀵嗗嚱鏁帮紝浣跨敤 SM2 鍏挜瀵规暟鎹繘琛屽姞瀵嗘垨瑙ｅ瘑鎿嶄綔
+  * @param	output : 杈撳嚭鏁版嵁缂撳啿鍖虹殑鎸囬拡锛堣緭鍑哄弬鏁帮級
+  * @param	Olen   : 杈撳嚭鏁版嵁闀垮害锛堣緭鍑哄弬鏁帮級
+  * @param	input  : 杈撳叆鏁版嵁缂撳啿鍖虹殑鎸囬拡锛堣緭鍏ュ弬鏁帮級
+  * @param	ilen   : 杈撳叆鏁版嵁闀垮害锛堣緭鍏ュ弬鏁帮級
+  * @param	key    : SM2 鍏挜锛堣緭鍏ュ弬鏁帮級
+  * @param	para   : 妞渾鏇茬嚎鍙傛暟锛堣緭鍏ュ弬鏁帮級
+  * @param	f_rng  : 闅忔満鏁板嚱鏁帮紙杈撳叆鍙傛暟锛
+  * @param	p_rng  : 闅忔満鏁板嚱鏁板弬鏁帮紙杈撳叆鍙傛暟锛
+  * @retval RET_SM2_ENC_SUCCESS or RET_SM2_ENC_FAILURE
+  */
+uint32_t SM2_Enc(uint8_t *output, uint32_t *olen,
+                 uint8_t *input, uint32_t ilen,
+                 SM2_PublicKeyTypeDef *key,  SM2_EllipseParaTypeDef *para,
+                 rng_callback f_rng, void *p_rng);
+
+/**
+  * @method	SM2_Dec
+  * @brief	SM2 绉侀挜鍔犺В瀵嗗嚱鏁帮紝浣跨敤 SM2 绉侀挜瀵规暟鎹繘琛屽姞瀵嗘垨瑙ｅ瘑鎿嶄綔
+  * @param	output : 杈撳嚭鏁版嵁缂撳啿鍖虹殑鎸囬拡锛堣緭鍑哄弬鏁帮級
+  * @param	olen   : 杈撳嚭鏁版嵁闀垮害锛堣緭鍑哄弬鏁帮級
+  * @param	input  : 杈撳叆鏁版嵁缂撳啿鍖虹殑鎸囬拡锛堣緭鍏ュ弬鏁帮級
+  * @param	ilen   : 杈撳叆鏁版嵁闀垮害锛堣緭鍏ュ弬鏁帮級
+  * @param	key    : SM2 绉侀挜锛堣緭鍏ュ弬鏁帮級
+  * @param	para   : 妞渾鏇茬嚎鍙傛暟锛堣緭鍏ュ弬鏁帮級
+  * @param	f_rng  : 闅忔満鏁板嚱鏁帮紙杈撳叆鍙傛暟锛
+  * @param	p_rng  : 闅忔満鏁板嚱鏁板弬鏁帮紙杈撳叆鍙傛暟锛
+  * @retval RET_SM2_DEC_SUCCESS or RET_SM2_DEC_FAILURE
+  */
+uint32_t SM2_Dec(uint8_t *output, uint32_t *olen,
+                 uint8_t *input, uint32_t ilen,
+                 SM2_PrivateKeyTypeDef *key,  SM2_EllipseParaTypeDef *para,
+                 rng_callback f_rng, void *p_rng);
+					
+/**
+  * @method	SM2_DigitalSignWith_e
+  * @brief	SM2 鏁板瓧绛惧悕鍑芥暟
+  * @param	sign  : SM2 鏁板瓧绛惧悕缁撴灉锛堣緭鍑哄弬鏁帮級
+  * @param	e     : hash 鍊硷紙杈撳叆鍙傛暟锛
+  * @param	msg   : 绛惧悕娑堟伅杈撳叆鏁版嵁缂撳啿鍖虹殑鎸囬拡锛堣緭鍏ュ弬鏁帮級
+  * @param	mlen  : 绛惧悕娑堟伅鏁版嵁闀垮害锛堣緭鍏ュ弬鏁帮級
+  * @param	key   : SM2 绉侀挜锛堣緭鍏ュ弬鏁帮級
+  * @param	para  : 妞渾鏇茬嚎鍙傛暟锛堣緭鍏ュ弬鏁帮級
+  * @param	f_rng : 闅忔満鏁板嚱鏁帮紙杈撳叆鍙傛暟锛
+  * @param	p_rng : 闅忔満鏁板嚱鏁板弬鏁帮紙杈撳叆鍙傛暟锛
+  * @retval RET_SM2_SIGN_SUCCESS or RET_SM2_SIGN_FAILURE
+  */
+uint32_t SM2_DigitalSignWith_e(SM2_SignTypeDef *sign, uint32_t *e,
+                               uint8_t *msg, uint32_t mlen,
+                               SM2_PrivateKeyTypeDef *key, SM2_EllipseParaTypeDef *para,
+                               rng_callback f_rng, void *p_rng, uint8_t config);
+
+/**
+  * @method	SM2_VerifySignWith_e
+  * @brief	SM2 绛惧悕楠岃瘉鍑芥暟
+  * @param	sign  : SM2 鏁板瓧绛惧悕缁撴灉锛堣緭鍑哄弬鏁帮級
+  * @param	e     : hash 鍊硷紙杈撳叆鍙傛暟锛
+  * @param	msg   : 绛惧悕娑堟伅杈撳叆鏁版嵁缂撳啿鍖虹殑鎸囬拡锛堣緭鍏ュ弬鏁帮級
+  * @param	mlen  : 绛惧悕娑堟伅鏁版嵁闀垮害锛堣緭鍏ュ弬鏁帮級
+  * @param	key   : SM2 绉侀挜锛堣緭鍏ュ弬鏁帮級
+  * @param	para  : 妞渾鏇茬嚎鍙傛暟锛堣緭鍏ュ弬鏁帮級
+  * @param	f_rng : 闅忔満鏁板嚱鏁帮紙杈撳叆鍙傛暟锛
+  * @param	p_rng : 闅忔満鏁板嚱鏁板弬鏁帮紙杈撳叆鍙傛暟锛
+  * @retval RET_SM2_VERIFY_SUCCESS or RET_SM2_VERIFY_FAILURE
+  */
+uint32_t SM2_VerifySignWith_e(SM2_SignTypeDef *sign, uint32_t *e,
+                              uint8_t *msg, uint32_t mlen,
+                              SM2_PublicKeyTypeDef *key, SM2_EllipseParaTypeDef *para,
+                              rng_callback f_rng, void *p_rng, uint8_t config);
+#endif 
Index: yc_crypt/yc_sm3.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_crypt/yc_sm3.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_crypt/yc_sm3.h	(working copy)
@@ -0,0 +1,58 @@
+
+#ifndef __YC_SM3_H__
+#define __YC_SM3_H__
+
+#include "yc3121.h"
+#include "yc_crypt.h"
+#include "system.h"
+
+#define RET_SM3_BUSY         (('R'<<24)|('S'<<16)|('3'<<8)|('B'))  //
+#define RET_SM3_SUCCESS      (('R'<<24)|('S'<<16)|('3'<<8)|('S'))  //
+#define RET_SM3_FAILE        (('R'<<24)|('S'<<16)|('3'<<8)|('F'))  //
+
+#define RET_SM3_MAC_SUCCESS  (('S'<<24)|('3'<<16)|('M'<<8)|('U'))  //RET_SM3_SUCCESS 璁＄畻鎴愬姛
+#define RET_SM4_MAC_FAILURE  (('S'<<24)|('3'<<16)|('M'<<8)|('F'))  //RET_SM3_BUSY 璁＄畻閿欒
+
+/**
+  * @method	sm3
+  * @brief	SM3 Hash Check
+  * @param	output : output data buffer
+  * @param	input  : input data buffer
+  * @param	ibytes : size of input data
+  * @retval SM3_SUCCESS or SM3_BUSY
+  */
+uint32_t SM3(uint8_t *output, uint8_t *input,uint32_t ibytes);
+
+/*
+ * @brief  sm3 hash check
+ * @param  output     : output data buffer 
+ * @param  input      : input data buffer
+ * @param  ibytes     : size of input data (when istep=0~1 ibytes must 64 multiples) 
+ * @param  totalbytes : size of all input datas
+ * @param  istep      : 0~2
+ * @return SM3_SUCCESS or SM3_BUSY or SM3_FAILE
+ */
+uint32_t SM3_Enhance(uint8_t *output, uint8_t *input,uint32_t ibytes,uint32_t totalbytes,uint32_t istep);
+
+/*
+ * @brief  sm3 hash check
+ * @param  output : output data buffer 
+ * @param  input  : input data 
+ * @param  istep  : number of data
+ * @param  isend  : is last data
+ * @return SM3_SUCCESS or SM3_BUSY or SM3_FAILE
+ */
+uint32_t SM3_BYTE(uint8_t *output, uint8_t input,uint32_t istep,uint8_t isend);
+
+/*
+ * @brief  sm3-mac
+ * @param  output  : output data buffer 
+ * @param  input   : input data  buffer
+ * @param  ibytes  : size of input buffer
+ * @param  key     : key buffer
+ * @param  key_len : size of key buffer
+ * @return SM3_MAC_SUCCESS  or SM3_MAC_FAILE
+ */
+uint32_t SM3_MAC(uint8_t *output, uint8_t *input,uint32_t ibytes,uint8_t *key,uint32_t key_len);
+
+#endif
Index: yc_crypt/yc_sm4.h
===================================================================
--- /YC3121_SDK/fw/sdk/yc_crypt/yc_sm4.h	(nonexistent)
+++ /YC3121_SDK/fw/sdk/yc_crypt/yc_sm4.h	(working copy)
@@ -0,0 +1,70 @@
+#ifndef __YC_SM4_H__
+#define __YC_SM4_H__
+
+#include "yc3121.h"
+#include "yc_crypt.h"
+#include "system.h"
+
+#define SM4_FLOW_CONTROL
+
+#define RET_SM4_SUCCESS             (('S'<<24)|('4'<<16)|('S'<<8)|('U'))  //璁＄畻鎴愬姛
+#define RET_SM4_FAILURE             (('S'<<24)|('4'<<16)|('S'<<8)|('F'))  //璁＄畻閿欒
+#define RET_SM4_KEY_IS_NULL         (('S'<<24)|('4'<<16)|('K'<<8)|('N'))
+#define RET_SM4_PACK_MODE_ERROR     (('S'<<24)|('4'<<16)|('P'<<8)|('E'))
+#define RET_SM4_OUTBUF_TOO_SMALL    (('S'<<24)|('4'<<16)|('O'<<8)|('S'))
+#define RET_SM4_INPUT_SIZE_ERROR    (('S'<<24)|('4'<<16)|('P'<<8)|('S'))
+#define RET_SM4_KEY_READBACK_ERROR  (('S'<<24)|('4'<<16)|('K'<<8)|('R'))
+#define RET_SM4_RESULT_CHECK_ERROR  (('S'<<24)|('4'<<16)|('R'<<8)|('C'))
+
+
+#define SM4_TYPE_DES_ENC            (('4'<<24)|('T'<<16)|('D'<<8)|('E'))    
+#define SM4_TYPE_DES_DEC            (('4'<<24)|('T'<<16)|('D'<<8)|('D'))    
+
+
+#define SM4_KEY_SIZE  (128 / 8)
+#define SM4_IV_SIZE   (128 / 8)
+	
+typedef uint8_t SM4_KeyTypeDef[SM4_KEY_SIZE];
+typedef uint8_t SM4_IvTypeDef[SM4_IV_SIZE];
+
+/**
+  * @method	SM4_Enc
+  * @brief	sm4 encrypt function
+  * @param	pack_mode : block encryption mode ECB or CBC
+  * @param	output    : the pointer of output data buffer
+  * @param	obytes    : the size of output data buffer
+  *                     ("obytes" must be bigger or equal then "iBytes")
+  * @param	input     : the pointer of input data buffer
+  * @param	ibytes    : the size of input data buffer
+  *                     ("ibytes" must be an integer multiple of key length)
+  * @param	key       : SM4 key
+  * @param	iv        : initialization vector
+  * @retval SM4 return value
+  */
+uint32_t SM4_Enc(PACK_ModeTypeDef pack_mode, 
+                 uint8_t *output, uint32_t obytes, 
+                 uint8_t *input, uint32_t ibytes, 
+                 SM4_KeyTypeDef key, SM4_IvTypeDef iv,
+                 rng_callback f_rng, void *p_rng);
+
+/**
+  * @method	SM4_Dec
+  * @brief	SM4 decrypt function
+  * @param	pack_mode : block encryption mode ECB or CBC
+  * @param	output    : the pointer of output data buffer
+  * @param	obytes    : the size of output data buffer
+  *                     ("obytes" must be bigger or equal then "iBytes")
+  * @param	input     : the pointer of input data buffer
+  * @param	ibytes    : the size of input data buffer
+  *                     ("ibytes" must be an integer multiple of key length)
+  * @param	key       : SM4 key
+  * @param	iv        : initialization vector
+  * @retval SM4 return value
+  */
+uint32_t SM4_Dec(PACK_ModeTypeDef pack_mode, 
+                 uint8_t *output, uint32_t obytes, 
+                 uint8_t *input, uint32_t ibytes, 
+                 SM4_KeyTypeDef key, SM4_IvTypeDef iv,
+                 rng_callback f_rng, void *p_rng);
+
+#endif
