Skip to content

Commit

Permalink
Type checks and integer shift checked
Browse files Browse the repository at this point in the history
  • Loading branch information
AshishYUO committed Apr 10, 2021
1 parent 6c4fdc5 commit 276fde9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 11 additions & 9 deletions ciphers/uint128_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T, typename = typename std::enable_if<
std::is_integral<T>::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 {
Expand All @@ -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 <typename T, typename = typename std::enable_if<
Expand Down
6 changes: 2 additions & 4 deletions ciphers/uint256_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,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((this->s << (p - 128)), uint128_t(0));
}
return uint256_t((this->f << p) + (this->s >> (128 - p)),
Expand All @@ -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),
Expand Down

0 comments on commit 276fde9

Please sign in to comment.