You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
arnaucube 9d84e20a5f add html and js to interact with the wasm lib, add server serving wasm lib mime type, wasm wrapper print shares result into document 5 years ago
wasm add html and js to interact with the wasm lib, add server serving wasm lib mime type, wasm wrapper print shares result into document 5 years ago
LICENSE Initial commit 5 years ago
README.md starting WASM wrapper 5 years ago
go.mod starting WASM wrapper 5 years ago
go.sum starting WASM wrapper 5 years ago
shamirsecretsharing.go add lagrange interpolation js to wasm wrapper and parser of the data struct 5 years ago
shamirsecretsharing_test.go add lagrange interpolation js to wasm wrapper and parser of the data struct 5 years ago

README.md

Shamir Secret Sharing Go Report Card GoDoc

This repo contains a Go lang implementation of Shamir Secret Sharing, and a compiled Web Assembly version from the Go code to be used from the browser.

Wasm usage

Compile to wasm, inside the wasm directory, execute:

GOARCH=wasm GOOS=js go build -o shamirsecretsharing.wasm shamirsecretsharing-wasm-wrapper.go

Add the file wasm_exec.js in the directory:

cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .

Call the library from javascript:

// Create shares from a secret
// nNeededShares: number of secrets needed
// nShares: number of shares
// p: random point
// k: secret to share
createShares(nNeededShares, nShares, p, k);

Usage from Go

// define secret to share
k, ok := new(big.Int).SetString("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", 10)
assert.True(t, ok)

// define random prime
p, err := rand.Prime(rand.Reader, bits/2)
assert.Nil(t, err)

// define how many shares want to generate
nShares := big.NewInt(int64(6))

// define how many shares are needed to recover the secret
nNeededShares := big.NewInt(int64(3))

// create the shares
shares, err := Create(
	nNeededShares,
	nShares,
	p,
	big.NewInt(int64(k)))
assert.Nil(t, err)

// select shares to use
var sharesToUse [][]*big.Int
sharesToUse = append(sharesToUse, shares[2])
sharesToUse = append(sharesToUse, shares[1])
sharesToUse = append(sharesToUse, shares[0])

// recover the secret using Lagrange Interpolation
secr := LagrangeInterpolation(sharesToUse, p)

// check that the restored secret matches the original secret
if !bytes.Equal(k.Bytes(), secr.Bytes()) {
	fmt.Println("reconstructed secret not correspond to original secret")
}