MCPcopy Create free account
hub / github.com/DOSNetwork/core / RecoverSecret

Function RecoverSecret

share/poly.go:174–200  ·  view source on GitHub ↗

RecoverSecret reconstructs the shared secret p(0) from a list of private shares using Lagrange interpolation.

(g kyber.Group, shares []*PriShare, t, n int)

Source from the content-addressed store, hash-verified

172// RecoverSecret reconstructs the shared secret p(0) from a list of private
173// shares using Lagrange interpolation.
174func RecoverSecret(g kyber.Group, shares []*PriShare, t, n int) (kyber.Scalar, error) {
175 x := xScalar(g, shares, t, n)
176
177 if len(x) < t {
178 return nil, errors.New("share: not enough shares to recover secret")
179 }
180
181 acc := g.Scalar().Zero()
182 num := g.Scalar()
183 den := g.Scalar()
184 tmp := g.Scalar()
185
186 for i, xi := range x {
187 num.Set(shares[i].V)
188 den.One()
189 for j, xj := range x {
190 if i == j {
191 continue
192 }
193 num.Mul(num, xj)
194 den.Mul(den, tmp.Sub(xj, xi))
195 }
196 acc.Add(acc, num.Div(num, den))
197 }
198
199 return acc, nil
200}
201
202func xScalar(g kyber.Group, shares []*PriShare, t, n int) map[int]kyber.Scalar {
203 x := make(map[int]kyber.Scalar)

Callers 3

TestSecretRecoveryFunction · 0.70
TestSecretRecoveryDeleteFunction · 0.70

Calls 10

xScalarFunction · 0.85
NewMethod · 0.65
ZeroMethod · 0.45
ScalarMethod · 0.45
SetMethod · 0.45
OneMethod · 0.45
MulMethod · 0.45
SubMethod · 0.45
AddMethod · 0.45
DivMethod · 0.45

Tested by 3

TestSecretRecoveryFunction · 0.56
TestSecretRecoveryDeleteFunction · 0.56