Skip to content

Commit 6c4fdc5

Browse files
committed
Type checks and destructor added
1 parent 2001c91 commit 6c4fdc5

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

ciphers/elliptic_curve_key_exchange.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ uint256_t exp(uint256_t number, uint256_t power, const uint256_t &mod) {
9191
* @return the resultant point
9292
*/
9393
Point addition(Point a, Point b, uint256_t curve_a_coeff, uint256_t mod) {
94-
uint256_t lambda; /// Slope
95-
uint256_t zero; /// value zero
94+
uint256_t lambda(0); /// Slope
95+
uint256_t zero(0); /// value zero
9696
lambda = zero = 0;
9797
uint256_t inf = ~zero;
9898
if (a.x != b.x || a.y != b.y) {

ciphers/uint128_t.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ struct std::is_unsigned<uint128_t> : std::true_type {};
3737
std::string add(const std::string &first, const std::string &second) {
3838
std::string third;
3939
int16_t sum = 0, carry = 0;
40-
for (int i = first.size() - 1, j = second.size() - 1; i >= 0 || j >= 0;
41-
--i, --j) {
40+
for (int32_t i = static_cast<int32_t>(first.size()) - 1,
41+
j = static_cast<int32_t>(second.size()) - 1;
42+
i >= 0 || j >= 0; --i, --j) {
4243
sum = ((i >= 0 ? first[i] - '0' : 0) + (j >= 0 ? second[j] - '0' : 0) +
4344
carry);
4445
carry = sum / 10;
@@ -125,6 +126,11 @@ class uint128_t {
125126
*/
126127
uint128_t(uint128_t &&num) : f(std::move(num.f)), s(std::move(num.s)) {}
127128

129+
/**
130+
* @brief Destructor for uint128_t
131+
*/
132+
~uint128_t() = default;
133+
128134
/**
129135
* @brief Leading zeroes in binary
130136
* @details Calculates leading zeros in 128-bit integer
@@ -632,7 +638,7 @@ class uint128_t {
632638
if (!p) {
633639
return uint128_t(f, s);
634640
}
635-
if (p >= 64) {
641+
if (p >= 64 && p <= 128) {
636642
return uint128_t((this->s << (p - 64)), 0);
637643
}
638644
return uint128_t((this->f << p) + ((this->s >> (64 - p))),

ciphers/uint256_t.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @file uint128_t.hpp
2+
* @file uint256_t.hpp
33
*
44
* @details Implementation of 256-bit unsigned integers.
55
* @note The implementation can be flagged as not completed. This header is used
@@ -103,6 +103,11 @@ class uint256_t {
103103
*/
104104
uint256_t(const uint64_t high, const uint64_t low) : f(high), s(low) {}
105105

106+
/**
107+
* @brief Destructor for uint256_t
108+
*/
109+
~uint256_t() = default;
110+
106111
/**
107112
* @brief Leading zeroes in binary
108113
* @details Calculates leading zeros in 256-bit integer

0 commit comments

Comments
 (0)