From 6c4fdc53d15ad6f07360dc5f650855d5533dd24f Mon Sep 17 00:00:00 2001 From: Ashish Bhanu Daulatabad Date: Sun, 11 Apr 2021 00:01:01 +0530 Subject: [PATCH] Type checks and destructor added --- ciphers/elliptic_curve_key_exchange.cpp | 4 ++-- ciphers/uint128_t.hpp | 12 +++++++++--- ciphers/uint256_t.hpp | 7 ++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ciphers/elliptic_curve_key_exchange.cpp b/ciphers/elliptic_curve_key_exchange.cpp index 48a6630cd..c4b74b577 100644 --- a/ciphers/elliptic_curve_key_exchange.cpp +++ b/ciphers/elliptic_curve_key_exchange.cpp @@ -91,8 +91,8 @@ uint256_t exp(uint256_t number, uint256_t power, const uint256_t &mod) { * @return the resultant point */ Point addition(Point a, Point b, uint256_t curve_a_coeff, uint256_t mod) { - uint256_t lambda; /// Slope - uint256_t zero; /// value zero + uint256_t lambda(0); /// Slope + uint256_t zero(0); /// value zero lambda = zero = 0; uint256_t inf = ~zero; if (a.x != b.x || a.y != b.y) { diff --git a/ciphers/uint128_t.hpp b/ciphers/uint128_t.hpp index 910ebde90..5093133e7 100644 --- a/ciphers/uint128_t.hpp +++ b/ciphers/uint128_t.hpp @@ -37,8 +37,9 @@ struct std::is_unsigned : std::true_type {}; std::string add(const std::string &first, const std::string &second) { std::string third; int16_t sum = 0, carry = 0; - for (int i = first.size() - 1, j = second.size() - 1; i >= 0 || j >= 0; - --i, --j) { + for (int32_t i = static_cast(first.size()) - 1, + j = static_cast(second.size()) - 1; + i >= 0 || j >= 0; --i, --j) { sum = ((i >= 0 ? first[i] - '0' : 0) + (j >= 0 ? second[j] - '0' : 0) + carry); carry = sum / 10; @@ -125,6 +126,11 @@ class uint128_t { */ uint128_t(uint128_t &&num) : f(std::move(num.f)), s(std::move(num.s)) {} + /** + * @brief Destructor for uint128_t + */ + ~uint128_t() = default; + /** * @brief Leading zeroes in binary * @details Calculates leading zeros in 128-bit integer @@ -632,7 +638,7 @@ class uint128_t { if (!p) { return uint128_t(f, s); } - if (p >= 64) { + if (p >= 64 && p <= 128) { return uint128_t((this->s << (p - 64)), 0); } return uint128_t((this->f << p) + ((this->s >> (64 - p))), diff --git a/ciphers/uint256_t.hpp b/ciphers/uint256_t.hpp index 979543019..3e099577c 100644 --- a/ciphers/uint256_t.hpp +++ b/ciphers/uint256_t.hpp @@ -1,5 +1,5 @@ /** - * @file uint128_t.hpp + * @file uint256_t.hpp * * @details Implementation of 256-bit unsigned integers. * @note The implementation can be flagged as not completed. This header is used @@ -103,6 +103,11 @@ class uint256_t { */ uint256_t(const uint64_t high, const uint64_t low) : f(high), s(low) {} + /** + * @brief Destructor for uint256_t + */ + ~uint256_t() = default; + /** * @brief Leading zeroes in binary * @details Calculates leading zeros in 256-bit integer