- unsigned int num;
- //任务2:产生一个随机数
- void task2(void *parameter)
- {
- while(1)
- {
- num = trng_module_get_data();
- rt_thread_delay(500);
- rt_kprintf("任务2正在运行 产生了一个随机数:%d \r\n\r\n",num);
- }
- }
//任务3:测试AES-CBC 加密和解密
- /* aes cbc key = 128bits
- * input 32 43 f6 a8 88 5a 30 8d 31 31 98 a2 e0 37 07 34
- * 32 43 f6 a8 88 5a 30 8d 31 31 98 a2 e0 37 07 34
- * 32 43 f6 a8 88 5a 30 8d 31 31 98 a2 e0 37 07 34
- * 32 43 f6 a8 88 5a 30 8d 31 31 98 a2 e0 37 07 34
- * cipher key 2b 7e 15 16 28 ae d2 a6 ab f7 15 88 09 cf 4f 3c
- * iv f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff
- * refer result 92 5a fa 80 48 a0 7d 7a d8 68 c5 f2 c3 94 68 a6
- 1d b9 bf 55 f0 be 88 67 5f 04 cb c2 fa c9 57 8c
- f4 a4 7f ad 59 61 e3 22 d6 a0 44 06 01 75 42 89
- 1c 22 ee 2f a0 46 08 aa c2 2f 64 29 92 40 06 6d
- */
- void test_aes_cbc_128()
- {
-
- md_crypt_set_key0(CRYPT, key[3]);
- md_crypt_set_key1(CRYPT, key[2]);
- md_crypt_set_key2(CRYPT, key[1]);
- md_crypt_set_key3(CRYPT, key[0]);
- md_crypt_set_iv0(CRYPT, ivr[3]);
- md_crypt_set_iv1(CRYPT, ivr[2]);
- md_crypt_set_iv2(CRYPT, ivr[1]);
- md_crypt_set_iv3(CRYPT, ivr[0]);
- //打印加密前的数据
- rt_kprintf("加密前的数据 :\r\n");
- for(loop =0;loop<16;loop++)
- {
- rt_kprintf("0X%08x ",plain[loop]);
- }
- rt_kprintf("\r\n");
- md_crypt_enable_iv(CRYPT);//开始AES加密
- md_crypt_encrypt(&h_crypt1,(uint8_t*)plain, (uint8_t*)result, sizeof(plain));
- //打印加密后的数据
- rt_kprintf("加密后的数据 :\r\n");
- for(loop =0;loop<16;loop++)
- {
- rt_kprintf("0X%08x ",result[loop]);
- }
- rt_kprintf("\r\n");
-
-
- md_crypt_set_key0(CRYPT, key[3]);
- md_crypt_set_key1(CRYPT, key[2]);
- md_crypt_set_key2(CRYPT, key[1]);
- md_crypt_set_key3(CRYPT, key[0]);
- md_crypt_set_iv0(CRYPT, ivr[3]);
- md_crypt_set_iv1(CRYPT, ivr[2]);
- md_crypt_set_iv2(CRYPT, ivr[1]);
- md_crypt_set_iv3(CRYPT, ivr[0]);
- md_crypt_enable_iv(CRYPT);
- md_crypt_decrypt(&h_crypt1,(uint8_t*)expect, (uint8_t*)result, sizeof(expect)); //开始AES解密
- //打印加密后的数据
- rt_kprintf("解密后的数据 :\r\n");
- for(loop =0;loop<16;loop++)
- {
- rt_kprintf("0X%08x ",result[loop]);
- }
- rt_kprintf("\r\n\r\n");
-
- //输出解答密过程的错误率
- }
- //任务3:测试AES-CBC 加密和解密
- void task3(void *parameter)
- {
- while(1)
- {
- rt_kprintf("任务3正在运行 测试AES_CBC128加密和解密算法 \r\n\r\n");
- test_aes_cbc_128();
- rt_thread_delay(1000);
- }
- }
//任务4:测试CRC
- uint32_t res = 0;
- uint16_t i = 0;
- uint8_t crc_buf[4] = {0, 1, 0, 2};
- //测试CRC
- void test_crc()
- {
- for (i = 0; i < 4; i++)
- md_crc_write_data(CRC, crc_buf[i]);
- /* start calculate and result is 0x93b2*/
- res = CRC->CHECKSUM;
- rt_kprintf("CRC 算法输出的结果: 0X%04x:\r\n\r\n",res);
- }
- //任务4:测试CRC
- void task4(void *parameter)
- {
- while(1)
- {
- rt_kprintf("任务4正在运行 测试CRC算法 \r\n");
- test_crc();
- rt_thread_delay(1000);
- }
- }
//任务5:测试旋钮ADC