Class: Sharing::CRT::AsmuthBloom::V2

Inherits:
Object
  • Object
show all
Includes:
HenselCode::Tools
Defined in:
lib/sharing/crt/asmuth-bloom/v2.rb

Overview

second version of Asmuth-Bloom proposed by Ersoy et al.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ V2

Returns a new instance of V2.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 26

def initialize(params = {})
  @threshold = params[:threshold]
  @secrecy = params[:secrecy]
  @total_shares = params[:total_shares]
  @k_add = params[:k_add]
  @k_mul = params[:k_mul]
  @lambda_ = params[:lambda_]
  generate_unique_primes
  compute_prime_products
  generate_single_prime
end

Instance Attribute Details

#aObject

Returns the value of attribute a.



13
14
15
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 13

def a
  @a
end

#k_addObject

Returns the value of attribute k_add.



13
14
15
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 13

def k_add
  @k_add
end

#k_mulObject

Returns the value of attribute k_mul.



13
14
15
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 13

def k_mul
  @k_mul
end

#lambda_Object

Returns the value of attribute lambda_.



13
14
15
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 13

def lambda_
  @lambda_
end

#m_rObject

Returns the value of attribute m_r.



13
14
15
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 13

def m_r
  @m_r
end

#m_to_sObject

Returns the value of attribute m_to_s.



13
14
15
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 13

def m_to_s
  @m_to_s
end

#pObject

Returns the value of attribute p.



13
14
15
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 13

def p
  @p
end

#primesObject

Returns the value of attribute primes.



13
14
15
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 13

def primes
  @primes
end

#secrecyObject

Returns the value of attribute secrecy.



13
14
15
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 13

def secrecy
  @secrecy
end

#thresholdObject

Returns the value of attribute threshold.



13
14
15
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 13

def threshold
  @threshold
end

#total_sharesObject

Returns the value of attribute total_shares.



13
14
15
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 13

def total_shares
  @total_shares
end

#upperboundObject

Returns the value of attribute upperbound.



13
14
15
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 13

def upperbound
  @upperbound
end

#yObject

Returns the value of attribute y.



13
14
15
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 13

def y
  @y
end

Class Method Details

.add(shares1, shares2) ⇒ Object



18
19
20
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 18

def self.add(shares1, shares2)
  shares1.zip(shares2).map { |s| [s[0][0], s[0][1] + s[1][1]] }
end

.mul(shares1, shares2) ⇒ Object



22
23
24
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 22

def self.mul(shares1, shares2)
  shares1.zip(shares2).map { |s| [s[0][0], s[0][1] * s[1][1]] }
end

Instance Method Details

#compute_prime_productsObject



62
63
64
65
66
67
68
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 62

def compute_prime_products
  @m_r = primes[0..threshold - 1].inject(:*)
  @m_to_s = 1
  (0..secrecy - 1).each do |i|
    @m_to_s *= primes[total_shares - (i + 2) + 1]
  end
end

#compute_shares(secret) ⇒ Object



42
43
44
45
46
47
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 42

def compute_shares(secret)
  compute_upperbound(secret)
  @a = rand(1..upperbound - 1)
  @y = secret + (a * p)
  primes.map.with_index { |prime, i| [i, y % prime] }
end

#compute_upperbound(secret) ⇒ Object



38
39
40
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 38

def compute_upperbound(secret)
  @upperbound = ((p * m_to_s) - secret) / p
end

#generate_primesObject



57
58
59
60
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 57

def generate_primes
  @primes = random_distinct_numbers("prime", total_shares, lambda_)
  @primes.sort!
end

#generate_single_primeObject



70
71
72
73
74
75
76
77
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 70

def generate_single_prime
  bits = lambda_
  @p = random_prime(lambda_)
  while m_r <= (k_add + 1) * ((@p * m_to_s)**(k_mul + 1))
    bits -= 1
    @p = random_prime(bits)
  end
end

#generate_unique_primesObject



79
80
81
82
83
84
85
86
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 79

def generate_unique_primes
  @primes = [random_prime(lambda_)]
  while primes.uniq.size < total_shares
    prime = random_prime(lambda_)
    @primes << prime unless @primes.include?(prime) && (@primes + [prime]).reduce(1, :gcd) != 1
  end
  @primes = @primes.uniq.sort
end

#reconstruct_secret(selected_shares) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/sharing/crt/asmuth-bloom/v2.rb', line 49

def reconstruct_secret(selected_shares)
  indices = selected_shares.map(&:first)
  moduli = primes.values_at(*indices)
  shares = selected_shares.map(&:last)
  y = crt(moduli, shares)
  y % p
end