/* Sha256.h -- SHA-256 Hash12023-04-02 : Igor Pavlov : Public domain */23#ifndef ZIP7_INC_SHA256_H4#define ZIP7_INC_SHA256_H56#include "7zTypes.h"78EXTERN_C_BEGIN910#define SHA256_NUM_BLOCK_WORDS 1611#define SHA256_NUM_DIGEST_WORDS 81213#define SHA256_BLOCK_SIZE (SHA256_NUM_BLOCK_WORDS * 4)14#define SHA256_DIGEST_SIZE (SHA256_NUM_DIGEST_WORDS * 4)1516typedef void (Z7_FASTCALL *SHA256_FUNC_UPDATE_BLOCKS)(UInt32 state[8], const Byte *data, size_t numBlocks);1718/*19if (the system supports different SHA256 code implementations)20{21(CSha256::func_UpdateBlocks) will be used22(CSha256::func_UpdateBlocks) can be set by23Sha256_Init() - to default (fastest)24Sha256_SetFunction() - to any algo25}26else27{28(CSha256::func_UpdateBlocks) is ignored.29}30*/3132typedef struct33{34SHA256_FUNC_UPDATE_BLOCKS func_UpdateBlocks;35UInt64 count;36UInt64 _pad_2[2];37UInt32 state[SHA256_NUM_DIGEST_WORDS];3839Byte buffer[SHA256_BLOCK_SIZE];40} CSha256;414243#define SHA256_ALGO_DEFAULT 044#define SHA256_ALGO_SW 145#define SHA256_ALGO_HW 24647/*48Sha256_SetFunction()49return:500 - (algo) value is not supported, and func_UpdateBlocks was not changed511 - func_UpdateBlocks was set according (algo) value.52*/5354BoolInt Sha256_SetFunction(CSha256 *p, unsigned algo);5556void Sha256_InitState(CSha256 *p);57void Sha256_Init(CSha256 *p);58void Sha256_Update(CSha256 *p, const Byte *data, size_t size);59void Sha256_Final(CSha256 *p, Byte *digest);6061626364// void Z7_FASTCALL Sha256_UpdateBlocks(UInt32 state[8], const Byte *data, size_t numBlocks);6566/*67call Sha256Prepare() once at program start.68It prepares all supported implementations, and detects the fastest implementation.69*/7071void Sha256Prepare(void);7273EXTERN_C_END7475#endif767778