rublon-ssh/PAM/ssh/include/rublon/sign.hpp
rublon-bwi 51b14c57d2
Bwi/memory management (#2)
Improve memory management
2023-09-21 16:52:20 +02:00

26 lines
665 B
C++

#pragma once
#include <array>
#include <cstring>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <string_view>
namespace rublon {
// +1 for \0
inline std::array< char, 64 + 1 > signData(std::string_view data, std::string_view secretKey) {
std::array< char, 64 + 1 > xRublon;
std::array< unsigned char, EVP_MAX_MD_SIZE > md;
unsigned int md_len{};
HMAC(EVP_sha256(), secretKey.data(), secretKey.size(), ( unsigned const char * ) data.data(), data.size(), md.data(), &md_len);
for(unsigned int i = 0; i < md_len; i++)
sprintf(&xRublon[i * 2], "%02x", ( unsigned int ) md[i]);
return xRublon;
}
} // namespace rublon