Removed deprecated GenerateSafePrimes function
The new function should be now called directly.
This commit is contained in:
5 files changed
+7
-56
No files matched your search
@@ -10,7 +10,6 @@ package paillier
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -63,6 +62,7 @@ func GenerateSafePrime(
|
|||||||
bitLen int,
|
bitLen int,
|
||||||
concurrencyLevel int,
|
concurrencyLevel int,
|
||||||
timeout time.Duration,
|
timeout time.Duration,
|
||||||
|
random io.Reader,
|
||||||
) (p *big.Int, q *big.Int, err error) {
|
) (p *big.Int, q *big.Int, err error) {
|
||||||
if bitLen < 6 {
|
if bitLen < 6 {
|
||||||
return nil, nil, errors.New("safe prime size must be at least 6 bits")
|
return nil, nil, errors.New("safe prime size must be at least 6 bits")
|
||||||
@@ -82,7 +82,7 @@ func GenerateSafePrime(
|
|||||||
|
|
||||||
for i := 0; i < concurrencyLevel; i++ {
|
for i := 0; i < concurrencyLevel; i++ {
|
||||||
runGenPrimeRoutine(
|
runGenPrimeRoutine(
|
||||||
ctx, primeChan, errChan, mutex, waitGroup, rand.Reader, bitLen,
|
ctx, primeChan, errChan, mutex, waitGroup, random, bitLen,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package paillier
|
package paillier
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -44,6 +44,7 @@ func TestAsyncGenerator(t *testing.T) {
|
|||||||
test.bitLen,
|
test.bitLen,
|
||||||
concurrencyLevel,
|
concurrencyLevel,
|
||||||
test.timeout,
|
test.timeout,
|
||||||
|
rand.Reader,
|
||||||
)
|
)
|
||||||
|
|
||||||
if test.expectedError != nil {
|
if test.expectedError != nil {
|
||||||
@@ -59,38 +60,7 @@ func TestAsyncGenerator(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !p.ProbablyPrime(20) {
|
AreSafePrimes(p, q, test.bitLen, t)
|
||||||
t.Errorf("p is not prime; p = %v", p)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !q.ProbablyPrime(20) {
|
|
||||||
t.Errorf("q is not prime; q = %v", q)
|
|
||||||
}
|
|
||||||
|
|
||||||
// p = 2q + 1 ?
|
|
||||||
expectedP := new(big.Int)
|
|
||||||
expectedP.Mul(big.NewInt(2), q)
|
|
||||||
expectedP.Add(expectedP, big.NewInt(1))
|
|
||||||
|
|
||||||
if expectedP.Cmp(p) != 0 {
|
|
||||||
t.Errorf("2q + 1 != p")
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.BitLen() != test.bitLen {
|
|
||||||
t.Fatalf(
|
|
||||||
"Unexpected p bit length\nActual: %v\nExpected: %v",
|
|
||||||
p.BitLen(),
|
|
||||||
test.bitLen,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if q.BitLen() != test.bitLen-1 {
|
|
||||||
t.Fatalf(
|
|
||||||
"Unexpected q bit length\nActual: %v\nExpected: %v",
|
|
||||||
q.BitLen(),
|
|
||||||
test.bitLen-1,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Generates a threshold Paillier key with an algorithm based on [DJN 10],
|
// Generates a threshold Paillier key with an algorithm based on [DJN 10],
|
||||||
@@ -58,7 +59,7 @@ func GetThresholdKeyGenerator(nbits, TotalNumberOfDecryptionServers, Threshold i
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tkg *ThresholdKeyGenerator) generateSafePrimes() (*big.Int, *big.Int, error) {
|
func (tkg *ThresholdKeyGenerator) generateSafePrimes() (*big.Int, *big.Int, error) {
|
||||||
return GenerateSafePrimes(tkg.nbits, tkg.Random)
|
return GenerateSafePrime(tkg.nbits, 4, 120*time.Second, tkg.Random)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tkg *ThresholdKeyGenerator) initPandP1() error {
|
func (tkg *ThresholdKeyGenerator) initPandP1() error {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var ZERO = big.NewInt(0)
|
var ZERO = big.NewInt(0)
|
||||||
@@ -21,15 +20,6 @@ func Factorial(n int) *big.Int {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns 2 primes such that p = 2 * q + 1 and that the length of
|
|
||||||
// p is nbits. `p` is called a safe prime
|
|
||||||
//
|
|
||||||
// Deprecated: This function has been left here just for backward compatibility.
|
|
||||||
// Please use `GenerateSafePrime` from the `safe_prime_generator.go` directly.
|
|
||||||
func GenerateSafePrimes(nbits int, random io.Reader) (p, q *big.Int, err error) {
|
|
||||||
return GenerateSafePrime(nbits, 4, 120*time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate a random element in the group of all the elements in Z/nZ that
|
// Generate a random element in the group of all the elements in Z/nZ that
|
||||||
// has a multiplicative inverse.
|
// has a multiplicative inverse.
|
||||||
func GetRandomNumberInMultiplicativeGroup(n *big.Int, random io.Reader) (*big.Int, error) {
|
func GetRandomNumberInMultiplicativeGroup(n *big.Int, random io.Reader) (*big.Int, error) {
|
||||||
|
|||||||
@@ -87,16 +87,6 @@ func GetEntireRQn(n int) map[int]bool {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateSafePrimes(t *testing.T) {
|
|
||||||
for i := 0; i < 10; i++ {
|
|
||||||
p, q, err := GenerateSafePrimes(20, rand.Reader)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
AreSafePrimes(p, q, 20, t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetRandomGeneratorOfTheQuadraticResidue(t *testing.T) {
|
func TestGetRandomGeneratorOfTheQuadraticResidue(t *testing.T) {
|
||||||
tooSmallPrime1, tooSmallPrime2 := b(347), b(359)
|
tooSmallPrime1, tooSmallPrime2 := b(347), b(359)
|
||||||
m := new(big.Int).Mul(tooSmallPrime1, tooSmallPrime2)
|
m := new(big.Int).Mul(tooSmallPrime1, tooSmallPrime2)
|
||||||
|
|||||||
Reference in new issue
Block a user