Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
13 changes: 12 additions & 1 deletion src/libSchnorr/src/MultiSig_CommitPointHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "MultiSig.h"
#include "SchnorrInternal.h"
#include <iostream>

using namespace std;

Expand All @@ -32,6 +33,9 @@ CommitPointHash::CommitPointHash()

CommitPointHash::CommitPointHash(const CommitPoint& point)
: m_h(BN_new(), BN_clear_free), m_initialized(false) {


std::cerr << "debug print" << std::endl;
if (!constructPreChecks()) {
// Memory allocation failure
throw std::bad_alloc();
Expand Down Expand Up @@ -104,6 +108,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 +131,10 @@ void CommitPointHash::Set(const CommitPoint& point) {
return;
}

if (BN_nnmod(m_h.get(), m_h.get(), Schnorr::GetCurveOrder(), NULL) == 0) {
std::cerr << "KILME" << std::endl;

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
3 changes: 2 additions & 1 deletion src/libSchnorr/src/Schnorr_PubKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ 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());
Copy link
Author

Choose a reason for hiding this comment

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

when the size of src was not PUB_KEY_SIZE this would fail. However if you allow compressed and uncompressed signatures your pub key size could vary.


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