From 22fd9382f02c45badb53e4e9e6fc5445788f216a Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 7 Jul 2019 18:05:22 +0200 Subject: [PATCH] Reverted digest --- src/misc/digest.cpp | 18 +++++-------- src/misc/digest.h | 64 +++++++++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/misc/digest.cpp b/src/misc/digest.cpp index 4319d1e..cbdb034 100644 --- a/src/misc/digest.cpp +++ b/src/misc/digest.cpp @@ -2,17 +2,13 @@ #ifdef NO_OPEN_SSL #include - #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) diff --git a/src/misc/digest.h b/src/misc/digest.h index cdc34c7..9233d70 100644 --- a/src/misc/digest.h +++ b/src/misc/digest.h @@ -5,40 +5,48 @@ #include #ifdef NO_OPEN_SSL -#define SHA_DIGEST_LENGTH 20 - #define SHA256_DIGEST_LENGTH 32 - #define SHA512_DIGEST_LENGTH 64 +#define SHA_DIGEST_LENGTH (20) + #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((const char*) result, (size_t) digestLength); \ + } \ + \ + inline std::string __ ##name(const char* input, int64_t length = -1) { \ + if(length == -1) length = strlen(input); \ + uint8_t result[digestLength]; \ + tomcrypt::name(input, length, result); \ + return std::string((const char*) result, (size_t) digestLength); \ + } \ + \ + inline void name(const char* input, size_t length, uint8_t(& result)[digestLength]) { \ + tomcrypt::name(input, length, result); \ + } #else #include - #define DECLARE_DIGEST(name, method, digestLength) \ - inline std::string name(const std::string& input) { \ - u_char buffer[digestLength]; \ - method((u_char*) input.data(), input.length(), buffer); \ - return std::string((const char*) buffer, digestLength); \ - } \ - \ - inline std::string name(const char* input, ssize_t length = -1) { \ - if(length == -1) length = strlen(input); \ - return name(std::string(input, length)); \ - } \ - \ + #define DECLARE_DIGEST(name, method, digestLength) \ + inline std::string name(const std::string& input) { \ + u_char buffer[digestLength]; \ + method((u_char*) input.data(), input.length(), buffer); \ + return std::string((const char*) buffer, (size_t) digestLength); \ + } \ + \ + inline std::string name(const char* input, ssize_t length = -1) { \ + if(length == -1) length = strlen(input); \ + return name(std::string(input, (size_t) length)); \ + } \ + \ inline void name(const char* input, size_t length, uint8_t(& result)[digestLength]) { \ - method((u_char*) input, length, result); \ + method((u_char*) input, length, result); \ } #endif