mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
fix(big): correct large divisor handling in Div
This commit is contained in:
parent
847352659f
commit
181ef114e4
2 changed files with 34 additions and 1 deletions
|
|
@ -59,7 +59,8 @@ void Div(BigBuffer& a, BigBuffer& b, const BigBuffer& c, const BigBuffer& d, Big
|
||||||
auto dCount = d.Count();
|
auto dCount = d.Count();
|
||||||
|
|
||||||
if (dCount > cCount) {
|
if (dCount > cCount) {
|
||||||
SetZero(b = c);
|
b = c;
|
||||||
|
SetZero(a);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -921,6 +921,38 @@ TEST_CASE("PowMod", "[big]") {
|
||||||
SBigDel(c);
|
SBigDel(c);
|
||||||
SBigDel(d);
|
SBigDel(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("takes 0xABCDEF1234567890 to the 16th power and mods the result by 0xEEEE000000000001") {
|
||||||
|
BigData* a;
|
||||||
|
SBigNew(&a);
|
||||||
|
|
||||||
|
BigData* b;
|
||||||
|
SBigNew(&b);
|
||||||
|
uint64_t b_ = 0xABCDEF1234567890;
|
||||||
|
SBigFromBinary(b, reinterpret_cast<uint8_t*>(&b_), sizeof(b_));
|
||||||
|
|
||||||
|
BigData* c;
|
||||||
|
SBigNew(&c);
|
||||||
|
SBigFromUnsigned(c, 16);
|
||||||
|
|
||||||
|
BigData* d;
|
||||||
|
SBigNew(&d);
|
||||||
|
uint64_t d_ = 0xEEEE000000000001;
|
||||||
|
SBigFromBinary(d, reinterpret_cast<uint8_t*>(&d_), sizeof(d_));
|
||||||
|
|
||||||
|
PowMod(a->Primary(), b->Primary(), c->Primary(), d->Primary(), a->Stack());
|
||||||
|
|
||||||
|
a->Primary().Trim();
|
||||||
|
|
||||||
|
CHECK(a->Primary().Count() == 2);
|
||||||
|
CHECK(a->Primary()[0] == 0x950A5465);
|
||||||
|
CHECK(a->Primary()[1] == 0xA0CB742F);
|
||||||
|
|
||||||
|
SBigDel(a);
|
||||||
|
SBigDel(b);
|
||||||
|
SBigDel(c);
|
||||||
|
SBigDel(d);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SetOne", "[big]") {
|
TEST_CASE("SetOne", "[big]") {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue