shamir

command module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2024 License: MIT Imports: 1 Imported by: 0

README

Shamir Secret Sharing

This is a practical example of Shamir's secret sharing.

This tool allows you to divide up a secret string S into n shares where any k of the shares will allow you to reconstruct the original secret S. If you have fewer than k of the shares, you will have no information (other than the length of the secret) about what that secret is.

Usage

To distribute the secrets, use the command

shamir distribute -S "<secret>" -n <number of shares to produce> -k <minimum number of shares to reconstruct the secret> -d "<output directory>"

The shares will be saved as text files in the specified output directory. The default directory is the current directory.

Way we run shamir distribute -S="This is a super secret secret." -n=5 -k=3. Five text files will be saved in the current directory, each containing a share of the secret. The first file might be called shamir-IW6CPGV5COQ6FHMI-11d-1.txt, and it contains the text

shamir-IW6CPGV5COQ6FHMI-11d-1-IyJneCEokIwf319Sl+sqeuLtBLwqWMxyd/m5Hj/U

The prefix shamir- indicates that this is a share in Shamir's secret sharing scheme. IW6CPGV5COQ6FHMI is a randomly generated ID that allows you to correlate secrets and shares. 11d is the primitive polynomial used to construct the underlying Galois field. 1 is the x coordinate of the share. The remaining text is base64-encoded data. Each byte corresponds to the value of a polynomial evaulated at the corresponding x-coordinate of the share. (Note that each byte is encoded separately, each with a randomly-generated polynomial.)

To reconstruct the message, simply run shamir reconstruct in the same directory you ran shamir distribute command. This will check any text files with the .txt file extension for shares.

Say we have the following text files:

shamir-IW6CPGV5COQ6FHMI-11d-1-IyJneCEokIwf319Sl+sqeuLtBLwqWMxyd/m5Hj/U
shamir-IW6CPGV5COQ6FHMI-11d-4-lKF0rNRgjQGXKJ0gbfKDMompvM6KGtAPw5TGAUGc
shamir-IW6CPGV5COQ6FHMI-11d-5-4+t6p9Uhbq3p17EHinzbaBgh2wDFNjwO0Q4Negpm

We then run the command shamir reconstruct, and we see that the secret is successfully reconstructed and printed to the console:

IW6CPGV5COQ6FHMI: This is a super secret secret.

If we try to only use shares 4 and 5, we cannot reconstruct the message, and we get gibberish:

IW6CPGV5COQ6FHMI: U�L��y&�r�-����G��=ѫ�G
����pS

Note that the file names themselves do not matter. All of the information needed to reconstruct them is provided in the file itself.

Documentation

Overview

Copyright © 2024 49pctber

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL