This project implements Shamir's Secret Sharing with zero dependency in Go. Shamir's Secret Sharing is a cryptographic algorithm that allows a secret to be divided into parts, giving each participant its own unique part. To reconstruct the secret, a minimum number of parts are needed. This implementation uses GF(256) arithmetic for secure and efficient operations.
To install this package, you need to have Go installed on your machine.
go get -u go.openfort.xyz/shamir-secret-sharing-go
import (
"go.openfort.xyz/shamir-secret-sharing-go"
)
package main
import (
"fmt"
sss "go.openfort.xyz/shamir-secret-sharing-go"
)
func main() {
secret := []byte("this is a secret")
n := 5
threshold := 3
shares, err := sss.Split(n, threshold, secret)
if err != nil {
fmt.Println("Error splitting the secret:", err)
return
}
fmt.Println("Shares:")
for i, share := range shares {
fmt.Printf("Share %d: %v\n", i+1, share)
}
// Using threshold shares to reconstruct the secret
recoveredSecret, err := sss.Combine(shares[:threshold])
if err != nil {
fmt.Println("Error reconstructing the secret:", err)
return
}
fmt.Printf("Recovered Secret: %s\n", recoveredSecret)
}
Split(n, threshold int, secret []byte) ([][]byte, error)
: Splits the secret into n shares with a minimum threshold of shares needed to reconstruct the secret.Combine(shares [][]byte) ([]byte, error)
: Combines the given shares to reconstruct the secret.