fix(big): correct large divisor handling in Div

This commit is contained in:
fallenoak 2023-02-06 22:15:20 -06:00
parent 847352659f
commit 181ef114e4
No known key found for this signature in database
GPG key ID: 7628F8E61AEA070D
2 changed files with 34 additions and 1 deletions

View file

@ -59,7 +59,8 @@ void Div(BigBuffer& a, BigBuffer& b, const BigBuffer& c, const BigBuffer& d, Big
auto dCount = d.Count();
if (dCount > cCount) {
SetZero(b = c);
b = c;
SetZero(a);
return;
}

View file

@ -921,6 +921,38 @@ TEST_CASE("PowMod", "[big]") {
SBigDel(c);
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]") {