-
Notifications
You must be signed in to change notification settings - Fork 251
/
proof_test.go
63 lines (48 loc) · 1.77 KB
/
proof_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright © 2019 Binance
//
// This file is part of Binance. The full Binance copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
package facproof_test
import (
"math/big"
"testing"
"github.com/stretchr/testify/assert"
"github.com/bnb-chain/tss-lib/common"
"github.com/bnb-chain/tss-lib/crypto"
. "github.com/bnb-chain/tss-lib/crypto/facproof"
"github.com/bnb-chain/tss-lib/tss"
)
// Using a modulus length of 2048 is recommended in the GG18 spec
const (
testSafePrimeBits = 1024
)
func TestFac(test *testing.T) {
ec := tss.EC()
N0p := common.GetRandomPrimeInt(testSafePrimeBits)
N0q := common.GetRandomPrimeInt(testSafePrimeBits)
N0 := new(big.Int).Mul(N0p, N0q)
primes := [2]*big.Int{common.GetRandomPrimeInt(testSafePrimeBits), common.GetRandomPrimeInt(testSafePrimeBits)}
NCap, s, t, err := crypto.GenerateNTildei(primes)
assert.NoError(test, err)
proof, err := NewProof(ec, N0, NCap, s, t, N0p, N0q)
assert.NoError(test, err)
ok := proof.Verify(ec, N0, NCap, s, t)
assert.True(test, ok, "proof must verify")
N0p = common.GetRandomPrimeInt(1024)
N0q = common.GetRandomPrimeInt(1024)
N0 = new(big.Int).Mul(N0p, N0q)
proof, err = NewProof(ec, N0, NCap, s, t, N0p, N0q)
assert.NoError(test, err)
ok = proof.Verify(ec, N0, NCap, s, t)
assert.True(test, ok, "proof must verify")
// factor should have bits [1024-16, 1024+16]
smallFactor := 900
N0p = common.GetRandomPrimeInt(smallFactor)
N0q = common.GetRandomPrimeInt(2048 - smallFactor)
N0 = new(big.Int).Mul(N0p, N0q)
proof, err = NewProof(ec, N0, NCap, s, t, N0p, N0q)
assert.NoError(test, err)
ok = proof.Verify(ec, N0, NCap, s, t)
assert.False(test, ok, "proof must not verify")
}