Make sure public key bit length is an even number

For an odd n-bit number, we can't find two n-1-bit numbers which
multiplied gives an n-bit number. That's why public key length n must be
an even number.

I have also renamed AreSafePrimes to IsSafePrime since only the first
function argument is considered to be a safe prime according to a safe
prime definition.
This commit is contained in:
Piotr Dyraga committed 2018-08-08 11:11:05 +02:00
1 parent d5973f86a7
commit 12b3dadef7
4 files changed
+26 -10

No files matched your search

+9 -1
View File
@@ -49,7 +49,8 @@ type ThresholdKeyGenerator struct {
// GetThresholdKeyGenerator is a preferable way to construct the
// ThresholdKeyGenerator.
// Due to the various properties that must be met for the threshold key to be
// considered valid, the minimum public key `N` bit length is 18 bits.
// considered valid, the minimum public key `N` bit length is 18 bits and the
// public key bit length should be an even number.
// The plaintext space for the key will be `Z_N`.
func GetThresholdKeyGenerator(
publicKeyBitLength int,
@@ -57,7 +58,14 @@ func GetThresholdKeyGenerator(
threshold int,
random io.Reader,
) (*ThresholdKeyGenerator, error) {
if publicKeyBitLength%2 == 1 {
// For an odd n-bit number, we can't find two n-1-bit numbers which
// multiplied gives an n-bit number.
return nil, errors.New("Public key bit length must be an even number")
}
if publicKeyBitLength < 18 {
// We need to find two n-bit safe primes, P and Q which are not equal.
// This is not possible for n<18.
return nil, errors.New("Public key bit length must be at least 18 bits")
}