Git Product home page Git Product logo

shamir_secret_share's Introduction

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

shamir_secret_share's People

Contributors

charlesaverill avatar onbit-uchenik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

shamir_secret_share's Issues

Using this library in EOS smart contract

I am trying to use this library in EOS smart contract, as it supports c++. Code is as follow:

#include <eosio/eosio.hpp>
#include <eosio/print.hpp>
#include <eosio/system.hpp>
#include <string>
#include <vector>
#include "shamir_secret_share/src/GF(256).h"
#include "shamir_secret_share/src/shamir.h"

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

class [[eosio::contract("shamirkey")]] shamirkey: public eosio::contract {
        public:
                using contract::contract;
                shamirkey(name receiver, name code, datastream<const char*> ds):contract(receiver, code, ds) {}
                [[eosio::action]]
                        void sharing(){
                                require_auth(_self);
                                init();
                                scheme scheme1(8,5);
                                shares* scheme1_shares = scheme1.createShares("its our team secret");
                                for(int i=0;i<8;i++) {
                                        print("shares of pariticipant ", (i+1), " => ");
                                        for(auto val:(*scheme1_shares)[i]) {
                                                print(val.x, " ", val.y);
                                        }
                                        print("_____________________________________________________");
                                }
                        }
};

when I compile this SC using:

eosio-cpp shamirkey.cpp -o shamirkey.wasm

Its giving errors :

/usr/opt/eosio.cdt/1.7.0/bin/wasm-ld: error: /tmp/shamirkey.cpp.o: undefined symbol: shamir::init()
/usr/opt/eosio.cdt/1.7.0/bin/wasm-ld: error: /tmp/shamirkey.cpp.o: undefined symbol: shamir::scheme::scheme(int, int)
/usr/opt/eosio.cdt/1.7.0/bin/wasm-ld: error: /tmp/shamirkey.cpp.o: undefined symbol: shamir::scheme::createShares(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)
/usr/opt/eosio.cdt/1.7.0/bin/wasm-ld: error: /tmp/shamirkey.cpp.o: undefined symbol: GF256::byte::print()

Please help. How to use this library in an EOSIO smart contract?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.