RecoverCommit reconstructs the secret commitment p(0) from a list of public shares using Lagrange interpolation.
(g kyber.Group, shares []*PubShare, t, n int)
| 392 | // RecoverCommit reconstructs the secret commitment p(0) from a list of public |
| 393 | // shares using Lagrange interpolation. |
| 394 | func RecoverCommit(g kyber.Group, shares []*PubShare, t, n int) (kyber.Point, error) { |
| 395 | x := make(map[int]kyber.Scalar) |
| 396 | for i, s := range shares { |
| 397 | if s == nil || s.V == nil || s.I < 0 || n <= s.I { |
| 398 | continue |
| 399 | } |
| 400 | x[i] = g.Scalar().SetInt64(1 + int64(s.I)) |
| 401 | } |
| 402 | |
| 403 | if len(x) < t { |
| 404 | return nil, errors.New("share: not enough good public shares to reconstruct secret commitment") |
| 405 | } |
| 406 | |
| 407 | num := g.Scalar() |
| 408 | den := g.Scalar() |
| 409 | tmp := g.Scalar() |
| 410 | Acc := g.Point().Null() |
| 411 | Tmp := g.Point() |
| 412 | |
| 413 | for i, xi := range x { |
| 414 | num.One() |
| 415 | den.One() |
| 416 | for j, xj := range x { |
| 417 | if i == j { |
| 418 | continue |
| 419 | } |
| 420 | num.Mul(num, xj) |
| 421 | den.Mul(den, tmp.Sub(xj, xi)) |
| 422 | } |
| 423 | Tmp.Mul(num.Div(num, den), shares[i].V) |
| 424 | Acc.Add(Acc, Tmp) |
| 425 | } |
| 426 | |
| 427 | return Acc, nil |
| 428 | } |