shamir

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package shamir is a port of the hashicorp/vault implementation of Shamir's Secret Sharing which has been modified to work with a finite field rather than arbitrary length content.

Their implementation splits every byte independently into shares and transposes the output together to form a single secret. For our purposes, we expect to be able to combine secrets using addition and then reconstruct a shared polynomial which doesn't work with the byte wise sharing.

This implementation IS NOT constant time as it leverages math/big for big number operations through the finitefield package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Combiner

type Combiner struct {
	// contains filtered or unexported fields
}

Combiner reconstructs the secret

func NewCombiner

func NewCombiner(f *finitefield.Field) *Combiner

func (Combiner) Combine

func (c Combiner) Combine(shares []*Share) ([]byte, error)

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

type Dealer

type Dealer struct {
	// contains filtered or unexported fields
}

Dealer knows the secret and constructs the polynomial

func NewDealer

func NewDealer(f *finitefield.Field) *Dealer

func (Dealer) Split

func (d Dealer) Split(secret []byte, threshold, parts int) (*ShareSet, error)

Split takes 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.

type Polynomial

type Polynomial struct {
	Coefficients []*finitefield.Element
}

Polynomial represents a polynomial of arbitrary degree

type Share

type Share struct {
	Identifier byte                 // x-coordinate
	Secret     *finitefield.Element // y-coordinate
}

Share is a part of the split secret

func NewShare

func NewShare(x byte, y []byte, f *finitefield.Field) *Share

NewShare is a Share constructor

func ShareFromBytes

func ShareFromBytes(b []byte, f *finitefield.Field) *Share

func (Share) Add

func (s Share) Add(other *Share) *Share

Add returns the sum of two Shares.

func (Share) Bytes

func (s Share) Bytes() []byte

Bytes returns the byte representation of the share: `identifier(1-byte) || secret`

func (Share) BytesLe

func (s Share) BytesLe() []byte

func (Share) Order

func (s Share) Order() *big.Int

Order is the order of the Share's finite field.

type ShareSet

type ShareSet struct {
	Shares []*Share
	Polynomial
}

ShareSet represents a set of shares generated from the embedded polynomial. The polynomial is included so that consumers of the shamir package can generate a VSS from the output.

Jump to

Keyboard shortcuts

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