tshare

package module
Version: v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2019 License: MIT Imports: 2 Imported by: 0

README

tshare GoDoc

This package implements (2,3) XOR 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.

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

View Source
var ErrInvalidShares = errors.New("invalid shares")

ErrInvalidShares returned when invalid combination of tagged shares.

View Source
var ErrSizeMismatch = errors.New("share size mismatch")

ErrSizeMismatch returned when share sizes don't match.

Functions

func JoinBytes

func JoinBytes(a, b []byte) ([]byte, error)

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

func SplitBytes(m []byte) ([][]byte, error)

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.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL