From 3eb16594d1cd569e1ba69d0ec083bdecb5e550f9 Mon Sep 17 00:00:00 2001 From: Fabio Tacke Date: Mon, 5 Jun 2017 14:06:10 +0200 Subject: [PATCH] Fix a bug that caused the generation of safe primes to fail --- PVSS.podspec | 2 +- Sources/PVSSInstance.swift | 3 +++ Tests/PVSSTests/PVSSTest.swift | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/PVSS.podspec b/PVSS.podspec index 0c61308..f469c16 100644 --- a/PVSS.podspec +++ b/PVSS.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'PVSS' - s.version = '1.0.4' + s.version = '1.0.5' s.summary = 'An implementation of Publicly Verifiably Secret Sharing (PVSS) in Swift.' s.description = <<-DESC The library implements a PVSS scheme in Swift. The algorithm is based on "A Simple Publicly Verifiable Secret Sharing Scheme and its Application to Electronic Voting" by Berry Schoenmakers. diff --git a/Sources/PVSSInstance.swift b/Sources/PVSSInstance.swift index 4d1d3e8..ed39104 100644 --- a/Sources/PVSSInstance.swift +++ b/Sources/PVSSInstance.swift @@ -30,6 +30,9 @@ public struct PVSSInstance { public init(length: Int) { // Find safe prime var q = BigUInt.randomInteger(withExactWidth: length) + if q % 2 == 0 { + q -= 1 + } var sophieGermainCandidate: BigUInt repeat { diff --git a/Tests/PVSSTests/PVSSTest.swift b/Tests/PVSSTests/PVSSTest.swift index 95e8b3c..f5cd813 100644 --- a/Tests/PVSSTests/PVSSTest.swift +++ b/Tests/PVSSTests/PVSSTest.swift @@ -137,7 +137,7 @@ class PVSSTest: XCTestCase { let secret = BigUInt(secretMessage.data(using: .utf8)!) // Create default PVSS Instance for the dealer - let pvssInstance = PVSSInstance() + let pvssInstance = PVSSInstance(length: 128) let dealer = Participant(pvssInstance: pvssInstance) // Participants p1, p2 and p3