42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/sssa.rb', line 42
def self.combine(shares)
secrets = []
shares.each_with_index do |share, index|
if share.size % 88 != 0
return
end
count = share.size / 88
secrets.push []
(0...count).each do |i|
cshare = share[i*88, (i+1)*88]
secrets[index][i] = [@util.from_base64(cshare[0...44]), @util.from_base64(cshare[44...88])]
end
end
secret = [0] * secrets[0].size
secret.each_with_index do |part, part_index|
secrets.each_with_index do |share, share_index|
origin = share[part_index][0]
originy = share[part_index][1]
numerator = 1
denominator = 1
secrets.each_with_index do |product, product_index|
if product_index != share_index
current = product[part_index][0]
numerator = (numerator * (-1*current)) % @prime
denominator = (denominator * (origin - current)) % @prime
end
end
working = ((originy * numerator * @util.mod_inverse(denominator)) + @prime)
secret[part_index] = (secret[part_index] + working) % @prime
end
end
return @util.merge_ints(secret)
end
|