aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/openssl/crypto/sha.h
diff options
context:
space:
mode:
authorqrort <qrort@yandex-team.com>2022-11-30 23:47:12 +0300
committerqrort <qrort@yandex-team.com>2022-11-30 23:47:12 +0300
commit22f8ae0e3f5d68b92aecccdf96c1d841a0334311 (patch)
treebffa27765faf54126ad44bcafa89fadecb7a73d7 /library/cpp/openssl/crypto/sha.h
parent332b99e2173f0425444abb759eebcb2fafaa9209 (diff)
downloadydb-22f8ae0e3f5d68b92aecccdf96c1d841a0334311.tar.gz
validate canons without yatest_common
Diffstat (limited to 'library/cpp/openssl/crypto/sha.h')
-rw-r--r--library/cpp/openssl/crypto/sha.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/library/cpp/openssl/crypto/sha.h b/library/cpp/openssl/crypto/sha.h
new file mode 100644
index 0000000000..dbc2dfa526
--- /dev/null
+++ b/library/cpp/openssl/crypto/sha.h
@@ -0,0 +1,78 @@
+#pragma once
+
+#include <util/generic/ptr.h>
+#include <util/generic/strbuf.h>
+#include <util/system/types.h>
+
+#include <array>
+
+struct SHAstate_st;
+struct SHA256state_st;
+
+namespace NOpenSsl::NSha1 {
+ constexpr size_t DIGEST_LENGTH = 20;
+ using TDigest = std::array<ui8, DIGEST_LENGTH>;
+
+ // not fragmented input
+ TDigest Calc(const void* data, size_t dataSize);
+
+ inline TDigest Calc(TStringBuf s) {
+ return Calc(s.data(), s.length());
+ }
+
+ // fragmented input
+ class TCalcer {
+ public:
+ TCalcer();
+ ~TCalcer();
+ void Update(const void* data, size_t dataSize);
+
+ void Update(TStringBuf s) {
+ Update(s.data(), s.length());
+ }
+
+ template <typename T>
+ void UpdateWithPodValue(const T& value) {
+ Update(&value, sizeof(value));
+ }
+
+ TDigest Final();
+
+ private:
+ THolder<SHAstate_st> Context;
+ };
+}
+
+namespace NOpenSsl::NSha256 {
+ constexpr size_t DIGEST_LENGTH = 32;
+ using TDigest = std::array<ui8, DIGEST_LENGTH>;
+
+ // not fragmented input
+ TDigest Calc(const void* data, size_t dataSize);
+
+ inline TDigest Calc(TStringBuf s) {
+ return Calc(s.data(), s.length());
+ }
+
+ // fragmented input
+ class TCalcer {
+ public:
+ TCalcer();
+ ~TCalcer();
+ void Update(const void* data, size_t dataSize);
+
+ void Update(TStringBuf s) {
+ Update(s.data(), s.length());
+ }
+
+ template <typename T>
+ void UpdateWithPodValue(const T& value) {
+ Update(&value, sizeof(value));
+ }
+
+ TDigest Final();
+
+ private:
+ THolder<SHA256state_st> Context;
+ };
+}