Index: CryptTest/RSA_GENKEY_TEST/user/main.c
===================================================================
--- /YC3121_demo/ModuleDemo/CryptTest/RSA_GENKEY_TEST/user/main.c	(revision 597)
+++ /YC3121_demo/ModuleDemo/CryptTest/RSA_GENKEY_TEST/user/main.c	(working copy)
@@ -34,12 +34,14 @@
 /* Private typedef -----------------------------------------------------------*/
 /* Private define ------------------------------------------------------------*/
 #define uartBaud 115200
+#define PLAIN "1234567890"
 
 /* Private macro -------------------------------------------------------------*/
 /* Private variables ---------------------------------------------------------*/
 /* Private function prototypes -----------------------------------------------*/
 void UART_Configuration(void);
 void test_rsa_genrsakey(void);
+int bn_read_string_to_bytes( uint8_t *r, uint32_t len, const char *s );
 
 /**
   * @brief  Main program
@@ -93,32 +95,122 @@
 
 void test_rsa_genrsakey(void)
 {
-		RSA_PrivateKeyTypeDef pri_key;
+	RSA_PrivateKeyTypeDef pri_key;
+	RSA_PublicKeyTypeDef pub_key;
 	
-		MyPrintf("\r\n RSA_GenerateKey 1024");
-		
-		RSA_GenerateKey(&pri_key,0x10001,1024,&RAND_RandP, NULL);
-		MyPrintf("\r\n RSA_GenerateKey OK ");
-		memcpy_r(pri_key.p,pri_key.p,pri_key.bytes/2);
-		memcpy_r(pri_key.q,pri_key.q,pri_key.bytes/2);
-		memcpy_r(pri_key.n,pri_key.n,pri_key.bytes);
-		
-		printv(pri_key.p,pri_key.bytes/2,"p");
-		printv(pri_key.q,pri_key.bytes/2,"q");
-		
-		printv(pri_key.n,pri_key.bytes,"n");
+	uint8_t plain[2048 / 8];
+	uint8_t cipher[2048 / 8];
+	uint8_t tmp0[2048 / 8];
 	
-		MyPrintf("\r\n RSA_GenerateKey 2048");
-	  RSA_GenerateKey(&pri_key,0x10001,2048,&RAND_RandP, NULL);
-		MyPrintf("\r\n RSA_GenerateKey OK ");
-		memcpy_r(pri_key.p,pri_key.p,pri_key.bytes/2);
-		memcpy_r(pri_key.q,pri_key.q,pri_key.bytes/2);
-		memcpy_r(pri_key.n,pri_key.n,pri_key.bytes);
-		
-		printv(pri_key.p,pri_key.bytes/2,"p");
-		printv(pri_key.q,pri_key.bytes/2,"q");
-		
-		printv(pri_key.n,pri_key.bytes,"n");
+	MyPrintf("\r\n RSA_GenerateKey 1024");
+
+	RSA_GenerateKey(&pri_key, 0x10001, 1024, &RAND_RandP, NULL);
+	MyPrintf("\r\n RSA_GenerateKey OK ");
+	memcpy_r(pri_key.p, pri_key.p, pri_key.bytes / 2);
+	memcpy_r(pri_key.q, pri_key.q, pri_key.bytes / 2);
+	memcpy_r(pri_key.n, pri_key.n, pri_key.bytes);
+	
+	printv(pri_key.p, pri_key.bytes / 2, "p");
+	printv(pri_key.q, pri_key.bytes / 2, "q");
+
+	printv(pri_key.n, pri_key.bytes, "n");
+	
+	MyPrintf("\n*************RSA 1024 Test In*************\n");
+	pri_key.bytes = 1024/8;//密钥bit长度
+
+	memcpy_r(pri_key.p, pri_key.p, pri_key.bytes / 2);
+	memcpy_r(pri_key.q, pri_key.q, pri_key.bytes / 2);
+	memcpy_r(pri_key.n, pri_key.n, pri_key.bytes);
+	
+	pub_key.bytes = pri_key.bytes;
+	memcpy(pub_key.e, pri_key.e, sizeof(pri_key.e));
+	memcpy(pub_key.n, pri_key.n, sizeof(pri_key.n));
+	memcpy(pub_key.n_c, pri_key.n_c, sizeof(pri_key.n_c));
+	memcpy(pub_key.n_q, pri_key.n_q, sizeof(pri_key.n_q));
+	
+	bn_read_string_to_bytes(plain, pri_key.bytes, PLAIN);
+	memcpy_r(plain, plain, 128);
+	
+	MyPrintf("\r\nRSA_public ret:%x\n", RSA_Public(cipher, plain, &pub_key, &RAND_RandP, NULL));
+	MyPrintf("\r\nRSA_private_crt ret:%x\n",RSA_Private_crt(tmp0, cipher,&pri_key, &RAND_RandP, NULL));
+	printv(tmp0, 10, "tmp0");
+	MyPrintf("\r\nTo compare test:%2x\n",(0 == memcmp(tmp0, plain, pri_key.bytes)));
+	
+	MyPrintf("\r\n RSA_GenerateKey 2048");
+	
+	RSA_GenerateKey(&pri_key, 0x10001, 2048, &RAND_RandP, NULL);
+	MyPrintf("\r\n RSA_GenerateKey OK ");
+	memcpy_r(pri_key.p, pri_key.p, pri_key.bytes / 2);
+	memcpy_r(pri_key.q, pri_key.q, pri_key.bytes / 2);
+	memcpy_r(pri_key.n, pri_key.n, pri_key.bytes);
+
+	printv(pri_key.p, pri_key.bytes / 2, "p");
+	printv(pri_key.q, pri_key.bytes / 2, "q");
+
+	printv(pri_key.n, pri_key.bytes, "n");
+	
+	MyPrintf("\n*************RSA 2048 Test In*************\n");
+	pri_key.bytes = 2048/8;//密钥bit长度
+
+	memcpy_r(pri_key.p, pri_key.p, pri_key.bytes / 2);
+	memcpy_r(pri_key.q, pri_key.q,pri_key.bytes / 2);
+	memcpy_r(pri_key.n, pri_key.n, pri_key.bytes);
+	
+	pub_key.bytes = pri_key.bytes;
+	memcpy(pub_key.e, pri_key.e, sizeof(pri_key.e));
+	memcpy(pub_key.n, pri_key.n, sizeof(pri_key.n));
+	memcpy(pub_key.n_c, pri_key.n_c, sizeof(pri_key.n_c));
+	memcpy(pub_key.n_q, pri_key.n_q, sizeof(pri_key.n_q));
+	
+	bn_read_string_to_bytes(plain, pri_key.bytes, PLAIN);
+	memcpy_r(plain, plain, 256);
+	
+	MyPrintf("\r\nRSA_public ret:%x\n", RSA_Public(cipher, plain, &pub_key, &RAND_RandP, NULL));
+	MyPrintf("\r\nRSA_private_crt ret:%x\n",RSA_Private_crt(tmp0, cipher,&pri_key, &RAND_RandP, NULL));
+	printv(tmp0, 10, "tmp0");
+	MyPrintf("\r\nTo compare test:%2x\n",(0 == memcmp(tmp0, plain, pri_key.bytes)));
+}
+
+/*
+ * Import from an ASCII string to an big endian data array
+ */
+
+static int bn_get_digit( uint32_t *d, char c )
+{
+    *d = 255;
+
+    if( c >= 0x30 && c <= 0x39 ) *d = c - 0x30;
+    if( c >= 0x41 && c <= 0x46 ) *d = c - 0x37;
+    if( c >= 0x61 && c <= 0x66 ) *d = c - 0x57;
+
+    if( *d >= (uint32_t) 16 )
+        return( -1 );
+
+    return( 0 );
+}
+
+int bn_read_string_to_bytes( uint8_t *r, uint32_t len, const char *s )
+{
+    uint32_t i, j, slen;
+    uint32_t d;
+	
+    slen = strlen( s );
+
+	if ((len * 2) < slen)
+		return(-1);
+
+	memset(r, 0, len);
+	
+	len = len - 1;
+	
+	for( i = slen, j = 0; i > 0; i--, j++)
+	{
+		if( -1 == bn_get_digit( &d, s[i - 1] ) )
+			return (-1);
+		r[len - j / 2] |= d << ( (j % 2) << 2 );
+	}
+
+    return( 0 );
 }
 
 /************************ (C) COPYRIGHT Yichip Microelectronics *****END OF FILE****/
Index: QSPI/QSPI_encrypt_rw/prj/MDK/Objects/YC3121_Keil.axf
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: QSPI/QSPI_encrypt_rw/prj/MDK/Objects/YC3121_Keil.axf
___________________________________________________________________
Deleted: svn:mime-type
## -1 +0,0 ##
-application/octet-stream
\ No newline at end of property
