Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rest/с++/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
All:
g++ exmo.cpp -lssl -lcurl -lcrypto -o exmo
clear:
rm exmo
13 changes: 6 additions & 7 deletions rest/с++/hmac_sha512.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const unsigned char*>(key.c_str()), key.size(), EVP_sha512(), NULL);
HMAC_Init_ex(ctx, reinterpret_cast<const unsigned char*>(key.c_str()), key.size(), EVP_sha512(), NULL);

// May be called repeatedly to insert all your data.
HMAC_Update(&ctx, reinterpret_cast<const unsigned char*>(msg.c_str()), msg.size());
HMAC_Update(ctx, reinterpret_cast<const unsigned char*>(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() {
Expand All @@ -42,4 +41,4 @@ class HMAC_SHA512 {
std::vector<unsigned char> digest_;
};

#endif // HMAC_SHA512_HPP
#endif // HMAC_SHA512_HPP