Skip to content
This repository was archived by the owner on Jul 25, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
d4aa532
JavaScript add and sub
simbo1905 Jun 14, 2019
430224e
mul
simbo1905 Jun 14, 2019
acdc6c1
div
simbo1905 Jun 14, 2019
e8af9de
degree
simbo1905 Jun 14, 2019
4a5b04f
git ignore stuff
simbo1905 Jun 14, 2019
2a82537
eval
simbo1905 Jun 14, 2019
37ee04a
generator tests
simbo1905 Jun 16, 2019
d400bd9
All of GF256 passing as JavaScript logic
simbo1905 Jun 16, 2019
b4b56f3
'i' goes backwards
simbo1905 Jun 16, 2019
373bdf1
formatting
simbo1905 Jun 16, 2019
e00b41a
do not use global `i`
simbo1905 Jun 16, 2019
a5bf166
split and join working
simbo1905 Jun 18, 2019
5a58b98
round trips an anglo saxon Rune Poem
simbo1905 Jun 19, 2019
4bee88c
comments on byte length and test beyond string length
simbo1905 Jun 19, 2019
2eabcb4
check only two parts
simbo1905 Jun 19, 2019
df7e0f5
fix N max value and k min value tests
simbo1905 Jun 19, 2019
06db18a
input parameter tests
simbo1905 Jun 19, 2019
ea410dd
fixed empty parts logic
simbo1905 Jun 19, 2019
1a17058
fixed empty parts logic
simbo1905 Jun 19, 2019
c788068
check for equal length parts
simbo1905 Jun 19, 2019
b949b8f
deleting unused file
Jun 20, 2019
4e56cd3
Polygot tests between Java and JavaScript
simbo1905 Jun 28, 2019
fefedc5
Merge branch 'master' of github.com:simbo1905/shamir
simbo1905 Jun 28, 2019
1264f71
reset Java to original codehale
simbo1905 Jun 29, 2019
3adc64e
dockerized testing of JS against Jave
simbo1905 Jun 29, 2019
a992236
improved jsdoc
simbo1905 Jun 30, 2019
eba5ecc
package doc
simbo1905 Jun 30, 2019
5d6b261
fixed types of jsdoc
Jun 30, 2019
55165c8
Fix jsdoc
Jun 30, 2019
5045930
rename script
simbo1905 Jun 30, 2019
2a0bf8c
circleci workflow
simbo1905 Jun 30, 2019
d746a6e
Merge branch 'master' of github.com:simbo1905/shamir
simbo1905 Jun 30, 2019
a579e25
debugging ci workflow
simbo1905 Jun 30, 2019
ad49cec
debugging ci
simbo1905 Jun 30, 2019
254a076
debugging ci
simbo1905 Jun 30, 2019
a9446f2
fixed export
simbo1905 Jun 30, 2019
d973cea
debugging ci
simbo1905 Jun 30, 2019
d21e5f8
debugging ci
simbo1905 Jun 30, 2019
a5a4938
working ci build
simbo1905 Jun 30, 2019
bb40cb3
eslint
simbo1905 Jun 30, 2019
ef2ca31
eslint suggestions
simbo1905 Jun 30, 2019
2a4170d
fix eslint parseInt radix warnings
simbo1905 Jun 30, 2019
c87de08
byte literals for the arrays
simbo1905 Jun 30, 2019
b8b64d1
no prettier formatting and no fixing
simbo1905 Jun 30, 2019
edca28c
eslint fix unnames functions
simbo1905 Jun 30, 2019
e7a3c6a
fix all the eslint
simbo1905 Jun 30, 2019
8269caf
fixed eslint issues
simbo1905 Jun 30, 2019
d11af3d
lint reformatting of the tests
simbo1905 Jun 30, 2019
546c81b
lint the tests
simbo1905 Jun 30, 2019
477feb6
fixed lint errors on GF256Tests.js
simbo1905 Jun 30, 2019
dd92c93
fixed eslint errors
simbo1905 Jun 30, 2019
510be6a
run lint in docker build
simbo1905 Jun 30, 2019
e5a01a8
clean up imports
simbo1905 Jun 30, 2019
24b4c63
fix up readme for JavaScipt notes
simbo1905 Jun 30, 2019
75304f5
remove tweetnacl dependency
simbo1905 Jul 1, 2019
428881b
better example
simbo1905 Jul 1, 2019
8a82673
match version number to upstream
simbo1905 Jul 1, 2019
6ad363b
fix circleci link
simbo1905 Jul 1, 2019
e1a32d3
fixing lint being broken by license headers in local docker build
simbo1905 Jul 1, 2019
1006346
fixed eslint rules in docker build
simbo1905 Jul 1, 2019
0bf58cc
benchmarks for js
simbo1905 Jul 1, 2019
e99a0b6
updated urls in package.json
simbo1905 Jul 1, 2019
54861aa
fixed version number
simbo1905 Jul 1, 2019
4698dc1
fixed figure in bench mark
simbo1905 Jul 1, 2019
df7d24e
tidy up of sample code
simbo1905 Jul 1, 2019
ff4709e
tidy up of sample code
simbo1905 Jul 1, 2019
bc783ac
tidy up of sample code
simbo1905 Jul 1, 2019
48b80a3
made test like the example code
simbo1905 Jul 1, 2019
4487075
Tiered Sharing JavaScript
simbo1905 Jul 2, 2019
8b7f874
wording around performance of js
simbo1905 Jul 2, 2019
5d95027
tidy up of TieredSharing example
simbo1905 Jul 2, 2019
4144409
clarity
simbo1905 Jul 2, 2019
545dcc3
Update README.md
Jul 5, 2023
b4cc321
Tests under Docker runs on latest GraalVM
simbo1905 Nov 12, 2023
359d4c1
docs
simbo1905 Nov 12, 2023
8739770
restore circleci
simbo1905 Nov 12, 2023
b241d65
touch
simbo1905 Nov 12, 2023
9c74a58
getting circleci to build
simbo1905 Nov 12, 2023
6fc4a06
Create docker-image.yml
Nov 12, 2023
59bb032
gh action
simbo1905 Nov 12, 2023
7ad6270
abandon ci
simbo1905 Nov 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions .circleci/config.yml

This file was deleted.

1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
16 changes: 16 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": ["eslint:recommended"],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2018
},
"rules": {
"linebreak-style": ["error", "unix"]
}
}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
node_modules/
.classpath
.idea/
.project
.settings
.vscode/
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package-lock.json
node_modules/
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Run the stand java build on openjdk
FROM maven AS build
COPY . src
WORKDIR src
RUN mvn package

# Copy the result to graaljs and test node.js+java in the same vm
FROM ghcr.io/graalvm/nodejs-community:23.0.2-jvm17-ol9-20231024 AS graal
COPY --from=build /src /app/src
WORKDIR src
RUN npm test && npm run testwithjava && npm run lint
119 changes: 109 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
# Shamir's Secret Sharing

[![CircleCI](https://circleci.com/gh/codahale/shamir.svg?style=svg)](https://circleci.com/gh/codahale/shamir)
A implementation of [Shamir's Secret Sharing
algorithm](http://en.wikipedia.org/wiki/Shamir's_Secret_Sharing) over GF(256) in both Java and JavaScript. The Java code is from
the archive Codahale's [shamir](https://github.com/codahale/shamir) implementation. The
Javascript version is original and is crossed checked against the Java version.

A Java implementation of [Shamir's Secret Sharing
algorithm](http://en.wikipedia.org/wiki/Shamir's_Secret_Sharing) over GF(256).
You can use docker build both codebases and run cross-checks between them using:

## Add to your project
`docker build . `

*Note: module name for Java 9+ is `com.codahale.shamir`.*

## Add to your JavaScript project

```sh
npm i shamir
```

## Use the thing in JavaScript

```javascript
const { split, join } = require('shamir');
const { randomBytes } = require('crypto');

const PARTS = 5;
const QUORUM = 3;

function doIt() {
const secret = 'hello there';
// you can use any polyfill to covert between strings and Uint8Array
const utf8Encoder = new TextEncoder();
const utf8Decoder = new TextDecoder();
const secretBytes = utf8Encoder.encode(secret);
// parts is a map of part numbers to Uint8Array
const parts = split(randomBytes, PARTS, QUORUM, secretBytes);
// we only need QUORUM of the parts to recover the secret
delete parts['2'];
delete parts['3'];
// recovered is an Unit8Array
const recovered = join(parts);
// prints 'hello there'
console.log(utf8Decoder.decode(recovered));
}
```

## [Optional] Add to your Java project

The Java version is available as the orginal Codahale distribution:

```xml
<dependency>
Expand All @@ -15,9 +56,7 @@ algorithm](http://en.wikipedia.org/wiki/Shamir's_Secret_Sharing) over GF(256).
</dependency>
```

*Note: module name for Java 9+ is `com.codahale.shamir`.*

## Use the thing
## Use the thing in Java

```java
import com.codahale.shamir.Scheme;
Expand Down Expand Up @@ -94,7 +133,7 @@ performing the same operation over `GF(Q)` takes several seconds, even using per
Treating the secret as a single `y` coordinate over `GF(Q)` is even slower, and requires a modulus
larger than the secret.

## Performance
## Java Performance

It's fast. Plenty fast.

Expand All @@ -108,7 +147,25 @@ Benchmarks.split 4 1024 avgt 200 396.708 ± 1.520 us/op

**N.B.:** `split` is quadratic with respect to the number of shares being combined.

## Tiered sharing
## JavaScript Performance

For a 1KiB secret split with a `n=4,k=3` scheme running on NodeJS v10.16.0:

```
Benchmark (n) (secretSize) Cnt Score Units
Benchmarks.join 4 1024 200 2.08 ms/op
Benchmarks.split 4 1024 200 2.78 ms/op
```

Split is dominated by the calls to `Crypto.randomBytes` to get random polynomials to encode each byte of the secet. Using a more realistic 128 bit secret with `n=4,k=3` scheme running on NodeJS v10.16.0:

```
Benchmark (n) (secretSize) Cnt Score Units
Benchmarks.join 5 16 200 0.083 ms/op
Benchmarks.split 5 16 200 0.081 ms/op
```

## Tiered Sharing Java

Some usages of secret sharing involve levels of access: e.g. recovering a secret requires two admin
shares and three user shares. As @ba1ciu discovered, these can be implemented by building a tree of
Expand All @@ -120,7 +177,7 @@ class BuildTree {
final byte[] secret = "this is a secret".getBytes(StandardCharsets.UTF_8);

// tier 1 of the tree
final Scheme adminScheme = new Scheme(new SecureRandom(), 5, 2);
final Scheme adminScheme = new Scheme(new SecureRandom(), 3, 2);
final Map<Integer, byte[]> admins = adminScheme.split(secret);

// tier 2 of the tree
Expand All @@ -147,8 +204,50 @@ By discarding the third admin share and the first two sets of user shares, we ha
which can be used to recover the original secret as long as either two admins or one admin and three
users agree.

## Tiered Sharing JavaScript

Sharing a secret requiring either two admins or one admin and three users to recover:

```javascript
const secret = new Unit8Array([1, 2, 3]);

const adminParts = 3;
const adminQuorum = 2;
const adminSplits = split(randomBytes, adminParts, adminQuorum, secret);

const userParts = 4;
const userQuorum = 3;
const usersSplits = split(randomBytes, userParts, userQuorum, adminSplits['3'] );

// throw away third share that is split into 4 user parts
delete adminSplits['3'];

console.log('Admin Shares:');
console.log(`1 = ${adminSplits['1']}`);
console.log(`2 = ${adminSplits['2']}`);

console.log('User Shares:');
console.log(`1 = ${usersSplits['1']}`);
console.log(`2 = ${usersSplits['2']}`);
console.log(`3 = ${usersSplits['3']}`);
console.log(`4 = ${usersSplits['4']}`);

// throw away an admin share and one user share
delete adminSplits['2'];
delete usersSplits['1'];

// reconstruct the deleted third admin share from the three user shares
const joinedUserShares = join(usersSplits);
// use the first admin share and the recovered third share
const recoverdSecret = join({ '1': adminSplits['1'], '3': joinedUserShares } );
```

There is a unit test for this in `src/test/js/TieredSharing.js`.

## License

Copyright © 2017 Coda Hale

Copyright © 2019 Simon Massey

Distributed under the Apache License 2.0.
Loading