Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused a SEGV when running ubuntu 20.04 - the API for bignum indicates that this argument should be provided. It is a scratch variable:

https://linux.die.net/man/3/bn_nnmod

For all functions, ctx is a previously allocated BN_CTX used for temporary variables;

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);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allocate temporary ctx variable here

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