mirror of
https://github.com/Fishwaldo/bl_mcu_sdk.git
synced 2025-07-05 12:28:45 +00:00
[update] update lhal, soc and demos
This commit is contained in:
parent
d44726c783
commit
c70a3cd8f0
80 changed files with 2206 additions and 323 deletions
|
@ -12,7 +12,7 @@ static uint8_t dma_tc_flag0 = 0;
|
|||
|
||||
#define ADC_CONVERT_COUNT 16
|
||||
|
||||
ATTR_NOCACHE_RAM_SECTION uint32_t raw_data[ADC_CONVERT_COUNT];
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION uint32_t raw_data[ADC_CONVERT_COUNT];
|
||||
|
||||
void dma0_ch0_isr(void *arg)
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@ int main(void)
|
|||
|
||||
struct bflb_adc_channel_s chan;
|
||||
|
||||
chan.pos_chan = ADC_CHAN_TSEN_P;
|
||||
chan.pos_chan = ADC_CHANNEL_TSEN_P;
|
||||
chan.neg_chan = ADC_CHANNEL_GND;
|
||||
|
||||
bflb_adc_init(adc, &cfg);
|
||||
|
|
|
@ -21,7 +21,7 @@ int main(void)
|
|||
|
||||
struct bflb_adc_channel_s chan;
|
||||
|
||||
chan.pos_chan = ADC_CHAN_VABT_HALF;
|
||||
chan.pos_chan = ADC_CHANNEL_VABT_HALF;
|
||||
chan.neg_chan = ADC_CHANNEL_GND;
|
||||
|
||||
bflb_adc_init(adc, &cfg);
|
||||
|
|
|
@ -6,4 +6,4 @@ find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})
|
|||
|
||||
sdk_set_main_file(main.c)
|
||||
|
||||
project(dma)
|
||||
project(dma_normal)
|
|
@ -1,5 +1,5 @@
|
|||
SDK_DEMO_PATH ?= .
|
||||
BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../..
|
||||
BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../../..
|
||||
|
||||
export BL_SDK_BASE
|
||||
|
103
examples/peripherals/dma/dma_normal/main.c
Normal file
103
examples/peripherals/dma/dma_normal/main.c
Normal file
|
@ -0,0 +1,103 @@
|
|||
#include "bflb_mtimer.h"
|
||||
#include "bflb_dma.h"
|
||||
|
||||
#define DMA_BUFFER_LENGTH 4100
|
||||
|
||||
extern void board_init(void);
|
||||
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t src1_buffer[DMA_BUFFER_LENGTH];
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t src2_buffer[DMA_BUFFER_LENGTH];
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t src3_buffer[DMA_BUFFER_LENGTH];
|
||||
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t dst1_buffer[DMA_BUFFER_LENGTH];
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t dst2_buffer[DMA_BUFFER_LENGTH];
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t dst3_buffer[DMA_BUFFER_LENGTH];
|
||||
static uint8_t dma_tc_flag0 = 0;
|
||||
|
||||
struct bflb_device_s *dma0_ch0;
|
||||
|
||||
void dma0_ch0_isr(void *arg)
|
||||
{
|
||||
dma_tc_flag0++;
|
||||
printf("tc done\r\n");
|
||||
}
|
||||
|
||||
void sram_init()
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < DMA_BUFFER_LENGTH; i++) {
|
||||
src1_buffer[i] = i & 0xff;
|
||||
src2_buffer[i] = (i * 0x07) & 0xff;
|
||||
src3_buffer[i] = (i * 0x0b) & 0xff;
|
||||
}
|
||||
|
||||
memset(dst1_buffer, 0, DMA_BUFFER_LENGTH);
|
||||
memset(dst2_buffer, 0, DMA_BUFFER_LENGTH);
|
||||
memset(dst3_buffer, 0, DMA_BUFFER_LENGTH);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
board_init();
|
||||
|
||||
sram_init();
|
||||
|
||||
printf("dma memory case:\r\n");
|
||||
dma0_ch0 = bflb_device_get_by_name("dma0_ch0");
|
||||
|
||||
struct bflb_dma_channel_config_s config;
|
||||
|
||||
config.direction = DMA_MEMORY_TO_MEMORY;
|
||||
config.src_req = 0;
|
||||
config.dst_req = 0;
|
||||
config.src_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
|
||||
config.dst_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
|
||||
config.src_burst_count = DMA_BURST_INCR1;
|
||||
config.dst_burst_count = DMA_BURST_INCR1;
|
||||
config.src_width = DMA_DATA_WIDTH_32BIT;
|
||||
config.dst_width = DMA_DATA_WIDTH_32BIT;
|
||||
bflb_dma_channel_init(dma0_ch0, &config);
|
||||
|
||||
bflb_dma_channel_irq_attach(dma0_ch0, dma0_ch0_isr, NULL);
|
||||
|
||||
struct bflb_dma_channel_lli_pool_s lli[20]; /* max trasnfer size 4064 * 20 */
|
||||
struct bflb_dma_channel_lli_transfer_s transfers[3];
|
||||
|
||||
transfers[0].src_addr = (uint32_t)src1_buffer;
|
||||
transfers[0].dst_addr = (uint32_t)dst1_buffer;
|
||||
transfers[0].nbytes = DMA_BUFFER_LENGTH;
|
||||
|
||||
transfers[1].src_addr = (uint32_t)src2_buffer;
|
||||
transfers[1].dst_addr = (uint32_t)dst2_buffer;
|
||||
transfers[1].nbytes = DMA_BUFFER_LENGTH;
|
||||
|
||||
transfers[2].src_addr = (uint32_t)src3_buffer;
|
||||
transfers[2].dst_addr = (uint32_t)dst3_buffer;
|
||||
transfers[2].nbytes = DMA_BUFFER_LENGTH;
|
||||
|
||||
bflb_dma_channel_lli_reload(dma0_ch0, lli, 20, transfers, 3);
|
||||
bflb_dma_channel_start(dma0_ch0);
|
||||
while (dma_tc_flag0 != 3) {
|
||||
bflb_mtimer_delay_ms(1);
|
||||
}
|
||||
|
||||
/* Check data */
|
||||
for (i = 0; i < DMA_BUFFER_LENGTH; i++) {
|
||||
if (src1_buffer[i] != dst1_buffer[i]) {
|
||||
printf("Error! index: %ld, src1: 0x%02x, dst1: 0x%02x\r\n", i, src1_buffer[i], dst1_buffer[i]);
|
||||
}
|
||||
if (src2_buffer[i] != dst2_buffer[i]) {
|
||||
printf("Error! index: %ld, src2: 0x%02x, dst2: 0x%02x\r\n", i, src2_buffer[i], dst2_buffer[i]);
|
||||
}
|
||||
if (src3_buffer[i] != dst3_buffer[i]) {
|
||||
printf("Error! index: %ld, src3: 0x%02x, dst3: 0x%02x\r\n", i, src3_buffer[i], dst3_buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
printf("end\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
include(proj.conf)
|
||||
|
||||
find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})
|
||||
|
||||
sdk_set_main_file(main.c)
|
||||
|
||||
project(dma_reduce_or_add)
|
13
examples/peripherals/dma/dma_reduce_or_add/Makefile
Normal file
13
examples/peripherals/dma/dma_reduce_or_add/Makefile
Normal file
|
@ -0,0 +1,13 @@
|
|||
SDK_DEMO_PATH ?= .
|
||||
BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../../..
|
||||
|
||||
export BL_SDK_BASE
|
||||
|
||||
CHIP ?= bl616
|
||||
BOARD ?= bl616dk
|
||||
CROSS_COMPILE ?= riscv64-unknown-elf-
|
||||
|
||||
# add custom cmake definition
|
||||
#cmake_definition+=-Dxxx=sss
|
||||
|
||||
include $(BL_SDK_BASE)/project.build
|
188
examples/peripherals/dma/dma_reduce_or_add/main.c
Normal file
188
examples/peripherals/dma/dma_reduce_or_add/main.c
Normal file
|
@ -0,0 +1,188 @@
|
|||
#include "bflb_mtimer.h"
|
||||
#include "bflb_dma.h"
|
||||
|
||||
#define DMA_BUFFER_MAX_LENGTH 128
|
||||
#define DMA_TRANSFER_LENGTH 64
|
||||
|
||||
extern void board_init(void);
|
||||
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t src_buffer[DMA_BUFFER_MAX_LENGTH];
|
||||
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t dst_buffer[DMA_BUFFER_MAX_LENGTH];
|
||||
static uint8_t dma_tc_flag0 = 0;
|
||||
|
||||
struct bflb_device_s *dma0_ch0;
|
||||
|
||||
void dma0_ch0_isr(void *arg)
|
||||
{
|
||||
dma_tc_flag0++;
|
||||
printf("tc done\r\n");
|
||||
}
|
||||
|
||||
void sram_init()
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < DMA_BUFFER_MAX_LENGTH; i++) {
|
||||
src_buffer[i] = i & 0xff;
|
||||
}
|
||||
|
||||
memset(dst_buffer, 0, DMA_BUFFER_MAX_LENGTH);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint32_t i;
|
||||
struct bflb_dma_channel_lli_pool_s lli[20];
|
||||
struct bflb_dma_channel_lli_transfer_s transfers[3];
|
||||
|
||||
board_init();
|
||||
|
||||
sram_init();
|
||||
|
||||
printf("dma memory case:\r\n");
|
||||
dma0_ch0 = bflb_device_get_by_name("dma0_ch0");
|
||||
|
||||
struct bflb_dma_channel_config_s config;
|
||||
|
||||
config.direction = DMA_MEMORY_TO_MEMORY;
|
||||
config.src_req = 0;
|
||||
config.dst_req = 0;
|
||||
config.src_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
|
||||
config.dst_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
|
||||
config.src_burst_count = DMA_BURST_INCR1;
|
||||
config.dst_burst_count = DMA_BURST_INCR4;
|
||||
config.src_width = DMA_DATA_WIDTH_32BIT;
|
||||
config.dst_width = DMA_DATA_WIDTH_8BIT;
|
||||
bflb_dma_channel_init(dma0_ch0, &config);
|
||||
|
||||
bflb_dma_channel_irq_attach(dma0_ch0, dma0_ch0_isr, NULL);
|
||||
|
||||
/* Disable reduce mode, transfer length = nbytes = 64 byte */
|
||||
transfers[0].src_addr = (uint32_t)src_buffer;
|
||||
transfers[0].dst_addr = (uint32_t)dst_buffer;
|
||||
transfers[0].nbytes = DMA_TRANSFER_LENGTH;
|
||||
bflb_dma_channel_lli_reload(dma0_ch0, lli, 20, transfers, 1);
|
||||
|
||||
bflb_dma_channel_start(dma0_ch0);
|
||||
|
||||
while (dma_tc_flag0 == 0) {
|
||||
bflb_mtimer_delay_ms(1);
|
||||
}
|
||||
|
||||
/* Check 0~63 data */
|
||||
for (i = 0; i < DMA_TRANSFER_LENGTH; i++) {
|
||||
if (src_buffer[i] != dst_buffer[i]) {
|
||||
printf("Error! index: %ld, src: 0x%02x, dst: 0x%02x\r\n", i, src_buffer[i], dst_buffer[i]);
|
||||
}
|
||||
}
|
||||
/* Check 64~127 data, should be 0 */
|
||||
for (i = DMA_TRANSFER_LENGTH; i < DMA_BUFFER_MAX_LENGTH; i++) {
|
||||
if (dst_buffer[i] != 0) {
|
||||
printf("Error! Dst should be 0. index: %ld, src: 0x%02x, dst: 0x%02x\r\n", i, src_buffer[i], dst_buffer[i]);
|
||||
}
|
||||
}
|
||||
printf("Check over\r\n\r\n");
|
||||
|
||||
memset(dst_buffer, 0, DMA_BUFFER_MAX_LENGTH);
|
||||
dma_tc_flag0 = 0;
|
||||
|
||||
/* Enable reduce mode, src_width = 32bit, dst_width = 8bit, nbytes = 64, transfer length = (nbytes - 1 * dst_width) = 63 byte */
|
||||
bflb_dma_feature_control(dma0_ch0, DMA_CMD_SET_REDUCE_MODE, 1);
|
||||
bflb_dma_channel_lli_reload(dma0_ch0, lli, 20, transfers, 1);
|
||||
|
||||
bflb_dma_channel_start(dma0_ch0);
|
||||
|
||||
while (dma_tc_flag0 == 0) {
|
||||
bflb_mtimer_delay_ms(1);
|
||||
}
|
||||
|
||||
/* Check 0~62 data */
|
||||
for (i = 0; i < DMA_TRANSFER_LENGTH - 1; i++) {
|
||||
if (src_buffer[i] != dst_buffer[i]) {
|
||||
printf("Error! index: %ld, src: 0x%02x, dst: 0x%02x\r\n", i, src_buffer[i], dst_buffer[i]);
|
||||
}
|
||||
}
|
||||
/* Check 63~127 data, should be 0 */
|
||||
for (i = DMA_TRANSFER_LENGTH - 1; i < DMA_BUFFER_MAX_LENGTH; i++) {
|
||||
if (dst_buffer[i] != 0) {
|
||||
printf("Error! Dst should be 0. index: %ld, src: 0x%02x, dst: 0x%02x\r\n", i, src_buffer[i], dst_buffer[i]);
|
||||
}
|
||||
}
|
||||
printf("Check over\r\n\r\n");
|
||||
|
||||
memset(dst_buffer, 0, DMA_BUFFER_MAX_LENGTH);
|
||||
dma_tc_flag0 = 0;
|
||||
|
||||
/* Disable reduce mode and enable add mode, src_width = 8bit, dst_width = 32bit, nbytes = 65, transfer length = nbytes + 3 = 68 byte, multiple of dst_width */
|
||||
bflb_dma_feature_control(dma0_ch0, DMA_CMD_SET_REDUCE_MODE, 0);
|
||||
bflb_dma_feature_control(dma0_ch0, DMA_CMD_SET_ADD_MODE, 1);
|
||||
|
||||
config.src_burst_count = DMA_BURST_INCR4;
|
||||
config.dst_burst_count = DMA_BURST_INCR1;
|
||||
config.src_width = DMA_DATA_WIDTH_8BIT;
|
||||
config.dst_width = DMA_DATA_WIDTH_32BIT;
|
||||
bflb_dma_channel_init(dma0_ch0, &config);
|
||||
|
||||
transfers[0].nbytes = DMA_TRANSFER_LENGTH + 1;
|
||||
bflb_dma_channel_lli_reload(dma0_ch0, lli, 20, transfers, 1);
|
||||
|
||||
bflb_dma_channel_start(dma0_ch0);
|
||||
|
||||
while (dma_tc_flag0 == 0) {
|
||||
bflb_mtimer_delay_ms(1);
|
||||
}
|
||||
|
||||
/* Check 0~64 data */
|
||||
for (i = 0; i < DMA_TRANSFER_LENGTH + 1; i++) {
|
||||
if (src_buffer[i] != dst_buffer[i]) {
|
||||
printf("Error! index: %ld, src: 0x%02x, dst: 0x%02x\r\n", i, src_buffer[i], dst_buffer[i]);
|
||||
}
|
||||
}
|
||||
/* Check 65~67 data */
|
||||
for (i = DMA_TRANSFER_LENGTH + 1; i < DMA_TRANSFER_LENGTH + 4; i++) {
|
||||
if (dst_buffer[i] == 0) {
|
||||
printf("Error! Dst should not be 0. index: %ld\r\n", i);
|
||||
} else {
|
||||
printf("Correct, meaningless data. index: %ld, src: 0x%02x, dst: 0x%02x\r\n", i, src_buffer[i], dst_buffer[i]);
|
||||
}
|
||||
}
|
||||
/* Check 68~127 data, should be 0 */
|
||||
for (i = DMA_TRANSFER_LENGTH + 4; i < DMA_BUFFER_MAX_LENGTH; i++) {
|
||||
if (dst_buffer[i] != 0) {
|
||||
printf("Error! Dst should be 0. index: %ld, src: 0x%02x, dst: 0x%02x\r\n", i, src_buffer[i], dst_buffer[i]);
|
||||
}
|
||||
}
|
||||
printf("Check over\r\n\r\n");
|
||||
|
||||
memset(dst_buffer, 0, DMA_BUFFER_MAX_LENGTH);
|
||||
dma_tc_flag0 = 0;
|
||||
|
||||
/* Disable add mode, src_width = 8bit, dst_width = 32bit, nbytes = 65, transfer length = nbytes - 1 = 64 byte, multiple of dst_width */
|
||||
bflb_dma_feature_control(dma0_ch0, DMA_CMD_SET_ADD_MODE, 0);
|
||||
bflb_dma_channel_lli_reload(dma0_ch0, lli, 20, transfers, 1);
|
||||
|
||||
bflb_dma_channel_start(dma0_ch0);
|
||||
|
||||
while (dma_tc_flag0 == 0) {
|
||||
bflb_mtimer_delay_ms(1);
|
||||
}
|
||||
|
||||
/* Check 0~63 data */
|
||||
for (i = 0; i < DMA_TRANSFER_LENGTH; i++) {
|
||||
if (src_buffer[i] != dst_buffer[i]) {
|
||||
printf("Error! index: %ld, src: 0x%02x, dst: 0x%02x\r\n", i, src_buffer[i], dst_buffer[i]);
|
||||
}
|
||||
}
|
||||
/* Check 64~127 data, should be 0 */
|
||||
for (i = DMA_TRANSFER_LENGTH; i < DMA_BUFFER_MAX_LENGTH; i++) {
|
||||
if (dst_buffer[i] != 0) {
|
||||
printf("Error! Dst should be 0. index: %ld, src: 0x%02x, dst: 0x%02x\r\n", i, src_buffer[i], dst_buffer[i]);
|
||||
}
|
||||
}
|
||||
printf("Check over\r\n\r\n");
|
||||
|
||||
printf("end\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
1
examples/peripherals/dma/dma_reduce_or_add/proj.conf
Normal file
1
examples/peripherals/dma/dma_reduce_or_add/proj.conf
Normal file
|
@ -0,0 +1 @@
|
|||
#set(CONFIG_XXX 1)
|
|
@ -1,84 +0,0 @@
|
|||
#include "bflb_mtimer.h"
|
||||
#include "bflb_dma.h"
|
||||
|
||||
extern void board_init(void);
|
||||
|
||||
static ATTR_NOCACHE_RAM_SECTION uint8_t src_buffer[4100];
|
||||
static ATTR_NOCACHE_RAM_SECTION uint8_t src2_buffer[4100];
|
||||
static ATTR_NOCACHE_RAM_SECTION uint8_t src3_buffer[4100];
|
||||
|
||||
static ATTR_NOCACHE_RAM_SECTION uint8_t dst_buffer[4100];
|
||||
static ATTR_NOCACHE_RAM_SECTION uint8_t dst2_buffer[4100];
|
||||
static ATTR_NOCACHE_RAM_SECTION uint8_t dst3_buffer[4100];
|
||||
static uint8_t dma_tc_flag0 = 0;
|
||||
|
||||
struct bflb_device_s *dma0_ch0;
|
||||
|
||||
void dma0_ch0_isr(void *arg)
|
||||
{
|
||||
dma_tc_flag0++;
|
||||
printf("tc done\r\n");
|
||||
}
|
||||
|
||||
void sram_init()
|
||||
{
|
||||
memset(src_buffer, 'a', 4100);
|
||||
src_buffer[3999] = 'B';
|
||||
src_buffer[4095] = 'A';
|
||||
src_buffer[4096] = 'B';
|
||||
src_buffer[4097] = 'C';
|
||||
src_buffer[4098] = 'D';
|
||||
src_buffer[4099] = 'E';
|
||||
|
||||
memset(src2_buffer, 'c', 512);
|
||||
memset(src3_buffer, 'd', 256);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
board_init();
|
||||
|
||||
sram_init();
|
||||
|
||||
printf("dma memory test\r\n");
|
||||
dma0_ch0 = bflb_device_get_by_name("dma0_ch0");
|
||||
|
||||
struct bflb_dma_channel_config_s config;
|
||||
|
||||
config.direction = DMA_MEMORY_TO_MEMORY;
|
||||
config.src_req = 0;
|
||||
config.dst_req = 0;
|
||||
config.src_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
|
||||
config.dst_addr_inc = DMA_ADDR_INCREMENT_ENABLE;
|
||||
config.src_burst_count = DMA_BURST_INCR1;
|
||||
config.dst_burst_count = DMA_BURST_INCR1;
|
||||
config.src_width = DMA_DATA_WIDTH_32BIT;
|
||||
config.dst_width = DMA_DATA_WIDTH_32BIT;
|
||||
bflb_dma_channel_init(dma0_ch0, &config);
|
||||
|
||||
bflb_dma_channel_irq_attach(dma0_ch0, dma0_ch0_isr, NULL);
|
||||
|
||||
struct bflb_dma_channel_lli_pool_s lli[20]; /* max trasnfer size 4064 * 20 */
|
||||
struct bflb_dma_channel_lli_transfer_s transfers[3];
|
||||
|
||||
transfers[0].src_addr = (uint32_t)src_buffer;
|
||||
transfers[0].dst_addr = (uint32_t)dst_buffer;
|
||||
transfers[0].nbytes = 4100;
|
||||
|
||||
transfers[1].src_addr = (uint32_t)src2_buffer;
|
||||
transfers[1].dst_addr = (uint32_t)dst2_buffer;
|
||||
transfers[1].nbytes = 4100;
|
||||
|
||||
transfers[2].src_addr = (uint32_t)src3_buffer;
|
||||
transfers[2].dst_addr = (uint32_t)dst3_buffer;
|
||||
transfers[2].nbytes = 4100;
|
||||
|
||||
bflb_dma_channel_lli_reload(dma0_ch0, lli, 20, transfers, 3);
|
||||
bflb_dma_channel_start(dma0_ch0);
|
||||
while (dma_tc_flag0 != 3) {
|
||||
bflb_mtimer_delay_ms(1);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@ static const uint8_t test_frame[42] = {
|
|||
0xc0, 0xa8, 0x7b, 0xb2 // dst ip 192.168.123.178
|
||||
};
|
||||
#define TEST_PATTERN_LEN (ETH_MAX_PACKET_SIZE - 32)
|
||||
ATTR_NOCACHE_RAM_SECTION static uint8_t test_pattern[TEST_PATTERN_LEN] = { 0 };
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION static uint8_t test_pattern[TEST_PATTERN_LEN] = { 0 };
|
||||
|
||||
static volatile uint32_t tx_pkg_cnt = 0;
|
||||
static volatile uint32_t tx_err_cnt = 0;
|
||||
|
|
|
@ -10,8 +10,8 @@ struct bflb_device_s *i2c0;
|
|||
struct bflb_device_s *dma0_ch0;
|
||||
struct bflb_device_s *dma0_ch1;
|
||||
|
||||
static ATTR_NOCACHE_RAM_SECTION uint32_t send_buffer[8];
|
||||
static ATTR_NOCACHE_RAM_SECTION uint32_t receive_buffer[8];
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint32_t send_buffer[8];
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint32_t receive_buffer[8];
|
||||
static volatile uint32_t dma_tc_flag0 = 0;
|
||||
static volatile uint32_t dma_tc_flag1 = 0;
|
||||
|
||||
|
@ -46,12 +46,12 @@ int main(void)
|
|||
bflb_i2c_init(i2c0, 400000);
|
||||
bflb_i2c_link_txdma(i2c0, true);
|
||||
bflb_i2c_link_rxdma(i2c0, true);
|
||||
|
||||
|
||||
/* Write page 0 */
|
||||
dma0_ch0 = bflb_device_get_by_name("dma0_ch0");
|
||||
|
||||
struct bflb_dma_channel_config_s tx_config;
|
||||
|
||||
|
||||
tx_config.direction = DMA_MEMORY_TO_PERIPH;
|
||||
tx_config.src_req = DMA_REQUEST_NONE;
|
||||
tx_config.dst_req = DMA_REQUEST_I2C0_TX;
|
||||
|
@ -90,13 +90,13 @@ int main(void)
|
|||
while ((bflb_i2c_get_intstatus(i2c0) & I2C_INT_END) == 0) {
|
||||
}
|
||||
bflb_i2c_deinit(i2c0);
|
||||
|
||||
|
||||
printf("write over\r\n");
|
||||
bflb_mtimer_delay_ms(100);
|
||||
|
||||
/* Read page 0 */
|
||||
dma0_ch1 = bflb_device_get_by_name("dma0_ch1");
|
||||
|
||||
|
||||
struct bflb_dma_channel_config_s rx_config;
|
||||
|
||||
rx_config.direction = DMA_PERIPH_TO_MEMORY;
|
||||
|
@ -109,31 +109,31 @@ int main(void)
|
|||
rx_config.src_width = DMA_DATA_WIDTH_32BIT;
|
||||
rx_config.dst_width = DMA_DATA_WIDTH_32BIT;
|
||||
bflb_dma_channel_init(dma0_ch1, &rx_config);
|
||||
|
||||
|
||||
bflb_dma_channel_irq_attach(dma0_ch1, dma0_ch1_isr, NULL);
|
||||
|
||||
|
||||
struct bflb_dma_channel_lli_pool_s rx_llipool[20];
|
||||
struct bflb_dma_channel_lli_transfer_s rx_transfers[1];
|
||||
rx_transfers[0].src_addr = (uint32_t)DMA_ADDR_I2C0_RDR;
|
||||
rx_transfers[0].dst_addr = (uint32_t)receive_buffer;
|
||||
rx_transfers[0].nbytes = 32;
|
||||
|
||||
|
||||
bflb_dma_channel_lli_reload(dma0_ch1, rx_llipool, 20, rx_transfers, 1);
|
||||
|
||||
|
||||
msgs[1].addr = 0x50;
|
||||
msgs[1].flags = I2C_M_DMA | I2C_M_READ;
|
||||
msgs[1].buffer = NULL;
|
||||
msgs[1].length = 32;
|
||||
bflb_i2c_transfer(i2c0, msgs, 2);
|
||||
|
||||
|
||||
bflb_dma_channel_start(dma0_ch1);
|
||||
|
||||
|
||||
while (dma_tc_flag1 == 0) {
|
||||
}
|
||||
while ((bflb_i2c_get_intstatus(i2c0) & I2C_INT_END) == 0) {
|
||||
}
|
||||
bflb_i2c_deinit(i2c0);
|
||||
|
||||
|
||||
printf("read over\r\n");
|
||||
|
||||
/* Check read data */
|
||||
|
|
|
@ -9,12 +9,12 @@ int main(void)
|
|||
board_init();
|
||||
board_pwm_gpio_init();
|
||||
|
||||
pwm = bflb_device_get_by_name("pwm");
|
||||
pwm = bflb_device_get_by_name("pwm0");
|
||||
|
||||
/* period = .PBCLK / .clk_div / .period = 80MHz / 80 / 1000 = 1KHz */
|
||||
/* period = .XCLK / .clk_div / .period = 32MHz / 32 / 1000 = 1KHz */
|
||||
struct bflb_pwm_v1_channel_config_s cfg = {
|
||||
.clk_source = BFLB_SYSTEM_PBCLK,
|
||||
.clk_div = 80,
|
||||
.clk_source = BFLB_SYSTEM_XCLK,
|
||||
.clk_div = 32,
|
||||
.period = 1000,
|
||||
};
|
||||
|
||||
|
|
|
@ -9,12 +9,12 @@ int main(void)
|
|||
board_init();
|
||||
board_pwm_gpio_init();
|
||||
|
||||
pwm = bflb_device_get_by_name("pwm");
|
||||
pwm = bflb_device_get_by_name("pwm0");
|
||||
|
||||
/* period = .PBCLK / .clk_div / .period = 80MHz / 80 / 1000 = 1KHz */
|
||||
/* period = .XCLK / .clk_div / .period = 32MHz / 32 / 1000 = 1KHz */
|
||||
struct bflb_pwm_v1_channel_config_s cfg = {
|
||||
.clk_source = BFLB_SYSTEM_PBCLK,
|
||||
.clk_div = 80,
|
||||
.clk_source = BFLB_SYSTEM_XCLK,
|
||||
.clk_div = 32,
|
||||
.period = 1000,
|
||||
};
|
||||
|
||||
|
|
|
@ -42,16 +42,16 @@ int main(void)
|
|||
board_init();
|
||||
board_pwm_gpio_init();
|
||||
|
||||
pwm = bflb_device_get_by_name("pwm");
|
||||
pwm = bflb_device_get_by_name("pwm0");
|
||||
|
||||
/* period = .PBCLK / .clk_div / .period = 80MHz / 80 / 1000 = 1kHz */
|
||||
/* period = .XCLK / .clk_div / .period = 32MHz / 32 / 1000 = 1KHz */
|
||||
struct bflb_pwm_v1_channel_config_s cfg = {
|
||||
.clk_source = BFLB_SYSTEM_PBCLK,
|
||||
.clk_div = 80,
|
||||
.clk_source = BFLB_SYSTEM_XCLK,
|
||||
.clk_div = 32,
|
||||
.period = 1000,
|
||||
};
|
||||
|
||||
for (uint8_t i = 0; i <= PWM_V1_CH_MAX; i++) {
|
||||
for (uint8_t i = 0; i < PWM_V1_CH_MAX; i++) {
|
||||
bflb_pwm_v1_channel_init(pwm, i, &cfg);
|
||||
bflb_pwm_v1_channel_set_threshold(pwm, i, 100, 500 + i * 100); /* duty = ((500 + i *100)-100)/1000 */
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ void pwm_isr(int irq, void *arg)
|
|||
int main(void)
|
||||
{
|
||||
board_init();
|
||||
// board_pwm0_gpio_init();
|
||||
board_pwm0_gpio_init();
|
||||
|
||||
pwm0 = bflb_device_get_by_name("pwm0");
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ const uint8_t aes_xts_256bit_ct[64] = {
|
|||
0x66, 0xb2, 0x7f, 0x06, 0x46, 0xbb, 0xb2, 0x46, 0x00, 0xf8, 0x6b, 0x0c, 0xc0, 0x5f, 0xb5, 0x20
|
||||
};
|
||||
|
||||
static struct bflb_aes_link_s aes_ecb_link = {
|
||||
ATTR_NOCACHE_RAM_SECTION struct bflb_aes_link_s aes_ecb_link = {
|
||||
.aes_key = AES_LINK_KEY_128BITS, /* 128-bit key mode select */
|
||||
.aes_dec_en = 0, /* Encode */
|
||||
.aes_newkey_dis = 0, /* Use new key */
|
||||
|
@ -111,7 +111,7 @@ static struct bflb_aes_link_s aes_ecb_link = {
|
|||
.aes_key7 = 0 /* Big endian aes key(aes-256 key LSB) */
|
||||
};
|
||||
|
||||
static struct bflb_aes_link_s aes_cbc_link = {
|
||||
ATTR_NOCACHE_RAM_SECTION struct bflb_aes_link_s aes_cbc_link = {
|
||||
.aes_key = AES_LINK_KEY_128BITS, /* 128-bit key mode select */
|
||||
.aes_dec_en = 0, /* Encode */
|
||||
.aes_newkey_dis = 0, /* Use new key */
|
||||
|
@ -138,7 +138,7 @@ static struct bflb_aes_link_s aes_cbc_link = {
|
|||
.aes_key7 = 0 /* Big endian aes key(aes-256 key LSB) */
|
||||
};
|
||||
|
||||
static struct bflb_aes_link_s aes_cbc_link2 = {
|
||||
ATTR_NOCACHE_RAM_SECTION struct bflb_aes_link_s aes_cbc_link2 = {
|
||||
.aes_key = AES_LINK_KEY_128BITS, /* 128-bit key mode select */
|
||||
.aes_dec_en = 0, /* Encode */
|
||||
.aes_newkey_dis = 0, /* Use new key */
|
||||
|
@ -165,7 +165,7 @@ static struct bflb_aes_link_s aes_cbc_link2 = {
|
|||
.aes_key7 = 0 /* Big endian aes key(aes-256 key LSB) */
|
||||
};
|
||||
|
||||
static struct bflb_aes_link_s aes_ctr_link = {
|
||||
ATTR_NOCACHE_RAM_SECTION struct bflb_aes_link_s aes_ctr_link = {
|
||||
.aes_key = AES_LINK_KEY_128BITS, /* 128-bit key mode select */
|
||||
.aes_dec_en = 0, /* Encode */
|
||||
.aes_newkey_dis = 0, /* Use new key */
|
||||
|
@ -192,7 +192,7 @@ static struct bflb_aes_link_s aes_ctr_link = {
|
|||
.aes_key7 = 0 /* Big endian aes key(aes-256 key LSB) */
|
||||
};
|
||||
|
||||
static struct bflb_aes_xts_link_s aes_xts_link1 = {
|
||||
ATTR_NOCACHE_RAM_SECTION struct bflb_aes_xts_link_s aes_xts_link1 = {
|
||||
.aes_key = AES_LINK_KEY_128BITS, /* 128-bit key mode select */
|
||||
.aes_dec_en = 0, /* Encode */
|
||||
.aes_newkey_dis = 0, /* Use new key */
|
||||
|
@ -201,7 +201,7 @@ static struct bflb_aes_xts_link_s aes_xts_link1 = {
|
|||
.aes_intset = 0, /* Not set interrupt */
|
||||
.aes_mode = AES_MODE_XTS, /* ECB mode select */
|
||||
.aes_newiv_dis = 0, /* Use new iv */
|
||||
.aes_xts = 0, /* XTS mode select */
|
||||
.aes_xts = AES_LINK_XTS_MODE1, /* XTS mode select */
|
||||
.aes_msglen = 1, /* Number of 128-bit block */
|
||||
.aes_srcaddr = 0, /* Message source address */
|
||||
.aes_dstaddr = 0, /* Message destination address */
|
||||
|
@ -228,7 +228,7 @@ static struct bflb_aes_xts_link_s aes_xts_link1 = {
|
|||
.aes_key27 = 0x00000000 /* Big endian aes key2(aes-256 key LSB) */
|
||||
};
|
||||
|
||||
static struct bflb_aes_xts_link_s aes_xts_link2 = {
|
||||
ATTR_NOCACHE_RAM_SECTION struct bflb_aes_xts_link_s aes_xts_link2 = {
|
||||
.aes_key = AES_LINK_KEY_192BITS, /* 128-bit key mode select */
|
||||
.aes_dec_en = 0, /* Encode */
|
||||
.aes_newkey_dis = 0, /* Use new key */
|
||||
|
@ -237,7 +237,7 @@ static struct bflb_aes_xts_link_s aes_xts_link2 = {
|
|||
.aes_intset = 0, /* Not set interrupt */
|
||||
.aes_mode = AES_MODE_XTS, /* ECB mode select */
|
||||
.aes_newiv_dis = 0, /* Use new iv */
|
||||
.aes_xts = 0, /* XTS mode select */
|
||||
.aes_xts = AES_LINK_XTS_MODE1, /* XTS mode select */
|
||||
.aes_msglen = 1, /* Number of 128-bit block */
|
||||
.aes_srcaddr = 0, /* Message source address */
|
||||
.aes_dstaddr = 0, /* Message destination address */
|
||||
|
@ -264,7 +264,7 @@ static struct bflb_aes_xts_link_s aes_xts_link2 = {
|
|||
.aes_key27 = 0x00000000 /* Big endian aes key2(aes-256 key LSB) */
|
||||
};
|
||||
|
||||
static struct bflb_aes_xts_link_s aes_xts_link3 = {
|
||||
ATTR_NOCACHE_RAM_SECTION struct bflb_aes_xts_link_s aes_xts_link3 = {
|
||||
.aes_key = AES_LINK_KEY_256BITS, /* 128-bit key mode select */
|
||||
.aes_dec_en = 0, /* Encode */
|
||||
.aes_newkey_dis = 0, /* Use new key */
|
||||
|
@ -273,7 +273,7 @@ static struct bflb_aes_xts_link_s aes_xts_link3 = {
|
|||
.aes_intset = 0, /* Not set interrupt */
|
||||
.aes_mode = AES_MODE_XTS, /* ECB mode select */
|
||||
.aes_newiv_dis = 0, /* Use new iv */
|
||||
.aes_xts = 0, /* XTS mode select */
|
||||
.aes_xts = AES_LINK_XTS_MODE1, /* XTS mode select */
|
||||
.aes_msglen = 1, /* Number of 128-bit block */
|
||||
.aes_srcaddr = 0, /* Message source address */
|
||||
.aes_dstaddr = 0, /* Message destination address */
|
||||
|
@ -314,8 +314,8 @@ static uint32_t bflb_data_compare(const uint8_t *expected, uint8_t *input, uint3
|
|||
return 0;
|
||||
}
|
||||
|
||||
ATTR_NOCACHE_RAM_SECTION uint8_t aes_enc_buf[512];
|
||||
ATTR_NOCACHE_RAM_SECTION uint8_t aes_dec_buf[512];
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t aes_enc_buf[512];
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t aes_dec_buf[512];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
@ -349,12 +349,12 @@ int main(void)
|
|||
bflb_data_compare(aes_xts_128bit_ct, aes_enc_buf, 16);
|
||||
printf("aes link xts 128 success\r\n");
|
||||
|
||||
bflb_aes_link_update(aes, (uint32_t)&aes_xts_link2, aes_xts_192bit_pt, aes_enc_buf, 16);
|
||||
bflb_data_compare(aes_xts_192bit_ct, aes_enc_buf, 16);
|
||||
bflb_aes_link_update(aes, (uint32_t)&aes_xts_link2, aes_xts_192bit_pt, aes_enc_buf, 32);
|
||||
bflb_data_compare(aes_xts_192bit_ct, aes_enc_buf, 32);
|
||||
printf("aes link xts 192 success\r\n");
|
||||
|
||||
bflb_aes_link_update(aes, (uint32_t)&aes_xts_link3, aes_xts_256bit_pt, aes_enc_buf, 16);
|
||||
bflb_data_compare(aes_xts_256bit_ct, aes_enc_buf, 16);
|
||||
bflb_aes_link_update(aes, (uint32_t)&aes_xts_link3, aes_xts_256bit_pt, aes_enc_buf, 32);
|
||||
bflb_data_compare(aes_xts_256bit_ct, aes_enc_buf, 32);
|
||||
printf("aes link xts 256 success\r\n");
|
||||
|
||||
printf("aes link success\r\n");
|
||||
|
|
|
@ -465,8 +465,8 @@ const uint8_t aes_xts_256bit_ct[3][64] = {
|
|||
|
||||
const uint8_t aes_xts_256bit_len[3] = { 64, 64, 64 };
|
||||
|
||||
ATTR_NOCACHE_RAM_SECTION uint8_t aes_enc_buf[512];
|
||||
ATTR_NOCACHE_RAM_SECTION uint8_t aes_dec_buf[512];
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t aes_enc_buf[512];
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t aes_dec_buf[512];
|
||||
|
||||
static uint32_t bflb_data_compare(const uint8_t *expected, uint8_t *input, uint32_t len)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
include(proj.conf)
|
||||
|
||||
find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})
|
||||
|
||||
sdk_set_main_file(main.c)
|
||||
|
||||
project(sec_eng_aes_sw_key_costtime)
|
|
@ -0,0 +1,13 @@
|
|||
SDK_DEMO_PATH ?= .
|
||||
BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../../..
|
||||
|
||||
export BL_SDK_BASE
|
||||
|
||||
CHIP ?= bl616
|
||||
BOARD ?= bl616dk
|
||||
CROSS_COMPILE ?= riscv64-unknown-elf-
|
||||
|
||||
# add custom cmake definition
|
||||
#cmake_definition+=-Dxxx=sss
|
||||
|
||||
include $(BL_SDK_BASE)/project.build
|
131
examples/peripherals/sec_eng/sec_eng_aes_sw_key_costtime/main.c
Normal file
131
examples/peripherals/sec_eng/sec_eng_aes_sw_key_costtime/main.c
Normal file
|
@ -0,0 +1,131 @@
|
|||
#include "bflb_mtimer.h"
|
||||
#include "bflb_sec_aes.h"
|
||||
#include "board.h"
|
||||
|
||||
const uint8_t aes_256bit_key[32] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
|
||||
};
|
||||
|
||||
uint8_t aes_iv[16] = { 0 };
|
||||
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t aes_input_buf[16 * 1024];
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t aes_enc_buf[16 * 1024];
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t aes_dec_buf[16 * 1024];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint64_t start_time;
|
||||
|
||||
board_init();
|
||||
|
||||
struct bflb_device_s *aes;
|
||||
|
||||
aes = bflb_device_get_by_name("aes");
|
||||
|
||||
bflb_group0_request_aes_access(aes);
|
||||
|
||||
for (uint32_t i = 0; i < 16 * 1024; i++) {
|
||||
aes_input_buf[i] = i & 0xff;
|
||||
}
|
||||
|
||||
bflb_aes_init(aes);
|
||||
|
||||
bflb_mtimer_delay_ms(500);
|
||||
|
||||
for (uint32_t i = 1; i <= 1024; i++) {
|
||||
printf("test aes ecb 128 \r\n");
|
||||
bflb_aes_set_mode(aes, AES_MODE_ECB);
|
||||
bflb_aes_setkey(aes, aes_256bit_key, 128);
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_encrypt(aes, aes_input_buf, aes_iv, aes_enc_buf, 16 * i);
|
||||
printf("aes ecb 128 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_decrypt(aes, aes_enc_buf, aes_iv, aes_dec_buf, 16 * i);
|
||||
printf("aes ecb 128 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
|
||||
printf("test aes ecb 256 \r\n");
|
||||
bflb_aes_set_mode(aes, AES_MODE_ECB);
|
||||
bflb_aes_setkey(aes, aes_256bit_key, 256);
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_encrypt(aes, aes_input_buf, aes_iv, aes_enc_buf, 16 * i);
|
||||
printf("aes ecb 256 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_decrypt(aes, aes_enc_buf, aes_iv, aes_dec_buf, 16 * i);
|
||||
printf("aes ecb 256 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
}
|
||||
|
||||
for (uint32_t i = 1; i <= 1024; i++) {
|
||||
printf("test aes cbc 128 \r\n");
|
||||
bflb_aes_set_mode(aes, AES_MODE_CBC);
|
||||
bflb_aes_setkey(aes, aes_256bit_key, 128);
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_encrypt(aes, aes_input_buf, aes_iv, aes_enc_buf, 16 * i);
|
||||
printf("aes cbc 128 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_decrypt(aes, aes_enc_buf, aes_iv, aes_dec_buf, 16 * i);
|
||||
printf("aes cbc 128 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
|
||||
printf("test aes cbc 256 \r\n");
|
||||
bflb_aes_set_mode(aes, AES_MODE_CBC);
|
||||
bflb_aes_setkey(aes, aes_256bit_key, 256);
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_encrypt(aes, aes_input_buf, aes_iv, aes_enc_buf, 16 * i);
|
||||
printf("aes cbc 256 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_decrypt(aes, aes_enc_buf, aes_iv, aes_dec_buf, 16 * i);
|
||||
printf("aes cbc 256 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
}
|
||||
|
||||
for (uint32_t i = 1; i <= 1024; i++) {
|
||||
printf("test aes ctr 128 \r\n");
|
||||
bflb_aes_set_mode(aes, AES_MODE_CTR);
|
||||
bflb_aes_setkey(aes, aes_256bit_key, 128);
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_encrypt(aes, aes_input_buf, aes_iv, aes_enc_buf, 16 * i);
|
||||
printf("aes ctr 128 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_decrypt(aes, aes_enc_buf, aes_iv, aes_dec_buf, 16 * i);
|
||||
printf("aes ctr 128 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
|
||||
printf("test aes ctr 256 \r\n");
|
||||
bflb_aes_set_mode(aes, AES_MODE_CTR);
|
||||
bflb_aes_setkey(aes, aes_256bit_key, 256);
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_encrypt(aes, aes_input_buf, aes_iv, aes_enc_buf, 16 * i);
|
||||
printf("aes ctr 256 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_decrypt(aes, aes_enc_buf, aes_iv, aes_dec_buf, 16 * i);
|
||||
printf("aes ctr 256 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
}
|
||||
|
||||
for (uint32_t i = 1; i <= 1024; i++) {
|
||||
printf("test aes xts 128 \r\n");
|
||||
bflb_aes_set_mode(aes, AES_MODE_XTS);
|
||||
bflb_aes_setkey(aes, aes_256bit_key, 128);
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_encrypt(aes, aes_input_buf, aes_iv, aes_enc_buf, 16 * i);
|
||||
printf("aes xts 128 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_decrypt(aes, aes_enc_buf, aes_iv, aes_dec_buf, 16 * i);
|
||||
printf("aes xts 128 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
|
||||
printf("test aes xts 256 \r\n");
|
||||
bflb_aes_set_mode(aes, AES_MODE_XTS);
|
||||
bflb_aes_setkey(aes, aes_256bit_key, 256);
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_encrypt(aes, aes_input_buf, aes_iv, aes_enc_buf, 16 * i);
|
||||
printf("aes xts 256 block:%d enc cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_aes_decrypt(aes, aes_enc_buf, aes_iv, aes_dec_buf, 16 * i);
|
||||
printf("aes xts 256 block:%d dec cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
}
|
||||
|
||||
printf("aes success\r\n");
|
||||
bflb_group0_release_aes_access(aes);
|
||||
while (1) {
|
||||
bflb_mtimer_delay_ms(2000);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
#set(CONFIG_XXX 1)
|
9
examples/peripherals/sec_eng/sec_eng_dsa/CMakeLists.txt
Normal file
9
examples/peripherals/sec_eng/sec_eng_dsa/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
include(proj.conf)
|
||||
|
||||
find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})
|
||||
|
||||
sdk_set_main_file(main.c)
|
||||
|
||||
project(sec_eng_dsa)
|
13
examples/peripherals/sec_eng/sec_eng_dsa/Makefile
Normal file
13
examples/peripherals/sec_eng/sec_eng_dsa/Makefile
Normal file
|
@ -0,0 +1,13 @@
|
|||
SDK_DEMO_PATH ?= .
|
||||
BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../../..
|
||||
|
||||
export BL_SDK_BASE
|
||||
|
||||
CHIP ?= bl616
|
||||
BOARD ?= bl616dk
|
||||
CROSS_COMPILE ?= riscv64-unknown-elf-
|
||||
|
||||
# add custom cmake definition
|
||||
#cmake_definition+=-Dxxx=sss
|
||||
|
||||
include $(BL_SDK_BASE)/project.build
|
145
examples/peripherals/sec_eng/sec_eng_dsa/main.c
Normal file
145
examples/peripherals/sec_eng/sec_eng_dsa/main.c
Normal file
|
@ -0,0 +1,145 @@
|
|||
#include "bflb_mtimer.h"
|
||||
#include "bflb_sec_dsa.h"
|
||||
#include "board.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
board_init();
|
||||
|
||||
#if 0
|
||||
p=int("00c952a3180f7bca497bc5ad1e9b5818b233702ac9ab43f744f451a4a241fcda5b9eff815351c45d046ee4262ac28f7f3df226ac2e949d1fe8d5b6923f33f1a641",16)
|
||||
q=int("00c225091c9a663843dd18cce92409581c2365d0fcbc956bf1152e11004bde53c99843f1f149a76a33fb46edb957f19e8720003b0345633f2840b35e3b302dec79",16)
|
||||
n=int("98adbfb43467d4a5df25d388e5605f12840ea66299cbdf3a807bbd99817798eb4a64a6885ba5494dba2fc00005fe87f5ec6585d1ba53dea9d48e48cfe6031843d84057a0c6233a598cb8a7d399eea7bce81e07ea574c26e44b4a925db3a9372d73c97bbe143c747ffc1123c2e0e57681e95462a81b7224e814270363bbe880b9",16)
|
||||
e=65537
|
||||
d=int("2a99a039b9bd96d9c94f969c45d403f2f8a1d5cf01369f4c857901480995c3373384adeab217864287c6b6fdcaae60653fd67be62ee523e5a307284dc9d1e73ce88bbd38e711536e48b181c1b5735d76675700fc2ddd89b7df67a8fb16eb4c1dde354fbc04f7c4c18975f5cba4f36ec7120b00bdd838d488ce37a9452e574401",16)
|
||||
dP=int("c2a434aed4797890272c6d3e042ede619bbdbc809226f9f01eceb87f6f9109843f6b041c0c17ef5e93dfdccec6a07a02e8155faf015c1037ca37e3995b9d2c81",16)
|
||||
dQ=int("161295dd9da43f835fb0c1234488976ee38b60de4b2685d62bfd47cb8bd4a41c0866b92c209e9b117be10d8803faa176656a014b96e8f8b63fdce4babff888a9",16)
|
||||
qInv=int("49727f7416d2e019b5436ffeb01b817cd57bb67aece0e56a7777db1547c197d1b00d088c436721a31eba5387b8d48394e47c806d3d1b546b03fd3e6c3ead5fda",16)
|
||||
#endif
|
||||
|
||||
uint8_t p[64] = { 0xc9, 0x52, 0xa3, 0x18, 0x0f, 0x7b, 0xca, 0x49, 0x7b, 0xc5, 0xad, 0x1e, 0x9b, 0x58, 0x18, 0xb2,
|
||||
0x33, 0x70, 0x2a, 0xc9, 0xab, 0x43, 0xf7, 0x44, 0xf4, 0x51, 0xa4, 0xa2, 0x41, 0xfc, 0xda, 0x5b,
|
||||
0x9e, 0xff, 0x81, 0x53, 0x51, 0xc4, 0x5d, 0x04, 0x6e, 0xe4, 0x26, 0x2a, 0xc2, 0x8f, 0x7f, 0x3d,
|
||||
0xf2, 0x26, 0xac, 0x2e, 0x94, 0x9d, 0x1f, 0xe8, 0xd5, 0xb6, 0x92, 0x3f, 0x33, 0xf1, 0xa6, 0x41 };
|
||||
|
||||
uint8_t q[64] = { 0xc2, 0x25, 0x09, 0x1c, 0x9a, 0x66, 0x38, 0x43, 0xdd, 0x18, 0xcc, 0xe9, 0x24, 0x09, 0x58, 0x1c,
|
||||
0x23, 0x65, 0xd0, 0xfc, 0xbc, 0x95, 0x6b, 0xf1, 0x15, 0x2e, 0x11, 0x00, 0x4b, 0xde, 0x53, 0xc9,
|
||||
0x98, 0x43, 0xf1, 0xf1, 0x49, 0xa7, 0x6a, 0x33, 0xfb, 0x46, 0xed, 0xb9, 0x57, 0xf1, 0x9e, 0x87,
|
||||
0x20, 0x00, 0x3b, 0x03, 0x45, 0x63, 0x3f, 0x28, 0x40, 0xb3, 0x5e, 0x3b, 0x30, 0x2d, 0xec, 0x79 };
|
||||
uint8_t n[128] = { 0x98, 0xad, 0xbf, 0xb4, 0x34, 0x67, 0xd4, 0xa5, 0xdf, 0x25, 0xd3, 0x88, 0xe5, 0x60, 0x5f, 0x12,
|
||||
0x84, 0x0e, 0xa6, 0x62, 0x99, 0xcb, 0xdf, 0x3a, 0x80, 0x7b, 0xbd, 0x99, 0x81, 0x77, 0x98, 0xeb,
|
||||
0x4a, 0x64, 0xa6, 0x88, 0x5b, 0xa5, 0x49, 0x4d, 0xba, 0x2f, 0xc0, 0x00, 0x05, 0xfe, 0x87, 0xf5,
|
||||
0xec, 0x65, 0x85, 0xd1, 0xba, 0x53, 0xde, 0xa9, 0xd4, 0x8e, 0x48, 0xcf, 0xe6, 0x03, 0x18, 0x43,
|
||||
0xd8, 0x40, 0x57, 0xa0, 0xc6, 0x23, 0x3a, 0x59, 0x8c, 0xb8, 0xa7, 0xd3, 0x99, 0xee, 0xa7, 0xbc,
|
||||
0xe8, 0x1e, 0x07, 0xea, 0x57, 0x4c, 0x26, 0xe4, 0x4b, 0x4a, 0x92, 0x5d, 0xb3, 0xa9, 0x37, 0x2d,
|
||||
0x73, 0xc9, 0x7b, 0xbe, 0x14, 0x3c, 0x74, 0x7f, 0xfc, 0x11, 0x23, 0xc2, 0xe0, 0xe5, 0x76, 0x81,
|
||||
0xe9, 0x54, 0x62, 0xa8, 0x1b, 0x72, 0x24, 0xe8, 0x14, 0x27, 0x03, 0x63, 0xbb, 0xe8, 0x80, 0xb9 };
|
||||
uint8_t e[128] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01 };
|
||||
uint8_t d[128] = { 0x2a, 0x99, 0xa0, 0x39, 0xb9, 0xbd, 0x96, 0xd9, 0xc9, 0x4f, 0x96, 0x9c, 0x45, 0xd4, 0x03, 0xf2,
|
||||
0xf8, 0xa1, 0xd5, 0xcf, 0x01, 0x36, 0x9f, 0x4c, 0x85, 0x79, 0x01, 0x48, 0x09, 0x95, 0xc3, 0x37,
|
||||
0x33, 0x84, 0xad, 0xea, 0xb2, 0x17, 0x86, 0x42, 0x87, 0xc6, 0xb6, 0xfd, 0xca, 0xae, 0x60, 0x65,
|
||||
0x3f, 0xd6, 0x7b, 0xe6, 0x2e, 0xe5, 0x23, 0xe5, 0xa3, 0x07, 0x28, 0x4d, 0xc9, 0xd1, 0xe7, 0x3c,
|
||||
0xe8, 0x8b, 0xbd, 0x38, 0xe7, 0x11, 0x53, 0x6e, 0x48, 0xb1, 0x81, 0xc1, 0xb5, 0x73, 0x5d, 0x76,
|
||||
0x67, 0x57, 0x00, 0xfc, 0x2d, 0xdd, 0x89, 0xb7, 0xdf, 0x67, 0xa8, 0xfb, 0x16, 0xeb, 0x4c, 0x1d,
|
||||
0xde, 0x35, 0x4f, 0xbc, 0x04, 0xf7, 0xc4, 0xc1, 0x89, 0x75, 0xf5, 0xcb, 0xa4, 0xf3, 0x6e, 0xc7,
|
||||
0x12, 0x0b, 0x00, 0xbd, 0xd8, 0x38, 0xd4, 0x88, 0xce, 0x37, 0xa9, 0x45, 0x2e, 0x57, 0x44, 0x01 };
|
||||
uint8_t dP[64] = { 0xc2, 0xa4, 0x34, 0xae, 0xd4, 0x79, 0x78, 0x90, 0x27, 0x2c, 0x6d, 0x3e, 0x04, 0x2e, 0xde, 0x61,
|
||||
0x9b, 0xbd, 0xbc, 0x80, 0x92, 0x26, 0xf9, 0xf0, 0x1e, 0xce, 0xb8, 0x7f, 0x6f, 0x91, 0x09, 0x84,
|
||||
0x3f, 0x6b, 0x04, 0x1c, 0x0c, 0x17, 0xef, 0x5e, 0x93, 0xdf, 0xdc, 0xce, 0xc6, 0xa0, 0x7a, 0x02,
|
||||
0xe8, 0x15, 0x5f, 0xaf, 0x01, 0x5c, 0x10, 0x37, 0xca, 0x37, 0xe3, 0x99, 0x5b, 0x9d, 0x2c, 0x81 };
|
||||
uint8_t dQ[64] = { 0x16, 0x12, 0x95, 0xdd, 0x9d, 0xa4, 0x3f, 0x83, 0x5f, 0xb0, 0xc1, 0x23, 0x44, 0x88, 0x97, 0x6e,
|
||||
0xe3, 0x8b, 0x60, 0xde, 0x4b, 0x26, 0x85, 0xd6, 0x2b, 0xfd, 0x47, 0xcb, 0x8b, 0xd4, 0xa4, 0x1c,
|
||||
0x08, 0x66, 0xb9, 0x2c, 0x20, 0x9e, 0x9b, 0x11, 0x7b, 0xe1, 0x0d, 0x88, 0x03, 0xfa, 0xa1, 0x76,
|
||||
0x65, 0x6a, 0x01, 0x4b, 0x96, 0xe8, 0xf8, 0xb6, 0x3f, 0xdc, 0xe4, 0xba, 0xbf, 0xf8, 0x88, 0xa9 };
|
||||
uint8_t qInv[64] = { 0x49, 0x72, 0x7f, 0x74, 0x16, 0xd2, 0xe0, 0x19, 0xb5, 0x43, 0x6f, 0xfe, 0xb0, 0x1b, 0x81, 0x7c,
|
||||
0xd5, 0x7b, 0xb6, 0x7a, 0xec, 0xe0, 0xe5, 0x6a, 0x77, 0x77, 0xdb, 0x15, 0x47, 0xc1, 0x97, 0xd1,
|
||||
0xb0, 0x0d, 0x08, 0x8c, 0x43, 0x67, 0x21, 0xa3, 0x1e, 0xba, 0x53, 0x87, 0xb8, 0xd4, 0x83, 0x94,
|
||||
0xe4, 0x7c, 0x80, 0x6d, 0x3d, 0x1b, 0x54, 0x6b, 0x03, 0xfd, 0x3e, 0x6c, 0x3e, 0xad, 0x5f, 0xda };
|
||||
uint8_t invR_p[64] = { 0x74, 0xc9, 0x11, 0x9b, 0x94, 0x7c, 0xc7, 0x0c, 0xd9, 0x39, 0x31, 0x06, 0x2c, 0x89, 0x7f, 0x90,
|
||||
0x83, 0xec, 0xdd, 0x9e, 0xd1, 0x53, 0x85, 0xb1, 0x2e, 0x01, 0xc0, 0x7a, 0xce, 0x44, 0x56, 0x77,
|
||||
0x4d, 0xbe, 0x96, 0xbe, 0xf2, 0x1d, 0x03, 0x09, 0x97, 0x7a, 0xd5, 0xa5, 0x5f, 0x2e, 0x32, 0xdb,
|
||||
0xd9, 0xdd, 0x80, 0x3c, 0x08, 0x52, 0x8e, 0x72, 0x14, 0xfd, 0x09, 0x6c, 0x6a, 0x0a, 0x40, 0x91 };
|
||||
uint8_t primeN_p[64] = { 0x94, 0x80, 0xcd, 0xff, 0x86, 0x44, 0x04, 0x7a, 0xa9, 0x62, 0x10, 0x8c, 0x4f, 0x9d, 0xee, 0x0e,
|
||||
0x70, 0x56, 0xfc, 0xaf, 0x12, 0xaa, 0x05, 0xb0, 0x3c, 0x0c, 0x8c, 0xc1, 0xef, 0xc5, 0x70, 0xc8,
|
||||
0x40, 0x76, 0xa2, 0xca, 0x4e, 0xe0, 0xae, 0x6d, 0x3c, 0xbc, 0x3b, 0xed, 0x85, 0xdf, 0x44, 0x39,
|
||||
0xcd, 0x89, 0x45, 0x2a, 0x3b, 0x4b, 0x12, 0x2d, 0x34, 0xef, 0xa5, 0x05, 0x04, 0x9e, 0x96, 0x3f };
|
||||
uint8_t invR_q[64] = { 0x07, 0x2d, 0x7c, 0xa1, 0x7d, 0xe7, 0xab, 0x44, 0x8d, 0xf0, 0xe1, 0xf0, 0xd0, 0x54, 0xb1, 0x7b,
|
||||
0x74, 0x74, 0xac, 0x42, 0xc2, 0x49, 0x56, 0xab, 0xbd, 0x94, 0xe7, 0x5c, 0x6b, 0x06, 0x39, 0x2e,
|
||||
0xc7, 0x75, 0xd3, 0xdc, 0x6c, 0x8b, 0xd8, 0x19, 0x7e, 0x6d, 0x59, 0x58, 0xc7, 0x95, 0x71, 0x9e,
|
||||
0x10, 0x1a, 0xab, 0x07, 0x6f, 0xf1, 0x81, 0x37, 0x68, 0x88, 0x6c, 0xdd, 0x9d, 0xd8, 0x74, 0x82 };
|
||||
uint8_t primeN_q[64] = { 0x09, 0x76, 0xeb, 0x06, 0xf9, 0x4b, 0xb4, 0xb8, 0xef, 0x02, 0x17, 0xf3, 0xa5, 0xa1, 0x12, 0xbc,
|
||||
0x85, 0xda, 0x82, 0x91, 0x31, 0xd4, 0x07, 0x49, 0xdf, 0xef, 0x6a, 0x4a, 0x71, 0x0e, 0xe0, 0x8f,
|
||||
0x14, 0xc7, 0x71, 0x3f, 0x92, 0xa8, 0x40, 0xd2, 0x9c, 0xf8, 0x76, 0x51, 0xaf, 0xe0, 0xbd, 0xbc,
|
||||
0x09, 0x21, 0x2a, 0x68, 0xab, 0x4a, 0xfa, 0x5a, 0xeb, 0x6f, 0xb6, 0x65, 0x67, 0xc3, 0x42, 0x37 };
|
||||
uint8_t c[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x56, 0x78 };
|
||||
uint8_t m[128] = { 0x94, 0x56, 0x39, 0x91, 0x66, 0x79, 0x4b, 0x55, 0x36, 0x55, 0x13, 0x90, 0x9d, 0x6c, 0x40, 0x02,
|
||||
0xf8, 0xd5, 0xb3, 0xae, 0x15, 0x90, 0xcd, 0xcf, 0x7b, 0x18, 0xe2, 0x03, 0x2b, 0xf2, 0x65, 0x08,
|
||||
0xfc, 0xc8, 0xbf, 0xc2, 0x47, 0xc4, 0x72, 0x55, 0x8a, 0x50, 0x26, 0x5e, 0x73, 0x7f, 0x18, 0x1e,
|
||||
0x6f, 0x64, 0x8f, 0x42, 0xd0, 0x1b, 0x92, 0x0e, 0xe3, 0x1e, 0x39, 0xea, 0x38, 0x76, 0x0b, 0xf8,
|
||||
0x0f, 0x25, 0x5d, 0x5d, 0x5d, 0x52, 0xf4, 0x7f, 0x74, 0x27, 0xdf, 0x4a, 0x89, 0xc4, 0xa3, 0xa7,
|
||||
0xf8, 0xd3, 0xf9, 0x3a, 0xaa, 0x6a, 0x34, 0x42, 0xb3, 0x5e, 0x5b, 0x68, 0x96, 0xc7, 0xc4, 0xfa,
|
||||
0x22, 0x95, 0x8a, 0xbf, 0xa6, 0xf3, 0x54, 0x2e, 0xcf, 0x66, 0x0f, 0x62, 0xef, 0xac, 0x11, 0xc1,
|
||||
0x69, 0xb2, 0x64, 0xf9, 0xcc, 0x75, 0x68, 0x50, 0x8f, 0xf1, 0xfe, 0x5c, 0xfa, 0x27, 0x6c, 0x7b };
|
||||
uint32_t dsa_tmp[32];
|
||||
uint32_t i = 0;
|
||||
uint8_t *k;
|
||||
struct bflb_dsa_s dsa_handle;
|
||||
uint32_t time = 0;
|
||||
|
||||
printf("DSA Case\r\n");
|
||||
|
||||
bflb_sec_dsa_init(&dsa_handle, 1024);
|
||||
dsa_handle.n = (uint32_t *)n;
|
||||
dsa_handle.e = (uint32_t *)e;
|
||||
dsa_handle.d = (uint32_t *)d;
|
||||
dsa_handle.crtCfg.dP = (uint32_t *)dP;
|
||||
dsa_handle.crtCfg.dQ = (uint32_t *)dQ;
|
||||
dsa_handle.crtCfg.qInv = (uint32_t *)qInv;
|
||||
dsa_handle.crtCfg.p = (uint32_t *)p;
|
||||
dsa_handle.crtCfg.invR_p = (uint32_t *)invR_p;
|
||||
dsa_handle.crtCfg.primeN_p = (uint32_t *)primeN_p;
|
||||
dsa_handle.crtCfg.q = (uint32_t *)q;
|
||||
dsa_handle.crtCfg.invR_q = (uint32_t *)invR_q;
|
||||
dsa_handle.crtCfg.primeN_q = (uint32_t *)primeN_q;
|
||||
|
||||
time = (unsigned int)bflb_mtimer_get_time_ms();
|
||||
|
||||
if (0 != bflb_sec_dsa_sign(&dsa_handle, (uint32_t *)c, 8, dsa_tmp)) {
|
||||
printf("Sign Fail\r\n");
|
||||
}
|
||||
|
||||
printf("DSA sign time=%dms\r\n", (unsigned int)bflb_mtimer_get_time_ms() - time);
|
||||
|
||||
printf("Check sign\r\n");
|
||||
k = (uint8_t *)(dsa_tmp);
|
||||
|
||||
for (i = 0; i < sizeof(m); i++) {
|
||||
if (k[i] != m[i]) {
|
||||
printf("DSA sign fail\r\n");
|
||||
while(1)
|
||||
{}
|
||||
}
|
||||
}
|
||||
|
||||
time = (unsigned int)bflb_mtimer_get_time_ms();
|
||||
|
||||
if (0 != bflb_sec_dsa_verify(&dsa_handle, (uint32_t *)c, 8, (uint32_t *)m)) {
|
||||
printf("DSA verify fail\r\n");
|
||||
}
|
||||
|
||||
printf("DSA verify time=%dms\r\n", (unsigned int)bflb_mtimer_get_time_ms()- time);
|
||||
|
||||
printf("Finished\r\n");
|
||||
|
||||
while (1) {
|
||||
bflb_mtimer_delay_ms(2000);
|
||||
}
|
||||
}
|
1
examples/peripherals/sec_eng/sec_eng_dsa/proj.conf
Normal file
1
examples/peripherals/sec_eng/sec_eng_dsa/proj.conf
Normal file
|
@ -0,0 +1 @@
|
|||
#set(CONFIG_XXX 1)
|
|
@ -126,13 +126,13 @@ static const unsigned char sha512_test_sum[6][64] = {
|
|||
0x4E, 0xAD, 0xB2, 0x17, 0xAD, 0x8C, 0xC0, 0x9B }
|
||||
};
|
||||
|
||||
ATTR_NOCACHE_RAM_SECTION __attribute__((aligned(32))) uint8_t sha_input_buf[1000]; /* input addr must be align 32 */
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION __attribute__((aligned(32))) uint8_t sha_input_buf[1000]; /* input addr must be align 32 */
|
||||
|
||||
uint8_t sha_output_buf[128];
|
||||
|
||||
ATTR_NOCACHE_RAM_SECTION struct bflb_sha1_ctx_s ctx_sha1;
|
||||
ATTR_NOCACHE_RAM_SECTION struct bflb_sha256_ctx_s ctx_sha256;
|
||||
ATTR_NOCACHE_RAM_SECTION struct bflb_sha512_ctx_s ctx_sha512;
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION struct bflb_sha1_ctx_s ctx_sha1;
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION struct bflb_sha256_ctx_s ctx_sha256;
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION struct bflb_sha512_ctx_s ctx_sha512;
|
||||
|
||||
static uint32_t bflb_data_compare(const uint8_t *expected, uint8_t *input, uint32_t len)
|
||||
{
|
||||
|
@ -192,7 +192,7 @@ int main(void)
|
|||
}
|
||||
|
||||
bflb_sha256_finish(sha, &ctx_sha256, sha_output_buf);
|
||||
bflb_data_compare(sha256_test_sum[i], sha_output_buf, 20);
|
||||
bflb_data_compare(sha256_test_sum[i], sha_output_buf, 28);
|
||||
}
|
||||
printf("sha224 success\r\n");
|
||||
|
||||
|
@ -210,7 +210,7 @@ int main(void)
|
|||
}
|
||||
|
||||
bflb_sha256_finish(sha, &ctx_sha256, sha_output_buf);
|
||||
bflb_data_compare(sha256_test_sum[i + 3], sha_output_buf, 20);
|
||||
bflb_data_compare(sha256_test_sum[i + 3], sha_output_buf, 32);
|
||||
}
|
||||
printf("sha256 success\r\n");
|
||||
|
||||
|
@ -228,7 +228,7 @@ int main(void)
|
|||
}
|
||||
|
||||
bflb_sha512_finish(sha, &ctx_sha512, sha_output_buf);
|
||||
bflb_data_compare(sha512_test_sum[i], sha_output_buf, 20);
|
||||
bflb_data_compare(sha512_test_sum[i], sha_output_buf, 48);
|
||||
}
|
||||
printf("sha384 success\r\n");
|
||||
|
||||
|
@ -246,7 +246,7 @@ int main(void)
|
|||
}
|
||||
|
||||
bflb_sha512_finish(sha, &ctx_sha512, sha_output_buf);
|
||||
bflb_data_compare(sha512_test_sum[i + 3], sha_output_buf, 20);
|
||||
bflb_data_compare(sha512_test_sum[i + 3], sha_output_buf, 64);
|
||||
}
|
||||
printf("sha512 success\r\n");
|
||||
bflb_group0_release_sha_access(sha);
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
include(proj.conf)
|
||||
|
||||
find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})
|
||||
|
||||
sdk_set_main_file(main.c)
|
||||
|
||||
project(sec_eng_sha_costtime)
|
13
examples/peripherals/sec_eng/sec_eng_sha_costtime/Makefile
Normal file
13
examples/peripherals/sec_eng/sec_eng_sha_costtime/Makefile
Normal file
|
@ -0,0 +1,13 @@
|
|||
SDK_DEMO_PATH ?= .
|
||||
BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../../..
|
||||
|
||||
export BL_SDK_BASE
|
||||
|
||||
CHIP ?= bl616
|
||||
BOARD ?= bl616dk
|
||||
CROSS_COMPILE ?= riscv64-unknown-elf-
|
||||
|
||||
# add custom cmake definition
|
||||
#cmake_definition+=-Dxxx=sss
|
||||
|
||||
include $(BL_SDK_BASE)/project.build
|
81
examples/peripherals/sec_eng/sec_eng_sha_costtime/main.c
Normal file
81
examples/peripherals/sec_eng/sec_eng_sha_costtime/main.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
#include "bflb_mtimer.h"
|
||||
#include "bflb_sec_sha.h"
|
||||
#include "board.h"
|
||||
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION __attribute__((aligned(32))) uint8_t sha_input_buf[16 * 1024]; /* input addr must be align 32 */
|
||||
|
||||
uint8_t sha_output_buf[128];
|
||||
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION struct bflb_sha1_ctx_s ctx_sha1;
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION struct bflb_sha256_ctx_s ctx_sha256;
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION struct bflb_sha512_ctx_s ctx_sha512;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint64_t start_time;
|
||||
|
||||
board_init();
|
||||
|
||||
struct bflb_device_s *sha;
|
||||
|
||||
sha = bflb_device_get_by_name("sha");
|
||||
|
||||
bflb_group0_request_sha_access(sha);
|
||||
|
||||
for (uint32_t i = 0; i < 16 * 1024; i++) {
|
||||
sha_input_buf[i] = i & 0xff;
|
||||
}
|
||||
|
||||
bflb_sha_init(sha, SHA_MODE_SHA1);
|
||||
|
||||
for (uint32_t i = 1; i <= 1024; i++) {
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_sha1_start(sha, &ctx_sha1);
|
||||
bflb_sha1_update(sha, &ctx_sha1, sha_input_buf, 16 * i);
|
||||
bflb_sha1_finish(sha, &ctx_sha1, sha_output_buf);
|
||||
printf("sha1 block:%d cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
}
|
||||
|
||||
printf("sha1 success\r\n");
|
||||
|
||||
bflb_sha_init(sha, SHA_MODE_SHA224);
|
||||
for (uint32_t i = 1; i <= 1024; i++) {
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_sha256_start(sha, &ctx_sha256);
|
||||
bflb_sha256_update(sha, &ctx_sha256, sha_input_buf, 16 * i);
|
||||
bflb_sha256_finish(sha, &ctx_sha256, sha_output_buf);
|
||||
printf("sha224 block:%d cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
}
|
||||
|
||||
bflb_sha_init(sha, SHA_MODE_SHA256);
|
||||
for (uint32_t i = 1; i <= 1024; i++) {
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_sha256_start(sha, &ctx_sha256);
|
||||
bflb_sha256_update(sha, &ctx_sha256, sha_input_buf, 16 * i);
|
||||
bflb_sha256_finish(sha, &ctx_sha256, sha_output_buf);
|
||||
printf("sha256 block:%d cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
}
|
||||
|
||||
bflb_sha_init(sha, SHA_MODE_SHA384);
|
||||
for (uint32_t i = 1; i <= 1024; i++) {
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_sha512_start(sha, &ctx_sha512);
|
||||
bflb_sha512_update(sha, &ctx_sha512, sha_input_buf, 16 * i);
|
||||
bflb_sha512_finish(sha, &ctx_sha512, sha_output_buf);
|
||||
printf("sha384 block:%d cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
}
|
||||
|
||||
bflb_sha_init(sha, SHA_MODE_SHA512);
|
||||
for (uint32_t i = 1; i <= 1024; i++) {
|
||||
start_time = bflb_mtimer_get_time_us();
|
||||
bflb_sha512_start(sha, &ctx_sha512);
|
||||
bflb_sha512_update(sha, &ctx_sha512, sha_input_buf, 16 * i);
|
||||
bflb_sha512_finish(sha, &ctx_sha512, sha_output_buf);
|
||||
printf("sha512 block:%d cost time:%d us\r\n", i, (uint32_t)(bflb_mtimer_get_time_us() - start_time));
|
||||
}
|
||||
|
||||
bflb_group0_release_sha_access(sha);
|
||||
while (1) {
|
||||
bflb_mtimer_delay_ms(2000);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
#set(CONFIG_XXX 1)
|
|
@ -45,7 +45,7 @@ const uint8_t sha512_testsum[2][128] = {
|
|||
0x84, 0x21, 0xc5, 0x75, 0x9c, 0x85, 0xc3, 0x37 }
|
||||
};
|
||||
|
||||
static struct bflb_sha_link_s sha256_link = {
|
||||
ATTR_NOCACHE_RAM_SECTION struct bflb_sha_link_s sha256_link = {
|
||||
.sha_mode = SHA_MODE_SHA256, /* Sha-256 */
|
||||
.sha_newhash_dis = 0, /* New hash */
|
||||
.sha_intclr = 0, /* Not clear interrupt */
|
||||
|
@ -56,7 +56,7 @@ static struct bflb_sha_link_s sha256_link = {
|
|||
{ 0 } /* Result of SHA */
|
||||
};
|
||||
|
||||
static struct bflb_sha_link_s sha512_link = {
|
||||
ATTR_NOCACHE_RAM_SECTION struct bflb_sha_link_s sha512_link = {
|
||||
.sha_mode = SHA_MODE_SHA512, /* Sha-512 */
|
||||
.sha_newhash_dis = 0, /* New hash */
|
||||
.sha_intclr = 0, /* Not clear interrupt */
|
||||
|
@ -67,12 +67,12 @@ static struct bflb_sha_link_s sha512_link = {
|
|||
{ 0 } /* Result of SHA */
|
||||
};
|
||||
|
||||
ATTR_NOCACHE_RAM_SECTION __attribute__((aligned(32))) uint8_t sha_input_buf[1000];
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION __attribute__((aligned(32))) uint8_t sha_input_buf[1000];
|
||||
|
||||
uint8_t sha_output_buf[128];
|
||||
|
||||
ATTR_NOCACHE_RAM_SECTION struct bflb_sha256_ctx_s ctx_sha256;
|
||||
ATTR_NOCACHE_RAM_SECTION struct bflb_sha512_ctx_s ctx_sha512;
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION struct bflb_sha256_link_ctx_s ctx_sha256;
|
||||
ATTR_NOCACHE_NOINIT_RAM_SECTION struct bflb_sha512_link_ctx_s ctx_sha512;
|
||||
|
||||
static uint32_t bflb_data_compare(const uint8_t *expected, uint8_t *input, uint32_t len)
|
||||
{
|
||||
|
@ -100,22 +100,21 @@ int main(void)
|
|||
|
||||
bflb_sha_link_init(sha);
|
||||
|
||||
bflb_sha256_link_start(sha, &ctx_sha256);
|
||||
bflb_sha256_link_start(sha, &ctx_sha256, &sha256_link);
|
||||
memcpy(sha_input_buf, sha256_testbuf[0], 104);
|
||||
bflb_sha256_link_update(sha, &ctx_sha256, (uint32_t)&sha256_link, sha_input_buf, 80);
|
||||
bflb_sha256_link_update(sha, &ctx_sha256, (uint32_t)&sha256_link, &sha_input_buf[80], 104 - 80);
|
||||
bflb_sha256_link_finish(sha, &ctx_sha256, (uint32_t)&sha256_link, sha_output_buf);
|
||||
bflb_sha256_link_update(sha, &ctx_sha256, sha_input_buf, 80);
|
||||
bflb_sha256_link_update(sha, &ctx_sha256, &sha_input_buf[80], 104 - 80);
|
||||
bflb_sha256_link_finish(sha, &ctx_sha256, sha_output_buf);
|
||||
bflb_data_compare(sha256_testsum[0], sha_output_buf, 32);
|
||||
printf("sha256 link success\r\n");
|
||||
|
||||
bflb_sha512_link_start(sha, &ctx_sha512);
|
||||
bflb_sha512_link_start(sha, &ctx_sha512, &sha512_link);
|
||||
memcpy(sha_input_buf, sha512_testbuf[0], 208);
|
||||
bflb_sha512_link_update(sha, &ctx_sha512, (uint32_t)&sha512_link, sha_input_buf, 160);
|
||||
bflb_sha512_link_update(sha, &ctx_sha512, (uint32_t)&sha512_link, &sha_input_buf[160], 208 - 80);
|
||||
bflb_sha512_link_finish(sha, &ctx_sha512, (uint32_t)&sha512_link, sha_output_buf);
|
||||
bflb_sha512_link_update(sha, &ctx_sha512, sha_input_buf, 160);
|
||||
bflb_sha512_link_update(sha, &ctx_sha512, &sha_input_buf[160], 208 - 160);
|
||||
bflb_sha512_link_finish(sha, &ctx_sha512, sha_output_buf);
|
||||
bflb_data_compare(sha512_testsum[0], sha_output_buf, 64);
|
||||
printf("sha512 link success\r\n");
|
||||
|
||||
bflb_group0_release_sha_access(sha);
|
||||
while (1) {
|
||||
bflb_mtimer_delay_ms(2000);
|
||||
|
|
|
@ -11,8 +11,8 @@ struct bflb_device_s *spi0;
|
|||
struct bflb_device_s *dma0_ch0;
|
||||
struct bflb_device_s *dma0_ch1;
|
||||
|
||||
static ATTR_NOCACHE_RAM_SECTION uint32_t tx_buffer[256];
|
||||
static ATTR_NOCACHE_RAM_SECTION uint32_t rx_buffer[256];
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint32_t tx_buffer[256];
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint32_t rx_buffer[256];
|
||||
|
||||
static volatile uint8_t dma_tc_flag0 = 0;
|
||||
static volatile uint8_t dma_tc_flag1 = 0;
|
||||
|
|
|
@ -53,21 +53,21 @@ int main(void)
|
|||
struct bflb_timer_config_s cfg0;
|
||||
cfg0.counter_mode = TIMER_COUNTER_MODE_PROLOAD; /* preload when match occur */
|
||||
cfg0.clock_source = TIMER_CLKSRC_XTAL;
|
||||
cfg0.clock_div = 0; /* for bl616/bl808/bl606p is 39, for bl702 is 31 */
|
||||
cfg0.clock_div = 39; /* for bl616/bl808/bl606p is 39, for bl702 is 31 */
|
||||
cfg0.trigger_comp_id = TEST_TIMER_COMP_ID;
|
||||
cfg0.comp0_val = 230000; /* match value 0 */
|
||||
cfg0.comp1_val = 260000; /* match value 1 */
|
||||
cfg0.comp2_val = 290000; /* match value 2 */
|
||||
cfg0.comp0_val = 1000000; /* match value 0 */
|
||||
cfg0.comp1_val = 1500000; /* match value 1 */
|
||||
cfg0.comp2_val = 2500000; /* match value 2 */
|
||||
cfg0.preload_val = 0; /* preload value */
|
||||
|
||||
struct bflb_timer_config_s cfg1;
|
||||
cfg1.counter_mode = TIMER_COUNTER_MODE_PROLOAD;
|
||||
cfg1.clock_source = TIMER_CLKSRC_XTAL;
|
||||
cfg1.clock_div = 0; /* for bl616/bl808/bl606p is 39, for bl702 is 31 */
|
||||
cfg1.clock_div = 39; /* for bl616/bl808/bl606p is 39, for bl702 is 31 */
|
||||
cfg1.trigger_comp_id = TEST_TIMER_COMP_ID;
|
||||
cfg1.comp0_val = 330000; /* match value 0 */
|
||||
cfg1.comp1_val = 360000; /* match value 1 */
|
||||
cfg1.comp2_val = 390000; /* match value 2 */
|
||||
cfg1.comp0_val = 1000000; /* match value 0 */
|
||||
cfg1.comp1_val = 1500000; /* match value 1 */
|
||||
cfg1.comp2_val = 2500000; /* match value 2 */
|
||||
cfg1.preload_val = 0; /* preload value */
|
||||
|
||||
timer0 = bflb_device_get_by_name("timer0");
|
||||
|
|
|
@ -8,10 +8,10 @@ struct bflb_device_s *uart1;
|
|||
struct bflb_device_s *dma0_ch0;
|
||||
struct bflb_device_s *dma0_ch1;
|
||||
|
||||
static ATTR_NOCACHE_RAM_SECTION uint8_t src_buffer[4100];
|
||||
static ATTR_NOCACHE_RAM_SECTION uint8_t src2_buffer[4100];
|
||||
static ATTR_NOCACHE_RAM_SECTION uint8_t src3_buffer[4100];
|
||||
static ATTR_NOCACHE_RAM_SECTION uint8_t receive_buffer[50] = { 0 };
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t src_buffer[4100];
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t src2_buffer[4100];
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t src3_buffer[4100];
|
||||
static ATTR_NOCACHE_NOINIT_RAM_SECTION uint8_t receive_buffer[50] = { 0 };
|
||||
|
||||
static volatile uint8_t dma_tc_flag0 = 0;
|
||||
static volatile uint8_t dma_tc_flag1 = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue