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.
- Share Generation: Split a secret into
nshares, requiringkshares 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).
Ensure you have Go installed (version 1.20+ recommended).
-
Clone the repository:
git clone https://github.com/roydsouza/dkg.git cd dkg -
Build the tool:
go build -o dkg ./cmd/dkg
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 5Output Format: x,y (one share per line)
1,829371...
2,192837...
3,918273...
...
To recover a secret, pipe a subset of the shares into the recover command.
# Example: Recover secret from saved shares
cat shares.txt | ./dkg recoverYou 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: 99999The project includes a test suite that verifies small secrets, large secrets, and edge cases.
Use the included helper script:
./run_tests.shOr run the test command directly:
go run ./cmd/dkg test -random-tests 10 -k 3 -n 5cmd/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.
MIT License (or whichever license you choose)