AnCH Framework 0.1
Another C++ Hack Framework
 
Loading...
Searching...
No Matches
sha1.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 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 <http://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include "crypto/hash/hash.hpp"
23
24
25namespace anch::crypto {
26
27 template<typename H> H HMAC(const std::string&, const std::string&);
28
36 class SHA1: public Hash<20,64> {
37
38 friend SHA1 anch::crypto::HMAC<SHA1>(const std::string&, const std::string&);
39
40 private:
46 struct Context {
48 std::array<uint32_t,5> state;
49
51 uint64_t size;
52
54 std::array<uint8_t,64> buffer;
55
57 std::array<uint8_t,20> digest;
58
62 Context();
63
67 void reset();
68
69 };
70
71 // Attributes +
72 private:
74 Context _context;
75 // Attributes -
76
77
78 // Constructors +
79 public:
84
90 SHA1(const std::string& data);
91
97 SHA1(std::istream& stream);
98
99 private:
106 SHA1(const uint8_t* data, std::size_t len);
107 // Constructors -
108
109
110 // Destructor +
111 public:
115 virtual ~SHA1();
116 // Destructor -
117
118
119 // Methods +
120 public:
126 virtual const std::array<uint8_t,20>& digest() const override;
127
128 protected:
132 virtual void reset() override;
133
140 virtual void addData(const uint8_t* data, std::size_t len) override;
141
145 virtual void finalize() override;
146
147 private:
153 void transform(const uint8_t* buffer);
154 // Methods -
155
156 };
157
158 extern template class Hash<20,64>;
160 extern template SHA1 HMAC<SHA1>(const std::string&, const std::string&);
161
166
167}
Hash algorithm abstract class.
Definition hash.hpp:38
SHA1 hash algorithm implementation.
Definition sha1.hpp:36
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:28
H HMAC(const std::string &, const std::string &)
template SHA1 HMAC< SHA1 >(const std::string &, const std::string &)
void registerSHA1UUIDProvider()