mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 18:01:39 +00:00
(no commit message provided)
This commit is contained in:
Executable
+35
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// Copyright Coinbase, Inc. All Rights Reserved.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
package sharing
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/onsonr/hway/crypto/core/curves"
|
||||
)
|
||||
|
||||
type Polynomial struct {
|
||||
Coefficients []curves.Scalar
|
||||
}
|
||||
|
||||
func (p *Polynomial) Init(intercept curves.Scalar, degree uint32, reader io.Reader) *Polynomial {
|
||||
p.Coefficients = make([]curves.Scalar, degree)
|
||||
p.Coefficients[0] = intercept.Clone()
|
||||
for i := 1; i < int(degree); i++ {
|
||||
p.Coefficients[i] = intercept.Random(reader)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p Polynomial) Evaluate(x curves.Scalar) curves.Scalar {
|
||||
degree := len(p.Coefficients) - 1
|
||||
out := p.Coefficients[degree].Clone()
|
||||
for i := degree - 1; i >= 0; i-- {
|
||||
out = out.Mul(x).Add(p.Coefficients[i])
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user