7zip/C/Sha1.h

87 lines
1.9 KiB
C
Raw Permalink Normal View History

2021-12-27 01:00:00 +01:00
/* Sha1.h -- SHA-1 Hash
2024-11-29 01:00:00 +01:00
: Igor Pavlov : Public domain */
2021-12-27 01:00:00 +01:00
2023-06-21 02:00:00 +02:00
#ifndef ZIP7_INC_SHA1_H
#define ZIP7_INC_SHA1_H
2021-12-27 01:00:00 +01:00
#include "7zTypes.h"
EXTERN_C_BEGIN
#define SHA1_NUM_BLOCK_WORDS 16
#define SHA1_NUM_DIGEST_WORDS 5
#define SHA1_BLOCK_SIZE (SHA1_NUM_BLOCK_WORDS * 4)
#define SHA1_DIGEST_SIZE (SHA1_NUM_DIGEST_WORDS * 4)
2024-11-29 01:00:00 +01:00
2023-06-21 02:00:00 +02:00
typedef void (Z7_FASTCALL *SHA1_FUNC_UPDATE_BLOCKS)(UInt32 state[5], const Byte *data, size_t numBlocks);
2021-12-27 01:00:00 +01:00
/*
if (the system supports different SHA1 code implementations)
{
(CSha1::func_UpdateBlocks) will be used
(CSha1::func_UpdateBlocks) can be set by
Sha1_Init() - to default (fastest)
Sha1_SetFunction() - to any algo
}
else
{
(CSha1::func_UpdateBlocks) is ignored.
}
*/
typedef struct
{
2024-11-29 01:00:00 +01:00
union
{
struct
{
SHA1_FUNC_UPDATE_BLOCKS func_UpdateBlocks;
UInt64 count;
} vars;
UInt64 _pad_64bit[4];
void *_pad_align_ptr[2];
} v;
2021-12-27 01:00:00 +01:00
UInt32 state[SHA1_NUM_DIGEST_WORDS];
2023-06-21 02:00:00 +02:00
UInt32 _pad_3[3];
2021-12-27 01:00:00 +01:00
Byte buffer[SHA1_BLOCK_SIZE];
} CSha1;
#define SHA1_ALGO_DEFAULT 0
#define SHA1_ALGO_SW 1
#define SHA1_ALGO_HW 2
/*
Sha1_SetFunction()
return:
0 - (algo) value is not supported, and func_UpdateBlocks was not changed
1 - func_UpdateBlocks was set according (algo) value.
*/
BoolInt Sha1_SetFunction(CSha1 *p, unsigned algo);
void Sha1_InitState(CSha1 *p);
void Sha1_Init(CSha1 *p);
void Sha1_Update(CSha1 *p, const Byte *data, size_t size);
void Sha1_Final(CSha1 *p, Byte *digest);
void Sha1_PrepareBlock(const CSha1 *p, Byte *block, unsigned size);
void Sha1_GetBlockDigest(const CSha1 *p, const Byte *data, Byte *destDigest);
2023-06-21 02:00:00 +02:00
// void Z7_FASTCALL Sha1_UpdateBlocks(UInt32 state[5], const Byte *data, size_t numBlocks);
2021-12-27 01:00:00 +01:00
/*
call Sha1Prepare() once at program start.
It prepares all supported implementations, and detects the fastest implementation.
*/
void Sha1Prepare(void);
EXTERN_C_END
#endif