shamir

package
v0.0.0-...-729ab49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2020 License: MIT Imports: 8 Imported by: 0

README

Documentation

Documentation

Index

Constants

View Source
const (
	DefaultPrimeStr = "115792089237316195423570985008687907853269984665640564039457584007913129639747"
)
View Source
const (
	// ShareOverhead is the byte size overhead of each share
	// when using Get on a secret. This is caused by appending
	// a one byte tag to the share.
	ShareOverhead = 1
)

Variables

View Source
var (
	ErrCannotRequireMoreShares = errors.New("cannot require more shares then existing")
	ErrOneOfTheSharesIsInvalid = errors.New("one of the shares is invalid")
)

Functions

func Combine

func Combine(parts [][]byte) ([]byte, error)

Combine is used to reverse a Get and reconstruct a secret once a `threshold` number of parts are available.

func Create

func Create(minimum int, shares int, raw string) ([]string, error)

*

  • Returns a new arary of secret shares (encoding x,y pairs as base64 strings)
  • created by Shamir's Secret Sharing Algorithm requring a minimum number of
  • share to recreate, of length shares, from the input secret raw as a string

*

func IsValidShare

func IsValidShare(candidate string) bool

*

  • Takes in a given string to check if it is a valid secret *
  • Requirements:
  • Length multiple of 88
  • Can decode each 44 character block as base64 *
  • Returns only success/failure (bool)

*

func Split

func Split(secret []byte, parts, threshold int) ([][]byte, error)

Get takes an arbitrarily long secret and generates a `parts` number of shares, `threshold` of which are required to reconstruct the secret. The parts and threshold must be at least 2, and less than 256. The returned shares are each one byte longer than the secret as they attach a tag used to reconstruct the secret.

Types

type ShamirSharingScheme

type ShamirSharingScheme struct {
	// N: the number of shares that each secret is split into
	N int
	// R: the minimum number of shares needed to reconstruct the secret
	R int
	// contains filtered or unexported fields
}

In Shamir’s scheme, instead of picking random field elements that sum up to the secret x as we did above, to share x we sample a random polynomial f with the condition that f(0) = x and evaluate this polynomial at N non-zero points to obtain the shares as f(1), f(2), …, f(N).

func NewShamirSharingScheme

func NewShamirSharingScheme(secret int, participants int, min int) ShamirSharingScheme

The essential idea of Adi Shamir's threshold scheme is that 2 points are sufficient to define a line, 3 points are sufficient to define a parabola, 4 points to define a cubic curve and so forth. That is, it takes k points to define a polynomial of degree k − 1

func (*ShamirSharingScheme) Generate

func (as *ShamirSharingScheme) Generate()

split secret using shamir scheme into requested shares given that only 'minimumSplits' shares are needed to reconstruct

func (*ShamirSharingScheme) Print

func (as *ShamirSharingScheme) Print()

it will print generated points using shamir secret schema

func (*ShamirSharingScheme) Reconstruct

func (as *ShamirSharingScheme) Reconstruct(points []int) (error, int)

tries to reconstruct given secret from a set of points

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL