luckfox-pico-sdk/media/security/librkcrypto/test/test_utils.c
luckfox-eng29 8f34c2760d project:build.sh: Added fastboot support; custom modifications to U-Boot and kernel implemented using patches.
project:cfg:BoardConfig_IPC: Added fastboot BoardConfig file and firmware post-scripts, distinguishing between
the BoardConfigs for Luckfox Pico Pro and Luckfox Pico Max. project:app: Added fastboot_client and rk_smart_door
for quick boot applications; updated rkipc app to adapt to the latest media library. media:samples: Added more
usage examples. media:rockit: Fixed bugs; removed support for retrieving data frames from VPSS. media:isp:
Updated rkaiq library and related tools to support connection to RKISP_Tuner. sysdrv:Makefile: Added support for
compiling drv_ko on Luckfox Pico Ultra W using Ubuntu; added support for custom root filesystem.
sysdrv:tools:board: Updated Buildroot optional mirror sources, updated some software versions, and stored device
tree files and configuration files that undergo multiple modifications for U-Boot and kernel separately.
sysdrv:source:mcu: Used RISC-V MCU SDK with RT-Thread system, mainly for initializing camera AE during quick
boot. sysdrv:source:uboot: Added support for fastboot; added high baud rate DDR bin for serial firmware upgrades.
sysdrv:source:kernel: Upgraded to version 5.10.160; increased NPU frequency for RV1106G3; added support for
fastboot.

Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
2024-10-14 09:47:04 +08:00

128 lines
2.9 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "rkcrypto_common.h"
#include "test_utils.h"
bool is_no_multi_blocksize(uint32_t mode)
{
if (mode == RK_CIPHER_MODE_CTS ||
mode == RK_CIPHER_MODE_CTR ||
mode == RK_CIPHER_MODE_CFB ||
mode == RK_CIPHER_MODE_OFB)
return true;
else
return false;
}
void test_get_rng(uint8_t *trn, uint32_t len)
{
static int init_flag;
if (!init_flag) {
srand(time(NULL));
init_flag = 1;
}
for (uint32_t i = 0; i < len; i++)
trn[i] = rand() & 0xff;
}
void test_dump_hex(char *var_name, const uint8_t *data, uint32_t len)
{
uint32_t i;
char buffer[256];
char *p;
printf("=================== %s [%u] ================\n", var_name, len);
p = buffer;
for (i = 0; i < len; i++) {
if (i % 16 == 0 && i != 0) {
printf("%s\n", buffer);
p = buffer;
memset(buffer, 0x00, sizeof(buffer));
}
p += snprintf(p, 256, "%02x ", data[i]);
}
printf("%s\n", buffer);
}
struct test_name_map {
uint32_t id;
const char *name;
};
static const struct test_name_map algo_map_tbl[] = {
{RK_ALGO_AES, "AES"},
{RK_ALGO_DES, "DES"},
{RK_ALGO_TDES, "TDES"},
{RK_ALGO_SM4, "SM4"},
{RK_ALGO_MD5, "MD5"},
{RK_ALGO_SHA1, "SHA1"},
{RK_ALGO_SHA256, "SHA256"},
{RK_ALGO_SHA224, "SHA224"},
{RK_ALGO_SHA512, "SHA512"},
{RK_ALGO_SHA384, "SHA384"},
{RK_ALGO_SHA512_224, "SHA512_224"},
{RK_ALGO_SHA512_256, "SHA512_256"},
{RK_ALGO_SM3, "SM3"},
{RK_ALGO_HMAC_MD5, "HMAC_MD5"},
{RK_ALGO_HMAC_SHA1, "HMAC_SHA1"},
{RK_ALGO_HMAC_SHA256, "HMAC_SHA256"},
{RK_ALGO_HMAC_SHA512, "HMAC_SHA512"},
{RK_ALGO_HMAC_SM3, "HMAC_SM3"},
{RK_ALGO_CMAC_SM4, "CMAC_SM4"},
{RK_ALGO_CBCMAC_SM4, "CBCMAC_SM4"},
{RK_ALGO_CMAC_AES, "CMAC_AES"},
{RK_ALGO_CBCMAC_AES, "CBCMAC_AES"},
};
static const struct test_name_map mode_map_tbl[] = {
{RK_CIPHER_MODE_ECB, "ECB"},
{RK_CIPHER_MODE_CBC, "CBC"},
{RK_CIPHER_MODE_CTS, "CTS"},
{RK_CIPHER_MODE_CTR, "CTR"},
{RK_CIPHER_MODE_CFB, "CFB"},
{RK_CIPHER_MODE_OFB, "OFB"},
{RK_CIPHER_MODE_XTS, "XTS"},
{RK_CIPHER_MODE_CCM, "CCM"},
{RK_CIPHER_MODE_GCM, "GCM"},
};
static const struct test_name_map ops_map_tbl[] = {
{RK_OP_CIPHER_ENC, "ENCRYPT"},
{RK_OP_CIPHER_DEC, "DECRYPT"},
};
static const char *get_name_from_map(uint32_t id, const struct test_name_map *map, uint32_t map_cnt)
{
uint32_t i;
for (i = 0; i < map_cnt; i++, map++) {
if (map->id == id)
return map->name;
}
return "Unknown";
}
const char *test_algo_name(uint32_t algo)
{
return get_name_from_map(algo, &algo_map_tbl[0], ARRAY_SIZE(algo_map_tbl));
}
const char *test_mode_name(uint32_t mode)
{
return get_name_from_map(mode, &mode_map_tbl[0], ARRAY_SIZE(mode_map_tbl));
}
const char *test_op_name(uint32_t operation)
{
return get_name_from_map(operation, &ops_map_tbl[0], ARRAY_SIZE(ops_map_tbl));
}