19#include "hitls_build.h"
20#ifdef HITLS_CRYPTO_SHA2
24#include "crypt_types.h"
25#include "bsl_params.h"
33#ifdef HITLS_CRYPTO_SHA224
34#define CRYPT_SHA2_224_BLOCKSIZE 64
35#define CRYPT_SHA2_224_DIGESTSIZE 28
38#ifdef HITLS_CRYPTO_SHA256
39#define CRYPT_SHA2_256_BLOCKSIZE 64
40#define CRYPT_SHA2_256_DIGESTSIZE 32
41#define CRYPT_SHA256_STATE_SIZE 8
44#ifdef HITLS_CRYPTO_SHA384
45#define CRYPT_SHA2_384_BLOCKSIZE 128
46#define CRYPT_SHA2_384_DIGESTSIZE 48
49#ifdef HITLS_CRYPTO_SHA512
50#define CRYPT_SHA2_512_BLOCKSIZE 128
51#define CRYPT_SHA2_512_DIGESTSIZE 64
54#ifdef HITLS_CRYPTO_SHA256
56typedef struct CryptSha256Ctx {
57 uint32_t h[CRYPT_SHA256_STATE_SIZE];
58 uint32_t block[CRYPT_SHA2_256_BLOCKSIZE /
sizeof(uint32_t)];
66#ifdef HITLS_CRYPTO_SHA224
68typedef struct CryptSha256Ctx CRYPT_SHA2_224_Ctx;
71#ifdef HITLS_CRYPTO_SHA512
73typedef struct CryptSha2512Ctx {
74 uint64_t h[CRYPT_SHA2_512_DIGESTSIZE /
sizeof(uint64_t)];
75 uint8_t block[CRYPT_SHA2_512_BLOCKSIZE];
82#ifdef HITLS_CRYPTO_SHA384
84typedef struct CryptSha2512Ctx CRYPT_SHA2_384_Ctx;
87#define CRYPT_SHA2_224_Squeeze NULL
88#define CRYPT_SHA2_256_Squeeze NULL
89#define CRYPT_SHA2_384_Squeeze NULL
90#define CRYPT_SHA2_512_Squeeze NULL
92#ifdef HITLS_CRYPTO_SHA224
94#define CRYPT_SHA2_224_NewCtx CRYPT_SHA2_256_NewCtx
95#define CRYPT_SHA2_224_NewCtxEx CRYPT_SHA2_256_NewCtxEx
96#define CRYPT_SHA2_224_FreeCtx CRYPT_SHA2_256_FreeCtx
97#define CRYPT_SHA2_224_Deinit CRYPT_SHA2_256_Deinit
98#define CRYPT_SHA2_224_CopyCtx CRYPT_SHA2_256_CopyCtx
99#define CRYPT_SHA2_224_DupCtx CRYPT_SHA2_256_DupCtx
100#define CRYPT_SHA2_224_Update CRYPT_SHA2_256_Update
101#define CRYPT_SHA2_224_Final CRYPT_SHA2_256_Final
126int32_t CRYPT_SHA2_224_Init(CRYPT_SHA2_224_Ctx *ctx);
138int32_t CRYPT_SHA2_224_InitEx(CRYPT_SHA2_224_Ctx *ctx,
void *param);
140#ifdef HITLS_CRYPTO_PROVIDER
151int32_t CRYPT_SHA2_224_GetParam(CRYPT_SHA2_224_Ctx *ctx, BSL_Param *param);
153#define CRYPT_SHA2_224_GetParam NULL
158#ifdef HITLS_CRYPTO_SHA256
167CRYPT_SHA2_256_Ctx *CRYPT_SHA2_256_NewCtx(
void);
179CRYPT_SHA2_256_Ctx *CRYPT_SHA2_256_NewCtxEx(
void *libCtx, int32_t algId);
187void CRYPT_SHA2_256_FreeCtx(CRYPT_SHA2_256_Ctx *ctx);
214int32_t CRYPT_SHA2_256_Init(CRYPT_SHA2_256_Ctx *ctx);
226int32_t CRYPT_SHA2_256_InitEx(CRYPT_SHA2_256_Ctx *ctx,
void *param);
254int32_t CRYPT_SHA2_256_Update(CRYPT_SHA2_256_Ctx *ctx,
const uint8_t *data, uint32_t nbytes);
283int32_t CRYPT_SHA2_256_Final(CRYPT_SHA2_256_Ctx *ctx, uint8_t *digest, uint32_t *outlen);
287 CRYPT_SHA2_256_Ctx *ctxs;
288} CRYPT_SHA2_256_MB_Ctx;
302CRYPT_SHA2_256_MB_Ctx *CRYPT_SHA256_MBNewCtx(uint32_t num);
310void CRYPT_SHA256_MBFreeCtx(CRYPT_SHA2_256_MB_Ctx *ctx);
325int32_t CRYPT_SHA256_MBInit(CRYPT_SHA2_256_MB_Ctx *ctx);
347int32_t CRYPT_SHA256_MBUpdate(CRYPT_SHA2_256_MB_Ctx *ctx,
const uint8_t *data[], uint32_t nbytes[], uint32_t num);
367int32_t CRYPT_SHA256_MBFinal(CRYPT_SHA2_256_MB_Ctx *ctx, uint8_t *digest[], uint32_t *outlen, uint32_t num);
382void CRYPT_SHA256x2_Compress(uint32_t state1[CRYPT_SHA256_STATE_SIZE], uint32_t state2[CRYPT_SHA256_STATE_SIZE],
383 const uint8_t *block1,
const uint8_t *block2, uint32_t nblocks);
404int32_t CRYPT_SHA256_MB(
const uint8_t *data[], uint32_t nbytes, uint8_t *digest[], uint32_t *outlen, uint32_t num);
427int32_t CRYPT_SHA256x2(uint32_t state1[CRYPT_SHA256_STATE_SIZE], uint32_t state2[CRYPT_SHA256_STATE_SIZE],
428 const uint8_t *data1,
const uint8_t *data2, uint32_t nbytes,
429 uint8_t dgst1[CRYPT_SHA2_256_DIGESTSIZE], uint8_t dgst2[CRYPT_SHA2_256_DIGESTSIZE]);
441int32_t CRYPT_SHA2_256_Deinit(CRYPT_SHA2_256_Ctx *ctx);
449int32_t CRYPT_SHA2_256_CopyCtx(CRYPT_SHA2_256_Ctx *dst,
const CRYPT_SHA2_256_Ctx *src);
456CRYPT_SHA2_256_Ctx *CRYPT_SHA2_256_DupCtx(
const CRYPT_SHA2_256_Ctx *src);
458#ifdef HITLS_CRYPTO_PROVIDER
469int32_t CRYPT_SHA2_256_GetParam(CRYPT_SHA2_256_Ctx *ctx, BSL_Param *param);
471#define CRYPT_SHA2_256_GetParam NULL
475#ifdef HITLS_CRYPTO_SHA384
477#define CRYPT_SHA2_384_NewCtx CRYPT_SHA2_512_NewCtx
478#define CRYPT_SHA2_384_NewCtxEx CRYPT_SHA2_512_NewCtxEx
479#define CRYPT_SHA2_384_FreeCtx CRYPT_SHA2_512_FreeCtx
480#define CRYPT_SHA2_384_Deinit CRYPT_SHA2_512_Deinit
481#define CRYPT_SHA2_384_CopyCtx CRYPT_SHA2_512_CopyCtx
482#define CRYPT_SHA2_384_DupCtx CRYPT_SHA2_512_DupCtx
483#define CRYPT_SHA2_384_Update CRYPT_SHA2_512_Update
484#define CRYPT_SHA2_384_Final CRYPT_SHA2_512_Final
508int32_t CRYPT_SHA2_384_Init(CRYPT_SHA2_384_Ctx *ctx);
520int32_t CRYPT_SHA2_384_InitEx(CRYPT_SHA2_384_Ctx *ctx,
void *param);
522#ifdef HITLS_CRYPTO_PROVIDER
533int32_t CRYPT_SHA2_384_GetParam(CRYPT_SHA2_384_Ctx *ctx, BSL_Param *param);
535#define CRYPT_SHA2_384_GetParam NULL
540#ifdef HITLS_CRYPTO_SHA512
549CRYPT_SHA2_512_Ctx *CRYPT_SHA2_512_NewCtx(
void);
561CRYPT_SHA2_512_Ctx *CRYPT_SHA2_512_NewCtxEx(
void *libCtx, int32_t algId);
569void CRYPT_SHA2_512_FreeCtx(CRYPT_SHA2_512_Ctx *ctx);
593int32_t CRYPT_SHA2_512_Init(CRYPT_SHA2_512_Ctx *ctx);
605int32_t CRYPT_SHA2_512_InitEx(CRYPT_SHA2_512_Ctx *ctx,
void *param);
631int32_t CRYPT_SHA2_512_Update(CRYPT_SHA2_512_Ctx *ctx,
const uint8_t *data, uint32_t nbytes);
657int32_t CRYPT_SHA2_512_Final(CRYPT_SHA2_512_Ctx *ctx, uint8_t *digest, uint32_t *len);
669int32_t CRYPT_SHA2_512_Deinit(CRYPT_SHA2_512_Ctx *ctx);
677int32_t CRYPT_SHA2_512_CopyCtx(CRYPT_SHA2_512_Ctx *dst,
const CRYPT_SHA2_512_Ctx *src);
684CRYPT_SHA2_512_Ctx *CRYPT_SHA2_512_DupCtx(
const CRYPT_SHA2_512_Ctx *src);
686#ifdef HITLS_CRYPTO_PROVIDER
697int32_t CRYPT_SHA2_512_GetParam(CRYPT_SHA2_512_Ctx *ctx, BSL_Param *param);
699#define CRYPT_SHA2_512_GetParam NULL