Skip to content

roydsouza/dkg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DKG: Distributed Key Generation (Shamir Secret Sharing)

DKG is a Go-based command-line tool that implements Shamir's Secret Sharing (SSS). It allows you to split a secret integer into multiple shares and recover the original secret using a threshold number of those shares.

Features

  • Share Generation: Split a secret into n shares, requiring k shares to recover.
  • Secret Recovery: Reconstruct the integer secret using Lagrange Interpolation.
  • Mathematical Security: Uses finite field arithmetic (Prime Field P-256) for information-theoretic security.
  • Simplicity: Designed to work with standard Unix pipes (stdin/stdout).

Installation

Ensure you have Go installed (version 1.20+ recommended).

  1. Clone the repository:

    git clone https://github.com/roydsouza/dkg.git
    cd dkg
  2. Build the tool:

    go build -o dkg ./cmd/dkg

Usage

1. Splitting a Secret (share)

To split a secret, use the share command. You must provide the secret (integer), the threshold k, and the total shares n.

# Syntax: ./dkg share -secret <INT> -k <THRESHOLD> -n <TOTAL>

# Example: Split secret '12345' into 5 shares, requiring 3 to recover
./dkg share -secret 12345 -k 3 -n 5

Output Format: x,y (one share per line)

1,829371...
2,192837...
3,918273...
...

2. Recovering a Secret (recover)

To recover a secret, pipe a subset of the shares into the recover command.

# Example: Recover secret from saved shares
cat shares.txt | ./dkg recover

3. End-to-End Example (Piping)

You can verify the process by piping share directly into recover.

# Split and immediately recover
./dkg share -secret 99999 -k 2 -n 3 | ./dkg recover
# Output: 99999

Testing

The project includes a test suite that verifies small secrets, large secrets, and edge cases.

Running Tests

Use the included helper script:

./run_tests.sh

Or run the test command directly:

go run ./cmd/dkg test -random-tests 10 -k 3 -n 5

Project Structure

  • cmd/dkg/: Main entry point for the CLI application.
  • internal/shamir/: Core logic for Shamir's Secret Sharing (finite field arithmetic, polynomial generation, interpolation).
  • run_tests.sh: Bash script for automated testing.

License

MIT License (or whichever license you choose)

About

Distributed Key Generator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published