shamir

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package shamirssgo

  • is a Shamir's Secret Sharing implementation in Go
  • Copyright (C) 2019 Prahesa Kusuma Setia (prahesa at yahoo dot com) *
  • This program is free software: you can redistribute it and/or modify
  • it under the terms of the GNU General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • This program is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU General Public License for more details. *
  • You should have received a copy of the GNU General Public License
  • along with this program. If not, see <http://www.gnu.org/licenses/>.

Package shamir

@author: xwc1125 @date: 2020/6/6 https://github.com/SSSaaS/sssa-golang

Package shamir

@author: xwc1125 @date: 2020/6/6

Index

Constants

View Source
const (
	DefaultPrimeStr = "115792089237316195423570985008687907853269984665640564039457584007913129639747"
)

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(shares []string) (string, error)

*

  • Takes a string array of shares encoded in base64 created via Shamir's
  • Algorithm; each string must be of equal length of a multiple of 88 characters
  • as a single 88 character share is a pair of 256-bit numbers (x, y). *
  • Note: the polynomial will converge if the specified minimum number of shares
  • or more are passed to this function. Passing thus does not affect it
  • Passing fewer however, simply means that the returned secret is wrong.

*

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 ReconstructSecret

func ReconstructSecret(sharesMap map[int]*big.Int, modulus *big.Int) (secret *big.Int, err error)

ReconstructSecret is used to reconstruct the original secret based on the shares given in the sharesMap parameter. The number of shares given need to be greater than or equal to the threshold, otherwise the result of this function is undefined

Types

type ShamirSecret

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

ShamirSecret is a type struct of the package

func New

func New(secret *big.Int, threshold int, modulus *big.Int) *ShamirSecret

New initialize a pointer of ShamirSecret based on the given parameters

func (*ShamirSecret) Shares

func (ss *ShamirSecret) Shares(index int) (share *big.Int, err error)

Shares computes a share based on the index given, index need to be greater than 0

Jump to

Keyboard shortcuts

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