修改上传所有文件

This commit is contained in:
2025-10-21 19:40:27 +08:00
parent 5a84d13ae4
commit 391f81f8fc
8417 changed files with 2995282 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,522 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <hash.h>
#include <hmac.h>
/* function: init HMAC
* parameters:
* ctx ------------------------ input, hmac_ctx_t context pointer
* key_flag ------------------- input, whether key byte length bigger than
* block byte length return: HASH_SUCCESS(success), other(error) caution:
* 1. please make sure hash_alg is valid
*/
static void hmac_key_state_recover(hmac_ctx_t *ctx, uint32_t key_flag)
{
hash_set_cpu_mode();
hash_set_hmac_mode();
hash_set_endian_uint32();
hash_disable_cpu_interruption();
hash_set_alg(ctx->hash_alg);
hash_set_hmac_key_mode();
hash_update_config();
if (1 == key_flag) {
hash_set_IV(ctx->hash_alg, ctx->hash_ctx->iterator_word_len);
hash_hmac_key_opr_one_block(ctx->K0, ctx->hash_ctx->block_byte_len);
} else if (2 == key_flag) {
hash_set_iterator(ctx->K0, ctx->hash_ctx->iterator_word_len);
hash_set_hmac_key_len(0);
hash_set_hmac_key_cnt(0);
hash_set_last_block(1);
hash_start();
hash_wait_till_done();
} else {
;
}
hash_clear_hmac_key_mode();
}
/* function: init HMAC
* parameters:
* ctx ------------------------ input, hmac_ctx_t context pointer
* hash_alg ------------------- input, specific hash algorithm
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of key, it could be 0
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure hash_alg is valid
*/
uint32_t hmac_init(hmac_ctx_t *ctx, HASH_ALG hash_alg, uint8_t *key,
uint16_t sp_key_idx, uint32_t key_bytes)
{
if (NULL == ctx) {
return HASH_BUFFER_NULL;
} else if (HASH_SUCCESS != check_hash_alg(hash_alg)) {
return HASH_INPUT_INVALID;
} else if (key_bytes & 0xE0000000) {
/*bit length overflow*/
return HASH_INPUT_INVALID;
} else if (NULL == key) {
#ifdef HMAC_SECURE_PORT_FUNCTION
if ((0 == sp_key_idx) || (sp_key_idx > HMAC_MAX_KEY_IDX) ||
(0 == key_bytes) || (key_bytes > HMAC_MAX_SP_KEY_SIZE)) {
return HASH_INPUT_INVALID;
} else if ((sp_key_idx == HMAC_MAX_KEY_IDX) &&
(key_bytes > HMAC_MAX_SP_KEY_SIZE / 2)) {
return HASH_INPUT_INVALID;
} else {
;
}
#else
key_bytes = 0;
#endif
} else {
;
}
/*set hash_ctx config*/
memset_(ctx, 0, sizeof(hmac_ctx_t));
if (key) {
/*key is from user input*/
hash_hmac_disable_secure_port();
} else {
/*key is from secure port*/
hash_hmac_enable_secure_port(sp_key_idx);
hash_hmac_enable_secure_port(sp_key_idx + 1);
}
hash_set_cpu_mode();
hash_set_hmac_mode();
hash_set_hmac_key_mode();
hash_set_endian_uint32();
hash_disable_cpu_interruption();
hash_set_alg(hash_alg);
hash_update_config();
ctx->hash_alg = hash_alg;
ctx->hash_ctx->hash_alg = hash_alg;
ctx->hash_ctx->block_byte_len = hash_get_block_word_len(hash_alg) << 2;
ctx->hash_ctx->iterator_word_len = hash_get_iterator_word_len(hash_alg);
ctx->hash_ctx->digest_byte_len = hash_get_digest_word_len(hash_alg) << 2;
ctx->hash_ctx->status.busy = 0;
ctx->hash_ctx->first_update_flag = 1;
ctx->hash_ctx->finish_flag = 0;
if (key) {
/*key is from user input*/
hash_set_IV(hash_alg, ctx->hash_ctx->iterator_word_len);
/*get K0*/
if (key_bytes <= ctx->hash_ctx->block_byte_len) {
/*K0 = (key)||000..00*/
ctx->key_flag = 1;
memcpy_((uint8_t *)(ctx->K0), key, key_bytes);
memset_(((uint8_t *)(ctx->K0)) + key_bytes, 0,
ctx->hash_ctx->block_byte_len - key_bytes);
hash_hmac_key_opr_one_block(ctx->K0, ctx->hash_ctx->block_byte_len);
} else {
ctx->key_flag = 2;
hash_hmac_key_opr(key, key_bytes);
hash_get_iterator(((uint8_t *)(ctx->K0)),
ctx->hash_ctx->digest_byte_len >> 2);
memset_(((uint8_t *)(ctx->K0)) + ctx->hash_ctx->digest_byte_len, 0,
ctx->hash_ctx->block_byte_len -
ctx->hash_ctx->digest_byte_len);
}
} else {
/*key is from secure port*/
hash_hmac_sp_key_opr(key_bytes << 3);
}
hash_clear_hmac_key_mode();
return HASH_SUCCESS;
}
/* function: hash iterate calc with some blocks
* parameters:
* ctx ------------------------ input, hash_ctx_t context pointer
* msg ------------------------ input, message of some blocks
* block_count ---------------- input, count of blocks
* return: none
* caution:
* 1. please make sure the three parameters is valid
*/
static void hash_hmac_calc_blocks(hash_ctx_t *ctx, const uint8_t *msg,
uint32_t block_count)
{
uint8_t block_word_len = (ctx->block_byte_len) >> 2;
#if CONFIG_HASH_SUPPORT_MUL_THREAD
/*set the input iterator data*/
if (1 != ctx->first_update_flag) {
hash_set_iterator(ctx->iterator, ctx->iterator_word_len);
} else {
;
}
#endif
/*set the bit length of the input blocks*/
hash_set_tx_bit_len(ctx, block_count);
hash_set_last_block(0);
ctx->first_update_flag = 0;
hash_start_calculate(ctx);
while (block_count--) {
/*input the block message*/
hash_input_msg((uint8_t *)msg, block_word_len);
msg += ctx->block_byte_len;
}
hash_wait_till_done();
#if CONFIG_HASH_SUPPORT_MUL_THREAD
/*if message update not done, get the new iterator hash value*/
if (1 != ctx->finish_flag) {
hash_get_iterator((uint8_t *)(ctx->iterator), ctx->iterator_word_len);
} else {
;
}
#endif
}
/* function: hmac update message
* parameters:
* ctx ------------------------ input, hmac_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_update(hmac_ctx_t *ctx, const uint8_t *msg, uint32_t msg_bytes)
{
uint32_t count;
uint8_t left, fill;
if (NULL == ctx) {
return HASH_BUFFER_NULL;
} else if ((NULL == msg) || (0 == msg_bytes)) {
return HASH_SUCCESS;
} else {
;
}
/*start to update processing*/
ctx->hash_ctx->status.busy = 1;
#if CONFIG_HASH_SUPPORT_MUL_THREAD
hmac_key_state_recover(ctx, ctx->key_flag);
#endif
/*byte length of valid message left in block buffer*/
/*byte length that block buffer need to fill a block*/
left = ctx->hash_ctx->total[0] % (ctx->hash_ctx->block_byte_len);
fill = (ctx->hash_ctx->block_byte_len) - left;
/*update total byte length*/
if (hash_total_len_add_uint32(ctx->hash_ctx->total,
ctx->hash_ctx->block_byte_len / 32,
msg_bytes)) {
return HASH_LEN_OVERFLOW;
} else {
;
}
if (left) {
if (msg_bytes >= fill) {
memcpy_(ctx->hash_ctx->hash_buffer + left, (uint8_t *)msg, fill);
hash_hmac_calc_blocks(ctx->hash_ctx, ctx->hash_ctx->hash_buffer, 1);
msg_bytes -= fill;
msg += fill;
} else {
memcpy_(ctx->hash_ctx->hash_buffer + left, (uint8_t *)msg,
msg_bytes);
goto end;
}
} else {
;
}
/*process some blocks*/
count = msg_bytes / (ctx->hash_ctx->block_byte_len);
if (count) {
hash_hmac_calc_blocks(ctx->hash_ctx, msg, count);
} else {
;
}
/*process the remainder*/
msg += (ctx->hash_ctx->block_byte_len) * count;
msg_bytes = msg_bytes % (ctx->hash_ctx->block_byte_len);
if (msg_bytes) {
memcpy_(ctx->hash_ctx->hash_buffer, (uint8_t *)msg, msg_bytes);
} else {
;
}
end:
/*update end, status becomes idle*/
ctx->hash_ctx->status.busy = 0;
return HASH_SUCCESS;
}
/* function: message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_ctx_t context pointer
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the ctx is valid and initialized
* 2. please make sure the mac buffer is sufficient
*/
uint32_t hmac_final(hmac_ctx_t *ctx, uint8_t *mac)
{
uint8_t tmp;
if (NULL == ctx || NULL == mac) {
return HASH_BUFFER_NULL;
} else {
;
}
#if CONFIG_HASH_SUPPORT_MUL_THREAD
hmac_key_state_recover(ctx, ctx->key_flag);
if (0 == ctx->hash_ctx->first_update_flag) {
hash_set_iterator((uint8_t *)(ctx->hash_ctx->iterator),
ctx->hash_ctx->iterator_word_len);
}
/*set not the last block*/
hash_set_last_block(0);
#endif
/*the last block calc*/
ctx->hash_ctx->finish_flag = 1;
/*get the byte length of the remainder msg(less than one block)*/
tmp = ctx->hash_ctx->total[0] % (ctx->hash_ctx->block_byte_len);
/*set total msg bit length*/
hash_total_bytelen_2_bitlen(ctx->hash_ctx->total,
(ctx->hash_ctx->block_byte_len) / 32);
hash_set_msg_total_bit_len(ctx->hash_ctx->total,
ctx->hash_ctx->block_byte_len);
hash_set_last_block(1);
hash_start();
hash_input_msg((uint8_t *)ctx->hash_ctx->hash_buffer, (tmp + 3) / 4);
hash_wait_till_done();
/*get the hash result*/
hash_get_iterator(mac, (ctx->hash_ctx->digest_byte_len) >> 2);
memset_(ctx, 0, sizeof(hmac_ctx_t));
return HASH_SUCCESS;
}
/* function: input key and whole message, get the mac
* parameters:
* hash_alg ------------------- input, specific hash algorithm
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of the key
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the mac buffer is sufficient
*/
uint32_t hmac(HASH_ALG hash_alg, uint8_t *key, uint16_t sp_key_idx,
uint32_t key_bytes, uint8_t *msg, uint32_t msg_bytes,
uint8_t *mac)
{
hmac_ctx_t ctx[1];
uint32_t ret;
ret = hmac_init(ctx, hash_alg, key, sp_key_idx, key_bytes);
if (HASH_SUCCESS != ret) {
return ret;
} else {
;
}
ret = hmac_update(ctx, msg, msg_bytes);
if (HASH_SUCCESS != ret) {
return ret;
} else {
;
}
return hmac_final(ctx, mac);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma hmac
* parameters:
* ctx ------------------------ input, hmac_dma_ctx_t context pointer
* hash_alg ------------------- input, specific hash algorithm
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t hmac_dma_init(hmac_dma_ctx_t *ctx, HASH_ALG hash_alg,
const uint8_t *key, uint16_t sp_key_idx,
uint32_t key_bytes, HASH_CALLBACK callback)
{
uint32_t ret;
if (NULL == ctx || NULL == callback) {
return HASH_BUFFER_NULL;
} else {
;
}
ret = hmac_init(ctx->hmac_ctx, hash_alg, (uint8_t *)key, sp_key_idx,
key_bytes);
if (HASH_SUCCESS == ret) {
hash_clear_dma_sa_da();
hash_set_dma_wlen(hash_get_digest_word_len(hash_alg) << 5);
hash_set_dma_mode();
hash_set_last_block(0);
ctx->hash_dma_ctx->block_word_len = hash_get_block_word_len(hash_alg);
ctx->hash_dma_ctx->callback = callback;
uint32_clear(ctx->hash_dma_ctx->total,
ctx->hash_dma_ctx->block_word_len / 8);
} else {
;
}
return ret;
}
/* function: dma hmac update message
* parameters:
* ctx ------------------------ input, hmac_dma_ctx_t context pointer
* msg ------------------------ input, message
* msg_words ------------------ input, word length of the input message,
* must be multiple of block word length of HASH tmp_iterator ---------------
* output, temporary hash iterator return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t hmac_dma_update_blocks(hmac_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *tmp_iterator)
{
if (NULL == ctx) {
return HASH_BUFFER_NULL;
} else {
return hash_dma_update_blocks(ctx->hash_dma_ctx, msg, msg_words,
tmp_iterator);
}
}
/* function: dma hmac message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_dma_ctx_t context pointer
* remainder_msg -------------- input, message
* remainder_bytes ------------ input, byte length of the last message, must
* be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of HASH
* tmp_iterator --------------- output, temporary hash iterator
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_dma_final(hmac_dma_ctx_t *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *tmp_iterator,
uint8_t *mac)
{
uint32_t ret;
if ((NULL == ctx) || (NULL == tmp_iterator) || (NULL == mac)) {
return HASH_BUFFER_NULL;
} else {
;
}
ret = hash_dma_final(ctx->hash_dma_ctx, remainder_msg, remainder_bytes,
tmp_iterator);
if (HASH_SUCCESS == ret) {
memcpy_(mac, (uint8_t *)tmp_iterator,
ctx->hmac_ctx->hash_ctx->digest_byte_len);
}
return ret;
}
/* function: dma hmac input key and message, get the mac
* parameters:
* hash_alg ------------------- input, specific hash algorithm
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* tmp_iterator --------------- output, for temporary hash iterator or
* digest(DMA) mac ------------------------ output, mac callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
*/
uint32_t hmac_dma(HASH_ALG hash_alg, uint8_t *key, uint16_t sp_key_idx,
uint32_t key_bytes, uint32_t *msg, uint32_t msg_bytes,
uint32_t *tmp_iterator, uint8_t *mac, HASH_CALLBACK callback)
{
uint32_t blocks_words, remainder_bytes;
uint32_t ret;
hmac_dma_ctx_t ctx[1];
ret = hmac_dma_init(ctx, hash_alg, key, sp_key_idx, key_bytes, callback);
if (HASH_SUCCESS != ret) {
return ret;
} else {
;
}
remainder_bytes = msg_bytes % ctx->hmac_ctx->hash_ctx->block_byte_len;
blocks_words = (msg_bytes - remainder_bytes) / 4;
ret = hash_dma_update_blocks(ctx->hash_dma_ctx, msg, blocks_words,
tmp_iterator);
if (HASH_SUCCESS != ret) {
return ret;
} else {
;
}
return hmac_dma_final(ctx, (uint32_t *)(msg + blocks_words),
remainder_bytes, tmp_iterator, mac);
}
#endif

View File

@@ -0,0 +1,153 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <hmac_md5.h>
#ifdef SUPPORT_HASH_MD5
/* function: init hmac-md5
* parameters:
* ctx ------------------------ input, HMAC_MD5_CTX context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of key, it could be 0
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t hmac_md5_init(HMAC_MD5_CTX *ctx, uint8_t *key, uint16_t sp_key_idx,
uint32_t key_bytes)
{
return hmac_init(ctx, HASH_MD5, key, sp_key_idx, key_bytes);
}
/* function: hmac-md5 update message
* parameters:
* ctx ------------------------ input, HMAC_MD5_CTX context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_md5_update(HMAC_MD5_CTX *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hmac_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_ctx_t context pointer
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the ctx is valid and initialized
* 2. please make sure the mac buffer is sufficient
*/
uint32_t hmac_md5_final(HMAC_MD5_CTX *ctx, uint8_t *mac)
{
return hmac_final(ctx, mac);
}
/* function: input key and whole message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of the key
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the mac buffer is sufficient
*/
uint32_t hmac_md5(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint8_t *msg, uint32_t msg_bytes, uint8_t *mac)
{
return hmac(HASH_MD5, key, sp_key_idx, key_bytes, msg, msg_bytes, mac);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma hmac-md5
* parameters:
* ctx ------------------------ input, HMAC_MD5_DMA_CTX context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t hmac_md5_dma_init(HMAC_MD5_DMA_CTX *ctx, const uint8_t *key,
uint16_t sp_key_idx, uint32_t key_bytes,
HASH_CALLBACK callback)
{
return hmac_dma_init(ctx, HASH_MD5, key, sp_key_idx, key_bytes, callback);
}
/* function: dma hmac-md5 update message
* parameters:
* ctx ------------------------ input, HMAC_MD5_DMA_CTX context pointer
* msg ------------------------ input, message
* msg_words ------------------ input, word length of the input message,
* must be a multiple of block word length of MD5(16) tmp_iterator
* --------------- output, temporary hash iterator return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t hmac_md5_dma_update_blocks(HMAC_MD5_DMA_CTX *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *tmp_iterator)
{
return hmac_dma_update_blocks(ctx, msg, msg_words, tmp_iterator);
}
/* function: dma hmac-md5 message update done, get the mac
* parameters:
* ctx ------------------------ input, HMAC_MD5_DMA_CTX context pointer
* remainder_msg -------------- input, message
* remainder_bytes ------------ input, byte length of the last message, must
* be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* MD5(64) tmp_iterator --------------- output, temporary hash iterator mac
* ------------------------ output, mac return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_md5_dma_final(HMAC_MD5_DMA_CTX *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *tmp_iterator,
uint8_t *mac)
{
return hmac_dma_final(ctx, remainder_msg, remainder_bytes, tmp_iterator,
mac);
}
/* function: dma hmac-md5 input key and message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* tmp_iterator --------------- output, for temporary hash iterator or
* digest(DMA) mac ------------------------ output, mac callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
*/
uint32_t hmac_md5_dma(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint32_t *msg, uint32_t msg_bytes, uint32_t *tmp_iterator,
uint8_t *mac, HASH_CALLBACK callback)
{
return hmac_dma(HASH_MD5, key, sp_key_idx, key_bytes, msg, msg_bytes,
tmp_iterator, mac, callback);
}
#endif
#endif

View File

@@ -0,0 +1,154 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <hmac_sha1.h>
#ifdef SUPPORT_HASH_SHA1
/* function: init hmac-sha1
* parameters:
* ctx ------------------------ input, HMAC_SHA1_CTX context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of key, it could be 0
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t hmac_sha1_init(HMAC_SHA1_CTX *ctx, uint8_t *key, uint16_t sp_key_idx,
uint32_t key_bytes)
{
return hmac_init(ctx, HASH_SHA1, key, sp_key_idx, key_bytes);
}
/* function: hmac-sha1 update message
* parameters:
* ctx ------------------------ input, HMAC_SHA1_CTX context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sha1_update(HMAC_SHA1_CTX *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hmac_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the mac
* parameters:
* ctx ------------------------ input, HMAC_CTX context pointer
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the ctx is valid and initialized
* 2. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sha1_final(HMAC_SHA1_CTX *ctx, uint8_t *mac)
{
return hmac_final(ctx, mac);
}
/* function: input key and whole message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of the key
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sha1(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint8_t *msg, uint32_t msg_bytes, uint8_t *mac)
{
return hmac(HASH_SHA1, key, sp_key_idx, key_bytes, msg, msg_bytes, mac);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma hmac-sha1
* parameters:
* ctx ------------------------ input, HMAC_SHA1_DMA_CTX context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t hmac_sha1_dma_init(HMAC_SHA1_DMA_CTX *ctx, const uint8_t *key,
uint16_t sp_key_idx, uint32_t key_bytes,
HASH_CALLBACK callback)
{
return hmac_dma_init(ctx, HASH_SHA1, key, sp_key_idx, key_bytes, callback);
}
/* function: dma hmac-sha1 update message
* parameters:
* ctx ------------------------ input, HMAC_SHA1_DMA_CTX context pointer
* msg ------------------------ input, message
* msg_words ------------------ input, word length of the input message,
* must be a multiple of block word length of SHA1(16) tmp_iterator
* --------------- output, temporary hash iterator return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t hmac_sha1_dma_update_blocks(HMAC_SHA1_DMA_CTX *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *tmp_iterator)
{
return hmac_dma_update_blocks(ctx, msg, msg_words, tmp_iterator);
}
/* function: dma hmac-sha1 message update done, get the mac
* parameters:
* ctx ------------------------ input, HMAC_SHA1_DMA_CTX context pointer
* remainder_msg -------------- input, message
* remainder_bytes ------------ input, byte length of the last message, must
* be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* SHA1(64) tmp_iterator --------------- output, temporary hash iterator mac
* ------------------------ output, mac return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sha1_dma_final(HMAC_SHA1_DMA_CTX *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *tmp_iterator,
uint8_t *mac)
{
return hmac_dma_final(ctx, remainder_msg, remainder_bytes, tmp_iterator,
mac);
}
/* function: dma hmac-sha1 input key and message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* tmp_iterator --------------- output, for temporary hash iterator or
* digest(DMA) mac ------------------------ output, mac callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
*/
uint32_t hmac_sha1_dma(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint32_t *msg, uint32_t msg_bytes,
uint32_t *tmp_iterator, uint8_t *mac,
HASH_CALLBACK callback)
{
return hmac_dma(HASH_SHA1, key, sp_key_idx, key_bytes, msg, msg_bytes,
tmp_iterator, mac, callback);
}
#endif
#endif

View File

@@ -0,0 +1,157 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <hmac_sha224.h>
#ifdef SUPPORT_HASH_SHA224
/* function: init hmac-sha224
* parameters:
* ctx ------------------------ input, HMAC_SHA224_CTX context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of key, it could be 0
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t hmac_sha224_init(HMAC_SHA224_CTX *ctx, uint8_t *key,
uint16_t sp_key_idx, uint32_t key_bytes)
{
return hmac_init(ctx, HASH_SHA224, key, sp_key_idx, key_bytes);
}
/* function: hmac-sha224 update message
* parameters:
* ctx ------------------------ input, HMAC_SHA224_CTX context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sha224_update(HMAC_SHA224_CTX *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hmac_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_ctx_t context pointer
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the ctx is valid and initialized
* 2. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sha224_final(HMAC_SHA224_CTX *ctx, uint8_t *mac)
{
return hmac_final(ctx, mac);
}
/* function: input key and whole message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of the key
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sha224(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint8_t *msg, uint32_t msg_bytes, uint8_t *mac)
{
return hmac(HASH_SHA224, key, sp_key_idx, key_bytes, msg, msg_bytes, mac);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma hmac-sha224
* parameters:
* ctx ------------------------ input, HMAC_SHA224_DMA_CTX context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t hmac_sha224_dma_init(HMAC_SHA224_DMA_CTX *ctx, const uint8_t *key,
uint16_t sp_key_idx, uint32_t key_bytes,
HASH_CALLBACK callback)
{
return hmac_dma_init(ctx, HASH_SHA224, key, sp_key_idx, key_bytes,
callback);
}
/* function: dma hmac-sha224 update message
* parameters:
* ctx ------------------------ input, HMAC_SHA224_DMA_CTX context pointer
* msg ------------------------ input, message
* msg_words ------------------ input, word length of the input message,
* must be multiple of block word length of SHA224(16) tmp_iterator
* --------------- output, temporary hash iterator return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t hmac_sha224_dma_update_blocks(HMAC_SHA224_DMA_CTX *ctx, uint32_t *msg,
uint32_t msg_words,
uint32_t *tmp_iterator)
{
return hmac_dma_update_blocks(ctx, msg, msg_words, tmp_iterator);
}
/* function: dma hmac-sha224 message update done, get the mac
* parameters:
* ctx ------------------------ input, HMAC_SHA224_DMA_CTX context pointer
* remainder_msg -------------- input, message
* remainder_bytes ------------ input, byte length of the last message, must
* be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* SHA224(64) tmp_iterator --------------- output, temporary hash iterator mac
* ------------------------ output, mac return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sha224_dma_final(HMAC_SHA224_DMA_CTX *ctx,
uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *tmp_iterator,
uint8_t *mac)
{
return hmac_dma_final(ctx, remainder_msg, remainder_bytes, tmp_iterator,
mac);
}
/* function: dma hmac-sha224 input key and message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* tmp_iterator --------------- output, for temporary hash iterator or
* digest(DMA) mac ------------------------ output, mac callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
*/
uint32_t hmac_sha224_dma(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint32_t *msg, uint32_t msg_bytes,
uint32_t *tmp_iterator, uint8_t *mac,
HASH_CALLBACK callback)
{
return hmac_dma(HASH_SHA224, key, sp_key_idx, key_bytes, msg, msg_bytes,
tmp_iterator, mac, callback);
}
#endif
#endif

View File

@@ -0,0 +1,156 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <hmac_sha256.h>
#ifdef SUPPORT_HASH_SHA256
/* function: init hmac-sha256
* parameters:
* ctx ------------------------ input, HMAC_SHA256_CTX context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of key, it could be 0
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t hmac_sha256_init(HMAC_SHA256_CTX *ctx, uint8_t *key,
uint16_t sp_key_idx, uint32_t key_bytes)
{
return hmac_init(ctx, HASH_SHA256, key, sp_key_idx, key_bytes);
}
/* function: hmac-sha256 update message
* parameters:
* ctx ------------------------ input, HMAC_SHA256_CTX context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sha256_update(HMAC_SHA256_CTX *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hmac_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_ctx_t context pointer
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the ctx is valid and initialized
* 2. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sha256_final(HMAC_SHA256_CTX *ctx, uint8_t *mac)
{
return hmac_final(ctx, mac);
}
/* function: input key and whole message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of the key
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sha256(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint8_t *msg, uint32_t msg_bytes, uint8_t *mac)
{
return hmac(HASH_SHA256, key, sp_key_idx, key_bytes, msg, msg_bytes, mac);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma hmac-sha256
* parameters:
* ctx ------------------------ input, HMAC_SHA256_DMA_CTX context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t hmac_sha256_dma_init(HMAC_SHA256_DMA_CTX *ctx, const uint8_t *key,
uint16_t sp_key_idx, uint32_t key_bytes,
HASH_CALLBACK callback)
{
return hmac_dma_init(ctx, HASH_SHA256, key, sp_key_idx, key_bytes,
callback);
}
/* function: dma hmac-sha256 update message
* parameters:
* ctx ------------------------ input, HMAC_SHA256_DMA_CTX context pointer
* msg ------------------------ input, message
* msg_words ------------------ input, word length of the input message,
* must be multiple of block word length of SHA256(16) tmp_iterator
* --------------- output, temporary hash iterator return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t hmac_sha256_dma_update_blocks(HMAC_SHA256_DMA_CTX *ctx, uint32_t *msg,
uint32_t msg_words,
uint32_t *tmp_iterator)
{
return hmac_dma_update_blocks(ctx, msg, msg_words, tmp_iterator);
}
/* function: dma hmac-sha256 message update done, get the mac
* parameters:
* ctx ------------------------ input, HMAC_SHA256_DMA_CTX context pointer
* remainder_msg -------------- input, message
* remainder_bytes ------------ input, byte length of the last message, must
* be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* SHA256(64) tmp_iterator --------------- output, temporary hash iterator mac
* ------------------------ output, mac return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sha256_dma_final(HMAC_SHA256_DMA_CTX *ctx,
uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *tmp_iterator,
uint8_t *mac)
{
return hmac_dma_final(ctx, remainder_msg, remainder_bytes, tmp_iterator,
mac);
}
/* function: dma hmac-sha256 input key and message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* tmp_iterator --------------- output, for temporary hash iterator or
* digest(DMA) mac ------------------------ output, mac callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
*/
uint32_t hmac_sha256_dma(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint32_t *msg, uint32_t msg_bytes,
uint32_t *tmp_iterator, uint8_t *mac,
HASH_CALLBACK callback)
{
return hmac_dma(HASH_SHA256, key, sp_key_idx, key_bytes, msg, msg_bytes,
tmp_iterator, mac, callback);
}
#endif
#endif

View File

@@ -0,0 +1,157 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <hmac_sha384.h>
#ifdef SUPPORT_HASH_SHA384
/* function: init hmac-sha384
* parameters:
* ctx ------------------------ input, hmac_sha384_ctx_t context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of key, it could be 0
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t hmac_sha384_init(hmac_sha384_ctx_t *ctx, uint8_t *key,
uint16_t sp_key_idx, uint32_t key_bytes)
{
return hmac_init(ctx, HASH_SHA384, key, sp_key_idx, key_bytes);
}
/* function: hmac-sha384 update message
* parameters:
* ctx ------------------------ input, hmac_sha384_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sha384_update(hmac_sha384_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hmac_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_ctx_t context pointer
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the ctx is valid and initialized
* 2. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sha384_final(hmac_sha384_ctx_t *ctx, uint8_t *mac)
{
return hmac_final(ctx, mac);
}
/* function: input key and whole message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of the key
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sha384(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint8_t *msg, uint32_t msg_bytes, uint8_t *mac)
{
return hmac(HASH_SHA384, key, sp_key_idx, key_bytes, msg, msg_bytes, mac);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma hmac-sha384
* parameters:
* ctx ------------------------ input, hmac_sha384_dma_ctx_t context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t hmac_sha384_dma_init(hmac_sha384_dma_ctx_t *ctx, const uint8_t *key,
uint16_t sp_key_idx, uint32_t key_bytes,
HASH_CALLBACK callback)
{
return hmac_dma_init(ctx, HASH_SHA384, key, sp_key_idx, key_bytes,
callback);
}
/* function: dma hmac-sha384 update message
* parameters:
* ctx ------------------------ input, hmac_sha384_dma_ctx_t context pointer
* msg ------------------------ input, message
* msg_words ------------------ input, word length of the input message,
* must be multiple of block word length of SHA384(32) tmp_iterator
* --------------- output, temporary hash iterator return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t hmac_sha384_dma_update_blocks(hmac_sha384_dma_ctx_t *ctx,
uint32_t *msg, uint32_t msg_words,
uint32_t *tmp_iterator)
{
return hmac_dma_update_blocks(ctx, msg, msg_words, tmp_iterator);
}
/* function: dma hmac-sha384 message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_sha384_dma_ctx_t context pointer
* remainder_msg -------------- input, message
* remainder_bytes ------------ input, byte length of the last message, must
* be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* SHA384(128) tmp_iterator --------------- output, temporary hash iterator mac
* ------------------------ output, mac return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sha384_dma_final(hmac_sha384_dma_ctx_t *ctx,
uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *tmp_iterator,
uint8_t *mac)
{
return hmac_dma_final(ctx, remainder_msg, remainder_bytes, tmp_iterator,
mac);
}
/* function: dma hmac-sha384 input key and message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* tmp_iterator --------------- output, for temporary hash iterator or
* digest(DMA) mac ------------------------ output, mac callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
*/
uint32_t hmac_sha384_dma(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint32_t *msg, uint32_t msg_bytes,
uint32_t *tmp_iterator, uint8_t *mac,
HASH_CALLBACK callback)
{
return hmac_dma(HASH_SHA384, key, sp_key_idx, key_bytes, msg, msg_bytes,
tmp_iterator, mac, callback);
}
#endif
#endif

View File

@@ -0,0 +1,157 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <hmac_sha512.h>
#ifdef SUPPORT_HASH_SHA512
/* function: init hmac-sha512
* parameters:
* ctx ------------------------ input, hmac_sha512_ctx_t context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of key, it could be 0
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t hmac_sha512_init(hmac_sha512_ctx_t *ctx, uint8_t *key,
uint16_t sp_key_idx, uint32_t key_bytes)
{
return hmac_init(ctx, HASH_SHA512, key, sp_key_idx, key_bytes);
}
/* function: hmac-sha512 update message
* parameters:
* ctx ------------------------ input, hmac_sha512_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sha512_update(hmac_sha512_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hmac_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_ctx_t context pointer
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the ctx is valid and initialized
* 2. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sha512_final(hmac_sha512_ctx_t *ctx, uint8_t *mac)
{
return hmac_final(ctx, mac);
}
/* function: input key and whole message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of the key
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sha512(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint8_t *msg, uint32_t msg_bytes, uint8_t *mac)
{
return hmac(HASH_SHA512, key, sp_key_idx, key_bytes, msg, msg_bytes, mac);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma hmac-sha512
* parameters:
* ctx ------------------------ input, hmac_sha512_dma_ctx_t context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t hmac_sha512_dma_init(hmac_sha512_dma_ctx_t *ctx, const uint8_t *key,
uint16_t sp_key_idx, uint32_t key_bytes,
HASH_CALLBACK callback)
{
return hmac_dma_init(ctx, HASH_SHA512, key, sp_key_idx, key_bytes,
callback);
}
/* function: dma hmac-sha512 update message
* parameters:
* ctx ------------------------ input, hmac_sha512_dma_ctx_t context pointer
* msg ------------------------ input, message
* msg_words ------------------ input, word length of the input message,
* must be multiple of block word length of SHA512(32) tmp_iterator
* --------------- output, temporary hash iterator return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t hmac_sha512_dma_update_blocks(hmac_sha512_dma_ctx_t *ctx,
uint32_t *msg, uint32_t msg_words,
uint32_t *tmp_iterator)
{
return hmac_dma_update_blocks(ctx, msg, msg_words, tmp_iterator);
}
/* function: dma hmac-sha512 message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_sha512_dma_ctx_t context pointer
* remainder_msg -------------- input, message
* remainder_bytes ------------ input, byte length of the last message, must
* be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* SHA512(128) tmp_iterator --------------- output, temporary hash iterator mac
* ------------------------ output, mac return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sha512_dma_final(hmac_sha512_dma_ctx_t *ctx,
uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *tmp_iterator,
uint8_t *mac)
{
return hmac_dma_final(ctx, remainder_msg, remainder_bytes, tmp_iterator,
mac);
}
/* function: dma hmac-sha512 input key and message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* tmp_iterator --------------- output, for temporary hash iterator or
* digest(DMA) mac ------------------------ output, mac callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
*/
uint32_t hmac_sha512_dma(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint32_t *msg, uint32_t msg_bytes,
uint32_t *tmp_iterator, uint8_t *mac,
HASH_CALLBACK callback)
{
return hmac_dma(HASH_SHA512, key, sp_key_idx, key_bytes, msg, msg_bytes,
tmp_iterator, mac, callback);
}
#endif
#endif

View File

@@ -0,0 +1,156 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <hmac_sha512_224.h>
#ifdef SUPPORT_HASH_SHA512_224
/* function: init hmac-sha512_224
* parameters:
* ctx ------------------------ input, hmac_sha512_224_ctx_t context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of key, it could be 0
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t hmac_sha512_224_init(hmac_sha512_224_ctx_t *ctx, uint8_t *key,
uint16_t sp_key_idx, uint32_t key_bytes)
{
return hmac_init(ctx, HASH_SHA512_224, key, sp_key_idx, key_bytes);
}
/* function: hmac-sha512_224 update message
* parameters:
* ctx ------------------------ input, hmac_sha512_224_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sha512_224_update(hmac_sha512_224_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hmac_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_ctx_t context pointer
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the ctx is valid and initialized
* 2. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sha512_224_final(hmac_sha512_224_ctx_t *ctx, uint8_t *mac)
{
return hmac_final(ctx, mac);
}
/* function: input key and whole message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of the key
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sha512_224(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint8_t *msg, uint32_t msg_bytes, uint8_t *mac)
{
return hmac(HASH_SHA512_224, key, sp_key_idx, key_bytes, msg, msg_bytes,
mac);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma hmac-sha512_224
* parameters:
* ctx ------------------------ input, hmac_sha512_224_dma_ctx_t context
* pointer key ------------------------ input, key sp_key_idx -----------------
* input, index of secure port key key_bytes ------------------ input, key byte
* length callback ------------------- callback function pointer return:
* HASH_SUCCESS(success), other(error) caution:
*/
uint32_t hmac_sha512_224_dma_init(hmac_sha512_224_dma_ctx_t *ctx,
const uint8_t *key, uint16_t sp_key_idx,
uint32_t key_bytes, HASH_CALLBACK callback)
{
return hmac_dma_init(ctx, HASH_SHA512_224, key, sp_key_idx, key_bytes,
callback);
}
/* function: dma hmac-sha512_224 update message
* parameters:
* ctx ------------------------ input, hmac_sha512_224_dma_ctx_t context
* pointer msg ------------------------ input, message msg_words
* ------------------ input, word length of the input message, must be multiple
* of block word length of SHA512_224(32) tmp_iterator --------------- output,
* temporary hash iterator return: HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t hmac_sha512_224_dma_update_blocks(hmac_sha512_224_dma_ctx_t *ctx,
uint32_t *msg, uint32_t msg_words,
uint32_t *tmp_iterator)
{
return hmac_dma_update_blocks(ctx, msg, msg_words, tmp_iterator);
}
/* function: dma hmac-sha512_224 message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_sha512_224_dma_ctx_t context
* pointer remainder_msg -------------- input, message remainder_bytes
* ------------ input, byte length of the last message, must be in [0,
* BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* SHA512_224(128) tmp_iterator --------------- output, temporary hash iterator
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sha512_224_dma_final(hmac_sha512_224_dma_ctx_t *ctx,
uint32_t *remainder_msg,
uint32_t remainder_bytes,
uint32_t *tmp_iterator, uint8_t *mac)
{
return hmac_dma_final(ctx, remainder_msg, remainder_bytes, tmp_iterator,
mac);
}
/* function: dma hmac-sha512_224 input key and message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* tmp_iterator --------------- output, for temporary hash iterator or
* digest(DMA) mac ------------------------ output, mac callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
*/
uint32_t hmac_sha512_224_dma(uint8_t *key, uint16_t sp_key_idx,
uint32_t key_bytes, uint32_t *msg,
uint32_t msg_bytes, uint32_t *tmp_iterator,
uint8_t *mac, HASH_CALLBACK callback)
{
return hmac_dma(HASH_SHA512_224, key, sp_key_idx, key_bytes, msg, msg_bytes,
tmp_iterator, mac, callback);
}
#endif
#endif

View File

@@ -0,0 +1,156 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <hmac_sha512_256.h>
#ifdef SUPPORT_HASH_SHA512_256
/* function: init hmac-sha512_256
* parameters:
* ctx ------------------------ input, hmac_sha512_256_ctx_t context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of key, it could be 0
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t hmac_sha512_256_init(hmac_sha512_256_ctx_t *ctx, uint8_t *key,
uint16_t sp_key_idx, uint32_t key_bytes)
{
return hmac_init(ctx, HASH_SHA512_256, key, sp_key_idx, key_bytes);
}
/* function: hmac-sha512_256 update message
* parameters:
* ctx ------------------------ input, hmac_sha512_256_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sha512_256_update(hmac_sha512_256_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hmac_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_ctx_t context pointer
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the ctx is valid and initialized
* 2. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sha512_256_final(hmac_sha512_256_ctx_t *ctx, uint8_t *mac)
{
return hmac_final(ctx, mac);
}
/* function: input key and whole message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of the key
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sha512_256(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint8_t *msg, uint32_t msg_bytes, uint8_t *mac)
{
return hmac(HASH_SHA512_256, key, sp_key_idx, key_bytes, msg, msg_bytes,
mac);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma hmac-sha512_256
* parameters:
* ctx ------------------------ input, hmac_sha512_256_dma_ctx_t context
* pointer key ------------------------ input, key sp_key_idx -----------------
* input, index of secure port key key_bytes ------------------ input, key byte
* length callback ------------------- callback function pointer return:
* HASH_SUCCESS(success), other(error) caution:
*/
uint32_t hmac_sha512_256_dma_init(hmac_sha512_256_dma_ctx_t *ctx,
const uint8_t *key, uint16_t sp_key_idx,
uint32_t key_bytes, HASH_CALLBACK callback)
{
return hmac_dma_init(ctx, HASH_SHA512_256, key, sp_key_idx, key_bytes,
callback);
}
/* function: dma hmac-sha512_256 update message
* parameters:
* ctx ------------------------ input, hmac_sha512_256_dma_ctx_t context
* pointer msg ------------------------ input, message msg_words
* ------------------ input, word length of the input message, must be multiple
* of block word length of SHA512_256(32) tmp_iterator --------------- output,
* temporary hash iterator return: HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t hmac_sha512_256_dma_update_blocks(hmac_sha512_256_dma_ctx_t *ctx,
uint32_t *msg, uint32_t msg_words,
uint32_t *tmp_iterator)
{
return hmac_dma_update_blocks(ctx, msg, msg_words, tmp_iterator);
}
/* function: dma hmac-sha512_256 message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_sha512_256_dma_ctx_t context
* pointer remainder_msg -------------- input, message remainder_bytes
* ------------ input, byte length of the last message, must be in [0,
* BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* SHA512_256(128) tmp_iterator --------------- output, temporary hash iterator
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sha512_256_dma_final(hmac_sha512_256_dma_ctx_t *ctx,
uint32_t *remainder_msg,
uint32_t remainder_bytes,
uint32_t *tmp_iterator, uint8_t *mac)
{
return hmac_dma_final(ctx, remainder_msg, remainder_bytes, tmp_iterator,
mac);
}
/* function: dma hmac-sha512_256 input key and message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* tmp_iterator --------------- output, for temporary hash iterator or
* digest(DMA) mac ------------------------ output, mac callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
*/
uint32_t hmac_sha512_256_dma(uint8_t *key, uint16_t sp_key_idx,
uint32_t key_bytes, uint32_t *msg,
uint32_t msg_bytes, uint32_t *tmp_iterator,
uint8_t *mac, HASH_CALLBACK callback)
{
return hmac_dma(HASH_SHA512_256, key, sp_key_idx, key_bytes, msg, msg_bytes,
tmp_iterator, mac, callback);
}
#endif
#endif

View File

@@ -0,0 +1,153 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <hmac_sm3.h>
#ifdef SUPPORT_HASH_SM3
/* function: init hmac-sm3
* parameters:
* ctx ------------------------ input, hmac_sm3_ctx_t context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of key, it could be 0
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t hmac_sm3_init(hmac_sm3_ctx_t *ctx, uint8_t *key, uint16_t sp_key_idx,
uint32_t key_bytes)
{
return hmac_init(ctx, HASH_SM3, key, sp_key_idx, key_bytes);
}
/* function: hmac-sm3 update message
* parameters:
* ctx ------------------------ input, hmac_sm3_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sm3_update(hmac_sm3_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hmac_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_ctx_t context pointer
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the ctx is valid and initialized
* 2. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sm3_final(hmac_sm3_ctx_t *ctx, uint8_t *mac)
{
return hmac_final(ctx, mac);
}
/* function: input key and whole message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, byte length of the key
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* mac ------------------------ output, mac
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the mac buffer is sufficient
*/
uint32_t hmac_sm3(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint8_t *msg, uint32_t msg_bytes, uint8_t *mac)
{
return hmac(HASH_SM3, key, sp_key_idx, key_bytes, msg, msg_bytes, mac);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma hmac-sm3
* parameters:
* ctx ------------------------ input, hmac_sm3_dma_ctx_t context pointer
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t hmac_sm3_dma_init(hmac_sm3_dma_ctx_t *ctx, const uint8_t *key,
uint16_t sp_key_idx, uint32_t key_bytes,
HASH_CALLBACK callback)
{
return hmac_dma_init(ctx, HASH_SM3, key, sp_key_idx, key_bytes, callback);
}
/* function: dma hmac-sm3 update message
* parameters:
* ctx ------------------------ input, hmac_sm3_dma_ctx_t context pointer
* msg ------------------------ input, message
* msg_words ------------------ input, word length of the input message,
* must be multiple of block word length of SM3(16) tmp_iterator ---------------
* output, temporary hash iterator return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t hmac_sm3_dma_update_blocks(hmac_sm3_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *tmp_iterator)
{
return hmac_dma_update_blocks(ctx, msg, msg_words, tmp_iterator);
}
/* function: dma hmac-sm3 message update done, get the mac
* parameters:
* ctx ------------------------ input, hmac_sm3_dma_ctx_t context pointer
* remainder_msg -------------- input, message
* remainder_bytes ------------ input, byte length of the last message, must
* be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* SM3(64) tmp_iterator --------------- output, temporary hash iterator mac
* ------------------------ output, mac return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t hmac_sm3_dma_final(hmac_sm3_dma_ctx_t *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *tmp_iterator,
uint8_t *mac)
{
return hmac_dma_final(ctx, remainder_msg, remainder_bytes, tmp_iterator,
mac);
}
/* function: dma hmac-sm3 input key and message, get the mac
* parameters:
* key ------------------------ input, key
* sp_key_idx ----------------- input, index of secure port key
* key_bytes ------------------ input, key byte length
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* tmp_iterator --------------- output, for temporary hash iterator or
* digest(DMA) mac ------------------------ output, mac callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
*/
uint32_t hmac_sm3_dma(uint8_t *key, uint16_t sp_key_idx, uint32_t key_bytes,
uint32_t *msg, uint32_t msg_bytes, uint32_t *tmp_iterator,
uint8_t *mac, HASH_CALLBACK callback)
{
return hmac_dma(HASH_SM3, key, sp_key_idx, key_bytes, msg, msg_bytes,
tmp_iterator, mac, callback);
}
#endif
#endif

View File

@@ -0,0 +1,124 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <md5.h>
#ifdef SUPPORT_HASH_MD5
/* function: init md5
* parameters:
* ctx ------------------------ input, md5_ctx_t context pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t md5_init(md5_ctx_t *ctx) { return hash_init(ctx, HASH_MD5); }
/* function: md5 update message
* parameters:
* ctx ------------------------ input, md5_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t md5_update(md5_ctx_t *ctx, const uint8_t *msg, uint32_t msg_bytes)
{
return hash_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the md5 digest
* parameters:
* digest --------------------- output, md5 digest, 16 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t md5_final(md5_ctx_t *ctx, uint8_t *digest)
{
return hash_final(ctx, digest);
}
/* function: input whole message and get its md5 digest
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message, it
* could be 0 digest --------------------- output, md5 digest, 16 bytes return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t md5_(uint8_t *msg, uint32_t msg_bytes, uint8_t *digest)
{
return hash(HASH_MD5, msg, msg_bytes, digest);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma md5
* parameters:
* ctx ------------------------ input, md5_dma_ctx_t context pointer
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t md5_dma_init(md5_dma_ctx_t *ctx, HASH_CALLBACK callback)
{
return hash_dma_init(ctx, HASH_MD5, callback);
}
/* function: dma md5 update some message blocks
* parameters:
* ctx ------------------------ input, md5_dma_ctx_t context pointer
* msg ------------------------ input, message blocks
* msg_words ------------------ input, word length of the input message,
* must be a multiple of md5 block word length(16) iterator -------------------
* output, md5 temporary result return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t md5_dma_update_blocks(md5_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *iterator)
{
return hash_dma_update_blocks(ctx, msg, msg_words, iterator);
}
/* function: dma md5 final(input the remainder message and get the digest)
* parameters:
* ctx ------------------------ input, md5_dma_ctx_t context pointer
* remainder_msg -------------- input, remainder message
* remainder_bytes ------------ input, byte length of the remainder message,
* must be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* md5, it is 64. digest --------------------- output, md5 digest, 16 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t md5_dma_final(md5_dma_ctx_t *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *digest)
{
return hash_dma_final(ctx, remainder_msg, remainder_bytes, digest);
}
/* function: dma md5 digest calculate
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the message, it could
* be 0 digest --------------------- output, md5 digest, 16 bytes callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the four parameters are valid
*/
uint32_t md5_dma(uint32_t *msg, uint32_t msg_bytes, uint32_t *digest,
HASH_CALLBACK callback)
{
return hash_dma(HASH_MD5, msg, msg_bytes, digest, callback);
}
#endif
#endif

View File

@@ -0,0 +1,124 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <sha1.h>
#ifdef SUPPORT_HASH_SHA1
/* function: init sha1
* parameters:
* ctx ------------------------ input, sha1_ctx_t context pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t sha1_init(sha1_ctx_t *ctx) { return hash_init(ctx, HASH_SHA1); }
/* function: sha1 update message
* parameters:
* ctx ------------------------ input, sha1_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t sha1_update(sha1_ctx_t *ctx, const uint8_t *msg, uint32_t msg_bytes)
{
return hash_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the sha1 digest
* parameters:
* digest --------------------- output, sha1 digest, 20 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha1_final(sha1_ctx_t *ctx, uint8_t *digest)
{
return hash_final(ctx, digest);
}
/* function: input whole message and get its sha1 digest
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message, it
* could be 0 digest --------------------- output, sha1 digest, 20 bytes return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha1(uint8_t *msg, uint32_t msg_bytes, uint8_t *digest)
{
return hash(HASH_SHA1, msg, msg_bytes, digest);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma sha1
* parameters:
* ctx ------------------------ input, sha1_dma_ctx_t context pointer
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t sha1_dma_init(sha1_dma_ctx_t *ctx, HASH_CALLBACK callback)
{
return hash_dma_init(ctx, HASH_SHA1, callback);
}
/* function: dma sha1 update some message blocks
* parameters:
* ctx ------------------------ input, sha1_dma_ctx_t context pointer
* msg ------------------------ input, message blocks
* msg_words ------------------ input, word length of the input message,
* must be a multiple of sha1 block word length(16) iterator -------------------
* output, sha1 temporary result return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha1_dma_update_blocks(sha1_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *iterator)
{
return hash_dma_update_blocks(ctx, msg, msg_words, iterator);
}
/* function: dma sha1 final(input the remainder message and get the digest)
* parameters:
* ctx ------------------------ input, sha1_dma_ctx_t context pointer
* remainder_msg -------------- input, remainder message
* remainder_bytes ------------ input, byte length of the remainder message,
* must be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* sha1, it is 64. digest --------------------- output, sha1 digest, 20 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha1_dma_final(sha1_dma_ctx_t *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *digest)
{
return hash_dma_final(ctx, remainder_msg, remainder_bytes, digest);
}
/* function: dma sha1 digest calculate
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the message, it could
* be 0 digest --------------------- output, sha1 digest, 20 bytes callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the four parameters are valid
*/
uint32_t sha1_dma(uint32_t *msg, uint32_t msg_bytes, uint32_t *digest,
HASH_CALLBACK callback)
{
return hash_dma(HASH_SHA1, msg, msg_bytes, digest, callback);
}
#endif
#endif

View File

@@ -0,0 +1,125 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <sha224.h>
#ifdef SUPPORT_HASH_SHA224
/* function: init sha224
* parameters:
* ctx ------------------------ input, sha224_ctx_t context pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t sha224_init(sha224_ctx_t *ctx) { return hash_init(ctx, HASH_SHA224); }
/* function: sha224 update message
* parameters:
* ctx ------------------------ input, sha224_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t sha224_update(sha224_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hash_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the sha224 digest
* parameters:
* digest --------------------- output, sha224 digest, 28 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha224_final(sha224_ctx_t *ctx, uint8_t *digest)
{
return hash_final(ctx, digest);
}
/* function: input whole message and get its sha224 digest
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message, it
* could be 0 digest --------------------- output, sha224 digest, 28 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha224(uint8_t *msg, uint32_t msg_bytes, uint8_t *digest)
{
return hash(HASH_SHA224, msg, msg_bytes, digest);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma sha224
* parameters:
* ctx ------------------------ input, sha224_dma_ctx_t context pointer
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t sha224_dma_init(sha224_dma_ctx_t *ctx, HASH_CALLBACK callback)
{
return hash_dma_init(ctx, HASH_SHA224, callback);
}
/* function: dma sha224 update some message blocks
* parameters:
* ctx ------------------------ input, sha224_dma_ctx_t context pointer
* msg ------------------------ input, message blocks
* msg_words ------------------ input, word length of the input message,
* must be multiple of sha224 block word length(16) iterator -------------------
* output, sha224 temporary result return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha224_dma_update_blocks(sha224_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *iterator)
{
return hash_dma_update_blocks(ctx, msg, msg_words, iterator);
}
/* function: dma sha224 final(input the remainder message and get the digest)
* parameters:
* ctx ------------------------ input, sha224_dma_ctx_t context pointer
* remainder_msg -------------- input, remainder message
* remainder_bytes ------------ input, byte length of the remainder message,
* must be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* sha224, it is 64. digest --------------------- output, sha224 digest, 28
* bytes return: HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha224_dma_final(sha224_dma_ctx_t *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *digest)
{
return hash_dma_final(ctx, remainder_msg, remainder_bytes, digest);
}
/* function: dma sha224 digest calculate
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the message, it could
* be 0 digest --------------------- output, sha224 digest, 28 bytes callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the four parameters are valid
*/
uint32_t sha224_dma(uint32_t *msg, uint32_t msg_bytes, uint32_t *digest,
HASH_CALLBACK callback)
{
return hash_dma(HASH_SHA224, msg, msg_bytes, digest, callback);
}
#endif
#endif

View File

@@ -0,0 +1,125 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <sha256.h>
#ifdef SUPPORT_HASH_SHA256
/* function: init sha256
* parameters:
* ctx ------------------------ input, sha256_ctx_t context pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t sha256_init(sha256_ctx_t *ctx) { return hash_init(ctx, HASH_SHA256); }
/* function: sha256 update message
* parameters:
* ctx ------------------------ input, sha256_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t sha256_update(sha256_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hash_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the sha256 digest
* parameters:
* digest --------------------- output, sha256 digest, 32 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha256_final(sha256_ctx_t *ctx, uint8_t *digest)
{
return hash_final(ctx, digest);
}
/* function: input whole message and get its sha256 digest
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message, it
* could be 0 digest --------------------- output, sha256 digest, 32 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha256(uint8_t *msg, uint32_t msg_bytes, uint8_t *digest)
{
return hash(HASH_SHA256, msg, msg_bytes, digest);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma sha256
* parameters:
* ctx ------------------------ input, sha256_dma_ctx_t context pointer
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t sha256_dma_init(sha256_dma_ctx_t *ctx, HASH_CALLBACK callback)
{
return hash_dma_init(ctx, HASH_SHA256, callback);
}
/* function: dma sha256 update some message blocks
* parameters:
* ctx ------------------------ input, sha256_dma_ctx_t context pointer
* msg ------------------------ input, message blocks
* msg_words ------------------ input, word length of the input message,
* must be multiple of sha256 block word length(16) iterator -------------------
* output, sha256 temporary result return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha256_dma_update_blocks(sha256_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *iterator)
{
return hash_dma_update_blocks(ctx, msg, msg_words, iterator);
}
/* function: dma sha256 final(input the remainder message and get the digest)
* parameters:
* ctx ------------------------ input, sha256_dma_ctx_t context pointer
* remainder_msg -------------- input, remainder message
* remainder_bytes ------------ input, byte length of the remainder message,
* must be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* sha256, it is 64. digest --------------------- output, sha256 digest, 32
* bytes return: HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha256_dma_final(sha256_dma_ctx_t *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *digest)
{
return hash_dma_final(ctx, remainder_msg, remainder_bytes, digest);
}
/* function: dma sha256 digest calculate
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the message, it could
* be 0 digest --------------------- output, sha256 digest, 32 bytes callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the four parameters are valid
*/
uint32_t sha256_dma(uint32_t *msg, uint32_t msg_bytes, uint32_t *digest,
HASH_CALLBACK callback)
{
return hash_dma(HASH_SHA256, msg, msg_bytes, digest, callback);
}
#endif
#endif

View File

@@ -0,0 +1,125 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <sha384.h>
#ifdef SUPPORT_HASH_SHA384
/* function: init sha384
* parameters:
* ctx ------------------------ input, sha384_ctx_t context pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t sha384_init(sha384_ctx_t *ctx) { return hash_init(ctx, HASH_SHA384); }
/* function: sha384 update message
* parameters:
* ctx ------------------------ input, sha384_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t sha384_update(sha384_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hash_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the sha384 digest
* parameters:
* digest --------------------- output, sha384 digest, 48 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha384_final(sha384_ctx_t *ctx, uint8_t *digest)
{
return hash_final(ctx, digest);
}
/* function: input whole message and get its sha384 digest
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message, it
* could be 0 digest --------------------- output, sha384 digest, 48 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha384(uint8_t *msg, uint32_t msg_bytes, uint8_t *digest)
{
return hash(HASH_SHA384, msg, msg_bytes, digest);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma sha384
* parameters:
* ctx ------------------------ input, sha384_dma_ctx_t context pointer
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t sha384_dma_init(sha384_dma_ctx_t *ctx, HASH_CALLBACK callback)
{
return hash_dma_init(ctx, HASH_SHA384, callback);
}
/* function: dma sha384 update some message blocks
* parameters:
* ctx ------------------------ input, sha384_dma_ctx_t context pointer
* msg ------------------------ input, message blocks
* msg_words ------------------ input, word length of the input message,
* must be multiple of sha384 block word length(32) iterator -------------------
* output, sha384 temporary result return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha384_dma_update_blocks(sha384_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *iterator)
{
return hash_dma_update_blocks(ctx, msg, msg_words, iterator);
}
/* function: dma sha384 final(input the remainder message and get the digest)
* parameters:
* ctx ------------------------ input, sha384_dma_ctx_t context pointer
* remainder_msg -------------- input, remainder message
* remainder_bytes ------------ input, byte length of the remainder message,
* must be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* sha384, it is 128. digest --------------------- output, sha384 digest, 48
* bytes return: HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha384_dma_final(sha384_dma_ctx_t *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *digest)
{
return hash_dma_final(ctx, remainder_msg, remainder_bytes, digest);
}
/* function: dma sha384 digest calculate
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the message, it could
* be 0 digest --------------------- output, sha384 digest, 48 bytes callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the four parameters are valid
*/
uint32_t sha384_dma(uint32_t *msg, uint32_t msg_bytes, uint32_t *digest,
HASH_CALLBACK callback)
{
return hash_dma(HASH_SHA384, msg, msg_bytes, digest, callback);
}
#endif
#endif

View File

@@ -0,0 +1,128 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <sha3_224.h>
#ifdef SUPPORT_HASH_SHA3_224
/* function: init sha3_224
* parameters:
* ctx ------------------------ input, sha3_224_ctx_t context pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t sha3_224_init(sha3_224_ctx_t *ctx)
{
return hash_init(ctx, HASH_SHA3_224);
}
/* function: sha3_224 update message
* parameters:
* ctx ------------------------ input, sha3_224_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t sha3_224_update(sha3_224_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hash_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the sha3_224 digest
* parameters:
* digest --------------------- output, sha3_224 digest, 28 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha3_224_final(sha3_224_ctx_t *ctx, uint8_t *digest)
{
return hash_final(ctx, digest);
}
/* function: input whole message and get its sha3_224 digest
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message, it
* could be 0 digest --------------------- output, sha3_224 digest, 28 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha3_224(uint8_t *msg, uint32_t msg_bytes, uint8_t *digest)
{
return hash(HASH_SHA3_224, msg, msg_bytes, digest);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma sha3_224
* parameters:
* ctx ------------------------ input, sha3_224_dma_ctx_t context pointer
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t sha3_224_dma_init(sha3_224_dma_ctx_t *ctx, HASH_CALLBACK callback)
{
return hash_dma_init(ctx, HASH_SHA3_224, callback);
}
/* function: dma sha3_224 update some message blocks
* parameters:
* ctx ------------------------ input, sha3_224_dma_ctx_t context pointer
* msg ------------------------ input, message blocks
* msg_words ------------------ input, word length of the input message,
* must be multiple of sha3_224 block word length(36) iterator
* ------------------- output, sha3_224 temporary result return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha3_224_dma_update_blocks(sha3_224_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *iterator)
{
return hash_dma_update_blocks(ctx, msg, msg_words, iterator);
}
/* function: dma sha3_224 final(input the remainder message and get the digest)
* parameters:
* ctx ------------------------ input, sha3_224_dma_ctx_t context pointer
* remainder_msg -------------- input, remainder message
* remainder_bytes ------------ input, byte length of the remainder message,
* must be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* sha3_224, it is 144. digest --------------------- output, sha3_224 digest, 28
* bytes return: HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha3_224_dma_final(sha3_224_dma_ctx_t *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *digest)
{
return hash_dma_final(ctx, remainder_msg, remainder_bytes, digest);
}
/* function: dma sha3_224 digest calculate
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the message, it could
* be 0 digest --------------------- output, sha3_224 digest, 28 bytes callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the four parameters are valid
*/
uint32_t sha3_224_dma(uint32_t *msg, uint32_t msg_bytes, uint32_t *digest,
HASH_CALLBACK callback)
{
return hash_dma(HASH_SHA3_224, msg, msg_bytes, digest, callback);
}
#endif
#endif

View File

@@ -0,0 +1,128 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <sha3_256.h>
#ifdef SUPPORT_HASH_SHA3_256
/* function: init sha3_256
* parameters:
* ctx ------------------------ input, sha3_256_ctx_t context pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t sha3_256_init(sha3_256_ctx_t *ctx)
{
return hash_init(ctx, HASH_SHA3_256);
}
/* function: sha3_256 update message
* parameters:
* ctx ------------------------ input, sha3_256_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t sha3_256_update(sha3_256_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hash_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the sha3_256 digest
* parameters:
* digest --------------------- output, sha3_256 digest, 32 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha3_256_final(sha3_256_ctx_t *ctx, uint8_t *digest)
{
return hash_final(ctx, digest);
}
/* function: input whole message and get its sha3_256 digest
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message, it
* could be 0 digest --------------------- output, sha3_256 digest, 32 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha3_256(uint8_t *msg, uint32_t msg_bytes, uint8_t *digest)
{
return hash(HASH_SHA3_256, msg, msg_bytes, digest);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma sha3_256
* parameters:
* ctx ------------------------ input, sha3_256_dma_ctx_t context pointer
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t sha3_256_dma_init(sha3_256_dma_ctx_t *ctx, HASH_CALLBACK callback)
{
return hash_dma_init(ctx, HASH_SHA3_256, callback);
}
/* function: dma sha3_256 update some message blocks
* parameters:
* ctx ------------------------ input, sha3_256_dma_ctx_t context pointer
* msg ------------------------ input, message blocks
* msg_words ------------------ input, word length of the input message,
* must be multiple of sha3_256 block word length(34) iterator
* ------------------- output, sha3_256 temporary result return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha3_256_dma_update_blocks(sha3_256_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *iterator)
{
return hash_dma_update_blocks(ctx, msg, msg_words, iterator);
}
/* function: dma sha3_256 final(input the remainder message and get the digest)
* parameters:
* ctx ------------------------ input, sha3_256_dma_ctx_t context pointer
* remainder_msg -------------- input, remainder message
* remainder_bytes ------------ input, byte length of the remainder message,
* must be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* sha3_256, it is 136. digest --------------------- output, sha3_256 digest, 32
* bytes return: HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha3_256_dma_final(sha3_256_dma_ctx_t *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *digest)
{
return hash_dma_final(ctx, remainder_msg, remainder_bytes, digest);
}
/* function: dma sha3_256 digest calculate
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the message, it could
* be 0 digest --------------------- output, sha3_256 digest, 32 bytes callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the four parameters are valid
*/
uint32_t sha3_256_dma(uint32_t *msg, uint32_t msg_bytes, uint32_t *digest,
HASH_CALLBACK callback)
{
return hash_dma(HASH_SHA3_256, msg, msg_bytes, digest, callback);
}
#endif
#endif

View File

@@ -0,0 +1,128 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <sha3_384.h>
#ifdef SUPPORT_HASH_SHA3_384
/* function: init sha3_384
* parameters:
* ctx ------------------------ input, sha3_384_ctx_t context pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t sha3_384_init(sha3_384_ctx_t *ctx)
{
return hash_init(ctx, HASH_SHA3_384);
}
/* function: sha3_384 update message
* parameters:
* ctx ------------------------ input, sha3_384_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t sha3_384_update(sha3_384_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hash_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the sha3_384 digest
* parameters:
* digest --------------------- output, sha3_384 digest, 48 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha3_384_final(sha3_384_ctx_t *ctx, uint8_t *digest)
{
return hash_final(ctx, digest);
}
/* function: input whole message and get its sha3_384 digest
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message, it
* could be 0 digest --------------------- output, sha3_384 digest, 48 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha3_384(uint8_t *msg, uint32_t msg_bytes, uint8_t *digest)
{
return hash(HASH_SHA3_384, msg, msg_bytes, digest);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma sha3_384
* parameters:
* ctx ------------------------ input, sha3_384_dma_ctx_t context pointer
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t sha3_384_dma_init(sha3_384_dma_ctx_t *ctx, HASH_CALLBACK callback)
{
return hash_dma_init(ctx, HASH_SHA3_384, callback);
}
/* function: dma sha3_384 update some message blocks
* parameters:
* ctx ------------------------ input, sha3_384_dma_ctx_t context pointer
* msg ------------------------ input, message blocks
* msg_words ------------------ input, word length of the input message,
* must be multiple of sha3_384 block word length(26) iterator
* ------------------- output, sha3_384 temporary result return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha3_384_dma_update_blocks(sha3_384_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *iterator)
{
return hash_dma_update_blocks(ctx, msg, msg_words, iterator);
}
/* function: dma sha3_384 final(input the remainder message and get the digest)
* parameters:
* ctx ------------------------ input, sha3_384_dma_ctx_t context pointer
* remainder_msg -------------- input, remainder message
* remainder_bytes ------------ input, byte length of the remainder message,
* must be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* sha3_384, it is 104. digest --------------------- output, sha3_384 digest, 48
* bytes return: HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha3_384_dma_final(sha3_384_dma_ctx_t *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *digest)
{
return hash_dma_final(ctx, remainder_msg, remainder_bytes, digest);
}
/* function: dma sha3_384 digest calculate
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the message, it could
* be 0 digest --------------------- output, sha3_384 digest, 48 bytes callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the four parameters are valid
*/
uint32_t sha3_384_dma(uint32_t *msg, uint32_t msg_bytes, uint32_t *digest,
HASH_CALLBACK callback)
{
return hash_dma(HASH_SHA3_384, msg, msg_bytes, digest, callback);
}
#endif
#endif

View File

@@ -0,0 +1,128 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <sha3_512.h>
#ifdef SUPPORT_HASH_SHA3_512
/* function: init sha3_512
* parameters:
* ctx ------------------------ input, sha3_512_ctx_t context pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t sha3_512_init(sha3_512_ctx_t *ctx)
{
return hash_init(ctx, HASH_SHA3_512);
}
/* function: sha3_512 update message
* parameters:
* ctx ------------------------ input, sha3_512_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t sha3_512_update(sha3_512_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hash_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the sha3_512 digest
* parameters:
* digest --------------------- output, sha3_512 digest, 64 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha3_512_final(sha3_512_ctx_t *ctx, uint8_t *digest)
{
return hash_final(ctx, digest);
}
/* function: input whole message and get its sha3_512 digest
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message, it
* could be 0 digest --------------------- output, sha3_512 digest, 64 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha3_512(uint8_t *msg, uint32_t msg_bytes, uint8_t *digest)
{
return hash(HASH_SHA3_512, msg, msg_bytes, digest);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma sha3_512
* parameters:
* ctx ------------------------ input, sha3_512_dma_ctx_t context pointer
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t sha3_512_dma_init(sha3_512_dma_ctx_t *ctx, HASH_CALLBACK callback)
{
return hash_dma_init(ctx, HASH_SHA3_512, callback);
}
/* function: dma sha3_512 update some message blocks
* parameters:
* ctx ------------------------ input, sha3_512_dma_ctx_t context pointer
* msg ------------------------ input, message blocks
* msg_words ------------------ input, word length of the input message,
* must be multiple of sha3_512 block word length(18) iterator
* ------------------- output, sha3_512 temporary result return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha3_512_dma_update_blocks(sha3_512_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *iterator)
{
return hash_dma_update_blocks(ctx, msg, msg_words, iterator);
}
/* function: dma sha3_512 final(input the remainder message and get the digest)
* parameters:
* ctx ------------------------ input, sha3_512_dma_ctx_t context pointer
* remainder_msg -------------- input, remainder message
* remainder_bytes ------------ input, byte length of the remainder message,
* must be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* sha3_512, it is 72. digest --------------------- output, sha3_512 digest, 64
* bytes return: HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha3_512_dma_final(sha3_512_dma_ctx_t *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *digest)
{
return hash_dma_final(ctx, remainder_msg, remainder_bytes, digest);
}
/* function: dma sha3_512 digest calculate
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the message, it could
* be 0 digest --------------------- output, sha3_512 digest, 64 bytes callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the four parameters are valid
*/
uint32_t sha3_512_dma(uint32_t *msg, uint32_t msg_bytes, uint32_t *digest,
HASH_CALLBACK callback)
{
return hash_dma(HASH_SHA3_512, msg, msg_bytes, digest, callback);
}
#endif
#endif

View File

@@ -0,0 +1,125 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <sha512.h>
#ifdef SUPPORT_HASH_SHA512
/* function: init sha512
* parameters:
* ctx ------------------------ input, sha512_ctx_t context pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t sha512_init(sha512_ctx_t *ctx) { return hash_init(ctx, HASH_SHA512); }
/* function: sha512 update message
* parameters:
* ctx ------------------------ input, sha512_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t sha512_update(sha512_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hash_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the sha512 digest
* parameters:
* digest --------------------- output, sha512 digest, 64 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha512_final(sha512_ctx_t *ctx, uint8_t *digest)
{
return hash_final(ctx, digest);
}
/* function: input whole message and get its sha512 digest
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message, it
* could be 0 digest --------------------- output, sha512 digest, 64 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha512(uint8_t *msg, uint32_t msg_bytes, uint8_t *digest)
{
return hash(HASH_SHA512, msg, msg_bytes, digest);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma sha512
* parameters:
* ctx ------------------------ input, sha512_dma_ctx_t context pointer
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t sha512_dma_init(sha512_dma_ctx_t *ctx, HASH_CALLBACK callback)
{
return hash_dma_init(ctx, HASH_SHA512, callback);
}
/* function: dma sha512 update some message blocks
* parameters:
* ctx ------------------------ input, sha512_dma_ctx_t context pointer
* msg ------------------------ input, message blocks
* msg_words ------------------ input, word length of the input message,
* must be multiple of sha512 block word length(32) iterator -------------------
* output, sha512 temporary result return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha512_dma_update_blocks(sha512_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *iterator)
{
return hash_dma_update_blocks(ctx, msg, msg_words, iterator);
}
/* function: dma sha512 final(input the remainder message and get the digest)
* parameters:
* ctx ------------------------ input, sha512_dma_ctx_t context pointer
* remainder_msg -------------- input, remainder message
* remainder_bytes ------------ input, byte length of the remainder message,
* must be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* sha512, it is 128. digest --------------------- output, sha512 digest, 64
* bytes return: HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha512_dma_final(sha512_dma_ctx_t *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *digest)
{
return hash_dma_final(ctx, remainder_msg, remainder_bytes, digest);
}
/* function: dma sha512 digest calculate
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the message, it could
* be 0 digest --------------------- output, sha512 digest, 64 bytes callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the four parameters are valid
*/
uint32_t sha512_dma(uint32_t *msg, uint32_t msg_bytes, uint32_t *digest,
HASH_CALLBACK callback)
{
return hash_dma(HASH_SHA512, msg, msg_bytes, digest, callback);
}
#endif
#endif

View File

@@ -0,0 +1,129 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <sha512_224.h>
#ifdef SUPPORT_HASH_SHA512_224
/* function: init sha512_224
* parameters:
* ctx ------------------------ input, sha512_224_ctx_t context pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t sha512_224_init(sha512_224_ctx_t *ctx)
{
return hash_init(ctx, HASH_SHA512_224);
}
/* function: sha512_224 update message
* parameters:
* ctx ------------------------ input, sha512_224_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t sha512_224_update(sha512_224_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hash_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the sha512_224 digest
* parameters:
* digest --------------------- output, sha512_224 digest, 28 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha512_224_final(sha512_224_ctx_t *ctx, uint8_t *digest)
{
return hash_final(ctx, digest);
}
/* function: input whole message and get its sha512_224 digest
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message, it
* could be 0 digest --------------------- output, sha512_224 digest, 28 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha512_224(uint8_t *msg, uint32_t msg_bytes, uint8_t *digest)
{
return hash(HASH_SHA512_224, msg, msg_bytes, digest);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma sha512_224
* parameters:
* ctx ------------------------ input, sha512_224_dma_ctx_t context pointer
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t sha512_224_dma_init(sha512_224_dma_ctx_t *ctx, HASH_CALLBACK callback)
{
return hash_dma_init(ctx, HASH_SHA512_224, callback);
}
/* function: dma sha512_224 update some message blocks
* parameters:
* ctx ------------------------ input, sha512_224_dma_ctx_t context pointer
* msg ------------------------ input, message blocks
* msg_words ------------------ input, word length of the input message,
* must be multiple of sha512_224 block word length(32) iterator
* ------------------- output, sha512_224 temporary result return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha512_224_dma_update_blocks(sha512_224_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *iterator)
{
return hash_dma_update_blocks(ctx, msg, msg_words, iterator);
}
/* function: dma sha512_224 final(input the remainder message and get the
* digest) parameters: ctx ------------------------ input, sha512_224_dma_ctx_t
* context pointer remainder_msg -------------- input, remainder message
* remainder_bytes ------------ input, byte length of the remainder message,
* must be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* sha512_224, it is 128. digest --------------------- output, sha512_224
* digest, 28 bytes return: HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha512_224_dma_final(sha512_224_dma_ctx_t *ctx,
uint32_t *remainder_msg, uint32_t remainder_bytes,
uint32_t *digest)
{
return hash_dma_final(ctx, remainder_msg, remainder_bytes, digest);
}
/* function: dma sha512_224 digest calculate
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the message, it could
* be 0 digest --------------------- output, sha512_224 digest, 28 bytes
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the four parameters are valid
*/
uint32_t sha512_224_dma(uint32_t *msg, uint32_t msg_bytes, uint32_t *digest,
HASH_CALLBACK callback)
{
return hash_dma(HASH_SHA512_224, msg, msg_bytes, digest, callback);
}
#endif
#endif

View File

@@ -0,0 +1,129 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <sha512_256.h>
#ifdef SUPPORT_HASH_SHA512_256
/* function: init sha512_256
* parameters:
* ctx ------------------------ input, sha512_256_ctx_t context pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t sha512_256_init(sha512_256_ctx_t *ctx)
{
return hash_init(ctx, HASH_SHA512_256);
}
/* function: sha512_256 update message
* parameters:
* ctx ------------------------ input, sha512_256_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t sha512_256_update(sha512_256_ctx_t *ctx, const uint8_t *msg,
uint32_t msg_bytes)
{
return hash_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the sha512_256 digest
* parameters:
* digest --------------------- output, sha512_256 digest, 32 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha512_256_final(sha512_256_ctx_t *ctx, uint8_t *digest)
{
return hash_final(ctx, digest);
}
/* function: input whole message and get its sha512_256 digest
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message, it
* could be 0 digest --------------------- output, sha512_256 digest, 32 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sha512_256(uint8_t *msg, uint32_t msg_bytes, uint8_t *digest)
{
return hash(HASH_SHA512_256, msg, msg_bytes, digest);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma sha512_256
* parameters:
* ctx ------------------------ input, sha512_256_dma_ctx_t context pointer
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t sha512_256_dma_init(sha512_256_dma_ctx_t *ctx, HASH_CALLBACK callback)
{
return hash_dma_init(ctx, HASH_SHA512_256, callback);
}
/* function: dma sha512_256 update some message blocks
* parameters:
* ctx ------------------------ input, sha512_256_dma_ctx_t context pointer
* msg ------------------------ input, message blocks
* msg_words ------------------ input, word length of the input message,
* must be multiple of sha512_256 block word length(32) iterator
* ------------------- output, sha512_256 temporary result return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha512_256_dma_update_blocks(sha512_256_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *iterator)
{
return hash_dma_update_blocks(ctx, msg, msg_words, iterator);
}
/* function: dma sha512_256 final(input the remainder message and get the
* digest) parameters: ctx ------------------------ input, sha512_256_dma_ctx_t
* context pointer remainder_msg -------------- input, remainder message
* remainder_bytes ------------ input, byte length of the remainder message,
* must be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* sha512_256, it is 128. digest --------------------- output, sha512_256
* digest, 32 bytes return: HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sha512_256_dma_final(sha512_256_dma_ctx_t *ctx,
uint32_t *remainder_msg, uint32_t remainder_bytes,
uint32_t *digest)
{
return hash_dma_final(ctx, remainder_msg, remainder_bytes, digest);
}
/* function: dma sha512_256 digest calculate
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the message, it could
* be 0 digest --------------------- output, sha512_256 digest, 32 bytes
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the four parameters are valid
*/
uint32_t sha512_256_dma(uint32_t *msg, uint32_t msg_bytes, uint32_t *digest,
HASH_CALLBACK callback)
{
return hash_dma(HASH_SHA512_256, msg, msg_bytes, digest, callback);
}
#endif
#endif

View File

@@ -0,0 +1,124 @@
/*****************************************************************************
*
*
*Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
*Software License Agreement
*
******************************************************************************
*/
#include <sm3.h>
#ifdef SUPPORT_HASH_SM3
/* function: init sm3
* parameters:
* ctx ------------------------ input, sm3_ctx_t context pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1.
*/
uint32_t sm3_init(sm3_ctx_t *ctx) { return hash_init(ctx, HASH_SM3); }
/* function: sm3 update message
* parameters:
* ctx ------------------------ input, sm3_ctx_t context pointer
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the three parameters are valid, and ctx is
* initialized
*/
uint32_t sm3_update(sm3_ctx_t *ctx, const uint8_t *msg, uint32_t msg_bytes)
{
return hash_update(ctx, msg, msg_bytes);
}
/* function: message update done, get the sm3 digest
* parameters:
* digest --------------------- output, sm3 digest, 32 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sm3_final(sm3_ctx_t *ctx, uint8_t *digest)
{
return hash_final(ctx, digest);
}
/* function: input whole message and get its sm3 digest
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the input message, it
* could be 0 digest --------------------- output, sm3 digest, 32 bytes return:
* HASH_SUCCESS(success), other(error) caution:
* 1. please make sure the digest buffer is sufficient
*/
uint32_t sm3(uint8_t *msg, uint32_t msg_bytes, uint8_t *digest)
{
return hash(HASH_SM3, msg, msg_bytes, digest);
}
#ifdef HASH_DMA_FUNCTION
/* function: init dma sm3
* parameters:
* ctx ------------------------ input, sm3_dma_ctx_t context pointer
* callback ------------------- callback function pointer
* return: HASH_SUCCESS(success), other(error)
* caution:
*/
uint32_t sm3_dma_init(sm3_dma_ctx_t *ctx, HASH_CALLBACK callback)
{
return hash_dma_init(ctx, HASH_SM3, callback);
}
/* function: dma sm3 update some message blocks
* parameters:
* ctx ------------------------ input, sm3_dma_ctx_t context pointer
* msg ------------------------ input, message blocks
* msg_words ------------------ input, word length of the input message,
* must be multiple of sm3 block word length(16) iterator -------------------
* output, sm3 temporary result return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sm3_dma_update_blocks(sm3_dma_ctx_t *ctx, uint32_t *msg,
uint32_t msg_words, uint32_t *iterator)
{
return hash_dma_update_blocks(ctx, msg, msg_words, iterator);
}
/* function: dma sm3 final(input the remainder message and get the digest)
* parameters:
* ctx ------------------------ input, sm3_dma_ctx_t context pointer
* remainder_msg -------------- input, remainder message
* remainder_bytes ------------ input, byte length of the remainder message,
* must be in [0, BLOCK_BYTE_LEN-1], here BLOCK_BYTE_LEN is block byte length of
* sm3, it is 64. digest --------------------- output, sm3 digest, 32 bytes
* return: HASH_SUCCESS(success), other(error)
* caution:
* 1. please make sure the four parameters are valid, and ctx is initialized
*/
uint32_t sm3_dma_final(sm3_dma_ctx_t *ctx, uint32_t *remainder_msg,
uint32_t remainder_bytes, uint32_t *digest)
{
return hash_dma_final(ctx, remainder_msg, remainder_bytes, digest);
}
/* function: dma sm3 digest calculate
* parameters:
* msg ------------------------ input, message
* msg_bytes ------------------ input, byte length of the message, it could
* be 0 digest --------------------- output, sm3 digest, 32 bytes callback
* ------------------- callback function pointer return: HASH_SUCCESS(success),
* other(error) caution:
* 1. please make sure the four parameters are valid
*/
uint32_t sm3_dma(uint32_t *msg, uint32_t msg_bytes, uint32_t *digest,
HASH_CALLBACK callback)
{
return hash_dma(HASH_SM3, msg, msg_bytes, digest, callback);
}
#endif
#endif