mirror of
https://github.com/revyos/th1520-vendor-uboot.git
synced 2026-09-17 12:52:01 +02:00
Linux_SDK_V1.2.1
Signed-off-by: thead_admin <occ_thead@service.alibaba.com>
This commit is contained in:
20
lib/sec_library/include/aes.h
Executable file → Normal file
20
lib/sec_library/include/aes.h
Executable file → Normal file
@@ -40,20 +40,20 @@ extern "C" {
|
||||
#define AES_DMA_DISABLE (0)
|
||||
|
||||
/**
|
||||
\brief DES data transfer mode config
|
||||
\brief AES data transfer mode config
|
||||
*/
|
||||
typedef enum {
|
||||
AES_SLAVE_MODE = 0U, ///< slave mode
|
||||
AES_DMA_MODE, ///< dma mode
|
||||
AES_SLAVE_MODE = 0U, /*slave mode*/
|
||||
AES_DMA_MODE, /*dma mode*/
|
||||
} csi_aes_trans_mode_t;
|
||||
|
||||
/**
|
||||
\brief AES Keylen type
|
||||
*/
|
||||
typedef enum {
|
||||
AES_KEY_LEN_BITS_128 = 0, ///< 128 Data bits
|
||||
AES_KEY_LEN_BITS_192, ///< 192 Data bits
|
||||
AES_KEY_LEN_BITS_256 ///< 256 Data bits
|
||||
AES_KEY_LEN_BITS_128 = 0, /*128 Data bits*/
|
||||
AES_KEY_LEN_BITS_192, /*192 Data bits*/
|
||||
AES_KEY_LEN_BITS_256 /*256 Data bits*/
|
||||
} csi_aes_key_bits_t;
|
||||
|
||||
/**
|
||||
@@ -73,8 +73,8 @@ typedef enum{
|
||||
\brief AES state
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t busy : 1; ///< Calculate busy flag
|
||||
uint32_t error : 1; ///< Calculate error flag
|
||||
uint32_t busy : 1; /*Calculate busy flag*/
|
||||
uint32_t error : 1; /*Calculate error flag*/
|
||||
} csi_aes_state_t;
|
||||
|
||||
/**
|
||||
@@ -82,7 +82,7 @@ typedef struct {
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t key_len_byte;
|
||||
uint8_t key[32]; ///< Data block being processed
|
||||
uint8_t key[32]; /*Data block being processed*/
|
||||
uint32_t sca;
|
||||
uint32_t is_kdf;
|
||||
uint32_t is_dma;
|
||||
@@ -350,7 +350,7 @@ void csi_aes_disable_pm(csi_aes_t *aes);
|
||||
\param[in] mode \ref csi_des_trans_mode_t
|
||||
\return None
|
||||
*/
|
||||
void csi_aes_trans_config(csi_aes_t *aes, csi_aes_trans_mode_t mode);
|
||||
csi_error_t csi_aes_trans_config(csi_aes_t *aes, csi_aes_trans_mode_t mode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
2
lib/sec_library/include/common.h
Executable file → Normal file
2
lib/sec_library/include/common.h
Executable file → Normal file
@@ -134,6 +134,8 @@ typedef struct {
|
||||
|
||||
csi_error_t target_get(csi_dev_tag_t dev_tag, uint32_t idx, csi_dev_t *dev);
|
||||
csi_error_t target_get_optimal_dma_channel(void *dma_list, uint32_t ctrl_num, csi_dev_t *parent_dev, void *ch_info);
|
||||
// void mdelay(uint32_t ms);
|
||||
// void udelay(uint32_t us);
|
||||
void msleep(uint32_t ms);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
0
lib/sec_library/include/core/README.txt
Executable file → Normal file
0
lib/sec_library/include/core/README.txt
Executable file → Normal file
0
lib/sec_library/include/core/cmsis/ARMCM0.h
Executable file → Normal file
0
lib/sec_library/include/core/cmsis/ARMCM0.h
Executable file → Normal file
0
lib/sec_library/include/core/cmsis/cmsis_compiler.h
Executable file → Normal file
0
lib/sec_library/include/core/cmsis/cmsis_compiler.h
Executable file → Normal file
0
lib/sec_library/include/core/cmsis/cmsis_gcc.h
Executable file → Normal file
0
lib/sec_library/include/core/cmsis/cmsis_gcc.h
Executable file → Normal file
0
lib/sec_library/include/core/cmsis/cmsis_version.h
Executable file → Normal file
0
lib/sec_library/include/core/cmsis/cmsis_version.h
Executable file → Normal file
0
lib/sec_library/include/core/cmsis/core_cm0.h
Executable file → Normal file
0
lib/sec_library/include/core/cmsis/core_cm0.h
Executable file → Normal file
0
lib/sec_library/include/core/cmsis/csi_core.h
Executable file → Normal file
0
lib/sec_library/include/core/cmsis/csi_core.h
Executable file → Normal file
0
lib/sec_library/include/core/cmsis/system_ARMCM0.h
Executable file → Normal file
0
lib/sec_library/include/core/cmsis/system_ARMCM0.h
Executable file → Normal file
0
lib/sec_library/include/core/core_801.h
Executable file → Normal file
0
lib/sec_library/include/core/core_801.h
Executable file → Normal file
0
lib/sec_library/include/core/core_802.h
Executable file → Normal file
0
lib/sec_library/include/core/core_802.h
Executable file → Normal file
0
lib/sec_library/include/core/core_803.h
Executable file → Normal file
0
lib/sec_library/include/core/core_803.h
Executable file → Normal file
0
lib/sec_library/include/core/core_804.h
Executable file → Normal file
0
lib/sec_library/include/core/core_804.h
Executable file → Normal file
0
lib/sec_library/include/core/core_805.h
Executable file → Normal file
0
lib/sec_library/include/core/core_805.h
Executable file → Normal file
0
lib/sec_library/include/core/core_807.h
Executable file → Normal file
0
lib/sec_library/include/core/core_807.h
Executable file → Normal file
0
lib/sec_library/include/core/core_810.h
Executable file → Normal file
0
lib/sec_library/include/core/core_810.h
Executable file → Normal file
0
lib/sec_library/include/core/core_ck610.h
Executable file → Normal file
0
lib/sec_library/include/core/core_ck610.h
Executable file → Normal file
0
lib/sec_library/include/core/core_ck801.h
Executable file → Normal file
0
lib/sec_library/include/core/core_ck801.h
Executable file → Normal file
0
lib/sec_library/include/core/core_ck802.h
Executable file → Normal file
0
lib/sec_library/include/core/core_ck802.h
Executable file → Normal file
0
lib/sec_library/include/core/core_ck803.h
Executable file → Normal file
0
lib/sec_library/include/core/core_ck803.h
Executable file → Normal file
0
lib/sec_library/include/core/core_ck807.h
Executable file → Normal file
0
lib/sec_library/include/core/core_ck807.h
Executable file → Normal file
0
lib/sec_library/include/core/core_ck810.h
Executable file → Normal file
0
lib/sec_library/include/core/core_ck810.h
Executable file → Normal file
0
lib/sec_library/include/core/core_rv32.h
Executable file → Normal file
0
lib/sec_library/include/core/core_rv32.h
Executable file → Normal file
0
lib/sec_library/include/core/core_rv64.h
Executable file → Normal file
0
lib/sec_library/include/core/core_rv64.h
Executable file → Normal file
0
lib/sec_library/include/core/csi_gcc.h
Executable file → Normal file
0
lib/sec_library/include/core/csi_gcc.h
Executable file → Normal file
0
lib/sec_library/include/core/csi_rv32_gcc.h
Executable file → Normal file
0
lib/sec_library/include/core/csi_rv32_gcc.h
Executable file → Normal file
0
lib/sec_library/include/core/csi_rv64_gcc.h
Executable file → Normal file
0
lib/sec_library/include/core/csi_rv64_gcc.h
Executable file → Normal file
0
lib/sec_library/include/csi_core.h
Executable file → Normal file
0
lib/sec_library/include/csi_core.h
Executable file → Normal file
@@ -21,7 +21,7 @@ typedef enum {
|
||||
IMAGE_ENCRYPT_EN = ~(IMAGE_ENCRYPT_DIS),
|
||||
} img_encrypt_st_t;
|
||||
|
||||
int csi_efuse_api_int(void);
|
||||
int csi_efuse_api_init(void);
|
||||
void csi_efuse_api_uninit(void);
|
||||
|
||||
int csi_efuse_get_secure_boot_st(sboot_st_t *sboot_st);
|
||||
@@ -48,8 +48,10 @@ int csi_efuse_read_raw(uint32_t addr, void *data, uint32_t cnt);
|
||||
|
||||
int csi_efuse_write_raw(uint32_t addr, const void *data, uint32_t cnt);
|
||||
|
||||
int csi_efuse_get_lc(int *lc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CSI_EFUSE_API_H__ */
|
||||
#endif /* __CSI_EFUSE_API_H__ */
|
||||
|
||||
2
lib/sec_library/include/csi_sec_img_verify.h
Executable file → Normal file
2
lib/sec_library/include/csi_sec_img_verify.h
Executable file → Normal file
@@ -24,6 +24,8 @@ int csi_sec_set_boot_stage(boot_stage_t boot_stage);
|
||||
|
||||
int csi_sec_get_lib_version(char ** p_version);
|
||||
|
||||
int csi_sec_library_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
86
lib/sec_library/include/curve25519.h
Normal file
86
lib/sec_library/include/curve25519.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2022 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file drv/curve25519.h
|
||||
* @brief Header File for CURVE25519 Driver
|
||||
* @version V3.3
|
||||
* @date 10.June 2022
|
||||
* @model ECC
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _DRV_CURVE25519_H_
|
||||
#define _DRV_CURVE25519_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
csi_dev_t dev;
|
||||
} csi_curve25519_t;
|
||||
|
||||
/**
|
||||
\brief Initialize CURVE25519.
|
||||
\param[in] idx device id
|
||||
\return Error code \ref csi_error_t
|
||||
*/
|
||||
csi_error_t csi_curve25519_init(void *ctx, uint32_t idx);
|
||||
|
||||
/**
|
||||
\brief De-initialize CURVE25519 Interface. stops operation and releases the software resources used by the interface
|
||||
\param[in] curve25519 ecc handle to operate.
|
||||
\return none
|
||||
*/
|
||||
void csi_curve25519_uninit(void *ctx);
|
||||
|
||||
/**
|
||||
\brief curve25519 gen public key
|
||||
\param[in] ctx ctx handle to operate.
|
||||
\param[in] privkey Pointer to the A(or B) private key.
|
||||
\param[out] pubkey Pointer to the A(or B) public key.
|
||||
\return Error code \ref csi_error_t.
|
||||
*/
|
||||
csi_error_t csi_curve25519_gen_pubkey(void *ctx, const uint8_t privkey[32], uint8_t pubkey[32]);
|
||||
|
||||
/**
|
||||
\brief curve25519 gen key pair
|
||||
\param[in] ctx ctx handle to operate.
|
||||
\param[out] privkey Pointer to the A(or B) private key.
|
||||
\param[out] pubkey Pointer to the A(or B) public key.
|
||||
\return Error code \ref csi_error_t.
|
||||
*/
|
||||
csi_error_t csi_curve25519_gen_keypair(void *ctx, uint8_t privkey[32], uint8_t pubkey[32]);
|
||||
|
||||
/**
|
||||
\brief curve25519 check key pair
|
||||
\param[in] ctx ctx handle to operate.
|
||||
\param[in] privkey Pointer to the B(or A) private key.
|
||||
\param[in] pubkey Pointer to the A(or B) public key.
|
||||
\param[out] sk Pointer to the share key.
|
||||
\param[out] sk_len Pointer to the share key length byte.
|
||||
\return Error code \ref csi_error_t.
|
||||
*/
|
||||
csi_error_t csi_curve25519_check_keypair(void *ctx, const uint8_t privkey[32], const uint8_t pubkey[32]);
|
||||
|
||||
/**
|
||||
\brief curve25519 check key pair
|
||||
\param[in] ctx ctx handle to operate.
|
||||
\param[in] privkey Pointer to the B(or A) private key.
|
||||
\param[in] pubkey Pointer to the A(or B) public key.
|
||||
\param[out] sk Pointer to the share key.
|
||||
\param[out] sk_len Pointer to the share key length byte.
|
||||
\return Error code \ref csi_error_t.
|
||||
*/
|
||||
csi_error_t csi_curve25519_calc_secret(void *ctx, const uint8_t privkey[32], const uint8_t pubkey[32], uint8_t sk[32], uint32_t *sk_len);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -25,17 +25,17 @@ extern "C" {
|
||||
\brief DES data transfer mode config
|
||||
*/
|
||||
typedef enum {
|
||||
DES_SLAVE_MODE = 0U, ///< slave mode
|
||||
DES_DMA_MODE, ///< dma mode
|
||||
DES_SLAVE_MODE = 0U, /*slave mode*/
|
||||
DES_DMA_MODE, /*dma mode*/
|
||||
} csi_des_trans_mode_t;
|
||||
|
||||
/**
|
||||
\brief DES key-len-bits type
|
||||
*/
|
||||
typedef enum {
|
||||
DES_KEY_LEN_BITS_64 = 0, ///< 64 Data bits
|
||||
DES_KEY_LEN_BITS_128, ///< 128 Data bits
|
||||
DES_KEY_LEN_BITS_192, ///< 192 Data bits
|
||||
DES_KEY_LEN_BITS_64 = 0, /*64 Data bits*/
|
||||
DES_KEY_LEN_BITS_128, /*128 Data bits*/
|
||||
DES_KEY_LEN_BITS_192, /*192 Data bits*/
|
||||
} csi_des_key_bits_t;
|
||||
|
||||
typedef enum{
|
||||
@@ -51,7 +51,7 @@ typedef enum{
|
||||
#define DES_KEY_LEN_BYTES_24 (24)
|
||||
#define DES_KEY_LEN_BYTES_8 (8)
|
||||
|
||||
#define DES_BLOCK_IV_SIZE (16)
|
||||
#define DES_BLOCK_IV_SIZE (8)
|
||||
#define DES_BLOCK_CRYPTO_SIZE (8)
|
||||
#define TDES_BLOCK_CRYPTO_SIZE (16)
|
||||
|
||||
@@ -65,8 +65,8 @@ typedef enum{
|
||||
\brief DES State
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t busy : 1; ///< Calculate busy flag
|
||||
uint32_t error : 1; ///< Calculate error flag
|
||||
uint32_t busy : 1; /*Calculate busy flag*/
|
||||
uint32_t error : 1; /*Calculate error flag*/
|
||||
} csi_des_state_t;
|
||||
|
||||
/**
|
||||
@@ -74,7 +74,7 @@ typedef struct {
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t key_len_byte;
|
||||
uint8_t key[32]; ///< Data block being processed
|
||||
uint8_t key[32]; /*Data block being processed*/
|
||||
uint32_t sca;
|
||||
uint32_t is_kdf;
|
||||
uint32_t is_dma;
|
||||
@@ -212,7 +212,7 @@ csi_error_t csi_tdes_cbc_decrypt(csi_des_t *des, void *in, void *out, uint32_t s
|
||||
\param[in] mode \ref csi_des_trans_mode_t
|
||||
\return None
|
||||
*/
|
||||
void csi_des_trans_config(csi_des_t *des, csi_des_trans_mode_t mode);
|
||||
csi_error_t csi_des_trans_config(csi_des_t *des, csi_des_trans_mode_t mode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
0
lib/sec_library/include/dev_tag.h
Executable file → Normal file
0
lib/sec_library/include/dev_tag.h
Executable file → Normal file
0
lib/sec_library/include/device_types.h
Executable file → Normal file
0
lib/sec_library/include/device_types.h
Executable file → Normal file
178
lib/sec_library/include/dsa.h
Normal file
178
lib/sec_library/include/dsa.h
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2022 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file drv/ecc.h
|
||||
* @brief Header File for ECC Driver
|
||||
* @version V3.3
|
||||
* @date 30. May 2022
|
||||
* @model ECC
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _DRV_DSA_H_
|
||||
#define _DRV_DSA_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define CSI_DSA_SHA1_PUBKEY_LEN (128)
|
||||
#define CSI_DSA_SHA1_PRIVKEY_LEN (20)
|
||||
#define CSI_DSA_SHA1_RK_LEN (20) /*random*/
|
||||
#define CSI_DSA_SHA1_SIGNATURE_LEN (40)
|
||||
#define CSI_DSA_SHA1_DIGEST_LEN (20)
|
||||
|
||||
#define CSI_DSA_SHA256_PUBKEY_LEN (256)
|
||||
#define CSI_DSA_SHA256_PRIVKEY_LEN (32)
|
||||
#define CSI_DSA_SHA256_RK_LEN (32) /*random*/
|
||||
#define CSI_DSA_SHA256_SIGNATURE_LEN (64)
|
||||
#define CSI_DSA_SHA256_DIGEST_LEN (32)
|
||||
|
||||
#define CSI_DSA_SHA224_PUBKEY_LEN (256)
|
||||
#define CSI_DSA_SHA224_PRIVKEY_LEN (28)
|
||||
#define CSI_DSA_SHA224_RK_LEN (28) /*random*/
|
||||
#define CSI_DSA_SHA224_SIGNATURE_LEN (56)
|
||||
#define CSI_DSA_SHA224_DIGEST_LEN (28)
|
||||
|
||||
#define CSI_DSA_SHA1_SHIFT_BYTES (1*4)
|
||||
#define CSI_DSA_SHA224_SHIFT_BYTES (1*4)
|
||||
|
||||
#define DSA_SHA1_GROUP_P_G_BYTES (128)
|
||||
#define DSA_SHA1_GROUP_PARAM_WORDS (76)
|
||||
#define DSA_SHA1_GROUP_N_BYTES (20)
|
||||
#define DSA_SHA1_A_LEN_WORDS (0x20)
|
||||
#define DSA_SHA1_B_LEN_WORDS (0x05)
|
||||
|
||||
#define DSA_SHA256_GROUP_P_G_BYTES (256)
|
||||
#define DSA_SHA256_GROUP_PARAM_WORDS (140)
|
||||
#define DSA_SHA256_GROUP_N_BYTES (32)
|
||||
#define DSA_SHA256_A_LEN_WORDS (0x40)
|
||||
#define DSA_SHA256_B_LEN_WORDS (0x08)
|
||||
|
||||
#define DSA_SHA224_GROUP_P_G_BYTES (256)
|
||||
#define DSA_SHA224_GROUP_PARAM_WORDS (140)
|
||||
#define DSA_SHA224_GROUP_N_BYTES (28)
|
||||
#define DSA_SHA224_A_LEN_WORDS (0x40)
|
||||
#define DSA_SHA224_B_LEN_WORDS (0x07)
|
||||
|
||||
|
||||
/**
|
||||
\brief DSA sha type
|
||||
*/
|
||||
typedef enum {
|
||||
DSA_SHA1 = 0,
|
||||
DSA_SHA224,
|
||||
DSA_SHA256,
|
||||
DSA_SHA_TYPE_MAX,
|
||||
} dsa_sha_type;
|
||||
|
||||
/**
|
||||
\brief DSA group param
|
||||
*/
|
||||
typedef struct {
|
||||
dsa_sha_type type;
|
||||
uint32_t *group;
|
||||
uint32_t words;
|
||||
uint32_t offset;
|
||||
} csi_dsa_group_t;
|
||||
|
||||
/**
|
||||
\brief DSA g param
|
||||
*/
|
||||
typedef struct {
|
||||
dsa_sha_type type;
|
||||
uint8_t *p;
|
||||
uint8_t *g;
|
||||
uint8_t *n;
|
||||
} csi_dsa_gpn_t;
|
||||
|
||||
typedef enum{
|
||||
CSI_DSA_SHA1_SIGN = 0,
|
||||
CSI_DSA_SHA1_VERIFY,
|
||||
CSI_DSA_SHA224_SIGN,
|
||||
CSI_DSA_SHA224_VERIFY,
|
||||
CSI_DSA_SHA256_SIGN,
|
||||
CSI_DSA_SHA256_VERIFY,
|
||||
CSI_DSA_FUN_MAX,
|
||||
}dsa_fun_type;
|
||||
|
||||
typedef struct {
|
||||
dsa_fun_type type;
|
||||
uint32_t dsa_pka_a_offset;
|
||||
uint32_t dsa_pka_b_offset;
|
||||
uint32_t dsa_pka_c_offset;
|
||||
uint32_t dsa_pka_d_offset;
|
||||
uint32_t dsa_pka_r_offset;
|
||||
uint32_t dsa_pka_s_offset;
|
||||
uint32_t dsa_pka_function;
|
||||
uint32_t dsa_pka_A_len;
|
||||
uint32_t dsa_pka_B_len;
|
||||
} csi_dsa_pka_offset_t;
|
||||
|
||||
/**
|
||||
\brief ECC handle
|
||||
*/
|
||||
typedef struct {
|
||||
csi_dev_t dev;
|
||||
dsa_sha_type sha_type;
|
||||
} csi_dsa_t;
|
||||
|
||||
/**
|
||||
\brief Initialize ECC.
|
||||
\param[in] idx device id
|
||||
\return Error code \ref csi_error_t
|
||||
*/
|
||||
csi_error_t csi_dsa_init(csi_dsa_t *dsa, uint32_t idx);
|
||||
|
||||
/**
|
||||
\brief De-initialize ECC Interface. stops operation and releases the software resources used by the interface
|
||||
\param[in] ecc ecc handle to operate.
|
||||
\return none
|
||||
*/
|
||||
void csi_dsa_uninit(csi_dsa_t *dsa);
|
||||
|
||||
/**
|
||||
\brief config dsa sha type
|
||||
\param[in] ecc ECC handle to operate.
|
||||
\param[in] type \ref dsa_sha_type.
|
||||
*/
|
||||
csi_error_t csi_dsa_config(csi_dsa_t *dsa, dsa_sha_type type);
|
||||
/**
|
||||
\brief dsa gen key pairs
|
||||
\param[in] ecc dsa handle to operate.
|
||||
\param[out] privkey Pointer to the private key
|
||||
\param[out] pubkey Pointer to the public key
|
||||
\return Error code \ref csi_error_t
|
||||
*/
|
||||
csi_error_t csi_dsa_gen_keypairs(csi_dsa_t *dsa, uint8_t *prikey, uint8_t *pubkey);
|
||||
|
||||
/**
|
||||
\brief dsa sign
|
||||
\param[in] ecc dsa handle to operate.
|
||||
\param[in] d Pointer to the digest.
|
||||
\param[out] privkey Pointer to the private key
|
||||
\param[out] s Pointer to the signature
|
||||
\return Error code \ref csi_error_t
|
||||
*/
|
||||
csi_error_t csi_dsa_sign(csi_dsa_t *dsa, uint8_t *d, uint8_t *prikey, uint8_t *s);
|
||||
|
||||
/**
|
||||
\brief dsa verify
|
||||
\param[in] ecc ecc handle to operate.
|
||||
\param[in] d Pointer to the digest.
|
||||
\param[out] privkey Pointer to the private key
|
||||
\param[out] s Pointer to the signature
|
||||
\return verify result
|
||||
*/
|
||||
bool csi_dsa_verify(csi_dsa_t *dsa, uint8_t *d, uint8_t *pubkey, uint8_t *s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
26
lib/sec_library/include/ecc.h
Executable file → Normal file
26
lib/sec_library/include/ecc.h
Executable file → Normal file
@@ -23,7 +23,7 @@ extern "C" {
|
||||
#define CSI_ECC_PUBKEY_LEN (65-1)
|
||||
#define CSI_ECC_PRIVKEY_LEN (32)
|
||||
#define CSI_ECC_PUBKEYTMP_LEN (65)
|
||||
#define CSI_ECC_RK_LEN (24) //random
|
||||
#define CSI_ECC_RK_LEN (32) /*random*/
|
||||
#define CSI_ECC_SIGNATURE_LEN (64)
|
||||
#define CSI_ECC_DIGEST_LEN (32)
|
||||
|
||||
@@ -31,7 +31,7 @@ extern "C" {
|
||||
#define ECC_PRIME_CURVE_P_BYTES (70)
|
||||
|
||||
typedef struct {
|
||||
uint32_t ecc_curve : 1; ///< supports 256bits curve
|
||||
uint32_t ecc_curve : 1; /*supports 256bits curve*/
|
||||
} ecc_capabilities_t;
|
||||
|
||||
/**
|
||||
@@ -46,8 +46,8 @@ typedef enum {
|
||||
\brief ECC endian mode
|
||||
*/
|
||||
typedef enum {
|
||||
ECC_ENDIAN_LITTLE = 0, ///< Little Endian
|
||||
ECC_ENDIAN_BIG ///< Big Endian
|
||||
ECC_ENDIAN_LITTLE = 0, /*Little Endian*/
|
||||
ECC_ENDIAN_BIG /*Big Endian*/
|
||||
} ecc_endian_mode_e;
|
||||
|
||||
/**
|
||||
@@ -64,12 +64,12 @@ typedef enum { ECC_Role_Sponsor = 0, ECC_Role_Responsor } ecc_exchange_role_e;
|
||||
|
||||
/****** ECC Event *****/
|
||||
typedef enum {
|
||||
ECC_EVENT_MAKE_KEY_COMPLETE = 0, ///< Make key completed
|
||||
ECC_EVENT_ENCRYPT_COMPLETE, ///< Encrypt completed
|
||||
ECC_EVENT_DECRYPT_COMPLETE, ///< Decrypt completed
|
||||
ECC_EVENT_SIGN_COMPLETE, ///< Sign completed
|
||||
ECC_EVENT_VERIFY_COMPLETE, ///< Verify completed
|
||||
ECC_EVENT_EXCHANGE_KEY_COMPLETE, ///< Exchange key completed
|
||||
ECC_EVENT_MAKE_KEY_COMPLETE = 0, /*Make key completed*/
|
||||
ECC_EVENT_ENCRYPT_COMPLETE, /*Encrypt completed*/
|
||||
ECC_EVENT_DECRYPT_COMPLETE, /*Decrypt completed*/
|
||||
ECC_EVENT_SIGN_COMPLETE, /*Sign completed*/
|
||||
ECC_EVENT_VERIFY_COMPLETE, /*Verify completed*/
|
||||
ECC_EVENT_EXCHANGE_KEY_COMPLETE, /*Exchange key completed*/
|
||||
} ecc_event_e;
|
||||
|
||||
/**
|
||||
@@ -93,7 +93,7 @@ typedef struct {
|
||||
\brief ECC status
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t busy : 1; ///< Calculate busy flag
|
||||
uint32_t busy : 1; /*Calculate busy flag*/
|
||||
} csi_ecc_state_t;
|
||||
|
||||
/**
|
||||
@@ -107,7 +107,7 @@ typedef struct {
|
||||
ecc_prime_curve_type type;
|
||||
} csi_ecc_t;
|
||||
|
||||
///< Pointer to \ref csi_ecc_callback_t : ECC Event call back.
|
||||
/*Pointer to \ref csi_ecc_callback_t : ECC Event call back.*/
|
||||
typedef void (*csi_ecc_callback_t)(ecc_event_e event);
|
||||
|
||||
/**
|
||||
@@ -300,7 +300,7 @@ csi_error_t csi_ecc_enable_pm(csi_ecc_t *ecc);
|
||||
void csi_ecc_disable_pm(csi_ecc_t *ecc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
2
lib/sec_library/include/ecdh.h
Executable file → Normal file
2
lib/sec_library/include/ecdh.h
Executable file → Normal file
@@ -37,7 +37,7 @@ extern "C" {
|
||||
csi_error_t csi_ecdh_calc_secret(csi_ecc_t *ecc, uint8_t privkey[32], uint8_t pubkey[65], uint8_t shareKey[32], uint32_t *len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
0
lib/sec_library/include/kdf.h
Executable file → Normal file
0
lib/sec_library/include/kdf.h
Executable file → Normal file
0
lib/sec_library/include/keyram.h
Executable file → Normal file
0
lib/sec_library/include/keyram.h
Executable file → Normal file
2
lib/sec_library/include/list.h
Executable file → Normal file
2
lib/sec_library/include/list.h
Executable file → Normal file
@@ -168,8 +168,10 @@ static inline int dlist_empty(const dlist_t *head)
|
||||
\param[in] member The name of the variable within the struct
|
||||
\return None
|
||||
*/
|
||||
#ifndef list_entry
|
||||
#define list_entry(ptr, type, member) \
|
||||
aos_container_of(ptr, type, member)
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
|
||||
0
lib/sec_library/include/rambus.h
Executable file → Normal file
0
lib/sec_library/include/rambus.h
Executable file → Normal file
10
lib/sec_library/include/rng.h
Executable file → Normal file
10
lib/sec_library/include/rng.h
Executable file → Normal file
@@ -22,16 +22,10 @@ extern "C" {
|
||||
/**
|
||||
\brief Get data from the TNG engine
|
||||
\param[out] Data Pointer to buffer with data get from TNG
|
||||
\param[in] Num Number of data items,uinit in uint32
|
||||
\param[in] Size Size of data items,uinit in uint32
|
||||
\return Error code \ref csi_error_t
|
||||
*/
|
||||
csi_error_t csi_rng_get_multi_word(uint32_t *data, uint32_t num);
|
||||
|
||||
/**
|
||||
\brief Get data from the TNG engine
|
||||
\return Error code \ref csi_error_t
|
||||
*/
|
||||
csi_error_t csi_rng_get_single_word(uint32_t* data);
|
||||
csi_error_t csi_rng_get_random_bytes(uint8_t *data, uint32_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
105
lib/sec_library/include/rsa.h
Executable file → Normal file
105
lib/sec_library/include/rsa.h
Executable file → Normal file
@@ -40,24 +40,52 @@ extern "C" {
|
||||
#define RSA_SHA384_OID_LEN (6 + 9 + 4)
|
||||
#define RSA_SHA512_OID_LEN (6 + 9 + 4)
|
||||
|
||||
#define RSA_192_A_LEN_WORDS (0x03)
|
||||
#define RSA_192_B_LEN_WORDS (0x03)
|
||||
#define RSA_192_D_LEN_WORDS (0x18)
|
||||
|
||||
#define RSA_256_A_LEN_WORDS (0x04)
|
||||
#define RSA_256_B_LEN_WORDS (0x04)
|
||||
#define RSA_256_D_LEN_WORDS (0x20)
|
||||
|
||||
#define RSA_512_A_LEN_WORDS (0x08)
|
||||
#define RSA_512_B_LEN_WORDS (0x08)
|
||||
#define RSA_512_D_LEN_WORDS (0x40)
|
||||
|
||||
#define RSA_1024_A_LEN_WORDS (0x10)
|
||||
#define RSA_1024_B_LEN_WORDS (0x10)
|
||||
#define RSA_1024_D_LEN_WORDS (0x80)
|
||||
|
||||
#define RSA_2048_A_LEN_WORDS (0x20)
|
||||
#define RSA_2048_B_LEN_WORDS (0x20)
|
||||
#define RSA_2048_D_LEN_WORDS (0x100)
|
||||
|
||||
#define RSA_3072_A_LEN_WORDS (0x30)
|
||||
#define RSA_3072_B_LEN_WORDS (0x30)
|
||||
#define RSA_3072_D_LEN_WORDS (0x180)
|
||||
|
||||
#define RSA_4096_A_LEN_WORDS (0x40)
|
||||
#define RSA_4096_B_LEN_WORDS (0x40)
|
||||
#define RSA_4096_D_LEN_WORDS (0x200)
|
||||
|
||||
/*----- RSA Control Codes: Mode Parameters: Key Bits -----*/
|
||||
typedef enum {
|
||||
RSA_KEY_BITS_192 = 0, ///< 192 Key bits
|
||||
RSA_KEY_BITS_256, ///< 256 Key bits
|
||||
RSA_KEY_BITS_512, ///< 512 Key bits
|
||||
RSA_KEY_BITS_1024, ///< 1024 Key bits
|
||||
RSA_KEY_BITS_2048, ///< 2048 Key bits
|
||||
RSA_KEY_BITS_3072, ///< 3072 Key bits
|
||||
RSA_KEY_BITS_4096 ///< 4096 Key bits
|
||||
RSA_KEY_BITS_192 = 0, /*192 Key bits*/
|
||||
RSA_KEY_BITS_256, /*256 Key bits*/
|
||||
RSA_KEY_BITS_512, /*512 Key bits*/
|
||||
RSA_KEY_BITS_1024, /*1024 Key bits*/
|
||||
RSA_KEY_BITS_2048, /*2048 Key bits*/
|
||||
RSA_KEY_BITS_3072, /*3072 Key bits*/
|
||||
RSA_KEY_BITS_4096 /*4096 Key bits*/
|
||||
} csi_rsa_key_bits_t;
|
||||
|
||||
typedef enum {
|
||||
RSA_PADDING_MODE_NO = 0, ///< RSA NO Padding Mode
|
||||
RSA_PADDING_MODE_PKCS1, ///< RSA PKCS1 Padding Mode
|
||||
RSA_PADDING_MODE_PKCS1_OAEP, ///< RSA PKCS1 OAEP Padding Mode
|
||||
RSA_PADDING_MODE_SSLV23, ///< RSA SSLV23 Padding Mode
|
||||
RSA_PADDING_MODE_X931, ///< RSA X931 Padding Mode
|
||||
RSA_PADDING_MODE_PSS ///< RSA PSS Padding Mode
|
||||
RSA_PADDING_MODE_NO = 0, /*RSA NO Padding Mode*/
|
||||
RSA_PADDING_MODE_PKCS1, /*RSA PKCS1 Padding Mode*/
|
||||
RSA_PADDING_MODE_PKCS1_OAEP, /*RSA PKCS1 OAEP Padding Mode*/
|
||||
RSA_PADDING_MODE_SSLV23, /*RSA SSLV23 Padding Mode*/
|
||||
RSA_PADDING_MODE_X931, /*RSA X931 Padding Mode*/
|
||||
RSA_PADDING_MODE_PSS /*RSA PSS Padding Mode*/
|
||||
} csi_rsa_padding_type_t;
|
||||
|
||||
typedef enum {
|
||||
@@ -69,6 +97,30 @@ typedef enum {
|
||||
RSA_HASH_TYPE_SHA512
|
||||
} csi_rsa_hash_type_t;
|
||||
|
||||
typedef enum {
|
||||
RSA_CRT_DISABLE = 0,
|
||||
RSA_CRT_ENABLE = 1,
|
||||
} csi_rsa_crt_t;
|
||||
|
||||
typedef enum {
|
||||
RSA_HASH_DISABLE = 0,
|
||||
RSA_HASH_ENABLE = 1,
|
||||
} csi_rsa_hash_t;
|
||||
|
||||
typedef struct {
|
||||
csi_rsa_key_bits_t type;
|
||||
uint32_t rsa_pka_dp_offset;
|
||||
uint32_t rsa_pka_dq_offset;
|
||||
uint32_t rsa_pka_p_offset;
|
||||
uint32_t rsa_pka_q_offset;
|
||||
uint32_t rsa_pka_qinv_offset;
|
||||
uint32_t rsa_pka_m_offset;
|
||||
uint32_t rsa_pka_r_offset;
|
||||
uint32_t rsa_pka_A_len;
|
||||
uint32_t rsa_pka_B_len;
|
||||
uint32_t rsa_pka_D_len;
|
||||
} csi_rsa_pka_offset_t;
|
||||
|
||||
typedef struct {
|
||||
csi_rsa_hash_type_t hash_type;
|
||||
uint32_t oid_len;
|
||||
@@ -76,19 +128,26 @@ typedef struct {
|
||||
}RSA_OID;
|
||||
|
||||
typedef struct {
|
||||
void *n; ///< Pointer to the public modulus
|
||||
void *e; ///< Pointer to the public exponent
|
||||
void *d; ///< Pointer to the private exponent
|
||||
csi_rsa_key_bits_t key_bits; ///< RSA KEY BITS
|
||||
csi_rsa_padding_type_t padding_type; ///< RSA PADDING TYPE
|
||||
void *n; /*Pointer to the public modulus*/
|
||||
void *e; /*Pointer to the public exponent*/
|
||||
void *d; /*Pointer to the private exponent*/
|
||||
void *p;
|
||||
void *q;
|
||||
void *dp;
|
||||
void *dq;
|
||||
void *qinv;
|
||||
csi_rsa_crt_t is_crt;
|
||||
csi_rsa_hash_t is_hash;
|
||||
csi_rsa_key_bits_t key_bits; /*RSA KEY BITS*/
|
||||
csi_rsa_padding_type_t padding_type; /*RSA PADDING TYPE*/
|
||||
} csi_rsa_context_t;
|
||||
|
||||
/**
|
||||
\brief RSA State
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t busy : 1; ///< Calculate busy flag
|
||||
uint8_t error : 1; ///< Calculate error flag
|
||||
uint8_t busy : 1; /*Calculate busy flag*/
|
||||
uint8_t error : 1; /*Calculate error flag*/
|
||||
} csi_rsa_state_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -113,13 +172,13 @@ typedef struct {
|
||||
|
||||
/****** RSA Event *****/
|
||||
typedef enum {
|
||||
RSA_EVENT_COMPLETE = 0, ///< rsa event completed
|
||||
RSA_EVENT_COMPLETE = 0, /*rsa event completed*/
|
||||
RSA_EVENT_VERIFY_SUCCESS,
|
||||
RSA_EVENT_VERIFY_FAILED,
|
||||
RSA_EVENT_ERROR, ///< error event
|
||||
RSA_EVENT_ERROR, /*error event*/
|
||||
} csi_rsa_event_t;
|
||||
|
||||
typedef void (*csi_rsa_callback_t)(csi_rsa_t *rsa, csi_rsa_event_t event, void *arg); ///< Pointer to \ref csi_rsa_callback_t : RSA Event call back.
|
||||
typedef void (*csi_rsa_callback_t)(csi_rsa_t *rsa, csi_rsa_event_t event, void *arg); /*Pointer to \ref csi_rsa_callback_t : RSA Event call back.*/
|
||||
|
||||
/**
|
||||
\brief Initialize RSA Interface. 1. Initializes the resources needed for the RSA interface 2.registers event callback function
|
||||
|
||||
@@ -35,17 +35,17 @@ extern "C" {
|
||||
\brief AES data transfer mode config
|
||||
*/
|
||||
typedef enum {
|
||||
SC_AES_SLAVE_MODE = 0U, ///< slave mode
|
||||
SC_AES_DMA_MODE, ///< dma mode
|
||||
SC_AES_SLAVE_MODE = 0U, /*slave mode*/
|
||||
SC_AES_DMA_MODE, /*dma mode*/
|
||||
} sc_aes_trans_mode_t;
|
||||
|
||||
/**
|
||||
\brief AES key-len-bits type
|
||||
*/
|
||||
typedef enum {
|
||||
SC_AES_KEY_LEN_BITS_128 = 0U, ///< 128 Data bits
|
||||
SC_AES_KEY_LEN_BITS_192, ///< 192 Data bits
|
||||
SC_AES_KEY_LEN_BITS_256 ///< 256 Data bits
|
||||
SC_AES_KEY_LEN_BITS_128 = 0U, /*128 Data bits*/
|
||||
SC_AES_KEY_LEN_BITS_192, /*192 Data bits*/
|
||||
SC_AES_KEY_LEN_BITS_256 /*256 Data bits*/
|
||||
} sc_aes_key_bits_t;
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,6 @@ typedef struct {
|
||||
#endif
|
||||
#ifdef CONFIG_CSI_V2
|
||||
csi_aes_t csi_aes;
|
||||
//unsigned char sc_ctx[SC_AES_CTX_SIZE];
|
||||
#endif
|
||||
#endif
|
||||
#if defined(CONFIG_TEE_CA)
|
||||
@@ -70,10 +69,9 @@ typedef struct {
|
||||
#if defined(CONFIG_SEC_CRYPTO_AES_SW)
|
||||
sc_mbedtls_aes_context aes_ctx;
|
||||
#endif
|
||||
//void *ctx;
|
||||
} sc_aes_t;
|
||||
|
||||
// Function documentation
|
||||
/*Function documentation*/
|
||||
/**
|
||||
\brief Initialize AES Interface. Initializes the resources needed for the AES interface
|
||||
\param[in] aes operate handle
|
||||
@@ -311,7 +309,7 @@ uint32_t sc_aes_ccm_decrypt(sc_aes_t *aes, void *in, void *out,uint32_t size, ui
|
||||
/**
|
||||
\brief Aes data transfer config
|
||||
*/
|
||||
void sc_aes_trans_config(sc_aes_t *aes, sc_aes_trans_mode_t mode) ;
|
||||
uint32_t sc_aes_trans_config(sc_aes_t *aes, sc_aes_trans_mode_t mode) ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
5
lib/sec_library/include/sec_crypto_common.h
Executable file → Normal file
5
lib/sec_library/include/sec_crypto_common.h
Executable file → Normal file
@@ -20,7 +20,10 @@
|
||||
#include "sec_crypto_sha.h"
|
||||
#include "sec_crypto_sm2.h"
|
||||
#include "sec_crypto_sm4.h"
|
||||
|
||||
#include "sec_crypto_des.h"
|
||||
#include "sec_crypto_dsa.h"
|
||||
#include "sec_crypto_ecc.h"
|
||||
#include "sec_crypto_ecdh.h"
|
||||
#define SC_lOG(...)
|
||||
|
||||
#endif
|
||||
|
||||
95
lib/sec_library/include/sec_crypto_curve25519.h
Normal file
95
lib/sec_library/include/sec_crypto_curve25519.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2022 Alibaba Group Holding Limited
|
||||
*/
|
||||
/******************************************************************************
|
||||
* @file sec_crypto_curve25519.h
|
||||
* @brief Header File for curve25519( a state-of-the-art Diffie-Hellman function)
|
||||
* @version V3.3
|
||||
* @date 10. June 2022
|
||||
* @model ecdh
|
||||
******************************************************************************/
|
||||
#ifndef _SC_CURVE25519_H_
|
||||
#define _SC_CURVE25519_H_
|
||||
#include "sec_include_config.h"
|
||||
|
||||
#define CONFIG_SEC_CRYPTO_CURVE25519
|
||||
|
||||
#ifdef CONFIG_SEC_CRYPTO_CURVE25519
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef SEC_LIB_VERSION
|
||||
#include "drv/curve25519.h"
|
||||
#include "sec_crypto_curve25519.h"
|
||||
#else
|
||||
#include "curve25519.h"
|
||||
#include "sec_crypto_curve25519.h"
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
#ifdef CONFIG_CSI_V2
|
||||
csi_curve25519_t ctx;
|
||||
#endif
|
||||
} sc_curve25519_t;
|
||||
|
||||
/**
|
||||
\brief Initialize CURVE25519.
|
||||
\param[in] idx device id
|
||||
\return Error code \ref csi_error_t
|
||||
*/
|
||||
csi_error_t sc_curve25519_init(void *ctx, uint32_t idx);
|
||||
|
||||
/**
|
||||
\brief De-initialize CURVE25519 Interface. stops operation and releases the software resources used by the interface
|
||||
\param[in] curve25519 ecc handle to operate.
|
||||
\return none
|
||||
*/
|
||||
void sc_curve25519_uninit(void *ctx);
|
||||
|
||||
/**
|
||||
\brief curve25519 gen public key
|
||||
\param[in] ctx ctx handle to operate.
|
||||
\param[in] privkey Pointer to the A(or B) private key.
|
||||
\param[out] pubkey Pointer to the A(or B) public key.
|
||||
\return \ref uint32_t.
|
||||
*/
|
||||
uint32_t sc_curve25519_gen_pubkey(void *ctx, const uint8_t privkey[32], uint8_t pubkey[32]);
|
||||
|
||||
/**
|
||||
\brief curve25519 gen key pair
|
||||
\param[in] ctx ctx handle to operate.
|
||||
\param[out] privkey Pointer to the A(or B) private key.
|
||||
\param[out] pubkey Pointer to the A(or B) public key.
|
||||
\return \ref uint32_t.
|
||||
*/
|
||||
uint32_t sc_curve25519_gen_keypair(void *ctx, uint8_t privkey[32], uint8_t pubkey[32]);
|
||||
|
||||
/**
|
||||
\brief curve25519 check key pair
|
||||
\param[in] ctx ctx handle to operate.
|
||||
\param[in] privkey Pointer to the A(or B) private key.
|
||||
\param[in] pubkey Pointer to the A(or B) public key.
|
||||
\return \ref uint32_t.
|
||||
*/
|
||||
uint32_t sc_curve25519_check_keypair(void *ctx, const uint8_t privkey[32], const uint8_t pubkey[32]);
|
||||
|
||||
/**
|
||||
\brief curve25519 check key pair
|
||||
\param[in] ctx ctx handle to operate.
|
||||
\param[in] privkey Pointer to the B(or A) private key.
|
||||
\param[in] pubkey Pointer to the A(or B) public key.
|
||||
\param[out] sk Pointer to the share key.
|
||||
\param[out] sk_len Pointer to the share key length byte.
|
||||
\return \ref uint32_t.
|
||||
*/
|
||||
uint32_t sc_curve25519_calc_secret(void *ctx, const uint8_t privkey[32], const uint8_t pubkey[32], uint8_t sk[32], uint32_t *sk_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _SC_CURVE15519_H_ */
|
||||
@@ -35,17 +35,17 @@ extern "C" {
|
||||
\brief DES data transfer mode config
|
||||
*/
|
||||
typedef enum {
|
||||
SC_DES_SLAVE_MODE = 0U, ///< slave mode
|
||||
SC_DES_DMA_MODE, ///< dma mode
|
||||
SC_DES_SLAVE_MODE = 0U, /*slave mode*/
|
||||
SC_DES_DMA_MODE, /*dma mode*/
|
||||
} sc_des_trans_mode_t;
|
||||
|
||||
/**
|
||||
\brief DES key-len-bits type
|
||||
*/
|
||||
typedef enum {
|
||||
SC_DES_KEY_LEN_BITS_64 = 0U, ///< 64 Data bits
|
||||
SC_DES_KEY_LEN_BITS_128, ///< 128 Data bits
|
||||
SC_TDES_KEY_LEN_BITS_192, ///< 192 Data bits
|
||||
SC_DES_KEY_LEN_BITS_64 = 0U, /*64 Data bits*/
|
||||
SC_TDES_KEY_LEN_BITS_128, /*128 Data bits*/
|
||||
SC_TDES_KEY_LEN_BITS_192, /*192 Data bits*/
|
||||
} sc_des_key_bits_t;
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,6 @@ typedef struct {
|
||||
#endif
|
||||
#ifdef CONFIG_CSI_V2
|
||||
csi_des_t csi_des;
|
||||
//unsigned char sc_ctx[SC_DES_CTX_SIZE];
|
||||
#endif
|
||||
#endif
|
||||
#if defined(CONFIG_TEE_CA)
|
||||
@@ -70,7 +69,6 @@ typedef struct {
|
||||
#if defined(CONFIG_SEC_CRYPTO_DES_SW)
|
||||
sc_mbedtls_des_context des_ctx;
|
||||
#endif
|
||||
//void *ctx;
|
||||
} sc_des_t;
|
||||
|
||||
// Function documentation
|
||||
@@ -196,7 +194,7 @@ uint32_t sc_tdes_cbc_decrypt(sc_des_t *des, void *in, void *out, uint32_t size,
|
||||
\param[in] mode \ref sc_des_trans_mode_t
|
||||
\return None
|
||||
*/
|
||||
void sc_des_trans_config(sc_des_t *des, sc_des_trans_mode_t mode) ;
|
||||
uint32_t sc_des_trans_config(sc_des_t *des, sc_des_trans_mode_t mode) ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
109
lib/sec_library/include/sec_crypto_dsa.h
Normal file
109
lib/sec_library/include/sec_crypto_dsa.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (C) 2017-2022 Alibaba Group Holding Limited
|
||||
*/
|
||||
/******************************************************************************
|
||||
* @file sec_crypt_dsa.h
|
||||
* @brief Header File for DSA
|
||||
* @version V3.3
|
||||
* @date 05. Dec 2022
|
||||
* @model dsa
|
||||
******************************************************************************/
|
||||
#ifndef _SC_DSA_H_
|
||||
#define _SC_DSA_H_
|
||||
#include "sec_include_config.h"
|
||||
|
||||
#define CONFIG_SEC_CRYPTO_DSA
|
||||
|
||||
#ifdef CONFIG_SEC_CRYPTO_DSA
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef SEC_LIB_VERSION
|
||||
#include "drv/dsa.h"
|
||||
#else
|
||||
#include "dsa.h"
|
||||
#endif
|
||||
|
||||
typedef enum{
|
||||
SC_DSA_SHA1 = 0,
|
||||
SC_DSA_SHA224,
|
||||
SC_DSA_SHA256,
|
||||
SC_DSA_SHA_MAX,
|
||||
}sc_dsa_sha_type;
|
||||
|
||||
/**
|
||||
\brief DSA status
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t busy : 1; /*Calculate busy flag*/
|
||||
} sc_dsa_state_t;
|
||||
|
||||
typedef struct {
|
||||
#ifdef CONFIG_CSI_V2
|
||||
csi_dsa_t dsa;
|
||||
#endif
|
||||
} sc_dsa_t;
|
||||
|
||||
/**
|
||||
\brief Initialize DSA.
|
||||
\param[in] dsa dsa handle to operate.
|
||||
\param[in] idx device id
|
||||
\return \ref uint32_t
|
||||
*/
|
||||
uint32_t sc_dsa_init(sc_dsa_t *dsa, uint32_t idx);
|
||||
|
||||
/**
|
||||
\brief De-initialize ECC Interface. stops operation and releases the
|
||||
software resources used by the interface \param[in] dsa dsa handle to
|
||||
operate. \return none
|
||||
*/
|
||||
void sc_dsa_uninit(sc_dsa_t *dsa);
|
||||
|
||||
/**
|
||||
\brief Initialize DSA.
|
||||
\param[in] dsa dsa handle to operate.
|
||||
\param[in] idx device id
|
||||
\return \ref uint32_t
|
||||
*/
|
||||
uint32_t sc_dsa_config(sc_dsa_t *dsa, sc_dsa_sha_type type);
|
||||
|
||||
/**
|
||||
\brief dsa gen key pairs
|
||||
\param[in] dsa dsa handle to operate.
|
||||
\param[out] privkey Pointer to the private key
|
||||
\param[out] pubkey Pointer to the public key
|
||||
\return Error code \ref csi_error_t
|
||||
*/
|
||||
uint32_t sc_dsa_gen_keypairs(sc_dsa_t *dsa, uint8_t *prikey, uint8_t *pubkey);
|
||||
|
||||
/**
|
||||
\brief dsa sign
|
||||
\param[in] dsa dsa handle to operate.
|
||||
\param[in] d Pointer to the digest.
|
||||
\param[out] privkey Pointer to the private key
|
||||
\param[out] s Pointer to the signature
|
||||
\return \ref uint32_t
|
||||
*/
|
||||
uint32_t sc_dsa_sign(sc_dsa_t *dsa, uint8_t *d, uint8_t *prikey, uint8_t *s);
|
||||
|
||||
/**
|
||||
\brief dsa verify
|
||||
\param[in] dsa dsa handle to operate.
|
||||
\param[in] d Pointer to the digest.
|
||||
\param[out] privkey Pointer to the private key
|
||||
\param[out] s Pointer to the signature
|
||||
\return verify result
|
||||
*/
|
||||
bool sc_dsa_verify(sc_dsa_t *dsa, uint8_t *d, uint8_t *pubkey, uint8_t *s);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _SC_ECC_H_ */
|
||||
|
||||
24
lib/sec_library/include/sec_crypto_ecc.h
Executable file → Normal file
24
lib/sec_library/include/sec_crypto_ecc.h
Executable file → Normal file
@@ -39,8 +39,8 @@ typedef enum {
|
||||
} sc_ecc_cipher_order_e;
|
||||
|
||||
typedef enum {
|
||||
SC_ECC_ENDIAN_LITTLE = 0, ///< Little Endian
|
||||
SC_ECC_ENDIAN_BIG ///< Big Endian
|
||||
SC_ECC_ENDIAN_LITTLE = 0, /*Little Endian*/
|
||||
SC_ECC_ENDIAN_BIG /*Big Endian*/
|
||||
} sc_ecc_endian_mode_e;
|
||||
|
||||
/**
|
||||
@@ -50,23 +50,23 @@ typedef enum { SC_ECC_Role_Sponsor = 0, SC_ECC_Role_Responsor } sc_ecc_exchange_
|
||||
|
||||
/****** ECC Event *****/
|
||||
typedef enum {
|
||||
SC_ECC_EVENT_MAKE_KEY_COMPLETE = 0, ///< Make key completed
|
||||
SC_ECC_EVENT_ENCRYPT_COMPLETE, ///< Encrypt completed
|
||||
SC_ECC_EVENT_DECRYPT_COMPLETE, ///< Decrypt completed
|
||||
SC_ECC_EVENT_SIGN_COMPLETE, ///< Sign completed
|
||||
SC_ECC_EVENT_VERIFY_COMPLETE, ///< Verify completed
|
||||
SC_ECC_EVENT_EXCHANGE_KEY_COMPLETE, ///< Exchange key completed
|
||||
SC_ECC_EVENT_MAKE_KEY_COMPLETE = 0, /*Make key completed*/
|
||||
SC_ECC_EVENT_ENCRYPT_COMPLETE, /*Encrypt completed*/
|
||||
SC_ECC_EVENT_DECRYPT_COMPLETE, /*Decrypt completed*/
|
||||
SC_ECC_EVENT_SIGN_COMPLETE, /*Sign completed*/
|
||||
SC_ECC_EVENT_VERIFY_COMPLETE, /*Verify completed*/
|
||||
SC_ECC_EVENT_EXCHANGE_KEY_COMPLETE, /*Exchange key completed*/
|
||||
} sc_ecc_event_e;
|
||||
|
||||
typedef struct {
|
||||
uint32_t ecc_curve : 1; ///< supports 256bits curve
|
||||
uint32_t ecc_curve : 1; /*supports 256bits curve*/
|
||||
} sc_ecc_capabilities_t;
|
||||
|
||||
/**
|
||||
\brief ECC status
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t busy : 1; ///< Calculate busy flag
|
||||
uint32_t busy : 1; /*Calculate busy flag*/
|
||||
} sc_ecc_state_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -75,7 +75,7 @@ typedef struct {
|
||||
#endif
|
||||
} sc_ecc_t;
|
||||
|
||||
///< Pointer to \ref sc_ecc_callback_t : ECC Event call back.
|
||||
/*Pointer to \ref sc_ecc_callback_t : ECC Event call back.*/
|
||||
typedef void (*sc_ecc_callback_t)(sc_ecc_event_e event);
|
||||
|
||||
/**
|
||||
@@ -256,7 +256,7 @@ uint32_t sc_ecc_getE(sc_ecc_t *ecc, uint8_t *m, uint32_t len, uint8_t z[32],
|
||||
uint32_t sc_ecc_get_state(sc_ecc_t *ecc, sc_ecc_state_t *state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
2
lib/sec_library/include/sec_crypto_ecdh.h
Executable file → Normal file
2
lib/sec_library/include/sec_crypto_ecdh.h
Executable file → Normal file
@@ -45,7 +45,7 @@ uint32_t sc_ecdh_calc_secret(sc_ecc_t *ecc, uint8_t privkey[32],
|
||||
uint32_t *len, sc_ecc_curve_type type) ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
0
lib/sec_library/include/sec_crypto_kdf.h
Executable file → Normal file
0
lib/sec_library/include/sec_crypto_kdf.h
Executable file → Normal file
0
lib/sec_library/include/sec_crypto_mac.h
Executable file → Normal file
0
lib/sec_library/include/sec_crypto_mac.h
Executable file → Normal file
@@ -23,16 +23,10 @@ extern "C" {
|
||||
/**
|
||||
\brief Get data from the TRNG engine
|
||||
\param[out] data Pointer to buffer with data get from TRNG
|
||||
\param[in] num Number of data items in bytes
|
||||
\param[in] size Size of data items in bytes
|
||||
\return error code
|
||||
*/
|
||||
uint32_t sc_rng_get_multi_byte(uint8_t *data, uint32_t num);
|
||||
|
||||
/**
|
||||
\brief Get data from the TRNG engine
|
||||
\return error code
|
||||
*/
|
||||
uint32_t sc_rng_get_single_word(uint32_t *data);
|
||||
uint32_t sc_rng_get_random_bytes(uint8_t *data, uint32_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -40,26 +40,26 @@ extern "C" {
|
||||
#include "sec_crypto_errcode.h"
|
||||
|
||||
|
||||
//TODO Del this file after updating to sc2.0
|
||||
/*TODO Del this file after updating to sc2.0*/
|
||||
|
||||
/*----- RSA Control Codes: Mode Parameters: Key Bits -----*/
|
||||
typedef enum {
|
||||
SC_RSA_KEY_BITS_192 = 0, ///< 192 Key bits
|
||||
SC_RSA_KEY_BITS_256, ///< 256 Key bits
|
||||
SC_RSA_KEY_BITS_512, ///< 512 Key bits
|
||||
SC_RSA_KEY_BITS_1024, ///< 1024 Key bits
|
||||
SC_RSA_KEY_BITS_2048, ///< 2048 Key bits
|
||||
SC_RSA_KEY_BITS_3072, ///< 3072 Key bits
|
||||
SC_RSA_KEY_BITS_4096 ///< 4096 Key bits
|
||||
SC_RSA_KEY_BITS_192 = 0, /*192 Key bits*/
|
||||
SC_RSA_KEY_BITS_256, /*256 Key bits*/
|
||||
SC_RSA_KEY_BITS_512, /*512 Key bits*/
|
||||
SC_RSA_KEY_BITS_1024, /*1024 Key bits*/
|
||||
SC_RSA_KEY_BITS_2048, /*2048 Key bits*/
|
||||
SC_RSA_KEY_BITS_3072, /*3072 Key bits*/
|
||||
SC_RSA_KEY_BITS_4096 /*4096 Key bits*/
|
||||
} sc_rsa_key_bits_t;
|
||||
|
||||
typedef enum {
|
||||
SC_RSA_PADDING_MODE_NO = 0, ///< RSA NO Padding Mode
|
||||
SC_RSA_PADDING_MODE_PKCS1, ///< RSA PKCS1 Padding Mode
|
||||
SC_RSA_PADDING_MODE_PKCS1_OAEP, ///< RSA PKCS1 OAEP Padding Mode
|
||||
SC_RSA_PADDING_MODE_SSLV23, ///< RSA SSLV23 Padding Mode
|
||||
SC_RSA_PADDING_MODE_X931, ///< RSA X931 Padding Mode
|
||||
SC_RSA_PADDING_MODE_PSS ///< RSA PSS Padding Mode
|
||||
SC_RSA_PADDING_MODE_NO = 0, /*RSA NO Padding Mode*/
|
||||
SC_RSA_PADDING_MODE_PKCS1, /*RSA PKCS1 Padding Mode*/
|
||||
SC_RSA_PADDING_MODE_PKCS1_OAEP, /*RSA PKCS1 OAEP Padding Mode*/
|
||||
SC_RSA_PADDING_MODE_SSLV23, /*RSA SSLV23 Padding Mode*/
|
||||
SC_RSA_PADDING_MODE_X931, /*RSA X931 Padding Mode*/
|
||||
SC_RSA_PADDING_MODE_PSS /*RSA PSS Padding Mode*/
|
||||
} sc_rsa_padding_type_t;
|
||||
|
||||
typedef enum {
|
||||
@@ -71,25 +71,40 @@ typedef enum {
|
||||
SC_RSA_HASH_TYPE_SHA512
|
||||
} sc_rsa_hash_type_t;
|
||||
|
||||
typedef enum {
|
||||
SC_RSA_CRT_DISABLE = 0,
|
||||
SC_RSA_CRT_ENABLE,
|
||||
} sc_rsa_crt_t;
|
||||
|
||||
typedef enum {
|
||||
SC_RSA_HASH_DISABLE = 0,
|
||||
SC_RSA_HASH_ENABLE,
|
||||
} sc_rsa_hash_t;
|
||||
|
||||
|
||||
/* the private key is the quintuplet(p, q, qinv, dp, dq) with CRT */
|
||||
typedef struct {
|
||||
// #if (defined(CONFIG_SYSTEM_SECURE) && defined(CONFIG_CSI_V2))
|
||||
// csi_rsa_context_t rsa_ctx;
|
||||
// #else
|
||||
void * n; ///< Pointer to the public modulus
|
||||
void * e; ///< Pointer to the public exponent
|
||||
void * d; ///< Pointer to the private exponent
|
||||
sc_rsa_key_bits_t key_bits; ///< RSA KEY BITS
|
||||
sc_rsa_padding_type_t padding_type; ///< RSA PADDING TYPE
|
||||
sc_rsa_hash_type_t hash_type;
|
||||
// #endif
|
||||
void * n; /*Pointer to the public modulus*/
|
||||
void * e; /*Pointer to the public exponent*/
|
||||
void * d; /*Pointer to the private exponent*/
|
||||
void * p; /*Pointer to the private key param p with CRT*/
|
||||
void * q; /*Pointer to the private key param q with CRT*/
|
||||
void * dp; /*Pointer to the private key param dp with CRT*/
|
||||
void * dq; /*Pointer to the private key param dq with CRT*/
|
||||
void * qinv; /*Pointer to the private key param qinv with CRT*/
|
||||
sc_rsa_crt_t is_crt; /*Enable RSA with CRT*/
|
||||
sc_rsa_hash_t is_hash; /*Enable RSA with HASH*/
|
||||
sc_rsa_key_bits_t key_bits; /*RSA KEY BITS*/
|
||||
sc_rsa_padding_type_t padding_type; /*RSA PADDING TYPE*/
|
||||
sc_rsa_hash_type_t hash_type;
|
||||
} sc_rsa_context_t;
|
||||
|
||||
/**
|
||||
\brief RSA State
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t busy : 1; ///< Calculate busy flag
|
||||
uint8_t error : 1; ///< Calculate error flag
|
||||
uint8_t busy : 1; /*Calculate busy flag*/
|
||||
uint8_t error : 1; /*Calculate error flag*/
|
||||
} sc_rsa_state_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -109,17 +124,17 @@ typedef struct {
|
||||
|
||||
/****** RSA Event *****/
|
||||
typedef enum {
|
||||
SC_RSA_EVENT_COMPLETE = 0, ///< rsa event completed
|
||||
SC_RSA_EVENT_COMPLETE = 0, /*rsa event completed*/
|
||||
SC_RSA_EVENT_VERIFY_SUCCESS,
|
||||
SC_RSA_EVENT_VERIFY_FAILED,
|
||||
SC_RSA_EVENT_ERROR, ///< error event
|
||||
SC_RSA_EVENT_ERROR, /*error event*/
|
||||
} sc_rsa_event_t;
|
||||
|
||||
typedef void (*sc_rsa_callback_t)(
|
||||
sc_rsa_t *rsa, sc_rsa_event_t event,
|
||||
void *arg); ///< Pointer to \ref sc_rsa_callback_t : RSA Event call back.
|
||||
void *arg); /*Pointer to \ref sc_rsa_callback_t : RSA Event call back.*/
|
||||
|
||||
// Function documentation
|
||||
/*Function documentation*/
|
||||
|
||||
/**
|
||||
\brief Initialize RSA Interface. 1. Initializes the resources needed for the RSA interface 2.registers event callback function
|
||||
|
||||
@@ -41,16 +41,24 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
\brief SHA data transfer mode config
|
||||
*/
|
||||
typedef enum {
|
||||
SC_SHA_SLAVE_MODE = 0U, /*slave mode*/
|
||||
SC_SHA_DMA_MODE, /*dma mode*/
|
||||
} sc_sha_trans_mode_t;
|
||||
|
||||
/*----- SHA Control Codes: Mode -----*/
|
||||
typedef enum {
|
||||
SC_SHA_MODE_SHA1 = 1U, ///< SHA_1 mode
|
||||
SC_SHA_MODE_256, ///< SHA_256 mode
|
||||
SC_SHA_MODE_224, ///< SHA_224 mode
|
||||
SC_SHA_MODE_512, ///< SHA_512 mode
|
||||
SC_SHA_MODE_384, ///< SHA_384 mode
|
||||
SC_SHA_MODE_512_256, ///< SHA_512_256 mode
|
||||
SC_SHA_MODE_512_224, ///< SHA_512_224 mode
|
||||
SC_SHA_MODE_MD5, ///< MD5 mode
|
||||
SC_SHA_MODE_SHA1 = 1U, /*SHA_1 mode*/
|
||||
SC_SHA_MODE_256, /*SHA_256 mode*/
|
||||
SC_SHA_MODE_224, /*SHA_224 mode*/
|
||||
SC_SHA_MODE_512, /*SHA_512 mode*/
|
||||
SC_SHA_MODE_384, /*SHA_384 mode*/
|
||||
SC_SHA_MODE_512_256, /*SHA_512_256 mode*/
|
||||
SC_SHA_MODE_512_224, /*SHA_512_224 mode*/
|
||||
SC_SHA_MODE_MD5, /*MD5 mode*/
|
||||
SC_SM3_MODE,
|
||||
} sc_sha_mode_t;
|
||||
|
||||
@@ -58,8 +66,8 @@ typedef enum {
|
||||
\brief SHA State
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t busy : 1; ///< calculate busy flag
|
||||
uint32_t error : 1; ///< calculate error flag
|
||||
uint32_t busy : 1; /*calculate busy flag*/
|
||||
uint32_t error : 1; /*calculate error flag*/
|
||||
} sc_sha_state_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -81,13 +89,13 @@ uint8_t ctx[SHA_CONTEXT_SIZE];
|
||||
sc_mbedtls_sha1_context sha1_ctx;
|
||||
sc_mbedtls_sha256_context sha2_ctx;
|
||||
#endif
|
||||
sc_sha_mode_t mode; ///< sha mode
|
||||
sc_sha_mode_t mode; /*sha mode*/
|
||||
} sc_sha_context_t;
|
||||
|
||||
/****** SHA Event *****/
|
||||
typedef enum {
|
||||
SC_SHA_EVENT_COMPLETE = 0U, ///< calculate completed
|
||||
SC_SHA_EVENT_ERROR ///< calculate error
|
||||
SC_SHA_EVENT_COMPLETE = 0U, /*calculate completed*/
|
||||
SC_SHA_EVENT_ERROR /*calculate error*/
|
||||
} sc_sha_event_t;
|
||||
|
||||
typedef struct sc_sha {
|
||||
@@ -95,7 +103,7 @@ typedef struct sc_sha {
|
||||
#ifdef CONFIG_CSI_V1
|
||||
sha_handle_t handle;
|
||||
sc_sha_context_t ctx;
|
||||
sc_sha_mode_t mode; ///< sha mode
|
||||
sc_sha_mode_t mode; /*sha mode*/
|
||||
#endif /* CONFIG_CSI_V1 */
|
||||
#ifdef CONFIG_CSI_V2
|
||||
csi_sha_t csi_sha;
|
||||
@@ -199,6 +207,12 @@ uint32_t sc_sha_digest(sc_sha_t *sha, uint32_t idx, sc_sha_context_t *context, s
|
||||
\return error code \ref uint32_t
|
||||
*/
|
||||
uint32_t sc_sha_get_state(sc_sha_t *sha,sc_sha_context_t *context);
|
||||
|
||||
/**
|
||||
\brief Sha data transfer config
|
||||
*/
|
||||
uint32_t sc_sha_trans_config(sc_sha_t *sha, sc_sha_context_t *context, sc_sha_trans_mode_t mode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -26,7 +26,7 @@ extern "C" {
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32_t sm2_curve : 1; ///< supports 256bits curve
|
||||
uint32_t sm2_curve : 1; /*supports 256bits curve*/
|
||||
} sc_sm2_capabilities_t;
|
||||
|
||||
/**
|
||||
@@ -38,15 +38,15 @@ typedef enum {
|
||||
} sc_sm2_cipher_order_e;
|
||||
|
||||
typedef enum {
|
||||
SC_SM2_ENDIAN_LITTLE = 0, ///< Little Endian
|
||||
SC_SM2_ENDIAN_BIG ///< Big Endian
|
||||
SC_SM2_ENDIAN_LITTLE = 0, /*Little Endian*/
|
||||
SC_SM2_ENDIAN_BIG /*Big Endian*/
|
||||
} sc_sm2_endian_mode_e;
|
||||
|
||||
/**
|
||||
\brief SM2 status
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t busy : 1; ///< Calculate busy flag
|
||||
uint32_t busy : 1; /*Calculate busy flag*/
|
||||
} sc_sm2_state_t;
|
||||
|
||||
/**
|
||||
@@ -56,12 +56,12 @@ typedef enum { SC_SM2_Role_Sponsor = 0, SC_SM2_Role_Responsor } sc_sm2_exchange_
|
||||
|
||||
/****** SM2 Event *****/
|
||||
typedef enum {
|
||||
SC_SM2_EVENT_MAKE_KEY_COMPLETE = 0, ///< Make key completed
|
||||
SC_SM2_EVENT_ENCRYPT_COMPLETE, ///< Encrypt completed
|
||||
SC_SM2_EVENT_DECRYPT_COMPLETE, ///< Decrypt completed
|
||||
SC_SM2_EVENT_SIGN_COMPLETE, ///< Sign completed
|
||||
SC_SM2_EVENT_VERIFY_COMPLETE, ///< Verify completed
|
||||
SC_SM2_EVENT_EXCHANGE_KEY_COMPLETE, ///< Exchange key completed
|
||||
SC_SM2_EVENT_MAKE_KEY_COMPLETE = 0, /*Make key completed*/
|
||||
SC_SM2_EVENT_ENCRYPT_COMPLETE, /*Encrypt completed*/
|
||||
SC_SM2_EVENT_DECRYPT_COMPLETE, /*Decrypt completed*/
|
||||
SC_SM2_EVENT_SIGN_COMPLETE, /*Sign completed*/
|
||||
SC_SM2_EVENT_VERIFY_COMPLETE, /*Verify completed*/
|
||||
SC_SM2_EVENT_EXCHANGE_KEY_COMPLETE, /*Exchange key completed*/
|
||||
} sc_sm2_event_e;
|
||||
|
||||
typedef struct {
|
||||
@@ -70,7 +70,7 @@ typedef struct {
|
||||
#endif
|
||||
} sc_sm2_t;
|
||||
|
||||
///< Pointer to \ref sc_sm2_callback_t : SM2 Event call back.
|
||||
/*Pointer to \ref sc_sm2_callback_t : SM2 Event call back.*/
|
||||
typedef void (*sc_sm2_callback_t)(sc_sm2_event_e event);
|
||||
|
||||
/**
|
||||
@@ -239,7 +239,7 @@ uint32_t sc_sm2_getE(sc_sm2_t *sm2, uint8_t *m, uint32_t len, uint8_t z[32], uin
|
||||
uint32_t sc_sm2_get_state(sc_sm2_t *sm2, sc_sm2_state_t *state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,14 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
\brief SM4 data transfer mode config
|
||||
*/
|
||||
typedef enum {
|
||||
SC_SM4_SLAVE_MODE = 0U, /*slave mode*/
|
||||
SC_SM4_DMA_MODE, /*dma mode*/
|
||||
} sc_sm4_trans_mode_t;
|
||||
|
||||
/**
|
||||
\brief SM4 Ctrl Block
|
||||
*/
|
||||
@@ -49,6 +57,11 @@ uint32_t sc_sm4_init(sc_sm4_t *sm4, uint32_t idx);
|
||||
*/
|
||||
void sc_sm4_uninit(sc_sm4_t *sm4);
|
||||
|
||||
/**
|
||||
\brief Sm4 data transfer config
|
||||
*/
|
||||
uint32_t sc_sm4_trans_config(sc_sm4_t *sm4, sc_sm4_trans_mode_t mode);
|
||||
|
||||
/**
|
||||
\brief Set encrypt key
|
||||
\param[in] sm4 handle to operate
|
||||
@@ -234,7 +247,7 @@ uint32_t sc_sm4_ctr_decrypt(sc_sm4_t *sm4, uint8_t *in, uint8_t *out,
|
||||
uint32_t size, uint8_t nonce_counter[16]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SC_SM4_H_ */
|
||||
|
||||
0
lib/sec_library/include/sec_include_config.h
Executable file → Normal file
0
lib/sec_library/include/sec_include_config.h
Executable file → Normal file
@@ -23,6 +23,10 @@
|
||||
#include "sec_crypto_kdf.h"
|
||||
#include "csi_efuse_api.h"
|
||||
#include "csi_efuse_api.h"
|
||||
#include "sec_crypto_des.h"
|
||||
#include "sec_crypto_dsa.h"
|
||||
#include "sec_crypto_ecc.h"
|
||||
#include "sec_crypto_ecdh.h"
|
||||
#include "csi_sec_img_verify.h"
|
||||
/* NOTE add more header */
|
||||
|
||||
|
||||
58
lib/sec_library/include/sha.h
Executable file → Normal file
58
lib/sec_library/include/sha.h
Executable file → Normal file
@@ -42,49 +42,58 @@ extern "C" {
|
||||
#define CSI_MD5_NEW_MODE (0x00000003)
|
||||
#define CSI_SHA1_NEW_MODE (0x00000005)
|
||||
|
||||
/**
|
||||
\brief SHA data transfer mode config
|
||||
*/
|
||||
typedef enum {
|
||||
SHA_SLAVE_MODE = 0U, /*slave mode*/
|
||||
SHA_DMA_MODE, /*dma mode*/
|
||||
} csi_sha_trans_mode_t;
|
||||
|
||||
/****** SHA mode ******/
|
||||
typedef enum {
|
||||
SHA_MODE_SHA1 = 1U, ///< SHA_1 mode
|
||||
SHA_MODE_256, ///< SHA_256 mode
|
||||
SHA_MODE_224, ///< SHA_224 mode
|
||||
SHA_MODE_512, ///< SHA_512 mode
|
||||
SHA_MODE_384, ///< SHA_384 mode
|
||||
SHA_MODE_512_256, ///< SHA_512_256 mode
|
||||
SHA_MODE_512_224, ///< SHA_512_224 mode
|
||||
SHA_MODE_MD5 ///< MD5 mode
|
||||
SHA_MODE_SHA1 = 1U, /*SHA_1 mode*/
|
||||
SHA_MODE_256, /*SHA_256 mode*/
|
||||
SHA_MODE_224, /*SHA_224 mode*/
|
||||
SHA_MODE_512, /*SHA_512 mode*/
|
||||
SHA_MODE_384, /*SHA_384 mode*/
|
||||
SHA_MODE_512_256, /*SHA_512_256 mode*/
|
||||
SHA_MODE_512_224, /*SHA_512_224 mode*/
|
||||
SHA_MODE_MD5 /*MD5 mode*/
|
||||
} csi_sha_mode_t;
|
||||
|
||||
/****** SHA State ******/
|
||||
typedef struct {
|
||||
uint32_t busy : 1; ///< Calculate busy flag
|
||||
uint32_t error : 1; ///< Calculate error flag
|
||||
uint32_t busy : 1; /*Calculate busy flag*/
|
||||
uint32_t error : 1; /*Calculate error flag*/
|
||||
} csi_sha_state_t;
|
||||
|
||||
typedef struct {
|
||||
csi_sha_mode_t mode; ///< SHA mode
|
||||
uint32_t total[2]; ///< Number of bytes processed
|
||||
uint32_t state[16]; ///< Intermediate digest state
|
||||
uint8_t buffer[128]; ///< Data block being processed
|
||||
uint8_t result[64]; ///< Data block has processed
|
||||
csi_sha_mode_t mode; /*SHA mode*/
|
||||
uint32_t total[2]; /*Number of bytes processed*/
|
||||
uint32_t state[16]; /*Intermediate digest state*/
|
||||
uint8_t buffer[128]; /*Data block being processed*/
|
||||
uint8_t result[64]; /*Data block has processed*/
|
||||
uint32_t process_len;
|
||||
uint32_t digest_len;
|
||||
uint32_t is_dma;
|
||||
} csi_sha_context_t;
|
||||
|
||||
/****** SHA Event ******/
|
||||
typedef enum {
|
||||
SHA_EVENT_COMPLETE = 0U, ///< Calculate completed
|
||||
SHA_EVENT_COMPLETE = 0U, /*Calculate completed*/
|
||||
SHA_EVENT_UPDATE,
|
||||
SHA_EVENT_START,
|
||||
SHA_EVENT_ERROR ///< Calculate error
|
||||
SHA_EVENT_ERROR /*Calculate error*/
|
||||
} csi_sha_event_t;
|
||||
|
||||
typedef struct csi_sha csi_sha_t;
|
||||
|
||||
struct csi_sha {
|
||||
csi_dev_t dev; ///< SHA hw-device info
|
||||
void (*callback)(csi_sha_t *sha, csi_sha_event_t event, void *arg); ///< SHA event callback for user
|
||||
void *arg; ///< SHA custom designed param passed to evt_cb
|
||||
csi_sha_state_t state; ///< SHA state
|
||||
csi_dev_t dev; /*SHA hw-device info*/
|
||||
void (*callback)(csi_sha_t *sha, csi_sha_event_t event, void *arg); /*SHA event callback for user*/
|
||||
void *arg; /*SHA custom designed param passed to evt_cb*/
|
||||
csi_sha_state_t state; /*SHA state*/
|
||||
void *priv;
|
||||
};
|
||||
|
||||
@@ -180,6 +189,13 @@ csi_error_t csi_sha_enable_pm(csi_sha_t *sha);
|
||||
*/
|
||||
void csi_sha_disable_pm(csi_sha_t *sha);
|
||||
|
||||
/**
|
||||
\brief Config SHA data transfer mode
|
||||
\param[in] mode \ref csi_des_trans_mode_t
|
||||
\return None
|
||||
*/
|
||||
csi_error_t csi_sha_trans_config(csi_sha_t *sha, csi_sha_context_t *context, csi_sha_trans_mode_t mode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
26
lib/sec_library/include/sm2.h
Executable file → Normal file
26
lib/sec_library/include/sm2.h
Executable file → Normal file
@@ -23,7 +23,7 @@ extern "C" {
|
||||
#define CSI_SM2_PUBKEY_LEN (65-1)
|
||||
#define CSI_SM2_PRIVKEY_LEN (32)
|
||||
#define CSI_SM2_PUBKEYTMP_LEN (65)
|
||||
#define CSI_SM2_RK_LEN (32) //random
|
||||
#define CSI_SM2_RK_LEN (32) /*random*/
|
||||
#define CSI_SM2_SIGNATURE_LEN (64)
|
||||
#define CSI_SM2_DIGEST_LEN (32)
|
||||
|
||||
@@ -31,7 +31,7 @@ extern "C" {
|
||||
#define SM2_PRIME_CURVE_N_BYTES (32)
|
||||
|
||||
typedef struct {
|
||||
uint32_t sm2_curve : 1; ///< supports 256bits curve
|
||||
uint32_t sm2_curve : 1; /*supports 256bits curve*/
|
||||
} sm2_capabilities_t;
|
||||
|
||||
/**
|
||||
@@ -43,15 +43,15 @@ typedef enum {
|
||||
} sm2_cipher_order_e;
|
||||
|
||||
typedef enum {
|
||||
SM2_ENDIAN_LITTLE = 0, ///< Little Endian
|
||||
SM2_ENDIAN_BIG ///< Big Endian
|
||||
SM2_ENDIAN_LITTLE = 0, /*Little Endian*/
|
||||
SM2_ENDIAN_BIG /*Big Endian*/
|
||||
} sm2_endian_mode_e;
|
||||
|
||||
/**
|
||||
\brief SM2 status
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t busy : 1; ///< Calculate busy flag
|
||||
uint32_t busy : 1; /*Calculate busy flag*/
|
||||
} csi_sm2_state_t;
|
||||
|
||||
/**
|
||||
@@ -61,12 +61,12 @@ typedef enum { SM2_Role_Sponsor = 0, SM2_Role_Responsor } sm2_exchange_role_e;
|
||||
|
||||
/****** SM2 Event *****/
|
||||
typedef enum {
|
||||
SM2_EVENT_MAKE_KEY_COMPLETE = 0, ///< Make key completed
|
||||
SM2_EVENT_ENCRYPT_COMPLETE, ///< Encrypt completed
|
||||
SM2_EVENT_DECRYPT_COMPLETE, ///< Decrypt completed
|
||||
SM2_EVENT_SIGN_COMPLETE, ///< Sign completed
|
||||
SM2_EVENT_VERIFY_COMPLETE, ///< Verify completed
|
||||
SM2_EVENT_EXCHANGE_KEY_COMPLETE, ///< Exchange key completed
|
||||
SM2_EVENT_MAKE_KEY_COMPLETE = 0, /*Make key completed*/
|
||||
SM2_EVENT_ENCRYPT_COMPLETE, /*Encrypt completed*/
|
||||
SM2_EVENT_DECRYPT_COMPLETE, /*Decrypt completed*/
|
||||
SM2_EVENT_SIGN_COMPLETE, /*Sign completed*/
|
||||
SM2_EVENT_VERIFY_COMPLETE, /*Verify completed*/
|
||||
SM2_EVENT_EXCHANGE_KEY_COMPLETE, /*Exchange key completed*/
|
||||
} sm2_event_e;
|
||||
|
||||
typedef struct {
|
||||
@@ -77,7 +77,7 @@ typedef struct {
|
||||
void * prim;
|
||||
} csi_sm2_t;
|
||||
|
||||
///< Pointer to \ref csi_sm2_callback_t : SM2 Event call back.
|
||||
/*Pointer to \ref csi_sm2_callback_t : SM2 Event call back.*/
|
||||
typedef void (*csi_sm2_callback_t)(sm2_event_e event);
|
||||
|
||||
/**
|
||||
@@ -263,7 +263,7 @@ csi_error_t csi_sm2_enable_pm(csi_sm2_t *sm2);
|
||||
void csi_sm2_disable_pm(csi_sm2_t *sm2);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
28
lib/sec_library/include/sm3.h
Executable file → Normal file
28
lib/sec_library/include/sm3.h
Executable file → Normal file
@@ -24,39 +24,39 @@ extern "C" {
|
||||
#define SM3_DIGEST_OUT_SIZE (32)
|
||||
|
||||
typedef struct {
|
||||
uint32_t total[2]; ///< Number of bytes processed
|
||||
uint32_t state[16]; ///< Intermediate digest state
|
||||
uint8_t buffer[SM3_DATAIN_BLOCK_SIZE]; ///< Data block beingprocessed
|
||||
uint8_t result[SM3_DIGEST_OUT_SIZE]; ///< Data block has processed
|
||||
uint32_t total[2]; /*Number of bytes processed*/
|
||||
uint32_t state[16]; /*Intermediate digest state*/
|
||||
uint8_t buffer[SM3_DATAIN_BLOCK_SIZE]; /*Data block beingprocessed*/
|
||||
uint8_t result[SM3_DIGEST_OUT_SIZE]; /*Data block has processed*/
|
||||
} csi_sm3_context_t;
|
||||
|
||||
/****** SM3 State ******/
|
||||
typedef struct {
|
||||
uint32_t busy : 1; ///< Calculate busy flag
|
||||
uint32_t error : 1; ///< Calculate error flag
|
||||
uint32_t busy : 1; /*Calculate busy flag*/
|
||||
uint32_t error : 1; /*Calculate error flag*/
|
||||
} csi_sm3_state_t;
|
||||
|
||||
|
||||
/****** SM3 Event ******/
|
||||
typedef enum {
|
||||
SM3_EVENT_COMPLETE = 0U, ///< Calculate completed
|
||||
SM3_EVENT_COMPLETE = 0U, /*Calculate completed*/
|
||||
SM3_EVENT_UPDATE,
|
||||
SM3_EVENT_START,
|
||||
SM3_EVENT_ERROR ///< Calculate error
|
||||
SM3_EVENT_ERROR /*Calculate error*/
|
||||
} csi_sm3_event_t;
|
||||
|
||||
typedef struct csi_sm3_t csi_sm3_t;
|
||||
|
||||
struct csi_sm3_t {
|
||||
csi_dev_t dev; ///< SM3 hw-device info
|
||||
csi_dev_t dev; /*SM3 hw-device info*/
|
||||
void (*callback)(csi_sm3_t *sm3, csi_sm3_event_t event,
|
||||
void *arg); ///< SM3 event callback for user
|
||||
void * arg; ///< SM3 custom designed param passed to evt_cb
|
||||
csi_sm3_state_t state; ///< SM3 state
|
||||
void *arg); /*SM3 event callback for user*/
|
||||
void * arg; /*SM3 custom designed param passed to evt_cb*/
|
||||
csi_sm3_state_t state; /*SM3 state*/
|
||||
void * priv;
|
||||
};
|
||||
|
||||
// Function documentation
|
||||
/*Function documentation*/
|
||||
|
||||
/**
|
||||
\brief Initialize SM3 Interface. Initializes the resources needed for the SM3 interface
|
||||
@@ -150,7 +150,7 @@ csi_error_t csi_sm3_enable_pm(csi_sm3_t *sm3);
|
||||
void csi_sm3_disable_pm(csi_sm3_t *sm3);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_DRV_SM3_H
|
||||
41
lib/sec_library/include/sm4.h
Executable file → Normal file
41
lib/sec_library/include/sm4.h
Executable file → Normal file
@@ -24,7 +24,28 @@ extern "C" {
|
||||
#define SM4_KEY_LEN_BYTES_24 (24)
|
||||
#define SM4_KEY_LEN_BYTES_16 (16)
|
||||
|
||||
#define SM4_IV_LEN_BYTES_16 (16)
|
||||
#define SM4_KEY_128_BITS (0x08)
|
||||
#define SM4_KEY_192_BITS (0x10)
|
||||
#define SM4_KEY_256_BITS (0x18)
|
||||
|
||||
#define SM4_IV_LEN_BYTES_16 (16)
|
||||
#define SM4_BLOCK_CRYPTO_SIZE (16)
|
||||
|
||||
#define SM4_DIR_ENCRYPT (1)
|
||||
#define SM4_DIR_DECRYPT (0)
|
||||
|
||||
/**
|
||||
\brief SM4 data transfer mode config
|
||||
*/
|
||||
typedef enum {
|
||||
SM4_SLAVE_MODE = 0U, /*slave mode*/
|
||||
SM4_DMA_MODE, /*dma mode*/
|
||||
} csi_sm4_trans_mode_t;
|
||||
|
||||
typedef enum{
|
||||
SM4_MODE_ECB = 0,
|
||||
SM4_MODE_CBC = 0x20000020,
|
||||
} csi_sm4_mode_t;
|
||||
|
||||
typedef enum {
|
||||
SM4_KEY_LEN_BITS_128 = 0, /*128 Data bits*/
|
||||
@@ -32,14 +53,15 @@ typedef enum {
|
||||
} csi_sm4_key_bits_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t busy : 1; ///< Calculate busy flag
|
||||
uint32_t error : 1; ///< Calculate error flag
|
||||
uint32_t busy : 1; /*Calculate busy flag*/
|
||||
uint32_t error : 1; /*Calculate error flag*/
|
||||
} csi_sm4_state_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t key_len_byte;
|
||||
uint8_t key[32]; ///< Data block being processed
|
||||
uint8_t key[32]; /*Data block being processed*/
|
||||
uint32_t sca;
|
||||
uint32_t is_dma;
|
||||
} csi_sm4_context_t;
|
||||
|
||||
/**
|
||||
@@ -53,7 +75,7 @@ typedef struct {
|
||||
uint32_t is_kdf;
|
||||
} csi_sm4_t;
|
||||
|
||||
// Function documentation
|
||||
/*Function documentation*/
|
||||
/**
|
||||
\brief Initialize sm4 Interface. Initializes the resources needed for the sm4 interface
|
||||
\param[in] sm4 operate handle
|
||||
@@ -69,6 +91,13 @@ csi_error_t csi_sm4_init(csi_sm4_t *sm4, uint32_t idx);
|
||||
*/
|
||||
void csi_sm4_uninit(csi_sm4_t *sm4);
|
||||
|
||||
/**
|
||||
\brief Config SM4 data transfer mode
|
||||
\param[in] mode \ref csi_sm4_trans_mode_t
|
||||
\return error code \ref csi_error_t
|
||||
*/
|
||||
csi_error_t csi_sm4_trans_config(csi_sm4_t *aes, csi_sm4_trans_mode_t mode);
|
||||
|
||||
/**
|
||||
\brief Set encrypt key
|
||||
\param[in] sm4 handle to operate
|
||||
@@ -266,7 +295,7 @@ csi_error_t csi_sm4_enable_pm(csi_sm4_t *sm4);
|
||||
void csi_sm4_disable_pm(csi_sm4_t *sm4);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _DRV_SM4_H_
|
||||
|
||||
0
lib/sec_library/include/soc.h
Executable file → Normal file
0
lib/sec_library/include/soc.h
Executable file → Normal file
0
lib/sec_library/include/sys_clk.h
Executable file → Normal file
0
lib/sec_library/include/sys_clk.h
Executable file → Normal file
Reference in New Issue
Block a user