You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.5 KiB
100 lines
2.5 KiB
4 months ago
|
/*
|
||
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2021. All rights reserved.
|
||
|
* Description: Test the file of the msid interface.
|
||
|
* Author: Hisilicon
|
||
|
* Create: 2019-09-20
|
||
|
*/
|
||
|
#include "sample_otp_base.h"
|
||
|
|
||
|
#define RSA_KEY_LEN 512
|
||
|
|
||
|
static td_s32 get_rsa_lock(td_s32 argc, td_char *argv[]);
|
||
|
static td_s32 set_rsa(td_s32 argc, td_char *argv[]);
|
||
|
|
||
|
static otp_sample g_otp_sample_data[] = {
|
||
|
{ 0, "help", NULL, { "Display this help and exit.", "example: ./sample_otp_rsa help" } },
|
||
|
{
|
||
|
1, "set", set_rsa,
|
||
|
{ "Set rsakey.", "example: ./sample_otp_rsa set" }
|
||
|
},
|
||
|
{
|
||
|
2, "get", get_rsa_lock,
|
||
|
{ "Get rsakey.", "example: ./sample_otp_rsa get" }
|
||
|
},
|
||
|
};
|
||
|
|
||
|
static td_s32 get_rsa_lock(td_s32 argc, td_char *argv[])
|
||
|
{
|
||
|
td_s32 ret;
|
||
|
td_bool lock;
|
||
|
|
||
|
ret = uapi_otp_get_asymmetric_key_lock_stat(UAPI_OTP_ASYMMETRIC_KEY_RSA, &lock);
|
||
|
if (ret != TD_SUCCESS) {
|
||
|
sample_printf("get asymmetric key lock stat, ret = 0x%x \n", ret);
|
||
|
goto out;
|
||
|
}
|
||
|
|
||
|
if (lock == TD_TRUE) {
|
||
|
printf("rsa is locked!\n");
|
||
|
} else {
|
||
|
printf("rsa is not locked!\n");
|
||
|
}
|
||
|
|
||
|
unused(argc);
|
||
|
unused(argv);
|
||
|
out:
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
static td_s32 set_rsa(td_s32 argc, td_char *argv[])
|
||
|
{
|
||
|
td_s32 ret;
|
||
|
/* RSA key: The total length is 512. The first 256 bits are rsa_n_key and the last 16 bits are rsa_e_key. */
|
||
|
td_u8 rsa[RSA_KEY_LEN] = {0};
|
||
|
|
||
|
ret = uapi_otp_set_asymmetric_key(UAPI_OTP_ASYMMETRIC_KEY_RSA, rsa, sizeof(rsa));
|
||
|
if (ret != TD_SUCCESS) {
|
||
|
sample_printf("set asymmetric key, ret = 0x%x \n", ret);
|
||
|
goto out;
|
||
|
}
|
||
|
|
||
|
print_buffer("Set rsa", rsa, sizeof(rsa));
|
||
|
|
||
|
unused(argc);
|
||
|
unused(argv);
|
||
|
out:
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
td_s32 main(int argc, char *argv[])
|
||
|
{
|
||
|
td_s32 ret;
|
||
|
|
||
|
if (argc < 0x2 || argv == TD_NULL) {
|
||
|
sample_printf("sample parameter error.\n");
|
||
|
ret = SOC_ERR_OTP_INVALID_PARA;
|
||
|
goto out1;
|
||
|
}
|
||
|
|
||
|
if (case_strcmp("help", argv[1])) {
|
||
|
show_usage(g_otp_sample_data, sizeof(g_otp_sample_data) / sizeof(g_otp_sample_data[0]));
|
||
|
ret = TD_SUCCESS;
|
||
|
goto out0;
|
||
|
}
|
||
|
|
||
|
ret = uapi_otp_init();
|
||
|
if (ret != TD_SUCCESS) {
|
||
|
sample_printf("OTP init failed, ret = 0x%x \n", ret);
|
||
|
goto out1;
|
||
|
}
|
||
|
|
||
|
ret = run_cmdline(argc, argv, g_otp_sample_data, sizeof(g_otp_sample_data) / sizeof(g_otp_sample_data[0]));
|
||
|
|
||
|
(td_void)uapi_otp_deinit();
|
||
|
|
||
|
out1:
|
||
|
show_returne_msg(g_otp_sample_data, sizeof(g_otp_sample_data) / sizeof(g_otp_sample_data[0]), ret);
|
||
|
out0:
|
||
|
return ret;
|
||
|
}
|