From 54f500f29bc7d78abc60ab2d2bbede69a3c81c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Wed, 16 Jun 2021 12:56:30 -0400 Subject: [PATCH 1/5] Update relic to 9206ae50b667de160fcc385ba3dc2c920143ab0a MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The diff contains: - a lot of changes that concern parts of the library we don't use (other curves a la BN, BLS24-X, BLS12-383 ...), integer protocols (ETRS), field extension machinery ... - otherwise irrelevant changes, e.g. CI/CD - some memory bug fixing [Full Changeset](https://github.com/relic-toolkit/relic/compare/7a9bba7f..9206ae5) **Fixed bugs:** - Unexpected failure of ep2\_mul\[\_lwnaf\] above the prime group order [\#64](https://github.com/relic-toolkit/relic/issues/64) **Closed issues:** - Other way to construct towered extension fields [\#203](https://github.com/relic-toolkit/relic/issues/203) - blake2.h:101:5: error: size of array element is not a multiple of its alignment [\#202](https://github.com/relic-toolkit/relic/issues/202) - ECIES 160bit [\#201](https://github.com/relic-toolkit/relic/issues/201) - Compilation with "ARITH gmp" fails [\#200](https://github.com/relic-toolkit/relic/issues/200) - Support for armv8-a ? [\#198](https://github.com/relic-toolkit/relic/issues/198) - Function name bn\_init conflicts with OpenSSL when used in tandem [\#196](https://github.com/relic-toolkit/relic/issues/196) - 16-bit MSP430 [\#193](https://github.com/relic-toolkit/relic/issues/193) - Modular exponentiation returns 1 if exponent is 0 and modulo is 1 [\#185](https://github.com/relic-toolkit/relic/issues/185) - Compilation of RELIC with bls12-446 and bls12-455 fails [\#182](https://github.com/relic-toolkit/relic/issues/182) - test\_bn fails with BLS12-381 preset [\#181](https://github.com/relic-toolkit/relic/issues/181) - \[BUG\] undefined reference to `bench_init', `bench\_clean' [\#180](https://github.com/relic-toolkit/relic/issues/180) - Tests FTBFS because of missing symbol in header [\#179](https://github.com/relic-toolkit/relic/issues/179) - Builds are broken [\#178](https://github.com/relic-toolkit/relic/issues/178) - compile error inlining failed in call to always\_inline ‘\_mm\_alignr\_epi8’ on unbantu20.04 gcc9 [\#177](https://github.com/relic-toolkit/relic/issues/177) - bn\_write\_str buffer overflow [\#176](https://github.com/relic-toolkit/relic/issues/176) - ECDSA verify succeeds when it should fail [\#175](https://github.com/relic-toolkit/relic/issues/175) - ec\_mul\_gen hangs with curve SECG\_K256 [\#174](https://github.com/relic-toolkit/relic/issues/174) - Wrong square root computation [\#173](https://github.com/relic-toolkit/relic/issues/173) - Out-of-bounds read via bn\_sqr\_basic [\#172](https://github.com/relic-toolkit/relic/issues/172) - OSS-Fuzz integration [\#171](https://github.com/relic-toolkit/relic/issues/171) - Building Relic with Curve NIST\_P256 throws FATAL ERROR in relic\_fp\_prime.c:120 [\#170](https://github.com/relic-toolkit/relic/issues/170) - Compressing \(packing\) a point to binary array does not comply with X9.62 standard [\#169](https://github.com/relic-toolkit/relic/issues/169) - ‘ctx\_t’ {aka ‘struct \_ctx\_t’} has no member named ‘total’ [\#168](https://github.com/relic-toolkit/relic/issues/168) - relic does not work with C++ [\#167](https://github.com/relic-toolkit/relic/issues/167) - Memory leak in ep2\_curve\_init/clean with ALLOC=DYNAMIC [\#166](https://github.com/relic-toolkit/relic/issues/166) - \*\_is\_valid\(\) functions produce false negative for not normalized points [\#147](https://github.com/relic-toolkit/relic/issues/147) - Bench and Test doesnt build [\#122](https://github.com/relic-toolkit/relic/issues/122) **Merged pull requests:** - Add pairing delegation protocols [\#199](https://github.com/relic-toolkit/relic/pull/199) ([dfaranha](https://github.com/dfaranha)) - Fix support for Win64/MSVC targets. [\#197](https://github.com/relic-toolkit/relic/pull/197) ([dfaranha](https://github.com/dfaranha)) - Simplify generator getting for Gt. [\#194](https://github.com/relic-toolkit/relic/pull/194) ([luozejiaqun](https://github.com/luozejiaqun)) - cmake: Always use user defined CFLAGS, not only for release builds [\#187](https://github.com/relic-toolkit/relic/pull/187) ([xdustinface](https://github.com/xdustinface)) - Fix MinGW build [\#186](https://github.com/relic-toolkit/relic/pull/186) ([xdustinface](https://github.com/xdustinface)) - Remove debug printf in bn\_mxp\_slide [\#184](https://github.com/relic-toolkit/relic/pull/184) ([guidovranken](https://github.com/guidovranken)) - Remove ALLOC = STACK to simplify memory allocation. [\#183](https://github.com/relic-toolkit/relic/pull/183) ([dfaranha](https://github.com/dfaranha)) - Update relic\_alloc.h [\#165](https://github.com/relic-toolkit/relic/pull/165) ([aguycalled](https://github.com/aguycalled)) - Add correct support for FreeBSD and NetBSD [\#164](https://github.com/relic-toolkit/relic/pull/164) ([hoffmang9](https://github.com/hoffmang9)) --- crypto/relic | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/relic b/crypto/relic index 7a9bba7fea0..9206ae50b66 160000 --- a/crypto/relic +++ b/crypto/relic @@ -1 +1 @@ -Subproject commit 7a9bba7fea01b022e8874f1b1ba7af19f06fa025 +Subproject commit 9206ae50b667de160fcc385ba3dc2c920143ab0a From 0b896c8a75871ed52da95cce2e01477cf5b43bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Fri, 25 Jun 2021 10:49:25 -0400 Subject: [PATCH 2/5] update relic tag in build_dependency script --- crypto/build_dependency.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/build_dependency.sh b/crypto/build_dependency.sh index c0e10d0af7a..30b9a811c6c 100644 --- a/crypto/build_dependency.sh +++ b/crypto/build_dependency.sh @@ -3,7 +3,7 @@ set -euo pipefail # relic version or tag -relic_version="7a9bba7f" +relic_version="9206ae50" rm -rf relic From 1fabd27ccd4ad0cddfdce21e0b9db1435ef3a0c2 Mon Sep 17 00:00:00 2001 From: Tarak Ben Youssef Date: Fri, 9 Jul 2021 11:43:46 -0700 Subject: [PATCH 3/5] update relic version and fix a breaking change --- crypto/bls.go | 20 +++++++++++++------- crypto/bls12381_utils.c | 15 ++++++++++++--- crypto/bls12381_utils.h | 3 ++- crypto/relic_build.sh | 2 +- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/crypto/bls.go b/crypto/bls.go index d609aac710f..a29b24f9a4b 100644 --- a/crypto/bls.go +++ b/crypto/bls.go @@ -171,10 +171,7 @@ func (a *blsBLS12381Algo) generatePrivateKey(seed []byte) (PrivateKey, error) { KeyGenSeedMaxLenBLSBLS12381) } - sk := &PrKeyBLSBLS12381{ - // public key is only computed when needed - pk: nil, - } + sk := newPrKeyBLSBLS12381() // maps the seed to a private key // error is not checked as it is guaranteed to be nil @@ -190,9 +187,8 @@ func (a *blsBLS12381Algo) decodePrivateKey(privateKeyBytes []byte) (PrivateKey, "the input length has to be equal to %d", prKeyLengthBLSBLS12381) } - sk := &PrKeyBLSBLS12381{ - pk: nil, - } + sk := newPrKeyBLSBLS12381() + readScalar(&sk.scalar, privateKeyBytes) if C.check_membership_Zr((*C.bn_st)(&sk.scalar)) == valid { return sk, nil @@ -231,6 +227,16 @@ type PrKeyBLSBLS12381 struct { scalar scalar } +func newPrKeyBLSBLS12381() *PrKeyBLSBLS12381 { + sk := PrKeyBLSBLS12381{ + // public key is only computed when needed + pk: nil, + } + // initialize the scalar + C.bn_new_wrapper((*C.bn_st)(&sk.scalar)) + return &sk +} + // Algorithm returns the Signing Algorithm func (sk *PrKeyBLSBLS12381) Algorithm() SigningAlgorithm { return BLSBLS12381 diff --git a/crypto/bls12381_utils.c b/crypto/bls12381_utils.c index 1a724c2b459..47e40804945 100644 --- a/crypto/bls12381_utils.c +++ b/crypto/bls12381_utils.c @@ -18,6 +18,10 @@ int get_invalid() { return INVALID; } +void bn_new_wrapper(bn_t a) { + bn_new(a); +} + // global variable of the pre-computed data prec_st bls_prec_st; prec_st* bls_prec = NULL; @@ -45,8 +49,8 @@ const uint64_t p_1div2_data[Fp_DIGITS] = { // sets the global variable to input -void precomputed_data_set(prec_st* p) { - bls_prec = p; +void precomputed_data_set(const prec_st* p) { + bls_prec = (prec_st*)p; } // Reads a prime field element from a digit vector in big endian format. @@ -58,9 +62,11 @@ prec_st* init_precomputed_data_BLS12_381() { bls_prec = &bls_prec_st; #if (hashToPoint == OPSWU) + fp_read_raw(bls_prec->a1, a1_data); fp_read_raw(bls_prec->b1, b1_data); // (p-3)/4 + bn_new(&bls_prec->p_3div4); bn_read_raw(&bls_prec->p_3div4, p_3div4_data, Fp_DIGITS); // (p-1)/2 fp_read_raw(bls_prec->fp_p_1div2, fp_p_1div2_data); @@ -75,10 +81,13 @@ prec_st* init_precomputed_data_BLS12_381() { #endif #if (MEMBERSHIP_CHECK_G1 == BOWE) + bn_new(&bls_prec->beta); bn_read_raw(&bls_prec->beta, beta_data, Fp_DIGITS); + bn_new(&bls_prec->z2_1_by3); bn_read_raw(&bls_prec->z2_1_by3, z2_1_by3_data, 2); #endif + bn_new(&bls_prec->p_1div2); bn_read_raw(&bls_prec->p_1div2, p_1div2_data, Fp_DIGITS); return bls_prec; } @@ -222,7 +231,7 @@ void bn_map_to_Zr_star(bn_t a, const uint8_t* bin, int len) { // returns the sign of y. // 1 if y > (p - 1)/2 and 0 otherwise. -static int fp_get_sign(fp_t y) { +static int fp_get_sign(const fp_t y) { bn_t bn_y; bn_new(bn_y); fp_prime_back(bn_y, y); diff --git a/crypto/bls12381_utils.h b/crypto/bls12381_utils.h index 63115be25fe..b7b0426becb 100644 --- a/crypto/bls12381_utils.h +++ b/crypto/bls12381_utils.h @@ -74,10 +74,11 @@ typedef struct prec_ { // Utility functions int get_valid(); int get_invalid(); +void bn_new_wrapper(bn_t a); ctx_t* relic_init_BLS12_381(); prec_st* init_precomputed_data_BLS12_381(); -void precomputed_data_set(prec_st* p); +void precomputed_data_set(const prec_st* p); void seed_relic(byte*, int); int ep_read_bin_compact(ep_t, const byte *, const int); diff --git a/crypto/relic_build.sh b/crypto/relic_build.sh index a236b4ee8ad..4886cbb2fab 100755 --- a/crypto/relic_build.sh +++ b/crypto/relic_build.sh @@ -46,7 +46,7 @@ else fi # Set RELIC config for Flow -COMP=(-DCOMP="-O3 -funroll-loops -fomit-frame-pointer ${MARCH} -mtune=native") +COMP=(-DCFLAGS="-O3 -funroll-loops -fomit-frame-pointer ${MARCH} -mtune=native") GENERAL=(-DTIMER=CYCLE -DCHECK=OFF -DVERBS=OFF) LIBS=(-DSHLIB=OFF -DSTLIB=ON) RAND=(-DRAND=HASHD -DSEED=) From 6bfd78cfe1f7070b4fefbeee226baef9d6708a04 Mon Sep 17 00:00:00 2001 From: Tarak Ben Youssef Date: Fri, 9 Jul 2021 13:19:24 -0700 Subject: [PATCH 4/5] add new BLS private key and public key functions --- crypto/bls.go | 37 +++++++++++++++++++++++++++++-------- crypto/bls12381_utils.c | 4 ++++ crypto/bls12381_utils.h | 1 + crypto/bls_multisig.go | 14 ++++---------- crypto/dkg_feldmanvss.go | 12 +++--------- crypto/dkg_feldmanvssq.go | 13 ++++--------- crypto/dkg_jointfeldman.go | 14 +++++--------- crypto/thresholdsign.go | 12 +++--------- 8 files changed, 53 insertions(+), 54 deletions(-) diff --git a/crypto/bls.go b/crypto/bls.go index a29b24f9a4b..1875fe221e7 100644 --- a/crypto/bls.go +++ b/crypto/bls.go @@ -171,7 +171,7 @@ func (a *blsBLS12381Algo) generatePrivateKey(seed []byte) (PrivateKey, error) { KeyGenSeedMaxLenBLSBLS12381) } - sk := newPrKeyBLSBLS12381() + sk := newPrKeyBLSBLS12381(nil) // maps the seed to a private key // error is not checked as it is guaranteed to be nil @@ -187,7 +187,7 @@ func (a *blsBLS12381Algo) decodePrivateKey(privateKeyBytes []byte) (PrivateKey, "the input length has to be equal to %d", prKeyLengthBLSBLS12381) } - sk := newPrKeyBLSBLS12381() + sk := newPrKeyBLSBLS12381(nil) readScalar(&sk.scalar, privateKeyBytes) if C.check_membership_Zr((*C.bn_st)(&sk.scalar)) == valid { @@ -227,13 +227,19 @@ type PrKeyBLSBLS12381 struct { scalar scalar } -func newPrKeyBLSBLS12381() *PrKeyBLSBLS12381 { - sk := PrKeyBLSBLS12381{ - // public key is only computed when needed - pk: nil, +// newPrKeyBLSBLS12381 creates a new BLS private key with the given scalar. +// If no scalar is provided, the function allocates an +// empty scalar. +func newPrKeyBLSBLS12381(x *scalar) *PrKeyBLSBLS12381 { + var sk PrKeyBLSBLS12381 + if x == nil { + // initialize the scalar + C.bn_new_wrapper((*C.bn_st)(&sk.scalar)) + } else { + // set the scalar + sk.scalar = *x } - // initialize the scalar - C.bn_new_wrapper((*C.bn_st)(&sk.scalar)) + // the embedded public key is only computed when needed return &sk } @@ -295,6 +301,21 @@ type PubKeyBLSBLS12381 struct { point pointG2 } +// newPubKeyBLSBLS12381 creates a new BLS public key with the given point. +// 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 + } + return &pk +} + // Algorithm returns the Signing Algorithm func (pk *PubKeyBLSBLS12381) Algorithm() SigningAlgorithm { return BLSBLS12381 diff --git a/crypto/bls12381_utils.c b/crypto/bls12381_utils.c index 47e40804945..aa1c032b24c 100644 --- a/crypto/bls12381_utils.c +++ b/crypto/bls12381_utils.c @@ -22,6 +22,10 @@ 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; diff --git a/crypto/bls12381_utils.h b/crypto/bls12381_utils.h index b7b0426becb..563c9d0c9f3 100644 --- a/crypto/bls12381_utils.h +++ b/crypto/bls12381_utils.h @@ -75,6 +75,7 @@ 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(); diff --git a/crypto/bls_multisig.go b/crypto/bls_multisig.go index 3426df3726f..b1f114f2f8e 100644 --- a/crypto/bls_multisig.go +++ b/crypto/bls_multisig.go @@ -133,12 +133,10 @@ func AggregateBLSPrivateKeys(keys []PrivateKey) (PrivateKey, error) { } var sum scalar + C.bn_sum_vector((*C.bn_st)(&sum), (*C.bn_st)(&scalars[0]), (C.int)(len(scalars))) - return &PrKeyBLSBLS12381{ - pk: nil, - scalar: sum, - }, nil + return newPrKeyBLSBLS12381(&sum), nil } // AggregateBLSPublicKeys aggregate multiple BLS public keys into one. @@ -167,9 +165,7 @@ func AggregateBLSPublicKeys(keys []PublicKey) (PublicKey, error) { var sum pointG2 C.ep2_sum_vector((*C.ep2_st)(&sum), (*C.ep2_st)(&points[0]), (C.int)(len(points))) - return &PubKeyBLSBLS12381{ - point: sum, - }, nil + return newPubKeyBLSBLS12381(&sum), nil } func NeutralBLSPublicKey() PublicKey { @@ -217,9 +213,7 @@ func RemoveBLSPublicKeys(aggKey PublicKey, keysToRemove []PublicKey) (PublicKey, C.ep2_subtract_vector((*C.ep2_st)(&resultKey), (*C.ep2_st)(&aggPKBLS.point), (*C.ep2_st)(&pointsToSubtract[0]), (C.int)(len(pointsToSubtract))) - return &PubKeyBLSBLS12381{ - point: resultKey, - }, nil + return newPubKeyBLSBLS12381(&resultKey), nil } // VerifyBLSSignatureOneMessage is a multi-signature verification that verifies a diff --git a/crypto/dkg_feldmanvss.go b/crypto/dkg_feldmanvss.go index 05bc2d95732..1b0d9069d2c 100644 --- a/crypto/dkg_feldmanvss.go +++ b/crypto/dkg_feldmanvss.go @@ -107,21 +107,15 @@ func (s *feldmanVSSstate) End() (PrivateKey, PublicKey, []PublicKey, error) { return nil, nil, nil, errors.New("keys are not correct") } // private key of the current node - x := &PrKeyBLSBLS12381{ - scalar: s.x, // the private share - } + x := newPrKeyBLSBLS12381(&s.x) // Group public key - Y := &PubKeyBLSBLS12381{ - point: s.vA[0], - } + Y := newPubKeyBLSBLS12381(&s.vA[0]) // The nodes public keys y := make([]PublicKey, s.size) for i, p := range s.y { - y[i] = &PubKeyBLSBLS12381{ - point: p, - } + y[i] = newPubKeyBLSBLS12381(&p) } return x, Y, y, nil } diff --git a/crypto/dkg_feldmanvssq.go b/crypto/dkg_feldmanvssq.go index d94b828b4b8..c377ba709c2 100644 --- a/crypto/dkg_feldmanvssq.go +++ b/crypto/dkg_feldmanvssq.go @@ -155,19 +155,14 @@ func (s *feldmanVSSQualState) End() (PrivateKey, PublicKey, []PublicKey, error) } // private key of the current node - x := &PrKeyBLSBLS12381{ - scalar: s.x, // the private share - } + x := newPrKeyBLSBLS12381(&s.x) + // Group public key - Y := &PubKeyBLSBLS12381{ - point: s.vA[0], - } + Y := newPubKeyBLSBLS12381(&s.vA[0]) // The nodes public keys y := make([]PublicKey, s.size) for i, p := range s.y { - y[i] = &PubKeyBLSBLS12381{ - point: p, - } + y[i] = newPubKeyBLSBLS12381(&p) } return x, Y, y, nil } diff --git a/crypto/dkg_jointfeldman.go b/crypto/dkg_jointfeldman.go index 1db1fad69f3..7fe53600efd 100644 --- a/crypto/dkg_jointfeldman.go +++ b/crypto/dkg_jointfeldman.go @@ -180,19 +180,15 @@ func (s *JointFeldmanState) End() (PrivateKey, PublicKey, []PublicKey, error) { jointx, jointPublicKey, jointy := s.sumUpQualifiedKeys(s.size - disqualifiedTotal) // private key of the current node - x := &PrKeyBLSBLS12381{ - scalar: *jointx, // the private share - } + x := newPrKeyBLSBLS12381(jointx) + // Group public key - Y := &PubKeyBLSBLS12381{ - point: *jointPublicKey, - } + Y := newPubKeyBLSBLS12381(jointPublicKey) + // The nodes public keys y := make([]PublicKey, s.size) for i, p := range jointy { - y[i] = &PubKeyBLSBLS12381{ - point: p, - } + y[i] = newPubKeyBLSBLS12381(&p) } return x, Y, y, nil } diff --git a/crypto/thresholdsign.go b/crypto/thresholdsign.go index 6d5bca0bb3e..a7b6941fa40 100644 --- a/crypto/thresholdsign.go +++ b/crypto/thresholdsign.go @@ -499,15 +499,9 @@ func ThresholdSignKeyGen(size int, threshold int, seed []byte) ([]PrivateKey, pkShares := make([]PublicKey, size) var pkGroup PublicKey for i := 0; i < size; i++ { - skShares[i] = &PrKeyBLSBLS12381{ - scalar: x[i], - } - pkShares[i] = &PubKeyBLSBLS12381{ - point: y[i], - } - } - pkGroup = &PubKeyBLSBLS12381{ - point: X0, + skShares[i] = newPrKeyBLSBLS12381(&x[i]) + pkShares[i] = newPubKeyBLSBLS12381(&y[i]) } + pkGroup = newPubKeyBLSBLS12381(&X0) return skShares, pkShares, pkGroup, nil } From da4eafd1d53f36e81ed97aab61794313a386efe2 Mon Sep 17 00:00:00 2001 From: Tarak Ben Youssef Date: Fri, 9 Jul 2021 16:15:10 -0700 Subject: [PATCH 5/5] add missing bn_t initializations and keep only initializations for bn_t --- crypto/bls.go | 13 +++++-------- crypto/bls12381_utils.c | 4 ---- crypto/bls12381_utils.h | 1 - crypto/bls_multisig.go | 4 ++-- crypto/dkg_feldmanvss.go | 2 ++ crypto/dkg_feldmanvssq.go | 4 +++- crypto/dkg_jointfeldman.go | 1 + 7 files changed, 13 insertions(+), 16 deletions(-) diff --git a/crypto/bls.go b/crypto/bls.go index 1875fe221e7..5d5793cafe8 100644 --- a/crypto/bls.go +++ b/crypto/bls.go @@ -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 diff --git a/crypto/bls12381_utils.c b/crypto/bls12381_utils.c index aa1c032b24c..47e40804945 100644 --- a/crypto/bls12381_utils.c +++ b/crypto/bls12381_utils.c @@ -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; diff --git a/crypto/bls12381_utils.h b/crypto/bls12381_utils.h index 563c9d0c9f3..b7b0426becb 100644 --- a/crypto/bls12381_utils.h +++ b/crypto/bls12381_utils.h @@ -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(); diff --git a/crypto/bls_multisig.go b/crypto/bls_multisig.go index b1f114f2f8e..99d97d4268c 100644 --- a/crypto/bls_multisig.go +++ b/crypto/bls_multisig.go @@ -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 @@ -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 diff --git a/crypto/dkg_feldmanvss.go b/crypto/dkg_feldmanvss.go index 1b0d9069d2c..6e4d09cb712 100644 --- a/crypto/dkg_feldmanvss.go +++ b/crypto/dkg_feldmanvss.go @@ -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 @@ -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]) } diff --git a/crypto/dkg_feldmanvssq.go b/crypto/dkg_feldmanvssq.go index c377ba709c2..ec1397af382 100644 --- a/crypto/dkg_feldmanvssq.go +++ b/crypto/dkg_feldmanvssq.go @@ -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, @@ -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, diff --git a/crypto/dkg_jointfeldman.go b/crypto/dkg_jointfeldman.go index 7fe53600efd..0e57f5b5b1a 100644 --- a/crypto/dkg_jointfeldman.go +++ b/crypto/dkg_jointfeldman.go @@ -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