Skip to content

Commit

Permalink
add missing bn_t initializations and keep only initializations for bn_t
Browse files Browse the repository at this point in the history
  • Loading branch information
tarakby authored and huitseeker committed Jul 12, 2021
1 parent 944b9c1 commit 6c68b77
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 16 deletions.
13 changes: 5 additions & 8 deletions crypto/bls.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,12 @@ type PubKeyBLSBLS12381 struct {
// If no scalar is provided, the function allocates an
// empty scalar.
func newPubKeyBLSBLS12381(p *pointG2) *PubKeyBLSBLS12381 {
var pk PubKeyBLSBLS12381
if p == nil {
// initialize the point
C.ep2_new_wrapper((*C.ep2_st)(&pk.point))
} else {
// set the point
pk.point = *p
if p != nil {
return &PubKeyBLSBLS12381{
point: *p,
}
}
return &pk
return &PubKeyBLSBLS12381{}
}

// Algorithm returns the Signing Algorithm
Expand Down
4 changes: 0 additions & 4 deletions crypto/bls12381_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ void bn_new_wrapper(bn_t a) {
bn_new(a);
}

void ep2_new_wrapper(ep2_t p) {
ep2_new(p);
}

// global variable of the pre-computed data
prec_st bls_prec_st;
prec_st* bls_prec = NULL;
Expand Down
1 change: 0 additions & 1 deletion crypto/bls12381_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ typedef struct prec_ {
int get_valid();
int get_invalid();
void bn_new_wrapper(bn_t a);
void ep2_new_wrapper(ep2_t p);

ctx_t* relic_init_BLS12_381();
prec_st* init_precomputed_data_BLS12_381();
Expand Down
4 changes: 2 additions & 2 deletions crypto/bls_multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func AggregateBLSPrivateKeys(keys []PrivateKey) (PrivateKey, error) {
}

var sum scalar

C.bn_new_wrapper((*C.bn_st)(&sum))
C.bn_sum_vector((*C.bn_st)(&sum), (*C.bn_st)(&scalars[0]),
(C.int)(len(scalars)))
return newPrKeyBLSBLS12381(&sum), nil
Expand Down Expand Up @@ -172,7 +172,7 @@ func NeutralBLSPublicKey() PublicKey {
// set BLS context
blsInstance.reInit()

var neutralPk PubKeyBLSBLS12381
neutralPk := *newPubKeyBLSBLS12381(nil)
// set the point to infinity
C.ep2_set_infty((*C.ep2_st)(&neutralPk.point))
return &neutralPk
Expand Down
2 changes: 2 additions & 0 deletions crypto/dkg_feldmanvss.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (s *feldmanVSSstate) init() {
s.y = nil
s.xReceived = false
s.vAReceived = false
C.bn_new_wrapper((*C.bn_st)(&s.x))
}

// Start starts running the protocol in the current node
Expand Down Expand Up @@ -236,6 +237,7 @@ func (s *feldmanVSSstate) generateShares(seed []byte) error {
randZrStar(&s.a[0]) // non zero a[0]
genScalarMultG2(&s.vA[0], &s.a[0])
for i := 1; i < s.threshold+1; i++ {
C.bn_new_wrapper((*C.bn_st)(&s.a[i]))
randZr(&s.a[i])
genScalarMultG2(&s.vA[i], &s.a[i])
}
Expand Down
4 changes: 3 additions & 1 deletion crypto/dkg_feldmanvssq.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ func (s *feldmanVSSQualState) receiveComplaintAnswer(origin index, data []byte)
}

// read the complainer private share
C.bn_new_wrapper((*C.bn_st)(&s.complaints[complainer].answer))
if C.bn_read_Zr_bin((*C.bn_st)(&s.complaints[complainer].answer),
(*C.uchar)(&data[1]),
PrKeyLenBLSBLS12381,
Expand All @@ -577,9 +578,10 @@ func (s *feldmanVSSQualState) receiveComplaintAnswer(origin index, data []byte)
}
c.answerReceived = true

// first flag check is a sanity check
// flag check is a sanity check
if c.received {
// read the complainer private share
C.bn_new_wrapper((*C.bn_st)(&c.answer))
if C.bn_read_Zr_bin((*C.bn_st)(&c.answer),
(*C.uchar)(&data[1]),
PrKeyLenBLSBLS12381,
Expand Down
1 change: 1 addition & 0 deletions crypto/dkg_jointfeldman.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func (s *JointFeldmanState) sumUpQualifiedKeys(qualified int) (*scalar, *pointG2

// sum up x
var jointx scalar
C.bn_new_wrapper((*C.bn_st)(&jointx))
C.bn_sum_vector((*C.bn_st)(&jointx), (*C.bn_st)(&qualifiedx[0]),
(C.int)(qualified))
// sum up Y
Expand Down

0 comments on commit 6c68b77

Please sign in to comment.