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

Go to the source code of this file.

Data Structures

struct  sdp_crypto_ctx_t
 SDP AES context structure. More...
 
struct  sdp_dma_ctx_t
 SDP DMA context. More...
 
struct  sdp_hash_ctx_t
 SDP HASH context. More...
 
struct  sdp_action_t
 SDP Action Structure. More...
 

Macros

#define HASH_BLOCK_SIZE   (64U)
 
#define AES_BLOCK_SIZE   (16U)
 
#define AES_128_KEY_SIZE   (0x10U)
 
#define AES_256_KEY_SIZE   (0x20U)
 
#define SM4_BLOCK_SIZE   (AES_BLOCK_SIZE)
 
#define SM4_KEY_SIZE   (AES_128_KEY_SIZE)
 
#define SDP_PKT_CTRL_DERSEMA_MASK   (1U << 2)
 Bitfield definitions for the PKT_CTRL. More...
 
#define SDP_PKT_CTRL_CHAIN_MASK   (1U << 3)
 
#define SDP_PKT_CTRL_HASHINIT_MASK   (1U << 4)
 
#define SDP_PKT_CTRL_HASHFINISH_MASK   (1U << 5)
 
#define SDP_PKT_CTRL_CIPHIV_MASK   (1U << 6)
 

Typedefs

typedef sdp_crypto_key_bits_t sdp_aes_key_bits_t
 
typedef sdp_crypto_key_bits_t sdp_sm4_key_bits_t
 
typedef sdp_crypto_op_t sdp_aes_op_t
 
typedef struct _sdp_packet_struct sdp_pkt_struct_t
 SDP Command Packet structure. More...
 
typedef sdp_crypto_ctx_t sdp_aes_ctx_t
 

Enumerations

enum  sdp_crypto_key_bits_t { sdp_aes_keybits_128 = 0 , sdp_aes_keybits_256 = 1 }
 SDP AES key bit options. More...
 
enum  sdp_crypto_op_t { sdp_aes_op_encrypt , sdp_aes_op_decrypt }
 Crypto operation option. More...
 
enum  sdp_crypto_alg_t { sdp_crypto_alg_aes = 0 }
 SDP Crypto algorithms. More...
 
enum  sdp_crypto_mode_t { sdp_crypto_mode_ecb = 0 , sdp_crypto_mode_cbc = 1 }
 SDP Crypto modes. More...
 
enum  sdp_data_swap_mode_t { sdp_swap_mode_none = 0 , sdp_swap_mode_bytes_in_word = 1 , sdp_swap_mode_word_swap = 2 , sdp_swap_mode_switch_endian = 3 }
 SDP Data Swap modes. More...
 
enum  sdp_calc_hash_mode_t { sdp_calc_hash_for_input = 0 , sdp_calc_hash_for_output = 1 }
 SDP HASH calculation mode. More...
 
enum  sdp_hash_alg_t { sdp_hash_alg_sha1 = 0 , sdp_hash_alg_crc32 = 1 , sdp_hash_alg_sha256 = 2 , sdp_hash_alg_max = sdp_hash_alg_sha256 }
 SDP HASH algorithm definitions. More...
 
enum  {
  status_sdp_no_crypto_support = ((uint32_t)( status_group_sdp )*1000U + (uint32_t)( 0 )) , status_sdp_no_hash_support = ((uint32_t)( status_group_sdp )*1000U + (uint32_t)( 1 )) , status_sdp_invalid_key_src = ((uint32_t)( status_group_sdp )*1000U + (uint32_t)( 2 )) , status_sdp_error_packet = ((uint32_t)( status_group_sdp )*1000U + (uint32_t)( 3 )) ,
  status_sdp_aes_busy = ((uint32_t)( status_group_sdp )*1000U + (uint32_t)( 4 )) , status_sdp_hash_busy = ((uint32_t)( status_group_sdp )*1000U + (uint32_t)( 5 )) , status_sdp_error_setup = ((uint32_t)( status_group_sdp )*1000U + (uint32_t)( 6 )) , status_sdp_error_src = ((uint32_t)( status_group_sdp )*1000U + (uint32_t)( 7 )) ,
  status_sdp_error_dst = ((uint32_t)( status_group_sdp )*1000U + (uint32_t)( 8 )) , status_sdp_error_hash = ((uint32_t)( status_group_sdp )*1000U + (uint32_t)( 9 )) , status_sdp_error_chain = ((uint32_t)( status_group_sdp )*1000U + (uint32_t)( 10 )) , status_sdp_error_invalid_mac = ((uint32_t)( status_group_sdp )*1000U + (uint32_t)( 11 )) ,
  status_sdp_invalid_alg = ((uint32_t)( status_group_sdp )*1000U + (uint32_t)( 12 ))
}
 SDP error status definitions. More...
 
enum  sdp_operation_t {
  sdp_op_invalid = 0 , sdp_op_cipher_only = SDP_SDPCR_CIPHEN_MASK , sdp_op_hash_only = SDP_SDPCR_HASHEN_MASK , sdp_op_memcpy_only = SDP_SDPCR_MCPEN_MASK ,
  sdp_op_memfill_only = SDP_SDPCR_CONFEN_MASK , sdp_op_cipher_hash = SDP_SDPCR_CIPHEN_MASK | SDP_SDPCR_HASHEN_MASK , sdp_op_copy_hash = SDP_SDPCR_MCPEN_MASK | SDP_SDPCR_HASHEN_MASK
}
 SDP Operations. More...
 

Functions

static void sdp_enable_interrupt (SDP_Type *base)
 Enable SDP interrupt. More...
 
static void sdp_disable_interrupt (SDP_Type *base)
 Disable SDP interrupt. More...
 
static void sdp_set_key_index (SDP_Type *base, uint32_t key_index)
 Set the Crypto Key Index in SDP. More...
 
static void sdp_write_key (SDP_Type *base, uint32_t key_index, uint32_t key_bits, const uint32_t *crypto_key)
 Write SDP key to specified SDP Key RAM. More...
 
static void sdp_write_hash_digest (SDP_Type *base, const uint32_t *digest, uint32_t num_words)
 Write the HASH digest result to SDP. More...
 
static void sdp_get_hash_digest (SDP_Type *base, uint32_t *digest, uint32_t num_words)
 Read the HASH digest result from SDP. More...
 
static void sdp_write_cipher_iv (SDP_Type *base, const uint32_t *iv)
 Write the cipher IV to SDP. More...
 
static void sdp_clear_status (SDP_Type *base, uint32_t mask)
 Clear SDP status. More...
 
static uint32_t sdp_get_status (SDP_Type *base)
 Get SDP status. 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_memcpy (SDP_Type *base, sdp_dma_ctx_t *sdp_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_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_wait_done (SDP_Type *base)
 Wait until the SDP operation gets done. 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...