Skip to content

onbit-uchenik/shamir_secret_share

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shamir_secret_share

C++ implementation of Shamir Secret Scheme over GF(256)

Using Shamir Secret Share Library

 git clone https://github.com/onbitSyn/shamir_secret_share.git
 cd shamir_secret_share/
 ls -la

open your favourite editor vscode or atom vscode

 code .

atom

atom .

now create a new c++ file

  #include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include "./src/GF(256).h"
#include "./src/shamir.h"

using namespace std;
using namespace GF256;
using namespace shamir;

int main() {
  init(); //to initialise the library
  scheme scheme1(6,4);// a scheme is formed with 6 members out of which 4 will be used to reconstruct secret message
  shares* scheme1_shares = scheme1.createShares("Keep it Secret"); //6 shares are formed for secret "Keep it Secret".
  string secret = scheme1.getSecret(scheme1_shares); //secret is reconstructed from the shares
  cout << secret << endl;
  return 0;
  }

for more information see the example to compile code

g++ example.cpp ./src/shamir.o ./src/GF\(256\).o -o example

How Shamir's Algorithm works

Consider a example in which a father wants to secretly divide his Will among 4 children and wants when 3 or more than 3 children wants to read it, then only it can be accessible. Now, father uses shamir's algorithm to secretly divide the will into 4 pieces. Shamir algorithm make a random polynomial :-

$$p(x) = a*x^2 + b*x + c p(0) = c (represent will in integer) p(1) = a+b+c p(2) = 4*a + 2*b + c p(3) = 9*a + 3*b + c$$

share of children 1 :- {1,p(1)}
share of children 2 :- {2,p(2)}
share of children 3 :- {3,p(3)}
share of children 4 :- {4,p(4)}

Implementation Details

Shamir's Secret Share Algorithm only works for the finite field, and this library performs all operations in GF(256).Each byte of the secret is encoded as separate byte. For reconstruction of the secret, Lagrange interpolation is used.

License

Copyright © 2020 Anubhav Vats Distributed under the Apache License 2.0

Releases

No releases published

Packages

No packages published

Languages