Fixed digest for no ssl buildings

This commit is contained in:
WolverinDEV 2019-07-05 20:45:32 +02:00
parent 89fd735919
commit 6fc6d16601
2 changed files with 26 additions and 23 deletions

View File

@ -2,17 +2,13 @@
#ifdef NO_OPEN_SSL
#include <tomcrypt.h>
#define DECLARE_DIGEST(name, _unused_, digestLength) \
std::string digest::tomcrypt::name(const std::string& input) { \
hash_state hash{}; \
\
uint8_t buffer[digestLength]; \
\
name ##_init(&hash); \
name ##_process(&hash, (uint8_t*) input.data(), input.length()); \
name ##_done(&hash, buffer); \
\
return std::string((const char*) buffer, digestLength); \
#define DECLARE_DIGEST(name, _unused_, digestLength) \
void digest::tomcrypt::name(const char* input, size_t length, uint8_t(& result)[digestLength]) { \
hash_state hash{}; \
\
name ##_init(&hash); \
name ##_process(&hash, (uint8_t*) input, length); \
name ##_done(&hash, result); \
}
DECLARE_DIGEST(sha1, SHA1, SHA_DIGEST_LENGTH)

View File

@ -9,18 +9,25 @@
#define SHA256_DIGEST_LENGTH 32
#define SHA512_DIGEST_LENGTH 64
#define DECLARE_DIGEST(name, _unused_, digestLength) \
namespace tomcrypt { \
extern std::string name(const std::string&); \
} \
inline std::string name(const std::string& input) { \
return tomcrypt::name(input); \
} \
\
inline std::string name(const char* input, int64_t length = -1) { \
if(length == -1) length = strlen(input); \
return name(std::string{input, (size_t) length}); \
} \
#define DECLARE_DIGEST(name, _unused_, digestLength) \
namespace tomcrypt { \
extern void name(const char* input, size_t length, uint8_t(& result)[digestLength]); \
} \
inline std::string name(const std::string& input) { \
uint8_t result[digestLength]; \
tomcrypt::name(input.data(), input.length(), result); \
return std::string(result, result); \
} \
\
inline std::string name(const char* input, int64_t length = -1) { \
uint8_t result[digestLength]; \
tomcrypt::name(input, length, result); \
return std::string(result, result); \
} \
\
inline void name(const char* input, size_t length, uint8_t(& result)[digestLength]) { \
tomcrypt::name(input, length, result); \
}
#else
#include <openssl/sha.h>