28
28
#include < iomanip> // / For functions like std::setw, std::setfill
29
29
#include < iostream> // / For managing io
30
30
#include < sstream> // / For bytes to hex string
31
- #include < string> // / For string data
32
- #include < thread> // / To parallelize for efficiency
33
- #include < vector> // / For dynamic arrays
31
+ #include < stdexcept> // / For standard exceptions like std::runtime_error
32
+ #include < string> // / For string data
33
+ #include < thread> // / To parallelize for efficiency
34
+ #include < vector> // / For dynamic arrays
34
35
35
36
/* *
36
37
* @namespace hashing
@@ -49,6 +50,7 @@ class RIPEMD160 {
49
50
* @param j Round number j / 16
50
51
* @param B,C,D The state values
51
52
* @return Returns the function value
53
+ * @note 0 <= j <= 4
52
54
*/
53
55
uint32_t f (int j, uint32_t B, uint32_t C, uint32_t D) {
54
56
switch (j) {
@@ -63,12 +65,15 @@ class RIPEMD160 {
63
65
case 4 :
64
66
return B ^ (C | ~D);
65
67
}
68
+
69
+ throw std::runtime_error (" j value out of bound" );
66
70
}
67
71
68
72
/* *
69
73
* @brief Implements K value for a given j
70
74
* @param j Round number j / 16
71
75
* @return Appropriate K value
76
+ * @note 0 <= j <= 4
72
77
*/
73
78
uint32_t K (int j) {
74
79
switch (j) {
@@ -83,12 +88,15 @@ class RIPEMD160 {
83
88
case 4 :
84
89
return static_cast <uint32_t >(0xA953FD4E );
85
90
}
91
+
92
+ throw std::runtime_error (" j value out of bound" );
86
93
}
87
94
88
95
/* *
89
96
* @brief Implements K' value for a given j
90
97
* @param j Round number j / 16
91
98
* @return Appropriate K' value
99
+ * @note 0 <= j <= 4
92
100
*/
93
101
uint32_t K_dash (int j) {
94
102
switch (j) {
@@ -103,6 +111,8 @@ class RIPEMD160 {
103
111
case 4 :
104
112
return 0x00000000 ;
105
113
}
114
+
115
+ throw std::runtime_error (" j value out of bound" );
106
116
}
107
117
108
118
/* *
0 commit comments