Small improvements to the threshold key generator tests
First of all, we should check both `p,p1` and `q,q1` in the `TestInitPsAndQs`. Moreover, it's better to operate on primes in `TestArePsAndQsGood` and in `TestInitShortcuts` because non-prime numbers are not allowed there in a real world and tests were a bit misleading because of it.
This commit is contained in:
1 file changed
+10
-12
@@ -18,10 +18,8 @@ func TestGenerateSafePrimesOfThresholdKeyGenerator(t *testing.T) {
|
|||||||
p, q, err := tkh.generateSafePrimes()
|
p, q, err := tkh.generateSafePrimes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
AreSafePrimes(p, q, 10, t)
|
AreSafePrimes(p, q, 10, t)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInitPandP1(t *testing.T) {
|
func TestInitPandP1(t *testing.T) {
|
||||||
@@ -31,7 +29,6 @@ func TestInitPandP1(t *testing.T) {
|
|||||||
|
|
||||||
tkh.initPandP1()
|
tkh.initPandP1()
|
||||||
AreSafePrimes(tkh.p, tkh.p1, 10, t)
|
AreSafePrimes(tkh.p, tkh.p1, 10, t)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInitQandQ1(t *testing.T) {
|
func TestInitQandQ1(t *testing.T) {
|
||||||
@@ -49,23 +46,24 @@ func TestInitPsAndQs(t *testing.T) {
|
|||||||
tkh.Random = rand.Reader
|
tkh.Random = rand.Reader
|
||||||
|
|
||||||
tkh.initPsAndQs()
|
tkh.initPsAndQs()
|
||||||
AreSafePrimes(tkh.q, tkh.q1, 10, t)
|
|
||||||
|
AreSafePrimes(tkh.p, tkh.p1, 10, t)
|
||||||
AreSafePrimes(tkh.q, tkh.q1, 10, t)
|
AreSafePrimes(tkh.q, tkh.q1, 10, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArePsAndQsGood(t *testing.T) {
|
func TestArePsAndQsGood(t *testing.T) {
|
||||||
tkh := new(ThresholdKeyGenerator)
|
tkh := new(ThresholdKeyGenerator)
|
||||||
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(6), b(5), b(4), b(3)
|
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(887), b(443), b(839), b(419)
|
||||||
if !tkh.arePsAndQsGood() {
|
if !tkh.arePsAndQsGood() {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(6), b(5), b(6), b(3)
|
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(887), b(443), b(887), b(443)
|
||||||
if tkh.arePsAndQsGood() {
|
if tkh.arePsAndQsGood() {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(6), b(5), b(5), b(3)
|
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(887), b(443), b(443), b(221)
|
||||||
if tkh.arePsAndQsGood() {
|
if tkh.arePsAndQsGood() {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
@@ -73,19 +71,19 @@ func TestArePsAndQsGood(t *testing.T) {
|
|||||||
|
|
||||||
func TestInitShortcuts(t *testing.T) {
|
func TestInitShortcuts(t *testing.T) {
|
||||||
tkh := new(ThresholdKeyGenerator)
|
tkh := new(ThresholdKeyGenerator)
|
||||||
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(11), b(7), b(5), b(3)
|
tkh.p, tkh.p1, tkh.q, tkh.q1 = b(839), b(419), b(887), b(443)
|
||||||
tkh.initShortcuts()
|
tkh.initShortcuts()
|
||||||
|
|
||||||
if n(tkh.n) != 11*5 {
|
if !reflect.DeepEqual(tkh.n, b(744193)) {
|
||||||
t.Error("wrong n", tkh.n)
|
t.Error("wrong n", tkh.n)
|
||||||
}
|
}
|
||||||
if n(tkh.m) != 7*3 {
|
if !reflect.DeepEqual(tkh.m, b(185617)) {
|
||||||
t.Error("wrong m", tkh.m)
|
t.Error("wrong m", tkh.m)
|
||||||
}
|
}
|
||||||
if n(tkh.nm) != 11*5*7*3 {
|
if !reflect.DeepEqual(tkh.nm, new(big.Int).Mul(b(744193), b(185617))) {
|
||||||
t.Error("wrong nm", tkh.nm)
|
t.Error("wrong nm", tkh.nm)
|
||||||
}
|
}
|
||||||
if n(tkh.nSquare) != 11*5*11*5 {
|
if !reflect.DeepEqual(tkh.nSquare, new(big.Int).Mul(b(744193), b(744193))) {
|
||||||
t.Error("wrong nSquare", tkh.nSquare)
|
t.Error("wrong nSquare", tkh.nSquare)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user