mirror of
https://github.com/lifegpc/c-utils.git
synced 2026-07-08 01:30:39 +08:00
Add SHA384 / SHA256 / SHA 224
This commit is contained in:
36
hash_lib.h
36
hash_lib.h
@@ -68,6 +68,42 @@ namespace hash_lib {
|
||||
protected:
|
||||
void _initState() override;
|
||||
};
|
||||
class SHA384: public SHA512 {
|
||||
public:
|
||||
SHA384();
|
||||
int digestLength() override;
|
||||
protected:
|
||||
void _initState() override;
|
||||
};
|
||||
class SHA256: public Hash {
|
||||
public:
|
||||
SHA256();
|
||||
virtual int digestLength() override;
|
||||
int blockSize() override;
|
||||
Hash* update(const uint8_t* data, size_t len) override;
|
||||
using Hash::update;
|
||||
Hash* reset() override;
|
||||
Hash* finish(uint8_t* data, size_t len) override;
|
||||
using Hash::finish;
|
||||
void clean() override;
|
||||
protected:
|
||||
uint32_t state[8];
|
||||
virtual void _initState();
|
||||
private:
|
||||
uint32_t _temp[64];
|
||||
uint8_t _buffer[128];
|
||||
size_t _bufferLength = 0;
|
||||
size_t _bytesHashed = 0;
|
||||
bool _finished = false;
|
||||
size_t hashBlocks(const uint8_t* m, size_t pos, size_t len);
|
||||
};
|
||||
class SHA224: public SHA256 {
|
||||
public:
|
||||
SHA224();
|
||||
int digestLength() override;
|
||||
protected:
|
||||
void _initState() override;
|
||||
};
|
||||
template<class H>
|
||||
std::vector<uint8_t> hash(const uint8_t* data, size_t len) {
|
||||
H h;
|
||||
|
||||
Reference in New Issue
Block a user