paillier 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paillier/primes.rb +29 -29
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d489649541fa6f023075161d2d2772bd0d05539
|
4
|
+
data.tar.gz: 8b6138fbebb78bcb2a8e3360b753bb2a43faa4ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 823b4a093380c87f0403589bf9a982fdf59628ced3df9fdf0bc3c0fbcee0338113d049e6b3423468df3b70570a2540cf95c2f12e5bed958ac07552ea29cb63dd
|
7
|
+
data.tar.gz: 0b931043d6fefe9bae67ef4765f59098ec8b102244af1fc62a5502c32b8501779bc9fa4bb1879f07825473f85f315a6c9512f9386c537d548c808a55affdb41a
|
data/lib/paillier/primes.rb
CHANGED
@@ -10,33 +10,37 @@ module Paillier
|
|
10
10
|
return int.to_s(2).length
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
13
|
+
# This is an implementation of the Rabin-Miller primality test.
|
14
|
+
# Previous versions used Little Fermat, but that is not effective
|
15
|
+
# in all cases; specifically, it can be thwarted by Carmichael
|
16
|
+
# numbers. We use 50 rounds as the default, in order to get a certainty
|
17
|
+
# of 2^-100 that we have found a prime. This implementation is adapted
|
18
|
+
# from https://rosettacode.org/wiki/Miller-Rabin_primality_test#Ruby
|
19
|
+
def self.probabilisticPrimeTest(target, k=50)
|
20
|
+
d = target-1
|
21
|
+
s = 0
|
22
|
+
while d % 2 == 0
|
23
|
+
d /= 2
|
24
|
+
s += 1
|
25
|
+
end
|
26
|
+
k.times do
|
27
|
+
a = 2 + rand(target-4)
|
28
|
+
x = a.to_bn.mod_exp(d, target)
|
29
|
+
next if x == 1 || x == target-1
|
30
|
+
for r in (1..s - 1)
|
31
|
+
x = x.to_bn.mod_exp(2, target)
|
32
|
+
return false if x == 1
|
33
|
+
break if x == target - 1
|
34
|
+
end
|
35
|
+
return false if x != target-1
|
36
|
+
end
|
37
|
+
return true # probs prime
|
38
|
+
end
|
32
39
|
|
33
|
-
def self.isProbablyPrime?(possible, k=
|
40
|
+
def self.isProbablyPrime?(possible, k=50)
|
34
41
|
if( possible == 1 )
|
35
42
|
return true
|
36
43
|
end
|
37
|
-
if( k.nil? )
|
38
|
-
k = defaultK(bitLength(possible))
|
39
|
-
end
|
40
44
|
for i in SmallPrimes
|
41
45
|
if( possible == i )
|
42
46
|
return true
|
@@ -59,14 +63,10 @@ module Paillier
|
|
59
63
|
end
|
60
64
|
|
61
65
|
# Get a random prime of appropriate length
|
62
|
-
def self.generatePrime(bits, k=
|
66
|
+
def self.generatePrime(bits, k=50)
|
63
67
|
if( bits < 8 )
|
64
68
|
raise "Bits less than eight!"
|
65
69
|
end
|
66
|
-
if( k == nil )
|
67
|
-
k = defaultK(bits)
|
68
|
-
end
|
69
|
-
|
70
70
|
while( true )
|
71
71
|
lowerBound = (2 ** (bits-1) + 1)
|
72
72
|
size = ((2 ** bits) - lowerBound)
|
@@ -82,7 +82,7 @@ module Paillier
|
|
82
82
|
raise "Bits less than eight!"
|
83
83
|
end
|
84
84
|
|
85
|
-
# If we find a number not
|
85
|
+
# If we find a number not coprime to n then finding `p` and `q` is trivial.
|
86
86
|
# This will almost never happen for keys of reasonable size, so if
|
87
87
|
# `coprime_to` is big enough we won't bother running the expensive test.
|
88
88
|
no_test_needed = false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paillier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daylighting Society
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: An implementation of Paillier homomorphic addition public key system
|
14
14
|
email: paillier@daylightingsociety.org
|