TeaSpeakLibrary/src/misc/digest.cpp

22 lines
854 B
C++
Raw Normal View History

#include "./digest.h"
#ifdef NO_OPEN_SSL
2019-07-07 12:02:46 -04:00
#include <tomcrypt.h>
2019-07-07 12:02:46 -04:00
#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); \
}
DECLARE_DIGEST(sha1, SHA1, SHA_DIGEST_LENGTH)
DECLARE_DIGEST(sha256, SHA256, SHA256_DIGEST_LENGTH)
DECLARE_DIGEST(sha512, SHA512, SHA512_DIGEST_LENGTH)
2019-07-07 12:02:46 -04:00
#endif