Skip to content
2 changes: 1 addition & 1 deletion src/libSchnorr/src/MultiSig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ bool MultiSig::MultiSigVerify(const bytes& message, unsigned int offset,
return false;
}
err2 = (BN_nnmod(challenge_built.get(), challenge_built.get(),
Schnorr::GetCurveOrder(), NULL) == 0);
Schnorr::GetCurveOrder(), ctx.get()) == 0);
err = err || err2;
if (err2) {
// Challenge rebuild mod failed
Expand Down
8 changes: 7 additions & 1 deletion src/libSchnorr/src/MultiSig_Challenge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ void Challenge::Set(const CommitPoint& aggregatedCommit,

bytes buf(Schnorr::PUBKEY_COMPRESSED_SIZE_BYTES);

unique_ptr<BN_CTX, void (*)(BN_CTX*)> ctx(BN_CTX_new(), BN_CTX_free);
if (!ctx) {
throw std::bad_alloc();
}

// Convert the committment to octets first
if (EC_POINT_point2oct(Schnorr::GetCurveGroup(), aggregatedCommit.m_p.get(),
POINT_CONVERSION_COMPRESSED, buf.data(),
Expand Down Expand Up @@ -166,7 +171,8 @@ void Challenge::Set(const CommitPoint& aggregatedCommit,
return;
}

if (BN_nnmod(m_c.get(), m_c.get(), Schnorr::GetCurveOrder(), NULL) == 0) {
if (BN_nnmod(m_c.get(), m_c.get(), Schnorr::GetCurveOrder(), ctx.get()) ==
0) {
// Could not reduce challenge modulo group order
return;
}
Expand Down
7 changes: 6 additions & 1 deletion src/libSchnorr/src/MultiSig_CommitPointHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ void CommitPointHash::Set(const CommitPoint& point) {
// byte to 0x01.
sha2.Update({SECOND_DOMAIN_SEPARATED_HASH_FUNCTION_BYTE});

unique_ptr<BN_CTX, void (*)(BN_CTX*)> ctx(BN_CTX_new(), BN_CTX_free);
if (!ctx) {
throw std::bad_alloc();
}
// Convert the commitment to octets first
if (EC_POINT_point2oct(Schnorr::GetCurveGroup(), point.m_p.get(),
POINT_CONVERSION_COMPRESSED, buf.data(),
Expand All @@ -123,7 +127,8 @@ void CommitPointHash::Set(const CommitPoint& point) {
return;
}

if (BN_nnmod(m_h.get(), m_h.get(), Schnorr::GetCurveOrder(), NULL) == 0) {
if (BN_nnmod(m_h.get(), m_h.get(), Schnorr::GetCurveOrder(), ctx.get()) ==
0) {
// Could not reduce hashpoint value modulo group order
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libSchnorr/src/Schnorr_PubKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool PubKey::Serialize(bytes& dst, unsigned int offset) const {

bool PubKey::Deserialize(const bytes& src, unsigned int offset) {
shared_ptr<EC_POINT> result =
ECPOINTSerialize::GetNumber(src, offset, PUB_KEY_SIZE);
ECPOINTSerialize::GetNumber(src, offset, src.size());

if (result == nullptr) {
// ECPOINTSerialize::GetNumber failed
Expand Down