Coder Social home page Coder Social logo

sss-go's Introduction

Shamir secret sharing with Go

Build Status

sss-go contains Go bindings for my Shamir secret sharing library. This library allows users to split secret data into a number of different shares. With the possession of some or all of these shares, the original secret can be restored.

An example use case is a beer brewery which has a vault which contains their precious super secret recipe. The 5 board members of this brewery do not trust all the others well enough that they won't secretly break into the vault and sell the recipe to a competitor. So they split the code into 5 shares, and allow 4 shares to restore the original code. Now they are sure that the majority of the staff will know when the vault is opened, but they can still open the vault when one of the staff members is abroad or sick at home.

Installation

go get github.com/dsprenkels/sss-go

Usage

Secrets are provided as []byte slices with a length of 64. Shares are generated from secret data using sss.CreateShares and shares can be combined again using the sss.CombineShares function. Shares are always 113 bytes long and sss.CombineShares will return an error if one of the given shares is of an invalid length.

package main

import (
    "log"
    "github.com/dsprenkels/sss-go"
)

func main() {
    // Make a new slice of secret data [42, ..., 42]
    data := make([]byte, 64)
    for i, _ := range data {
        data[i] = 42
    }

    // Create 5 shares; allow 4 to restore the original data
    shares, err := sss.CreateShares(data, 5, 4)
    if err != nil {
        log.Fatalln(err)
    }

    // Permute and lose some of the shares (for demonstrational purposes)
    new_shares := make([][]byte, 4)
    new_shares[0] = shares[2]
    new_shares[1] = shares[4]
    new_shares[2] = shares[0]
    new_shares[3] = shares[3]

    // Try to restore the original secret
    restored, err := sss.CombineShares(new_shares)
    if err != nil {
        log.Fatalln(err)
    }

    log.Println(restored)
}

Changelog

Version 0.1.1

  • Remove an unintended side channel which allows a participating attacker with access to a accurate timing channel to iteratively guess shares during the execution of combine_shares.

Questions

Feel free to send me an email on my Github associated e-mail address.

sss-go's People

Contributors

dsprenkels avatar robincgit avatar

Stargazers

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

Watchers

 avatar  avatar

sss-go's Issues

warning: non-void function does not return a value [-Wreturn-type]

When building in high language, an error occurred as below.

$ go version
$ go version go1.20.3 darwin/arm64
$ go build
# github.com/dsprenkels/sss-go
../../../../go/pkg/mod/github.com/dsprenkels/[email protected]/sss.go:34:2: warning: non-void function does not return a value [-Wreturn-type]

sss-go/sss.go

Line 31 in 780fb2c

// sss_combine_shares_go_wrapper(uint8_t *data, sss_Share *shares, uint8_t k)

I fixed some of the contents of the cgo in your code.
https://github.com/minias/sss-go

// int sss_combine_shares_go_wrapper(uint8_t *data, sss_Share *shares, uint8_t k)
// {
//     return sss_combine_shares(data, shares, k);
// }

not usable as go module due to git submodule not being initialized

I was converting a project of mine to use go modules to be independent of GOPATH and compilation fails with:

go: finding github.com/dsprenkels/sss-go v0.1.2-0.20171030131311-7f0045c35e77
# github.com/dsprenkels/sss-go
../../../../go/pkg/mod/github.com/dsprenkels/[email protected]/hazmat.go:3:11: fatal error: hazmat.h: No such file or directory
 // #include "hazmat.h"
           ^~~~~~~~~~
compilation terminated.

This is apparently due to golang/go#24094 (comment), i.e. Git submodules not being initialized in go modules. And since this binding uses dsprenkels/sss in a submodule ..

$ ls -la ~/go/pkg/mod/github.com/dsprenkels/[email protected]/
total 52
dr-xr-xr-x 1 ansemjo users  216 Feb 19 14:23 .
drwxr-xr-x 1 ansemjo users   86 Feb 19 14:23 ..
-r--r--r-- 1 ansemjo users   42 Feb 19 14:23 .editorconfig
-r--r--r-- 1 ansemjo users  275 Feb 19 14:23 .gitignore
-r--r--r-- 1 ansemjo users   75 Feb 19 14:23 .gitmodules
-r--r--r-- 1 ansemjo users 4742 Feb 19 14:23 hazmat.go
-r--r--r-- 1 ansemjo users 1354 Feb 19 14:23 hazmat_test.go
-r--r--r-- 1 ansemjo users 1098 Feb 19 14:23 LICENSE
-r--r--r-- 1 ansemjo users 2540 Feb 19 14:23 README.md
-r--r--r-- 1 ansemjo users 4785 Feb 19 14:23 sss.go
-r--r--r-- 1 ansemjo users 1606 Feb 19 14:23 sss_test.go
-r--r--r-- 1 ansemjo users   53 Feb 19 14:23 .travis.yml
-r--r--r-- 1 ansemjo users  625 Feb 19 14:23 util.go

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.