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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGRmOTk3Y2EyYTJhY2FiODk2YWYwODNlNWZlMzI5ZTJlY2M0MDk3Yg==
4
+ YjQ4ZTU3ZjUxMDRlNWUxNGQ2MDJlYzg2OWQyYTY1NzliNjFjM2Q4ZA==
5
5
  data.tar.gz: !binary |-
6
- ZTVkODUxZjRkMGUzZWYyMzRkYzFiNTYyNWU2OWUyMzJjYzhkNjU3OA==
6
+ ZTljYjJkOTc0MDEzOGU0OTlkNTNjYWM4ZGNjZmEyMjE1NjlhMjYxZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjY5OTQ3ZTU4NjA1MzhkMmY0MzkwM2U0NTVkYmJjOTg3MDMyZjIyNmUwZWUw
10
- OGRmZDAzZWFjYzBiMDlkNzdhZmMyMjU5N2Y5MzNmOTA3ZTc2YTY3Zjg4ZDFk
11
- NDRhYmZmZTc4NjFkY2FlOGRlZmQ1ZmZhZjdjOGI5MmRjYWE5NGM=
9
+ MTA2ZGYxZWIyNjRiNDMxYjhmOWE5YmNmNTg2MDY3Y2YyYTJkYzk3NzZhNWU3
10
+ ZDM5MmUzZTFmOGEwMTAzZTNlOGNmMDYxMjk1YWUzMzYyZmE1ZTkzNDRiNTNl
11
+ ZDhiMDFlMmZiNjY1M2YyMDVmM2Q3MzI1MzJiZjMzNGZhYzc1NDY=
12
12
  data.tar.gz: !binary |-
13
- Y2YwZjQ1YjVjMGJlOGU2YzVlZTA4NTJhZWEzMDFiYjRlNzU0NGQ1M2ViNjZj
14
- NTQ0MTc4NjNmYjI1NWIyNTkwOWYzYmE2ZjBkOGRhMDQ3MTdjZTk2Zjk0YmY4
15
- NTEyYzg1NzU2NDhkN2YwMTE2ZGQ0ZjE5MzY2Y2U1NjQ1ZTQ0MTQ=
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 shamir's secret sharing.
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 shamir's secret sharing has initially been developed to
31
- be used in [duse](https://duse.io/), however, it is designed to be used in any
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
@@ -15,7 +15,7 @@ module SecretSharing
15
15
  #
16
16
  # Example
17
17
  #
18
- # SecretSharing.split_secret('secret', 2, 3)
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 split_secret(secret_string, share_threshold, num_shares)
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
- # {#split_secret}.
38
+ # {#split}.
39
39
  #
40
40
  # Example
41
41
  #
42
- # SecretSharing.recover_secret ["1-1e489c32507823aa", "2-1c9134c644739461"]
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 recover_secret(raw_shares)
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)
@@ -1,4 +1,4 @@
1
1
  module SecretSharing
2
2
  # gem version
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
  end
@@ -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.split_secret(secret, 2, num_of_shares)
9
- expect(SecretSharing.recover_secret(shares[0..1])).to eq(secret)
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.split_secret('secret', 2, 4) }
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.recover_secret(shares[0, 1])).not_to eq 'secret'
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.recover_secret(share_combination)).to eq 'secret'
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.recover_secret(share_combination)).to eq 'secret'
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.recover_secret(shares)).to eq 'secret'
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.split_secret('secret', 2, 11) }
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
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-04-25 00:00:00.000000000 Z
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: