secret_sharing 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.md +4 -3
- data/lib/secret_sharing.rb +5 -5
- data/lib/secret_sharing/version.rb +1 -1
- data/spec/secret_sharing_spec.rb +8 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjQ4ZTU3ZjUxMDRlNWUxNGQ2MDJlYzg2OWQyYTY1NzliNjFjM2Q4ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTljYjJkOTc0MDEzOGU0OTlkNTNjYWM4ZGNjZmEyMjE1NjlhMjYxZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTA2ZGYxZWIyNjRiNDMxYjhmOWE5YmNmNTg2MDY3Y2YyYTJkYzk3NzZhNWU3
|
10
|
+
ZDM5MmUzZTFmOGEwMTAzZTNlOGNmMDYxMjk1YWUzMzYyZmE1ZTkzNDRiNTNl
|
11
|
+
ZDhiMDFlMmZiNjY1M2YyMDVmM2Q3MzI1MzJiZjMzNGZhYzc1NDY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTY5OTlmOTZmZDg2ODlhMjU3NzMxZWZmOTExZWEwMmVkYWI2OWU5MTEwZTYw
|
14
|
+
MTcwNTEzM2I3MGMyM2U2NjYyYWQxOTVhYmQzMjZiMGM5YTJhMWJmNjA1MWJi
|
15
|
+
OGU0YTZjOTRkMDdkNDNjOTU2OWJmZDRlZjE4Yjg4YzI4OTViMmY=
|
data/README.md
CHANGED
@@ -9,7 +9,8 @@
|
|
9
9
|
> **Warning:** This implementation has not been tested in production nor has it
|
10
10
|
> been examined by a security audit. All uses are your own responsibility.
|
11
11
|
|
12
|
-
A ruby implementation of
|
12
|
+
A ruby implementation of [Shamir's Secret
|
13
|
+
Sharing](http://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing).
|
13
14
|
|
14
15
|
## Installation
|
15
16
|
|
@@ -27,8 +28,8 @@ Or install it yourself as:
|
|
27
28
|
|
28
29
|
## Implementation details
|
29
30
|
|
30
|
-
This implementation of
|
31
|
-
be used in [duse](
|
31
|
+
This implementation of Shamir's Secret Sharing has initially been developed to
|
32
|
+
be used in [duse](http://duse.io/), however, it is designed to be used in any
|
32
33
|
other context just as well.
|
33
34
|
|
34
35
|
The representation of a share is simply `x-hex(y)`. We chose this
|
data/lib/secret_sharing.rb
CHANGED
@@ -15,7 +15,7 @@ module SecretSharing
|
|
15
15
|
#
|
16
16
|
# Example
|
17
17
|
#
|
18
|
-
# SecretSharing.
|
18
|
+
# SecretSharing.split('secret', 2, 3)
|
19
19
|
# # => ["1-1e489c32507823aa", "2-1c9134c644739461", "3-1ad9cd5a386f0518"]
|
20
20
|
#
|
21
21
|
# @param secret_string [String] Secret to split.
|
@@ -23,7 +23,7 @@ module SecretSharing
|
|
23
23
|
# @param num_shares [Integer] Total number of shares to generate.
|
24
24
|
#
|
25
25
|
# @return [Array] Array of shares that can be used to recover the secret.
|
26
|
-
def
|
26
|
+
def split(secret_string, share_threshold, num_shares)
|
27
27
|
secret_int = Charset::ASCIICharset.s_to_i(secret_string)
|
28
28
|
points = Polynomial.points_from_secret(secret_int,
|
29
29
|
share_threshold,
|
@@ -35,17 +35,17 @@ module SecretSharing
|
|
35
35
|
end
|
36
36
|
|
37
37
|
# Recover a secret with an array of string shares generated with
|
38
|
-
# {#
|
38
|
+
# {#split}.
|
39
39
|
#
|
40
40
|
# Example
|
41
41
|
#
|
42
|
-
# SecretSharing.
|
42
|
+
# SecretSharing.reconstruct ["1-1e489c32507823aa", "2-1c9134c644739461"]
|
43
43
|
# # => "secret"
|
44
44
|
#
|
45
45
|
# @param raw_shares [Array] Shares (array of strings) to recover the secret
|
46
46
|
#
|
47
47
|
# @return [String] Recovered secret in a string representation.
|
48
|
-
def
|
48
|
+
def reconstruct(raw_shares)
|
49
49
|
shares = raw_shares.map { |raw_share| Share.from_string raw_share }
|
50
50
|
points = shares.map(&:point)
|
51
51
|
secret_int = Polynomial.modular_lagrange_interpolation(points)
|
data/spec/secret_sharing_spec.rb
CHANGED
@@ -5,41 +5,41 @@ RSpec.describe SecretSharing do
|
|
5
5
|
50.times do
|
6
6
|
secret = SecureRandom.base64(130)
|
7
7
|
num_of_shares = 2 + SecureRandom.random_number(100)
|
8
|
-
shares = SecretSharing.
|
9
|
-
expect(SecretSharing.
|
8
|
+
shares = SecretSharing.split(secret, 2, num_of_shares)
|
9
|
+
expect(SecretSharing.reconstruct(shares[0..1])).to eq(secret)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'threshold 2 out of 4 shares' do
|
14
|
-
subject(:shares) { SecretSharing.
|
14
|
+
subject(:shares) { SecretSharing.split('secret', 2, 4) }
|
15
15
|
|
16
16
|
it 'generates 4 shares' do
|
17
17
|
expect(shares.length). to eq 4
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'cannot reconstruct with only one share' do
|
21
|
-
expect(SecretSharing.
|
21
|
+
expect(SecretSharing.reconstruct(shares[0, 1])).not_to eq 'secret'
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'can reconstruct the secret with any combination of 2 shares' do
|
25
25
|
shares.permutation(2).each do |share_combination|
|
26
|
-
expect(SecretSharing.
|
26
|
+
expect(SecretSharing.reconstruct(share_combination)).to eq 'secret'
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'can reconstruct the secret with any combination of 3 shares' do
|
31
31
|
shares.permutation(3).each do |share_combination|
|
32
|
-
expect(SecretSharing.
|
32
|
+
expect(SecretSharing.reconstruct(share_combination)).to eq 'secret'
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'can reconstruct the secret with all shares' do
|
37
|
-
expect(SecretSharing.
|
37
|
+
expect(SecretSharing.reconstruct(shares)).to eq 'secret'
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
context 'threshold 2 out of 11 shares' do
|
42
|
-
subject(:shares) { SecretSharing.
|
42
|
+
subject(:shares) { SecretSharing.split('secret', 2, 11) }
|
43
43
|
|
44
44
|
it 'adds zero padding for shares 1 to 9' do
|
45
45
|
shares[0, 9].each_with_index do |share, index|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secret_sharing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- flower-pot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Split and reconstruct secrets using the shamir's secret sharing algorithm
|
14
14
|
email:
|