]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sha256.cpp
Convert m_sha256 to use a vendored library instead of bundling.
[user/henk/code/inspircd.git] / src / modules / m_sha256.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7  *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
8  *
9  * This file is part of InspIRCd.  InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 /// $CompilerFlags: -Ivendor_directory("sha2")
23 /// $CompilerFlags: require_compiler("GCC") -Wno-long-long
24
25
26 // Fix warnings about the use of `long long` on C++03.
27 #if defined __clang__
28 # pragma clang diagnostic ignored "-Wc++11-long-long"
29 #elif defined __GNUC__
30 # pragma GCC diagnostic ignored "-Wlong-long"
31 #endif
32
33 #include "inspircd.h"
34 #include "modules/hash.h"
35
36 #include <sha2.c>
37
38 class HashSHA256 : public HashProvider
39 {
40  public:
41         std::string GenerateRaw(const std::string& data) CXX11_OVERRIDE
42         {
43                 unsigned char bytes[SHA256_DIGEST_SIZE];
44                 sha256((unsigned char*)data.data(), data.length(),  bytes);
45                 return std::string((char*)bytes, SHA256_DIGEST_SIZE);
46         }
47
48         HashSHA256(Module* parent)
49                 : HashProvider(parent, "sha256", 32, 64)
50         {
51         }
52 };
53
54 class ModuleSHA256 : public Module
55 {
56         HashSHA256 sha;
57  public:
58         ModuleSHA256() : sha(this)
59         {
60         }
61
62         Version GetVersion() CXX11_OVERRIDE
63         {
64                 return Version("Implements SHA-256 hashing", VF_VENDOR);
65         }
66 };
67
68 MODULE_INIT(ModuleSHA256)