Skip to content

A zero dependency implementation of Shamir Secret Sharing in pure Go

License

Notifications You must be signed in to change notification settings

openfort-xyz/shamir-secret-sharing-go

Repository files navigation

Shamir's Secret Sharing

Go Go Report Card Go Reference

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.

Installation

To install this package, you need to have Go installed on your machine.

go get -u go.openfort.xyz/shamir-secret-sharing-go

Usage

Import the package

import (
    "go.openfort.xyz/shamir-secret-sharing-go"
)

Example: Splitting and Combining a Secret

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)
}

Functions

  • 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.

About

A zero dependency implementation of Shamir Secret Sharing in pure Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages