From 6c6f1bd96b90d97ab2ed89ac44788ab3fccb58e6 Mon Sep 17 00:00:00 2001 From: Rostislav Savinkov Date: Wed, 12 May 2021 16:17:17 +0300 Subject: [PATCH] Fixed hmac_sha512.hpp to new standart & added Makefile for example code. --- "rest/\321\201++/Makefile" | 4 ++++ "rest/\321\201++/hmac_sha512.hpp" | 13 ++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 "rest/\321\201++/Makefile" diff --git "a/rest/\321\201++/Makefile" "b/rest/\321\201++/Makefile" new file mode 100644 index 0000000..9a85a4e --- /dev/null +++ "b/rest/\321\201++/Makefile" @@ -0,0 +1,4 @@ +All: + g++ exmo.cpp -lssl -lcurl -lcrypto -o exmo +clear: + rm exmo diff --git "a/rest/\321\201++/hmac_sha512.hpp" "b/rest/\321\201++/hmac_sha512.hpp" index a0f410d..5eedb9e 100644 --- "a/rest/\321\201++/hmac_sha512.hpp" +++ "b/rest/\321\201++/hmac_sha512.hpp" @@ -8,23 +8,22 @@ class HMAC_SHA512 { public: HMAC_SHA512(const std::string& key, const std::string& msg) { - HMAC_CTX ctx; - HMAC_CTX_init(&ctx); + HMAC_CTX* ctx = HMAC_CTX_new(); // Set HMAC key. - HMAC_Init_ex(&ctx, reinterpret_cast(key.c_str()), key.size(), EVP_sha512(), NULL); + HMAC_Init_ex(ctx, reinterpret_cast(key.c_str()), key.size(), EVP_sha512(), NULL); // May be called repeatedly to insert all your data. - HMAC_Update(&ctx, reinterpret_cast(msg.c_str()), msg.size()); + HMAC_Update(ctx, reinterpret_cast(msg.c_str()), msg.size()); // Finish HMAC computation and fetch result. unsigned char* result = new unsigned char[129]; unsigned int result_len = 129; - HMAC_Final(&ctx, result, &result_len); + HMAC_Final(ctx, result, &result_len); for (int i = 0; i < result_len; i++) { digest_.push_back(int(result[i])); } - HMAC_CTX_cleanup(&ctx); + HMAC_CTX_free(ctx); } std::string hex_digest() { @@ -42,4 +41,4 @@ class HMAC_SHA512 { std::vector digest_; }; -#endif // HMAC_SHA512_HPP \ No newline at end of file +#endif // HMAC_SHA512_HPP