Documentation ¶
Index ¶
Constants ¶
const ()
Variables ¶
var ( // config ErrRequiredConfig = fmt.Errorf("configuration is required") ErrConfigMin = fmt.Errorf("wrong minimum number of shares") ErrConfigNoPrime = fmt.Errorf("no prime provided") ErrConfigInvalidPrime = fmt.Errorf("invalid prime provided") ErrMessageTooLong = fmt.Errorf("the message cannot be hidden with the prime provided") // encode // math ErrReadingRandom = fmt.Errorf("error reading random number") )
var DefaultPrime, _ = new(big.Int).SetString("21888242871839275222246405745257275088548364400416034343698204186575808495617", 10)
bn254 𝔽r
Functions ¶
func HideMessage ¶
HideMessage generates the shares of the message using the Shamir Secret Sharing algorithm. It returns the shares as strings. The message is encoded as a big.Int and the shares are calculated solving a polynomial with random coefficients. The first coefficient is the encoded message. It uses the configuration provided in the Config struct, if the prime number is not defined it uses the 12th Mersenne Prime (2^127 - 1) as default. It returns an error if the message cannot be encoded.
func RecoverMessage ¶
RecoverMessage recovers the message from the shares using the Shamir Secret Sharing algorithm. It returns the message as a string. The shares are given as strings. It uses the configuration provided in the Config struct, if the prime number is not defined it uses the 12th Mersenne Prime (2^127 - 1) as default. It returns an error if the message cannot be recovered. The shares include the index of the share and the share itself, so the order of the provided shares does not matter. It decodes the points of the polynomial from the shares and calculates the Lagrange interpolation to recover the secret.
Types ¶
type Config ¶
Config struct defines the configuration for the Shamir Secret Sharing algorithm. It includes the number of shares to generate, the minimum number of shares to recover the secret, and the prime number to use as finite field.
func (*Config) MaxMessageLen ¶ added in v0.0.4
MaxMessageLen returns the maximum size of the secret that can be hidden in a share, it is the size of the prime number in bytes minus 1, to ensure the secret is smaller than the prime number.
func (*Config) ValidConfig ¶ added in v0.0.4
ValidConfig checks if the configuration is valid for the secret provided. It checks if the number of shares is greater than the minimum number of shares, if the minimum number of shares is greater than the number of shares less one or if it is smaller than the minimum number of shares less one, if the config has a valid prime number, and if the message can be hidden with the prime number.
func (*Config) ValidPrime ¶ added in v0.0.4
ValidPrime checks if the configuration has a valid prime number. It returns an error if the prime number is not defined or if it is not a prime number.