diff options
author | komels <komels@yandex-team.ru> | 2022-04-14 13:10:53 +0300 |
---|---|---|
committer | komels <komels@yandex-team.ru> | 2022-04-14 13:10:53 +0300 |
commit | 21c9b0e6b039e9765eb414c406c2b86e8cea6850 (patch) | |
tree | f40ebc18ff8958dfbd189954ad024043ca983ea5 /library/cpp/openssl/crypto/sha.cpp | |
parent | 9a4effa852abe489707139c2b260dccc6f4f9aa9 (diff) | |
download | ydb-21c9b0e6b039e9765eb414c406c2b86e8cea6850.tar.gz |
Final part on compatibility layer: LOGBROKER-7215
ref:777c67aadbf705d19034a09a792b2df61ba53697
Diffstat (limited to 'library/cpp/openssl/crypto/sha.cpp')
-rw-r--r-- | library/cpp/openssl/crypto/sha.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/library/cpp/openssl/crypto/sha.cpp b/library/cpp/openssl/crypto/sha.cpp new file mode 100644 index 0000000000..8e7e88ccde --- /dev/null +++ b/library/cpp/openssl/crypto/sha.cpp @@ -0,0 +1,62 @@ +#include "sha.h" + +#include <util/generic/yexception.h> + +#include <contrib/libs/openssl/include/openssl/sha.h> + +namespace NOpenSsl { + namespace NSha1 { + static_assert(DIGEST_LENGTH == SHA_DIGEST_LENGTH); + + TDigest Calc(const void* data, size_t dataSize) { + TDigest digest; + Y_ENSURE(SHA1(static_cast<const ui8*>(data), dataSize, digest.data()) != nullptr); + return digest; + } + + TCalcer::TCalcer() + : Context{new SHAstate_st} { + Y_ENSURE(SHA1_Init(Context.Get()) == 1); + } + + TCalcer::~TCalcer() { + } + + void TCalcer::Update(const void* data, size_t dataSize) { + Y_ENSURE(SHA1_Update(Context.Get(), data, dataSize) == 1); + } + + TDigest TCalcer::Final() { + TDigest digest; + Y_ENSURE(SHA1_Final(digest.data(), Context.Get()) == 1); + return digest; + } + } + namespace NSha256 { + static_assert(DIGEST_LENGTH == SHA256_DIGEST_LENGTH); + + TDigest Calc(const void* data, size_t dataSize) { + TDigest digest; + Y_ENSURE(SHA256(static_cast<const ui8*>(data), dataSize, digest.data()) != nullptr); + return digest; + } + + TCalcer::TCalcer() + : Context{new SHA256state_st} { + Y_ENSURE(SHA256_Init(Context.Get()) == 1); + } + + TCalcer::~TCalcer() { + } + + void TCalcer::Update(const void* data, size_t dataSize) { + Y_ENSURE(SHA256_Update(Context.Get(), data, dataSize) == 1); + } + + TDigest TCalcer::Final() { + TDigest digest; + Y_ENSURE(SHA256_Final(digest.data(), Context.Get()) == 1); + return digest; + } + } +} |