Enigma 3.2.2
A Simple, Reliable and Efficient Encryption Tool
Loading...
Searching...
No Matches
HashingTool.hpp
Go to the documentation of this file.
1#pragma once
2#include "Tool.hpp"
3#include <Core/Core.hpp>
4#include <imgui.h>
5
6#include <cryptlib.h>
7//#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
8#include <files.h> // CryptoPP::FileSink
9#include <hex.h> // CryptoPP::HexEncoder
10#include <keccak.h> // Keccak
11#include <md2.h> // MD2
12#include <md4.h> // MD4
13#include <md5.h> // MD5
14#include <sha.h> // SHA1, SHA244, SHA256, SHA384, SHA512
15#include <shake.h> // Shake
16#include <tiger.h> // Tiger
17#include <whrlpool.h> // Whirlpool
18#include <sm3.h> // SM3
19#include <ripemd.h> // RIPEMD128,RIPEMD160,RIPEMD256,RIPEMD320
20
21/*
22* Hashing Tool Collapsing Header View To be drawn in ToolsScene
23*/
25class HashingTool : public Tool {
26 enum class HashAlgorithm : byte {
27 MD2 = 0x00,
28 MD4,
29 MD5,
30
31 SHA1,
32 SHA224,
33 SHA256,
34 SHA384,
35 SHA512,
36
37 SHAKE128,
38 SHAKE256,
39
40 KECCAK224,
41 KECCAK256,
42 KECCAK384,
43 KECCAK512,
44
45 RIPEMD128,
46 RIPEMD160,
47 RIPEMD256,
48 RIPEMD320,
49
50 TIGER,
51 WHIRLPOOL,
52 SM3,
53
55 };
56 friend const char *operator*(const HashAlgorithm hash_algo) noexcept // stringify HashAlgorithm enum for radio buttons
57 {
58#define CASE_RET(c) \
59 case HashingTool::HashAlgorithm::c: \
60 return #c
61 switch (hash_algo) {
62 CASE_RET(MD2);
63 CASE_RET(MD4);
64 CASE_RET(MD5);
65
66 CASE_RET(SHA1);
67 CASE_RET(SHA224);
68 CASE_RET(SHA256);
69 CASE_RET(SHA384);
70 CASE_RET(SHA512);
71
72 CASE_RET(SHAKE128);
73 CASE_RET(SHAKE256);
74
75 CASE_RET(KECCAK224);
76 CASE_RET(KECCAK256);
77 CASE_RET(KECCAK384);
78 CASE_RET(KECCAK512);
79
80 CASE_RET(RIPEMD128);
81 CASE_RET(RIPEMD160);
82 CASE_RET(RIPEMD256);
83 CASE_RET(RIPEMD320);
84
85 CASE_RET(TIGER);
86 CASE_RET(WHIRLPOOL);
87 CASE_RET(SM3);
88
89 default:
90 return "<unknown hash algorithm>";
91 };
92#undef CASE_RET
93 }
94
95 public:
96 HashingTool() = default;
97 ~HashingTool() = default;
98
99 public: /* Tool Life Cycle */
100 void OnCreate() override;
101 void OnDraw(Scene *parent) override;
102 void OnDestroy() override;
103
104 private: /* Callbacks */
105 void OnCalculateHashButtonPressed();
106 void OnCopyHashButtonPressed();
107
108 private: /* Hash Algorithms */
109 enum class InputSource : byte {
110 Text,
111 File,
113 } m_input_source = InputSource::Text;
114 static const char *inputSourceEnumToStr(InputSource is) {
115 switch (is) {
116 default:
117 case InputSource::Text:
118 return "Text";
119 case InputSource::File:
120 return "File";
121 }
122 }
123
124 std::string m_input{}; // text to calculate hash for (Message) or input file
125 std::string m_output{}; // calculated hash (Digest)
126
127 HashAlgorithm m_selected_hash; // Radio buttons selected hash algorithm
128 std::unique_ptr<CryptoPP::Weak::MD2> m_md2{nullptr};
129 std::unique_ptr<CryptoPP::Weak::MD4> m_md4{nullptr};
130 std::unique_ptr<CryptoPP::Weak::MD5> m_md5{nullptr};
131
132 std::unique_ptr<CryptoPP::SHA1> m_sha1{nullptr};
133 std::unique_ptr<CryptoPP::SHA224> m_sha224{nullptr};
134 std::unique_ptr<CryptoPP::SHA256> m_sha256{nullptr};
135 std::unique_ptr<CryptoPP::SHA384> m_sha384{nullptr};
136 std::unique_ptr<CryptoPP::SHA512> m_sha512{nullptr};
137
138 std::unique_ptr<CryptoPP::Keccak_224> m_keccak224{nullptr};
139 std::unique_ptr<CryptoPP::Keccak_256> m_keccak256{nullptr};
140 std::unique_ptr<CryptoPP::Keccak_384> m_keccak384{nullptr};
141 std::unique_ptr<CryptoPP::Keccak_512> m_keccak512{nullptr};
142
143 std::unique_ptr<CryptoPP::SHAKE128> m_shake128{nullptr};
144 std::unique_ptr<CryptoPP::SHAKE256> m_shake256{nullptr};
145
146 std::unique_ptr<CryptoPP::RIPEMD128> m_ripemd128{nullptr};
147 std::unique_ptr<CryptoPP::RIPEMD160> m_ripemd160{nullptr};
148 std::unique_ptr<CryptoPP::RIPEMD256> m_ripemd256{nullptr};
149 std::unique_ptr<CryptoPP::RIPEMD320> m_ripemd320{nullptr};
150
151 std::unique_ptr<CryptoPP::Tiger> m_tiger{nullptr};
152 std::unique_ptr<CryptoPP::Whirlpool> m_whirlpool{nullptr};
153 std::unique_ptr<CryptoPP::SM3> m_sm3{nullptr};
154
155};
#define CASE_RET(c)
#define NS_ENIGMA_BEGIN
Enable/Disable Assertions.
Definition Macros.hpp:13
#define NS_ENIGMA_END
Definition Macros.hpp:14
#define ENIGMA_ENUM_DECLARE_BEGIN_END(begin)
Allows looping over an enum by providing a BEGIN and END enum values NOTE: should be placed at the en...
Definition Macros.hpp:148
void OnDraw(Scene *parent) override
HashingTool()=default
void OnDestroy() override
void OnCreate() override
friend const char * operator*(const HashAlgorithm hash_algo) noexcept
~HashingTool()=default
Definition Tool.hpp:10