HPM SDK
HPMicro Software Development Kit
hpm_sdp_drv.c File Reference
#include "hpm_sdp_drv.h"
#include "hpm_soc_feature.h"

Data Structures

struct  sdp_hash_internal_ctx_t
 

Macros

#define AES_KEY_SRC_SDP_START_IDX   0U
 
#define AES128_KEY_SRC_SDP_END_IDX   0xFU
 
#define AES256_KEY_SRC_SDP_END_IDX   0x7U
 
#define AES_KEY_SRC_KEYMAN_START_IDX   0x20U
 
#define AES128_KEY_SRC_KEYMAN_END_IDX   0x2FU
 
#define AES256_KEY_SRC_KEYMAN_END_IDX   0x2FU
 
#define AES_KEY_SRC_UNIQUE_KEY_START_IDX   0x3EU
 
#define AES_KEY_SRC_OTP_KEY_START_IDX   0x3FU
 
#define AES_256_KEY_SIZE_IN_WORDS   (8U)
 
#define AES_256_KEY_SIZE_IN_BYTES   (32U)
 
#define CRC32_DIGEST_SIZE_IN_BYTES   (4U)
 
#define SHA1_DIGEST_SIZE_IN_BYTES   (20U)
 
#define SHA256_DIGEST_SIZE_IN_BYTES   (32U)
 
#define AES_CTR_BLOCK_UNIT   (16U)
 
#define AES_BLOCK_SIZE   (16U)
 
#define HASH_BLOCK_SIZE   (64U)
 
#define HASH_DIGEST_SIZE_MAX   (32)
 
#define SDP_CRYPTO_ALG_IDX_AES128   (0U)
 
#define SDP_CRYPTO_ALG_IDX_AES256   (1U)
 
#define SDP_CRYPTO_ALG_IDX_SM4   (8U)
 

Enumerations

enum  sdp_hash_alg_state_t { sdp_state_hash_init , sdp_state_hash_update }
 

Functions

static void sdp_hash_internal_engine_init (SDP_Type *base, sdp_hash_ctx_t *hash_ctx)
 
static hpm_stat_t sdp_hash_process_message (SDP_Type *base, sdp_hash_ctx_t *ctx, const uint8_t *msg, uint32_t msg_size)
 
static hpm_stat_t sdp_hash_internal_update (SDP_Type *base, sdp_hash_ctx_t *ctx, const uint8_t *msg, uint32_t msg_size)
 
static hpm_stat_t sdp_hash_finalize (SDP_Type *base, sdp_hash_ctx_t *hash_ctx)
 
static void sdp_clear_error_status (SDP_Type *base)
 
static void sdp_increment_bn (uint8_t *big_num, uint32_t bytes)
 
static void uint32_to_be (uint8_t *dst, uint32_t len, uint32_t num)
 
static hpm_stat_t aes_ccm_auth_crypt (SDP_Type *base, sdp_aes_ctx_t *aes_ctx, sdp_aes_op_t op, uint32_t input_len, const uint8_t *iv, uint32_t iv_len, const uint8_t *aad, uint32_t aad_len, const uint8_t *input, uint8_t *output, uint8_t *mac, uint32_t mac_len)
 
static void aes_ccm_format_b0 (uint8_t *block, const uint8_t *iv, uint32_t iv_len, uint32_t mac_len, uint32_t aad_len, uint32_t input_len)
 
static void aes_ccm_format_ctr0 (uint8_t *ctr, const uint8_t *iv, uint8_t iv_len)
 
static uint8_t sdp_constant_time_cmp (const void *dst, const void *src, uint32_t len)
 
hpm_stat_t sdp_wait_done (SDP_Type *base)
 Wait until the SDP operation gets done. More...
 
hpm_stat_t sdp_init (SDP_Type *base)
 Initialize the SDP controller. More...
 
hpm_stat_t sdp_deinit (SDP_Type *base)
 De-initialize the SDP controller. More...
 
hpm_stat_t sdp_aes_set_key (SDP_Type *base, sdp_aes_ctx_t *aes_ctx, const uint8_t *key, sdp_aes_key_bits_t key_bits, uint32_t key_idx)
 Set the AES key for the SDP AES operation. More...
 
hpm_stat_t sdp_aes_crypt_ecb (SDP_Type *base, sdp_aes_ctx_t *aes_ctx, sdp_aes_op_t op, uint32_t len, const uint8_t *in, uint8_t *out)
 Perform the basic AES ECB operation. More...
 
hpm_stat_t sdp_aes_crypt_cbc (SDP_Type *base, sdp_aes_ctx_t *aes_ctx, sdp_aes_op_t op, uint32_t length, const uint8_t iv[16], const uint8_t *input, uint8_t *output)
 Perform the AES CBC operation. More...
 
hpm_stat_t sdp_aes_crypt_ctr (SDP_Type *base, sdp_aes_ctx_t *aes_ctx, uint8_t *nonce_counter, uint8_t *input, uint8_t *output, uint32_t length)
 Perform the AES-CTR operation See NIST Special Publication800-38A for more details. More...
 
hpm_stat_t sdp_aes_ccm_generate_encrypt (SDP_Type *base, sdp_aes_ctx_t *aes_ctx, uint32_t input_len, const uint8_t *iv, uint32_t iv_len, const uint8_t *aad, uint32_t aad_len, const uint8_t *input, uint8_t *output, uint8_t *tag, uint32_t tag_len)
 Perform the AES-CCM generate and encrypt See NIST Special Publication 800-38C for more details. More...
 
hpm_stat_t sdp_aes_ccm_decrypt_verify (SDP_Type *base, sdp_aes_ctx_t *aes_ctx, uint32_t input_len, const uint8_t *iv, uint32_t iv_len, const uint8_t *aad, uint32_t aad_len, const uint8_t *input, uint8_t *output, const uint8_t *tag, uint32_t tag_len)
 Perform the AES-CCM decrypt and verify See NIST Special Publication 800-38C for more details. More...
 
hpm_stat_t sdp_hash_init (SDP_Type *base, sdp_hash_ctx_t *hash_ctx, sdp_hash_alg_t alg)
 Initialize the HASH engine. More...
 
hpm_stat_t sdp_hash_update (SDP_Type *base, sdp_hash_ctx_t *hash_ctx, const uint8_t *data, uint32_t length)
 Compute the HASH digest. More...
 
hpm_stat_t sdp_hash_finish (SDP_Type *base, sdp_hash_ctx_t *hash_ctx, uint8_t *digest)
 Finish the HASH calculation and output the digest. More...
 
hpm_stat_t sdp_memcpy (SDP_Type *base, sdp_dma_ctx_t *dma_ctx, void *dst, const void *src, uint32_t length)
 Perform the DMA accelerated memcpy. More...
 
hpm_stat_t sdp_memset (SDP_Type *base, sdp_dma_ctx_t *sdp_ctx, void *dst, uint8_t pattern, uint32_t length)
 Perform the DMA accelerated memset. More...
 
hpm_stat_t sdp_trigger_action (SDP_Type *base, const sdp_action_t *action, const sdp_pkt_struct_t *cmd_pkt)
 Trigger SDP operation via the specified SDP packet description. More...
 

Macro Definition Documentation

◆ AES128_KEY_SRC_KEYMAN_END_IDX

#define AES128_KEY_SRC_KEYMAN_END_IDX   0x2FU

◆ AES128_KEY_SRC_SDP_END_IDX

#define AES128_KEY_SRC_SDP_END_IDX   0xFU

◆ AES256_KEY_SRC_KEYMAN_END_IDX

#define AES256_KEY_SRC_KEYMAN_END_IDX   0x2FU

◆ AES256_KEY_SRC_SDP_END_IDX

#define AES256_KEY_SRC_SDP_END_IDX   0x7U

◆ AES_256_KEY_SIZE_IN_BYTES

#define AES_256_KEY_SIZE_IN_BYTES   (32U)

◆ AES_256_KEY_SIZE_IN_WORDS

#define AES_256_KEY_SIZE_IN_WORDS   (8U)

◆ AES_BLOCK_SIZE

#define AES_BLOCK_SIZE   (16U)

◆ AES_CTR_BLOCK_UNIT

#define AES_CTR_BLOCK_UNIT   (16U)

◆ AES_KEY_SRC_KEYMAN_START_IDX

#define AES_KEY_SRC_KEYMAN_START_IDX   0x20U

◆ AES_KEY_SRC_OTP_KEY_START_IDX

#define AES_KEY_SRC_OTP_KEY_START_IDX   0x3FU

◆ AES_KEY_SRC_SDP_START_IDX

#define AES_KEY_SRC_SDP_START_IDX   0U

AES Key source definition

◆ AES_KEY_SRC_UNIQUE_KEY_START_IDX

#define AES_KEY_SRC_UNIQUE_KEY_START_IDX   0x3EU

◆ CRC32_DIGEST_SIZE_IN_BYTES

#define CRC32_DIGEST_SIZE_IN_BYTES   (4U)

◆ HASH_BLOCK_SIZE

#define HASH_BLOCK_SIZE   (64U)

◆ HASH_DIGEST_SIZE_MAX

#define HASH_DIGEST_SIZE_MAX   (32)

◆ SDP_CRYPTO_ALG_IDX_AES128

#define SDP_CRYPTO_ALG_IDX_AES128   (0U)

◆ SDP_CRYPTO_ALG_IDX_AES256

#define SDP_CRYPTO_ALG_IDX_AES256   (1U)

◆ SDP_CRYPTO_ALG_IDX_SM4

#define SDP_CRYPTO_ALG_IDX_SM4   (8U)

◆ SHA1_DIGEST_SIZE_IN_BYTES

#define SHA1_DIGEST_SIZE_IN_BYTES   (20U)

◆ SHA256_DIGEST_SIZE_IN_BYTES

#define SHA256_DIGEST_SIZE_IN_BYTES   (32U)

Enumeration Type Documentation

◆ sdp_hash_alg_state_t

Enumerator
sdp_state_hash_init 
sdp_state_hash_update 

Function Documentation

◆ aes_ccm_auth_crypt()

static hpm_stat_t aes_ccm_auth_crypt ( SDP_Type base,
sdp_aes_ctx_t aes_ctx,
sdp_aes_op_t  op,
uint32_t  input_len,
const uint8_t *  iv,
uint32_t  iv_len,
const uint8_t *  aad,
uint32_t  aad_len,
const uint8_t *  input,
uint8_t *  output,
uint8_t *  mac,
uint32_t  mac_len 
)
static

◆ aes_ccm_format_b0()

static void aes_ccm_format_b0 ( uint8_t *  block,
const uint8_t *  iv,
uint32_t  iv_len,
uint32_t  mac_len,
uint32_t  aad_len,
uint32_t  input_len 
)
static

◆ aes_ccm_format_ctr0()

static void aes_ccm_format_ctr0 ( uint8_t *  ctr,
const uint8_t *  iv,
uint8_t  iv_len 
)
static

◆ sdp_clear_error_status()

static void sdp_clear_error_status ( SDP_Type base)
inlinestatic

◆ sdp_constant_time_cmp()

static uint8_t sdp_constant_time_cmp ( const void *  dst,
const void *  src,
uint32_t  len 
)
static

◆ sdp_hash_finalize()

static hpm_stat_t sdp_hash_finalize ( SDP_Type base,
sdp_hash_ctx_t hash_ctx 
)
static

◆ sdp_hash_internal_engine_init()

static void sdp_hash_internal_engine_init ( SDP_Type base,
sdp_hash_ctx_t hash_ctx 
)
static

◆ sdp_hash_internal_update()

static hpm_stat_t sdp_hash_internal_update ( SDP_Type base,
sdp_hash_ctx_t ctx,
const uint8_t *  msg,
uint32_t  msg_size 
)
static

◆ sdp_hash_process_message()

static hpm_stat_t sdp_hash_process_message ( SDP_Type base,
sdp_hash_ctx_t ctx,
const uint8_t *  msg,
uint32_t  msg_size 
)
static

◆ sdp_increment_bn()

static void sdp_increment_bn ( uint8_t *  big_num,
uint32_t  bytes 
)
static

◆ uint32_to_be()

static void uint32_to_be ( uint8_t *  dst,
uint32_t  len,
uint32_t  num 
)
static