sss: github.com/itslab-kyushu/sss/sss Index | Examples | Files

package sss

import "github.com/itslab-kyushu/sss/sss"

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

Package Files

doc.go field.go polynomial.go share.go sss.go

func Distribute Uses

func Distribute(secret []byte, chunkByte, size, threshold int) (shares []Share, err error)

Distribute computes shares having a given secret.

Example code for Distribute function.

Code:

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 Reconstruct Uses

func Reconstruct(shares []Share) (bytes []byte, err error)

Reconstruct computes the secret value from a set of shares.

Example code for Reconstruct function.

Code:

// 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)
}

type Field Uses

type Field struct {
    // Prime number.
    Prime *big.Int
    // Max is Prime - 1.
    Max *big.Int
}

Field represents a finite field Z/pZ.

func NewField Uses

func NewField(prime *big.Int) *Field

NewField creates a new finite field.

func (*Field) MarshalJSON Uses

func (f *Field) MarshalJSON() ([]byte, error)

MarshalJSON implements Marshaler interface.

func (*Field) UnmarshalJSON Uses

func (f *Field) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements Unmarshaler interface.

type Polynomial Uses

type Polynomial struct {
    Field        *Field
    Dimension    int
    Coefficients []*big.Int
    Const        *big.Int
}

Polynomial represents a polynomial defined on a finite field.

func NewPolynomial Uses

func NewPolynomial(field *Field, c *big.Int, dim int) (*Polynomial, error)

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.

func (*Polynomial) Call Uses

func (p *Polynomial) Call(x *big.Int) *big.Int

Call computes a value F(x) where x is the given number.

type Share Uses

type Share struct {
    Key   *big.Int
    Value []*big.Int
    Field *Field
}

Share defines a share of Shamir's Secret Sharing scheme.

func (Share) MarshalJSON Uses

func (s Share) MarshalJSON() ([]byte, error)

MarshalJSON implements Marshaler interface.

func (*Share) UnmarshalJSON Uses

func (s *Share) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements Unmarshaler interface.

Package sss imports 5 packages (graph) and is imported by 4 packages. Updated 2017-03-08. Refresh now. Tools for package owners.