AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
md5.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 MD5: public Hash<16,64> {
39
40 friend MD5 anch::crypto::HMAC<MD5>(const std::string&, const std::string&);
41
42 private:
43 struct Context {
45 uint32_t handle[2];
46
48 uint32_t buffer[4];
49
51 uint32_t input[16];
52
54 std::array<uint8_t,16> digest;
55
59 Context();
60
64 void reset();
65
66 };
67
68 // Attributes +
69 private:
71 Context _context;
72 // Attributes -
73
74 // Constructors +
75 public:
79 MD5();
80
86 MD5(const std::string& data);
87
93 MD5(std::istream& stream);
94
95 private:
102 MD5(const uint8_t* data, std::size_t len);
103 // Constructors -
104
105 // Destructor +
106 public:
110 virtual ~MD5();
111 // Destructor -
112
113 // Methods +
114 public:
120 virtual const std::array<uint8_t,16>& digest() const override;
121
126 using Hash<16,64>::digest;
127
128 protected:
132 virtual void reset() override;/* {
133 _context.reset();
134 }*/
135
142 virtual void addData(const uint8_t* data, std::size_t len) override;
143
147 virtual void finalize() override;
148
149 private:
153 void transform();
154 // Methods -
155
156 };
157
158 extern template class Hash<16,64>;
160 extern template MD5 HMAC<MD5>(const std::string&, const std::string&);
161
165 ANCH_CRYPTO_EXPORT void registerMD5UUIDProvider();
166
167}
Hash algorithm abstract class.
Definition hash.hpp:40
MD5 hash algorithm implementation.
Definition md5.hpp:38
virtual void reset() override
virtual const std::array< uint8_t, 16 > & digest() const override
MD5(std::istream &stream)
MD5(const std::string &data)
virtual void finalize() override
virtual void addData(const uint8_t *data, std::size_t len) override
Cryptography namespace.
Definition base64.hpp:30
H HMAC(const std::string &, const std::string &)
void registerMD5UUIDProvider()
template MD5 HMAC< MD5 >(const std::string &, const std::string &)