mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: C++-ify SHA1 interface
All callers of the SHA1 code are C++. Might just as well use a C++ like interface. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
729356e0b1
commit
21f68387ae
6 changed files with 71 additions and 78 deletions
29
core/sha1.h
29
core/sha1.h
|
|
@ -9,31 +9,28 @@
|
|||
#define SHA1_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
struct SHA1
|
||||
{
|
||||
SHA1();
|
||||
void update(const void *dataIn, unsigned long len);
|
||||
void update(const std::string &s);
|
||||
// Note: the hash() functions change state. Call only once.
|
||||
std::array<unsigned char, 20> hash();
|
||||
uint32_t hash_uint32(); // Return first 4 bytes of hash interpreted
|
||||
// as little-endian unsigned integer.
|
||||
private:
|
||||
unsigned long long size;
|
||||
unsigned int H[5];
|
||||
unsigned int W[16];
|
||||
} blk_SHA_CTX;
|
||||
|
||||
void blk_SHA1_Init(blk_SHA_CTX *ctx);
|
||||
void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, unsigned long len);
|
||||
void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx);
|
||||
|
||||
/* Make us use the standard names */
|
||||
#define SHA_CTX blk_SHA_CTX
|
||||
#define SHA1_Init blk_SHA1_Init
|
||||
#define SHA1_Update blk_SHA1_Update
|
||||
#define SHA1_Final blk_SHA1_Final
|
||||
};
|
||||
|
||||
/* Helper function that calculates an SHA1 has and returns the first 4 bytes as uint32_t */
|
||||
uint32_t SHA1_uint32(const void *dataIn, unsigned long len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SHA1_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue