SemiDrive SSDK Appication Program Interface PTG3.0
hash.h
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 *
4 *Copyright (c) 2021-2029 Semidrive Incorporated. All rights reserved.
5 *Software License Agreement
6 *
7 ******************************************************************************
8 */
9#ifndef HASH_H
10#define HASH_H
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16#include <hash_basic.h>
17
18/*HASH status*/
19typedef struct {
20 uint32_t busy : 1; /* calculate busy flag*/
22
23/*HASH context*/
24typedef struct {
25 HASH_ALG hash_alg; /*current hash algorithm*/
30 status; /*hash update status, .busy=1 means doing =0 means idle*/
31 uint8_t
32 first_update_flag; /*whether first time to update message(1:yes, 0:no)*/
33 uint8_t finish_flag; /*whether the whole message has been inputted(1:yes,
34 0:no)*/
35 uint8_t hash_buffer[HASH_BLOCK_MAX_BYTE_LEN]; /*block buffer*/
36 uint32_t total[HASH_TOTAL_LEN_MAX_WORD_LEN]; /*total byte length of the
37 whole message*/
38
39#if CONFIG_HASH_SUPPORT_MUL_THREAD
40 uint32_t
41 iterator[HASH_ITERATOR_MAX_WORD_LEN]; /*keep current hash iterator value
42 for multiple thread*/
43#endif
45
46#ifdef HASH_DMA_FUNCTION
47/*HASH DMA context*/
48typedef struct {
49 HASH_ALG hash_alg;
50 uint32_t total[HASH_TOTAL_LEN_MAX_WORD_LEN]; /*total byte length of the
51 whole message*/
52 uint8_t block_word_len;
53 HASH_CALLBACK callback;
54} hash_dma_ctx_t;
55#endif
56
57/*APIs*/
58uint8_t check_hash_alg(HASH_ALG hash_alg);
59
61
63
65
66void hash_set_tx_bit_len(hash_ctx_t *ctx, uint32_t block_count);
67
69
70uint8_t hash_total_len_add_uint32(uint32_t *a, uint32_t a_words, uint32_t b);
71
72void hash_total_bytelen_2_bitlen(uint32_t *a, uint32_t a_words);
73
74uint32_t hash_init(hash_ctx_t *ctx, HASH_ALG hash_alg);
75
76uint32_t hash_update(hash_ctx_t *ctx, const uint8_t *msg, uint32_t msg_bytes);
77
78uint32_t hash_final(hash_ctx_t *ctx, uint8_t *digest);
79
80uint32_t hash(HASH_ALG hash_alg, uint8_t *msg, uint32_t msg_bytes,
81 uint8_t *digest);
82
83void hash_set_IV(HASH_ALG hash_alg, uint8_t hash_iterator_words);
84
85#ifdef HASH_DMA_FUNCTION
86uint32_t hash_dma_init(hash_dma_ctx_t *ctx, HASH_ALG hash_alg,
87 HASH_CALLBACK callback);
88
89uint32_t hash_dma_update_blocks(hash_dma_ctx_t *ctx, uint32_t *msg,
90 uint32_t msg_words, uint32_t *iterator);
91
92uint32_t hash_dma_final(hash_dma_ctx_t *ctx, uint32_t *remainder_msg,
93 uint32_t remainder_bytes, uint32_t *digest);
94
95uint32_t hash_dma(HASH_ALG hash_alg, uint32_t *msg, uint32_t msg_bytes,
96 uint32_t *digest, HASH_CALLBACK callback);
97#endif
98
99#ifdef __cplusplus
100}
101#endif
102
103#endif
uint32_t hash_init(hash_ctx_t *ctx, HASH_ALG hash_alg)
uint8_t hash_total_len_add_uint32(uint32_t *a, uint32_t a_words, uint32_t b)
uint8_t hash_get_digest_word_len(HASH_ALG hash_alg)
void hash_total_bytelen_2_bitlen(uint32_t *a, uint32_t a_words)
uint32_t hash_update(hash_ctx_t *ctx, const uint8_t *msg, uint32_t msg_bytes)
uint32_t hash(HASH_ALG hash_alg, uint8_t *msg, uint32_t msg_bytes, uint8_t *digest)
uint8_t check_hash_alg(HASH_ALG hash_alg)
void hash_start_calculate(hash_ctx_t *ctx)
uint8_t hash_get_iterator_word_len(HASH_ALG hash_alg)
void hash_set_IV(HASH_ALG hash_alg, uint8_t hash_iterator_words)
uint32_t hash_final(hash_ctx_t *ctx, uint8_t *digest)
uint8_t hash_get_block_word_len(HASH_ALG hash_alg)
void hash_set_tx_bit_len(hash_ctx_t *ctx, uint32_t block_count)
Semidrive CRYPTO hash basic header file.
HASH_ALG
Definition: hash_basic.h:131
#define HASH_ITERATOR_MAX_WORD_LEN
Definition: hash_basic.h:118
void(* HASH_CALLBACK)(void)
Definition: hash_basic.h:195
#define HASH_BLOCK_MAX_BYTE_LEN
Definition: hash_basic.h:114
#define HASH_TOTAL_LEN_MAX_WORD_LEN
Definition: hash_basic.h:125
Definition: hash.h:24
HASH_ALG hash_alg
Definition: hash.h:25
uint8_t first_update_flag
Definition: hash.h:32
uint8_t finish_flag
Definition: hash.h:33
uint8_t iterator_word_len
Definition: hash.h:27
uint8_t block_byte_len
Definition: hash.h:26
hash_status_t status
Definition: hash.h:30
uint8_t digest_byte_len
Definition: hash.h:28
Definition: hash.h:19
uint32_t busy
Definition: hash.h:20