123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #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;
- };
- }
- namespace NOpenSsl::NSha224 {
- constexpr size_t DIGEST_LENGTH = 28;
- 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;
- };
- }
|