Documentation
¶
Overview ¶
Package sss implements Distribute and Reconstruct functions, which execute distribute and reconstruct procedures defined in the Shamir's Secret Sharing scheme.
This package also provides useful structures, Field and Polynomial.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Reconstruct ¶
Reconstruct computes the secret value from a set of shares.
Example ¶
Example code for Reconstruct function.
// filenames is a slice of file names of shares.
filenames := []string{"share1.dat", "share2.dat", "share3.dat"}
shares := make([]Share, len(filenames))
for i, f := range filenames {
data, err := ioutil.ReadFile(f)
if err != nil {
log.Fatal(err)
}
if err = json.Unmarshal(data, &shares[i]); err != nil {
log.Fatal(err)
}
}
secret, err := Reconstruct(shares)
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile("secret-file", secret, 0644)
if err != nil {
log.Fatal(err)
}
Types ¶
type Field ¶
Field represents a finite field Z/pZ.
func (*Field) MarshalJSON ¶
MarshalJSON implements Marshaler interface.
func (*Field) UnmarshalJSON ¶
UnmarshalJSON implements Unmarshaler interface.
type Polynomial ¶
Polynomial represents a polynomial defined on a finite field.
func NewPolynomial ¶
NewPolynomial creates a new random polynomial on the given finite field. The dimension of the polynomial is the given dim, and it has a given constant.
type Share ¶
type Share struct {
}
Share defines a share of Shamir's Secret Sharing scheme.
func Distribute ¶
Distribute computes shares having a given secret.
Example ¶
Example code for Distribute function.
chunksize := 256
totalShares := 10
threshold := 5
secret, err := ioutil.ReadFile("secret-file")
if err != nil {
log.Fatal(err)
}
shares, err := Distribute(secret, chunksize, totalShares, threshold)
if err != nil {
log.Fatal(err)
}
for i, s := range shares {
data, err := json.Marshal(s)
if err != nil {
log.Fatal(err)
}
filename := fmt.Sprintf("%s.%d.json", "share-", i)
if err = ioutil.WriteFile(filename, data, 0644); err != nil {
log.Fatal(err)
}
}
func (Share) MarshalJSON ¶
MarshalJSON implements Marshaler interface.
func (*Share) UnmarshalJSON ¶
UnmarshalJSON implements Unmarshaler interface.