-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSHA1Debug.cpp
101 lines (92 loc) · 2.49 KB
/
SHA1Debug.cpp
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
94
95
96
97
98
99
100
101
//
// Created by lukas on 6/13/19.
//
#include "SHA1Debug.hpp"
#include "BlockFactory.hpp"
using namespace std;
SHA1Debug::SHA1Debug(std::string message) : SHA1() {
BlockFactory b = BlockFactory(message);
list<Block> blocks = b.getBlocks();
createHash(&blocks);
}
SHA1Debug::SHA1Debug(std::list<Block> *blocks) : SHA1(){
createHash(blocks);
}
void SHA1Debug::printX(std::array<uint,80> *x) {
cout << "X" << endl;
for(int i=0;i<80;i++){
cout << setfill('0') << setw(8) << hex << (*x)[i] << "\t";
if(i==19||i==39||i==59||i==79){
cout << endl;
}
}
}
void SHA1Debug::printH() {
cout << "H1 H2 H3 H4 H5" << endl;
cout << setfill('0') << setw(8) << hex << h1 << "\t";
cout << setfill('0') << setw(8) << hex << h2 << "\t";
cout << setfill('0') << setw(8) << hex << h3 << "\t";
cout << setfill('0') << setw(8) << hex << h4 << "\t";
cout << setfill('0') << setw(8) << hex << h5 << endl;
}
void SHA1Debug::printA() {
cout << "A B C D E" << endl;
cout << setfill('0') << setw(8) << hex << a << "\t";
cout << setfill('0') << setw(8) << hex << b << "\t";
cout << setfill('0') << setw(8) << hex << c << "\t";
cout << setfill('0') << setw(8) << hex << d << "\t";
cout << setfill('0') << setw(8) << hex << e << endl;
}
void SHA1Debug::createHash(std::list<Block> *blocks) {
for(auto const& block :*blocks){
cout << "Block" << endl;
cout << block;
// init a,b,c,d,e
cout << "Init" << endl;
printH();
printA();
a = h1;
b = h2;
c = h3;
d = h4;
e = h5;
printA();
// assign x
cout << "Assign x" << endl;
array<uint, 80> x = {0};
array<uint, 16> words = block.getWords();
for(int i=0;i<16;i++){
x[i] = words[i];
}
printX(&x);
// expand x
cout << "Expand x" << endl;
expansion(&x);
printX(&x);
// round 1,2,3,4
cout << "Round 1" << endl;
round1(&x);
printA();
printX(&x);
cout << "Round 2" << endl;
round2(&x);
printA();
printX(&x);
cout << "Round 3" << endl;
round3(&x);
printA();
printX(&x);
cout << "Round 4" << endl;
round4(&x);
printA();
printX(&x);
// new h
cout << "New h" << endl;
h1 += a;
h2 += b;
h3 += c;
h4 += d;
h5 += e;
printH();
}
}