Documentation ¶
Overview ¶
Package tshare implements methods for (2,3) threshold secret sharing for splitting secrets into three shares. None of the shares alone give away any information about the secret (other than the length) but any combination of two shares is able to fully recover the secret.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
ErrInvalidShares returned when invalid combination of tagged shares.
var ErrSizeMismatch = errors.New("share size mismatch")
ErrSizeMismatch returned when share sizes don't match.
Functions ¶
func JoinBytes ¶
JoinBytes recovers secret from any two tagged shares.
Example ¶
Recover secret by joining two tagged shares.
package main import ( "fmt" "log" "github.com/wybiral/tshare" ) var shares [][]byte func main() { // any combination of two different shares will work secret, err := tshare.JoinBytes(shares[0], shares[1]) if err != nil { log.Fatal(err) } fmt.Println(secret) }
Output:
func SplitBytes ¶
SplitBytes splits m into 3 shares using 2,3 threshold secret sharing algorithm defined by:
m = secret byte with bits [m7 m6 m5 m4 m3 m2 m1 m0] r = random byte s0 = [ 0 0 0 0 m7 m6 m5 m4] ^ r s1 = [m3 m2 m1 m0 0 0 0 0] ^ r s2 = [m7 m6 m5 m4 m3 m2 m1 m0] ^ r
The first byte of each share is a tag denoting which share it is.
Example ¶
Split secret into three tagged shares.
package main import ( "fmt" "log" "github.com/wybiral/tshare" ) func main() { secret := []byte("Hello world!") shares, err := tshare.SplitBytes(secret) if err != nil { log.Fatal(err) } fmt.Println(shares[0]) fmt.Println(shares[1]) fmt.Println(shares[2]) }
Output:
Types ¶
This section is empty.