AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
sha1.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++23 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <https://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "anch-crypto-export.hpp"
23
24#include "crypto/hash/hash.hpp"
25
26
27namespace anch::crypto {
28
29 template<typename H> ANCH_CRYPTO_EXPORT H HMAC(const std::string&, const std::string&);
30
38 class ANCH_CRYPTO_EXPORT SHA1: public Hash<20,64> {
39
40 friend SHA1 anch::crypto::HMAC<SHA1>(const std::string&, const std::string&);
41
42 private:
48 struct Context {
50 std::array<uint32_t,5> state;
51
53 uint64_t size;
54
56 std::array<uint8_t,64> buffer;
57
59 std::array<uint8_t,20> digest;
60
64 Context();
65
69 void reset();
70
71 };
72
73 // Attributes +
74 private:
76 Context _context;
77 // Attributes -
78
79
80 // Constructors +
81 public:
86
92 SHA1(const std::string& data);
93
99 SHA1(std::istream& stream);
100
101 private:
108 SHA1(const uint8_t* data, std::size_t len);
109 // Constructors -
110
111
112 // Destructor +
113 public:
117 virtual ~SHA1();
118 // Destructor -
119
120
121 // Methods +
122 public:
128 virtual const std::array<uint8_t,20>& digest() const override;
129
134 using Hash<20,64>::digest;
135
136 protected:
140 virtual void reset() override;
141
148 virtual void addData(const uint8_t* data, std::size_t len) override;
149
153 virtual void finalize() override;
154
155 private:
161 void transform(const uint8_t* buffer);
162 // Methods -
163
164 };
165
166 extern template class Hash<20,64>;
168 extern template SHA1 HMAC<SHA1>(const std::string&, const std::string&);
169
173 ANCH_CRYPTO_EXPORT void registerSHA1UUIDProvider();
174
175}
Hash algorithm abstract class.
Definition hash.hpp:40
SHA1 hash algorithm implementation.
Definition sha1.hpp:38
virtual void addData(const uint8_t *data, std::size_t len) override
SHA1(const std::string &data)
virtual void reset() override
virtual const std::array< uint8_t, 20 > & digest() const override
SHA1(std::istream &stream)
virtual void finalize() override
Cryptography namespace.
Definition base64.hpp:30
H HMAC(const std::string &, const std::string &)
template SHA1 HMAC< SHA1 >(const std::string &, const std::string &)
void registerSHA1UUIDProvider()