secret

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Secret

An implementation of Shamir's secret sharing.

What?

Secret sharing splits a secret (typically a password, key or similar short data) into a number of shares to be given to trusted parties, with a threshold of required shares to reassemble lower than the total number.

In other words, a secret can be split into 10 shares, and with a threshold of 2 you can recreate the secret with any pair of shares.

Recommendations

This implementation technically supports a very large number of shares, with pretty huge secrets (several megabytes). You shouldn't, but you could make use of that. The resulting shares will be larger than the input secret, so it can get clunky.

Keeping the number of shares in the dozens at most is probably smart, and the size of the input secret shouldn't normally be required to be larger than a typical login certificate.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSyntax = errors.New("invalid syntax in share")

ErrInvalidSyntax is returned if a share isn't formatted as a number, hyphen and string.

Functions

func Combine

func Combine(points []Point) []byte

Combine points via Lagrange interpolation to form the secret, provided a number of points equivalent to the threshold are supplied.

func ShareToString

func ShareToString(p Point) string

ShareToString returns a nicely formatted hexadecimal representation of a share.

Types

type Point

type Point struct {
	X uint32
	Y *gmp.Int
}

Point in the polynomial.

func FixedSplit added in v1.1.0

func FixedSplit(secret []byte, t, n uint, prime *gmp.Int) []Point

FixedSplit works like Split, with the option to specify a prime to use. This allows uniform share lengths across different input sizes. The prime still needs to be larger than the secret, and will be adjusted accordingly.

func Split

func Split(secret []byte, t, n uint) []Point

SplitSecret into n parts, requiring threshold t parts to recover it. secret should be relatively small, otherwise the resulting shares end up huge. threshold must be minimum 2, and will be silently increased to 2 if less. n should be higher than t, and will be corrected to t+1 if not.

The resulting slice of points will be numbered from 1 and up.

func StringToShare

func StringToShare(s string) (Point, error)

StringToShare will split a share string into a Point.

Directories

Path Synopsis
Package mersenne returns Mersenne primes as libgmp numbers.
Package mersenne returns Mersenne primes as libgmp numbers.

Jump to

Keyboard shortcuts

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