-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
93 lines (84 loc) · 3.03 KB
/
main.cpp
File metadata and controls
93 lines (84 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <openssl/sha.h>
#include "Hash.hpp"
int main() {
std::string message = "it is helloworld,and after tomorrow day.";
{
auto start = std::chrono::system_clock::now();
unsigned char digest[SHA256_DIGEST_LENGTH];
SHA256_CTX sha_ctx;
SHA256_Init(&sha_ctx); // コンテキストを初期化
SHA256_Update(&sha_ctx, message.c_str(),
message.size()); // message を入力にする
SHA256_Final(digest, &sha_ctx); // digest に出力
auto end = std::chrono::system_clock::now();
double elapsed =
std::chrono::duration_cast<std::chrono::nanoseconds>(end - start)
.count();
std::cout << elapsed << " nano seconds " << std::endl;
for (int i = 0; i < sizeof(digest); ++i) {
std::cout << std::setfill('0') << std::setw(2) << std::hex
<< static_cast<unsigned int>(digest[i]);
// printf("%x", digest[i]);
}
std::cout << std::endl;
// 処理
}
{
auto start = std::chrono::system_clock::now();
using namespace sha;
auto hash = Hash<sha256>::createHash(message);
auto [seed, hashArray] = hash();
// std::cout << "seed is " << seed << std::endl;
auto end = std::chrono::system_clock::now();
double elapsed =
std::chrono::duration_cast<std::chrono::nanoseconds>(end - start)
.count();
std::cout << elapsed << " nano seconds " << std::endl;
for (int i = 0; i < hashArray.size(); ++i) {
std::cout << std::hex << std::setfill('0') << std::setw(8)
<< hashArray[i];
}
std::cout << std::endl;
}
{
std::string message = "";
auto start = std::chrono::system_clock::now();
unsigned char hash[SHA512_DIGEST_LENGTH];
SHA512_CTX c;
SHA512_Init(&c);
SHA512_Update(&c, message.c_str(), message.size());
SHA512_Final(hash, &c);
auto end = std::chrono::system_clock::now();
double elapsed =
std::chrono::duration_cast<std::chrono::nanoseconds>(end - start)
.count();
std::cout << elapsed << " nano seconds " << std::endl;
std::cout << "size is " << sizeof(hash) << std::endl;
for (int i = 0; i < sizeof(hash); ++i) {
std::cout << std::setfill('0') << std::setw(2) << std::hex
<< static_cast<unsigned int>(hash[i]);
// printf("%x", digest[i]);
}
std::cout << std::endl;
// 処理
}
{
auto start = std::chrono::system_clock::now();
using namespace sha;
auto hash = Hash<sha512>::createHash("");
auto [seed, hashArray] = hash();
// std::cout << "seed is " << seed << std::endl;
auto end = std::chrono::system_clock::now();
double elapsed =
std::chrono::duration_cast<std::chrono::nanoseconds>(end - start)
.count();
std::cout << elapsed << " nano seconds " << std::endl;
std::cout << "size is " << hashArray.size() << std::endl;
for (int i = 0; i < hashArray.size(); ++i) {
std::cout << std::setfill('0') << std::setw(16) << std::hex
<< hashArray[i] << std::endl;
}
std::cout << std::endl;
}
return 0;
}