This repository has been archived on 2023-07-17. You can view files and clone it, but cannot push or open issues or pull requests.
bl_mcu_sdk/drivers/lhal/include/bflb_sec_sha.h

106 lines
5.2 KiB
C
Raw Normal View History

#ifndef _BFLB_SEC_SHA_H
#define _BFLB_SEC_SHA_H
#include "bflb_core.h"
2022-10-29 13:33:23 +08:00
#define SHA_MODE_SHA256 0
#define SHA_MODE_SHA224 1
#define SHA_MODE_SHA1 2
#define SHA_MODE_SHA512 4
#define SHA_MODE_SHA384 5
#define SHA_MODE_SHA512T224 6
#define SHA_MODE_SHA512T256 7
struct bflb_sha1_ctx_s {
uint32_t total[2]; /*!< Number of bytes processed */
__attribute__((aligned(32))) uint8_t sha_buf[64]; /*!< Data not processed but in this temp buffer */
__attribute__((aligned(32))) uint8_t sha_padding[64]; /*!< Padding data */
uint8_t sha_feed; /*!< Sha has feed data */
};
struct bflb_sha256_ctx_s {
uint32_t total[2]; /*!< Number of bytes processed */
__attribute__((aligned(32))) uint8_t sha_buf[64]; /*!< Data not processed but in this temp buffer */
__attribute__((aligned(32))) uint8_t sha_padding[64]; /*!< Padding data */
uint8_t sha_feed; /*!< Sha has feed data */
};
struct bflb_sha512_ctx_s {
uint64_t total[2]; /*!< Number of bytes processed */
__attribute__((aligned(32))) uint8_t sha_buf[128]; /*!< Data not processed but in this temp buffer */
__attribute__((aligned(32))) uint8_t sha_padding[128]; /*!< Padding data */
uint8_t sha_feed; /*!< Sha has feed data */
};
2022-10-29 13:33:23 +08:00
struct bflb_sha_link_s {
uint32_t : 2; /*!< [1:0]Reserved */
uint32_t sha_mode : 3; /*!< [4:2]Sha-256/sha-224/sha-1/sha-1/sha-512/sha-384/sha-512T224/sha-512T256 */
uint32_t : 1; /*!< [5]Reserved */
uint32_t sha_newhash_dis : 1; /*!< [6]New hash or accumulate last hash */
uint32_t : 2; /*!< [8:7]Reserved */
uint32_t sha_intclr : 1; /*!< [9]Clear interrupt */
uint32_t sha_intset : 1; /*!< [10]Set interrupt */
uint32_t : 1; /*!< [11]Reserved */
uint32_t sha_mode_ext : 2; /*!< [13:12]Extention,0:sha 1:md5 2:crc16 3:crc32 */
uint32_t : 2; /*!< [15:14]Reserved */
uint32_t sha_msglen : 16; /*!< [31:16]Number of 512-bit block */
uint32_t sha_srcaddr; /*!< Message source address */
uint32_t result[16]; /*!< Result of SHA */
};
#ifdef __cplusplus
extern "C" {
#endif
void bflb_sha_init(struct bflb_device_s *dev, uint8_t mode);
void bflb_sha1_start(struct bflb_device_s *dev, struct bflb_sha1_ctx_s *ctx);
void bflb_sha256_start(struct bflb_device_s *dev, struct bflb_sha256_ctx_s *ctx);
void bflb_sha512_start(struct bflb_device_s *dev, struct bflb_sha512_ctx_s *ctx);
int bflb_sha1_update(struct bflb_device_s *dev, struct bflb_sha1_ctx_s *ctx, const uint8_t *input, uint32_t len);
int bflb_sha256_update(struct bflb_device_s *dev, struct bflb_sha256_ctx_s *ctx, const uint8_t *input, uint32_t len);
int bflb_sha512_update(struct bflb_device_s *dev, struct bflb_sha512_ctx_s *ctx, const uint8_t *input, uint32_t len);
void bflb_sha1_finish(struct bflb_device_s *dev, struct bflb_sha1_ctx_s *ctx, uint8_t *output);
void bflb_sha256_finish(struct bflb_device_s *dev, struct bflb_sha256_ctx_s *ctx, uint8_t *output);
void bflb_sha512_finish(struct bflb_device_s *dev, struct bflb_sha512_ctx_s *ctx, uint8_t *output);
2022-10-29 13:33:23 +08:00
void bflb_sha_link_init(struct bflb_device_s *dev);
void bflb_sha_link_deinit(struct bflb_device_s *dev);
void bflb_sha1_link_start(struct bflb_device_s *dev, struct bflb_sha1_ctx_s *ctx);
void bflb_sha256_link_start(struct bflb_device_s *dev, struct bflb_sha256_ctx_s *ctx);
void bflb_sha512_link_start(struct bflb_device_s *dev, struct bflb_sha512_ctx_s *ctx);
int bflb_sha1_link_update(struct bflb_device_s *dev,
struct bflb_sha1_ctx_s *ctx,
uint32_t link_addr,
const uint8_t *input,
uint32_t len);
int bflb_sha256_link_update(struct bflb_device_s *dev,
struct bflb_sha256_ctx_s *ctx,
uint32_t link_addr,
const uint8_t *input,
uint32_t len);
int bflb_sha512_link_update(struct bflb_device_s *dev,
struct bflb_sha512_ctx_s *ctx,
uint32_t link_addr,
const uint8_t *input,
uint32_t len);
void bflb_sha1_link_finish(struct bflb_device_s *dev,
struct bflb_sha1_ctx_s *ctx,
uint32_t link_addr,
uint8_t *output);
void bflb_sha256_link_finish(struct bflb_device_s *dev,
struct bflb_sha256_ctx_s *ctx,
uint32_t link_addr,
uint8_t *output);
void bflb_sha512_link_finish(struct bflb_device_s *dev,
struct bflb_sha512_ctx_s *ctx,
uint32_t link_addr,
uint8_t *output);
void bflb_group0_request_sha_access(struct bflb_device_s *dev);
void bflb_group0_release_sha_access(struct bflb_device_s *dev);
#ifdef __cplusplus
}
#endif
#endif