diff --git a/ciphers/uint128_t.hpp b/ciphers/uint128_t.hpp index 5093133e7..9db50bbdb 100644 --- a/ciphers/uint128_t.hpp +++ b/ciphers/uint128_t.hpp @@ -637,19 +637,20 @@ class uint128_t { uint128_t operator<<(const T p) { if (!p) { return uint128_t(f, s); - } - if (p >= 64 && p <= 128) { + } else if (p >= 64 && p <= 128) { return uint128_t((this->s << (p - 64)), 0); + } else if (p < 64 && p > 0) { + return uint128_t((this->f << p) + ((this->s >> (64 - p))), + this->s << p); } - return uint128_t((this->f << p) + ((this->s >> (64 - p))), - this->s << p); + return uint128_t(0); } template ::value, T>::type> uint128_t &operator<<=(const T p) { if (p) { - if (p >= 64) { + if (p >= 64 && p <= 128) { this->f = (this->s << (p - 64)); this->s = 0; } else { @@ -665,12 +666,13 @@ class uint128_t { uint128_t operator>>(const T p) { if (!p) { return uint128_t(this->f, this->s); - } - if (p >= 64) { + } else if (p >= 64 && p <= 128) { return uint128_t(0, (this->f >> (p - 64))); + } else if (p < 64 && p > 0) { + return uint128_t((this->f >> p), + (this->s >> p) + (this->f << (64 - p))); } - return uint128_t((this->f >> p), - (this->s >> p) + (this->f << (64 - p))); + return uint128_t(0); } template f, this->s); - } - if (p >= 128) { + } else if (p >= 128) { return uint256_t((this->s << (p - 128)), uint128_t(0)); } return uint256_t((this->f << p) + (this->s >> (128 - p)), @@ -625,8 +624,7 @@ class uint256_t { uint256_t operator>>(const T &p) { if (!p) { return uint256_t(this->f, this->s); - } - if (p >= 128) { + } else if (p >= 128) { return uint256_t(uint128_t(0), (this->f >> (p - 128))); } return uint256_t((this->f >> p),