From d4aa53213364d97a867247e73a7f488215110d95 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Fri, 14 Jun 2019 07:25:27 +0100 Subject: [PATCH 01/78] JavaScript add and sub --- package.json | 30 +++++++++++++++++++++++++++++ shamir.iml | 39 ++++++++++++++++++++++++++++++++++++++ src/main/js/GF256.js | 11 +++++++++++ src/main/js/Scheme.js | 4 ++++ src/test/js/ShamirTests.js | 28 +++++++++++++++++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 package.json create mode 100644 shamir.iml create mode 100644 src/main/js/GF256.js create mode 100644 src/main/js/Scheme.js create mode 100644 src/test/js/ShamirTests.js diff --git a/package.json b/package.json new file mode 100644 index 0000000..2421c66 --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "shamir", + "version": "1.0.0", + "description": "A JavaScript implementation of Shamir's Secret Sharing algorithm over GF(256).", + "main": "src/main/js/Scheme.js", + "scripts": { + "test": "node --polyglot --jvm src/test/js/ShamirTests.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/codahale/shamir.git" + }, + "keywords": [ + "sss", + "shamir", + "secrets", + "sharing", + "crypto", + "nuclear-codes" + ], + "author": "Simon Massey", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/codahale/shamir/issues" + }, + "homepage": "https://github.com/codahale/shamir#readme", + "devDependencies": { + "tape": "^4.10.2" + } +} diff --git a/shamir.iml b/shamir.iml new file mode 100644 index 0000000..ab5590c --- /dev/null +++ b/shamir.iml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js new file mode 100644 index 0000000..f16ed2b --- /dev/null +++ b/src/main/js/GF256.js @@ -0,0 +1,11 @@ + +exports.add = function(a, b) { + console.log('From GF256 add function'); + return a ^ b; + }; + +/* The Laws of Cryptograhy with Java Code by Neal R. Wagner +Page 120 (134) section "20.3 Addition in GP(2^n)" is equal +to subtraction. +*/ +exports.sub = exports.add; \ No newline at end of file diff --git a/src/main/js/Scheme.js b/src/main/js/Scheme.js new file mode 100644 index 0000000..95b3805 --- /dev/null +++ b/src/main/js/Scheme.js @@ -0,0 +1,4 @@ + +exports.myDateTime = function () { + return Date.now(); +}; \ No newline at end of file diff --git a/src/test/js/ShamirTests.js b/src/test/js/ShamirTests.js new file mode 100644 index 0000000..8c11863 --- /dev/null +++ b/src/test/js/ShamirTests.js @@ -0,0 +1,28 @@ +var test = require('tape'); + +const GF256 = require('../../main/js/GF256.js'); + +test('GF256Tests add', function (t) { + t.plan(1); + + console.log(GF256); + + t.equal( GF256.add(100, 30), 122 ); +}); + +test('GF256Tests sub', function (t) { + t.plan(1); + + console.log(GF256); + + t.equal( GF256.sub(100, 30), 122 ); +}); + + + +// const JavaPI = Java.type('java.lang.Math').PI; + +// test('PI test', function (t) { +// t.plan(1); +// t.equal( JavaPI.toString(), "3.141592653589793" ); +// }); From 430224e5935cfac87089c262ad36b34da0993e99 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Fri, 14 Jun 2019 19:06:32 +0100 Subject: [PATCH 02/78] mul --- src/main/js/GF256.js | 131 +++++++++++++++++++++++++++++++++++-- src/test/js/ShamirTests.js | 16 +++-- 2 files changed, 139 insertions(+), 8 deletions(-) diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index f16ed2b..9fad4bf 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -1,11 +1,134 @@ exports.add = function(a, b) { - console.log('From GF256 add function'); - return a ^ b; - }; + return a ^ b; +}; /* The Laws of Cryptograhy with Java Code by Neal R. Wagner Page 120 (134) section "20.3 Addition in GP(2^n)" is equal to subtraction. */ -exports.sub = exports.add; \ No newline at end of file +exports.sub = exports.add; + + + const LOG = [ + parseInt("0xff"), parseInt("0x00"), parseInt("0x19"), parseInt("0x01"), parseInt("0x32"), parseInt("0x02"), parseInt("0x1a"), + parseInt("0xc6"), parseInt("0x4b"), parseInt("0xc7"), parseInt("0x1b"), parseInt("0x68"), parseInt("0x33"), parseInt("0xee"), + parseInt("0xdf"), parseInt("0x03"), parseInt("0x64"), parseInt("0x04"), parseInt("0xe0"), parseInt("0x0e"), parseInt("0x34"), + parseInt("0x8d"), parseInt("0x81"), parseInt("0xef"), parseInt("0x4c"), parseInt("0x71"), parseInt("0x08"), parseInt("0xc8"), + parseInt("0xf8"), parseInt("0x69"), parseInt("0x1c"), parseInt("0xc1"), parseInt("0x7d"), parseInt("0xc2"), parseInt("0x1d"), + parseInt("0xb5"), parseInt("0xf9"), parseInt("0xb9"), parseInt("0x27"), parseInt("0x6a"), parseInt("0x4d"), parseInt("0xe4"), + parseInt("0xa6"), parseInt("0x72"), parseInt("0x9a"), parseInt("0xc9"), parseInt("0x09"), parseInt("0x78"), parseInt("0x65"), + parseInt("0x2f"), parseInt("0x8a"), parseInt("0x05"), parseInt("0x21"), parseInt("0x0f"), parseInt("0xe1"), parseInt("0x24"), + parseInt("0x12"), parseInt("0xf0"), parseInt("0x82"), parseInt("0x45"), parseInt("0x35"), parseInt("0x93"), parseInt("0xda"), + parseInt("0x8e"), parseInt("0x96"), parseInt("0x8f"), parseInt("0xdb"), parseInt("0xbd"), parseInt("0x36"), parseInt("0xd0"), + parseInt("0xce"), parseInt("0x94"), parseInt("0x13"), parseInt("0x5c"), parseInt("0xd2"), parseInt("0xf1"), parseInt("0x40"), + parseInt("0x46"), parseInt("0x83"), parseInt("0x38"), parseInt("0x66"), parseInt("0xdd"), parseInt("0xfd"), parseInt("0x30"), + parseInt("0xbf"), parseInt("0x06"), parseInt("0x8b"), parseInt("0x62"), parseInt("0xb3"), parseInt("0x25"), parseInt("0xe2"), + parseInt("0x98"), parseInt("0x22"), parseInt("0x88"), parseInt("0x91"), parseInt("0x10"), parseInt("0x7e"), parseInt("0x6e"), + parseInt("0x48"), parseInt("0xc3"), parseInt("0xa3"), parseInt("0xb6"), parseInt("0x1e"), parseInt("0x42"), parseInt("0x3a"), + parseInt("0x6b"), parseInt("0x28"), parseInt("0x54"), parseInt("0xfa"), parseInt("0x85"), parseInt("0x3d"), parseInt("0xba"), + parseInt("0x2b"), parseInt("0x79"), parseInt("0x0a"), parseInt("0x15"), parseInt("0x9b"), parseInt("0x9f"), parseInt("0x5e"), + parseInt("0xca"), parseInt("0x4e"), parseInt("0xd4"), parseInt("0xac"), parseInt("0xe5"), parseInt("0xf3"), parseInt("0x73"), + parseInt("0xa7"), parseInt("0x57"), parseInt("0xaf"), parseInt("0x58"), parseInt("0xa8"), parseInt("0x50"), parseInt("0xf4"), + parseInt("0xea"), parseInt("0xd6"), parseInt("0x74"), parseInt("0x4f"), parseInt("0xae"), parseInt("0xe9"), parseInt("0xd5"), + parseInt("0xe7"), parseInt("0xe6"), parseInt("0xad"), parseInt("0xe8"), parseInt("0x2c"), parseInt("0xd7"), parseInt("0x75"), + parseInt("0x7a"), parseInt("0xeb"), parseInt("0x16"), parseInt("0x0b"), parseInt("0xf5"), parseInt("0x59"), parseInt("0xcb"), + parseInt("0x5f"), parseInt("0xb0"), parseInt("0x9c"), parseInt("0xa9"), parseInt("0x51"), parseInt("0xa0"), parseInt("0x7f"), + parseInt("0x0c"), parseInt("0xf6"), parseInt("0x6f"), parseInt("0x17"), parseInt("0xc4"), parseInt("0x49"), parseInt("0xec"), + parseInt("0xd8"), parseInt("0x43"), parseInt("0x1f"), parseInt("0x2d"), parseInt("0xa4"), parseInt("0x76"), parseInt("0x7b"), + parseInt("0xb7"), parseInt("0xcc"), parseInt("0xbb"), parseInt("0x3e"), parseInt("0x5a"), parseInt("0xfb"), parseInt("0x60"), + parseInt("0xb1"), parseInt("0x86"), parseInt("0x3b"), parseInt("0x52"), parseInt("0xa1"), parseInt("0x6c"), parseInt("0xaa"), + parseInt("0x55"), parseInt("0x29"), parseInt("0x9d"), parseInt("0x97"), parseInt("0xb2"), parseInt("0x87"), parseInt("0x90"), + parseInt("0x61"), parseInt("0xbe"), parseInt("0xdc"), parseInt("0xfc"), parseInt("0xbc"), parseInt("0x95"), parseInt("0xcf"), + parseInt("0xcd"), parseInt("0x37"), parseInt("0x3f"), parseInt("0x5b"), parseInt("0xd1"), parseInt("0x53"), parseInt("0x39"), + parseInt("0x84"), parseInt("0x3c"), parseInt("0x41"), parseInt("0xa2"), parseInt("0x6d"), parseInt("0x47"), parseInt("0x14"), + parseInt("0x2a"), parseInt("0x9e"), parseInt("0x5d"), parseInt("0x56"), parseInt("0xf2"), parseInt("0xd3"), parseInt("0xab"), + parseInt("0x44"), parseInt("0x11"), parseInt("0x92"), parseInt("0xd9"), parseInt("0x23"), parseInt("0x20"), parseInt("0x2e"), + parseInt("0x89"), parseInt("0xb4"), parseInt("0x7c"), parseInt("0xb8"), parseInt("0x26"), parseInt("0x77"), parseInt("0x99"), + parseInt("0xe3"), parseInt("0xa5"), parseInt("0x67"), parseInt("0x4a"), parseInt("0xed"), parseInt("0xde"), parseInt("0xc5"), + parseInt("0x31"), parseInt("0xfe"), parseInt("0x18"), parseInt("0x0d"), parseInt("0x63"), parseInt("0x8c"), parseInt("0x80"), + parseInt("0xc0"), parseInt("0xf7"), parseInt("0x70"), parseInt("0x07"), + ]; + const EXP = [ + parseInt("0x01"), parseInt("0x03"), parseInt("0x05"), parseInt("0x0f"), parseInt("0x11"), parseInt("0x33"), parseInt("0x55"), + parseInt("0xff"), parseInt("0x1a"), parseInt("0x2e"), parseInt("0x72"), parseInt("0x96"), parseInt("0xa1"), parseInt("0xf8"), + parseInt("0x13"), parseInt("0x35"), parseInt("0x5f"), parseInt("0xe1"), parseInt("0x38"), parseInt("0x48"), parseInt("0xd8"), + parseInt("0x73"), parseInt("0x95"), parseInt("0xa4"), parseInt("0xf7"), parseInt("0x02"), parseInt("0x06"), parseInt("0x0a"), + parseInt("0x1e"), parseInt("0x22"), parseInt("0x66"), parseInt("0xaa"), parseInt("0xe5"), parseInt("0x34"), parseInt("0x5c"), + parseInt("0xe4"), parseInt("0x37"), parseInt("0x59"), parseInt("0xeb"), parseInt("0x26"), parseInt("0x6a"), parseInt("0xbe"), + parseInt("0xd9"), parseInt("0x70"), parseInt("0x90"), parseInt("0xab"), parseInt("0xe6"), parseInt("0x31"), parseInt("0x53"), + parseInt("0xf5"), parseInt("0x04"), parseInt("0x0c"), parseInt("0x14"), parseInt("0x3c"), parseInt("0x44"), parseInt("0xcc"), + parseInt("0x4f"), parseInt("0xd1"), parseInt("0x68"), parseInt("0xb8"), parseInt("0xd3"), parseInt("0x6e"), parseInt("0xb2"), + parseInt("0xcd"), parseInt("0x4c"), parseInt("0xd4"), parseInt("0x67"), parseInt("0xa9"), parseInt("0xe0"), parseInt("0x3b"), + parseInt("0x4d"), parseInt("0xd7"), parseInt("0x62"), parseInt("0xa6"), parseInt("0xf1"), parseInt("0x08"), parseInt("0x18"), + parseInt("0x28"), parseInt("0x78"), parseInt("0x88"), parseInt("0x83"), parseInt("0x9e"), parseInt("0xb9"), parseInt("0xd0"), + parseInt("0x6b"), parseInt("0xbd"), parseInt("0xdc"), parseInt("0x7f"), parseInt("0x81"), parseInt("0x98"), parseInt("0xb3"), + parseInt("0xce"), parseInt("0x49"), parseInt("0xdb"), parseInt("0x76"), parseInt("0x9a"), parseInt("0xb5"), parseInt("0xc4"), + parseInt("0x57"), parseInt("0xf9"), parseInt("0x10"), parseInt("0x30"), parseInt("0x50"), parseInt("0xf0"), parseInt("0x0b"), + parseInt("0x1d"), parseInt("0x27"), parseInt("0x69"), parseInt("0xbb"), parseInt("0xd6"), parseInt("0x61"), parseInt("0xa3"), + parseInt("0xfe"), parseInt("0x19"), parseInt("0x2b"), parseInt("0x7d"), parseInt("0x87"), parseInt("0x92"), parseInt("0xad"), + parseInt("0xec"), parseInt("0x2f"), parseInt("0x71"), parseInt("0x93"), parseInt("0xae"), parseInt("0xe9"), parseInt("0x20"), + parseInt("0x60"), parseInt("0xa0"), parseInt("0xfb"), parseInt("0x16"), parseInt("0x3a"), parseInt("0x4e"), parseInt("0xd2"), + parseInt("0x6d"), parseInt("0xb7"), parseInt("0xc2"), parseInt("0x5d"), parseInt("0xe7"), parseInt("0x32"), parseInt("0x56"), + parseInt("0xfa"), parseInt("0x15"), parseInt("0x3f"), parseInt("0x41"), parseInt("0xc3"), parseInt("0x5e"), parseInt("0xe2"), + parseInt("0x3d"), parseInt("0x47"), parseInt("0xc9"), parseInt("0x40"), parseInt("0xc0"), parseInt("0x5b"), parseInt("0xed"), + parseInt("0x2c"), parseInt("0x74"), parseInt("0x9c"), parseInt("0xbf"), parseInt("0xda"), parseInt("0x75"), parseInt("0x9f"), + parseInt("0xba"), parseInt("0xd5"), parseInt("0x64"), parseInt("0xac"), parseInt("0xef"), parseInt("0x2a"), parseInt("0x7e"), + parseInt("0x82"), parseInt("0x9d"), parseInt("0xbc"), parseInt("0xdf"), parseInt("0x7a"), parseInt("0x8e"), parseInt("0x89"), + parseInt("0x80"), parseInt("0x9b"), parseInt("0xb6"), parseInt("0xc1"), parseInt("0x58"), parseInt("0xe8"), parseInt("0x23"), + parseInt("0x65"), parseInt("0xaf"), parseInt("0xea"), parseInt("0x25"), parseInt("0x6f"), parseInt("0xb1"), parseInt("0xc8"), + parseInt("0x43"), parseInt("0xc5"), parseInt("0x54"), parseInt("0xfc"), parseInt("0x1f"), parseInt("0x21"), parseInt("0x63"), + parseInt("0xa5"), parseInt("0xf4"), parseInt("0x07"), parseInt("0x09"), parseInt("0x1b"), parseInt("0x2d"), parseInt("0x77"), + parseInt("0x99"), parseInt("0xb0"), parseInt("0xcb"), parseInt("0x46"), parseInt("0xca"), parseInt("0x45"), parseInt("0xcf"), + parseInt("0x4a"), parseInt("0xde"), parseInt("0x79"), parseInt("0x8b"), parseInt("0x86"), parseInt("0x91"), parseInt("0xa8"), + parseInt("0xe3"), parseInt("0x3e"), parseInt("0x42"), parseInt("0xc6"), parseInt("0x51"), parseInt("0xf3"), parseInt("0x0e"), + parseInt("0x12"), parseInt("0x36"), parseInt("0x5a"), parseInt("0xee"), parseInt("0x29"), parseInt("0x7b"), parseInt("0x8d"), + parseInt("0x8c"), parseInt("0x8f"), parseInt("0x8a"), parseInt("0x85"), parseInt("0x94"), parseInt("0xa7"), parseInt("0xf2"), + parseInt("0x0d"), parseInt("0x17"), parseInt("0x39"), parseInt("0x4b"), parseInt("0xdd"), parseInt("0x7c"), parseInt("0x84"), + parseInt("0x97"), parseInt("0xa2"), parseInt("0xfd"), parseInt("0x1c"), parseInt("0x24"), parseInt("0x6c"), parseInt("0xb4"), + parseInt("0xc7"), parseInt("0x52"), parseInt("0xf6"), parseInt("0x01"), parseInt("0x03"), parseInt("0x05"), parseInt("0x0f"), + parseInt("0x11"), parseInt("0x33"), parseInt("0x55"), parseInt("0xff"), parseInt("0x1a"), parseInt("0x2e"), parseInt("0x72"), + parseInt("0x96"), parseInt("0xa1"), parseInt("0xf8"), parseInt("0x13"), parseInt("0x35"), parseInt("0x5f"), parseInt("0xe1"), + parseInt("0x38"), parseInt("0x48"), parseInt("0xd8"), parseInt("0x73"), parseInt("0x95"), parseInt("0xa4"), parseInt("0xf7"), + parseInt("0x02"), parseInt("0x06"), parseInt("0x0a"), parseInt("0x1e"), parseInt("0x22"), parseInt("0x66"), parseInt("0xaa"), + parseInt("0xe5"), parseInt("0x34"), parseInt("0x5c"), parseInt("0xe4"), parseInt("0x37"), parseInt("0x59"), parseInt("0xeb"), + parseInt("0x26"), parseInt("0x6a"), parseInt("0xbe"), parseInt("0xd9"), parseInt("0x70"), parseInt("0x90"), parseInt("0xab"), + parseInt("0xe6"), parseInt("0x31"), parseInt("0x53"), parseInt("0xf5"), parseInt("0x04"), parseInt("0x0c"), parseInt("0x14"), + parseInt("0x3c"), parseInt("0x44"), parseInt("0xcc"), parseInt("0x4f"), parseInt("0xd1"), parseInt("0x68"), parseInt("0xb8"), + parseInt("0xd3"), parseInt("0x6e"), parseInt("0xb2"), parseInt("0xcd"), parseInt("0x4c"), parseInt("0xd4"), parseInt("0x67"), + parseInt("0xa9"), parseInt("0xe0"), parseInt("0x3b"), parseInt("0x4d"), parseInt("0xd7"), parseInt("0x62"), parseInt("0xa6"), + parseInt("0xf1"), parseInt("0x08"), parseInt("0x18"), parseInt("0x28"), parseInt("0x78"), parseInt("0x88"), parseInt("0x83"), + parseInt("0x9e"), parseInt("0xb9"), parseInt("0xd0"), parseInt("0x6b"), parseInt("0xbd"), parseInt("0xdc"), parseInt("0x7f"), + parseInt("0x81"), parseInt("0x98"), parseInt("0xb3"), parseInt("0xce"), parseInt("0x49"), parseInt("0xdb"), parseInt("0x76"), + parseInt("0x9a"), parseInt("0xb5"), parseInt("0xc4"), parseInt("0x57"), parseInt("0xf9"), parseInt("0x10"), parseInt("0x30"), + parseInt("0x50"), parseInt("0xf0"), parseInt("0x0b"), parseInt("0x1d"), parseInt("0x27"), parseInt("0x69"), parseInt("0xbb"), + parseInt("0xd6"), parseInt("0x61"), parseInt("0xa3"), parseInt("0xfe"), parseInt("0x19"), parseInt("0x2b"), parseInt("0x7d"), + parseInt("0x87"), parseInt("0x92"), parseInt("0xad"), parseInt("0xec"), parseInt("0x2f"), parseInt("0x71"), parseInt("0x93"), + parseInt("0xae"), parseInt("0xe9"), parseInt("0x20"), parseInt("0x60"), parseInt("0xa0"), parseInt("0xfb"), parseInt("0x16"), + parseInt("0x3a"), parseInt("0x4e"), parseInt("0xd2"), parseInt("0x6d"), parseInt("0xb7"), parseInt("0xc2"), parseInt("0x5d"), + parseInt("0xe7"), parseInt("0x32"), parseInt("0x56"), parseInt("0xfa"), parseInt("0x15"), parseInt("0x3f"), parseInt("0x41"), + parseInt("0xc3"), parseInt("0x5e"), parseInt("0xe2"), parseInt("0x3d"), parseInt("0x47"), parseInt("0xc9"), parseInt("0x40"), + parseInt("0xc0"), parseInt("0x5b"), parseInt("0xed"), parseInt("0x2c"), parseInt("0x74"), parseInt("0x9c"), parseInt("0xbf"), + parseInt("0xda"), parseInt("0x75"), parseInt("0x9f"), parseInt("0xba"), parseInt("0xd5"), parseInt("0x64"), parseInt("0xac"), + parseInt("0xef"), parseInt("0x2a"), parseInt("0x7e"), parseInt("0x82"), parseInt("0x9d"), parseInt("0xbc"), parseInt("0xdf"), + parseInt("0x7a"), parseInt("0x8e"), parseInt("0x89"), parseInt("0x80"), parseInt("0x9b"), parseInt("0xb6"), parseInt("0xc1"), + parseInt("0x58"), parseInt("0xe8"), parseInt("0x23"), parseInt("0x65"), parseInt("0xaf"), parseInt("0xea"), parseInt("0x25"), + parseInt("0x6f"), parseInt("0xb1"), parseInt("0xc8"), parseInt("0x43"), parseInt("0xc5"), parseInt("0x54"), parseInt("0xfc"), + parseInt("0x1f"), parseInt("0x21"), parseInt("0x63"), parseInt("0xa5"), parseInt("0xf4"), parseInt("0x07"), parseInt("0x09"), + parseInt("0x1b"), parseInt("0x2d"), parseInt("0x77"), parseInt("0x99"), parseInt("0xb0"), parseInt("0xcb"), parseInt("0x46"), + parseInt("0xca"), parseInt("0x45"), parseInt("0xcf"), parseInt("0x4a"), parseInt("0xde"), parseInt("0x79"), parseInt("0x8b"), + parseInt("0x86"), parseInt("0x91"), parseInt("0xa8"), parseInt("0xe3"), parseInt("0x3e"), parseInt("0x42"), parseInt("0xc6"), + parseInt("0x51"), parseInt("0xf3"), parseInt("0x0e"), parseInt("0x12"), parseInt("0x36"), parseInt("0x5a"), parseInt("0xee"), + parseInt("0x29"), parseInt("0x7b"), parseInt("0x8d"), parseInt("0x8c"), parseInt("0x8f"), parseInt("0x8a"), parseInt("0x85"), + parseInt("0x94"), parseInt("0xa7"), parseInt("0xf2"), parseInt("0x0d"), parseInt("0x17"), parseInt("0x39"), parseInt("0x4b"), + parseInt("0xdd"), parseInt("0x7c"), parseInt("0x84"), parseInt("0x97"), parseInt("0xa2"), parseInt("0xfd"), parseInt("0x1c"), + parseInt("0x24"), parseInt("0x6c"), parseInt("0xb4"), parseInt("0xc7"), parseInt("0x52"), parseInt("0xf6"), + ]; + + +exports.mul = function(a, b) { + if (a == 0 || b == 0) { + return 0; + } + return EXP[LOG[a] + LOG[b]]; +}; diff --git a/src/test/js/ShamirTests.js b/src/test/js/ShamirTests.js index 8c11863..9188a8d 100644 --- a/src/test/js/ShamirTests.js +++ b/src/test/js/ShamirTests.js @@ -5,19 +5,27 @@ const GF256 = require('../../main/js/GF256.js'); test('GF256Tests add', function (t) { t.plan(1); - console.log(GF256); - t.equal( GF256.add(100, 30), 122 ); }); test('GF256Tests sub', function (t) { t.plan(1); - console.log(GF256); - t.equal( GF256.sub(100, 30), 122 ); }); +test('GF256Tests mult', function (t) { + t.plan(4); + + + t.equal( GF256.mul(90, 21), 254 ); + t.equal( GF256.mul(133, 5), 167 ); + + t.equal( GF256.mul(0, 21), 0 ); + t.equal( GF256.mul(parseInt("0xb6"), parseInt("0x53")), parseInt("0x36") ); + +}); + // const JavaPI = Java.type('java.lang.Math').PI; From acdc6c1b45ee3f760bd775b01fba2761cdb408c0 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Fri, 14 Jun 2019 19:11:44 +0100 Subject: [PATCH 03/78] div --- src/main/js/GF256.js | 7 +++++++ src/test/js/ShamirTests.js | 14 ++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index 9fad4bf..190ad9e 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -132,3 +132,10 @@ exports.mul = function(a, b) { } return EXP[LOG[a] + LOG[b]]; }; + +const mul = exports.mul; + +exports.div = function(a, b) { + // multiply by the inverse of b + return mul(a, EXP[255 - LOG[b]]); +}; diff --git a/src/test/js/ShamirTests.js b/src/test/js/ShamirTests.js index 9188a8d..7d66f98 100644 --- a/src/test/js/ShamirTests.js +++ b/src/test/js/ShamirTests.js @@ -4,26 +4,28 @@ const GF256 = require('../../main/js/GF256.js'); test('GF256Tests add', function (t) { t.plan(1); - t.equal( GF256.add(100, 30), 122 ); }); test('GF256Tests sub', function (t) { t.plan(1); - t.equal( GF256.sub(100, 30), 122 ); }); -test('GF256Tests mult', function (t) { +test('GF256Tests mul', function (t) { t.plan(4); - - t.equal( GF256.mul(90, 21), 254 ); t.equal( GF256.mul(133, 5), 167 ); - t.equal( GF256.mul(0, 21), 0 ); t.equal( GF256.mul(parseInt("0xb6"), parseInt("0x53")), parseInt("0x36") ); +}); +test('GF256Tests div', function (t) { + t.plan(4); + t.equal( GF256.div(90, 21), 189 ); + t.equal( GF256.div(6, 55), 151 ); + t.equal( GF256.div(22, 192), 138 ); + t.equal( GF256.div(0, 192), 0 ); }); From e8af9ded8c1f4b460be8b48b700390d3fff9e3fd Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Fri, 14 Jun 2019 19:47:42 +0100 Subject: [PATCH 04/78] degree --- src/main/js/GF256.js | 15 ++++++++++++--- src/test/js/ShamirTests.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index 190ad9e..d1e9531 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -49,6 +49,7 @@ exports.sub = exports.add; parseInt("0x31"), parseInt("0xfe"), parseInt("0x18"), parseInt("0x0d"), parseInt("0x63"), parseInt("0x8c"), parseInt("0x80"), parseInt("0xc0"), parseInt("0xf7"), parseInt("0x70"), parseInt("0x07"), ]; + const EXP = [ parseInt("0x01"), parseInt("0x03"), parseInt("0x05"), parseInt("0x0f"), parseInt("0x11"), parseInt("0x33"), parseInt("0x55"), parseInt("0xff"), parseInt("0x1a"), parseInt("0x2e"), parseInt("0x72"), parseInt("0x96"), parseInt("0xa1"), parseInt("0xf8"), @@ -125,17 +126,25 @@ exports.sub = exports.add; parseInt("0x24"), parseInt("0x6c"), parseInt("0xb4"), parseInt("0xc7"), parseInt("0x52"), parseInt("0xf6"), ]; - -exports.mul = function(a, b) { +const mul = function(a, b) { if (a == 0 || b == 0) { return 0; } return EXP[LOG[a] + LOG[b]]; }; -const mul = exports.mul; +exports.mul = mul; exports.div = function(a, b) { // multiply by the inverse of b return mul(a, EXP[255 - LOG[b]]); }; + +exports.degree = function(p) { + for (i = p.length - 1; i >= 1; i--) { + if (p[i] != 0) { + return i; + } + } + return 0; +}; \ No newline at end of file diff --git a/src/test/js/ShamirTests.js b/src/test/js/ShamirTests.js index 7d66f98..730c4b1 100644 --- a/src/test/js/ShamirTests.js +++ b/src/test/js/ShamirTests.js @@ -28,6 +28,35 @@ test('GF256Tests div', function (t) { t.equal( GF256.div(0, 192), 0 ); }); +test('GF256Tests degree', function (t) { + t.plan(4); + t.equal( GF256.degree([1, 2]), 1 ); + t.equal( GF256.degree([1, 2, 0]), 1 ); + t.equal( GF256.degree([1, 2, 3]), 2 ); + t.equal( GF256.degree([0, 0, 0]), 0 ); +}); + +const bytes = [ + 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 +]; + +function pairs(arr) { + var res = [], + l = arr.length; + for(var i=0; i Date: Fri, 14 Jun 2019 19:49:22 +0100 Subject: [PATCH 05/78] git ignore stuff --- .gitignore | 5 + package-lock.json | 282 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 287 insertions(+) create mode 100644 package-lock.json diff --git a/.gitignore b/.gitignore index 1cdc9f7..475bfaf 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,8 @@ release.properties dependency-reduced-pom.xml buildNumber.properties .mvn/timing.properties +node_modules/ +.classpath +.idea/ +.project +.settings diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..60c97e6 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,282 @@ +{ + "name": "shamir", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "deep-equal": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz", + "integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=", + "dev": true + }, + "define-properties": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", + "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", + "dev": true, + "requires": { + "object-keys": "^1.0.12" + } + }, + "defined": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/defined/-/defined-1.0.0.tgz", + "integrity": "sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM=", + "dev": true + }, + "es-abstract": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.13.0.tgz", + "integrity": "sha512-vDZfg/ykNxQVwup/8E1BZhVzFfBxs9NqMzGcvIJrqg5k2/5Za2bWo40dK2J1pgLngZ7c+Shh8lwYtLGyrwPutg==", + "dev": true, + "requires": { + "es-to-primitive": "^1.2.0", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "is-callable": "^1.1.4", + "is-regex": "^1.0.4", + "object-keys": "^1.0.12" + } + }, + "es-to-primitive": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.0.tgz", + "integrity": "sha512-qZryBOJjV//LaxLTV6UC//WewneB3LcXOL9NP++ozKVXsIIIpm/2c13UDiD9Jp2eThsecw9m3jPqDwTyobcdbg==", + "dev": true, + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, + "for-each": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", + "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", + "dev": true, + "requires": { + "is-callable": "^1.1.3" + } + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true + }, + "glob": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", + "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "requires": { + "function-bind": "^1.1.1" + } + }, + "has-symbols": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz", + "integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q=", + "dev": true + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "is-callable": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", + "integrity": "sha512-r5p9sxJjYnArLjObpjA4xu5EKI3CuKHkJXMhT7kwbpUyIFD1n5PMAsoPvWnvtZiNz7LjkYDRZhd7FlI0eMijEA==", + "dev": true + }, + "is-date-object": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz", + "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=", + "dev": true + }, + "is-regex": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz", + "integrity": "sha1-VRdIm1RwkbCTDglWVM7SXul+lJE=", + "dev": true, + "requires": { + "has": "^1.0.1" + } + }, + "is-symbol": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.2.tgz", + "integrity": "sha512-HS8bZ9ox60yCJLH9snBpIwv9pYUAkcuLhSA1oero1UB5y9aiQpRA8y2ex945AOtCZL1lJDeIk3G5LthswI46Lw==", + "dev": true, + "requires": { + "has-symbols": "^1.0.0" + } + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "dev": true + }, + "object-inspect": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.6.0.tgz", + "integrity": "sha512-GJzfBZ6DgDAmnuaM3104jR4s1Myxr3Y3zfIyN4z3UdqN69oSRacNK8UhnobDdC+7J2AHCjGwxQubNJfE70SXXQ==", + "dev": true + }, + "object-keys": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", + "dev": true + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true + }, + "resolve": { + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.1.tgz", + "integrity": "sha512-KuIe4mf++td/eFb6wkaPbMDnP6kObCaEtIDuHOUED6MNUo4K670KZUHuuvYPZDxNF0WVLw49n06M2m2dXphEzA==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + }, + "resumer": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/resumer/-/resumer-0.0.0.tgz", + "integrity": "sha1-8ej0YeQGS6Oegq883CqMiT0HZ1k=", + "dev": true, + "requires": { + "through": "~2.3.4" + } + }, + "string.prototype.trim": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.1.2.tgz", + "integrity": "sha1-0E3iyJ4Tf019IG8Ia17S+ua+jOo=", + "dev": true, + "requires": { + "define-properties": "^1.1.2", + "es-abstract": "^1.5.0", + "function-bind": "^1.0.2" + } + }, + "tape": { + "version": "4.10.2", + "resolved": "https://registry.npmjs.org/tape/-/tape-4.10.2.tgz", + "integrity": "sha512-mgl23h7W2yuk3N85FOYrin2OvThTYWdwbk6XQ1pr2PMJieyW2FM/4Bu/+kD/wecb3aZ0Enm+Syinyq467OPq2w==", + "dev": true, + "requires": { + "deep-equal": "~1.0.1", + "defined": "~1.0.0", + "for-each": "~0.3.3", + "function-bind": "~1.1.1", + "glob": "~7.1.4", + "has": "~1.0.3", + "inherits": "~2.0.3", + "minimist": "~1.2.0", + "object-inspect": "~1.6.0", + "resolve": "~1.10.1", + "resumer": "~0.0.0", + "string.prototype.trim": "~1.1.2", + "through": "~2.3.8" + } + }, + "through": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", + "dev": true + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + } + } +} From 2a825376a7b57d1ae1888eea6b2116504680b002 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Fri, 14 Jun 2019 20:05:34 +0100 Subject: [PATCH 06/78] eval --- src/main/js/GF256.js | 23 ++++++++++++++---- src/test/js/ShamirTests.js | 49 ++++++++++++++++++++++++++++++++------ 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index d1e9531..7414826 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -1,16 +1,20 @@ -exports.add = function(a, b) { +const add = function(a, b) { return a ^ b; }; +exports.add = add; + /* The Laws of Cryptograhy with Java Code by Neal R. Wagner Page 120 (134) section "20.3 Addition in GP(2^n)" is equal to subtraction. */ +const sub = add; + exports.sub = exports.add; - const LOG = [ +const LOG = [ parseInt("0xff"), parseInt("0x00"), parseInt("0x19"), parseInt("0x01"), parseInt("0x32"), parseInt("0x02"), parseInt("0x1a"), parseInt("0xc6"), parseInt("0x4b"), parseInt("0xc7"), parseInt("0x1b"), parseInt("0x68"), parseInt("0x33"), parseInt("0xee"), parseInt("0xdf"), parseInt("0x03"), parseInt("0x64"), parseInt("0x04"), parseInt("0xe0"), parseInt("0x0e"), parseInt("0x34"), @@ -135,11 +139,13 @@ const mul = function(a, b) { exports.mul = mul; -exports.div = function(a, b) { +const div = function(a, b) { // multiply by the inverse of b return mul(a, EXP[255 - LOG[b]]); }; +exports.div = div; + exports.degree = function(p) { for (i = p.length - 1; i >= 1; i--) { if (p[i] != 0) { @@ -147,4 +153,13 @@ exports.degree = function(p) { } } return 0; -}; \ No newline at end of file +}; + +exports.eval = function(p, x) { + // Horner's method + result = 0; + for (i = p.length - 1; i >= 0; i--) { + result = add(mul(result, x), p[i]); + } + return result; + } \ No newline at end of file diff --git a/src/test/js/ShamirTests.js b/src/test/js/ShamirTests.js index 730c4b1..8300b20 100644 --- a/src/test/js/ShamirTests.js +++ b/src/test/js/ShamirTests.js @@ -40,7 +40,7 @@ const bytes = [ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 ]; -function pairs(arr) { +function makePairs(arr) { var res = [], l = arr.length; for(var i=0; i Date: Sun, 16 Jun 2019 07:33:23 +0100 Subject: [PATCH 07/78] generator tests --- package-lock.json | 6 ++ package.json | 3 +- src/main/java/com/codahale/shamir/GF256.java | 13 ++++ src/main/js/GF256.js | 66 ++++++++++++++++++- src/main/js/Scheme.js | 15 +++++ .../java/com/codahale/shamir/GF256Test.java | 49 +++++++++++++- src/test/js/ShamirTests.js | 52 +++++++++++++-- 7 files changed, 195 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 60c97e6..eb5a97f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -272,6 +272,12 @@ "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, + "tweetnacl": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.1.tgz", + "integrity": "sha512-kcoMoKTPYnoeS50tzoqjPY3Uv9axeuuFAZY9M/9zFnhoVvRfxz9K29IMPD7jGmt2c8SW7i3gT9WqDl2+nV7p4A==", + "dev": true + }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/package.json b/package.json index 2421c66..82e9c3e 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ }, "homepage": "https://github.com/codahale/shamir#readme", "devDependencies": { - "tape": "^4.10.2" + "tape": "^4.10.2", + "tweetnacl": "^1.0.1" } } diff --git a/src/main/java/com/codahale/shamir/GF256.java b/src/main/java/com/codahale/shamir/GF256.java index 9b85ea9..1fcd88d 100644 --- a/src/main/java/com/codahale/shamir/GF256.java +++ b/src/main/java/com/codahale/shamir/GF256.java @@ -70,6 +70,13 @@ private GF256() { (byte) 0x31, (byte) 0xfe, (byte) 0x18, (byte) 0x0d, (byte) 0x63, (byte) 0x8c, (byte) 0x80, (byte) 0xc0, (byte) 0xf7, (byte) 0x70, (byte) 0x07, }; + + static byte[] LOG() { + byte[] logs = new byte[LOG.length]; + System.arraycopy(LOG, 0, logs, 0, logs.length); + return logs; + } + private static final byte[] EXP = { (byte) 0x01, (byte) 0x03, (byte) 0x05, (byte) 0x0f, (byte) 0x11, (byte) 0x33, (byte) 0x55, (byte) 0xff, (byte) 0x1a, (byte) 0x2e, (byte) 0x72, (byte) 0x96, (byte) 0xa1, (byte) 0xf8, @@ -146,6 +153,12 @@ private GF256() { (byte) 0x24, (byte) 0x6c, (byte) 0xb4, (byte) 0xc7, (byte) 0x52, (byte) 0xf6, }; + static byte[] EXP() { + byte[] exp = new byte[EXP.length]; + System.arraycopy(EXP, 0, exp, 0, exp.length); + return exp; + } + static byte add(byte a, byte b) { return (byte) (a ^ b); } diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index 7414826..5e8ec6a 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -1,3 +1,18 @@ +/* + * Copyright © 2017 Coda Hale (coda.hale@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ const add = function(a, b) { return a ^ b; @@ -6,6 +21,7 @@ const add = function(a, b) { exports.add = add; /* The Laws of Cryptograhy with Java Code by Neal R. Wagner +http://www.cs.utsa.edu/~wagner/lawsbookcolor/laws.pdf Page 120 (134) section "20.3 Addition in GP(2^n)" is equal to subtraction. */ @@ -54,7 +70,9 @@ const LOG = [ parseInt("0xc0"), parseInt("0xf7"), parseInt("0x70"), parseInt("0x07"), ]; - const EXP = [ +/* https://crypto.stackexchange.com/a/21174/13860 +*/ +const EXP = [ parseInt("0x01"), parseInt("0x03"), parseInt("0x05"), parseInt("0x0f"), parseInt("0x11"), parseInt("0x33"), parseInt("0x55"), parseInt("0xff"), parseInt("0x1a"), parseInt("0x2e"), parseInt("0x72"), parseInt("0x96"), parseInt("0xa1"), parseInt("0xf8"), parseInt("0x13"), parseInt("0x35"), parseInt("0x5f"), parseInt("0xe1"), parseInt("0x38"), parseInt("0x48"), parseInt("0xd8"), @@ -146,7 +164,7 @@ const div = function(a, b) { exports.div = div; -exports.degree = function(p) { +const degree = function(p) { for (i = p.length - 1; i >= 1; i--) { if (p[i] != 0) { return i; @@ -155,6 +173,8 @@ exports.degree = function(p) { return 0; }; +exports.degree = degree; + exports.eval = function(p, x) { // Horner's method result = 0; @@ -162,4 +182,44 @@ exports.eval = function(p, x) { result = add(mul(result, x), p[i]); } return result; - } \ No newline at end of file + } + +exports.interpolate = function(points) { + // calculate f(0) of the given points using Lagrangian interpolation + const x = 0; + var y = 0; + for (i = 0; i < points.length; i++) { + const aX = points[i][0]; + const aY = points[i][1]; + var li = 1; + for (j = 0; j < points.length; j++) { + const bX = points[j][0]; + if (i != j) { + li = mul(li, div(sub(x, bX), sub(aX, bX))); + } + } + y = add(y, mul(li, aY)); + } + return y; + } + +/** + * Generates a random polynomal of the correct degree and sets x. + * @param {function int -> array[byte]} randomBytes Takes a lenght and returns a Uint8Array of that length + * @param {Number} d The degree of the polynomial driven by the number shares and join threshold. + * @return {Number} x The point to hide. + */ +exports.generate = function(randomBytes, d, x){ + var p = null; + + // generate random polynomials until we find one of the given degree + do { + p = randomBytes(d + 1); + } while (degree(p) != d); + + // set y intercept + p[0] = x; + + return p; + } + diff --git a/src/main/js/Scheme.js b/src/main/js/Scheme.js index 95b3805..6cfb2e4 100644 --- a/src/main/js/Scheme.js +++ b/src/main/js/Scheme.js @@ -1,3 +1,18 @@ +/* + * Copyright © 2017 Coda Hale (coda.hale@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ exports.myDateTime = function () { return Date.now(); diff --git a/src/test/java/com/codahale/shamir/GF256Test.java b/src/test/java/com/codahale/shamir/GF256Test.java index 079488c..0ae571f 100644 --- a/src/test/java/com/codahale/shamir/GF256Test.java +++ b/src/test/java/com/codahale/shamir/GF256Test.java @@ -21,9 +21,53 @@ import java.security.SecureRandom; import org.junit.jupiter.api.Test; import org.quicktheories.WithQuickTheories; +import static java.lang.Byte.toUnsignedInt; class GF256Test implements WithQuickTheories { + @Test + void exp() { + // https://crypto.stackexchange.com/a/21174/13860 + final byte[] EXP = GF256.EXP(); + final byte g = 0x03; + int t = 0x01; + for (int i = 0; i < EXP.length; i++) { + int expected = t; + int actual = toUnsignedInt(EXP[i]); + assertThat(actual).isEqualTo(expected); + t = toUnsignedInt(GF256.mul(g, (byte) (t & 0xFF))); + } + } + + @Test + void log() { + // https://crypto.stackexchange.com/a/21174/13860 + final byte[] LOG = GF256.LOG(); + final byte[] EXP = GF256.EXP(); + final byte[] log = new byte[255]; + + for (int i = 0; i < log.length - 1; i++) { + int index = toUnsignedInt(EXP[i]) % 255; + log[index] = (byte) (i & 0xFF); + //log[index] = (byte) ((i & 0xFF) % 255); +// if( index < 255 ) { +// log[index] = (byte) (i & 0xFF); +// } else { +// System.out.println(String.format("i=%d index=%d", i, index)); +// } + } + + for (int i = 1; i < LOG.length; i++) { + int expected = toUnsignedInt(log[i]); + int actual = toUnsignedInt(LOG[i]); + if( expected != actual) + System.out.println(String.format("i=%d expected=%d actual=%d", i, expected, actual)); + assertThat(actual).isEqualTo(expected); + } + } + + + @Test void add() { assertThat(GF256.add((byte) 100, (byte) 30)).isEqualTo((byte) 122); @@ -88,9 +132,12 @@ void eval() { assertThat(GF256.eval(new byte[] {1, 0, 2, 3}, (byte) 2)).isEqualTo((byte) 17); } + static class NotRandom extends SecureRandom {} + @Test void generate() { - final SecureRandom random = new SecureRandom(); + + final NotRandom random = new NotRandom(); final byte[] p = GF256.generate(random, 5, (byte) 20); assertThat(p[0]).isEqualTo((byte) 20); assertThat(p.length).isEqualTo(6); diff --git a/src/test/js/ShamirTests.js b/src/test/js/ShamirTests.js index 8300b20..a5d96b9 100644 --- a/src/test/js/ShamirTests.js +++ b/src/test/js/ShamirTests.js @@ -1,4 +1,22 @@ -var test = require('tape'); +/* + * Copyright © 2017 Coda Hale (coda.hale@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const test = require('tape'); + +// Returns a Uint8Array of the given length containing random bytes of cryptographic quality. +const randomBytes = require('tweetnacl').randomBytes; const GF256 = require('../../main/js/GF256.js'); @@ -51,16 +69,16 @@ function makePairs(arr) { const pairs = makePairs(bytes); -test('GF256Tests mul is commutitive', function (t) { +test('GF256Tests mul is commutative', function (t) { pairs.forEach(function(pair){ if( GF256.mul(pair[0], pair[1]) != GF256.mul(pair[1], pair[0]) ){ - throw "mul not commutitive for pair "+pair; + throw "mul not commutative for pair "+pair; } }); t.end(); }); -test('GF256Tests add is commutitive', function (t) { +test('GF256Tests add is commutative', function (t) { pairs.forEach(function(pair){ if( GF256.add(pair[0], pair[1]) != GF256.add(pair[1], pair[0]) ){ throw "add not commutitive for pair "+pair; @@ -100,3 +118,29 @@ test('GF256Tests eval', function (t) { t.equal( GF256.eval([1, 0, 2, 3], 2), 17 ); t.end(); }); + +test('GF256Tests interpolate', function (t) { + t.equal( GF256.interpolate([[1, 1], [2, 2], [3, 3]]), 0 ); + t.equal( GF256.interpolate([[1, 80], [2, 90], [3, 20]]), 30 ); + t.equal( GF256.interpolate([[1, 43], [2, 22], [3, 86]]), 107 ); + t.end(); +}); + +var countDownFrom2 =2; + +const zeroLastByteFirstTWoAttemptsRandomBytes = function (length) { + const p = randomBytes(length); + if( countDownFrom2 >= 0 ){ + p[p.length-1] = 0; + countDownFrom2--; + } + return p; +} + +test('GF256Tests generate', function (t) { + const p = GF256.generate(zeroLastByteFirstTWoAttemptsRandomBytes, 5, 20); + t.equal( p[0], 20 ); + t.equal( p.length, 6 ); + t.notOk( p[p.length-1] == 0 ); + t.end(); +}); \ No newline at end of file From d400bd952550f52e756eaaef977d38a603a84063 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 16 Jun 2019 09:16:25 +0100 Subject: [PATCH 08/78] All of GF256 passing as JavaScript logic --- src/main/js/GF256.js | 16 ++++++++++++++-- src/test/js/{ShamirTests.js => GF256Tests.js} | 13 +++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) rename src/test/js/{ShamirTests.js => GF256Tests.js} (96%) diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index 5e8ec6a..d5e4a41 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -205,9 +205,9 @@ exports.interpolate = function(points) { /** * Generates a random polynomal of the correct degree and sets x. - * @param {function int -> array[byte]} randomBytes Takes a lenght and returns a Uint8Array of that length + * @param {function int -> array[Uint8Array]} randomBytes Takes a lenght and returns a Uint8Array of that length * @param {Number} d The degree of the polynomial driven by the number shares and join threshold. - * @return {Number} x The point to hide. + * @return {Number} x The point to hide. */ exports.generate = function(randomBytes, d, x){ var p = null; @@ -223,3 +223,15 @@ exports.generate = function(randomBytes, d, x){ return p; } +/** + * Evaluates a polynomal at point x using Horner's method. + * @param {array[Uint8Array]} p The polynomial + * @return {Number} x The point to evaluate. + */ +exports.eval = function(p, x){ + var result = 0 + for( var i = p.length -1; i >=0; i--){ + result = add(mul(result, x), p[i]); + } + return result; + } \ No newline at end of file diff --git a/src/test/js/ShamirTests.js b/src/test/js/GF256Tests.js similarity index 96% rename from src/test/js/ShamirTests.js rename to src/test/js/GF256Tests.js index a5d96b9..7acd974 100644 --- a/src/test/js/ShamirTests.js +++ b/src/test/js/GF256Tests.js @@ -1,5 +1,5 @@ /* - * Copyright © 2017 Coda Hale (coda.hale@gmail.com) + * Copyright © 2019 Simon Massey (massey1905@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,11 +15,10 @@ */ const test = require('tape'); -// Returns a Uint8Array of the given length containing random bytes of cryptographic quality. -const randomBytes = require('tweetnacl').randomBytes; - const GF256 = require('../../main/js/GF256.js'); +const randomBytes = require('tweetnacl').randomBytes; + test('GF256Tests add', function (t) { t.plan(1); t.equal( GF256.add(100, 30), 122 ); @@ -143,4 +142,10 @@ test('GF256Tests generate', function (t) { t.equal( p.length, 6 ); t.notOk( p[p.length-1] == 0 ); t.end(); +}); + +test('GF256Tests eval', function (t) { + t.plan(1); + const v = GF256.eval([1, 0, 2, 3], 2); + t.equal( v, 17 ); }); \ No newline at end of file From b4b56f30e8b9b357c072afa221cc322bc3254cd2 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 16 Jun 2019 18:39:44 +0100 Subject: [PATCH 09/78] 'i' goes backwards --- src/main/js/GF256.js | 3 +- src/main/js/Scheme.js | 66 ++++++++++++++++++++++++++++++++++++-- src/test/js/SchemeTests.js | 35 ++++++++++++++++++++ 3 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 src/test/js/SchemeTests.js diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index d5e4a41..b353279 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -205,13 +205,12 @@ exports.interpolate = function(points) { /** * Generates a random polynomal of the correct degree and sets x. - * @param {function int -> array[Uint8Array]} randomBytes Takes a lenght and returns a Uint8Array of that length + * @param {function int -> array[Uint8Array]} randomBytes Takes a length and returns a Uint8Array of that length * @param {Number} d The degree of the polynomial driven by the number shares and join threshold. * @return {Number} x The point to hide. */ exports.generate = function(randomBytes, d, x){ var p = null; - // generate random polynomials until we find one of the given degree do { p = randomBytes(d + 1); diff --git a/src/main/js/Scheme.js b/src/main/js/Scheme.js index 6cfb2e4..39b7b8f 100644 --- a/src/main/js/Scheme.js +++ b/src/main/js/Scheme.js @@ -14,6 +14,68 @@ * limitations under the License. */ -exports.myDateTime = function () { - return Date.now(); +const GF256 = require('./GF256.js'); + +/** + * Splits the given secret into {@code n} parts, of which any {@code k} or more can be combined to + * recover the original secret. + * @param {function int -> array[Uint8Array]} randomBytes Takes a length and returns a Uint8Array of that length + * @param {Number} n the number of parts to produce (must be {@code >1}) + * @param {Number} k the threshold of joinable parts (must be {@code <= n}) + * @param {array[Uint8Array]} secret The secret to split as an array of bytes + * @return {object} an associative array of {@code n} part IDs and their values as array[Uint8Array] + */ +exports.split = function (randomBytes, n, k, secret) { + if (k < 1) throw "K must be > 1"; + if (n <= k) throw "N must be >= K"; + if (n >= 255) throw "N must be <= 255"; + //if( !secret.isArray()) throw "secret must be an array"; + + // // generate part values + // final byte[][] values = new byte[n][secret.length]; + // for (int i = 0; i < secret.length; i++) { + // // for each byte, generate a random polynomial, p + // final byte[] p = GF256.generate(random, k - 1, secret[i]); + // for (int x = 1; x <= n; x++) { + // // each part's byte is p(partId) + // values[x - 1][i] = GF256.eval(p, (byte) x); + // } + // } + + console.log("n:"+n+", k:"+k+" secret.length:"+secret.length); + + const values = []; + for ( i = 0; i < secret.length; i++ ){ + console.log("before i:"+ i + " "+ secret.length); + const p = GF256.generate(randomBytes, k - 1, secret[0]); + console.log("after i:"+ i + " "+ secret.length); + // const parts = []; + // for ( x = 1; x <= n; x++ ) { + // parts.push(GF256.eval(p, x)) + // } + // values.push(parts); + } + + // // return as a set of objects + // final Map parts = new HashMap<>(n()); + // for (int i = 0; i < values.length; i++) { + // parts.put(i + 1, values[i]); + // } + + return {}; +}; + +/** + * Joins the given parts to recover the original secret. + * + *

N.B.: There is no way to determine whether or not the returned value is actually the + * original secret. If the parts are incorrect, or are under the threshold value used to split the + * secret, a random value will be returned. + * + * @param {object} an associative array of {@code n} part IDs and their values as array[Uint8Array] + * @return {array[Uint8Array]} the original secret + * + */ +exports.join = function(){ + return new Uint8Array(); }; \ No newline at end of file diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js new file mode 100644 index 0000000..c8f80e1 --- /dev/null +++ b/src/test/js/SchemeTests.js @@ -0,0 +1,35 @@ +/* + * Copyright © 2019 Simon Massey (massey1905@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const test = require('tape'); + +const split = require('../../main/js/Scheme.js').split; +const join = require('../../main/js/Scheme.js').join; + +const randomBytes = require('tweetnacl').randomBytes; + +test('SchemeTests roundtrip', function (t) { + t.plan(1); + const secret = []; + secret[0] = 1; + secret[1] = 2; + secret[2] = 3; + const splits = split(randomBytes, 3,2, secret); + const joined = join(splits); + t.equal( joined[0], secret[0] ); + t.equal( joined[1], secret[1] ); + t.equal( joined[2], secret[2] ); +}); + From 373bdf175783b331c8a1305d9d6a46657e84cec8 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 16 Jun 2019 18:59:59 +0100 Subject: [PATCH 10/78] formatting --- possibleBug.sh | 1 + src/main/js/Scheme.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100755 possibleBug.sh diff --git a/possibleBug.sh b/possibleBug.sh new file mode 100755 index 0000000..acb8de2 --- /dev/null +++ b/possibleBug.sh @@ -0,0 +1 @@ +node src/test/js/SchemeTests.js diff --git a/src/main/js/Scheme.js b/src/main/js/Scheme.js index 39b7b8f..223fef4 100644 --- a/src/main/js/Scheme.js +++ b/src/main/js/Scheme.js @@ -48,7 +48,7 @@ exports.split = function (randomBytes, n, k, secret) { for ( i = 0; i < secret.length; i++ ){ console.log("before i:"+ i + " "+ secret.length); const p = GF256.generate(randomBytes, k - 1, secret[0]); - console.log("after i:"+ i + " "+ secret.length); + console.log("after i:"+ i + " "+ secret.length); // const parts = []; // for ( x = 1; x <= n; x++ ) { // parts.push(GF256.eval(p, x)) From e00b41a902127f1c424dbc24522921333fb3e9bd Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 16 Jun 2019 21:53:39 +0100 Subject: [PATCH 11/78] do not use global `i` --- src/main/js/GF256.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index b353279..b65e47d 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -188,7 +188,7 @@ exports.interpolate = function(points) { // calculate f(0) of the given points using Lagrangian interpolation const x = 0; var y = 0; - for (i = 0; i < points.length; i++) { + for (var i = 0; i < points.length; i++) { const aX = points[i][0]; const aY = points[i][1]; var li = 1; From a5bf166782f0756ba4b526a90fef7e2be22bd308 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Tue, 18 Jun 2019 21:03:43 +0100 Subject: [PATCH 12/78] split and join working --- src/main/js/GF256.js | 8 ++- src/main/js/Scheme.js | 71 ++++++++++--------- .../java/com/codahale/shamir/GF256Test.java | 52 +++++++------- .../com/codahale/shamir/tests/SchemeTest.java | 32 ++++----- src/test/js/SchemeTests.js | 12 ++-- 5 files changed, 92 insertions(+), 83 deletions(-) diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index b65e47d..3c64e4a 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -14,6 +14,8 @@ * limitations under the License. */ +"use strict"; + const add = function(a, b) { return a ^ b; }; @@ -165,7 +167,7 @@ const div = function(a, b) { exports.div = div; const degree = function(p) { - for (i = p.length - 1; i >= 1; i--) { + for (var i = p.length - 1; i >= 1; i--) { if (p[i] != 0) { return i; } @@ -178,7 +180,7 @@ exports.degree = degree; exports.eval = function(p, x) { // Horner's method result = 0; - for (i = p.length - 1; i >= 0; i--) { + for (var i = p.length - 1; i >= 0; i--) { result = add(mul(result, x), p[i]); } return result; @@ -192,7 +194,7 @@ exports.interpolate = function(points) { const aX = points[i][0]; const aY = points[i][1]; var li = 1; - for (j = 0; j < points.length; j++) { + for (var j = 0; j < points.length; j++) { const bX = points[j][0]; if (i != j) { li = mul(li, div(sub(x, bX), sub(aX, bX))); diff --git a/src/main/js/Scheme.js b/src/main/js/Scheme.js index 223fef4..af5c151 100644 --- a/src/main/js/Scheme.js +++ b/src/main/js/Scheme.js @@ -14,6 +14,8 @@ * limitations under the License. */ +"use strict"; + const GF256 = require('./GF256.js'); /** @@ -23,46 +25,29 @@ const GF256 = require('./GF256.js'); * @param {Number} n the number of parts to produce (must be {@code >1}) * @param {Number} k the threshold of joinable parts (must be {@code <= n}) * @param {array[Uint8Array]} secret The secret to split as an array of bytes - * @return {object} an associative array of {@code n} part IDs and their values as array[Uint8Array] + * @return {map[Number,Uint8Array[byte]]} an map of {@code n} parts that are arrays of bytes of the secret length */ exports.split = function (randomBytes, n, k, secret) { if (k < 1) throw "K must be > 1"; if (n <= k) throw "N must be >= K"; if (n >= 255) throw "N must be <= 255"; - //if( !secret.isArray()) throw "secret must be an array"; - - // // generate part values - // final byte[][] values = new byte[n][secret.length]; - // for (int i = 0; i < secret.length; i++) { - // // for each byte, generate a random polynomial, p - // final byte[] p = GF256.generate(random, k - 1, secret[i]); - // for (int x = 1; x <= n; x++) { - // // each part's byte is p(partId) - // values[x - 1][i] = GF256.eval(p, (byte) x); - // } - // } - console.log("n:"+n+", k:"+k+" secret.length:"+secret.length); - - const values = []; - for ( i = 0; i < secret.length; i++ ){ - console.log("before i:"+ i + " "+ secret.length); - const p = GF256.generate(randomBytes, k - 1, secret[0]); - console.log("after i:"+ i + " "+ secret.length); - // const parts = []; - // for ( x = 1; x <= n; x++ ) { - // parts.push(GF256.eval(p, x)) - // } - // values.push(parts); + const values = new Array(n).fill(0).map(() => new Uint8Array(secret.length).fill(0)); + for ( var i = 0; i < secret.length; i++ ){ + const p = GF256.generate(randomBytes, k - 1, secret[i]); + for ( var x = 1; x <= n; x++ ) { + values[x-1][i] = GF256.eval(p, x); + } } - // // return as a set of objects - // final Map parts = new HashMap<>(n()); - // for (int i = 0; i < values.length; i++) { - // parts.put(i + 1, values[i]); - // } + const parts = {}; - return {}; + for (var i = 0; i < values.length; i++) { + var part = ""+(i+1); + parts[part] = values[i]; + } + + return parts; }; /** @@ -72,10 +57,28 @@ exports.split = function (randomBytes, n, k, secret) { * original secret. If the parts are incorrect, or are under the threshold value used to split the * secret, a random value will be returned. * - * @param {object} an associative array of {@code n} part IDs and their values as array[Uint8Array] + * @param {array[array[byte]]} parts an array of {@code n} parts * @return {array[Uint8Array]} the original secret * */ -exports.join = function(){ - return new Uint8Array(); +exports.join = function(parts){ + if( parts.length == 0 ) throw "No parts provided" + const lengths = Object.values(parts).map(x => x.length); + const max = Math.max.apply(null, lengths) + const min = Math.min.apply(null, lengths) + if( max != min ) throw `Varying lengths of part values. Min ${min}, Max ${max}` + const secret = new Uint8Array(max); + for( var i = 0; i < secret.length; i++){ + const keys = Object.keys(parts); + const points = new Array(keys.length).fill(0).map(() => new Uint8Array(2).fill(0)); + for( var j = 0; j < keys.length; j++) { + const key = keys[j]; + const k = Number(key); + points[j][0] = k; + points[j][1] = parts[key][i]; + } + secret[i] = GF256.interpolate(points); + } + + return secret; }; \ No newline at end of file diff --git a/src/test/java/com/codahale/shamir/GF256Test.java b/src/test/java/com/codahale/shamir/GF256Test.java index 0ae571f..2d2e46c 100644 --- a/src/test/java/com/codahale/shamir/GF256Test.java +++ b/src/test/java/com/codahale/shamir/GF256Test.java @@ -39,32 +39,32 @@ void exp() { } } - @Test - void log() { - // https://crypto.stackexchange.com/a/21174/13860 - final byte[] LOG = GF256.LOG(); - final byte[] EXP = GF256.EXP(); - final byte[] log = new byte[255]; - - for (int i = 0; i < log.length - 1; i++) { - int index = toUnsignedInt(EXP[i]) % 255; - log[index] = (byte) (i & 0xFF); - //log[index] = (byte) ((i & 0xFF) % 255); -// if( index < 255 ) { -// log[index] = (byte) (i & 0xFF); -// } else { -// System.out.println(String.format("i=%d index=%d", i, index)); -// } - } - - for (int i = 1; i < LOG.length; i++) { - int expected = toUnsignedInt(log[i]); - int actual = toUnsignedInt(LOG[i]); - if( expected != actual) - System.out.println(String.format("i=%d expected=%d actual=%d", i, expected, actual)); - assertThat(actual).isEqualTo(expected); - } - } +// @Test +// void log() { +// // https://crypto.stackexchange.com/a/21174/13860 +// final byte[] LOG = GF256.LOG(); +// final byte[] EXP = GF256.EXP(); +// final byte[] log = new byte[255]; +// +// for (int i = 0; i < log.length - 1; i++) { +// int index = toUnsignedInt(EXP[i]) % 255; +// log[index] = (byte) (i & 0xFF); +// //log[index] = (byte) ((i & 0xFF) % 255); +//// if( index < 255 ) { +//// log[index] = (byte) (i & 0xFF); +//// } else { +//// System.out.println(String.format("i=%d index=%d", i, index)); +//// } +// } +// +// for (int i = 1; i < LOG.length; i++) { +// int expected = toUnsignedInt(log[i]); +// int actual = toUnsignedInt(LOG[i]); +// if( expected != actual) +// System.out.println(String.format("i=%d expected=%d actual=%d", i, expected, actual)); +// assertThat(actual).isEqualTo(expected); +// } +// } diff --git a/src/test/java/com/codahale/shamir/tests/SchemeTest.java b/src/test/java/com/codahale/shamir/tests/SchemeTest.java index fbf47cd..4f8b2c0 100644 --- a/src/test/java/com/codahale/shamir/tests/SchemeTest.java +++ b/src/test/java/com/codahale/shamir/tests/SchemeTest.java @@ -60,25 +60,25 @@ void thresholdTooHigh() { .isInstanceOf(IllegalArgumentException.class); } - @Test - void joinEmptyParts() { - assertThatThrownBy(() -> new Scheme(new SecureRandom(), 3, 2).join(Collections.emptyMap())) - .isInstanceOf(IllegalArgumentException.class); - } - - @Test - void joinIrregularParts() { - final byte[] one = new byte[] {1}; - final byte[] two = new byte[] {1, 2}; - - assertThatThrownBy( - () -> new Scheme(new SecureRandom(), 3, 2).join(ImmutableMap.of(1, one, 2, two))) - .isInstanceOf(IllegalArgumentException.class); - } +// @Test +// void joinEmptyParts() { +// assertThatThrownBy(() -> new Scheme(new SecureRandom(), 3, 2).join(Collections.emptyMap())) +// .isInstanceOf(IllegalArgumentException.class); +// } + +// @Test +// void joinIrregularParts() { +// final byte[] one = new byte[] {1}; +// final byte[] two = new byte[] {1, 2}; +// +// assertThatThrownBy( +// () -> new Scheme(new SecureRandom(), 3, 2).join(ImmutableMap.of(1, one, 2, two))) +// .isInstanceOf(IllegalArgumentException.class); +// } @Test void splitAndJoinSingleByteSecret() { - final Scheme scheme = new Scheme(new SecureRandom(), 8, 3); + final Scheme scheme = new Scheme(new SecureRandom(), 3, 2); final byte[] secret = "x".getBytes(StandardCharsets.UTF_8); assertThat(scheme.join(scheme.split(secret))).containsExactly(secret); diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index c8f80e1..cf61913 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -21,15 +21,19 @@ const join = require('../../main/js/Scheme.js').join; const randomBytes = require('tweetnacl').randomBytes; test('SchemeTests roundtrip', function (t) { - t.plan(1); + const parts = 3; + const quorum = 2; const secret = []; secret[0] = 1; secret[1] = 2; - secret[2] = 3; - const splits = split(randomBytes, 3,2, secret); + // secret[2] = 3; + const splits = split(randomBytes, parts, quorum, secret); + t.equal(Object.keys(splits).length, parts); + //console.log(splits); const joined = join(splits); t.equal( joined[0], secret[0] ); t.equal( joined[1], secret[1] ); - t.equal( joined[2], secret[2] ); + // t.equal( joined[2], secret[2] ); + t.end(); }); From 5a58b985218e7bc275fff0ab1d2eab9379916a3e Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Wed, 19 Jun 2019 07:41:14 +0100 Subject: [PATCH 13/78] round trips an anglo saxon Rune Poem --- src/test/js/SchemeTests.js | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index cf61913..1cb0dbd 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -20,20 +20,46 @@ const join = require('../../main/js/Scheme.js').join; const randomBytes = require('tweetnacl').randomBytes; +// https://codereview.stackexchange.com/a/3589/75693 +function bytesToSring(bytes) { + var chars = []; + for(var i = 0, n = bytes.length; i < n;) { + chars.push(((bytes[i++] & 0xff) << 8) | (bytes[i++] & 0xff)); + } + return String.fromCharCode.apply(null, chars); +} + +// https://codereview.stackexchange.com/a/3589/75693 +function stringToBytes(str) { + var bytes = []; + for(var i = 0, n = str.length; i < n; i++) { + var char = str.charCodeAt(i); + bytes.push(char >>> 8, char & 0xFF); + } + return bytes; +} + test('SchemeTests roundtrip', function (t) { const parts = 3; const quorum = 2; - const secret = []; - secret[0] = 1; - secret[1] = 2; - // secret[2] = 3; + + // http://kermitproject.org/utf8.html + // From the Anglo-Saxon Rune Poem (Rune version) + const secretUtf8 = `ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ +ᛋᚳᛖᚪᛚ᛫ᚦᛖᚪᚻ᛫ᛗᚪᚾᚾᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ᛫ᛗᛁᚳᛚᚢᚾ᛫ᚻᛦᛏ᛫ᛞᚫᛚᚪᚾ +ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ᛬`; + + var secret = stringToBytes(secretUtf8); + const splits = split(randomBytes, parts, quorum, secret); t.equal(Object.keys(splits).length, parts); - //console.log(splits); const joined = join(splits); t.equal( joined[0], secret[0] ); t.equal( joined[1], secret[1] ); - // t.equal( joined[2], secret[2] ); + const joinedUtf8 = bytesToSring(joined); + t.equal( secretUtf8, joinedUtf8 ); + // console.log("The secret is: "+secretUtf8); + // console.log("The decoded secret is: "+joinedUtf8); t.end(); }); From 4bee88c5775838a4be08f15b079ab44e2575ad82 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Wed, 19 Jun 2019 08:20:51 +0100 Subject: [PATCH 14/78] comments on byte length and test beyond string length --- src/test/js/SchemeTests.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index 1cb0dbd..7293194 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -49,13 +49,14 @@ test('SchemeTests roundtrip', function (t) { ᛋᚳᛖᚪᛚ᛫ᚦᛖᚪᚻ᛫ᛗᚪᚾᚾᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ᛫ᛗᛁᚳᛚᚢᚾ᛫ᚻᛦᛏ᛫ᛞᚫᛚᚪᚾ ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ᛬`; + // string length is only 117 characters but the byte length is 234. var secret = stringToBytes(secretUtf8); const splits = split(randomBytes, parts, quorum, secret); t.equal(Object.keys(splits).length, parts); const joined = join(splits); - t.equal( joined[0], secret[0] ); - t.equal( joined[1], secret[1] ); + t.equal( joined[200], secret[200] ); + t.equal( joined[201], secret[201] ); const joinedUtf8 = bytesToSring(joined); t.equal( secretUtf8, joinedUtf8 ); // console.log("The secret is: "+secretUtf8); From 2eabcb4fd2d6d6dfb9a2fb981a14eca2d4365ed3 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Wed, 19 Jun 2019 17:49:18 +0100 Subject: [PATCH 15/78] check only two parts --- src/test/js/SchemeTests.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index 7293194..a6009f8 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -64,3 +64,19 @@ test('SchemeTests roundtrip', function (t) { t.end(); }); +test('SchemeTests roundtrip two parts', function (t) { + const parts = 3; + const quorum = 2; + + const secretUtf8 = `ᚠᛇᚻ`; + const secret = stringToBytes(secretUtf8); + + for( var i = 1; i <=3; i++) { + const splits = split(randomBytes, parts, quorum, secret); + delete splits[""+i]; + const joinedUtf8 = bytesToSring(join(splits)); + t.equal( secretUtf8, joinedUtf8 ); + } + + t.end(); +}); From df7e0f5622a450cd153cb059eb88c9d4ec274a96 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Wed, 19 Jun 2019 18:01:06 +0100 Subject: [PATCH 16/78] fix N max value and k min value tests --- src/main/js/Scheme.js | 6 +++--- src/test/js/SchemeTests.js | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/js/Scheme.js b/src/main/js/Scheme.js index af5c151..6556aaa 100644 --- a/src/main/js/Scheme.js +++ b/src/main/js/Scheme.js @@ -28,9 +28,9 @@ const GF256 = require('./GF256.js'); * @return {map[Number,Uint8Array[byte]]} an map of {@code n} parts that are arrays of bytes of the secret length */ exports.split = function (randomBytes, n, k, secret) { - if (k < 1) throw "K must be > 1"; - if (n <= k) throw "N must be >= K"; - if (n >= 255) throw "N must be <= 255"; + if (k <= 1) throw "K must be > 1"; + if (n < k) throw "N must be >= K"; + if (n > 255) throw "N must be <= 255"; const values = new Array(n).fill(0).map(() => new Uint8Array(secret.length).fill(0)); for ( var i = 0; i < secret.length; i++ ){ diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index a6009f8..cd68e7b 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -80,3 +80,25 @@ test('SchemeTests roundtrip two parts', function (t) { t.end(); }); + +test('SchemeTests check input validation', function (t) { + const secretUtf8 = `ᚠᛇᚻ`; + const secret = stringToBytes(secretUtf8); + t.plan(2); + + try { + const splits = split(randomBytes, 256, 2, secret); + t.notOk(true); + } catch (e) { + t.ok(e.toString().includes('N must be <= 255'), e); + } + + try { + const splits = split(randomBytes, 3, 1, secret); + t.notOk(true); + } catch (e) { + t.ok(e.toString().includes('K must be > 1'), e); + } + + t.end(); +}); From 06db18a777850266629dca06043c7ecc759c5bb7 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Wed, 19 Jun 2019 18:02:39 +0100 Subject: [PATCH 17/78] input parameter tests --- src/test/js/SchemeTests.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index cd68e7b..0dda2b9 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -84,7 +84,8 @@ test('SchemeTests roundtrip two parts', function (t) { test('SchemeTests check input validation', function (t) { const secretUtf8 = `ᚠᛇᚻ`; const secret = stringToBytes(secretUtf8); - t.plan(2); + + t.plan(3); try { const splits = split(randomBytes, 256, 2, secret); @@ -100,5 +101,12 @@ test('SchemeTests check input validation', function (t) { t.ok(e.toString().includes('K must be > 1'), e); } + try { + const splits = split(randomBytes, 2, 3, secret); + t.notOk(true); + } catch (e) { + t.ok(e.toString().includes('N must be >= K'), e); + } + t.end(); }); From ea410dd385273f48fcd70217bd4001685c7a8181 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Wed, 19 Jun 2019 18:09:43 +0100 Subject: [PATCH 18/78] fixed empty parts logic --- src/main/js/Scheme.js | 2 +- src/test/js/SchemeTests.js | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/js/Scheme.js b/src/main/js/Scheme.js index 6556aaa..e6a14a2 100644 --- a/src/main/js/Scheme.js +++ b/src/main/js/Scheme.js @@ -62,7 +62,7 @@ exports.split = function (randomBytes, n, k, secret) { * */ exports.join = function(parts){ - if( parts.length == 0 ) throw "No parts provided" + if( Object.keys(parts).length == 0 ) throw "No parts provided" const lengths = Object.values(parts).map(x => x.length); const max = Math.max.apply(null, lengths) const min = Math.min.apply(null, lengths) diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index 0dda2b9..55887f1 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -81,7 +81,7 @@ test('SchemeTests roundtrip two parts', function (t) { t.end(); }); -test('SchemeTests check input validation', function (t) { +test('SchemeTests split input validation', function (t) { const secretUtf8 = `ᚠᛇᚻ`; const secret = stringToBytes(secretUtf8); @@ -108,5 +108,21 @@ test('SchemeTests check input validation', function (t) { t.ok(e.toString().includes('N must be >= K'), e); } + t.end(); +}); + +test('SchemeTests join input validation', function (t) { + +// const splits = split(randomBytes, 3, 2, stringToBytes(`ᚠᛇᚻ`)); + + try { + join({}); + t.notOk(true); + } catch (e) { + t.ok(e.toString().includes('No parts provided'), e); + } + + + t.end(); }); From 1a1705828d20cf1afcb04fa30a6c0775cf44d477 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Wed, 19 Jun 2019 18:10:30 +0100 Subject: [PATCH 19/78] fixed empty parts logic --- src/test/js/SchemeTests.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index 55887f1..9fdd7c2 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -113,7 +113,7 @@ test('SchemeTests split input validation', function (t) { test('SchemeTests join input validation', function (t) { -// const splits = split(randomBytes, 3, 2, stringToBytes(`ᚠᛇᚻ`)); +// try { join({}); @@ -122,7 +122,13 @@ test('SchemeTests join input validation', function (t) { t.ok(e.toString().includes('No parts provided'), e); } - + try { + const splits = split(randomBytes, 3, 2, stringToBytes(`ᚠᛇᚻ`)); + join(splits["2"].pop()); + t.notOk(true); + } catch (e) { + t.ok(e.toString().includes('No parts provided'), e); + } t.end(); }); From c788068332fc9542bf977f2583bad86252ced26d Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Wed, 19 Jun 2019 18:14:45 +0100 Subject: [PATCH 20/78] check for equal length parts --- src/test/js/SchemeTests.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index 9fdd7c2..1953de4 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -124,10 +124,11 @@ test('SchemeTests join input validation', function (t) { try { const splits = split(randomBytes, 3, 2, stringToBytes(`ᚠᛇᚻ`)); - join(splits["2"].pop()); + splits["2"] = Uint8Array.of(216, 30, 190, 102) + join(splits); t.notOk(true); } catch (e) { - t.ok(e.toString().includes('No parts provided'), e); + t.ok(e.toString().includes('Varying lengths of part values'), e); } t.end(); From b949b8ffe4e384661cdb8133cc7343af43a8eff0 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Thu, 20 Jun 2019 10:39:09 +0100 Subject: [PATCH 21/78] deleting unused file --- possibleBug.sh | 1 - 1 file changed, 1 deletion(-) delete mode 100755 possibleBug.sh diff --git a/possibleBug.sh b/possibleBug.sh deleted file mode 100755 index acb8de2..0000000 --- a/possibleBug.sh +++ /dev/null @@ -1 +0,0 @@ -node src/test/js/SchemeTests.js From 4e56cd3091f5dba4512eba93368cd6f351d96ef8 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Fri, 28 Jun 2019 21:18:00 +0100 Subject: [PATCH 22/78] Polygot tests between Java and JavaScript --- package-lock.json | 40 ++++ package.json | 4 +- possibleBug.sh | 1 - src/main/js/GF256.js | 14 +- .../shamir/polygot/JavaScriptUtils.java | 47 ++++ .../shamir/polygot/NotRandomSource.java | 34 +++ src/test/js/PolygotTests.js | 217 ++++++++++++++++++ src/test/js/SchemeTests.js | 2 - 8 files changed, 344 insertions(+), 15 deletions(-) delete mode 100755 possibleBug.sh create mode 100644 src/test/java/com/codahale/shamir/polygot/JavaScriptUtils.java create mode 100644 src/test/java/com/codahale/shamir/polygot/NotRandomSource.java create mode 100644 src/test/js/PolygotTests.js diff --git a/package-lock.json b/package-lock.json index eb5a97f..8efa1a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -47,6 +47,12 @@ "integrity": "sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM=", "dev": true }, + "dom-walk": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.1.tgz", + "integrity": "sha1-ZyIm3HTI95mtNTB9+TaroRrNYBg=", + "dev": true + }, "es-abstract": { "version": "1.13.0", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.13.0.tgz", @@ -107,6 +113,16 @@ "path-is-absolute": "^1.0.0" } }, + "global": { + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/global/-/global-4.3.2.tgz", + "integrity": "sha1-52mJJopsdMOJCLEwWxD8DjlOnQ8=", + "dev": true, + "requires": { + "min-document": "^2.19.0", + "process": "~0.5.1" + } + }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -168,6 +184,15 @@ "has-symbols": "^1.0.0" } }, + "min-document": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/min-document/-/min-document-2.19.0.tgz", + "integrity": "sha1-e9KC4/WELtKVu3SM3Z8f+iyCRoU=", + "dev": true, + "requires": { + "dom-walk": "^0.1.0" + } + }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", @@ -216,6 +241,12 @@ "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "dev": true }, + "process": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/process/-/process-0.5.2.tgz", + "integrity": "sha1-FjjYqONML0QKkduVq5rrZ3/Bhc8=", + "dev": true + }, "resolve": { "version": "1.10.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.1.tgz", @@ -266,6 +297,15 @@ "through": "~2.3.8" } }, + "tape-catch": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/tape-catch/-/tape-catch-1.0.6.tgz", + "integrity": "sha1-EpMdXqYKA6l9m9GdDX2M/D9s7PE=", + "dev": true, + "requires": { + "global": "~4.3.0" + } + }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", diff --git a/package.json b/package.json index 82e9c3e..7823355 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "A JavaScript implementation of Shamir's Secret Sharing algorithm over GF(256).", "main": "src/main/js/Scheme.js", "scripts": { - "test": "node --polyglot --jvm src/test/js/ShamirTests.js" + "test": "tape src/test/js/GF256Tests.js src/test/js/SchemeTests.js", + "testwithjava": "node --jvm --vm.cp=./target/classes:./target/test-classes src/test/js/PolygotTests.js" }, "repository": { "type": "git", @@ -26,6 +27,7 @@ "homepage": "https://github.com/codahale/shamir#readme", "devDependencies": { "tape": "^4.10.2", + "tape-catch": "^1.0.6", "tweetnacl": "^1.0.1" } } diff --git a/possibleBug.sh b/possibleBug.sh deleted file mode 100755 index acb8de2..0000000 --- a/possibleBug.sh +++ /dev/null @@ -1 +0,0 @@ -node src/test/js/SchemeTests.js diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index 3c64e4a..362fcdd 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -1,5 +1,5 @@ /* - * Copyright © 2017 Coda Hale (coda.hale@gmail.com) + * Copyright © 2019 Simon Massey (massey1905@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -177,15 +177,6 @@ const degree = function(p) { exports.degree = degree; -exports.eval = function(p, x) { - // Horner's method - result = 0; - for (var i = p.length - 1; i >= 0; i--) { - result = add(mul(result, x), p[i]); - } - return result; - } - exports.interpolate = function(points) { // calculate f(0) of the given points using Lagrangian interpolation const x = 0; @@ -224,6 +215,7 @@ exports.generate = function(randomBytes, d, x){ return p; } + /** * Evaluates a polynomal at point x using Horner's method. * @param {array[Uint8Array]} p The polynomial @@ -235,4 +227,4 @@ exports.eval = function(p, x){ result = add(mul(result, x), p[i]); } return result; - } \ No newline at end of file + } diff --git a/src/test/java/com/codahale/shamir/polygot/JavaScriptUtils.java b/src/test/java/com/codahale/shamir/polygot/JavaScriptUtils.java new file mode 100644 index 0000000..782965f --- /dev/null +++ b/src/test/java/com/codahale/shamir/polygot/JavaScriptUtils.java @@ -0,0 +1,47 @@ +/* + * Copyright © 2019 Simon Massey (massey1905@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.codahale.shamir.polygot; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +public class JavaScriptUtils { + // https://stackoverflow.com/a/12310078/329496 + public static String byteToBinaryString(final byte b) { + return String.format("%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0'); + } + + static Map signedToUnsignedByteMap() { + final Map result = new HashMap<>(); + for (byte b = Byte.MIN_VALUE; ; b++) { + final String bits = byteToBinaryString(b); + final Integer i = Integer.parseInt(bits, 2) & 0xff; + result.put((int)b, i); + if (b == Byte.MAX_VALUE) break; + } + return Collections.unmodifiableMap(result); + } + + public static Map signedToUnsignedByteMap = signedToUnsignedByteMap(); + + public static Map unsignedToSignedByteMap = + signedToUnsignedByteMap.entrySet().stream() + .collect(Collectors.toMap(Entry::getValue, Entry::getKey));; + +} diff --git a/src/test/java/com/codahale/shamir/polygot/NotRandomSource.java b/src/test/java/com/codahale/shamir/polygot/NotRandomSource.java new file mode 100644 index 0000000..e9e709b --- /dev/null +++ b/src/test/java/com/codahale/shamir/polygot/NotRandomSource.java @@ -0,0 +1,34 @@ +/* + * Copyright © 2019 Simon Massey (massey1905@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.codahale.shamir.polygot; + +import java.security.SecureRandom; + +public class NotRandomSource extends SecureRandom { + + @Override + public void nextBytes(byte[] bytes) { + for (int b = 0; b < bytes.length; b++) { + bytes[b] = (byte) (b + 1); + } + } + + public byte[] notRandomBytes(int len) { + byte[] bytes = new byte[len]; + this.nextBytes(bytes); + return bytes; + } +} diff --git a/src/test/js/PolygotTests.js b/src/test/js/PolygotTests.js new file mode 100644 index 0000000..c766fd9 --- /dev/null +++ b/src/test/js/PolygotTests.js @@ -0,0 +1,217 @@ +/* + * Copyright © 2019 Simon Massey (massey1905@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const test = require('tape-catch'); + +const randomBytes = require('tweetnacl').randomBytes; + +// https://codereview.stackexchange.com/a/3589/75693 +function bytesToSring(bytes) { + var chars = []; + for(var i = 0, n = bytes.length; i < n;) { + chars.push(((bytes[i++] & 0xff) << 8) | (bytes[i++] & 0xff)); + } + return String.fromCharCode.apply(null, chars); +} + +// https://codereview.stackexchange.com/a/3589/75693 +function stringToBytes(str) { + var bytes = []; + for(var i = 0, n = str.length; i < n; i++) { + var char = str.charCodeAt(i); + bytes.push(char >>> 8, char & 0xFF); + } + return bytes; +} + +const ByteArray = Java.type("byte[]"); +const Byte = Java.type("java.lang.Byte"); +const JavaScriptUtils = Java.type("com.codahale.shamir.polygot.JavaScriptUtils"); + +var hexChar = ["0", "1", "2", "3", "4", "5", "6", "7","8", "9", "A", "B", "C", "D", "E", "F"]; +function byteToHex(b) { + return hexChar[(b >> 4) & 0x0f] + hexChar[b & 0x0f]; +} + + +function jsByteArrayToJavaByteArray(jsarray){ + const jbarray = new ByteArray(jsarray.length); + for( var i = 0; i < jsarray.length; i++){ + jbarray[i] = JavaScriptUtils.unsignedToSignedByteMap.get(jsarray[i]); + }; + return jbarray; +} + + +function jBytesArrayToJavaScriptByteArray(barray){ + const jsarray = []; + for ( var i = 0; i < barray.length; i++ ){ + jsarray.push(JavaScriptUtils.signedToUnsignedByteMap.get(barray[i])); + } + return jsarray; +} + + +test('PolygotTests Java and JavaScript byte array roundtrip', function (t) { + t.plan(1); + const secretUtf8 = `ᚠᛇᚻ`; + const jsBytes = stringToBytes(secretUtf8); + const jbytes = jsByteArrayToJavaByteArray(jsBytes); + const jsRoundTripBytes = jBytesArrayToJavaScriptByteArray(jbytes); + t.equal( secretUtf8, bytesToSring(jsRoundTripBytes) ); +}); + +const Scheme = Java.type('com.codahale.shamir.Scheme'); +const SecureRandom = Java.type('java.security.SecureRandom'); +const secureRandom = new SecureRandom(); + +test('PolygotTests JavaScript strings with all Java logic', function (t) { + t.plan(1); + const scheme = new Scheme(secureRandom, 5, 3); + const secretUtf8 = `ᚠᛇᚻ`; + + const parts = scheme.split(jsByteArrayToJavaByteArray(stringToBytes(secretUtf8))); + const joined = scheme.join(parts); + + t.equal( secretUtf8, bytesToSring(jBytesArrayToJavaScriptByteArray(joined)) ); +}); + +const split = require('../../main/js/Scheme.js').split; + +function javaScriptToJavaParts(parts) { + const HashMap = Java.type('java.util.HashMap'); + const map = new HashMap(); + for( var key in parts) { + const bytes = parts[key]; + const jbarr = new jsByteArrayToJavaByteArray(bytes); + map.put(Number(key), jbarr); + } + return map; +} + + +function javaToJavaScriptParts(javaMap) { + const result = {} + const entrySetIterator = javaMap.entrySet().iterator(); + while (entrySetIterator.hasNext()) { + const pair = entrySetIterator.next(); + const key = pair.getKey(); + const value = pair.getValue(); + result[key] = jBytesArrayToJavaScriptByteArray(value); + } + return result; +} + + +const Collectors = Java.type('java.util.stream.Collectors'); + + +function equalParts( jParts, jsParts){ + // js keys are strings + const jsKeysNumbers = Object.keys(jsParts); + // j keys are java integers that we map to strings + const jKeysSet = jParts.keySet().stream().map( n => n.toString() ).collect(Collectors.toList()); + + // check that all js keys are in the j keys + for( const jsk of jsKeysNumbers ) { + if( !jKeysSet.contains(jsk) ) { + throw `jKeysSet ${jKeysSet} does not contain jsk ${jsk}` + } + } + + // check that all j keys are in the js keys + for( const jk of jKeysSet ) { + if( !jsKeysNumbers.includes(jk)) { + throw `jsKeysNumbers ${jsKeysNumbers} does not contain jk ${jk}` + } + } + + for( const k of Object.keys(jsParts) ) { + const jArray = jBytesArrayToJavaScriptByteArray(jParts.get(Number(k))); + const jsArray = jsParts[k]; + if( jArray.length != jsArray.length ){ + throw `unequal lengths ${jArray.length} != ${jsArray.length}` + } + for( var l = 0; l < jArray.length; l++ ){ + if( jArray[l] != jsArray[l] ){ + throw `at index ${l}: ${jArray[l]} != ${jsArray[l]}` + } + } + } + + return true; +} + + +test('PolygotTests roundrip parts between JavaScript and Java', function (t) { + t.plan(1); + const secretUtf8 = `ᚠᛇᚻ`; + const secret = stringToBytes(secretUtf8); + const parts = split(randomBytes, 3, 2, secret); + const jParts = javaScriptToJavaParts(parts); + const jsParts = javaToJavaScriptParts(jParts); + t.ok(equalParts(jParts, jsParts), `roundtrip parts`) +}); + + +const NotRandomSource = Java.type('com.codahale.shamir.polygot.NotRandomSource'); +const notRandomSource = new NotRandomSource(); +function notRandomSourceJavaScript(len) { + const bytes = []; + for( var i = 0; i < len; i++){ + bytes[i] = i+1; + } + return bytes; +} + + +test('PolygotTests compare Java and JavaScript split', function (t) { + t.plan(1); + const secretUtf8 = `ᚠᛇᚻ`; + const secret = stringToBytes(secretUtf8); + + const jsParts = split(notRandomSourceJavaScript, 3, 2, secret); + + const jscheme = new Scheme(notRandomSource, 3, 2); + const jParts = jscheme.split(jsByteArrayToJavaByteArray(secret)); + t.ok(equalParts(jParts, jsParts), `splits match`) +}); + + +test('PolygotTests JavaScript split with Java join', function (t) { + t.plan(1); + const secretUtf8 = `ᚠᛇᚻ`; + + const secret = stringToBytes(secretUtf8); + const jsParts = split(randomBytes, 3, 2, secret); + const jscheme = new Scheme(secureRandom, 3, 2); + const joined = jscheme.join(javaScriptToJavaParts(jsParts)); + + t.equal(bytesToSring(jBytesArrayToJavaScriptByteArray(joined)), secretUtf8, `java joined js parts` ); +}); + +const join = require('../../main/js/Scheme.js').join; + +test('PolygotTests Java split with JavaScript join', function (t) { + t.plan(1); + const secretUtf8 = `ᚠᛇᚻ`; + + const secret = stringToBytes(secretUtf8); + const jscheme = new Scheme(secureRandom, 3, 2); + const jParts = jscheme.split(jsByteArrayToJavaByteArray(secret)); + const joined = join(javaToJavaScriptParts(jParts)); + + t.equal(bytesToSring(joined), secretUtf8, `java joined js parts` ); +}); \ No newline at end of file diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index 1953de4..28e88e3 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -112,8 +112,6 @@ test('SchemeTests split input validation', function (t) { }); test('SchemeTests join input validation', function (t) { - -// try { join({}); From 1264f713067eca33b3a46b0e5b0e4aefe10b41a8 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sat, 29 Jun 2019 06:17:37 +0100 Subject: [PATCH 23/78] reset Java to original codehale --- src/main/java/com/codahale/shamir/GF256.java | 13 ----- .../java/com/codahale/shamir/GF256Test.java | 49 +------------------ .../com/codahale/shamir/tests/SchemeTest.java | 32 ++++++------ 3 files changed, 17 insertions(+), 77 deletions(-) diff --git a/src/main/java/com/codahale/shamir/GF256.java b/src/main/java/com/codahale/shamir/GF256.java index 1fcd88d..9b85ea9 100644 --- a/src/main/java/com/codahale/shamir/GF256.java +++ b/src/main/java/com/codahale/shamir/GF256.java @@ -70,13 +70,6 @@ private GF256() { (byte) 0x31, (byte) 0xfe, (byte) 0x18, (byte) 0x0d, (byte) 0x63, (byte) 0x8c, (byte) 0x80, (byte) 0xc0, (byte) 0xf7, (byte) 0x70, (byte) 0x07, }; - - static byte[] LOG() { - byte[] logs = new byte[LOG.length]; - System.arraycopy(LOG, 0, logs, 0, logs.length); - return logs; - } - private static final byte[] EXP = { (byte) 0x01, (byte) 0x03, (byte) 0x05, (byte) 0x0f, (byte) 0x11, (byte) 0x33, (byte) 0x55, (byte) 0xff, (byte) 0x1a, (byte) 0x2e, (byte) 0x72, (byte) 0x96, (byte) 0xa1, (byte) 0xf8, @@ -153,12 +146,6 @@ static byte[] LOG() { (byte) 0x24, (byte) 0x6c, (byte) 0xb4, (byte) 0xc7, (byte) 0x52, (byte) 0xf6, }; - static byte[] EXP() { - byte[] exp = new byte[EXP.length]; - System.arraycopy(EXP, 0, exp, 0, exp.length); - return exp; - } - static byte add(byte a, byte b) { return (byte) (a ^ b); } diff --git a/src/test/java/com/codahale/shamir/GF256Test.java b/src/test/java/com/codahale/shamir/GF256Test.java index 2d2e46c..079488c 100644 --- a/src/test/java/com/codahale/shamir/GF256Test.java +++ b/src/test/java/com/codahale/shamir/GF256Test.java @@ -21,53 +21,9 @@ import java.security.SecureRandom; import org.junit.jupiter.api.Test; import org.quicktheories.WithQuickTheories; -import static java.lang.Byte.toUnsignedInt; class GF256Test implements WithQuickTheories { - @Test - void exp() { - // https://crypto.stackexchange.com/a/21174/13860 - final byte[] EXP = GF256.EXP(); - final byte g = 0x03; - int t = 0x01; - for (int i = 0; i < EXP.length; i++) { - int expected = t; - int actual = toUnsignedInt(EXP[i]); - assertThat(actual).isEqualTo(expected); - t = toUnsignedInt(GF256.mul(g, (byte) (t & 0xFF))); - } - } - -// @Test -// void log() { -// // https://crypto.stackexchange.com/a/21174/13860 -// final byte[] LOG = GF256.LOG(); -// final byte[] EXP = GF256.EXP(); -// final byte[] log = new byte[255]; -// -// for (int i = 0; i < log.length - 1; i++) { -// int index = toUnsignedInt(EXP[i]) % 255; -// log[index] = (byte) (i & 0xFF); -// //log[index] = (byte) ((i & 0xFF) % 255); -//// if( index < 255 ) { -//// log[index] = (byte) (i & 0xFF); -//// } else { -//// System.out.println(String.format("i=%d index=%d", i, index)); -//// } -// } -// -// for (int i = 1; i < LOG.length; i++) { -// int expected = toUnsignedInt(log[i]); -// int actual = toUnsignedInt(LOG[i]); -// if( expected != actual) -// System.out.println(String.format("i=%d expected=%d actual=%d", i, expected, actual)); -// assertThat(actual).isEqualTo(expected); -// } -// } - - - @Test void add() { assertThat(GF256.add((byte) 100, (byte) 30)).isEqualTo((byte) 122); @@ -132,12 +88,9 @@ void eval() { assertThat(GF256.eval(new byte[] {1, 0, 2, 3}, (byte) 2)).isEqualTo((byte) 17); } - static class NotRandom extends SecureRandom {} - @Test void generate() { - - final NotRandom random = new NotRandom(); + final SecureRandom random = new SecureRandom(); final byte[] p = GF256.generate(random, 5, (byte) 20); assertThat(p[0]).isEqualTo((byte) 20); assertThat(p.length).isEqualTo(6); diff --git a/src/test/java/com/codahale/shamir/tests/SchemeTest.java b/src/test/java/com/codahale/shamir/tests/SchemeTest.java index 4f8b2c0..fbf47cd 100644 --- a/src/test/java/com/codahale/shamir/tests/SchemeTest.java +++ b/src/test/java/com/codahale/shamir/tests/SchemeTest.java @@ -60,25 +60,25 @@ void thresholdTooHigh() { .isInstanceOf(IllegalArgumentException.class); } -// @Test -// void joinEmptyParts() { -// assertThatThrownBy(() -> new Scheme(new SecureRandom(), 3, 2).join(Collections.emptyMap())) -// .isInstanceOf(IllegalArgumentException.class); -// } - -// @Test -// void joinIrregularParts() { -// final byte[] one = new byte[] {1}; -// final byte[] two = new byte[] {1, 2}; -// -// assertThatThrownBy( -// () -> new Scheme(new SecureRandom(), 3, 2).join(ImmutableMap.of(1, one, 2, two))) -// .isInstanceOf(IllegalArgumentException.class); -// } + @Test + void joinEmptyParts() { + assertThatThrownBy(() -> new Scheme(new SecureRandom(), 3, 2).join(Collections.emptyMap())) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + void joinIrregularParts() { + final byte[] one = new byte[] {1}; + final byte[] two = new byte[] {1, 2}; + + assertThatThrownBy( + () -> new Scheme(new SecureRandom(), 3, 2).join(ImmutableMap.of(1, one, 2, two))) + .isInstanceOf(IllegalArgumentException.class); + } @Test void splitAndJoinSingleByteSecret() { - final Scheme scheme = new Scheme(new SecureRandom(), 3, 2); + final Scheme scheme = new Scheme(new SecureRandom(), 8, 3); final byte[] secret = "x".getBytes(StandardCharsets.UTF_8); assertThat(scheme.join(scheme.split(secret))).containsExactly(secret); From 3adc64e80031ad1e4a72af5da0e532091f6fee2e Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sat, 29 Jun 2019 11:50:54 +0100 Subject: [PATCH 24/78] dockerized testing of JS against Jave --- .gitignore | 1 + Dockerfile.graaljs | 10 ++++++++++ testJavaScriptAgainstJava.sh | 2 ++ 3 files changed, 13 insertions(+) create mode 100644 Dockerfile.graaljs create mode 100755 testJavaScriptAgainstJava.sh diff --git a/.gitignore b/.gitignore index 475bfaf..9701a9c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ node_modules/ .idea/ .project .settings +.vscode/ diff --git a/Dockerfile.graaljs b/Dockerfile.graaljs new file mode 100644 index 0000000..46b159a --- /dev/null +++ b/Dockerfile.graaljs @@ -0,0 +1,10 @@ +FROM maven:3-jdk-12-alpine AS build +COPY . src +WORKDIR src +RUN mvn package + +FROM oracle/graalvm-ce:latest AS graal +COPY --from=build /src /src +WORKDIR src +RUN npm test && npm run testwithjava + diff --git a/testJavaScriptAgainstJava.sh b/testJavaScriptAgainstJava.sh new file mode 100755 index 0000000..e007762 --- /dev/null +++ b/testJavaScriptAgainstJava.sh @@ -0,0 +1,2 @@ +#!/bin/sh +docker build -f Dockerfile.graaljs . \ No newline at end of file From a99223656aa5dc54bbe650dd4600e7bd45157a46 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 08:27:07 +0100 Subject: [PATCH 25/78] improved jsdoc --- Dockerfile.graaljs | 2 ++ src/main/js/GF256.js | 14 +++++++++----- src/main/js/Scheme.js | 6 +++--- .../codahale/shamir/polygot/JavaScriptUtils.java | 8 ++++++++ .../codahale/shamir/polygot/NotRandomSource.java | 4 ++++ src/test/js/SchemeTests.js | 2 -- testJavaScriptAgainstJava.sh | 1 + 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Dockerfile.graaljs b/Dockerfile.graaljs index 46b159a..36fe5f3 100644 --- a/Dockerfile.graaljs +++ b/Dockerfile.graaljs @@ -1,8 +1,10 @@ +# Run the stand java build on openjdk FROM maven:3-jdk-12-alpine AS build COPY . src WORKDIR src RUN mvn package +# Copy the result to graaljs and test node.js+java in the same vm FROM oracle/graalvm-ce:latest AS graal COPY --from=build /src /src WORKDIR src diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index 362fcdd..f0e1445 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -29,7 +29,7 @@ to subtraction. */ const sub = add; -exports.sub = exports.add; +exports.sub = exports.sub; const LOG = [ @@ -177,8 +177,11 @@ const degree = function(p) { exports.degree = degree; +/** + * Calculates f(0) of the given points using Lagrangian interpolation. + * @param {array[array[Uint8Array]]} points The supplied point. + */ exports.interpolate = function(points) { - // calculate f(0) of the given points using Lagrangian interpolation const x = 0; var y = 0; for (var i = 0; i < points.length; i++) { @@ -197,10 +200,11 @@ exports.interpolate = function(points) { } /** - * Generates a random polynomal of the correct degree and sets x. - * @param {function int -> array[Uint8Array]} randomBytes Takes a length and returns a Uint8Array of that length + * Generates a random polynomal of the correct degree and sets x as the first coefficient. + * @param {function int -> array[Uint8Array]} randomBytes Takes a length and returns a Uint8Array of that length. * @param {Number} d The degree of the polynomial driven by the number shares and join threshold. - * @return {Number} x The point to hide. + * @param {Number} x The point to hide. + * @return { array[Uint8Array]} The random polynomial with x as the fist coefficient. */ exports.generate = function(randomBytes, d, x){ var p = null; diff --git a/src/main/js/Scheme.js b/src/main/js/Scheme.js index e6a14a2..49a7aaf 100644 --- a/src/main/js/Scheme.js +++ b/src/main/js/Scheme.js @@ -1,5 +1,5 @@ /* - * Copyright © 2017 Coda Hale (coda.hale@gmail.com) + * Copyright © 2019 Simon Massey (massey1905@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ const GF256 = require('./GF256.js'); * @param {Number} n the number of parts to produce (must be {@code >1}) * @param {Number} k the threshold of joinable parts (must be {@code <= n}) * @param {array[Uint8Array]} secret The secret to split as an array of bytes - * @return {map[Number,Uint8Array[byte]]} an map of {@code n} parts that are arrays of bytes of the secret length + * @return {Object.} an map of {@code n} parts that are arrays of bytes of the secret length */ exports.split = function (randomBytes, n, k, secret) { if (k <= 1) throw "K must be > 1"; @@ -57,7 +57,7 @@ exports.split = function (randomBytes, n, k, secret) { * original secret. If the parts are incorrect, or are under the threshold value used to split the * secret, a random value will be returned. * - * @param {array[array[byte]]} parts an array of {@code n} parts + * @param {Object.} parts an map of {@code n} parts that are arrays of bytes of the secret length * @return {array[Uint8Array]} the original secret * */ diff --git a/src/test/java/com/codahale/shamir/polygot/JavaScriptUtils.java b/src/test/java/com/codahale/shamir/polygot/JavaScriptUtils.java index 782965f..3f673fb 100644 --- a/src/test/java/com/codahale/shamir/polygot/JavaScriptUtils.java +++ b/src/test/java/com/codahale/shamir/polygot/JavaScriptUtils.java @@ -21,6 +21,13 @@ import java.util.Map.Entry; import java.util.stream.Collectors; +/** + * The GraalJS internals cannot be fooled into casting between unsigned + * JavaScript bytes and signed Java bytes. We only ever want to + * do this within unit tests to compare arrays in-memory. This class uses + * an inefficent workaround of building bidirectional maps. The keys are + * Integer to fit a signed byte. + */ public class JavaScriptUtils { // https://stackoverflow.com/a/12310078/329496 public static String byteToBinaryString(final byte b) { @@ -33,6 +40,7 @@ static Map signedToUnsignedByteMap() { final String bits = byteToBinaryString(b); final Integer i = Integer.parseInt(bits, 2) & 0xff; result.put((int)b, i); + // here we avoid overflow on b++ causing an infinit loop if (b == Byte.MAX_VALUE) break; } return Collections.unmodifiableMap(result); diff --git a/src/test/java/com/codahale/shamir/polygot/NotRandomSource.java b/src/test/java/com/codahale/shamir/polygot/NotRandomSource.java index e9e709b..0d4bb52 100644 --- a/src/test/java/com/codahale/shamir/polygot/NotRandomSource.java +++ b/src/test/java/com/codahale/shamir/polygot/NotRandomSource.java @@ -17,6 +17,10 @@ import java.security.SecureRandom; +/** + * This class ensures that unit tests can repeatedly initalise with + * the same polynomial. + */ public class NotRandomSource extends SecureRandom { @Override diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index 28e88e3..e5e03f4 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -59,8 +59,6 @@ test('SchemeTests roundtrip', function (t) { t.equal( joined[201], secret[201] ); const joinedUtf8 = bytesToSring(joined); t.equal( secretUtf8, joinedUtf8 ); - // console.log("The secret is: "+secretUtf8); - // console.log("The decoded secret is: "+joinedUtf8); t.end(); }); diff --git a/testJavaScriptAgainstJava.sh b/testJavaScriptAgainstJava.sh index e007762..6f84f09 100755 --- a/testJavaScriptAgainstJava.sh +++ b/testJavaScriptAgainstJava.sh @@ -1,2 +1,3 @@ #!/bin/sh +# This tests the docker build -f Dockerfile.graaljs . \ No newline at end of file From eba5eccef1dd710a022297fa3420ae8303790051 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 08:27:39 +0100 Subject: [PATCH 26/78] package doc --- src/test/java/com/codahale/shamir/polygot/package-info.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/test/java/com/codahale/shamir/polygot/package-info.java diff --git a/src/test/java/com/codahale/shamir/polygot/package-info.java b/src/test/java/com/codahale/shamir/polygot/package-info.java new file mode 100644 index 0000000..766d31d --- /dev/null +++ b/src/test/java/com/codahale/shamir/polygot/package-info.java @@ -0,0 +1,5 @@ +/* + * This package provides classes to aid testing JavaScript against Java within + * the same JVM using GraalJS. + */ +package com.codahale.shamir.polygot; From 5d6b2612325b98e77f43b31a959f62dd16769652 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 09:55:33 +0100 Subject: [PATCH 27/78] fixed types of jsdoc --- src/main/js/GF256.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index f0e1445..75b2a04 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -179,7 +179,7 @@ exports.degree = degree; /** * Calculates f(0) of the given points using Lagrangian interpolation. - * @param {array[array[Uint8Array]]} points The supplied point. + * @param {array[Uint8Array]} points The supplied point. */ exports.interpolate = function(points) { const x = 0; @@ -204,7 +204,7 @@ exports.interpolate = function(points) { * @param {function int -> array[Uint8Array]} randomBytes Takes a length and returns a Uint8Array of that length. * @param {Number} d The degree of the polynomial driven by the number shares and join threshold. * @param {Number} x The point to hide. - * @return { array[Uint8Array]} The random polynomial with x as the fist coefficient. + * @return {Uint8Array} The random polynomial with x as the fist coefficient. */ exports.generate = function(randomBytes, d, x){ var p = null; @@ -222,7 +222,7 @@ exports.generate = function(randomBytes, d, x){ /** * Evaluates a polynomal at point x using Horner's method. - * @param {array[Uint8Array]} p The polynomial + * @param {Uint8Array} p The polynomial * @return {Number} x The point to evaluate. */ exports.eval = function(p, x){ From 55165c83305b16a56da33121df749fbaf2947def Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 09:56:52 +0100 Subject: [PATCH 28/78] Fix jsdoc --- src/main/js/Scheme.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/js/Scheme.js b/src/main/js/Scheme.js index 49a7aaf..ce0e3e5 100644 --- a/src/main/js/Scheme.js +++ b/src/main/js/Scheme.js @@ -21,7 +21,7 @@ const GF256 = require('./GF256.js'); /** * Splits the given secret into {@code n} parts, of which any {@code k} or more can be combined to * recover the original secret. - * @param {function int -> array[Uint8Array]} randomBytes Takes a length and returns a Uint8Array of that length + * @param {function int -> Uint8Array} randomBytes Takes a length and returns a random Uint8Array of that length * @param {Number} n the number of parts to produce (must be {@code >1}) * @param {Number} k the threshold of joinable parts (must be {@code <= n}) * @param {array[Uint8Array]} secret The secret to split as an array of bytes @@ -58,7 +58,7 @@ exports.split = function (randomBytes, n, k, secret) { * secret, a random value will be returned. * * @param {Object.} parts an map of {@code n} parts that are arrays of bytes of the secret length - * @return {array[Uint8Array]} the original secret + * @return {Uint8Array} the original secret * */ exports.join = function(parts){ @@ -81,4 +81,4 @@ exports.join = function(parts){ } return secret; -}; \ No newline at end of file +}; From 5045930a4d0b78bf01b70d07f319833870d3c2d6 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 17:41:28 +0100 Subject: [PATCH 29/78] rename script --- testJavaScriptAgainstJava.sh => test_js_against_java.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename testJavaScriptAgainstJava.sh => test_js_against_java.sh (100%) diff --git a/testJavaScriptAgainstJava.sh b/test_js_against_java.sh similarity index 100% rename from testJavaScriptAgainstJava.sh rename to test_js_against_java.sh From 2a0bf8ca653a2e735dfb28ad6d8fe6f74ea45f44 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 17:41:45 +0100 Subject: [PATCH 30/78] circleci workflow --- .circleci/config.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index ecf8859..458f5ee 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -44,3 +44,26 @@ jobs: path: ~/junit - store_artifacts: path: ~/junit + - persist_to_workspace: + # Must be an absolute path, or relative path from working_directory. This is a directory on the container which is + # taken to be the root directory of the workspace. + root: target + # Must be relative path from root + paths: + - classes + - test-classes + testjs: + docker: + - image: oracle/graalvm-ce:latest + working_directory: ~/repo + steps: + - checkout + - run: npm test && npm run testwithjava +workflows: + version: 2 + build_and_test: + jobs: + - build + - testjs + requires: + - build \ No newline at end of file From a579e2589cb51bd718125d14d2e4192f4249bb4f Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 17:47:10 +0100 Subject: [PATCH 31/78] debugging ci workflow --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 458f5ee..38f8b4c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,6 +64,6 @@ workflows: build_and_test: jobs: - build - - testjs + - testjs: requires: - build \ No newline at end of file From ad49cecafae791165089c3d051106211623b4286 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 17:48:27 +0100 Subject: [PATCH 32/78] debugging ci --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 38f8b4c..7425dff 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -65,5 +65,5 @@ workflows: jobs: - build - testjs: - requires: - - build \ No newline at end of file + requires: + - build \ No newline at end of file From 254a0767559176a43c0d05ce374ee2524d9610b8 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 17:52:50 +0100 Subject: [PATCH 33/78] debugging ci --- .circleci/config.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7425dff..e215c45 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,17 +47,18 @@ jobs: - persist_to_workspace: # Must be an absolute path, or relative path from working_directory. This is a directory on the container which is # taken to be the root directory of the workspace. - root: target + root: ~/repo # Must be relative path from root paths: - - classes - - test-classes + - src + - target testjs: docker: - image: oracle/graalvm-ce:latest working_directory: ~/repo steps: - checkout + - run: npm install tape --save-dev - run: npm test && npm run testwithjava workflows: version: 2 From a9446f2d7994aba2cdeb1f65b87ff9ea39804914 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 17:58:49 +0100 Subject: [PATCH 34/78] fixed export --- src/main/js/GF256.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index 75b2a04..c402de2 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -29,7 +29,7 @@ to subtraction. */ const sub = add; -exports.sub = exports.sub; +exports.sub = exports.add; const LOG = [ From d973cea2cf1ce664df670670b740631986096617 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 18:02:09 +0100 Subject: [PATCH 35/78] debugging ci --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e215c45..178628a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -57,7 +57,8 @@ jobs: - image: oracle/graalvm-ce:latest working_directory: ~/repo steps: - - checkout + - attach_workspace: + at: ~/repo - run: npm install tape --save-dev - run: npm test && npm run testwithjava workflows: From d21e5f88e7d47c8523fa87975bd54e926fde445f Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 18:55:46 +0100 Subject: [PATCH 36/78] debugging ci --- .circleci/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 178628a..a400d60 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -52,6 +52,9 @@ jobs: paths: - src - target + - package.json + - package-lock.json + testjs: docker: - image: oracle/graalvm-ce:latest From a5a49382d2bd72e6bcebbcc0d53c3f90c2334944 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 19:29:41 +0100 Subject: [PATCH 37/78] working ci build --- .circleci/config.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a400d60..74b9e0f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -45,10 +45,7 @@ jobs: - store_artifacts: path: ~/junit - persist_to_workspace: - # Must be an absolute path, or relative path from working_directory. This is a directory on the container which is - # taken to be the root directory of the workspace. root: ~/repo - # Must be relative path from root paths: - src - target From bb40cb38de044fac99f58ddc6eb00a9e2d2254c8 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 19:30:31 +0100 Subject: [PATCH 38/78] eslint --- .eslintignore | 1 + .eslintrc | 18 + .prettierignore | 2 + .prettierrc | 3 + package-lock.json | 940 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 7 +- 6 files changed, 970 insertions(+), 1 deletion(-) create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .prettierignore create mode 100644 .prettierrc diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +node_modules diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..daf08d4 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,18 @@ +{ + "env": { + "browser": true, + "commonjs": true, + "es6": true, + "node": true + }, + "extends": ["eslint:recommended", "plugin:prettier/recommended"], + "parserOptions": { + "sourceType": "module", + "ecmaVersion": 2018 + }, + "rules": { + "linebreak-style": ["error", "unix"], + "react-hooks/rules-of-hooks": "error", + "react-hooks/exhaustive-deps": "warn" + } +} \ No newline at end of file diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..fed401d --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +package-lock.json +node_modules/ \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..92cde39 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,3 @@ +{ + "singleQuote": true +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8efa1a1..252f18d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,86 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@babel/code-frame": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", + "integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==", + "dev": true, + "requires": { + "@babel/highlight": "^7.0.0" + } + }, + "@babel/highlight": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0.tgz", + "integrity": "sha512-UFMC4ZeFC48Tpvj7C8UgLvtkaUuovQX+5xNWrsIoMG8o2z+XFKjKaN9iVmS84dPwVN00W4wPmqvYoZF3EGAsfw==", + "dev": true, + "requires": { + "chalk": "^2.0.0", + "esutils": "^2.0.2", + "js-tokens": "^4.0.0" + } + }, + "acorn": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz", + "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==", + "dev": true + }, + "acorn-jsx": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.0.1.tgz", + "integrity": "sha512-HJ7CfNHrfJLlNTzIEUTj43LNWGkqpRLxm3YjAlcD0ACydk9XynzYsCBHxut+iqt+1aBXkx9UP/w/ZqMr13XIzg==", + "dev": true + }, + "ajv": { + "version": "6.10.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz", + "integrity": "sha512-nffhOpkymDECQyR0mnsUtoCE8RlX38G0rYP+wgLWFyZuUyuuojSSvi/+euOiQBIn63whYwYVIIH1TvE3tu4OEg==", + "dev": true, + "requires": { + "fast-deep-equal": "^2.0.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + } + }, + "ansi-escapes": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz", + "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==", + "dev": true + }, + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "dev": true + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "requires": { + "sprintf-js": "~1.0.2" + } + }, + "astral-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", + "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", + "dev": true + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -20,18 +100,99 @@ "concat-map": "0.0.1" } }, + "callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "chardet": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", + "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", + "dev": true + }, + "cli-cursor": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", + "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", + "dev": true, + "requires": { + "restore-cursor": "^2.0.0" + } + }, + "cli-width": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", + "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=", + "dev": true + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, + "cross-spawn": { + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", + "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", + "dev": true, + "requires": { + "nice-try": "^1.0.4", + "path-key": "^2.0.1", + "semver": "^5.5.0", + "shebang-command": "^1.2.0", + "which": "^1.2.9" + } + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, "deep-equal": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz", "integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=", "dev": true }, + "deep-is": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", + "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", + "dev": true + }, "define-properties": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", @@ -47,12 +208,27 @@ "integrity": "sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM=", "dev": true }, + "doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, + "requires": { + "esutils": "^2.0.2" + } + }, "dom-walk": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.1.tgz", "integrity": "sha1-ZyIm3HTI95mtNTB9+TaroRrNYBg=", "dev": true }, + "emoji-regex": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", + "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", + "dev": true + }, "es-abstract": { "version": "1.13.0", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.13.0.tgz", @@ -78,6 +254,213 @@ "is-symbol": "^1.0.2" } }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, + "eslint": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.0.1.tgz", + "integrity": "sha512-DyQRaMmORQ+JsWShYsSg4OPTjY56u1nCjAmICrE8vLWqyLKxhFXOthwMj1SA8xwfrv0CofLNVnqbfyhwCkaO0w==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "ajv": "^6.10.0", + "chalk": "^2.1.0", + "cross-spawn": "^6.0.5", + "debug": "^4.0.1", + "doctrine": "^3.0.0", + "eslint-scope": "^4.0.3", + "eslint-utils": "^1.3.1", + "eslint-visitor-keys": "^1.0.0", + "espree": "^6.0.0", + "esquery": "^1.0.1", + "esutils": "^2.0.2", + "file-entry-cache": "^5.0.1", + "functional-red-black-tree": "^1.0.1", + "glob-parent": "^3.1.0", + "globals": "^11.7.0", + "ignore": "^4.0.6", + "import-fresh": "^3.0.0", + "imurmurhash": "^0.1.4", + "inquirer": "^6.2.2", + "is-glob": "^4.0.0", + "js-yaml": "^3.13.1", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.3.0", + "lodash": "^4.17.11", + "minimatch": "^3.0.4", + "mkdirp": "^0.5.1", + "natural-compare": "^1.4.0", + "optionator": "^0.8.2", + "progress": "^2.0.0", + "regexpp": "^2.0.1", + "semver": "^5.5.1", + "strip-ansi": "^4.0.0", + "strip-json-comments": "^2.0.1", + "table": "^5.2.3", + "text-table": "^0.2.0" + } + }, + "eslint-config-prettier": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-6.0.0.tgz", + "integrity": "sha512-vDrcCFE3+2ixNT5H83g28bO/uYAwibJxerXPj+E7op4qzBCsAV36QfvdAyVOoNxKAH2Os/e01T/2x++V0LPukA==", + "dev": true, + "requires": { + "get-stdin": "^6.0.0" + } + }, + "eslint-plugin-prettier": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.0.tgz", + "integrity": "sha512-XWX2yVuwVNLOUhQijAkXz+rMPPoCr7WFiAl8ig6I7Xn+pPVhDhzg4DxHpmbeb0iqjO9UronEA3Tb09ChnFVHHA==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0" + } + }, + "eslint-scope": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.3.tgz", + "integrity": "sha512-p7VutNr1O/QrxysMo3E45FjYDTeXBy0iTltPFNSqKAIfjDSXC+4dj+qfyuD8bfAXrW/y6lW3O76VaYNPKfpKrg==", + "dev": true, + "requires": { + "esrecurse": "^4.1.0", + "estraverse": "^4.1.1" + } + }, + "eslint-utils": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.3.1.tgz", + "integrity": "sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q==", + "dev": true + }, + "eslint-visitor-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", + "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==", + "dev": true + }, + "espree": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-6.0.0.tgz", + "integrity": "sha512-lJvCS6YbCn3ImT3yKkPe0+tJ+mH6ljhGNjHQH9mRtiO6gjhVAOhVXW1yjnwqGwTkK3bGbye+hb00nFNmu0l/1Q==", + "dev": true, + "requires": { + "acorn": "^6.0.7", + "acorn-jsx": "^5.0.0", + "eslint-visitor-keys": "^1.0.0" + } + }, + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true + }, + "esquery": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.0.1.tgz", + "integrity": "sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA==", + "dev": true, + "requires": { + "estraverse": "^4.0.0" + } + }, + "esrecurse": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", + "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", + "dev": true, + "requires": { + "estraverse": "^4.1.0" + } + }, + "estraverse": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz", + "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=", + "dev": true + }, + "esutils": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", + "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", + "dev": true + }, + "external-editor": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.0.3.tgz", + "integrity": "sha512-bn71H9+qWoOQKyZDo25mOMVpSmXROAsTJVVVYzrrtol3d4y+AsKjf4Iwl2Q+IuT0kFSQ1qo166UuIwqYq7mGnA==", + "dev": true, + "requires": { + "chardet": "^0.7.0", + "iconv-lite": "^0.4.24", + "tmp": "^0.0.33" + } + }, + "fast-deep-equal": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", + "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=", + "dev": true + }, + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, + "fast-json-stable-stringify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", + "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=", + "dev": true + }, + "fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", + "dev": true + }, + "figures": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", + "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", + "dev": true, + "requires": { + "escape-string-regexp": "^1.0.5" + } + }, + "file-entry-cache": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-5.0.1.tgz", + "integrity": "sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g==", + "dev": true, + "requires": { + "flat-cache": "^2.0.1" + } + }, + "flat-cache": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz", + "integrity": "sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA==", + "dev": true, + "requires": { + "flatted": "^2.0.0", + "rimraf": "2.6.3", + "write": "1.0.3" + } + }, + "flatted": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.1.tgz", + "integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==", + "dev": true + }, "for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -99,6 +482,18 @@ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "dev": true }, + "functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", + "dev": true + }, + "get-stdin": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", + "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", + "dev": true + }, "glob": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", @@ -113,6 +508,27 @@ "path-is-absolute": "^1.0.0" } }, + "glob-parent": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-3.1.0.tgz", + "integrity": "sha1-nmr2KZ2NO9K9QEMIMr0RPfkGxa4=", + "dev": true, + "requires": { + "is-glob": "^3.1.0", + "path-dirname": "^1.0.0" + }, + "dependencies": { + "is-glob": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-3.1.0.tgz", + "integrity": "sha1-e6WuJCF4BKxwcHuWkiVnSGzD6Eo=", + "dev": true, + "requires": { + "is-extglob": "^2.1.0" + } + } + } + }, "global": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/global/-/global-4.3.2.tgz", @@ -123,6 +539,12 @@ "process": "~0.5.1" } }, + "globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "dev": true + }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -132,12 +554,49 @@ "function-bind": "^1.1.1" } }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "dev": true + }, "has-symbols": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz", "integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q=", "dev": true }, + "iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "dev": true, + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + }, + "ignore": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", + "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", + "dev": true + }, + "import-fresh": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.1.0.tgz", + "integrity": "sha512-PpuksHKGt8rXfWEr9m9EHIpgyyaltBy8+eF6GJM0QCAxMgxCfucMF3mjecK2QsJr0amJW7gTqh5/wht0z2UhEQ==", + "dev": true, + "requires": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + } + }, + "imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", + "dev": true + }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -154,6 +613,44 @@ "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", "dev": true }, + "inquirer": { + "version": "6.4.1", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-6.4.1.tgz", + "integrity": "sha512-/Jw+qPZx4EDYsaT6uz7F4GJRNFMRdKNeUZw3ZnKV8lyuUgz/YWRCSUAJMZSVhSq4Ec0R2oYnyi6b3d4JXcL5Nw==", + "dev": true, + "requires": { + "ansi-escapes": "^3.2.0", + "chalk": "^2.4.2", + "cli-cursor": "^2.1.0", + "cli-width": "^2.0.0", + "external-editor": "^3.0.3", + "figures": "^2.0.0", + "lodash": "^4.17.11", + "mute-stream": "0.0.7", + "run-async": "^2.2.0", + "rxjs": "^6.4.0", + "string-width": "^2.1.0", + "strip-ansi": "^5.1.0", + "through": "^2.3.6" + }, + "dependencies": { + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } + } + } + }, "is-callable": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", @@ -166,6 +663,33 @@ "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=", "dev": true }, + "is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", + "dev": true + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "dev": true + }, + "is-glob": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", + "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", + "dev": true, + "requires": { + "is-extglob": "^2.1.1" + } + }, + "is-promise": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", + "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=", + "dev": true + }, "is-regex": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz", @@ -184,6 +708,62 @@ "has-symbols": "^1.0.0" } }, + "isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", + "dev": true + }, + "js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true + }, + "js-yaml": { + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", + "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", + "dev": true, + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + }, + "json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", + "dev": true + }, + "levn": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", + "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", + "dev": true, + "requires": { + "prelude-ls": "~1.1.2", + "type-check": "~0.3.2" + } + }, + "lodash": { + "version": "4.17.11", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", + "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "dev": true + }, + "mimic-fn": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", + "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", + "dev": true + }, "min-document": { "version": "2.19.0", "resolved": "https://registry.npmjs.org/min-document/-/min-document-2.19.0.tgz", @@ -208,6 +788,47 @@ "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + }, + "dependencies": { + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + } + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "mute-stream": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", + "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", + "dev": true + }, + "natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", + "dev": true + }, + "nice-try": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", + "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", + "dev": true + }, "object-inspect": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.6.0.tgz", @@ -229,24 +850,113 @@ "wrappy": "1" } }, + "onetime": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", + "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", + "dev": true, + "requires": { + "mimic-fn": "^1.0.0" + } + }, + "optionator": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", + "integrity": "sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q=", + "dev": true, + "requires": { + "deep-is": "~0.1.3", + "fast-levenshtein": "~2.0.4", + "levn": "~0.3.0", + "prelude-ls": "~1.1.2", + "type-check": "~0.3.2", + "wordwrap": "~1.0.0" + } + }, + "os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", + "dev": true + }, + "parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "requires": { + "callsites": "^3.0.0" + } + }, + "path-dirname": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/path-dirname/-/path-dirname-1.0.2.tgz", + "integrity": "sha1-zDPSTVJeCZpTiMAzbG4yuRYGCeA=", + "dev": true + }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, + "path-key": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", + "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", + "dev": true + }, "path-parse": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "dev": true }, + "prelude-ls": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", + "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", + "dev": true + }, + "prettier": { + "version": "1.18.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.18.2.tgz", + "integrity": "sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==", + "dev": true + }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "process": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/process/-/process-0.5.2.tgz", "integrity": "sha1-FjjYqONML0QKkduVq5rrZ3/Bhc8=", "dev": true }, + "progress": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", + "dev": true + }, + "punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "dev": true + }, + "regexpp": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", + "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==", + "dev": true + }, "resolve": { "version": "1.10.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.1.tgz", @@ -256,6 +966,22 @@ "path-parse": "^1.0.6" } }, + "resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true + }, + "restore-cursor": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", + "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", + "dev": true, + "requires": { + "onetime": "^2.0.0", + "signal-exit": "^3.0.2" + } + }, "resumer": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/resumer/-/resumer-0.0.0.tgz", @@ -265,6 +991,93 @@ "through": "~2.3.4" } }, + "rimraf": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", + "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, + "run-async": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", + "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", + "dev": true, + "requires": { + "is-promise": "^2.1.0" + } + }, + "rxjs": { + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.2.tgz", + "integrity": "sha512-HUb7j3kvb7p7eCUHE3FqjoDsC1xfZQ4AHFWfTKSpZ+sAhhz5X1WX0ZuUqWbzB2QhSLp3DoLUG+hMdEDKqWo2Zg==", + "dev": true, + "requires": { + "tslib": "^1.9.0" + } + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true + }, + "semver": { + "version": "5.7.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", + "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", + "dev": true + }, + "shebang-command": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", + "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", + "dev": true, + "requires": { + "shebang-regex": "^1.0.0" + } + }, + "shebang-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", + "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", + "dev": true + }, + "signal-exit": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", + "dev": true + }, + "slice-ansi": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", + "integrity": "sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.0", + "astral-regex": "^1.0.0", + "is-fullwidth-code-point": "^2.0.0" + } + }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", + "dev": true + }, + "string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "dev": true, + "requires": { + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^4.0.0" + } + }, "string.prototype.trim": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.1.2.tgz", @@ -276,6 +1089,70 @@ "function-bind": "^1.0.2" } }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "dev": true, + "requires": { + "ansi-regex": "^3.0.0" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", + "dev": true + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + }, + "table": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/table/-/table-5.4.1.tgz", + "integrity": "sha512-E6CK1/pZe2N75rGZQotFOdmzWQ1AILtgYbMAbAjvms0S1l5IDB47zG3nCnFGB/w+7nB3vKofbLXCH7HPBo864w==", + "dev": true, + "requires": { + "ajv": "^6.9.1", + "lodash": "^4.17.11", + "slice-ansi": "^2.1.0", + "string-width": "^3.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "dev": true, + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } + } + } + }, "tape": { "version": "4.10.2", "resolved": "https://registry.npmjs.org/tape/-/tape-4.10.2.tgz", @@ -306,23 +1183,86 @@ "global": "~4.3.0" } }, + "text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", + "dev": true + }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, + "tmp": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", + "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", + "dev": true, + "requires": { + "os-tmpdir": "~1.0.2" + } + }, + "tslib": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", + "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==", + "dev": true + }, "tweetnacl": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.1.tgz", "integrity": "sha512-kcoMoKTPYnoeS50tzoqjPY3Uv9axeuuFAZY9M/9zFnhoVvRfxz9K29IMPD7jGmt2c8SW7i3gT9WqDl2+nV7p4A==", "dev": true }, + "type-check": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", + "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", + "dev": true, + "requires": { + "prelude-ls": "~1.1.2" + } + }, + "uri-js": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", + "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", + "dev": true, + "requires": { + "punycode": "^2.1.0" + } + }, + "which": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } + }, + "wordwrap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", + "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", + "dev": true + }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true + }, + "write": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz", + "integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==", + "dev": true, + "requires": { + "mkdirp": "^0.5.1" + } } } } diff --git a/package.json b/package.json index 7823355..6a570a1 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "src/main/js/Scheme.js", "scripts": { "test": "tape src/test/js/GF256Tests.js src/test/js/SchemeTests.js", - "testwithjava": "node --jvm --vm.cp=./target/classes:./target/test-classes src/test/js/PolygotTests.js" + "testwithjava": "node --jvm --vm.cp=./target/classes:./target/test-classes src/test/js/PolygotTests.js", + "lint": "eslint --fix ./src/main/js/GF256.js ./src/main/js/Scheme.js && echo 'Lint complete.'" }, "repository": { "type": "git", @@ -26,6 +27,10 @@ }, "homepage": "https://github.com/codahale/shamir#readme", "devDependencies": { + "eslint": "^6.0.1", + "eslint-config-prettier": "^6.0.0", + "eslint-plugin-prettier": "^3.1.0", + "prettier": "^1.18.2", "tape": "^4.10.2", "tape-catch": "^1.0.6", "tweetnacl": "^1.0.1" From ef2ca310d127c2c1428b6accb02135c8e8624d8a Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 19:49:04 +0100 Subject: [PATCH 39/78] eslint suggestions --- src/main/js/GF256.js | 324 +++++++++++++++++++++--------------------- src/main/js/Scheme.js | 67 ++++----- 2 files changed, 195 insertions(+), 196 deletions(-) diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index c402de2..6124e3d 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -14,10 +14,8 @@ * limitations under the License. */ -"use strict"; - const add = function(a, b) { - return a ^ b; + return a ^ b; }; exports.add = add; @@ -31,204 +29,202 @@ const sub = add; exports.sub = exports.add; - -const LOG = [ - parseInt("0xff"), parseInt("0x00"), parseInt("0x19"), parseInt("0x01"), parseInt("0x32"), parseInt("0x02"), parseInt("0x1a"), - parseInt("0xc6"), parseInt("0x4b"), parseInt("0xc7"), parseInt("0x1b"), parseInt("0x68"), parseInt("0x33"), parseInt("0xee"), - parseInt("0xdf"), parseInt("0x03"), parseInt("0x64"), parseInt("0x04"), parseInt("0xe0"), parseInt("0x0e"), parseInt("0x34"), - parseInt("0x8d"), parseInt("0x81"), parseInt("0xef"), parseInt("0x4c"), parseInt("0x71"), parseInt("0x08"), parseInt("0xc8"), - parseInt("0xf8"), parseInt("0x69"), parseInt("0x1c"), parseInt("0xc1"), parseInt("0x7d"), parseInt("0xc2"), parseInt("0x1d"), - parseInt("0xb5"), parseInt("0xf9"), parseInt("0xb9"), parseInt("0x27"), parseInt("0x6a"), parseInt("0x4d"), parseInt("0xe4"), - parseInt("0xa6"), parseInt("0x72"), parseInt("0x9a"), parseInt("0xc9"), parseInt("0x09"), parseInt("0x78"), parseInt("0x65"), - parseInt("0x2f"), parseInt("0x8a"), parseInt("0x05"), parseInt("0x21"), parseInt("0x0f"), parseInt("0xe1"), parseInt("0x24"), - parseInt("0x12"), parseInt("0xf0"), parseInt("0x82"), parseInt("0x45"), parseInt("0x35"), parseInt("0x93"), parseInt("0xda"), - parseInt("0x8e"), parseInt("0x96"), parseInt("0x8f"), parseInt("0xdb"), parseInt("0xbd"), parseInt("0x36"), parseInt("0xd0"), - parseInt("0xce"), parseInt("0x94"), parseInt("0x13"), parseInt("0x5c"), parseInt("0xd2"), parseInt("0xf1"), parseInt("0x40"), - parseInt("0x46"), parseInt("0x83"), parseInt("0x38"), parseInt("0x66"), parseInt("0xdd"), parseInt("0xfd"), parseInt("0x30"), - parseInt("0xbf"), parseInt("0x06"), parseInt("0x8b"), parseInt("0x62"), parseInt("0xb3"), parseInt("0x25"), parseInt("0xe2"), - parseInt("0x98"), parseInt("0x22"), parseInt("0x88"), parseInt("0x91"), parseInt("0x10"), parseInt("0x7e"), parseInt("0x6e"), - parseInt("0x48"), parseInt("0xc3"), parseInt("0xa3"), parseInt("0xb6"), parseInt("0x1e"), parseInt("0x42"), parseInt("0x3a"), - parseInt("0x6b"), parseInt("0x28"), parseInt("0x54"), parseInt("0xfa"), parseInt("0x85"), parseInt("0x3d"), parseInt("0xba"), - parseInt("0x2b"), parseInt("0x79"), parseInt("0x0a"), parseInt("0x15"), parseInt("0x9b"), parseInt("0x9f"), parseInt("0x5e"), - parseInt("0xca"), parseInt("0x4e"), parseInt("0xd4"), parseInt("0xac"), parseInt("0xe5"), parseInt("0xf3"), parseInt("0x73"), - parseInt("0xa7"), parseInt("0x57"), parseInt("0xaf"), parseInt("0x58"), parseInt("0xa8"), parseInt("0x50"), parseInt("0xf4"), - parseInt("0xea"), parseInt("0xd6"), parseInt("0x74"), parseInt("0x4f"), parseInt("0xae"), parseInt("0xe9"), parseInt("0xd5"), - parseInt("0xe7"), parseInt("0xe6"), parseInt("0xad"), parseInt("0xe8"), parseInt("0x2c"), parseInt("0xd7"), parseInt("0x75"), - parseInt("0x7a"), parseInt("0xeb"), parseInt("0x16"), parseInt("0x0b"), parseInt("0xf5"), parseInt("0x59"), parseInt("0xcb"), - parseInt("0x5f"), parseInt("0xb0"), parseInt("0x9c"), parseInt("0xa9"), parseInt("0x51"), parseInt("0xa0"), parseInt("0x7f"), - parseInt("0x0c"), parseInt("0xf6"), parseInt("0x6f"), parseInt("0x17"), parseInt("0xc4"), parseInt("0x49"), parseInt("0xec"), - parseInt("0xd8"), parseInt("0x43"), parseInt("0x1f"), parseInt("0x2d"), parseInt("0xa4"), parseInt("0x76"), parseInt("0x7b"), - parseInt("0xb7"), parseInt("0xcc"), parseInt("0xbb"), parseInt("0x3e"), parseInt("0x5a"), parseInt("0xfb"), parseInt("0x60"), - parseInt("0xb1"), parseInt("0x86"), parseInt("0x3b"), parseInt("0x52"), parseInt("0xa1"), parseInt("0x6c"), parseInt("0xaa"), - parseInt("0x55"), parseInt("0x29"), parseInt("0x9d"), parseInt("0x97"), parseInt("0xb2"), parseInt("0x87"), parseInt("0x90"), - parseInt("0x61"), parseInt("0xbe"), parseInt("0xdc"), parseInt("0xfc"), parseInt("0xbc"), parseInt("0x95"), parseInt("0xcf"), - parseInt("0xcd"), parseInt("0x37"), parseInt("0x3f"), parseInt("0x5b"), parseInt("0xd1"), parseInt("0x53"), parseInt("0x39"), - parseInt("0x84"), parseInt("0x3c"), parseInt("0x41"), parseInt("0xa2"), parseInt("0x6d"), parseInt("0x47"), parseInt("0x14"), - parseInt("0x2a"), parseInt("0x9e"), parseInt("0x5d"), parseInt("0x56"), parseInt("0xf2"), parseInt("0xd3"), parseInt("0xab"), - parseInt("0x44"), parseInt("0x11"), parseInt("0x92"), parseInt("0xd9"), parseInt("0x23"), parseInt("0x20"), parseInt("0x2e"), - parseInt("0x89"), parseInt("0xb4"), parseInt("0x7c"), parseInt("0xb8"), parseInt("0x26"), parseInt("0x77"), parseInt("0x99"), - parseInt("0xe3"), parseInt("0xa5"), parseInt("0x67"), parseInt("0x4a"), parseInt("0xed"), parseInt("0xde"), parseInt("0xc5"), - parseInt("0x31"), parseInt("0xfe"), parseInt("0x18"), parseInt("0x0d"), parseInt("0x63"), parseInt("0x8c"), parseInt("0x80"), - parseInt("0xc0"), parseInt("0xf7"), parseInt("0x70"), parseInt("0x07"), - ]; +const LOG = new Uint8Array([ + parseInt('0xff'), parseInt('0x00'), parseInt('0x19'), parseInt('0x01'), parseInt('0x32'), parseInt('0x02'), parseInt('0x1a'), + parseInt('0xc6'), parseInt('0x4b'), parseInt('0xc7'), parseInt('0x1b'), parseInt('0x68'), parseInt('0x33'), parseInt('0xee'), + parseInt('0xdf'), parseInt('0x03'), parseInt('0x64'), parseInt('0x04'), parseInt('0xe0'), parseInt('0x0e'), parseInt('0x34'), + parseInt('0x8d'), parseInt('0x81'), parseInt('0xef'), parseInt('0x4c'), parseInt('0x71'), parseInt('0x08'), parseInt('0xc8'), + parseInt('0xf8'), parseInt('0x69'), parseInt('0x1c'), parseInt('0xc1'), parseInt('0x7d'), parseInt('0xc2'), parseInt('0x1d'), + parseInt('0xb5'), parseInt('0xf9'), parseInt('0xb9'), parseInt('0x27'), parseInt('0x6a'), parseInt('0x4d'), parseInt('0xe4'), + parseInt('0xa6'), parseInt('0x72'), parseInt('0x9a'), parseInt('0xc9'), parseInt('0x09'), parseInt('0x78'), parseInt('0x65'), + parseInt('0x2f'), parseInt('0x8a'), parseInt('0x05'), parseInt('0x21'), parseInt('0x0f'), parseInt('0xe1'), parseInt('0x24'), + parseInt('0x12'), parseInt('0xf0'), parseInt('0x82'), parseInt('0x45'), parseInt('0x35'), parseInt('0x93'), parseInt('0xda'), + parseInt('0x8e'), parseInt('0x96'), parseInt('0x8f'), parseInt('0xdb'), parseInt('0xbd'), parseInt('0x36'), parseInt('0xd0'), + parseInt('0xce'), parseInt('0x94'), parseInt('0x13'), parseInt('0x5c'), parseInt('0xd2'), parseInt('0xf1'), parseInt('0x40'), + parseInt('0x46'), parseInt('0x83'), parseInt('0x38'), parseInt('0x66'), parseInt('0xdd'), parseInt('0xfd'), parseInt('0x30'), + parseInt('0xbf'), parseInt('0x06'), parseInt('0x8b'), parseInt('0x62'), parseInt('0xb3'), parseInt('0x25'), parseInt('0xe2'), + parseInt('0x98'), parseInt('0x22'), parseInt('0x88'), parseInt('0x91'), parseInt('0x10'), parseInt('0x7e'), parseInt('0x6e'), + parseInt('0x48'), parseInt('0xc3'), parseInt('0xa3'), parseInt('0xb6'), parseInt('0x1e'), parseInt('0x42'), parseInt('0x3a'), + parseInt('0x6b'), parseInt('0x28'), parseInt('0x54'), parseInt('0xfa'), parseInt('0x85'), parseInt('0x3d'), parseInt('0xba'), + parseInt('0x2b'), parseInt('0x79'), parseInt('0x0a'), parseInt('0x15'), parseInt('0x9b'), parseInt('0x9f'), parseInt('0x5e'), + parseInt('0xca'), parseInt('0x4e'), parseInt('0xd4'), parseInt('0xac'), parseInt('0xe5'), parseInt('0xf3'), parseInt('0x73'), + parseInt('0xa7'), parseInt('0x57'), parseInt('0xaf'), parseInt('0x58'), parseInt('0xa8'), parseInt('0x50'), parseInt('0xf4'), + parseInt('0xea'), parseInt('0xd6'), parseInt('0x74'), parseInt('0x4f'), parseInt('0xae'), parseInt('0xe9'), parseInt('0xd5'), + parseInt('0xe7'), parseInt('0xe6'), parseInt('0xad'), parseInt('0xe8'), parseInt('0x2c'), parseInt('0xd7'), parseInt('0x75'), + parseInt('0x7a'), parseInt('0xeb'), parseInt('0x16'), parseInt('0x0b'), parseInt('0xf5'), parseInt('0x59'), parseInt('0xcb'), + parseInt('0x5f'), parseInt('0xb0'), parseInt('0x9c'), parseInt('0xa9'), parseInt('0x51'), parseInt('0xa0'), parseInt('0x7f'), + parseInt('0x0c'), parseInt('0xf6'), parseInt('0x6f'), parseInt('0x17'), parseInt('0xc4'), parseInt('0x49'), parseInt('0xec'), + parseInt('0xd8'), parseInt('0x43'), parseInt('0x1f'), parseInt('0x2d'), parseInt('0xa4'), parseInt('0x76'), parseInt('0x7b'), + parseInt('0xb7'), parseInt('0xcc'), parseInt('0xbb'), parseInt('0x3e'), parseInt('0x5a'), parseInt('0xfb'), parseInt('0x60'), + parseInt('0xb1'), parseInt('0x86'), parseInt('0x3b'), parseInt('0x52'), parseInt('0xa1'), parseInt('0x6c'), parseInt('0xaa'), + parseInt('0x55'), parseInt('0x29'), parseInt('0x9d'), parseInt('0x97'), parseInt('0xb2'), parseInt('0x87'), parseInt('0x90'), + parseInt('0x61'), parseInt('0xbe'), parseInt('0xdc'), parseInt('0xfc'), parseInt('0xbc'), parseInt('0x95'), parseInt('0xcf'), + parseInt('0xcd'), parseInt('0x37'), parseInt('0x3f'), parseInt('0x5b'), parseInt('0xd1'), parseInt('0x53'), parseInt('0x39'), + parseInt('0x84'), parseInt('0x3c'), parseInt('0x41'), parseInt('0xa2'), parseInt('0x6d'), parseInt('0x47'), parseInt('0x14'), + parseInt('0x2a'), parseInt('0x9e'), parseInt('0x5d'), parseInt('0x56'), parseInt('0xf2'), parseInt('0xd3'), parseInt('0xab'), + parseInt('0x44'), parseInt('0x11'), parseInt('0x92'), parseInt('0xd9'), parseInt('0x23'), parseInt('0x20'), parseInt('0x2e'), + parseInt('0x89'), parseInt('0xb4'), parseInt('0x7c'), parseInt('0xb8'), parseInt('0x26'), parseInt('0x77'), parseInt('0x99'), + parseInt('0xe3'), parseInt('0xa5'), parseInt('0x67'), parseInt('0x4a'), parseInt('0xed'), parseInt('0xde'), parseInt('0xc5'), + parseInt('0x31'), parseInt('0xfe'), parseInt('0x18'), parseInt('0x0d'), parseInt('0x63'), parseInt('0x8c'), parseInt('0x80'), + parseInt('0xc0'), parseInt('0xf7'), parseInt('0x70'), parseInt('0x07'), + ]); /* https://crypto.stackexchange.com/a/21174/13860 */ -const EXP = [ - parseInt("0x01"), parseInt("0x03"), parseInt("0x05"), parseInt("0x0f"), parseInt("0x11"), parseInt("0x33"), parseInt("0x55"), - parseInt("0xff"), parseInt("0x1a"), parseInt("0x2e"), parseInt("0x72"), parseInt("0x96"), parseInt("0xa1"), parseInt("0xf8"), - parseInt("0x13"), parseInt("0x35"), parseInt("0x5f"), parseInt("0xe1"), parseInt("0x38"), parseInt("0x48"), parseInt("0xd8"), - parseInt("0x73"), parseInt("0x95"), parseInt("0xa4"), parseInt("0xf7"), parseInt("0x02"), parseInt("0x06"), parseInt("0x0a"), - parseInt("0x1e"), parseInt("0x22"), parseInt("0x66"), parseInt("0xaa"), parseInt("0xe5"), parseInt("0x34"), parseInt("0x5c"), - parseInt("0xe4"), parseInt("0x37"), parseInt("0x59"), parseInt("0xeb"), parseInt("0x26"), parseInt("0x6a"), parseInt("0xbe"), - parseInt("0xd9"), parseInt("0x70"), parseInt("0x90"), parseInt("0xab"), parseInt("0xe6"), parseInt("0x31"), parseInt("0x53"), - parseInt("0xf5"), parseInt("0x04"), parseInt("0x0c"), parseInt("0x14"), parseInt("0x3c"), parseInt("0x44"), parseInt("0xcc"), - parseInt("0x4f"), parseInt("0xd1"), parseInt("0x68"), parseInt("0xb8"), parseInt("0xd3"), parseInt("0x6e"), parseInt("0xb2"), - parseInt("0xcd"), parseInt("0x4c"), parseInt("0xd4"), parseInt("0x67"), parseInt("0xa9"), parseInt("0xe0"), parseInt("0x3b"), - parseInt("0x4d"), parseInt("0xd7"), parseInt("0x62"), parseInt("0xa6"), parseInt("0xf1"), parseInt("0x08"), parseInt("0x18"), - parseInt("0x28"), parseInt("0x78"), parseInt("0x88"), parseInt("0x83"), parseInt("0x9e"), parseInt("0xb9"), parseInt("0xd0"), - parseInt("0x6b"), parseInt("0xbd"), parseInt("0xdc"), parseInt("0x7f"), parseInt("0x81"), parseInt("0x98"), parseInt("0xb3"), - parseInt("0xce"), parseInt("0x49"), parseInt("0xdb"), parseInt("0x76"), parseInt("0x9a"), parseInt("0xb5"), parseInt("0xc4"), - parseInt("0x57"), parseInt("0xf9"), parseInt("0x10"), parseInt("0x30"), parseInt("0x50"), parseInt("0xf0"), parseInt("0x0b"), - parseInt("0x1d"), parseInt("0x27"), parseInt("0x69"), parseInt("0xbb"), parseInt("0xd6"), parseInt("0x61"), parseInt("0xa3"), - parseInt("0xfe"), parseInt("0x19"), parseInt("0x2b"), parseInt("0x7d"), parseInt("0x87"), parseInt("0x92"), parseInt("0xad"), - parseInt("0xec"), parseInt("0x2f"), parseInt("0x71"), parseInt("0x93"), parseInt("0xae"), parseInt("0xe9"), parseInt("0x20"), - parseInt("0x60"), parseInt("0xa0"), parseInt("0xfb"), parseInt("0x16"), parseInt("0x3a"), parseInt("0x4e"), parseInt("0xd2"), - parseInt("0x6d"), parseInt("0xb7"), parseInt("0xc2"), parseInt("0x5d"), parseInt("0xe7"), parseInt("0x32"), parseInt("0x56"), - parseInt("0xfa"), parseInt("0x15"), parseInt("0x3f"), parseInt("0x41"), parseInt("0xc3"), parseInt("0x5e"), parseInt("0xe2"), - parseInt("0x3d"), parseInt("0x47"), parseInt("0xc9"), parseInt("0x40"), parseInt("0xc0"), parseInt("0x5b"), parseInt("0xed"), - parseInt("0x2c"), parseInt("0x74"), parseInt("0x9c"), parseInt("0xbf"), parseInt("0xda"), parseInt("0x75"), parseInt("0x9f"), - parseInt("0xba"), parseInt("0xd5"), parseInt("0x64"), parseInt("0xac"), parseInt("0xef"), parseInt("0x2a"), parseInt("0x7e"), - parseInt("0x82"), parseInt("0x9d"), parseInt("0xbc"), parseInt("0xdf"), parseInt("0x7a"), parseInt("0x8e"), parseInt("0x89"), - parseInt("0x80"), parseInt("0x9b"), parseInt("0xb6"), parseInt("0xc1"), parseInt("0x58"), parseInt("0xe8"), parseInt("0x23"), - parseInt("0x65"), parseInt("0xaf"), parseInt("0xea"), parseInt("0x25"), parseInt("0x6f"), parseInt("0xb1"), parseInt("0xc8"), - parseInt("0x43"), parseInt("0xc5"), parseInt("0x54"), parseInt("0xfc"), parseInt("0x1f"), parseInt("0x21"), parseInt("0x63"), - parseInt("0xa5"), parseInt("0xf4"), parseInt("0x07"), parseInt("0x09"), parseInt("0x1b"), parseInt("0x2d"), parseInt("0x77"), - parseInt("0x99"), parseInt("0xb0"), parseInt("0xcb"), parseInt("0x46"), parseInt("0xca"), parseInt("0x45"), parseInt("0xcf"), - parseInt("0x4a"), parseInt("0xde"), parseInt("0x79"), parseInt("0x8b"), parseInt("0x86"), parseInt("0x91"), parseInt("0xa8"), - parseInt("0xe3"), parseInt("0x3e"), parseInt("0x42"), parseInt("0xc6"), parseInt("0x51"), parseInt("0xf3"), parseInt("0x0e"), - parseInt("0x12"), parseInt("0x36"), parseInt("0x5a"), parseInt("0xee"), parseInt("0x29"), parseInt("0x7b"), parseInt("0x8d"), - parseInt("0x8c"), parseInt("0x8f"), parseInt("0x8a"), parseInt("0x85"), parseInt("0x94"), parseInt("0xa7"), parseInt("0xf2"), - parseInt("0x0d"), parseInt("0x17"), parseInt("0x39"), parseInt("0x4b"), parseInt("0xdd"), parseInt("0x7c"), parseInt("0x84"), - parseInt("0x97"), parseInt("0xa2"), parseInt("0xfd"), parseInt("0x1c"), parseInt("0x24"), parseInt("0x6c"), parseInt("0xb4"), - parseInt("0xc7"), parseInt("0x52"), parseInt("0xf6"), parseInt("0x01"), parseInt("0x03"), parseInt("0x05"), parseInt("0x0f"), - parseInt("0x11"), parseInt("0x33"), parseInt("0x55"), parseInt("0xff"), parseInt("0x1a"), parseInt("0x2e"), parseInt("0x72"), - parseInt("0x96"), parseInt("0xa1"), parseInt("0xf8"), parseInt("0x13"), parseInt("0x35"), parseInt("0x5f"), parseInt("0xe1"), - parseInt("0x38"), parseInt("0x48"), parseInt("0xd8"), parseInt("0x73"), parseInt("0x95"), parseInt("0xa4"), parseInt("0xf7"), - parseInt("0x02"), parseInt("0x06"), parseInt("0x0a"), parseInt("0x1e"), parseInt("0x22"), parseInt("0x66"), parseInt("0xaa"), - parseInt("0xe5"), parseInt("0x34"), parseInt("0x5c"), parseInt("0xe4"), parseInt("0x37"), parseInt("0x59"), parseInt("0xeb"), - parseInt("0x26"), parseInt("0x6a"), parseInt("0xbe"), parseInt("0xd9"), parseInt("0x70"), parseInt("0x90"), parseInt("0xab"), - parseInt("0xe6"), parseInt("0x31"), parseInt("0x53"), parseInt("0xf5"), parseInt("0x04"), parseInt("0x0c"), parseInt("0x14"), - parseInt("0x3c"), parseInt("0x44"), parseInt("0xcc"), parseInt("0x4f"), parseInt("0xd1"), parseInt("0x68"), parseInt("0xb8"), - parseInt("0xd3"), parseInt("0x6e"), parseInt("0xb2"), parseInt("0xcd"), parseInt("0x4c"), parseInt("0xd4"), parseInt("0x67"), - parseInt("0xa9"), parseInt("0xe0"), parseInt("0x3b"), parseInt("0x4d"), parseInt("0xd7"), parseInt("0x62"), parseInt("0xa6"), - parseInt("0xf1"), parseInt("0x08"), parseInt("0x18"), parseInt("0x28"), parseInt("0x78"), parseInt("0x88"), parseInt("0x83"), - parseInt("0x9e"), parseInt("0xb9"), parseInt("0xd0"), parseInt("0x6b"), parseInt("0xbd"), parseInt("0xdc"), parseInt("0x7f"), - parseInt("0x81"), parseInt("0x98"), parseInt("0xb3"), parseInt("0xce"), parseInt("0x49"), parseInt("0xdb"), parseInt("0x76"), - parseInt("0x9a"), parseInt("0xb5"), parseInt("0xc4"), parseInt("0x57"), parseInt("0xf9"), parseInt("0x10"), parseInt("0x30"), - parseInt("0x50"), parseInt("0xf0"), parseInt("0x0b"), parseInt("0x1d"), parseInt("0x27"), parseInt("0x69"), parseInt("0xbb"), - parseInt("0xd6"), parseInt("0x61"), parseInt("0xa3"), parseInt("0xfe"), parseInt("0x19"), parseInt("0x2b"), parseInt("0x7d"), - parseInt("0x87"), parseInt("0x92"), parseInt("0xad"), parseInt("0xec"), parseInt("0x2f"), parseInt("0x71"), parseInt("0x93"), - parseInt("0xae"), parseInt("0xe9"), parseInt("0x20"), parseInt("0x60"), parseInt("0xa0"), parseInt("0xfb"), parseInt("0x16"), - parseInt("0x3a"), parseInt("0x4e"), parseInt("0xd2"), parseInt("0x6d"), parseInt("0xb7"), parseInt("0xc2"), parseInt("0x5d"), - parseInt("0xe7"), parseInt("0x32"), parseInt("0x56"), parseInt("0xfa"), parseInt("0x15"), parseInt("0x3f"), parseInt("0x41"), - parseInt("0xc3"), parseInt("0x5e"), parseInt("0xe2"), parseInt("0x3d"), parseInt("0x47"), parseInt("0xc9"), parseInt("0x40"), - parseInt("0xc0"), parseInt("0x5b"), parseInt("0xed"), parseInt("0x2c"), parseInt("0x74"), parseInt("0x9c"), parseInt("0xbf"), - parseInt("0xda"), parseInt("0x75"), parseInt("0x9f"), parseInt("0xba"), parseInt("0xd5"), parseInt("0x64"), parseInt("0xac"), - parseInt("0xef"), parseInt("0x2a"), parseInt("0x7e"), parseInt("0x82"), parseInt("0x9d"), parseInt("0xbc"), parseInt("0xdf"), - parseInt("0x7a"), parseInt("0x8e"), parseInt("0x89"), parseInt("0x80"), parseInt("0x9b"), parseInt("0xb6"), parseInt("0xc1"), - parseInt("0x58"), parseInt("0xe8"), parseInt("0x23"), parseInt("0x65"), parseInt("0xaf"), parseInt("0xea"), parseInt("0x25"), - parseInt("0x6f"), parseInt("0xb1"), parseInt("0xc8"), parseInt("0x43"), parseInt("0xc5"), parseInt("0x54"), parseInt("0xfc"), - parseInt("0x1f"), parseInt("0x21"), parseInt("0x63"), parseInt("0xa5"), parseInt("0xf4"), parseInt("0x07"), parseInt("0x09"), - parseInt("0x1b"), parseInt("0x2d"), parseInt("0x77"), parseInt("0x99"), parseInt("0xb0"), parseInt("0xcb"), parseInt("0x46"), - parseInt("0xca"), parseInt("0x45"), parseInt("0xcf"), parseInt("0x4a"), parseInt("0xde"), parseInt("0x79"), parseInt("0x8b"), - parseInt("0x86"), parseInt("0x91"), parseInt("0xa8"), parseInt("0xe3"), parseInt("0x3e"), parseInt("0x42"), parseInt("0xc6"), - parseInt("0x51"), parseInt("0xf3"), parseInt("0x0e"), parseInt("0x12"), parseInt("0x36"), parseInt("0x5a"), parseInt("0xee"), - parseInt("0x29"), parseInt("0x7b"), parseInt("0x8d"), parseInt("0x8c"), parseInt("0x8f"), parseInt("0x8a"), parseInt("0x85"), - parseInt("0x94"), parseInt("0xa7"), parseInt("0xf2"), parseInt("0x0d"), parseInt("0x17"), parseInt("0x39"), parseInt("0x4b"), - parseInt("0xdd"), parseInt("0x7c"), parseInt("0x84"), parseInt("0x97"), parseInt("0xa2"), parseInt("0xfd"), parseInt("0x1c"), - parseInt("0x24"), parseInt("0x6c"), parseInt("0xb4"), parseInt("0xc7"), parseInt("0x52"), parseInt("0xf6"), - ]; +const EXP = new Uint8Array([ + parseInt('0x01'), parseInt('0x03'), parseInt('0x05'), parseInt('0x0f'), parseInt('0x11'), parseInt('0x33'), parseInt('0x55'), + parseInt('0xff'), parseInt('0x1a'), parseInt('0x2e'), parseInt('0x72'), parseInt('0x96'), parseInt('0xa1'), parseInt('0xf8'), + parseInt('0x13'), parseInt('0x35'), parseInt('0x5f'), parseInt('0xe1'), parseInt('0x38'), parseInt('0x48'), parseInt('0xd8'), + parseInt('0x73'), parseInt('0x95'), parseInt('0xa4'), parseInt('0xf7'), parseInt('0x02'), parseInt('0x06'), parseInt('0x0a'), + parseInt('0x1e'), parseInt('0x22'), parseInt('0x66'), parseInt('0xaa'), parseInt('0xe5'), parseInt('0x34'), parseInt('0x5c'), + parseInt('0xe4'), parseInt('0x37'), parseInt('0x59'), parseInt('0xeb'), parseInt('0x26'), parseInt('0x6a'), parseInt('0xbe'), + parseInt('0xd9'), parseInt('0x70'), parseInt('0x90'), parseInt('0xab'), parseInt('0xe6'), parseInt('0x31'), parseInt('0x53'), + parseInt('0xf5'), parseInt('0x04'), parseInt('0x0c'), parseInt('0x14'), parseInt('0x3c'), parseInt('0x44'), parseInt('0xcc'), + parseInt('0x4f'), parseInt('0xd1'), parseInt('0x68'), parseInt('0xb8'), parseInt('0xd3'), parseInt('0x6e'), parseInt('0xb2'), + parseInt('0xcd'), parseInt('0x4c'), parseInt('0xd4'), parseInt('0x67'), parseInt('0xa9'), parseInt('0xe0'), parseInt('0x3b'), + parseInt('0x4d'), parseInt('0xd7'), parseInt('0x62'), parseInt('0xa6'), parseInt('0xf1'), parseInt('0x08'), parseInt('0x18'), + parseInt('0x28'), parseInt('0x78'), parseInt('0x88'), parseInt('0x83'), parseInt('0x9e'), parseInt('0xb9'), parseInt('0xd0'), + parseInt('0x6b'), parseInt('0xbd'), parseInt('0xdc'), parseInt('0x7f'), parseInt('0x81'), parseInt('0x98'), parseInt('0xb3'), + parseInt('0xce'), parseInt('0x49'), parseInt('0xdb'), parseInt('0x76'), parseInt('0x9a'), parseInt('0xb5'), parseInt('0xc4'), + parseInt('0x57'), parseInt('0xf9'), parseInt('0x10'), parseInt('0x30'), parseInt('0x50'), parseInt('0xf0'), parseInt('0x0b'), + parseInt('0x1d'), parseInt('0x27'), parseInt('0x69'), parseInt('0xbb'), parseInt('0xd6'), parseInt('0x61'), parseInt('0xa3'), + parseInt('0xfe'), parseInt('0x19'), parseInt('0x2b'), parseInt('0x7d'), parseInt('0x87'), parseInt('0x92'), parseInt('0xad'), + parseInt('0xec'), parseInt('0x2f'), parseInt('0x71'), parseInt('0x93'), parseInt('0xae'), parseInt('0xe9'), parseInt('0x20'), + parseInt('0x60'), parseInt('0xa0'), parseInt('0xfb'), parseInt('0x16'), parseInt('0x3a'), parseInt('0x4e'), parseInt('0xd2'), + parseInt('0x6d'), parseInt('0xb7'), parseInt('0xc2'), parseInt('0x5d'), parseInt('0xe7'), parseInt('0x32'), parseInt('0x56'), + parseInt('0xfa'), parseInt('0x15'), parseInt('0x3f'), parseInt('0x41'), parseInt('0xc3'), parseInt('0x5e'), parseInt('0xe2'), + parseInt('0x3d'), parseInt('0x47'), parseInt('0xc9'), parseInt('0x40'), parseInt('0xc0'), parseInt('0x5b'), parseInt('0xed'), + parseInt('0x2c'), parseInt('0x74'), parseInt('0x9c'), parseInt('0xbf'), parseInt('0xda'), parseInt('0x75'), parseInt('0x9f'), + parseInt('0xba'), parseInt('0xd5'), parseInt('0x64'), parseInt('0xac'), parseInt('0xef'), parseInt('0x2a'), parseInt('0x7e'), + parseInt('0x82'), parseInt('0x9d'), parseInt('0xbc'), parseInt('0xdf'), parseInt('0x7a'), parseInt('0x8e'), parseInt('0x89'), + parseInt('0x80'), parseInt('0x9b'), parseInt('0xb6'), parseInt('0xc1'), parseInt('0x58'), parseInt('0xe8'), parseInt('0x23'), + parseInt('0x65'), parseInt('0xaf'), parseInt('0xea'), parseInt('0x25'), parseInt('0x6f'), parseInt('0xb1'), parseInt('0xc8'), + parseInt('0x43'), parseInt('0xc5'), parseInt('0x54'), parseInt('0xfc'), parseInt('0x1f'), parseInt('0x21'), parseInt('0x63'), + parseInt('0xa5'), parseInt('0xf4'), parseInt('0x07'), parseInt('0x09'), parseInt('0x1b'), parseInt('0x2d'), parseInt('0x77'), + parseInt('0x99'), parseInt('0xb0'), parseInt('0xcb'), parseInt('0x46'), parseInt('0xca'), parseInt('0x45'), parseInt('0xcf'), + parseInt('0x4a'), parseInt('0xde'), parseInt('0x79'), parseInt('0x8b'), parseInt('0x86'), parseInt('0x91'), parseInt('0xa8'), + parseInt('0xe3'), parseInt('0x3e'), parseInt('0x42'), parseInt('0xc6'), parseInt('0x51'), parseInt('0xf3'), parseInt('0x0e'), + parseInt('0x12'), parseInt('0x36'), parseInt('0x5a'), parseInt('0xee'), parseInt('0x29'), parseInt('0x7b'), parseInt('0x8d'), + parseInt('0x8c'), parseInt('0x8f'), parseInt('0x8a'), parseInt('0x85'), parseInt('0x94'), parseInt('0xa7'), parseInt('0xf2'), + parseInt('0x0d'), parseInt('0x17'), parseInt('0x39'), parseInt('0x4b'), parseInt('0xdd'), parseInt('0x7c'), parseInt('0x84'), + parseInt('0x97'), parseInt('0xa2'), parseInt('0xfd'), parseInt('0x1c'), parseInt('0x24'), parseInt('0x6c'), parseInt('0xb4'), + parseInt('0xc7'), parseInt('0x52'), parseInt('0xf6'), parseInt('0x01'), parseInt('0x03'), parseInt('0x05'), parseInt('0x0f'), + parseInt('0x11'), parseInt('0x33'), parseInt('0x55'), parseInt('0xff'), parseInt('0x1a'), parseInt('0x2e'), parseInt('0x72'), + parseInt('0x96'), parseInt('0xa1'), parseInt('0xf8'), parseInt('0x13'), parseInt('0x35'), parseInt('0x5f'), parseInt('0xe1'), + parseInt('0x38'), parseInt('0x48'), parseInt('0xd8'), parseInt('0x73'), parseInt('0x95'), parseInt('0xa4'), parseInt('0xf7'), + parseInt('0x02'), parseInt('0x06'), parseInt('0x0a'), parseInt('0x1e'), parseInt('0x22'), parseInt('0x66'), parseInt('0xaa'), + parseInt('0xe5'), parseInt('0x34'), parseInt('0x5c'), parseInt('0xe4'), parseInt('0x37'), parseInt('0x59'), parseInt('0xeb'), + parseInt('0x26'), parseInt('0x6a'), parseInt('0xbe'), parseInt('0xd9'), parseInt('0x70'), parseInt('0x90'), parseInt('0xab'), + parseInt('0xe6'), parseInt('0x31'), parseInt('0x53'), parseInt('0xf5'), parseInt('0x04'), parseInt('0x0c'), parseInt('0x14'), + parseInt('0x3c'), parseInt('0x44'), parseInt('0xcc'), parseInt('0x4f'), parseInt('0xd1'), parseInt('0x68'), parseInt('0xb8'), + parseInt('0xd3'), parseInt('0x6e'), parseInt('0xb2'), parseInt('0xcd'), parseInt('0x4c'), parseInt('0xd4'), parseInt('0x67'), + parseInt('0xa9'), parseInt('0xe0'), parseInt('0x3b'), parseInt('0x4d'), parseInt('0xd7'), parseInt('0x62'), parseInt('0xa6'), + parseInt('0xf1'), parseInt('0x08'), parseInt('0x18'), parseInt('0x28'), parseInt('0x78'), parseInt('0x88'), parseInt('0x83'), + parseInt('0x9e'), parseInt('0xb9'), parseInt('0xd0'), parseInt('0x6b'), parseInt('0xbd'), parseInt('0xdc'), parseInt('0x7f'), + parseInt('0x81'), parseInt('0x98'), parseInt('0xb3'), parseInt('0xce'), parseInt('0x49'), parseInt('0xdb'), parseInt('0x76'), + parseInt('0x9a'), parseInt('0xb5'), parseInt('0xc4'), parseInt('0x57'), parseInt('0xf9'), parseInt('0x10'), parseInt('0x30'), + parseInt('0x50'), parseInt('0xf0'), parseInt('0x0b'), parseInt('0x1d'), parseInt('0x27'), parseInt('0x69'), parseInt('0xbb'), + parseInt('0xd6'), parseInt('0x61'), parseInt('0xa3'), parseInt('0xfe'), parseInt('0x19'), parseInt('0x2b'), parseInt('0x7d'), + parseInt('0x87'), parseInt('0x92'), parseInt('0xad'), parseInt('0xec'), parseInt('0x2f'), parseInt('0x71'), parseInt('0x93'), + parseInt('0xae'), parseInt('0xe9'), parseInt('0x20'), parseInt('0x60'), parseInt('0xa0'), parseInt('0xfb'), parseInt('0x16'), + parseInt('0x3a'), parseInt('0x4e'), parseInt('0xd2'), parseInt('0x6d'), parseInt('0xb7'), parseInt('0xc2'), parseInt('0x5d'), + parseInt('0xe7'), parseInt('0x32'), parseInt('0x56'), parseInt('0xfa'), parseInt('0x15'), parseInt('0x3f'), parseInt('0x41'), + parseInt('0xc3'), parseInt('0x5e'), parseInt('0xe2'), parseInt('0x3d'), parseInt('0x47'), parseInt('0xc9'), parseInt('0x40'), + parseInt('0xc0'), parseInt('0x5b'), parseInt('0xed'), parseInt('0x2c'), parseInt('0x74'), parseInt('0x9c'), parseInt('0xbf'), + parseInt('0xda'), parseInt('0x75'), parseInt('0x9f'), parseInt('0xba'), parseInt('0xd5'), parseInt('0x64'), parseInt('0xac'), + parseInt('0xef'), parseInt('0x2a'), parseInt('0x7e'), parseInt('0x82'), parseInt('0x9d'), parseInt('0xbc'), parseInt('0xdf'), + parseInt('0x7a'), parseInt('0x8e'), parseInt('0x89'), parseInt('0x80'), parseInt('0x9b'), parseInt('0xb6'), parseInt('0xc1'), + parseInt('0x58'), parseInt('0xe8'), parseInt('0x23'), parseInt('0x65'), parseInt('0xaf'), parseInt('0xea'), parseInt('0x25'), + parseInt('0x6f'), parseInt('0xb1'), parseInt('0xc8'), parseInt('0x43'), parseInt('0xc5'), parseInt('0x54'), parseInt('0xfc'), + parseInt('0x1f'), parseInt('0x21'), parseInt('0x63'), parseInt('0xa5'), parseInt('0xf4'), parseInt('0x07'), parseInt('0x09'), + parseInt('0x1b'), parseInt('0x2d'), parseInt('0x77'), parseInt('0x99'), parseInt('0xb0'), parseInt('0xcb'), parseInt('0x46'), + parseInt('0xca'), parseInt('0x45'), parseInt('0xcf'), parseInt('0x4a'), parseInt('0xde'), parseInt('0x79'), parseInt('0x8b'), + parseInt('0x86'), parseInt('0x91'), parseInt('0xa8'), parseInt('0xe3'), parseInt('0x3e'), parseInt('0x42'), parseInt('0xc6'), + parseInt('0x51'), parseInt('0xf3'), parseInt('0x0e'), parseInt('0x12'), parseInt('0x36'), parseInt('0x5a'), parseInt('0xee'), + parseInt('0x29'), parseInt('0x7b'), parseInt('0x8d'), parseInt('0x8c'), parseInt('0x8f'), parseInt('0x8a'), parseInt('0x85'), + parseInt('0x94'), parseInt('0xa7'), parseInt('0xf2'), parseInt('0x0d'), parseInt('0x17'), parseInt('0x39'), parseInt('0x4b'), + parseInt('0xdd'), parseInt('0x7c'), parseInt('0x84'), parseInt('0x97'), parseInt('0xa2'), parseInt('0xfd'), parseInt('0x1c'), + parseInt('0x24'), parseInt('0x6c'), parseInt('0xb4'), parseInt('0xc7'), parseInt('0x52'), parseInt('0xf6'), + ]); const mul = function(a, b) { - if (a == 0 || b == 0) { - return 0; - } - return EXP[LOG[a] + LOG[b]]; + if (a == 0 || b == 0) { + return 0; + } + return EXP[LOG[a] + LOG[b]]; }; exports.mul = mul; const div = function(a, b) { - // multiply by the inverse of b - return mul(a, EXP[255 - LOG[b]]); + // multiply by the inverse of b + return mul(a, EXP[255 - LOG[b]]); }; exports.div = div; const degree = function(p) { - for (var i = p.length - 1; i >= 1; i--) { - if (p[i] != 0) { - return i; - } + for (let i = p.length - 1; i >= 1; i--) { + if (p[i] != 0) { + return i; } - return 0; + } + return 0; }; exports.degree = degree; /** - * Calculates f(0) of the given points using Lagrangian interpolation. - * @param {array[Uint8Array]} points The supplied point. + * Calculates f(0) of the given points using Lagrangian interpolation. + * @param {array[Uint8Array]} points The supplied point. */ exports.interpolate = function(points) { - const x = 0; - var y = 0; - for (var i = 0; i < points.length; i++) { - const aX = points[i][0]; - const aY = points[i][1]; - var li = 1; - for (var j = 0; j < points.length; j++) { - const bX = points[j][0]; - if (i != j) { - li = mul(li, div(sub(x, bX), sub(aX, bX))); - } + const x = 0; + let y = 0; + for (let i = 0; i < points.length; i++) { + const aX = points[i][0]; + const aY = points[i][1]; + let li = 1; + for (let j = 0; j < points.length; j++) { + const bX = points[j][0]; + if (i != j) { + li = mul(li, div(sub(x, bX), sub(aX, bX))); } - y = add(y, mul(li, aY)); } - return y; + y = add(y, mul(li, aY)); } + return y; +}; /** - * Generates a random polynomal of the correct degree and sets x as the first coefficient. + * Generates a random polynomal of the correct degree and sets x as the first coefficient. * @param {function int -> array[Uint8Array]} randomBytes Takes a length and returns a Uint8Array of that length. - * @param {Number} d The degree of the polynomial driven by the number shares and join threshold. + * @param {Number} d The degree of the polynomial driven by the number shares and join threshold. * @param {Number} x The point to hide. * @return {Uint8Array} The random polynomial with x as the fist coefficient. */ -exports.generate = function(randomBytes, d, x){ - var p = null; - // generate random polynomials until we find one of the given degree - do { - p = randomBytes(d + 1); - } while (degree(p) != d); +exports.generate = function(randomBytes, d, x) { + let p = null; + // generate random polynomials until we find one of the given degree + do { + p = randomBytes(d + 1); + } while (degree(p) != d); - // set y intercept - p[0] = x; - - return p; - } + // set y intercept + p[0] = x; + return p; +}; /** - * Evaluates a polynomal at point x using Horner's method. + * Evaluates a polynomal at point x using Horner's method. * @param {Uint8Array} p The polynomial * @return {Number} x The point to evaluate. */ -exports.eval = function(p, x){ - var result = 0 - for( var i = p.length -1; i >=0; i--){ - result = add(mul(result, x), p[i]); - } - return result; +exports.eval = function(p, x) { + let result = 0; + for (let i = p.length - 1; i >= 0; i--) { + result = add(mul(result, x), p[i]); } + return result; +}; diff --git a/src/main/js/Scheme.js b/src/main/js/Scheme.js index ce0e3e5..c871dec 100644 --- a/src/main/js/Scheme.js +++ b/src/main/js/Scheme.js @@ -14,8 +14,6 @@ * limitations under the License. */ -"use strict"; - const GF256 = require('./GF256.js'); /** @@ -27,23 +25,25 @@ const GF256 = require('./GF256.js'); * @param {array[Uint8Array]} secret The secret to split as an array of bytes * @return {Object.} an map of {@code n} parts that are arrays of bytes of the secret length */ -exports.split = function (randomBytes, n, k, secret) { - if (k <= 1) throw "K must be > 1"; - if (n < k) throw "N must be >= K"; - if (n > 255) throw "N must be <= 255"; - - const values = new Array(n).fill(0).map(() => new Uint8Array(secret.length).fill(0)); - for ( var i = 0; i < secret.length; i++ ){ +exports.split = function(randomBytes, n, k, secret) { + if (k <= 1) throw 'K must be > 1'; + if (n < k) throw 'N must be >= K'; + if (n > 255) throw 'N must be <= 255'; + + const values = new Array(n) + .fill(0) + .map(() => new Uint8Array(secret.length).fill(0)); + for (let i = 0; i < secret.length; i++) { const p = GF256.generate(randomBytes, k - 1, secret[i]); - for ( var x = 1; x <= n; x++ ) { - values[x-1][i] = GF256.eval(p, x); + for (let x = 1; x <= n; x++) { + values[x - 1][i] = GF256.eval(p, x); } } - + const parts = {}; - for (var i = 0; i < values.length; i++) { - var part = ""+(i+1); + for (let i = 0; i < values.length; i++) { + const part = `${i + 1}`; parts[part] = values[i]; } @@ -51,33 +51,36 @@ exports.split = function (randomBytes, n, k, secret) { }; /** - * Joins the given parts to recover the original secret. - * - *

N.B.: There is no way to determine whether or not the returned value is actually the - * original secret. If the parts are incorrect, or are under the threshold value used to split the - * secret, a random value will be returned. - * - * @param {Object.} parts an map of {@code n} parts that are arrays of bytes of the secret length - * @return {Uint8Array} the original secret - * + * Joins the given parts to recover the original secret. + * + *

N.B.: There is no way to determine whether or not the returned value is actually the + * original secret. If the parts are incorrect, or are under the threshold value used to split the + * secret, a random value will be returned. + * + * @param {Object.} parts an map of {@code n} parts that are arrays of bytes of the secret length + * @return {Uint8Array} the original secret + * */ -exports.join = function(parts){ - if( Object.keys(parts).length == 0 ) throw "No parts provided" +exports.join = function(parts) { + if (Object.keys(parts).length == 0) throw 'No parts provided'; const lengths = Object.values(parts).map(x => x.length); - const max = Math.max.apply(null, lengths) - const min = Math.min.apply(null, lengths) - if( max != min ) throw `Varying lengths of part values. Min ${min}, Max ${max}` + const max = Math.max.apply(null, lengths); + const min = Math.min.apply(null, lengths); + if (max != min) + throw `Varying lengths of part values. Min ${min}, Max ${max}`; const secret = new Uint8Array(max); - for( var i = 0; i < secret.length; i++){ + for (let i = 0; i < secret.length; i++) { const keys = Object.keys(parts); - const points = new Array(keys.length).fill(0).map(() => new Uint8Array(2).fill(0)); - for( var j = 0; j < keys.length; j++) { + const points = new Array(keys.length) + .fill(0) + .map(() => new Uint8Array(2).fill(0)); + for (let j = 0; j < keys.length; j++) { const key = keys[j]; const k = Number(key); points[j][0] = k; points[j][1] = parts[key][i]; } - secret[i] = GF256.interpolate(points); + secret[i] = GF256.interpolate(points); } return secret; From 2a4170d167ceeb6e4281a53997384e8f2b69a207 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 19:58:53 +0100 Subject: [PATCH 40/78] fix eslint parseInt radix warnings --- src/main/js/GF256.js | 220 +++++++++++++++++++++---------------------- 1 file changed, 110 insertions(+), 110 deletions(-) diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index 6124e3d..9eb0bf7 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -30,121 +30,121 @@ const sub = add; exports.sub = exports.add; const LOG = new Uint8Array([ - parseInt('0xff'), parseInt('0x00'), parseInt('0x19'), parseInt('0x01'), parseInt('0x32'), parseInt('0x02'), parseInt('0x1a'), - parseInt('0xc6'), parseInt('0x4b'), parseInt('0xc7'), parseInt('0x1b'), parseInt('0x68'), parseInt('0x33'), parseInt('0xee'), - parseInt('0xdf'), parseInt('0x03'), parseInt('0x64'), parseInt('0x04'), parseInt('0xe0'), parseInt('0x0e'), parseInt('0x34'), - parseInt('0x8d'), parseInt('0x81'), parseInt('0xef'), parseInt('0x4c'), parseInt('0x71'), parseInt('0x08'), parseInt('0xc8'), - parseInt('0xf8'), parseInt('0x69'), parseInt('0x1c'), parseInt('0xc1'), parseInt('0x7d'), parseInt('0xc2'), parseInt('0x1d'), - parseInt('0xb5'), parseInt('0xf9'), parseInt('0xb9'), parseInt('0x27'), parseInt('0x6a'), parseInt('0x4d'), parseInt('0xe4'), - parseInt('0xa6'), parseInt('0x72'), parseInt('0x9a'), parseInt('0xc9'), parseInt('0x09'), parseInt('0x78'), parseInt('0x65'), - parseInt('0x2f'), parseInt('0x8a'), parseInt('0x05'), parseInt('0x21'), parseInt('0x0f'), parseInt('0xe1'), parseInt('0x24'), - parseInt('0x12'), parseInt('0xf0'), parseInt('0x82'), parseInt('0x45'), parseInt('0x35'), parseInt('0x93'), parseInt('0xda'), - parseInt('0x8e'), parseInt('0x96'), parseInt('0x8f'), parseInt('0xdb'), parseInt('0xbd'), parseInt('0x36'), parseInt('0xd0'), - parseInt('0xce'), parseInt('0x94'), parseInt('0x13'), parseInt('0x5c'), parseInt('0xd2'), parseInt('0xf1'), parseInt('0x40'), - parseInt('0x46'), parseInt('0x83'), parseInt('0x38'), parseInt('0x66'), parseInt('0xdd'), parseInt('0xfd'), parseInt('0x30'), - parseInt('0xbf'), parseInt('0x06'), parseInt('0x8b'), parseInt('0x62'), parseInt('0xb3'), parseInt('0x25'), parseInt('0xe2'), - parseInt('0x98'), parseInt('0x22'), parseInt('0x88'), parseInt('0x91'), parseInt('0x10'), parseInt('0x7e'), parseInt('0x6e'), - parseInt('0x48'), parseInt('0xc3'), parseInt('0xa3'), parseInt('0xb6'), parseInt('0x1e'), parseInt('0x42'), parseInt('0x3a'), - parseInt('0x6b'), parseInt('0x28'), parseInt('0x54'), parseInt('0xfa'), parseInt('0x85'), parseInt('0x3d'), parseInt('0xba'), - parseInt('0x2b'), parseInt('0x79'), parseInt('0x0a'), parseInt('0x15'), parseInt('0x9b'), parseInt('0x9f'), parseInt('0x5e'), - parseInt('0xca'), parseInt('0x4e'), parseInt('0xd4'), parseInt('0xac'), parseInt('0xe5'), parseInt('0xf3'), parseInt('0x73'), - parseInt('0xa7'), parseInt('0x57'), parseInt('0xaf'), parseInt('0x58'), parseInt('0xa8'), parseInt('0x50'), parseInt('0xf4'), - parseInt('0xea'), parseInt('0xd6'), parseInt('0x74'), parseInt('0x4f'), parseInt('0xae'), parseInt('0xe9'), parseInt('0xd5'), - parseInt('0xe7'), parseInt('0xe6'), parseInt('0xad'), parseInt('0xe8'), parseInt('0x2c'), parseInt('0xd7'), parseInt('0x75'), - parseInt('0x7a'), parseInt('0xeb'), parseInt('0x16'), parseInt('0x0b'), parseInt('0xf5'), parseInt('0x59'), parseInt('0xcb'), - parseInt('0x5f'), parseInt('0xb0'), parseInt('0x9c'), parseInt('0xa9'), parseInt('0x51'), parseInt('0xa0'), parseInt('0x7f'), - parseInt('0x0c'), parseInt('0xf6'), parseInt('0x6f'), parseInt('0x17'), parseInt('0xc4'), parseInt('0x49'), parseInt('0xec'), - parseInt('0xd8'), parseInt('0x43'), parseInt('0x1f'), parseInt('0x2d'), parseInt('0xa4'), parseInt('0x76'), parseInt('0x7b'), - parseInt('0xb7'), parseInt('0xcc'), parseInt('0xbb'), parseInt('0x3e'), parseInt('0x5a'), parseInt('0xfb'), parseInt('0x60'), - parseInt('0xb1'), parseInt('0x86'), parseInt('0x3b'), parseInt('0x52'), parseInt('0xa1'), parseInt('0x6c'), parseInt('0xaa'), - parseInt('0x55'), parseInt('0x29'), parseInt('0x9d'), parseInt('0x97'), parseInt('0xb2'), parseInt('0x87'), parseInt('0x90'), - parseInt('0x61'), parseInt('0xbe'), parseInt('0xdc'), parseInt('0xfc'), parseInt('0xbc'), parseInt('0x95'), parseInt('0xcf'), - parseInt('0xcd'), parseInt('0x37'), parseInt('0x3f'), parseInt('0x5b'), parseInt('0xd1'), parseInt('0x53'), parseInt('0x39'), - parseInt('0x84'), parseInt('0x3c'), parseInt('0x41'), parseInt('0xa2'), parseInt('0x6d'), parseInt('0x47'), parseInt('0x14'), - parseInt('0x2a'), parseInt('0x9e'), parseInt('0x5d'), parseInt('0x56'), parseInt('0xf2'), parseInt('0xd3'), parseInt('0xab'), - parseInt('0x44'), parseInt('0x11'), parseInt('0x92'), parseInt('0xd9'), parseInt('0x23'), parseInt('0x20'), parseInt('0x2e'), - parseInt('0x89'), parseInt('0xb4'), parseInt('0x7c'), parseInt('0xb8'), parseInt('0x26'), parseInt('0x77'), parseInt('0x99'), - parseInt('0xe3'), parseInt('0xa5'), parseInt('0x67'), parseInt('0x4a'), parseInt('0xed'), parseInt('0xde'), parseInt('0xc5'), - parseInt('0x31'), parseInt('0xfe'), parseInt('0x18'), parseInt('0x0d'), parseInt('0x63'), parseInt('0x8c'), parseInt('0x80'), - parseInt('0xc0'), parseInt('0xf7'), parseInt('0x70'), parseInt('0x07'), + parseInt('0xff', 16), parseInt('0x00', 16), parseInt('0x19', 16), parseInt('0x01', 16), parseInt('0x32', 16), parseInt('0x02', 16), parseInt('0x1a', 16), + parseInt('0xc6', 16), parseInt('0x4b', 16), parseInt('0xc7', 16), parseInt('0x1b', 16), parseInt('0x68', 16), parseInt('0x33', 16), parseInt('0xee', 16), + parseInt('0xdf', 16), parseInt('0x03', 16), parseInt('0x64', 16), parseInt('0x04', 16), parseInt('0xe0', 16), parseInt('0x0e', 16), parseInt('0x34', 16), + parseInt('0x8d', 16), parseInt('0x81', 16), parseInt('0xef', 16), parseInt('0x4c', 16), parseInt('0x71', 16), parseInt('0x08', 16), parseInt('0xc8', 16), + parseInt('0xf8', 16), parseInt('0x69', 16), parseInt('0x1c', 16), parseInt('0xc1', 16), parseInt('0x7d', 16), parseInt('0xc2', 16), parseInt('0x1d', 16), + parseInt('0xb5', 16), parseInt('0xf9', 16), parseInt('0xb9', 16), parseInt('0x27', 16), parseInt('0x6a', 16), parseInt('0x4d', 16), parseInt('0xe4', 16), + parseInt('0xa6', 16), parseInt('0x72', 16), parseInt('0x9a', 16), parseInt('0xc9', 16), parseInt('0x09', 16), parseInt('0x78', 16), parseInt('0x65', 16), + parseInt('0x2f', 16), parseInt('0x8a', 16), parseInt('0x05', 16), parseInt('0x21', 16), parseInt('0x0f', 16), parseInt('0xe1', 16), parseInt('0x24', 16), + parseInt('0x12', 16), parseInt('0xf0', 16), parseInt('0x82', 16), parseInt('0x45', 16), parseInt('0x35', 16), parseInt('0x93', 16), parseInt('0xda', 16), + parseInt('0x8e', 16), parseInt('0x96', 16), parseInt('0x8f', 16), parseInt('0xdb', 16), parseInt('0xbd', 16), parseInt('0x36', 16), parseInt('0xd0', 16), + parseInt('0xce', 16), parseInt('0x94', 16), parseInt('0x13', 16), parseInt('0x5c', 16), parseInt('0xd2', 16), parseInt('0xf1', 16), parseInt('0x40', 16), + parseInt('0x46', 16), parseInt('0x83', 16), parseInt('0x38', 16), parseInt('0x66', 16), parseInt('0xdd', 16), parseInt('0xfd', 16), parseInt('0x30', 16), + parseInt('0xbf', 16), parseInt('0x06', 16), parseInt('0x8b', 16), parseInt('0x62', 16), parseInt('0xb3', 16), parseInt('0x25', 16), parseInt('0xe2', 16), + parseInt('0x98', 16), parseInt('0x22', 16), parseInt('0x88', 16), parseInt('0x91', 16), parseInt('0x10', 16), parseInt('0x7e', 16), parseInt('0x6e', 16), + parseInt('0x48', 16), parseInt('0xc3', 16), parseInt('0xa3', 16), parseInt('0xb6', 16), parseInt('0x1e', 16), parseInt('0x42', 16), parseInt('0x3a', 16), + parseInt('0x6b', 16), parseInt('0x28', 16), parseInt('0x54', 16), parseInt('0xfa', 16), parseInt('0x85', 16), parseInt('0x3d', 16), parseInt('0xba', 16), + parseInt('0x2b', 16), parseInt('0x79', 16), parseInt('0x0a', 16), parseInt('0x15', 16), parseInt('0x9b', 16), parseInt('0x9f', 16), parseInt('0x5e', 16), + parseInt('0xca', 16), parseInt('0x4e', 16), parseInt('0xd4', 16), parseInt('0xac', 16), parseInt('0xe5', 16), parseInt('0xf3', 16), parseInt('0x73', 16), + parseInt('0xa7', 16), parseInt('0x57', 16), parseInt('0xaf', 16), parseInt('0x58', 16), parseInt('0xa8', 16), parseInt('0x50', 16), parseInt('0xf4', 16), + parseInt('0xea', 16), parseInt('0xd6', 16), parseInt('0x74', 16), parseInt('0x4f', 16), parseInt('0xae', 16), parseInt('0xe9', 16), parseInt('0xd5', 16), + parseInt('0xe7', 16), parseInt('0xe6', 16), parseInt('0xad', 16), parseInt('0xe8', 16), parseInt('0x2c', 16), parseInt('0xd7', 16), parseInt('0x75', 16), + parseInt('0x7a', 16), parseInt('0xeb', 16), parseInt('0x16', 16), parseInt('0x0b', 16), parseInt('0xf5', 16), parseInt('0x59', 16), parseInt('0xcb', 16), + parseInt('0x5f', 16), parseInt('0xb0', 16), parseInt('0x9c', 16), parseInt('0xa9', 16), parseInt('0x51', 16), parseInt('0xa0', 16), parseInt('0x7f', 16), + parseInt('0x0c', 16), parseInt('0xf6', 16), parseInt('0x6f', 16), parseInt('0x17', 16), parseInt('0xc4', 16), parseInt('0x49', 16), parseInt('0xec', 16), + parseInt('0xd8', 16), parseInt('0x43', 16), parseInt('0x1f', 16), parseInt('0x2d', 16), parseInt('0xa4', 16), parseInt('0x76', 16), parseInt('0x7b', 16), + parseInt('0xb7', 16), parseInt('0xcc', 16), parseInt('0xbb', 16), parseInt('0x3e', 16), parseInt('0x5a', 16), parseInt('0xfb', 16), parseInt('0x60', 16), + parseInt('0xb1', 16), parseInt('0x86', 16), parseInt('0x3b', 16), parseInt('0x52', 16), parseInt('0xa1', 16), parseInt('0x6c', 16), parseInt('0xaa', 16), + parseInt('0x55', 16), parseInt('0x29', 16), parseInt('0x9d', 16), parseInt('0x97', 16), parseInt('0xb2', 16), parseInt('0x87', 16), parseInt('0x90', 16), + parseInt('0x61', 16), parseInt('0xbe', 16), parseInt('0xdc', 16), parseInt('0xfc', 16), parseInt('0xbc', 16), parseInt('0x95', 16), parseInt('0xcf', 16), + parseInt('0xcd', 16), parseInt('0x37', 16), parseInt('0x3f', 16), parseInt('0x5b', 16), parseInt('0xd1', 16), parseInt('0x53', 16), parseInt('0x39', 16), + parseInt('0x84', 16), parseInt('0x3c', 16), parseInt('0x41', 16), parseInt('0xa2', 16), parseInt('0x6d', 16), parseInt('0x47', 16), parseInt('0x14', 16), + parseInt('0x2a', 16), parseInt('0x9e', 16), parseInt('0x5d', 16), parseInt('0x56', 16), parseInt('0xf2', 16), parseInt('0xd3', 16), parseInt('0xab', 16), + parseInt('0x44', 16), parseInt('0x11', 16), parseInt('0x92', 16), parseInt('0xd9', 16), parseInt('0x23', 16), parseInt('0x20', 16), parseInt('0x2e', 16), + parseInt('0x89', 16), parseInt('0xb4', 16), parseInt('0x7c', 16), parseInt('0xb8', 16), parseInt('0x26', 16), parseInt('0x77', 16), parseInt('0x99', 16), + parseInt('0xe3', 16), parseInt('0xa5', 16), parseInt('0x67', 16), parseInt('0x4a', 16), parseInt('0xed', 16), parseInt('0xde', 16), parseInt('0xc5', 16), + parseInt('0x31', 16), parseInt('0xfe', 16), parseInt('0x18', 16), parseInt('0x0d', 16), parseInt('0x63', 16), parseInt('0x8c', 16), parseInt('0x80', 16), + parseInt('0xc0', 16), parseInt('0xf7', 16), parseInt('0x70', 16), parseInt('0x07', 16), ]); /* https://crypto.stackexchange.com/a/21174/13860 */ const EXP = new Uint8Array([ - parseInt('0x01'), parseInt('0x03'), parseInt('0x05'), parseInt('0x0f'), parseInt('0x11'), parseInt('0x33'), parseInt('0x55'), - parseInt('0xff'), parseInt('0x1a'), parseInt('0x2e'), parseInt('0x72'), parseInt('0x96'), parseInt('0xa1'), parseInt('0xf8'), - parseInt('0x13'), parseInt('0x35'), parseInt('0x5f'), parseInt('0xe1'), parseInt('0x38'), parseInt('0x48'), parseInt('0xd8'), - parseInt('0x73'), parseInt('0x95'), parseInt('0xa4'), parseInt('0xf7'), parseInt('0x02'), parseInt('0x06'), parseInt('0x0a'), - parseInt('0x1e'), parseInt('0x22'), parseInt('0x66'), parseInt('0xaa'), parseInt('0xe5'), parseInt('0x34'), parseInt('0x5c'), - parseInt('0xe4'), parseInt('0x37'), parseInt('0x59'), parseInt('0xeb'), parseInt('0x26'), parseInt('0x6a'), parseInt('0xbe'), - parseInt('0xd9'), parseInt('0x70'), parseInt('0x90'), parseInt('0xab'), parseInt('0xe6'), parseInt('0x31'), parseInt('0x53'), - parseInt('0xf5'), parseInt('0x04'), parseInt('0x0c'), parseInt('0x14'), parseInt('0x3c'), parseInt('0x44'), parseInt('0xcc'), - parseInt('0x4f'), parseInt('0xd1'), parseInt('0x68'), parseInt('0xb8'), parseInt('0xd3'), parseInt('0x6e'), parseInt('0xb2'), - parseInt('0xcd'), parseInt('0x4c'), parseInt('0xd4'), parseInt('0x67'), parseInt('0xa9'), parseInt('0xe0'), parseInt('0x3b'), - parseInt('0x4d'), parseInt('0xd7'), parseInt('0x62'), parseInt('0xa6'), parseInt('0xf1'), parseInt('0x08'), parseInt('0x18'), - parseInt('0x28'), parseInt('0x78'), parseInt('0x88'), parseInt('0x83'), parseInt('0x9e'), parseInt('0xb9'), parseInt('0xd0'), - parseInt('0x6b'), parseInt('0xbd'), parseInt('0xdc'), parseInt('0x7f'), parseInt('0x81'), parseInt('0x98'), parseInt('0xb3'), - parseInt('0xce'), parseInt('0x49'), parseInt('0xdb'), parseInt('0x76'), parseInt('0x9a'), parseInt('0xb5'), parseInt('0xc4'), - parseInt('0x57'), parseInt('0xf9'), parseInt('0x10'), parseInt('0x30'), parseInt('0x50'), parseInt('0xf0'), parseInt('0x0b'), - parseInt('0x1d'), parseInt('0x27'), parseInt('0x69'), parseInt('0xbb'), parseInt('0xd6'), parseInt('0x61'), parseInt('0xa3'), - parseInt('0xfe'), parseInt('0x19'), parseInt('0x2b'), parseInt('0x7d'), parseInt('0x87'), parseInt('0x92'), parseInt('0xad'), - parseInt('0xec'), parseInt('0x2f'), parseInt('0x71'), parseInt('0x93'), parseInt('0xae'), parseInt('0xe9'), parseInt('0x20'), - parseInt('0x60'), parseInt('0xa0'), parseInt('0xfb'), parseInt('0x16'), parseInt('0x3a'), parseInt('0x4e'), parseInt('0xd2'), - parseInt('0x6d'), parseInt('0xb7'), parseInt('0xc2'), parseInt('0x5d'), parseInt('0xe7'), parseInt('0x32'), parseInt('0x56'), - parseInt('0xfa'), parseInt('0x15'), parseInt('0x3f'), parseInt('0x41'), parseInt('0xc3'), parseInt('0x5e'), parseInt('0xe2'), - parseInt('0x3d'), parseInt('0x47'), parseInt('0xc9'), parseInt('0x40'), parseInt('0xc0'), parseInt('0x5b'), parseInt('0xed'), - parseInt('0x2c'), parseInt('0x74'), parseInt('0x9c'), parseInt('0xbf'), parseInt('0xda'), parseInt('0x75'), parseInt('0x9f'), - parseInt('0xba'), parseInt('0xd5'), parseInt('0x64'), parseInt('0xac'), parseInt('0xef'), parseInt('0x2a'), parseInt('0x7e'), - parseInt('0x82'), parseInt('0x9d'), parseInt('0xbc'), parseInt('0xdf'), parseInt('0x7a'), parseInt('0x8e'), parseInt('0x89'), - parseInt('0x80'), parseInt('0x9b'), parseInt('0xb6'), parseInt('0xc1'), parseInt('0x58'), parseInt('0xe8'), parseInt('0x23'), - parseInt('0x65'), parseInt('0xaf'), parseInt('0xea'), parseInt('0x25'), parseInt('0x6f'), parseInt('0xb1'), parseInt('0xc8'), - parseInt('0x43'), parseInt('0xc5'), parseInt('0x54'), parseInt('0xfc'), parseInt('0x1f'), parseInt('0x21'), parseInt('0x63'), - parseInt('0xa5'), parseInt('0xf4'), parseInt('0x07'), parseInt('0x09'), parseInt('0x1b'), parseInt('0x2d'), parseInt('0x77'), - parseInt('0x99'), parseInt('0xb0'), parseInt('0xcb'), parseInt('0x46'), parseInt('0xca'), parseInt('0x45'), parseInt('0xcf'), - parseInt('0x4a'), parseInt('0xde'), parseInt('0x79'), parseInt('0x8b'), parseInt('0x86'), parseInt('0x91'), parseInt('0xa8'), - parseInt('0xe3'), parseInt('0x3e'), parseInt('0x42'), parseInt('0xc6'), parseInt('0x51'), parseInt('0xf3'), parseInt('0x0e'), - parseInt('0x12'), parseInt('0x36'), parseInt('0x5a'), parseInt('0xee'), parseInt('0x29'), parseInt('0x7b'), parseInt('0x8d'), - parseInt('0x8c'), parseInt('0x8f'), parseInt('0x8a'), parseInt('0x85'), parseInt('0x94'), parseInt('0xa7'), parseInt('0xf2'), - parseInt('0x0d'), parseInt('0x17'), parseInt('0x39'), parseInt('0x4b'), parseInt('0xdd'), parseInt('0x7c'), parseInt('0x84'), - parseInt('0x97'), parseInt('0xa2'), parseInt('0xfd'), parseInt('0x1c'), parseInt('0x24'), parseInt('0x6c'), parseInt('0xb4'), - parseInt('0xc7'), parseInt('0x52'), parseInt('0xf6'), parseInt('0x01'), parseInt('0x03'), parseInt('0x05'), parseInt('0x0f'), - parseInt('0x11'), parseInt('0x33'), parseInt('0x55'), parseInt('0xff'), parseInt('0x1a'), parseInt('0x2e'), parseInt('0x72'), - parseInt('0x96'), parseInt('0xa1'), parseInt('0xf8'), parseInt('0x13'), parseInt('0x35'), parseInt('0x5f'), parseInt('0xe1'), - parseInt('0x38'), parseInt('0x48'), parseInt('0xd8'), parseInt('0x73'), parseInt('0x95'), parseInt('0xa4'), parseInt('0xf7'), - parseInt('0x02'), parseInt('0x06'), parseInt('0x0a'), parseInt('0x1e'), parseInt('0x22'), parseInt('0x66'), parseInt('0xaa'), - parseInt('0xe5'), parseInt('0x34'), parseInt('0x5c'), parseInt('0xe4'), parseInt('0x37'), parseInt('0x59'), parseInt('0xeb'), - parseInt('0x26'), parseInt('0x6a'), parseInt('0xbe'), parseInt('0xd9'), parseInt('0x70'), parseInt('0x90'), parseInt('0xab'), - parseInt('0xe6'), parseInt('0x31'), parseInt('0x53'), parseInt('0xf5'), parseInt('0x04'), parseInt('0x0c'), parseInt('0x14'), - parseInt('0x3c'), parseInt('0x44'), parseInt('0xcc'), parseInt('0x4f'), parseInt('0xd1'), parseInt('0x68'), parseInt('0xb8'), - parseInt('0xd3'), parseInt('0x6e'), parseInt('0xb2'), parseInt('0xcd'), parseInt('0x4c'), parseInt('0xd4'), parseInt('0x67'), - parseInt('0xa9'), parseInt('0xe0'), parseInt('0x3b'), parseInt('0x4d'), parseInt('0xd7'), parseInt('0x62'), parseInt('0xa6'), - parseInt('0xf1'), parseInt('0x08'), parseInt('0x18'), parseInt('0x28'), parseInt('0x78'), parseInt('0x88'), parseInt('0x83'), - parseInt('0x9e'), parseInt('0xb9'), parseInt('0xd0'), parseInt('0x6b'), parseInt('0xbd'), parseInt('0xdc'), parseInt('0x7f'), - parseInt('0x81'), parseInt('0x98'), parseInt('0xb3'), parseInt('0xce'), parseInt('0x49'), parseInt('0xdb'), parseInt('0x76'), - parseInt('0x9a'), parseInt('0xb5'), parseInt('0xc4'), parseInt('0x57'), parseInt('0xf9'), parseInt('0x10'), parseInt('0x30'), - parseInt('0x50'), parseInt('0xf0'), parseInt('0x0b'), parseInt('0x1d'), parseInt('0x27'), parseInt('0x69'), parseInt('0xbb'), - parseInt('0xd6'), parseInt('0x61'), parseInt('0xa3'), parseInt('0xfe'), parseInt('0x19'), parseInt('0x2b'), parseInt('0x7d'), - parseInt('0x87'), parseInt('0x92'), parseInt('0xad'), parseInt('0xec'), parseInt('0x2f'), parseInt('0x71'), parseInt('0x93'), - parseInt('0xae'), parseInt('0xe9'), parseInt('0x20'), parseInt('0x60'), parseInt('0xa0'), parseInt('0xfb'), parseInt('0x16'), - parseInt('0x3a'), parseInt('0x4e'), parseInt('0xd2'), parseInt('0x6d'), parseInt('0xb7'), parseInt('0xc2'), parseInt('0x5d'), - parseInt('0xe7'), parseInt('0x32'), parseInt('0x56'), parseInt('0xfa'), parseInt('0x15'), parseInt('0x3f'), parseInt('0x41'), - parseInt('0xc3'), parseInt('0x5e'), parseInt('0xe2'), parseInt('0x3d'), parseInt('0x47'), parseInt('0xc9'), parseInt('0x40'), - parseInt('0xc0'), parseInt('0x5b'), parseInt('0xed'), parseInt('0x2c'), parseInt('0x74'), parseInt('0x9c'), parseInt('0xbf'), - parseInt('0xda'), parseInt('0x75'), parseInt('0x9f'), parseInt('0xba'), parseInt('0xd5'), parseInt('0x64'), parseInt('0xac'), - parseInt('0xef'), parseInt('0x2a'), parseInt('0x7e'), parseInt('0x82'), parseInt('0x9d'), parseInt('0xbc'), parseInt('0xdf'), - parseInt('0x7a'), parseInt('0x8e'), parseInt('0x89'), parseInt('0x80'), parseInt('0x9b'), parseInt('0xb6'), parseInt('0xc1'), - parseInt('0x58'), parseInt('0xe8'), parseInt('0x23'), parseInt('0x65'), parseInt('0xaf'), parseInt('0xea'), parseInt('0x25'), - parseInt('0x6f'), parseInt('0xb1'), parseInt('0xc8'), parseInt('0x43'), parseInt('0xc5'), parseInt('0x54'), parseInt('0xfc'), - parseInt('0x1f'), parseInt('0x21'), parseInt('0x63'), parseInt('0xa5'), parseInt('0xf4'), parseInt('0x07'), parseInt('0x09'), - parseInt('0x1b'), parseInt('0x2d'), parseInt('0x77'), parseInt('0x99'), parseInt('0xb0'), parseInt('0xcb'), parseInt('0x46'), - parseInt('0xca'), parseInt('0x45'), parseInt('0xcf'), parseInt('0x4a'), parseInt('0xde'), parseInt('0x79'), parseInt('0x8b'), - parseInt('0x86'), parseInt('0x91'), parseInt('0xa8'), parseInt('0xe3'), parseInt('0x3e'), parseInt('0x42'), parseInt('0xc6'), - parseInt('0x51'), parseInt('0xf3'), parseInt('0x0e'), parseInt('0x12'), parseInt('0x36'), parseInt('0x5a'), parseInt('0xee'), - parseInt('0x29'), parseInt('0x7b'), parseInt('0x8d'), parseInt('0x8c'), parseInt('0x8f'), parseInt('0x8a'), parseInt('0x85'), - parseInt('0x94'), parseInt('0xa7'), parseInt('0xf2'), parseInt('0x0d'), parseInt('0x17'), parseInt('0x39'), parseInt('0x4b'), - parseInt('0xdd'), parseInt('0x7c'), parseInt('0x84'), parseInt('0x97'), parseInt('0xa2'), parseInt('0xfd'), parseInt('0x1c'), - parseInt('0x24'), parseInt('0x6c'), parseInt('0xb4'), parseInt('0xc7'), parseInt('0x52'), parseInt('0xf6'), + parseInt('0x01', 16), parseInt('0x03', 16), parseInt('0x05', 16), parseInt('0x0f', 16), parseInt('0x11', 16), parseInt('0x33', 16), parseInt('0x55', 16), + parseInt('0xff', 16), parseInt('0x1a', 16), parseInt('0x2e', 16), parseInt('0x72', 16), parseInt('0x96', 16), parseInt('0xa1', 16), parseInt('0xf8', 16), + parseInt('0x13', 16), parseInt('0x35', 16), parseInt('0x5f', 16), parseInt('0xe1', 16), parseInt('0x38', 16), parseInt('0x48', 16), parseInt('0xd8', 16), + parseInt('0x73', 16), parseInt('0x95', 16), parseInt('0xa4', 16), parseInt('0xf7', 16), parseInt('0x02', 16), parseInt('0x06', 16), parseInt('0x0a', 16), + parseInt('0x1e', 16), parseInt('0x22', 16), parseInt('0x66', 16), parseInt('0xaa', 16), parseInt('0xe5', 16), parseInt('0x34', 16), parseInt('0x5c', 16), + parseInt('0xe4', 16), parseInt('0x37', 16), parseInt('0x59', 16), parseInt('0xeb', 16), parseInt('0x26', 16), parseInt('0x6a', 16), parseInt('0xbe', 16), + parseInt('0xd9', 16), parseInt('0x70', 16), parseInt('0x90', 16), parseInt('0xab', 16), parseInt('0xe6', 16), parseInt('0x31', 16), parseInt('0x53', 16), + parseInt('0xf5', 16), parseInt('0x04', 16), parseInt('0x0c', 16), parseInt('0x14', 16), parseInt('0x3c', 16), parseInt('0x44', 16), parseInt('0xcc', 16), + parseInt('0x4f', 16), parseInt('0xd1', 16), parseInt('0x68', 16), parseInt('0xb8', 16), parseInt('0xd3', 16), parseInt('0x6e', 16), parseInt('0xb2', 16), + parseInt('0xcd', 16), parseInt('0x4c', 16), parseInt('0xd4', 16), parseInt('0x67', 16), parseInt('0xa9', 16), parseInt('0xe0', 16), parseInt('0x3b', 16), + parseInt('0x4d', 16), parseInt('0xd7', 16), parseInt('0x62', 16), parseInt('0xa6', 16), parseInt('0xf1', 16), parseInt('0x08', 16), parseInt('0x18', 16), + parseInt('0x28', 16), parseInt('0x78', 16), parseInt('0x88', 16), parseInt('0x83', 16), parseInt('0x9e', 16), parseInt('0xb9', 16), parseInt('0xd0', 16), + parseInt('0x6b', 16), parseInt('0xbd', 16), parseInt('0xdc', 16), parseInt('0x7f', 16), parseInt('0x81', 16), parseInt('0x98', 16), parseInt('0xb3', 16), + parseInt('0xce', 16), parseInt('0x49', 16), parseInt('0xdb', 16), parseInt('0x76', 16), parseInt('0x9a', 16), parseInt('0xb5', 16), parseInt('0xc4', 16), + parseInt('0x57', 16), parseInt('0xf9', 16), parseInt('0x10', 16), parseInt('0x30', 16), parseInt('0x50', 16), parseInt('0xf0', 16), parseInt('0x0b', 16), + parseInt('0x1d', 16), parseInt('0x27', 16), parseInt('0x69', 16), parseInt('0xbb', 16), parseInt('0xd6', 16), parseInt('0x61', 16), parseInt('0xa3', 16), + parseInt('0xfe', 16), parseInt('0x19', 16), parseInt('0x2b', 16), parseInt('0x7d', 16), parseInt('0x87', 16), parseInt('0x92', 16), parseInt('0xad', 16), + parseInt('0xec', 16), parseInt('0x2f', 16), parseInt('0x71', 16), parseInt('0x93', 16), parseInt('0xae', 16), parseInt('0xe9', 16), parseInt('0x20', 16), + parseInt('0x60', 16), parseInt('0xa0', 16), parseInt('0xfb', 16), parseInt('0x16', 16), parseInt('0x3a', 16), parseInt('0x4e', 16), parseInt('0xd2', 16), + parseInt('0x6d', 16), parseInt('0xb7', 16), parseInt('0xc2', 16), parseInt('0x5d', 16), parseInt('0xe7', 16), parseInt('0x32', 16), parseInt('0x56', 16), + parseInt('0xfa', 16), parseInt('0x15', 16), parseInt('0x3f', 16), parseInt('0x41', 16), parseInt('0xc3', 16), parseInt('0x5e', 16), parseInt('0xe2', 16), + parseInt('0x3d', 16), parseInt('0x47', 16), parseInt('0xc9', 16), parseInt('0x40', 16), parseInt('0xc0', 16), parseInt('0x5b', 16), parseInt('0xed', 16), + parseInt('0x2c', 16), parseInt('0x74', 16), parseInt('0x9c', 16), parseInt('0xbf', 16), parseInt('0xda', 16), parseInt('0x75', 16), parseInt('0x9f', 16), + parseInt('0xba', 16), parseInt('0xd5', 16), parseInt('0x64', 16), parseInt('0xac', 16), parseInt('0xef', 16), parseInt('0x2a', 16), parseInt('0x7e', 16), + parseInt('0x82', 16), parseInt('0x9d', 16), parseInt('0xbc', 16), parseInt('0xdf', 16), parseInt('0x7a', 16), parseInt('0x8e', 16), parseInt('0x89', 16), + parseInt('0x80', 16), parseInt('0x9b', 16), parseInt('0xb6', 16), parseInt('0xc1', 16), parseInt('0x58', 16), parseInt('0xe8', 16), parseInt('0x23', 16), + parseInt('0x65', 16), parseInt('0xaf', 16), parseInt('0xea', 16), parseInt('0x25', 16), parseInt('0x6f', 16), parseInt('0xb1', 16), parseInt('0xc8', 16), + parseInt('0x43', 16), parseInt('0xc5', 16), parseInt('0x54', 16), parseInt('0xfc', 16), parseInt('0x1f', 16), parseInt('0x21', 16), parseInt('0x63', 16), + parseInt('0xa5', 16), parseInt('0xf4', 16), parseInt('0x07', 16), parseInt('0x09', 16), parseInt('0x1b', 16), parseInt('0x2d', 16), parseInt('0x77', 16), + parseInt('0x99', 16), parseInt('0xb0', 16), parseInt('0xcb', 16), parseInt('0x46', 16), parseInt('0xca', 16), parseInt('0x45', 16), parseInt('0xcf', 16), + parseInt('0x4a', 16), parseInt('0xde', 16), parseInt('0x79', 16), parseInt('0x8b', 16), parseInt('0x86', 16), parseInt('0x91', 16), parseInt('0xa8', 16), + parseInt('0xe3', 16), parseInt('0x3e', 16), parseInt('0x42', 16), parseInt('0xc6', 16), parseInt('0x51', 16), parseInt('0xf3', 16), parseInt('0x0e', 16), + parseInt('0x12', 16), parseInt('0x36', 16), parseInt('0x5a', 16), parseInt('0xee', 16), parseInt('0x29', 16), parseInt('0x7b', 16), parseInt('0x8d', 16), + parseInt('0x8c', 16), parseInt('0x8f', 16), parseInt('0x8a', 16), parseInt('0x85', 16), parseInt('0x94', 16), parseInt('0xa7', 16), parseInt('0xf2', 16), + parseInt('0x0d', 16), parseInt('0x17', 16), parseInt('0x39', 16), parseInt('0x4b', 16), parseInt('0xdd', 16), parseInt('0x7c', 16), parseInt('0x84', 16), + parseInt('0x97', 16), parseInt('0xa2', 16), parseInt('0xfd', 16), parseInt('0x1c', 16), parseInt('0x24', 16), parseInt('0x6c', 16), parseInt('0xb4', 16), + parseInt('0xc7', 16), parseInt('0x52', 16), parseInt('0xf6', 16), parseInt('0x01', 16), parseInt('0x03', 16), parseInt('0x05', 16), parseInt('0x0f', 16), + parseInt('0x11', 16), parseInt('0x33', 16), parseInt('0x55', 16), parseInt('0xff', 16), parseInt('0x1a', 16), parseInt('0x2e', 16), parseInt('0x72', 16), + parseInt('0x96', 16), parseInt('0xa1', 16), parseInt('0xf8', 16), parseInt('0x13', 16), parseInt('0x35', 16), parseInt('0x5f', 16), parseInt('0xe1', 16), + parseInt('0x38', 16), parseInt('0x48', 16), parseInt('0xd8', 16), parseInt('0x73', 16), parseInt('0x95', 16), parseInt('0xa4', 16), parseInt('0xf7', 16), + parseInt('0x02', 16), parseInt('0x06', 16), parseInt('0x0a', 16), parseInt('0x1e', 16), parseInt('0x22', 16), parseInt('0x66', 16), parseInt('0xaa', 16), + parseInt('0xe5', 16), parseInt('0x34', 16), parseInt('0x5c', 16), parseInt('0xe4', 16), parseInt('0x37', 16), parseInt('0x59', 16), parseInt('0xeb', 16), + parseInt('0x26', 16), parseInt('0x6a', 16), parseInt('0xbe', 16), parseInt('0xd9', 16), parseInt('0x70', 16), parseInt('0x90', 16), parseInt('0xab', 16), + parseInt('0xe6', 16), parseInt('0x31', 16), parseInt('0x53', 16), parseInt('0xf5', 16), parseInt('0x04', 16), parseInt('0x0c', 16), parseInt('0x14', 16), + parseInt('0x3c', 16), parseInt('0x44', 16), parseInt('0xcc', 16), parseInt('0x4f', 16), parseInt('0xd1', 16), parseInt('0x68', 16), parseInt('0xb8', 16), + parseInt('0xd3', 16), parseInt('0x6e', 16), parseInt('0xb2', 16), parseInt('0xcd', 16), parseInt('0x4c', 16), parseInt('0xd4', 16), parseInt('0x67', 16), + parseInt('0xa9', 16), parseInt('0xe0', 16), parseInt('0x3b', 16), parseInt('0x4d', 16), parseInt('0xd7', 16), parseInt('0x62', 16), parseInt('0xa6', 16), + parseInt('0xf1', 16), parseInt('0x08', 16), parseInt('0x18', 16), parseInt('0x28', 16), parseInt('0x78', 16), parseInt('0x88', 16), parseInt('0x83', 16), + parseInt('0x9e', 16), parseInt('0xb9', 16), parseInt('0xd0', 16), parseInt('0x6b', 16), parseInt('0xbd', 16), parseInt('0xdc', 16), parseInt('0x7f', 16), + parseInt('0x81', 16), parseInt('0x98', 16), parseInt('0xb3', 16), parseInt('0xce', 16), parseInt('0x49', 16), parseInt('0xdb', 16), parseInt('0x76', 16), + parseInt('0x9a', 16), parseInt('0xb5', 16), parseInt('0xc4', 16), parseInt('0x57', 16), parseInt('0xf9', 16), parseInt('0x10', 16), parseInt('0x30', 16), + parseInt('0x50', 16), parseInt('0xf0', 16), parseInt('0x0b', 16), parseInt('0x1d', 16), parseInt('0x27', 16), parseInt('0x69', 16), parseInt('0xbb', 16), + parseInt('0xd6', 16), parseInt('0x61', 16), parseInt('0xa3', 16), parseInt('0xfe', 16), parseInt('0x19', 16), parseInt('0x2b', 16), parseInt('0x7d', 16), + parseInt('0x87', 16), parseInt('0x92', 16), parseInt('0xad', 16), parseInt('0xec', 16), parseInt('0x2f', 16), parseInt('0x71', 16), parseInt('0x93', 16), + parseInt('0xae', 16), parseInt('0xe9', 16), parseInt('0x20', 16), parseInt('0x60', 16), parseInt('0xa0', 16), parseInt('0xfb', 16), parseInt('0x16', 16), + parseInt('0x3a', 16), parseInt('0x4e', 16), parseInt('0xd2', 16), parseInt('0x6d', 16), parseInt('0xb7', 16), parseInt('0xc2', 16), parseInt('0x5d', 16), + parseInt('0xe7', 16), parseInt('0x32', 16), parseInt('0x56', 16), parseInt('0xfa', 16), parseInt('0x15', 16), parseInt('0x3f', 16), parseInt('0x41', 16), + parseInt('0xc3', 16), parseInt('0x5e', 16), parseInt('0xe2', 16), parseInt('0x3d', 16), parseInt('0x47', 16), parseInt('0xc9', 16), parseInt('0x40', 16), + parseInt('0xc0', 16), parseInt('0x5b', 16), parseInt('0xed', 16), parseInt('0x2c', 16), parseInt('0x74', 16), parseInt('0x9c', 16), parseInt('0xbf', 16), + parseInt('0xda', 16), parseInt('0x75', 16), parseInt('0x9f', 16), parseInt('0xba', 16), parseInt('0xd5', 16), parseInt('0x64', 16), parseInt('0xac', 16), + parseInt('0xef', 16), parseInt('0x2a', 16), parseInt('0x7e', 16), parseInt('0x82', 16), parseInt('0x9d', 16), parseInt('0xbc', 16), parseInt('0xdf', 16), + parseInt('0x7a', 16), parseInt('0x8e', 16), parseInt('0x89', 16), parseInt('0x80', 16), parseInt('0x9b', 16), parseInt('0xb6', 16), parseInt('0xc1', 16), + parseInt('0x58', 16), parseInt('0xe8', 16), parseInt('0x23', 16), parseInt('0x65', 16), parseInt('0xaf', 16), parseInt('0xea', 16), parseInt('0x25', 16), + parseInt('0x6f', 16), parseInt('0xb1', 16), parseInt('0xc8', 16), parseInt('0x43', 16), parseInt('0xc5', 16), parseInt('0x54', 16), parseInt('0xfc', 16), + parseInt('0x1f', 16), parseInt('0x21', 16), parseInt('0x63', 16), parseInt('0xa5', 16), parseInt('0xf4', 16), parseInt('0x07', 16), parseInt('0x09', 16), + parseInt('0x1b', 16), parseInt('0x2d', 16), parseInt('0x77', 16), parseInt('0x99', 16), parseInt('0xb0', 16), parseInt('0xcb', 16), parseInt('0x46', 16), + parseInt('0xca', 16), parseInt('0x45', 16), parseInt('0xcf', 16), parseInt('0x4a', 16), parseInt('0xde', 16), parseInt('0x79', 16), parseInt('0x8b', 16), + parseInt('0x86', 16), parseInt('0x91', 16), parseInt('0xa8', 16), parseInt('0xe3', 16), parseInt('0x3e', 16), parseInt('0x42', 16), parseInt('0xc6', 16), + parseInt('0x51', 16), parseInt('0xf3', 16), parseInt('0x0e', 16), parseInt('0x12', 16), parseInt('0x36', 16), parseInt('0x5a', 16), parseInt('0xee', 16), + parseInt('0x29', 16), parseInt('0x7b', 16), parseInt('0x8d', 16), parseInt('0x8c', 16), parseInt('0x8f', 16), parseInt('0x8a', 16), parseInt('0x85', 16), + parseInt('0x94', 16), parseInt('0xa7', 16), parseInt('0xf2', 16), parseInt('0x0d', 16), parseInt('0x17', 16), parseInt('0x39', 16), parseInt('0x4b', 16), + parseInt('0xdd', 16), parseInt('0x7c', 16), parseInt('0x84', 16), parseInt('0x97', 16), parseInt('0xa2', 16), parseInt('0xfd', 16), parseInt('0x1c', 16), + parseInt('0x24', 16), parseInt('0x6c', 16), parseInt('0xb4', 16), parseInt('0xc7', 16), parseInt('0x52', 16), parseInt('0xf6', 16), ]); const mul = function(a, b) { From c87de0874b10b6cbbf9349abb8007bdb9ba54bf4 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 20:01:46 +0100 Subject: [PATCH 41/78] byte literals for the arrays --- src/main/js/GF256.js | 220 +++++++++++++++++++++---------------------- 1 file changed, 110 insertions(+), 110 deletions(-) diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index 9eb0bf7..57bfccc 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -30,121 +30,121 @@ const sub = add; exports.sub = exports.add; const LOG = new Uint8Array([ - parseInt('0xff', 16), parseInt('0x00', 16), parseInt('0x19', 16), parseInt('0x01', 16), parseInt('0x32', 16), parseInt('0x02', 16), parseInt('0x1a', 16), - parseInt('0xc6', 16), parseInt('0x4b', 16), parseInt('0xc7', 16), parseInt('0x1b', 16), parseInt('0x68', 16), parseInt('0x33', 16), parseInt('0xee', 16), - parseInt('0xdf', 16), parseInt('0x03', 16), parseInt('0x64', 16), parseInt('0x04', 16), parseInt('0xe0', 16), parseInt('0x0e', 16), parseInt('0x34', 16), - parseInt('0x8d', 16), parseInt('0x81', 16), parseInt('0xef', 16), parseInt('0x4c', 16), parseInt('0x71', 16), parseInt('0x08', 16), parseInt('0xc8', 16), - parseInt('0xf8', 16), parseInt('0x69', 16), parseInt('0x1c', 16), parseInt('0xc1', 16), parseInt('0x7d', 16), parseInt('0xc2', 16), parseInt('0x1d', 16), - parseInt('0xb5', 16), parseInt('0xf9', 16), parseInt('0xb9', 16), parseInt('0x27', 16), parseInt('0x6a', 16), parseInt('0x4d', 16), parseInt('0xe4', 16), - parseInt('0xa6', 16), parseInt('0x72', 16), parseInt('0x9a', 16), parseInt('0xc9', 16), parseInt('0x09', 16), parseInt('0x78', 16), parseInt('0x65', 16), - parseInt('0x2f', 16), parseInt('0x8a', 16), parseInt('0x05', 16), parseInt('0x21', 16), parseInt('0x0f', 16), parseInt('0xe1', 16), parseInt('0x24', 16), - parseInt('0x12', 16), parseInt('0xf0', 16), parseInt('0x82', 16), parseInt('0x45', 16), parseInt('0x35', 16), parseInt('0x93', 16), parseInt('0xda', 16), - parseInt('0x8e', 16), parseInt('0x96', 16), parseInt('0x8f', 16), parseInt('0xdb', 16), parseInt('0xbd', 16), parseInt('0x36', 16), parseInt('0xd0', 16), - parseInt('0xce', 16), parseInt('0x94', 16), parseInt('0x13', 16), parseInt('0x5c', 16), parseInt('0xd2', 16), parseInt('0xf1', 16), parseInt('0x40', 16), - parseInt('0x46', 16), parseInt('0x83', 16), parseInt('0x38', 16), parseInt('0x66', 16), parseInt('0xdd', 16), parseInt('0xfd', 16), parseInt('0x30', 16), - parseInt('0xbf', 16), parseInt('0x06', 16), parseInt('0x8b', 16), parseInt('0x62', 16), parseInt('0xb3', 16), parseInt('0x25', 16), parseInt('0xe2', 16), - parseInt('0x98', 16), parseInt('0x22', 16), parseInt('0x88', 16), parseInt('0x91', 16), parseInt('0x10', 16), parseInt('0x7e', 16), parseInt('0x6e', 16), - parseInt('0x48', 16), parseInt('0xc3', 16), parseInt('0xa3', 16), parseInt('0xb6', 16), parseInt('0x1e', 16), parseInt('0x42', 16), parseInt('0x3a', 16), - parseInt('0x6b', 16), parseInt('0x28', 16), parseInt('0x54', 16), parseInt('0xfa', 16), parseInt('0x85', 16), parseInt('0x3d', 16), parseInt('0xba', 16), - parseInt('0x2b', 16), parseInt('0x79', 16), parseInt('0x0a', 16), parseInt('0x15', 16), parseInt('0x9b', 16), parseInt('0x9f', 16), parseInt('0x5e', 16), - parseInt('0xca', 16), parseInt('0x4e', 16), parseInt('0xd4', 16), parseInt('0xac', 16), parseInt('0xe5', 16), parseInt('0xf3', 16), parseInt('0x73', 16), - parseInt('0xa7', 16), parseInt('0x57', 16), parseInt('0xaf', 16), parseInt('0x58', 16), parseInt('0xa8', 16), parseInt('0x50', 16), parseInt('0xf4', 16), - parseInt('0xea', 16), parseInt('0xd6', 16), parseInt('0x74', 16), parseInt('0x4f', 16), parseInt('0xae', 16), parseInt('0xe9', 16), parseInt('0xd5', 16), - parseInt('0xe7', 16), parseInt('0xe6', 16), parseInt('0xad', 16), parseInt('0xe8', 16), parseInt('0x2c', 16), parseInt('0xd7', 16), parseInt('0x75', 16), - parseInt('0x7a', 16), parseInt('0xeb', 16), parseInt('0x16', 16), parseInt('0x0b', 16), parseInt('0xf5', 16), parseInt('0x59', 16), parseInt('0xcb', 16), - parseInt('0x5f', 16), parseInt('0xb0', 16), parseInt('0x9c', 16), parseInt('0xa9', 16), parseInt('0x51', 16), parseInt('0xa0', 16), parseInt('0x7f', 16), - parseInt('0x0c', 16), parseInt('0xf6', 16), parseInt('0x6f', 16), parseInt('0x17', 16), parseInt('0xc4', 16), parseInt('0x49', 16), parseInt('0xec', 16), - parseInt('0xd8', 16), parseInt('0x43', 16), parseInt('0x1f', 16), parseInt('0x2d', 16), parseInt('0xa4', 16), parseInt('0x76', 16), parseInt('0x7b', 16), - parseInt('0xb7', 16), parseInt('0xcc', 16), parseInt('0xbb', 16), parseInt('0x3e', 16), parseInt('0x5a', 16), parseInt('0xfb', 16), parseInt('0x60', 16), - parseInt('0xb1', 16), parseInt('0x86', 16), parseInt('0x3b', 16), parseInt('0x52', 16), parseInt('0xa1', 16), parseInt('0x6c', 16), parseInt('0xaa', 16), - parseInt('0x55', 16), parseInt('0x29', 16), parseInt('0x9d', 16), parseInt('0x97', 16), parseInt('0xb2', 16), parseInt('0x87', 16), parseInt('0x90', 16), - parseInt('0x61', 16), parseInt('0xbe', 16), parseInt('0xdc', 16), parseInt('0xfc', 16), parseInt('0xbc', 16), parseInt('0x95', 16), parseInt('0xcf', 16), - parseInt('0xcd', 16), parseInt('0x37', 16), parseInt('0x3f', 16), parseInt('0x5b', 16), parseInt('0xd1', 16), parseInt('0x53', 16), parseInt('0x39', 16), - parseInt('0x84', 16), parseInt('0x3c', 16), parseInt('0x41', 16), parseInt('0xa2', 16), parseInt('0x6d', 16), parseInt('0x47', 16), parseInt('0x14', 16), - parseInt('0x2a', 16), parseInt('0x9e', 16), parseInt('0x5d', 16), parseInt('0x56', 16), parseInt('0xf2', 16), parseInt('0xd3', 16), parseInt('0xab', 16), - parseInt('0x44', 16), parseInt('0x11', 16), parseInt('0x92', 16), parseInt('0xd9', 16), parseInt('0x23', 16), parseInt('0x20', 16), parseInt('0x2e', 16), - parseInt('0x89', 16), parseInt('0xb4', 16), parseInt('0x7c', 16), parseInt('0xb8', 16), parseInt('0x26', 16), parseInt('0x77', 16), parseInt('0x99', 16), - parseInt('0xe3', 16), parseInt('0xa5', 16), parseInt('0x67', 16), parseInt('0x4a', 16), parseInt('0xed', 16), parseInt('0xde', 16), parseInt('0xc5', 16), - parseInt('0x31', 16), parseInt('0xfe', 16), parseInt('0x18', 16), parseInt('0x0d', 16), parseInt('0x63', 16), parseInt('0x8c', 16), parseInt('0x80', 16), - parseInt('0xc0', 16), parseInt('0xf7', 16), parseInt('0x70', 16), parseInt('0x07', 16), + 0xff, 0x00, 0x19, 0x01, 0x32, 0x02, 0x1a, + 0xc6, 0x4b, 0xc7, 0x1b, 0x68, 0x33, 0xee, + 0xdf, 0x03, 0x64, 0x04, 0xe0, 0x0e, 0x34, + 0x8d, 0x81, 0xef, 0x4c, 0x71, 0x08, 0xc8, + 0xf8, 0x69, 0x1c, 0xc1, 0x7d, 0xc2, 0x1d, + 0xb5, 0xf9, 0xb9, 0x27, 0x6a, 0x4d, 0xe4, + 0xa6, 0x72, 0x9a, 0xc9, 0x09, 0x78, 0x65, + 0x2f, 0x8a, 0x05, 0x21, 0x0f, 0xe1, 0x24, + 0x12, 0xf0, 0x82, 0x45, 0x35, 0x93, 0xda, + 0x8e, 0x96, 0x8f, 0xdb, 0xbd, 0x36, 0xd0, + 0xce, 0x94, 0x13, 0x5c, 0xd2, 0xf1, 0x40, + 0x46, 0x83, 0x38, 0x66, 0xdd, 0xfd, 0x30, + 0xbf, 0x06, 0x8b, 0x62, 0xb3, 0x25, 0xe2, + 0x98, 0x22, 0x88, 0x91, 0x10, 0x7e, 0x6e, + 0x48, 0xc3, 0xa3, 0xb6, 0x1e, 0x42, 0x3a, + 0x6b, 0x28, 0x54, 0xfa, 0x85, 0x3d, 0xba, + 0x2b, 0x79, 0x0a, 0x15, 0x9b, 0x9f, 0x5e, + 0xca, 0x4e, 0xd4, 0xac, 0xe5, 0xf3, 0x73, + 0xa7, 0x57, 0xaf, 0x58, 0xa8, 0x50, 0xf4, + 0xea, 0xd6, 0x74, 0x4f, 0xae, 0xe9, 0xd5, + 0xe7, 0xe6, 0xad, 0xe8, 0x2c, 0xd7, 0x75, + 0x7a, 0xeb, 0x16, 0x0b, 0xf5, 0x59, 0xcb, + 0x5f, 0xb0, 0x9c, 0xa9, 0x51, 0xa0, 0x7f, + 0x0c, 0xf6, 0x6f, 0x17, 0xc4, 0x49, 0xec, + 0xd8, 0x43, 0x1f, 0x2d, 0xa4, 0x76, 0x7b, + 0xb7, 0xcc, 0xbb, 0x3e, 0x5a, 0xfb, 0x60, + 0xb1, 0x86, 0x3b, 0x52, 0xa1, 0x6c, 0xaa, + 0x55, 0x29, 0x9d, 0x97, 0xb2, 0x87, 0x90, + 0x61, 0xbe, 0xdc, 0xfc, 0xbc, 0x95, 0xcf, + 0xcd, 0x37, 0x3f, 0x5b, 0xd1, 0x53, 0x39, + 0x84, 0x3c, 0x41, 0xa2, 0x6d, 0x47, 0x14, + 0x2a, 0x9e, 0x5d, 0x56, 0xf2, 0xd3, 0xab, + 0x44, 0x11, 0x92, 0xd9, 0x23, 0x20, 0x2e, + 0x89, 0xb4, 0x7c, 0xb8, 0x26, 0x77, 0x99, + 0xe3, 0xa5, 0x67, 0x4a, 0xed, 0xde, 0xc5, + 0x31, 0xfe, 0x18, 0x0d, 0x63, 0x8c, 0x80, + 0xc0, 0xf7, 0x70, 0x07, ]); /* https://crypto.stackexchange.com/a/21174/13860 */ const EXP = new Uint8Array([ - parseInt('0x01', 16), parseInt('0x03', 16), parseInt('0x05', 16), parseInt('0x0f', 16), parseInt('0x11', 16), parseInt('0x33', 16), parseInt('0x55', 16), - parseInt('0xff', 16), parseInt('0x1a', 16), parseInt('0x2e', 16), parseInt('0x72', 16), parseInt('0x96', 16), parseInt('0xa1', 16), parseInt('0xf8', 16), - parseInt('0x13', 16), parseInt('0x35', 16), parseInt('0x5f', 16), parseInt('0xe1', 16), parseInt('0x38', 16), parseInt('0x48', 16), parseInt('0xd8', 16), - parseInt('0x73', 16), parseInt('0x95', 16), parseInt('0xa4', 16), parseInt('0xf7', 16), parseInt('0x02', 16), parseInt('0x06', 16), parseInt('0x0a', 16), - parseInt('0x1e', 16), parseInt('0x22', 16), parseInt('0x66', 16), parseInt('0xaa', 16), parseInt('0xe5', 16), parseInt('0x34', 16), parseInt('0x5c', 16), - parseInt('0xe4', 16), parseInt('0x37', 16), parseInt('0x59', 16), parseInt('0xeb', 16), parseInt('0x26', 16), parseInt('0x6a', 16), parseInt('0xbe', 16), - parseInt('0xd9', 16), parseInt('0x70', 16), parseInt('0x90', 16), parseInt('0xab', 16), parseInt('0xe6', 16), parseInt('0x31', 16), parseInt('0x53', 16), - parseInt('0xf5', 16), parseInt('0x04', 16), parseInt('0x0c', 16), parseInt('0x14', 16), parseInt('0x3c', 16), parseInt('0x44', 16), parseInt('0xcc', 16), - parseInt('0x4f', 16), parseInt('0xd1', 16), parseInt('0x68', 16), parseInt('0xb8', 16), parseInt('0xd3', 16), parseInt('0x6e', 16), parseInt('0xb2', 16), - parseInt('0xcd', 16), parseInt('0x4c', 16), parseInt('0xd4', 16), parseInt('0x67', 16), parseInt('0xa9', 16), parseInt('0xe0', 16), parseInt('0x3b', 16), - parseInt('0x4d', 16), parseInt('0xd7', 16), parseInt('0x62', 16), parseInt('0xa6', 16), parseInt('0xf1', 16), parseInt('0x08', 16), parseInt('0x18', 16), - parseInt('0x28', 16), parseInt('0x78', 16), parseInt('0x88', 16), parseInt('0x83', 16), parseInt('0x9e', 16), parseInt('0xb9', 16), parseInt('0xd0', 16), - parseInt('0x6b', 16), parseInt('0xbd', 16), parseInt('0xdc', 16), parseInt('0x7f', 16), parseInt('0x81', 16), parseInt('0x98', 16), parseInt('0xb3', 16), - parseInt('0xce', 16), parseInt('0x49', 16), parseInt('0xdb', 16), parseInt('0x76', 16), parseInt('0x9a', 16), parseInt('0xb5', 16), parseInt('0xc4', 16), - parseInt('0x57', 16), parseInt('0xf9', 16), parseInt('0x10', 16), parseInt('0x30', 16), parseInt('0x50', 16), parseInt('0xf0', 16), parseInt('0x0b', 16), - parseInt('0x1d', 16), parseInt('0x27', 16), parseInt('0x69', 16), parseInt('0xbb', 16), parseInt('0xd6', 16), parseInt('0x61', 16), parseInt('0xa3', 16), - parseInt('0xfe', 16), parseInt('0x19', 16), parseInt('0x2b', 16), parseInt('0x7d', 16), parseInt('0x87', 16), parseInt('0x92', 16), parseInt('0xad', 16), - parseInt('0xec', 16), parseInt('0x2f', 16), parseInt('0x71', 16), parseInt('0x93', 16), parseInt('0xae', 16), parseInt('0xe9', 16), parseInt('0x20', 16), - parseInt('0x60', 16), parseInt('0xa0', 16), parseInt('0xfb', 16), parseInt('0x16', 16), parseInt('0x3a', 16), parseInt('0x4e', 16), parseInt('0xd2', 16), - parseInt('0x6d', 16), parseInt('0xb7', 16), parseInt('0xc2', 16), parseInt('0x5d', 16), parseInt('0xe7', 16), parseInt('0x32', 16), parseInt('0x56', 16), - parseInt('0xfa', 16), parseInt('0x15', 16), parseInt('0x3f', 16), parseInt('0x41', 16), parseInt('0xc3', 16), parseInt('0x5e', 16), parseInt('0xe2', 16), - parseInt('0x3d', 16), parseInt('0x47', 16), parseInt('0xc9', 16), parseInt('0x40', 16), parseInt('0xc0', 16), parseInt('0x5b', 16), parseInt('0xed', 16), - parseInt('0x2c', 16), parseInt('0x74', 16), parseInt('0x9c', 16), parseInt('0xbf', 16), parseInt('0xda', 16), parseInt('0x75', 16), parseInt('0x9f', 16), - parseInt('0xba', 16), parseInt('0xd5', 16), parseInt('0x64', 16), parseInt('0xac', 16), parseInt('0xef', 16), parseInt('0x2a', 16), parseInt('0x7e', 16), - parseInt('0x82', 16), parseInt('0x9d', 16), parseInt('0xbc', 16), parseInt('0xdf', 16), parseInt('0x7a', 16), parseInt('0x8e', 16), parseInt('0x89', 16), - parseInt('0x80', 16), parseInt('0x9b', 16), parseInt('0xb6', 16), parseInt('0xc1', 16), parseInt('0x58', 16), parseInt('0xe8', 16), parseInt('0x23', 16), - parseInt('0x65', 16), parseInt('0xaf', 16), parseInt('0xea', 16), parseInt('0x25', 16), parseInt('0x6f', 16), parseInt('0xb1', 16), parseInt('0xc8', 16), - parseInt('0x43', 16), parseInt('0xc5', 16), parseInt('0x54', 16), parseInt('0xfc', 16), parseInt('0x1f', 16), parseInt('0x21', 16), parseInt('0x63', 16), - parseInt('0xa5', 16), parseInt('0xf4', 16), parseInt('0x07', 16), parseInt('0x09', 16), parseInt('0x1b', 16), parseInt('0x2d', 16), parseInt('0x77', 16), - parseInt('0x99', 16), parseInt('0xb0', 16), parseInt('0xcb', 16), parseInt('0x46', 16), parseInt('0xca', 16), parseInt('0x45', 16), parseInt('0xcf', 16), - parseInt('0x4a', 16), parseInt('0xde', 16), parseInt('0x79', 16), parseInt('0x8b', 16), parseInt('0x86', 16), parseInt('0x91', 16), parseInt('0xa8', 16), - parseInt('0xe3', 16), parseInt('0x3e', 16), parseInt('0x42', 16), parseInt('0xc6', 16), parseInt('0x51', 16), parseInt('0xf3', 16), parseInt('0x0e', 16), - parseInt('0x12', 16), parseInt('0x36', 16), parseInt('0x5a', 16), parseInt('0xee', 16), parseInt('0x29', 16), parseInt('0x7b', 16), parseInt('0x8d', 16), - parseInt('0x8c', 16), parseInt('0x8f', 16), parseInt('0x8a', 16), parseInt('0x85', 16), parseInt('0x94', 16), parseInt('0xa7', 16), parseInt('0xf2', 16), - parseInt('0x0d', 16), parseInt('0x17', 16), parseInt('0x39', 16), parseInt('0x4b', 16), parseInt('0xdd', 16), parseInt('0x7c', 16), parseInt('0x84', 16), - parseInt('0x97', 16), parseInt('0xa2', 16), parseInt('0xfd', 16), parseInt('0x1c', 16), parseInt('0x24', 16), parseInt('0x6c', 16), parseInt('0xb4', 16), - parseInt('0xc7', 16), parseInt('0x52', 16), parseInt('0xf6', 16), parseInt('0x01', 16), parseInt('0x03', 16), parseInt('0x05', 16), parseInt('0x0f', 16), - parseInt('0x11', 16), parseInt('0x33', 16), parseInt('0x55', 16), parseInt('0xff', 16), parseInt('0x1a', 16), parseInt('0x2e', 16), parseInt('0x72', 16), - parseInt('0x96', 16), parseInt('0xa1', 16), parseInt('0xf8', 16), parseInt('0x13', 16), parseInt('0x35', 16), parseInt('0x5f', 16), parseInt('0xe1', 16), - parseInt('0x38', 16), parseInt('0x48', 16), parseInt('0xd8', 16), parseInt('0x73', 16), parseInt('0x95', 16), parseInt('0xa4', 16), parseInt('0xf7', 16), - parseInt('0x02', 16), parseInt('0x06', 16), parseInt('0x0a', 16), parseInt('0x1e', 16), parseInt('0x22', 16), parseInt('0x66', 16), parseInt('0xaa', 16), - parseInt('0xe5', 16), parseInt('0x34', 16), parseInt('0x5c', 16), parseInt('0xe4', 16), parseInt('0x37', 16), parseInt('0x59', 16), parseInt('0xeb', 16), - parseInt('0x26', 16), parseInt('0x6a', 16), parseInt('0xbe', 16), parseInt('0xd9', 16), parseInt('0x70', 16), parseInt('0x90', 16), parseInt('0xab', 16), - parseInt('0xe6', 16), parseInt('0x31', 16), parseInt('0x53', 16), parseInt('0xf5', 16), parseInt('0x04', 16), parseInt('0x0c', 16), parseInt('0x14', 16), - parseInt('0x3c', 16), parseInt('0x44', 16), parseInt('0xcc', 16), parseInt('0x4f', 16), parseInt('0xd1', 16), parseInt('0x68', 16), parseInt('0xb8', 16), - parseInt('0xd3', 16), parseInt('0x6e', 16), parseInt('0xb2', 16), parseInt('0xcd', 16), parseInt('0x4c', 16), parseInt('0xd4', 16), parseInt('0x67', 16), - parseInt('0xa9', 16), parseInt('0xe0', 16), parseInt('0x3b', 16), parseInt('0x4d', 16), parseInt('0xd7', 16), parseInt('0x62', 16), parseInt('0xa6', 16), - parseInt('0xf1', 16), parseInt('0x08', 16), parseInt('0x18', 16), parseInt('0x28', 16), parseInt('0x78', 16), parseInt('0x88', 16), parseInt('0x83', 16), - parseInt('0x9e', 16), parseInt('0xb9', 16), parseInt('0xd0', 16), parseInt('0x6b', 16), parseInt('0xbd', 16), parseInt('0xdc', 16), parseInt('0x7f', 16), - parseInt('0x81', 16), parseInt('0x98', 16), parseInt('0xb3', 16), parseInt('0xce', 16), parseInt('0x49', 16), parseInt('0xdb', 16), parseInt('0x76', 16), - parseInt('0x9a', 16), parseInt('0xb5', 16), parseInt('0xc4', 16), parseInt('0x57', 16), parseInt('0xf9', 16), parseInt('0x10', 16), parseInt('0x30', 16), - parseInt('0x50', 16), parseInt('0xf0', 16), parseInt('0x0b', 16), parseInt('0x1d', 16), parseInt('0x27', 16), parseInt('0x69', 16), parseInt('0xbb', 16), - parseInt('0xd6', 16), parseInt('0x61', 16), parseInt('0xa3', 16), parseInt('0xfe', 16), parseInt('0x19', 16), parseInt('0x2b', 16), parseInt('0x7d', 16), - parseInt('0x87', 16), parseInt('0x92', 16), parseInt('0xad', 16), parseInt('0xec', 16), parseInt('0x2f', 16), parseInt('0x71', 16), parseInt('0x93', 16), - parseInt('0xae', 16), parseInt('0xe9', 16), parseInt('0x20', 16), parseInt('0x60', 16), parseInt('0xa0', 16), parseInt('0xfb', 16), parseInt('0x16', 16), - parseInt('0x3a', 16), parseInt('0x4e', 16), parseInt('0xd2', 16), parseInt('0x6d', 16), parseInt('0xb7', 16), parseInt('0xc2', 16), parseInt('0x5d', 16), - parseInt('0xe7', 16), parseInt('0x32', 16), parseInt('0x56', 16), parseInt('0xfa', 16), parseInt('0x15', 16), parseInt('0x3f', 16), parseInt('0x41', 16), - parseInt('0xc3', 16), parseInt('0x5e', 16), parseInt('0xe2', 16), parseInt('0x3d', 16), parseInt('0x47', 16), parseInt('0xc9', 16), parseInt('0x40', 16), - parseInt('0xc0', 16), parseInt('0x5b', 16), parseInt('0xed', 16), parseInt('0x2c', 16), parseInt('0x74', 16), parseInt('0x9c', 16), parseInt('0xbf', 16), - parseInt('0xda', 16), parseInt('0x75', 16), parseInt('0x9f', 16), parseInt('0xba', 16), parseInt('0xd5', 16), parseInt('0x64', 16), parseInt('0xac', 16), - parseInt('0xef', 16), parseInt('0x2a', 16), parseInt('0x7e', 16), parseInt('0x82', 16), parseInt('0x9d', 16), parseInt('0xbc', 16), parseInt('0xdf', 16), - parseInt('0x7a', 16), parseInt('0x8e', 16), parseInt('0x89', 16), parseInt('0x80', 16), parseInt('0x9b', 16), parseInt('0xb6', 16), parseInt('0xc1', 16), - parseInt('0x58', 16), parseInt('0xe8', 16), parseInt('0x23', 16), parseInt('0x65', 16), parseInt('0xaf', 16), parseInt('0xea', 16), parseInt('0x25', 16), - parseInt('0x6f', 16), parseInt('0xb1', 16), parseInt('0xc8', 16), parseInt('0x43', 16), parseInt('0xc5', 16), parseInt('0x54', 16), parseInt('0xfc', 16), - parseInt('0x1f', 16), parseInt('0x21', 16), parseInt('0x63', 16), parseInt('0xa5', 16), parseInt('0xf4', 16), parseInt('0x07', 16), parseInt('0x09', 16), - parseInt('0x1b', 16), parseInt('0x2d', 16), parseInt('0x77', 16), parseInt('0x99', 16), parseInt('0xb0', 16), parseInt('0xcb', 16), parseInt('0x46', 16), - parseInt('0xca', 16), parseInt('0x45', 16), parseInt('0xcf', 16), parseInt('0x4a', 16), parseInt('0xde', 16), parseInt('0x79', 16), parseInt('0x8b', 16), - parseInt('0x86', 16), parseInt('0x91', 16), parseInt('0xa8', 16), parseInt('0xe3', 16), parseInt('0x3e', 16), parseInt('0x42', 16), parseInt('0xc6', 16), - parseInt('0x51', 16), parseInt('0xf3', 16), parseInt('0x0e', 16), parseInt('0x12', 16), parseInt('0x36', 16), parseInt('0x5a', 16), parseInt('0xee', 16), - parseInt('0x29', 16), parseInt('0x7b', 16), parseInt('0x8d', 16), parseInt('0x8c', 16), parseInt('0x8f', 16), parseInt('0x8a', 16), parseInt('0x85', 16), - parseInt('0x94', 16), parseInt('0xa7', 16), parseInt('0xf2', 16), parseInt('0x0d', 16), parseInt('0x17', 16), parseInt('0x39', 16), parseInt('0x4b', 16), - parseInt('0xdd', 16), parseInt('0x7c', 16), parseInt('0x84', 16), parseInt('0x97', 16), parseInt('0xa2', 16), parseInt('0xfd', 16), parseInt('0x1c', 16), - parseInt('0x24', 16), parseInt('0x6c', 16), parseInt('0xb4', 16), parseInt('0xc7', 16), parseInt('0x52', 16), parseInt('0xf6', 16), + 0x01, 0x03, 0x05, 0x0f, 0x11, 0x33, 0x55, + 0xff, 0x1a, 0x2e, 0x72, 0x96, 0xa1, 0xf8, + 0x13, 0x35, 0x5f, 0xe1, 0x38, 0x48, 0xd8, + 0x73, 0x95, 0xa4, 0xf7, 0x02, 0x06, 0x0a, + 0x1e, 0x22, 0x66, 0xaa, 0xe5, 0x34, 0x5c, + 0xe4, 0x37, 0x59, 0xeb, 0x26, 0x6a, 0xbe, + 0xd9, 0x70, 0x90, 0xab, 0xe6, 0x31, 0x53, + 0xf5, 0x04, 0x0c, 0x14, 0x3c, 0x44, 0xcc, + 0x4f, 0xd1, 0x68, 0xb8, 0xd3, 0x6e, 0xb2, + 0xcd, 0x4c, 0xd4, 0x67, 0xa9, 0xe0, 0x3b, + 0x4d, 0xd7, 0x62, 0xa6, 0xf1, 0x08, 0x18, + 0x28, 0x78, 0x88, 0x83, 0x9e, 0xb9, 0xd0, + 0x6b, 0xbd, 0xdc, 0x7f, 0x81, 0x98, 0xb3, + 0xce, 0x49, 0xdb, 0x76, 0x9a, 0xb5, 0xc4, + 0x57, 0xf9, 0x10, 0x30, 0x50, 0xf0, 0x0b, + 0x1d, 0x27, 0x69, 0xbb, 0xd6, 0x61, 0xa3, + 0xfe, 0x19, 0x2b, 0x7d, 0x87, 0x92, 0xad, + 0xec, 0x2f, 0x71, 0x93, 0xae, 0xe9, 0x20, + 0x60, 0xa0, 0xfb, 0x16, 0x3a, 0x4e, 0xd2, + 0x6d, 0xb7, 0xc2, 0x5d, 0xe7, 0x32, 0x56, + 0xfa, 0x15, 0x3f, 0x41, 0xc3, 0x5e, 0xe2, + 0x3d, 0x47, 0xc9, 0x40, 0xc0, 0x5b, 0xed, + 0x2c, 0x74, 0x9c, 0xbf, 0xda, 0x75, 0x9f, + 0xba, 0xd5, 0x64, 0xac, 0xef, 0x2a, 0x7e, + 0x82, 0x9d, 0xbc, 0xdf, 0x7a, 0x8e, 0x89, + 0x80, 0x9b, 0xb6, 0xc1, 0x58, 0xe8, 0x23, + 0x65, 0xaf, 0xea, 0x25, 0x6f, 0xb1, 0xc8, + 0x43, 0xc5, 0x54, 0xfc, 0x1f, 0x21, 0x63, + 0xa5, 0xf4, 0x07, 0x09, 0x1b, 0x2d, 0x77, + 0x99, 0xb0, 0xcb, 0x46, 0xca, 0x45, 0xcf, + 0x4a, 0xde, 0x79, 0x8b, 0x86, 0x91, 0xa8, + 0xe3, 0x3e, 0x42, 0xc6, 0x51, 0xf3, 0x0e, + 0x12, 0x36, 0x5a, 0xee, 0x29, 0x7b, 0x8d, + 0x8c, 0x8f, 0x8a, 0x85, 0x94, 0xa7, 0xf2, + 0x0d, 0x17, 0x39, 0x4b, 0xdd, 0x7c, 0x84, + 0x97, 0xa2, 0xfd, 0x1c, 0x24, 0x6c, 0xb4, + 0xc7, 0x52, 0xf6, 0x01, 0x03, 0x05, 0x0f, + 0x11, 0x33, 0x55, 0xff, 0x1a, 0x2e, 0x72, + 0x96, 0xa1, 0xf8, 0x13, 0x35, 0x5f, 0xe1, + 0x38, 0x48, 0xd8, 0x73, 0x95, 0xa4, 0xf7, + 0x02, 0x06, 0x0a, 0x1e, 0x22, 0x66, 0xaa, + 0xe5, 0x34, 0x5c, 0xe4, 0x37, 0x59, 0xeb, + 0x26, 0x6a, 0xbe, 0xd9, 0x70, 0x90, 0xab, + 0xe6, 0x31, 0x53, 0xf5, 0x04, 0x0c, 0x14, + 0x3c, 0x44, 0xcc, 0x4f, 0xd1, 0x68, 0xb8, + 0xd3, 0x6e, 0xb2, 0xcd, 0x4c, 0xd4, 0x67, + 0xa9, 0xe0, 0x3b, 0x4d, 0xd7, 0x62, 0xa6, + 0xf1, 0x08, 0x18, 0x28, 0x78, 0x88, 0x83, + 0x9e, 0xb9, 0xd0, 0x6b, 0xbd, 0xdc, 0x7f, + 0x81, 0x98, 0xb3, 0xce, 0x49, 0xdb, 0x76, + 0x9a, 0xb5, 0xc4, 0x57, 0xf9, 0x10, 0x30, + 0x50, 0xf0, 0x0b, 0x1d, 0x27, 0x69, 0xbb, + 0xd6, 0x61, 0xa3, 0xfe, 0x19, 0x2b, 0x7d, + 0x87, 0x92, 0xad, 0xec, 0x2f, 0x71, 0x93, + 0xae, 0xe9, 0x20, 0x60, 0xa0, 0xfb, 0x16, + 0x3a, 0x4e, 0xd2, 0x6d, 0xb7, 0xc2, 0x5d, + 0xe7, 0x32, 0x56, 0xfa, 0x15, 0x3f, 0x41, + 0xc3, 0x5e, 0xe2, 0x3d, 0x47, 0xc9, 0x40, + 0xc0, 0x5b, 0xed, 0x2c, 0x74, 0x9c, 0xbf, + 0xda, 0x75, 0x9f, 0xba, 0xd5, 0x64, 0xac, + 0xef, 0x2a, 0x7e, 0x82, 0x9d, 0xbc, 0xdf, + 0x7a, 0x8e, 0x89, 0x80, 0x9b, 0xb6, 0xc1, + 0x58, 0xe8, 0x23, 0x65, 0xaf, 0xea, 0x25, + 0x6f, 0xb1, 0xc8, 0x43, 0xc5, 0x54, 0xfc, + 0x1f, 0x21, 0x63, 0xa5, 0xf4, 0x07, 0x09, + 0x1b, 0x2d, 0x77, 0x99, 0xb0, 0xcb, 0x46, + 0xca, 0x45, 0xcf, 0x4a, 0xde, 0x79, 0x8b, + 0x86, 0x91, 0xa8, 0xe3, 0x3e, 0x42, 0xc6, + 0x51, 0xf3, 0x0e, 0x12, 0x36, 0x5a, 0xee, + 0x29, 0x7b, 0x8d, 0x8c, 0x8f, 0x8a, 0x85, + 0x94, 0xa7, 0xf2, 0x0d, 0x17, 0x39, 0x4b, + 0xdd, 0x7c, 0x84, 0x97, 0xa2, 0xfd, 0x1c, + 0x24, 0x6c, 0xb4, 0xc7, 0x52, 0xf6, ]); const mul = function(a, b) { From b8b64d15bef2f2a784ce4502f517bacbb0d135fc Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 20:02:17 +0100 Subject: [PATCH 42/78] no prettier formatting and no fixing --- .eslintrc | 6 ++---- package.json | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.eslintrc b/.eslintrc index daf08d4..397702a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,14 +5,12 @@ "es6": true, "node": true }, - "extends": ["eslint:recommended", "plugin:prettier/recommended"], + "extends": ["eslint:recommended"], "parserOptions": { "sourceType": "module", "ecmaVersion": 2018 }, "rules": { - "linebreak-style": ["error", "unix"], - "react-hooks/rules-of-hooks": "error", - "react-hooks/exhaustive-deps": "warn" + "linebreak-style": ["error", "unix"] } } \ No newline at end of file diff --git a/package.json b/package.json index 6a570a1..da81e5e 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "test": "tape src/test/js/GF256Tests.js src/test/js/SchemeTests.js", "testwithjava": "node --jvm --vm.cp=./target/classes:./target/test-classes src/test/js/PolygotTests.js", - "lint": "eslint --fix ./src/main/js/GF256.js ./src/main/js/Scheme.js && echo 'Lint complete.'" + "lint": "eslint ./src/main/js/GF256.js ./src/main/js/Scheme.js && echo 'Lint complete.'" }, "repository": { "type": "git", From edca28c1197564c0fe11aabf5571d82eff0c3141 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 20:04:44 +0100 Subject: [PATCH 43/78] eslint fix unnames functions --- src/main/js/GF256.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index 57bfccc..14bd96c 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -14,7 +14,7 @@ * limitations under the License. */ -const add = function(a, b) { +function add(a, b) { return a ^ b; }; @@ -147,7 +147,7 @@ const EXP = new Uint8Array([ 0x24, 0x6c, 0xb4, 0xc7, 0x52, 0xf6, ]); -const mul = function(a, b) { +function mul(a, b) { if (a == 0 || b == 0) { return 0; } @@ -156,14 +156,14 @@ const mul = function(a, b) { exports.mul = mul; -const div = function(a, b) { +function div(a, b) { // multiply by the inverse of b return mul(a, EXP[255 - LOG[b]]); }; exports.div = div; -const degree = function(p) { +function degree(p) { for (let i = p.length - 1; i >= 1; i--) { if (p[i] != 0) { return i; From e7a3c6a465456d30ef8106056acdac51adc916c2 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 20:18:48 +0100 Subject: [PATCH 44/78] fix all the eslint --- src/main/js/GF256.js | 274 ++++++++++++++++++++++--------------------- 1 file changed, 143 insertions(+), 131 deletions(-) diff --git a/src/main/js/GF256.js b/src/main/js/GF256.js index 14bd96c..af14e9e 100644 --- a/src/main/js/GF256.js +++ b/src/main/js/GF256.js @@ -14,163 +14,165 @@ * limitations under the License. */ +/* eslint-disable no-bitwise */ function add(a, b) { return a ^ b; -}; +} exports.add = add; /* The Laws of Cryptograhy with Java Code by Neal R. Wagner http://www.cs.utsa.edu/~wagner/lawsbookcolor/laws.pdf -Page 120 (134) section "20.3 Addition in GP(2^n)" is equal -to subtraction. +Page 120 (134) section "20.3 Addition in GP(2^n)" is equal \ +to subtraction. */ const sub = add; exports.sub = exports.add; const LOG = new Uint8Array([ - 0xff, 0x00, 0x19, 0x01, 0x32, 0x02, 0x1a, - 0xc6, 0x4b, 0xc7, 0x1b, 0x68, 0x33, 0xee, - 0xdf, 0x03, 0x64, 0x04, 0xe0, 0x0e, 0x34, - 0x8d, 0x81, 0xef, 0x4c, 0x71, 0x08, 0xc8, - 0xf8, 0x69, 0x1c, 0xc1, 0x7d, 0xc2, 0x1d, - 0xb5, 0xf9, 0xb9, 0x27, 0x6a, 0x4d, 0xe4, - 0xa6, 0x72, 0x9a, 0xc9, 0x09, 0x78, 0x65, - 0x2f, 0x8a, 0x05, 0x21, 0x0f, 0xe1, 0x24, - 0x12, 0xf0, 0x82, 0x45, 0x35, 0x93, 0xda, - 0x8e, 0x96, 0x8f, 0xdb, 0xbd, 0x36, 0xd0, - 0xce, 0x94, 0x13, 0x5c, 0xd2, 0xf1, 0x40, - 0x46, 0x83, 0x38, 0x66, 0xdd, 0xfd, 0x30, - 0xbf, 0x06, 0x8b, 0x62, 0xb3, 0x25, 0xe2, - 0x98, 0x22, 0x88, 0x91, 0x10, 0x7e, 0x6e, - 0x48, 0xc3, 0xa3, 0xb6, 0x1e, 0x42, 0x3a, - 0x6b, 0x28, 0x54, 0xfa, 0x85, 0x3d, 0xba, - 0x2b, 0x79, 0x0a, 0x15, 0x9b, 0x9f, 0x5e, - 0xca, 0x4e, 0xd4, 0xac, 0xe5, 0xf3, 0x73, - 0xa7, 0x57, 0xaf, 0x58, 0xa8, 0x50, 0xf4, - 0xea, 0xd6, 0x74, 0x4f, 0xae, 0xe9, 0xd5, - 0xe7, 0xe6, 0xad, 0xe8, 0x2c, 0xd7, 0x75, - 0x7a, 0xeb, 0x16, 0x0b, 0xf5, 0x59, 0xcb, - 0x5f, 0xb0, 0x9c, 0xa9, 0x51, 0xa0, 0x7f, - 0x0c, 0xf6, 0x6f, 0x17, 0xc4, 0x49, 0xec, - 0xd8, 0x43, 0x1f, 0x2d, 0xa4, 0x76, 0x7b, - 0xb7, 0xcc, 0xbb, 0x3e, 0x5a, 0xfb, 0x60, - 0xb1, 0x86, 0x3b, 0x52, 0xa1, 0x6c, 0xaa, - 0x55, 0x29, 0x9d, 0x97, 0xb2, 0x87, 0x90, - 0x61, 0xbe, 0xdc, 0xfc, 0xbc, 0x95, 0xcf, - 0xcd, 0x37, 0x3f, 0x5b, 0xd1, 0x53, 0x39, - 0x84, 0x3c, 0x41, 0xa2, 0x6d, 0x47, 0x14, - 0x2a, 0x9e, 0x5d, 0x56, 0xf2, 0xd3, 0xab, - 0x44, 0x11, 0x92, 0xd9, 0x23, 0x20, 0x2e, - 0x89, 0xb4, 0x7c, 0xb8, 0x26, 0x77, 0x99, - 0xe3, 0xa5, 0x67, 0x4a, 0xed, 0xde, 0xc5, - 0x31, 0xfe, 0x18, 0x0d, 0x63, 0x8c, 0x80, - 0xc0, 0xf7, 0x70, 0x07, - ]); - -/* https://crypto.stackexchange.com/a/21174/13860 + 0xff, 0x00, 0x19, 0x01, 0x32, 0x02, 0x1a, + 0xc6, 0x4b, 0xc7, 0x1b, 0x68, 0x33, 0xee, + 0xdf, 0x03, 0x64, 0x04, 0xe0, 0x0e, 0x34, + 0x8d, 0x81, 0xef, 0x4c, 0x71, 0x08, 0xc8, + 0xf8, 0x69, 0x1c, 0xc1, 0x7d, 0xc2, 0x1d, + 0xb5, 0xf9, 0xb9, 0x27, 0x6a, 0x4d, 0xe4, + 0xa6, 0x72, 0x9a, 0xc9, 0x09, 0x78, 0x65, + 0x2f, 0x8a, 0x05, 0x21, 0x0f, 0xe1, 0x24, + 0x12, 0xf0, 0x82, 0x45, 0x35, 0x93, 0xda, + 0x8e, 0x96, 0x8f, 0xdb, 0xbd, 0x36, 0xd0, + 0xce, 0x94, 0x13, 0x5c, 0xd2, 0xf1, 0x40, + 0x46, 0x83, 0x38, 0x66, 0xdd, 0xfd, 0x30, + 0xbf, 0x06, 0x8b, 0x62, 0xb3, 0x25, 0xe2, + 0x98, 0x22, 0x88, 0x91, 0x10, 0x7e, 0x6e, + 0x48, 0xc3, 0xa3, 0xb6, 0x1e, 0x42, 0x3a, + 0x6b, 0x28, 0x54, 0xfa, 0x85, 0x3d, 0xba, + 0x2b, 0x79, 0x0a, 0x15, 0x9b, 0x9f, 0x5e, + 0xca, 0x4e, 0xd4, 0xac, 0xe5, 0xf3, 0x73, + 0xa7, 0x57, 0xaf, 0x58, 0xa8, 0x50, 0xf4, + 0xea, 0xd6, 0x74, 0x4f, 0xae, 0xe9, 0xd5, + 0xe7, 0xe6, 0xad, 0xe8, 0x2c, 0xd7, 0x75, + 0x7a, 0xeb, 0x16, 0x0b, 0xf5, 0x59, 0xcb, + 0x5f, 0xb0, 0x9c, 0xa9, 0x51, 0xa0, 0x7f, + 0x0c, 0xf6, 0x6f, 0x17, 0xc4, 0x49, 0xec, + 0xd8, 0x43, 0x1f, 0x2d, 0xa4, 0x76, 0x7b, + 0xb7, 0xcc, 0xbb, 0x3e, 0x5a, 0xfb, 0x60, + 0xb1, 0x86, 0x3b, 0x52, 0xa1, 0x6c, 0xaa, + 0x55, 0x29, 0x9d, 0x97, 0xb2, 0x87, 0x90, + 0x61, 0xbe, 0xdc, 0xfc, 0xbc, 0x95, 0xcf, + 0xcd, 0x37, 0x3f, 0x5b, 0xd1, 0x53, 0x39, + 0x84, 0x3c, 0x41, 0xa2, 0x6d, 0x47, 0x14, + 0x2a, 0x9e, 0x5d, 0x56, 0xf2, 0xd3, 0xab, + 0x44, 0x11, 0x92, 0xd9, 0x23, 0x20, 0x2e, + 0x89, 0xb4, 0x7c, 0xb8, 0x26, 0x77, 0x99, + 0xe3, 0xa5, 0x67, 0x4a, 0xed, 0xde, 0xc5, + 0x31, 0xfe, 0x18, 0x0d, 0x63, 0x8c, 0x80, + 0xc0, 0xf7, 0x70, 0x07, +]); + +/* https://crypto.stackexchange.com/a/21174/13860 */ const EXP = new Uint8Array([ - 0x01, 0x03, 0x05, 0x0f, 0x11, 0x33, 0x55, - 0xff, 0x1a, 0x2e, 0x72, 0x96, 0xa1, 0xf8, - 0x13, 0x35, 0x5f, 0xe1, 0x38, 0x48, 0xd8, - 0x73, 0x95, 0xa4, 0xf7, 0x02, 0x06, 0x0a, - 0x1e, 0x22, 0x66, 0xaa, 0xe5, 0x34, 0x5c, - 0xe4, 0x37, 0x59, 0xeb, 0x26, 0x6a, 0xbe, - 0xd9, 0x70, 0x90, 0xab, 0xe6, 0x31, 0x53, - 0xf5, 0x04, 0x0c, 0x14, 0x3c, 0x44, 0xcc, - 0x4f, 0xd1, 0x68, 0xb8, 0xd3, 0x6e, 0xb2, - 0xcd, 0x4c, 0xd4, 0x67, 0xa9, 0xe0, 0x3b, - 0x4d, 0xd7, 0x62, 0xa6, 0xf1, 0x08, 0x18, - 0x28, 0x78, 0x88, 0x83, 0x9e, 0xb9, 0xd0, - 0x6b, 0xbd, 0xdc, 0x7f, 0x81, 0x98, 0xb3, - 0xce, 0x49, 0xdb, 0x76, 0x9a, 0xb5, 0xc4, - 0x57, 0xf9, 0x10, 0x30, 0x50, 0xf0, 0x0b, - 0x1d, 0x27, 0x69, 0xbb, 0xd6, 0x61, 0xa3, - 0xfe, 0x19, 0x2b, 0x7d, 0x87, 0x92, 0xad, - 0xec, 0x2f, 0x71, 0x93, 0xae, 0xe9, 0x20, - 0x60, 0xa0, 0xfb, 0x16, 0x3a, 0x4e, 0xd2, - 0x6d, 0xb7, 0xc2, 0x5d, 0xe7, 0x32, 0x56, - 0xfa, 0x15, 0x3f, 0x41, 0xc3, 0x5e, 0xe2, - 0x3d, 0x47, 0xc9, 0x40, 0xc0, 0x5b, 0xed, - 0x2c, 0x74, 0x9c, 0xbf, 0xda, 0x75, 0x9f, - 0xba, 0xd5, 0x64, 0xac, 0xef, 0x2a, 0x7e, - 0x82, 0x9d, 0xbc, 0xdf, 0x7a, 0x8e, 0x89, - 0x80, 0x9b, 0xb6, 0xc1, 0x58, 0xe8, 0x23, - 0x65, 0xaf, 0xea, 0x25, 0x6f, 0xb1, 0xc8, - 0x43, 0xc5, 0x54, 0xfc, 0x1f, 0x21, 0x63, - 0xa5, 0xf4, 0x07, 0x09, 0x1b, 0x2d, 0x77, - 0x99, 0xb0, 0xcb, 0x46, 0xca, 0x45, 0xcf, - 0x4a, 0xde, 0x79, 0x8b, 0x86, 0x91, 0xa8, - 0xe3, 0x3e, 0x42, 0xc6, 0x51, 0xf3, 0x0e, - 0x12, 0x36, 0x5a, 0xee, 0x29, 0x7b, 0x8d, - 0x8c, 0x8f, 0x8a, 0x85, 0x94, 0xa7, 0xf2, - 0x0d, 0x17, 0x39, 0x4b, 0xdd, 0x7c, 0x84, - 0x97, 0xa2, 0xfd, 0x1c, 0x24, 0x6c, 0xb4, - 0xc7, 0x52, 0xf6, 0x01, 0x03, 0x05, 0x0f, - 0x11, 0x33, 0x55, 0xff, 0x1a, 0x2e, 0x72, - 0x96, 0xa1, 0xf8, 0x13, 0x35, 0x5f, 0xe1, - 0x38, 0x48, 0xd8, 0x73, 0x95, 0xa4, 0xf7, - 0x02, 0x06, 0x0a, 0x1e, 0x22, 0x66, 0xaa, - 0xe5, 0x34, 0x5c, 0xe4, 0x37, 0x59, 0xeb, - 0x26, 0x6a, 0xbe, 0xd9, 0x70, 0x90, 0xab, - 0xe6, 0x31, 0x53, 0xf5, 0x04, 0x0c, 0x14, - 0x3c, 0x44, 0xcc, 0x4f, 0xd1, 0x68, 0xb8, - 0xd3, 0x6e, 0xb2, 0xcd, 0x4c, 0xd4, 0x67, - 0xa9, 0xe0, 0x3b, 0x4d, 0xd7, 0x62, 0xa6, - 0xf1, 0x08, 0x18, 0x28, 0x78, 0x88, 0x83, - 0x9e, 0xb9, 0xd0, 0x6b, 0xbd, 0xdc, 0x7f, - 0x81, 0x98, 0xb3, 0xce, 0x49, 0xdb, 0x76, - 0x9a, 0xb5, 0xc4, 0x57, 0xf9, 0x10, 0x30, - 0x50, 0xf0, 0x0b, 0x1d, 0x27, 0x69, 0xbb, - 0xd6, 0x61, 0xa3, 0xfe, 0x19, 0x2b, 0x7d, - 0x87, 0x92, 0xad, 0xec, 0x2f, 0x71, 0x93, - 0xae, 0xe9, 0x20, 0x60, 0xa0, 0xfb, 0x16, - 0x3a, 0x4e, 0xd2, 0x6d, 0xb7, 0xc2, 0x5d, - 0xe7, 0x32, 0x56, 0xfa, 0x15, 0x3f, 0x41, - 0xc3, 0x5e, 0xe2, 0x3d, 0x47, 0xc9, 0x40, - 0xc0, 0x5b, 0xed, 0x2c, 0x74, 0x9c, 0xbf, - 0xda, 0x75, 0x9f, 0xba, 0xd5, 0x64, 0xac, - 0xef, 0x2a, 0x7e, 0x82, 0x9d, 0xbc, 0xdf, - 0x7a, 0x8e, 0x89, 0x80, 0x9b, 0xb6, 0xc1, - 0x58, 0xe8, 0x23, 0x65, 0xaf, 0xea, 0x25, - 0x6f, 0xb1, 0xc8, 0x43, 0xc5, 0x54, 0xfc, - 0x1f, 0x21, 0x63, 0xa5, 0xf4, 0x07, 0x09, - 0x1b, 0x2d, 0x77, 0x99, 0xb0, 0xcb, 0x46, - 0xca, 0x45, 0xcf, 0x4a, 0xde, 0x79, 0x8b, - 0x86, 0x91, 0xa8, 0xe3, 0x3e, 0x42, 0xc6, - 0x51, 0xf3, 0x0e, 0x12, 0x36, 0x5a, 0xee, - 0x29, 0x7b, 0x8d, 0x8c, 0x8f, 0x8a, 0x85, - 0x94, 0xa7, 0xf2, 0x0d, 0x17, 0x39, 0x4b, - 0xdd, 0x7c, 0x84, 0x97, 0xa2, 0xfd, 0x1c, - 0x24, 0x6c, 0xb4, 0xc7, 0x52, 0xf6, - ]); + 0x01, 0x03, 0x05, 0x0f, 0x11, 0x33, 0x55, + 0xff, 0x1a, 0x2e, 0x72, 0x96, 0xa1, 0xf8, + 0x13, 0x35, 0x5f, 0xe1, 0x38, 0x48, 0xd8, + 0x73, 0x95, 0xa4, 0xf7, 0x02, 0x06, 0x0a, + 0x1e, 0x22, 0x66, 0xaa, 0xe5, 0x34, 0x5c, + 0xe4, 0x37, 0x59, 0xeb, 0x26, 0x6a, 0xbe, + 0xd9, 0x70, 0x90, 0xab, 0xe6, 0x31, 0x53, + 0xf5, 0x04, 0x0c, 0x14, 0x3c, 0x44, 0xcc, + 0x4f, 0xd1, 0x68, 0xb8, 0xd3, 0x6e, 0xb2, + 0xcd, 0x4c, 0xd4, 0x67, 0xa9, 0xe0, 0x3b, + 0x4d, 0xd7, 0x62, 0xa6, 0xf1, 0x08, 0x18, + 0x28, 0x78, 0x88, 0x83, 0x9e, 0xb9, 0xd0, + 0x6b, 0xbd, 0xdc, 0x7f, 0x81, 0x98, 0xb3, + 0xce, 0x49, 0xdb, 0x76, 0x9a, 0xb5, 0xc4, + 0x57, 0xf9, 0x10, 0x30, 0x50, 0xf0, 0x0b, + 0x1d, 0x27, 0x69, 0xbb, 0xd6, 0x61, 0xa3, + 0xfe, 0x19, 0x2b, 0x7d, 0x87, 0x92, 0xad, + 0xec, 0x2f, 0x71, 0x93, 0xae, 0xe9, 0x20, + 0x60, 0xa0, 0xfb, 0x16, 0x3a, 0x4e, 0xd2, + 0x6d, 0xb7, 0xc2, 0x5d, 0xe7, 0x32, 0x56, + 0xfa, 0x15, 0x3f, 0x41, 0xc3, 0x5e, 0xe2, + 0x3d, 0x47, 0xc9, 0x40, 0xc0, 0x5b, 0xed, + 0x2c, 0x74, 0x9c, 0xbf, 0xda, 0x75, 0x9f, + 0xba, 0xd5, 0x64, 0xac, 0xef, 0x2a, 0x7e, + 0x82, 0x9d, 0xbc, 0xdf, 0x7a, 0x8e, 0x89, + 0x80, 0x9b, 0xb6, 0xc1, 0x58, 0xe8, 0x23, + 0x65, 0xaf, 0xea, 0x25, 0x6f, 0xb1, 0xc8, + 0x43, 0xc5, 0x54, 0xfc, 0x1f, 0x21, 0x63, + 0xa5, 0xf4, 0x07, 0x09, 0x1b, 0x2d, 0x77, + 0x99, 0xb0, 0xcb, 0x46, 0xca, 0x45, 0xcf, + 0x4a, 0xde, 0x79, 0x8b, 0x86, 0x91, 0xa8, + 0xe3, 0x3e, 0x42, 0xc6, 0x51, 0xf3, 0x0e, + 0x12, 0x36, 0x5a, 0xee, 0x29, 0x7b, 0x8d, + 0x8c, 0x8f, 0x8a, 0x85, 0x94, 0xa7, 0xf2, + 0x0d, 0x17, 0x39, 0x4b, 0xdd, 0x7c, 0x84, + 0x97, 0xa2, 0xfd, 0x1c, 0x24, 0x6c, 0xb4, + 0xc7, 0x52, 0xf6, 0x01, 0x03, 0x05, 0x0f, + 0x11, 0x33, 0x55, 0xff, 0x1a, 0x2e, 0x72, + 0x96, 0xa1, 0xf8, 0x13, 0x35, 0x5f, 0xe1, + 0x38, 0x48, 0xd8, 0x73, 0x95, 0xa4, 0xf7, + 0x02, 0x06, 0x0a, 0x1e, 0x22, 0x66, 0xaa, + 0xe5, 0x34, 0x5c, 0xe4, 0x37, 0x59, 0xeb, + 0x26, 0x6a, 0xbe, 0xd9, 0x70, 0x90, 0xab, + 0xe6, 0x31, 0x53, 0xf5, 0x04, 0x0c, 0x14, + 0x3c, 0x44, 0xcc, 0x4f, 0xd1, 0x68, 0xb8, + 0xd3, 0x6e, 0xb2, 0xcd, 0x4c, 0xd4, 0x67, + 0xa9, 0xe0, 0x3b, 0x4d, 0xd7, 0x62, 0xa6, + 0xf1, 0x08, 0x18, 0x28, 0x78, 0x88, 0x83, + 0x9e, 0xb9, 0xd0, 0x6b, 0xbd, 0xdc, 0x7f, + 0x81, 0x98, 0xb3, 0xce, 0x49, 0xdb, 0x76, + 0x9a, 0xb5, 0xc4, 0x57, 0xf9, 0x10, 0x30, + 0x50, 0xf0, 0x0b, 0x1d, 0x27, 0x69, 0xbb, + 0xd6, 0x61, 0xa3, 0xfe, 0x19, 0x2b, 0x7d, + 0x87, 0x92, 0xad, 0xec, 0x2f, 0x71, 0x93, + 0xae, 0xe9, 0x20, 0x60, 0xa0, 0xfb, 0x16, + 0x3a, 0x4e, 0xd2, 0x6d, 0xb7, 0xc2, 0x5d, + 0xe7, 0x32, 0x56, 0xfa, 0x15, 0x3f, 0x41, + 0xc3, 0x5e, 0xe2, 0x3d, 0x47, 0xc9, 0x40, + 0xc0, 0x5b, 0xed, 0x2c, 0x74, 0x9c, 0xbf, + 0xda, 0x75, 0x9f, 0xba, 0xd5, 0x64, 0xac, + 0xef, 0x2a, 0x7e, 0x82, 0x9d, 0xbc, 0xdf, + 0x7a, 0x8e, 0x89, 0x80, 0x9b, 0xb6, 0xc1, + 0x58, 0xe8, 0x23, 0x65, 0xaf, 0xea, 0x25, + 0x6f, 0xb1, 0xc8, 0x43, 0xc5, 0x54, 0xfc, + 0x1f, 0x21, 0x63, 0xa5, 0xf4, 0x07, 0x09, + 0x1b, 0x2d, 0x77, 0x99, 0xb0, 0xcb, 0x46, + 0xca, 0x45, 0xcf, 0x4a, 0xde, 0x79, 0x8b, + 0x86, 0x91, 0xa8, 0xe3, 0x3e, 0x42, 0xc6, + 0x51, 0xf3, 0x0e, 0x12, 0x36, 0x5a, 0xee, + 0x29, 0x7b, 0x8d, 0x8c, 0x8f, 0x8a, 0x85, + 0x94, 0xa7, 0xf2, 0x0d, 0x17, 0x39, 0x4b, + 0xdd, 0x7c, 0x84, 0x97, 0xa2, 0xfd, 0x1c, + 0x24, 0x6c, 0xb4, 0xc7, 0x52, 0xf6, +]); function mul(a, b) { - if (a == 0 || b == 0) { + if (a === 0 || b === 0) { return 0; } return EXP[LOG[a] + LOG[b]]; -}; +} exports.mul = mul; function div(a, b) { // multiply by the inverse of b return mul(a, EXP[255 - LOG[b]]); -}; +} exports.div = div; function degree(p) { + // eslint-disable-next-line no-plusplus for (let i = p.length - 1; i >= 1; i--) { - if (p[i] != 0) { + if (p[i] !== 0) { return i; } } return 0; -}; +} exports.degree = degree; @@ -178,53 +180,63 @@ exports.degree = degree; * Calculates f(0) of the given points using Lagrangian interpolation. * @param {array[Uint8Array]} points The supplied point. */ -exports.interpolate = function(points) { +function interpolate(points) { const x = 0; let y = 0; + // eslint-disable-next-line no-plusplus for (let i = 0; i < points.length; i++) { const aX = points[i][0]; const aY = points[i][1]; let li = 1; + // eslint-disable-next-line no-plusplus for (let j = 0; j < points.length; j++) { const bX = points[j][0]; - if (i != j) { + if (i !== j) { li = mul(li, div(sub(x, bX), sub(aX, bX))); } } y = add(y, mul(li, aY)); } return y; -}; +} + +exports.interpolate = interpolate; /** * Generates a random polynomal of the correct degree and sets x as the first coefficient. - * @param {function int -> array[Uint8Array]} randomBytes Takes a length and returns a Uint8Array of that length. + * @param {function int -> array[Uint8Array]} randomBytes Takes a length and returns a + * Uint8Array of that length. * @param {Number} d The degree of the polynomial driven by the number shares and join threshold. * @param {Number} x The point to hide. * @return {Uint8Array} The random polynomial with x as the fist coefficient. */ -exports.generate = function(randomBytes, d, x) { +function generate(randomBytes, d, x) { let p = null; // generate random polynomials until we find one of the given degree do { p = randomBytes(d + 1); - } while (degree(p) != d); + } while (degree(p) !== d); // set y intercept p[0] = x; return p; -}; +} + +exports.generate = generate; /** * Evaluates a polynomal at point x using Horner's method. * @param {Uint8Array} p The polynomial * @return {Number} x The point to evaluate. */ -exports.eval = function(p, x) { +function evaluate(p, x) { let result = 0; + // eslint-disable-next-line no-plusplus for (let i = p.length - 1; i >= 0; i--) { result = add(mul(result, x), p[i]); } return result; -}; +} + +exports.eval = evaluate; From 8269caf77d76b6403c473fbcf9f346fdced7f63e Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 20:28:16 +0100 Subject: [PATCH 45/78] fixed eslint issues --- src/main/js/Scheme.js | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/main/js/Scheme.js b/src/main/js/Scheme.js index c871dec..c57bd41 100644 --- a/src/main/js/Scheme.js +++ b/src/main/js/Scheme.js @@ -19,22 +19,26 @@ const GF256 = require('./GF256.js'); /** * Splits the given secret into {@code n} parts, of which any {@code k} or more can be combined to * recover the original secret. - * @param {function int -> Uint8Array} randomBytes Takes a length and returns a random Uint8Array of that length + * @param {function int -> Uint8Array} randomBytes Takes a length and returns a random + * Uint8Array of that length * @param {Number} n the number of parts to produce (must be {@code >1}) * @param {Number} k the threshold of joinable parts (must be {@code <= n}) * @param {array[Uint8Array]} secret The secret to split as an array of bytes - * @return {Object.} an map of {@code n} parts that are arrays of bytes of the secret length + * @return {Object.} an map of {@code n} parts that are arrays of bytes of the + * secret length */ -exports.split = function(randomBytes, n, k, secret) { - if (k <= 1) throw 'K must be > 1'; - if (n < k) throw 'N must be >= K'; - if (n > 255) throw 'N must be <= 255'; +function split(randomBytes, n, k, secret) { + if (k <= 1) throw new Error('K must be > 1'); + if (n < k) throw new Error('N must be >= K'); + if (n > 255) throw new Error('N must be <= 255'); const values = new Array(n) .fill(0) .map(() => new Uint8Array(secret.length).fill(0)); + // eslint-disable-next-line no-plusplus for (let i = 0; i < secret.length; i++) { const p = GF256.generate(randomBytes, k - 1, secret[i]); + // eslint-disable-next-line no-plusplus for (let x = 1; x <= n; x++) { values[x - 1][i] = GF256.eval(p, x); } @@ -42,13 +46,16 @@ exports.split = function(randomBytes, n, k, secret) { const parts = {}; + // eslint-disable-next-line no-plusplus for (let i = 0; i < values.length; i++) { const part = `${i + 1}`; parts[part] = values[i]; } return parts; -}; +} + +exports.split = split; /** * Joins the given parts to recover the original secret. @@ -57,23 +64,27 @@ exports.split = function(randomBytes, n, k, secret) { * original secret. If the parts are incorrect, or are under the threshold value used to split the * secret, a random value will be returned. * - * @param {Object.} parts an map of {@code n} parts that are arrays of bytes of the secret length + * @param {Object.} parts an map of {@code n} parts that are arrays of bytes + * of the secret length * @return {Uint8Array} the original secret * */ -exports.join = function(parts) { - if (Object.keys(parts).length == 0) throw 'No parts provided'; +function join(parts) { + if (Object.keys(parts).length === 0) throw new Error('No parts provided'); const lengths = Object.values(parts).map(x => x.length); const max = Math.max.apply(null, lengths); const min = Math.min.apply(null, lengths); - if (max != min) - throw `Varying lengths of part values. Min ${min}, Max ${max}`; + if (max !== min) { + throw new Error(`Varying lengths of part values. Min ${min}, Max ${max}`); + } const secret = new Uint8Array(max); + // eslint-disable-next-line no-plusplus for (let i = 0; i < secret.length; i++) { const keys = Object.keys(parts); const points = new Array(keys.length) .fill(0) .map(() => new Uint8Array(2).fill(0)); + // eslint-disable-next-line no-plusplus for (let j = 0; j < keys.length; j++) { const key = keys[j]; const k = Number(key); @@ -84,4 +95,6 @@ exports.join = function(parts) { } return secret; -}; +} + +exports.join = join; From d11af3d1f4f0bc41565d43ab24d46abf8e07874c Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 20:52:38 +0100 Subject: [PATCH 46/78] lint reformatting of the tests --- src/test/js/GF256Tests.js | 449 ++++++++++++++++++++++++++++-------- src/test/js/PolygotTests.js | 305 ++++++++++++------------ src/test/js/SchemeTests.js | 183 ++++++++------- 3 files changed, 606 insertions(+), 331 deletions(-) diff --git a/src/test/js/GF256Tests.js b/src/test/js/GF256Tests.js index 7acd974..718d86e 100644 --- a/src/test/js/GF256Tests.js +++ b/src/test/js/GF256Tests.js @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,139 +13,394 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* eslint-disable import/no-extraneous-dependencies */ const test = require('tape'); +const { randomBytes } = require('tweetnacl'); const GF256 = require('../../main/js/GF256.js'); -const randomBytes = require('tweetnacl').randomBytes; - -test('GF256Tests add', function (t) { - t.plan(1); - t.equal( GF256.add(100, 30), 122 ); +/* eslint-disable prefer-arrow-callback */ +/* eslint-disable func-names */ +test('GF256Tests add', function(t) { + t.plan(1); + t.equal(GF256.add(100, 30), 122); }); -test('GF256Tests sub', function (t) { - t.plan(1); - t.equal( GF256.sub(100, 30), 122 ); +test('GF256Tests sub', function(t) { + t.plan(1); + t.equal(GF256.sub(100, 30), 122); }); -test('GF256Tests mul', function (t) { - t.plan(4); - t.equal( GF256.mul(90, 21), 254 ); - t.equal( GF256.mul(133, 5), 167 ); - t.equal( GF256.mul(0, 21), 0 ); - t.equal( GF256.mul(parseInt("0xb6"), parseInt("0x53")), parseInt("0x36") ); +test('GF256Tests mul', function(t) { + t.plan(4); + t.equal(GF256.mul(90, 21), 254); + t.equal(GF256.mul(133, 5), 167); + t.equal(GF256.mul(0, 21), 0); + t.equal(GF256.mul(parseInt('0xb6'), parseInt('0x53')), parseInt('0x36')); }); -test('GF256Tests div', function (t) { - t.plan(4); - t.equal( GF256.div(90, 21), 189 ); - t.equal( GF256.div(6, 55), 151 ); - t.equal( GF256.div(22, 192), 138 ); - t.equal( GF256.div(0, 192), 0 ); +test('GF256Tests div', function(t) { + t.plan(4); + t.equal(GF256.div(90, 21), 189); + t.equal(GF256.div(6, 55), 151); + t.equal(GF256.div(22, 192), 138); + t.equal(GF256.div(0, 192), 0); }); -test('GF256Tests degree', function (t) { - t.plan(4); - t.equal( GF256.degree([1, 2]), 1 ); - t.equal( GF256.degree([1, 2, 0]), 1 ); - t.equal( GF256.degree([1, 2, 3]), 2 ); - t.equal( GF256.degree([0, 0, 0]), 0 ); +test('GF256Tests degree', function(t) { + t.plan(4); + t.equal(GF256.degree([1, 2]), 1); + t.equal(GF256.degree([1, 2, 0]), 1); + t.equal(GF256.degree([1, 2, 3]), 2); + t.equal(GF256.degree([0, 0, 0]), 0); }); const bytes = [ - 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45, + 46, + 47, + 48, + 49, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 59, + 60, + 61, + 62, + 63, + 64, + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72, + 73, + 74, + 75, + 76, + 77, + 78, + 79, + 80, + 81, + 82, + 83, + 84, + 85, + 86, + 87, + 88, + 89, + 90, + 91, + 92, + 93, + 94, + 95, + 96, + 97, + 98, + 99, + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110, + 111, + 112, + 113, + 114, + 115, + 116, + 117, + 118, + 119, + 120, + 121, + 122, + 123, + 124, + 125, + 126, + 127, + 128, + 129, + 130, + 131, + 132, + 133, + 134, + 135, + 136, + 137, + 138, + 139, + 140, + 141, + 142, + 143, + 144, + 145, + 146, + 147, + 148, + 149, + 150, + 151, + 152, + 153, + 154, + 155, + 156, + 157, + 158, + 159, + 160, + 161, + 162, + 163, + 164, + 165, + 166, + 167, + 168, + 169, + 170, + 171, + 172, + 173, + 174, + 175, + 176, + 177, + 178, + 179, + 180, + 181, + 182, + 183, + 184, + 185, + 186, + 187, + 188, + 189, + 190, + 191, + 192, + 193, + 194, + 195, + 196, + 197, + 198, + 199, + 200, + 201, + 202, + 203, + 204, + 205, + 206, + 207, + 208, + 209, + 210, + 211, + 212, + 213, + 214, + 215, + 216, + 217, + 218, + 219, + 220, + 221, + 222, + 223, + 224, + 225, + 226, + 227, + 228, + 229, + 230, + 231, + 232, + 233, + 234, + 235, + 236, + 237, + 238, + 239, + 240, + 241, + 242, + 243, + 244, + 245, + 246, + 247, + 248, + 249, + 250, + 251, + 252, + 253, + 254, + 255 ]; function makePairs(arr) { - var res = [], - l = arr.length; - for(var i=0; i= 0 ){ - p[p.length-1] = 0; - countDownFrom2--; - } - return p; -} +const zeroLastByteFirstTWoAttemptsRandomBytes = function(length) { + const p = randomBytes(length); + if (countDownFrom2 >= 0) { + p[p.length - 1] = 0; + countDownFrom2--; + } + return p; +}; -test('GF256Tests generate', function (t) { - const p = GF256.generate(zeroLastByteFirstTWoAttemptsRandomBytes, 5, 20); - t.equal( p[0], 20 ); - t.equal( p.length, 6 ); - t.notOk( p[p.length-1] == 0 ); - t.end(); +test('GF256Tests generate', function(t) { + const p = GF256.generate(zeroLastByteFirstTWoAttemptsRandomBytes, 5, 20); + t.equal(p[0], 20); + t.equal(p.length, 6); + t.notOk(p[p.length - 1] == 0); + t.end(); }); -test('GF256Tests eval', function (t) { - t.plan(1); - const v = GF256.eval([1, 0, 2, 3], 2); - t.equal( v, 17 ); -}); \ No newline at end of file +test('GF256Tests eval', function(t) { + t.plan(1); + const v = GF256.eval([1, 0, 2, 3], 2); + t.equal(v, 17); +}); diff --git a/src/test/js/PolygotTests.js b/src/test/js/PolygotTests.js index c766fd9..8b82b2b 100644 --- a/src/test/js/PolygotTests.js +++ b/src/test/js/PolygotTests.js @@ -15,203 +15,224 @@ */ const test = require('tape-catch'); -const randomBytes = require('tweetnacl').randomBytes; +const { randomBytes } = require('tweetnacl'); // https://codereview.stackexchange.com/a/3589/75693 function bytesToSring(bytes) { - var chars = []; - for(var i = 0, n = bytes.length; i < n;) { - chars.push(((bytes[i++] & 0xff) << 8) | (bytes[i++] & 0xff)); - } - return String.fromCharCode.apply(null, chars); + const chars = []; + for (let i = 0, n = bytes.length; i < n; ) { + chars.push(((bytes[i++] & 0xff) << 8) | (bytes[i++] & 0xff)); + } + return String.fromCharCode.apply(null, chars); } // https://codereview.stackexchange.com/a/3589/75693 function stringToBytes(str) { - var bytes = []; - for(var i = 0, n = str.length; i < n; i++) { - var char = str.charCodeAt(i); - bytes.push(char >>> 8, char & 0xFF); - } - return bytes; + const bytes = []; + for (let i = 0, n = str.length; i < n; i++) { + const char = str.charCodeAt(i); + bytes.push(char >>> 8, char & 0xff); + } + return bytes; } -const ByteArray = Java.type("byte[]"); -const Byte = Java.type("java.lang.Byte"); -const JavaScriptUtils = Java.type("com.codahale.shamir.polygot.JavaScriptUtils"); - -var hexChar = ["0", "1", "2", "3", "4", "5", "6", "7","8", "9", "A", "B", "C", "D", "E", "F"]; +const ByteArray = Java.type('byte[]'); +const Byte = Java.type('java.lang.Byte'); +const JavaScriptUtils = Java.type( + 'com.codahale.shamir.polygot.JavaScriptUtils' +); + +const hexChar = [ + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + 'A', + 'B', + 'C', + 'D', + 'E', + 'F' +]; function byteToHex(b) { - return hexChar[(b >> 4) & 0x0f] + hexChar[b & 0x0f]; + return hexChar[(b >> 4) & 0x0f] + hexChar[b & 0x0f]; } - -function jsByteArrayToJavaByteArray(jsarray){ - const jbarray = new ByteArray(jsarray.length); - for( var i = 0; i < jsarray.length; i++){ - jbarray[i] = JavaScriptUtils.unsignedToSignedByteMap.get(jsarray[i]); - }; - return jbarray; +function jsByteArrayToJavaByteArray(jsarray) { + const jbarray = new ByteArray(jsarray.length); + for (let i = 0; i < jsarray.length; i++) { + jbarray[i] = JavaScriptUtils.unsignedToSignedByteMap.get(jsarray[i]); + } + return jbarray; } - -function jBytesArrayToJavaScriptByteArray(barray){ - const jsarray = []; - for ( var i = 0; i < barray.length; i++ ){ - jsarray.push(JavaScriptUtils.signedToUnsignedByteMap.get(barray[i])); - } - return jsarray; +function jBytesArrayToJavaScriptByteArray(barray) { + const jsarray = []; + for (let i = 0; i < barray.length; i++) { + jsarray.push(JavaScriptUtils.signedToUnsignedByteMap.get(barray[i])); + } + return jsarray; } - -test('PolygotTests Java and JavaScript byte array roundtrip', function (t) { - t.plan(1); - const secretUtf8 = `ᚠᛇᚻ`; - const jsBytes = stringToBytes(secretUtf8); - const jbytes = jsByteArrayToJavaByteArray(jsBytes); - const jsRoundTripBytes = jBytesArrayToJavaScriptByteArray(jbytes); - t.equal( secretUtf8, bytesToSring(jsRoundTripBytes) ); +test('PolygotTests Java and JavaScript byte array roundtrip', function(t) { + t.plan(1); + const secretUtf8 = `ᚠᛇᚻ`; + const jsBytes = stringToBytes(secretUtf8); + const jbytes = jsByteArrayToJavaByteArray(jsBytes); + const jsRoundTripBytes = jBytesArrayToJavaScriptByteArray(jbytes); + t.equal(secretUtf8, bytesToSring(jsRoundTripBytes)); }); const Scheme = Java.type('com.codahale.shamir.Scheme'); const SecureRandom = Java.type('java.security.SecureRandom'); const secureRandom = new SecureRandom(); -test('PolygotTests JavaScript strings with all Java logic', function (t) { - t.plan(1); - const scheme = new Scheme(secureRandom, 5, 3); - const secretUtf8 = `ᚠᛇᚻ`; +test('PolygotTests JavaScript strings with all Java logic', function(t) { + t.plan(1); + const scheme = new Scheme(secureRandom, 5, 3); + const secretUtf8 = `ᚠᛇᚻ`; - const parts = scheme.split(jsByteArrayToJavaByteArray(stringToBytes(secretUtf8))); - const joined = scheme.join(parts); + const parts = scheme.split( + jsByteArrayToJavaByteArray(stringToBytes(secretUtf8)) + ); + const joined = scheme.join(parts); - t.equal( secretUtf8, bytesToSring(jBytesArrayToJavaScriptByteArray(joined)) ); + t.equal(secretUtf8, bytesToSring(jBytesArrayToJavaScriptByteArray(joined))); }); -const split = require('../../main/js/Scheme.js').split; +const { split } = require('../../main/js/Scheme.js'); function javaScriptToJavaParts(parts) { - const HashMap = Java.type('java.util.HashMap'); - const map = new HashMap(); - for( var key in parts) { - const bytes = parts[key]; - const jbarr = new jsByteArrayToJavaByteArray(bytes); - map.put(Number(key), jbarr); - } - return map; + const HashMap = Java.type('java.util.HashMap'); + const map = new HashMap(); + for (const key in parts) { + const bytes = parts[key]; + const jbarr = new jsByteArrayToJavaByteArray(bytes); + map.put(Number(key), jbarr); + } + return map; } - function javaToJavaScriptParts(javaMap) { - const result = {} - const entrySetIterator = javaMap.entrySet().iterator(); - while (entrySetIterator.hasNext()) { - const pair = entrySetIterator.next(); - const key = pair.getKey(); - const value = pair.getValue(); - result[key] = jBytesArrayToJavaScriptByteArray(value); - } - return result; + const result = {}; + const entrySetIterator = javaMap.entrySet().iterator(); + while (entrySetIterator.hasNext()) { + const pair = entrySetIterator.next(); + const key = pair.getKey(); + const value = pair.getValue(); + result[key] = jBytesArrayToJavaScriptByteArray(value); + } + return result; } - const Collectors = Java.type('java.util.stream.Collectors'); - -function equalParts( jParts, jsParts){ - // js keys are strings - const jsKeysNumbers = Object.keys(jsParts); - // j keys are java integers that we map to strings - const jKeysSet = jParts.keySet().stream().map( n => n.toString() ).collect(Collectors.toList()); - - // check that all js keys are in the j keys - for( const jsk of jsKeysNumbers ) { - if( !jKeysSet.contains(jsk) ) { - throw `jKeysSet ${jKeysSet} does not contain jsk ${jsk}` - } +function equalParts(jParts, jsParts) { + // js keys are strings + const jsKeysNumbers = Object.keys(jsParts); + // j keys are java integers that we map to strings + const jKeysSet = jParts + .keySet() + .stream() + .map(n => n.toString()) + .collect(Collectors.toList()); + + // check that all js keys are in the j keys + for (const jsk of jsKeysNumbers) { + if (!jKeysSet.contains(jsk)) { + throw `jKeysSet ${jKeysSet} does not contain jsk ${jsk}`; } - - // check that all j keys are in the js keys - for( const jk of jKeysSet ) { - if( !jsKeysNumbers.includes(jk)) { - throw `jsKeysNumbers ${jsKeysNumbers} does not contain jk ${jk}` - } + } + + // check that all j keys are in the js keys + for (const jk of jKeysSet) { + if (!jsKeysNumbers.includes(jk)) { + throw `jsKeysNumbers ${jsKeysNumbers} does not contain jk ${jk}`; } + } - for( const k of Object.keys(jsParts) ) { - const jArray = jBytesArrayToJavaScriptByteArray(jParts.get(Number(k))); - const jsArray = jsParts[k]; - if( jArray.length != jsArray.length ){ - throw `unequal lengths ${jArray.length} != ${jsArray.length}` - } - for( var l = 0; l < jArray.length; l++ ){ - if( jArray[l] != jsArray[l] ){ - throw `at index ${l}: ${jArray[l]} != ${jsArray[l]}` - } - } + for (const k of Object.keys(jsParts)) { + const jArray = jBytesArrayToJavaScriptByteArray(jParts.get(Number(k))); + const jsArray = jsParts[k]; + if (jArray.length != jsArray.length) { + throw `unequal lengths ${jArray.length} != ${jsArray.length}`; } + for (let l = 0; l < jArray.length; l++) { + if (jArray[l] != jsArray[l]) { + throw `at index ${l}: ${jArray[l]} != ${jsArray[l]}`; + } + } + } - return true; + return true; } - -test('PolygotTests roundrip parts between JavaScript and Java', function (t) { - t.plan(1); - const secretUtf8 = `ᚠᛇᚻ`; - const secret = stringToBytes(secretUtf8); - const parts = split(randomBytes, 3, 2, secret); - const jParts = javaScriptToJavaParts(parts); - const jsParts = javaToJavaScriptParts(jParts); - t.ok(equalParts(jParts, jsParts), `roundtrip parts`) +test('PolygotTests roundrip parts between JavaScript and Java', function(t) { + t.plan(1); + const secretUtf8 = `ᚠᛇᚻ`; + const secret = stringToBytes(secretUtf8); + const parts = split(randomBytes, 3, 2, secret); + const jParts = javaScriptToJavaParts(parts); + const jsParts = javaToJavaScriptParts(jParts); + t.ok(equalParts(jParts, jsParts), `roundtrip parts`); }); - -const NotRandomSource = Java.type('com.codahale.shamir.polygot.NotRandomSource'); +const NotRandomSource = Java.type( + 'com.codahale.shamir.polygot.NotRandomSource' +); const notRandomSource = new NotRandomSource(); function notRandomSourceJavaScript(len) { - const bytes = []; - for( var i = 0; i < len; i++){ - bytes[i] = i+1; - } - return bytes; + const bytes = []; + for (let i = 0; i < len; i++) { + bytes[i] = i + 1; + } + return bytes; } +test('PolygotTests compare Java and JavaScript split', function(t) { + t.plan(1); + const secretUtf8 = `ᚠᛇᚻ`; + const secret = stringToBytes(secretUtf8); -test('PolygotTests compare Java and JavaScript split', function (t) { - t.plan(1); - const secretUtf8 = `ᚠᛇᚻ`; - const secret = stringToBytes(secretUtf8); + const jsParts = split(notRandomSourceJavaScript, 3, 2, secret); - const jsParts = split(notRandomSourceJavaScript, 3, 2, secret); - - const jscheme = new Scheme(notRandomSource, 3, 2); - const jParts = jscheme.split(jsByteArrayToJavaByteArray(secret)); - t.ok(equalParts(jParts, jsParts), `splits match`) + const jscheme = new Scheme(notRandomSource, 3, 2); + const jParts = jscheme.split(jsByteArrayToJavaByteArray(secret)); + t.ok(equalParts(jParts, jsParts), `splits match`); }); +test('PolygotTests JavaScript split with Java join', function(t) { + t.plan(1); + const secretUtf8 = `ᚠᛇᚻ`; -test('PolygotTests JavaScript split with Java join', function (t) { - t.plan(1); - const secretUtf8 = `ᚠᛇᚻ`; - - const secret = stringToBytes(secretUtf8); - const jsParts = split(randomBytes, 3, 2, secret); - const jscheme = new Scheme(secureRandom, 3, 2); - const joined = jscheme.join(javaScriptToJavaParts(jsParts)); + const secret = stringToBytes(secretUtf8); + const jsParts = split(randomBytes, 3, 2, secret); + const jscheme = new Scheme(secureRandom, 3, 2); + const joined = jscheme.join(javaScriptToJavaParts(jsParts)); - t.equal(bytesToSring(jBytesArrayToJavaScriptByteArray(joined)), secretUtf8, `java joined js parts` ); + t.equal( + bytesToSring(jBytesArrayToJavaScriptByteArray(joined)), + secretUtf8, + `java joined js parts` + ); }); -const join = require('../../main/js/Scheme.js').join; +const { join } = require('../../main/js/Scheme.js'); -test('PolygotTests Java split with JavaScript join', function (t) { - t.plan(1); - const secretUtf8 = `ᚠᛇᚻ`; - - const secret = stringToBytes(secretUtf8); - const jscheme = new Scheme(secureRandom, 3, 2); - const jParts = jscheme.split(jsByteArrayToJavaByteArray(secret)); - const joined = join(javaToJavaScriptParts(jParts)); +test('PolygotTests Java split with JavaScript join', function(t) { + t.plan(1); + const secretUtf8 = `ᚠᛇᚻ`; - t.equal(bytesToSring(joined), secretUtf8, `java joined js parts` ); -}); \ No newline at end of file + const secret = stringToBytes(secretUtf8); + const jscheme = new Scheme(secureRandom, 3, 2); + const jParts = jscheme.split(jsByteArrayToJavaByteArray(secret)); + const joined = join(javaToJavaScriptParts(jParts)); + + t.equal(bytesToSring(joined), secretUtf8, `java joined js parts`); +}); diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index e5e03f4..bae8522 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -15,117 +15,116 @@ */ const test = require('tape'); -const split = require('../../main/js/Scheme.js').split; -const join = require('../../main/js/Scheme.js').join; +const { split } = require('../../main/js/Scheme.js'); +const { join } = require('../../main/js/Scheme.js'); -const randomBytes = require('tweetnacl').randomBytes; +const { randomBytes } = require('tweetnacl'); // https://codereview.stackexchange.com/a/3589/75693 function bytesToSring(bytes) { - var chars = []; - for(var i = 0, n = bytes.length; i < n;) { - chars.push(((bytes[i++] & 0xff) << 8) | (bytes[i++] & 0xff)); - } - return String.fromCharCode.apply(null, chars); + const chars = []; + for (let i = 0, n = bytes.length; i < n; ) { + chars.push(((bytes[i++] & 0xff) << 8) | (bytes[i++] & 0xff)); + } + return String.fromCharCode.apply(null, chars); } // https://codereview.stackexchange.com/a/3589/75693 function stringToBytes(str) { - var bytes = []; - for(var i = 0, n = str.length; i < n; i++) { - var char = str.charCodeAt(i); - bytes.push(char >>> 8, char & 0xFF); - } - return bytes; + const bytes = []; + for (let i = 0, n = str.length; i < n; i++) { + const char = str.charCodeAt(i); + bytes.push(char >>> 8, char & 0xff); + } + return bytes; } -test('SchemeTests roundtrip', function (t) { - const parts = 3; - const quorum = 2; +test('SchemeTests roundtrip', function(t) { + const parts = 3; + const quorum = 2; - // http://kermitproject.org/utf8.html - // From the Anglo-Saxon Rune Poem (Rune version) - const secretUtf8 = `ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ + // http://kermitproject.org/utf8.html + // From the Anglo-Saxon Rune Poem (Rune version) + const secretUtf8 = `ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ ᛋᚳᛖᚪᛚ᛫ᚦᛖᚪᚻ᛫ᛗᚪᚾᚾᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ᛫ᛗᛁᚳᛚᚢᚾ᛫ᚻᛦᛏ᛫ᛞᚫᛚᚪᚾ ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ᛬`; - // string length is only 117 characters but the byte length is 234. - var secret = stringToBytes(secretUtf8); + // string length is only 117 characters but the byte length is 234. + const secret = stringToBytes(secretUtf8); + + const splits = split(randomBytes, parts, quorum, secret); + t.equal(Object.keys(splits).length, parts); + const joined = join(splits); + t.equal(joined[200], secret[200]); + t.equal(joined[201], secret[201]); + const joinedUtf8 = bytesToSring(joined); + t.equal(secretUtf8, joinedUtf8); + t.end(); +}); + +test('SchemeTests roundtrip two parts', function(t) { + const parts = 3; + const quorum = 2; + const secretUtf8 = `ᚠᛇᚻ`; + const secret = stringToBytes(secretUtf8); + + for (let i = 1; i <= 3; i++) { const splits = split(randomBytes, parts, quorum, secret); - t.equal(Object.keys(splits).length, parts); - const joined = join(splits); - t.equal( joined[200], secret[200] ); - t.equal( joined[201], secret[201] ); - const joinedUtf8 = bytesToSring(joined); - t.equal( secretUtf8, joinedUtf8 ); - t.end(); -}); + delete splits[`${i}`]; + const joinedUtf8 = bytesToSring(join(splits)); + t.equal(secretUtf8, joinedUtf8); + } -test('SchemeTests roundtrip two parts', function (t) { - const parts = 3; - const quorum = 2; - - const secretUtf8 = `ᚠᛇᚻ`; - const secret = stringToBytes(secretUtf8); - - for( var i = 1; i <=3; i++) { - const splits = split(randomBytes, parts, quorum, secret); - delete splits[""+i]; - const joinedUtf8 = bytesToSring(join(splits)); - t.equal( secretUtf8, joinedUtf8 ); - } - - t.end(); + t.end(); }); -test('SchemeTests split input validation', function (t) { - const secretUtf8 = `ᚠᛇᚻ`; - const secret = stringToBytes(secretUtf8); - - t.plan(3); - - try { - const splits = split(randomBytes, 256, 2, secret); - t.notOk(true); - } catch (e) { - t.ok(e.toString().includes('N must be <= 255'), e); - } - - try { - const splits = split(randomBytes, 3, 1, secret); - t.notOk(true); - } catch (e) { - t.ok(e.toString().includes('K must be > 1'), e); - } - - try { - const splits = split(randomBytes, 2, 3, secret); - t.notOk(true); - } catch (e) { - t.ok(e.toString().includes('N must be >= K'), e); - } - - t.end(); +test('SchemeTests split input validation', function(t) { + const secretUtf8 = `ᚠᛇᚻ`; + const secret = stringToBytes(secretUtf8); + + t.plan(3); + + try { + const splits = split(randomBytes, 256, 2, secret); + t.notOk(true); + } catch (e) { + t.ok(e.toString().includes('N must be <= 255'), e); + } + + try { + const splits = split(randomBytes, 3, 1, secret); + t.notOk(true); + } catch (e) { + t.ok(e.toString().includes('K must be > 1'), e); + } + + try { + const splits = split(randomBytes, 2, 3, secret); + t.notOk(true); + } catch (e) { + t.ok(e.toString().includes('N must be >= K'), e); + } + + t.end(); }); -test('SchemeTests join input validation', function (t) { - - try { - join({}); - t.notOk(true); - } catch (e) { - t.ok(e.toString().includes('No parts provided'), e); - } - - try { - const splits = split(randomBytes, 3, 2, stringToBytes(`ᚠᛇᚻ`)); - splits["2"] = Uint8Array.of(216, 30, 190, 102) - join(splits); - t.notOk(true); - } catch (e) { - t.ok(e.toString().includes('Varying lengths of part values'), e); - } - - t.end(); +test('SchemeTests join input validation', function(t) { + try { + join({}); + t.notOk(true); + } catch (e) { + t.ok(e.toString().includes('No parts provided'), e); + } + + try { + const splits = split(randomBytes, 3, 2, stringToBytes(`ᚠᛇᚻ`)); + splits['2'] = Uint8Array.of(216, 30, 190, 102); + join(splits); + t.notOk(true); + } catch (e) { + t.ok(e.toString().includes('Varying lengths of part values'), e); + } + + t.end(); }); From 546c81b7540b1408ea4337cd087bb16d1a53c104 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 20:55:13 +0100 Subject: [PATCH 47/78] lint the tests --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index da81e5e..ce5e57c 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "test": "tape src/test/js/GF256Tests.js src/test/js/SchemeTests.js", "testwithjava": "node --jvm --vm.cp=./target/classes:./target/test-classes src/test/js/PolygotTests.js", - "lint": "eslint ./src/main/js/GF256.js ./src/main/js/Scheme.js && echo 'Lint complete.'" + "lint": "eslint ./src/main/js/GF256.js ./src/main/js/Scheme.js ./src/test/js/GF256Tests.js ./src/test/js/SchemeTests.js ./src/test/js/PolygotTests.js && echo 'Lint complete.'" }, "repository": { "type": "git", From 477feb68dac8c039b53b8741f5e782062f25aae0 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 21:19:29 +0100 Subject: [PATCH 48/78] fixed lint errors on GF256Tests.js --- src/test/js/GF256Tests.js | 323 +++++--------------------------------- 1 file changed, 38 insertions(+), 285 deletions(-) diff --git a/src/test/js/GF256Tests.js b/src/test/js/GF256Tests.js index 718d86e..157f494 100644 --- a/src/test/js/GF256Tests.js +++ b/src/test/js/GF256Tests.js @@ -21,25 +21,26 @@ const GF256 = require('../../main/js/GF256.js'); /* eslint-disable prefer-arrow-callback */ /* eslint-disable func-names */ -test('GF256Tests add', function(t) { +/* eslint-disable no-plusplus */ +test('GF256Tests add', function (t) { t.plan(1); t.equal(GF256.add(100, 30), 122); }); -test('GF256Tests sub', function(t) { +test('GF256Tests sub', function (t) { t.plan(1); t.equal(GF256.sub(100, 30), 122); }); -test('GF256Tests mul', function(t) { +test('GF256Tests mul', function (t) { t.plan(4); t.equal(GF256.mul(90, 21), 254); t.equal(GF256.mul(133, 5), 167); t.equal(GF256.mul(0, 21), 0); - t.equal(GF256.mul(parseInt('0xb6'), parseInt('0x53')), parseInt('0x36')); + t.equal(GF256.mul(0xb6, 0x53), 0x36); }); -test('GF256Tests div', function(t) { +test('GF256Tests div', function (t) { t.plan(4); t.equal(GF256.div(90, 21), 189); t.equal(GF256.div(6, 55), 151); @@ -47,7 +48,7 @@ test('GF256Tests div', function(t) { t.equal(GF256.div(0, 192), 0); }); -test('GF256Tests degree', function(t) { +test('GF256Tests degree', function (t) { t.plan(4); t.equal(GF256.degree([1, 2]), 1); t.equal(GF256.degree([1, 2, 0]), 1); @@ -55,325 +56,77 @@ test('GF256Tests degree', function(t) { t.equal(GF256.degree([0, 0, 0]), 0); }); -const bytes = [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27, - 28, - 29, - 30, - 31, - 32, - 33, - 34, - 35, - 36, - 37, - 38, - 39, - 40, - 41, - 42, - 43, - 44, - 45, - 46, - 47, - 48, - 49, - 50, - 51, - 52, - 53, - 54, - 55, - 56, - 57, - 58, - 59, - 60, - 61, - 62, - 63, - 64, - 65, - 66, - 67, - 68, - 69, - 70, - 71, - 72, - 73, - 74, - 75, - 76, - 77, - 78, - 79, - 80, - 81, - 82, - 83, - 84, - 85, - 86, - 87, - 88, - 89, - 90, - 91, - 92, - 93, - 94, - 95, - 96, - 97, - 98, - 99, - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120, - 121, - 122, - 123, - 124, - 125, - 126, - 127, - 128, - 129, - 130, - 131, - 132, - 133, - 134, - 135, - 136, - 137, - 138, - 139, - 140, - 141, - 142, - 143, - 144, - 145, - 146, - 147, - 148, - 149, - 150, - 151, - 152, - 153, - 154, - 155, - 156, - 157, - 158, - 159, - 160, - 161, - 162, - 163, - 164, - 165, - 166, - 167, - 168, - 169, - 170, - 171, - 172, - 173, - 174, - 175, - 176, - 177, - 178, - 179, - 180, - 181, - 182, - 183, - 184, - 185, - 186, - 187, - 188, - 189, - 190, - 191, - 192, - 193, - 194, - 195, - 196, - 197, - 198, - 199, - 200, - 201, - 202, - 203, - 204, - 205, - 206, - 207, - 208, - 209, - 210, - 211, - 212, - 213, - 214, - 215, - 216, - 217, - 218, - 219, - 220, - 221, - 222, - 223, - 224, - 225, - 226, - 227, - 228, - 229, - 230, - 231, - 232, - 233, - 234, - 235, - 236, - 237, - 238, - 239, - 240, - 241, - 242, - 243, - 244, - 245, - 246, - 247, - 248, - 249, - 250, - 251, - 252, - 253, - 254, - 255 -]; + +const bytes = new Uint8Array(function () { + const returned = []; + for (let i = 1; i <= 255; i++) { + returned.push(i); + } + return returned; +}()); function makePairs(arr) { const res = []; const l = arr.length; - for (let i = 0; i < l; ++i) + for (let i = 0; i < l; ++i) { for (let j = i + 1; j < l; ++j) res.push([arr[i], arr[j]]); + } return res; } const pairs = makePairs(bytes); -test('GF256Tests mul is commutative', function(t) { - pairs.forEach(function(pair) { - if (GF256.mul(pair[0], pair[1]) != GF256.mul(pair[1], pair[0])) { +test('GF256Tests mul is commutative', function (t) { + pairs.forEach(function (pair) { + if (GF256.mul(pair[0], pair[1]) !== GF256.mul(pair[1], pair[0])) { throw new Error(`mul not commutative for pair ${pair}`); } }); t.end(); }); -test('GF256Tests add is commutative', function(t) { - pairs.forEach(function(pair) { - if (GF256.add(pair[0], pair[1]) != GF256.add(pair[1], pair[0])) { +test('GF256Tests add is commutative', function (t) { + pairs.forEach(function (pair) { + if (GF256.add(pair[0], pair[1]) !== GF256.add(pair[1], pair[0])) { throw new Error(`add not commutitive for pair ${pair}`); } }); t.end(); }); -test('GF256Tests sub is the inverse of add', function(t) { - pairs.forEach(function(pair) { - if (GF256.sub(GF256.add(pair[0], pair[1]), pair[1]) != pair[0]) { +test('GF256Tests sub is the inverse of add', function (t) { + pairs.forEach(function (pair) { + if (GF256.sub(GF256.add(pair[0], pair[1]), pair[1]) !== pair[0]) { throw new Error(`sub is not the inverse of add for pair ${pair}`); } }); t.end(); }); -test('GF256Tests div is the inverse of mul', function(t) { - pairs.forEach(function(pair) { - if (GF256.div(GF256.mul(pair[0], pair[1]), pair[1]) != pair[0]) { +test('GF256Tests div is the inverse of mul', function (t) { + pairs.forEach(function (pair) { + if (GF256.div(GF256.mul(pair[0], pair[1]), pair[1]) !== pair[0]) { throw new Error(`div is not the inverse of mul for pair ${pair}`); } }); t.end(); }); -test('GF256Tests mul is the inverse of div', function(t) { - pairs.forEach(function(pair) { - if (GF256.mul(GF256.div(pair[0], pair[1]), pair[1]) != pair[0]) { +test('GF256Tests mul is the inverse of div', function (t) { + pairs.forEach(function (pair) { + if (GF256.mul(GF256.div(pair[0], pair[1]), pair[1]) !== pair[0]) { throw new Error(`mul is not the inverse of div for pair ${pair}`); } }); t.end(); }); -test('GF256Tests eval', function(t) { +test('GF256Tests eval', function (t) { t.equal(GF256.eval([1, 0, 2, 3], 2), 17); t.end(); }); -test('GF256Tests interpolate', function(t) { +test('GF256Tests interpolate', function (t) { t.equal(GF256.interpolate([[1, 1], [2, 2], [3, 3]]), 0); t.equal(GF256.interpolate([[1, 80], [2, 90], [3, 20]]), 30); t.equal(GF256.interpolate([[1, 43], [2, 22], [3, 86]]), 107); @@ -382,7 +135,7 @@ test('GF256Tests interpolate', function(t) { let countDownFrom2 = 2; -const zeroLastByteFirstTWoAttemptsRandomBytes = function(length) { +const zeroLastByteFirstTWoAttemptsRandomBytes = function (length) { const p = randomBytes(length); if (countDownFrom2 >= 0) { p[p.length - 1] = 0; @@ -391,15 +144,15 @@ const zeroLastByteFirstTWoAttemptsRandomBytes = function(length) { return p; }; -test('GF256Tests generate', function(t) { +test('GF256Tests generate', function (t) { const p = GF256.generate(zeroLastByteFirstTWoAttemptsRandomBytes, 5, 20); t.equal(p[0], 20); t.equal(p.length, 6); - t.notOk(p[p.length - 1] == 0); + t.notOk(p[p.length - 1] === 0); t.end(); }); -test('GF256Tests eval', function(t) { +test('GF256Tests eval', function (t) { t.plan(1); const v = GF256.eval([1, 0, 2, 3], 2); t.equal(v, 17); From dd92c932b6e4a3767e42636e61ed6c3719eb2f09 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 21:47:50 +0100 Subject: [PATCH 49/78] fixed eslint errors --- src/test/js/PolygotTests.js | 104 ++++++++++++++++-------------------- src/test/js/SchemeTests.js | 29 ++++++---- 2 files changed, 64 insertions(+), 69 deletions(-) diff --git a/src/test/js/PolygotTests.js b/src/test/js/PolygotTests.js index 8b82b2b..f6550e9 100644 --- a/src/test/js/PolygotTests.js +++ b/src/test/js/PolygotTests.js @@ -13,14 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* eslint-disable import/no-extraneous-dependencies */ const test = require('tape-catch'); - const { randomBytes } = require('tweetnacl'); +/* eslint-disable prefer-arrow-callback */ +/* eslint-disable func-names */ +/* eslint-disable no-plusplus */ +/* eslint-disable no-bitwise */ + // https://codereview.stackexchange.com/a/3589/75693 function bytesToSring(bytes) { const chars = []; - for (let i = 0, n = bytes.length; i < n; ) { + for (let i = 0, n = bytes.length; i < n;) { chars.push(((bytes[i++] & 0xff) << 8) | (bytes[i++] & 0xff)); } return String.fromCharCode.apply(null, chars); @@ -36,33 +41,10 @@ function stringToBytes(str) { return bytes; } +// eslint-disable-next-line no-undef const ByteArray = Java.type('byte[]'); -const Byte = Java.type('java.lang.Byte'); -const JavaScriptUtils = Java.type( - 'com.codahale.shamir.polygot.JavaScriptUtils' -); - -const hexChar = [ - '0', - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - 'A', - 'B', - 'C', - 'D', - 'E', - 'F' -]; -function byteToHex(b) { - return hexChar[(b >> 4) & 0x0f] + hexChar[b & 0x0f]; -} +// eslint-disable-next-line no-undef +const JavaScriptUtils = Java.type('com.codahale.shamir.polygot.JavaScriptUtils'); function jsByteArrayToJavaByteArray(jsarray) { const jbarray = new ByteArray(jsarray.length); @@ -80,27 +62,27 @@ function jBytesArrayToJavaScriptByteArray(barray) { return jsarray; } -test('PolygotTests Java and JavaScript byte array roundtrip', function(t) { +test('PolygotTests Java and JavaScript byte array roundtrip', function (t) { t.plan(1); - const secretUtf8 = `ᚠᛇᚻ`; + const secretUtf8 = 'ᚠᛇᚻ'; const jsBytes = stringToBytes(secretUtf8); const jbytes = jsByteArrayToJavaByteArray(jsBytes); const jsRoundTripBytes = jBytesArrayToJavaScriptByteArray(jbytes); t.equal(secretUtf8, bytesToSring(jsRoundTripBytes)); }); +// eslint-disable-next-line no-undef const Scheme = Java.type('com.codahale.shamir.Scheme'); +// eslint-disable-next-line no-undef const SecureRandom = Java.type('java.security.SecureRandom'); const secureRandom = new SecureRandom(); -test('PolygotTests JavaScript strings with all Java logic', function(t) { +test('PolygotTests JavaScript strings with all Java logic', function (t) { t.plan(1); const scheme = new Scheme(secureRandom, 5, 3); - const secretUtf8 = `ᚠᛇᚻ`; + const secretUtf8 = 'ᚠᛇᚻ'; - const parts = scheme.split( - jsByteArrayToJavaByteArray(stringToBytes(secretUtf8)) - ); + const parts = scheme.split(jsByteArrayToJavaByteArray(stringToBytes(secretUtf8))); const joined = scheme.join(parts); t.equal(secretUtf8, bytesToSring(jBytesArrayToJavaScriptByteArray(joined))); @@ -108,12 +90,15 @@ test('PolygotTests JavaScript strings with all Java logic', function(t) { const { split } = require('../../main/js/Scheme.js'); +// eslint-disable-next-line no-undef +const HashMap = Java.type('java.util.HashMap'); + function javaScriptToJavaParts(parts) { - const HashMap = Java.type('java.util.HashMap'); const map = new HashMap(); + // eslint-disable-next-line no-restricted-syntax, guard-for-in for (const key in parts) { const bytes = parts[key]; - const jbarr = new jsByteArrayToJavaByteArray(bytes); + const jbarr = jsByteArrayToJavaByteArray(bytes); map.put(Number(key), jbarr); } return map; @@ -131,6 +116,7 @@ function javaToJavaScriptParts(javaMap) { return result; } +// eslint-disable-next-line no-undef const Collectors = Java.type('java.util.stream.Collectors'); function equalParts(jParts, jsParts) { @@ -144,28 +130,31 @@ function equalParts(jParts, jsParts) { .collect(Collectors.toList()); // check that all js keys are in the j keys + // eslint-disable-next-line no-restricted-syntax for (const jsk of jsKeysNumbers) { if (!jKeysSet.contains(jsk)) { - throw `jKeysSet ${jKeysSet} does not contain jsk ${jsk}`; + throw new Error(`jKeysSet ${jKeysSet} does not contain jsk ${jsk}`); } } // check that all j keys are in the js keys + // eslint-disable-next-line no-restricted-syntax for (const jk of jKeysSet) { if (!jsKeysNumbers.includes(jk)) { - throw `jsKeysNumbers ${jsKeysNumbers} does not contain jk ${jk}`; + throw new Error(`jsKeysNumbers ${jsKeysNumbers} does not contain jk ${jk}`); } } + // eslint-disable-next-line no-restricted-syntax for (const k of Object.keys(jsParts)) { const jArray = jBytesArrayToJavaScriptByteArray(jParts.get(Number(k))); const jsArray = jsParts[k]; - if (jArray.length != jsArray.length) { - throw `unequal lengths ${jArray.length} != ${jsArray.length}`; + if (jArray.length !== jsArray.length) { + throw new Error(`unequal lengths ${jArray.length} != ${jsArray.length}`); } for (let l = 0; l < jArray.length; l++) { - if (jArray[l] != jsArray[l]) { - throw `at index ${l}: ${jArray[l]} != ${jsArray[l]}`; + if (jArray[l] !== jsArray[l]) { + throw new Error(`at index ${l}: ${jArray[l]} != ${jsArray[l]}`); } } } @@ -173,19 +162,18 @@ function equalParts(jParts, jsParts) { return true; } -test('PolygotTests roundrip parts between JavaScript and Java', function(t) { +test('PolygotTests roundrip parts between JavaScript and Java', function (t) { t.plan(1); - const secretUtf8 = `ᚠᛇᚻ`; + const secretUtf8 = 'ᚠᛇᚻ'; const secret = stringToBytes(secretUtf8); const parts = split(randomBytes, 3, 2, secret); const jParts = javaScriptToJavaParts(parts); const jsParts = javaToJavaScriptParts(jParts); - t.ok(equalParts(jParts, jsParts), `roundtrip parts`); + t.ok(equalParts(jParts, jsParts), 'roundtrip parts'); }); -const NotRandomSource = Java.type( - 'com.codahale.shamir.polygot.NotRandomSource' -); +// eslint-disable-next-line no-undef +const NotRandomSource = Java.type('com.codahale.shamir.polygot.NotRandomSource'); const notRandomSource = new NotRandomSource(); function notRandomSourceJavaScript(len) { const bytes = []; @@ -195,21 +183,21 @@ function notRandomSourceJavaScript(len) { return bytes; } -test('PolygotTests compare Java and JavaScript split', function(t) { +test('PolygotTests compare Java and JavaScript split', function (t) { t.plan(1); - const secretUtf8 = `ᚠᛇᚻ`; + const secretUtf8 = 'ᚠᛇᚻ'; const secret = stringToBytes(secretUtf8); const jsParts = split(notRandomSourceJavaScript, 3, 2, secret); const jscheme = new Scheme(notRandomSource, 3, 2); const jParts = jscheme.split(jsByteArrayToJavaByteArray(secret)); - t.ok(equalParts(jParts, jsParts), `splits match`); + t.ok(equalParts(jParts, jsParts), 'splits match'); }); -test('PolygotTests JavaScript split with Java join', function(t) { +test('PolygotTests JavaScript split with Java join', function (t) { t.plan(1); - const secretUtf8 = `ᚠᛇᚻ`; + const secretUtf8 = 'ᚠᛇᚻ'; const secret = stringToBytes(secretUtf8); const jsParts = split(randomBytes, 3, 2, secret); @@ -219,20 +207,20 @@ test('PolygotTests JavaScript split with Java join', function(t) { t.equal( bytesToSring(jBytesArrayToJavaScriptByteArray(joined)), secretUtf8, - `java joined js parts` + 'java joined js parts', ); }); const { join } = require('../../main/js/Scheme.js'); -test('PolygotTests Java split with JavaScript join', function(t) { +test('PolygotTests Java split with JavaScript join', function (t) { t.plan(1); - const secretUtf8 = `ᚠᛇᚻ`; + const secretUtf8 = 'ᚠᛇᚻ'; const secret = stringToBytes(secretUtf8); const jscheme = new Scheme(secureRandom, 3, 2); const jParts = jscheme.split(jsByteArrayToJavaByteArray(secret)); const joined = join(javaToJavaScriptParts(jParts)); - t.equal(bytesToSring(joined), secretUtf8, `java joined js parts`); + t.equal(bytesToSring(joined), secretUtf8, 'java joined js parts'); }); diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index bae8522..c352d6d 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +/* eslint-disable import/no-extraneous-dependencies */ const test = require('tape'); const { split } = require('../../main/js/Scheme.js'); @@ -20,15 +21,21 @@ const { join } = require('../../main/js/Scheme.js'); const { randomBytes } = require('tweetnacl'); +/* eslint-disable prefer-arrow-callback */ +/* eslint-disable func-names */ +/* eslint-disable no-plusplus */ +/* eslint-disable no-bitwise */ + // https://codereview.stackexchange.com/a/3589/75693 function bytesToSring(bytes) { const chars = []; - for (let i = 0, n = bytes.length; i < n; ) { + for (let i = 0, n = bytes.length; i < n;) { chars.push(((bytes[i++] & 0xff) << 8) | (bytes[i++] & 0xff)); } return String.fromCharCode.apply(null, chars); } + // https://codereview.stackexchange.com/a/3589/75693 function stringToBytes(str) { const bytes = []; @@ -39,7 +46,7 @@ function stringToBytes(str) { return bytes; } -test('SchemeTests roundtrip', function(t) { +test('SchemeTests roundtrip', function (t) { const parts = 3; const quorum = 2; @@ -62,11 +69,11 @@ test('SchemeTests roundtrip', function(t) { t.end(); }); -test('SchemeTests roundtrip two parts', function(t) { +test('SchemeTests roundtrip two parts', function (t) { const parts = 3; const quorum = 2; - const secretUtf8 = `ᚠᛇᚻ`; + const secretUtf8 = 'ᚠᛇᚻ'; const secret = stringToBytes(secretUtf8); for (let i = 1; i <= 3; i++) { @@ -79,28 +86,28 @@ test('SchemeTests roundtrip two parts', function(t) { t.end(); }); -test('SchemeTests split input validation', function(t) { - const secretUtf8 = `ᚠᛇᚻ`; +test('SchemeTests split input validation', function (t) { + const secretUtf8 = 'ᚠᛇᚻ'; const secret = stringToBytes(secretUtf8); t.plan(3); try { - const splits = split(randomBytes, 256, 2, secret); + split(randomBytes, 256, 2, secret); t.notOk(true); } catch (e) { t.ok(e.toString().includes('N must be <= 255'), e); } try { - const splits = split(randomBytes, 3, 1, secret); + split(randomBytes, 3, 1, secret); t.notOk(true); } catch (e) { t.ok(e.toString().includes('K must be > 1'), e); } try { - const splits = split(randomBytes, 2, 3, secret); + split(randomBytes, 2, 3, secret); t.notOk(true); } catch (e) { t.ok(e.toString().includes('N must be >= K'), e); @@ -109,7 +116,7 @@ test('SchemeTests split input validation', function(t) { t.end(); }); -test('SchemeTests join input validation', function(t) { +test('SchemeTests join input validation', function (t) { try { join({}); t.notOk(true); @@ -118,7 +125,7 @@ test('SchemeTests join input validation', function(t) { } try { - const splits = split(randomBytes, 3, 2, stringToBytes(`ᚠᛇᚻ`)); + const splits = split(randomBytes, 3, 2, stringToBytes('ᚠᛇᚻ')); splits['2'] = Uint8Array.of(216, 30, 190, 102); join(splits); t.notOk(true); From 510be6a34cece34cfab9429bc5ee144916adddd5 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 21:55:11 +0100 Subject: [PATCH 50/78] run lint in docker build --- Dockerfile.graaljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.graaljs b/Dockerfile.graaljs index 36fe5f3..4af8925 100644 --- a/Dockerfile.graaljs +++ b/Dockerfile.graaljs @@ -8,5 +8,5 @@ RUN mvn package FROM oracle/graalvm-ce:latest AS graal COPY --from=build /src /src WORKDIR src -RUN npm test && npm run testwithjava +RUN npm test && npm run testwithjava && npm run lint From e5a01a8eb4bb0b4317d120186ae2dc88228b3b28 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 22:32:12 +0100 Subject: [PATCH 51/78] clean up imports --- src/test/js/SchemeTests.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index c352d6d..c99d6d6 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -16,8 +16,7 @@ /* eslint-disable import/no-extraneous-dependencies */ const test = require('tape'); -const { split } = require('../../main/js/Scheme.js'); -const { join } = require('../../main/js/Scheme.js'); +const { split, join } = require('../../main/js/Scheme.js'); const { randomBytes } = require('tweetnacl'); From 24b4c63e2717c2a088f90a2ad88b1980dff616fa Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 30 Jun 2019 22:32:43 +0100 Subject: [PATCH 52/78] fix up readme for JavaScipt notes --- README.md | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 64ce109..87a25e3 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ [![CircleCI](https://circleci.com/gh/codahale/shamir.svg?style=svg)](https://circleci.com/gh/codahale/shamir) -A Java implementation of [Shamir's Secret Sharing -algorithm](http://en.wikipedia.org/wiki/Shamir's_Secret_Sharing) over GF(256). +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. -## Add to your project +## Add to your Java project ```xml @@ -17,7 +17,7 @@ algorithm](http://en.wikipedia.org/wiki/Shamir's_Secret_Sharing) over GF(256). *Note: module name for Java 9+ is `com.codahale.shamir`.* -## Use the thing +## Use the thing in Java ```java import com.codahale.shamir.Scheme; @@ -36,6 +36,22 @@ class Example { } ``` +## Use the thing in JavaScript + +```JavaScript +const { split, join } = require('shamir'); +const { randomBytes } = require('tweetnacl'); + +function doIt() { + const utf8Encoder = new TextEncoder(); + const utf8Decoder = new TextDecoder(); + const secret = utf8Encoder.encode('hello there'); + const parts = split(randomBytes, 5, 3 secret); + const recovered = join(parts); + console.log(utf8Decoder.decode()); +} +``` + ## How it works Shamir's Secret Sharing algorithm is a way to split an arbitrary secret `S` into `N` parts, of which @@ -94,7 +110,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. @@ -150,5 +166,6 @@ users agree. ## License Copyright © 2017 Coda Hale +Copyright © 2019 Simon Massey Distributed under the Apache License 2.0. From 75304f5a9d35ed448b78eafbd9cea8cf76221efd Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Mon, 1 Jul 2019 05:55:48 +0100 Subject: [PATCH 53/78] remove tweetnacl dependency --- README.md | 2 +- package-lock.json | 30 ++++++++++++++++-------------- package.json | 5 ++--- src/test/js/GF256Tests.js | 2 +- src/test/js/PolygotTests.js | 2 +- src/test/js/SchemeTests.js | 2 +- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 87a25e3..de2aa46 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ class Example { ```JavaScript const { split, join } = require('shamir'); -const { randomBytes } = require('tweetnacl'); +const { randomBytes } = require('crypto'); function doIt() { const utf8Encoder = new TextEncoder(); diff --git a/package-lock.json b/package-lock.json index 252f18d..ee93bb6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -958,9 +958,9 @@ "dev": true }, "resolve": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.1.tgz", - "integrity": "sha512-KuIe4mf++td/eFb6wkaPbMDnP6kObCaEtIDuHOUED6MNUo4K670KZUHuuvYPZDxNF0WVLw49n06M2m2dXphEzA==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz", + "integrity": "sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==", "dev": true, "requires": { "path-parse": "^1.0.6" @@ -1154,9 +1154,9 @@ } }, "tape": { - "version": "4.10.2", - "resolved": "https://registry.npmjs.org/tape/-/tape-4.10.2.tgz", - "integrity": "sha512-mgl23h7W2yuk3N85FOYrin2OvThTYWdwbk6XQ1pr2PMJieyW2FM/4Bu/+kD/wecb3aZ0Enm+Syinyq467OPq2w==", + "version": "4.11.0", + "resolved": "https://registry.npmjs.org/tape/-/tape-4.11.0.tgz", + "integrity": "sha512-yixvDMX7q7JIs/omJSzSZrqulOV51EC9dK8dM0TzImTIkHWfe2/kFyL5v+d9C+SrCMaICk59ujsqFAVidDqDaA==", "dev": true, "requires": { "deep-equal": "~1.0.1", @@ -1165,13 +1165,21 @@ "function-bind": "~1.1.1", "glob": "~7.1.4", "has": "~1.0.3", - "inherits": "~2.0.3", + "inherits": "~2.0.4", "minimist": "~1.2.0", "object-inspect": "~1.6.0", - "resolve": "~1.10.1", + "resolve": "~1.11.1", "resumer": "~0.0.0", "string.prototype.trim": "~1.1.2", "through": "~2.3.8" + }, + "dependencies": { + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true + } } }, "tape-catch": { @@ -1210,12 +1218,6 @@ "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==", "dev": true }, - "tweetnacl": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.1.tgz", - "integrity": "sha512-kcoMoKTPYnoeS50tzoqjPY3Uv9axeuuFAZY9M/9zFnhoVvRfxz9K29IMPD7jGmt2c8SW7i3gT9WqDl2+nV7p4A==", - "dev": true - }, "type-check": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", diff --git a/package.json b/package.json index ce5e57c..a272924 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,7 @@ "eslint-config-prettier": "^6.0.0", "eslint-plugin-prettier": "^3.1.0", "prettier": "^1.18.2", - "tape": "^4.10.2", - "tape-catch": "^1.0.6", - "tweetnacl": "^1.0.1" + "tape": "^4.11.0", + "tape-catch": "^1.0.6" } } diff --git a/src/test/js/GF256Tests.js b/src/test/js/GF256Tests.js index 157f494..1f82979 100644 --- a/src/test/js/GF256Tests.js +++ b/src/test/js/GF256Tests.js @@ -15,7 +15,7 @@ */ /* eslint-disable import/no-extraneous-dependencies */ const test = require('tape'); -const { randomBytes } = require('tweetnacl'); +const { randomBytes } = require('crypto'); const GF256 = require('../../main/js/GF256.js'); diff --git a/src/test/js/PolygotTests.js b/src/test/js/PolygotTests.js index f6550e9..ee966f4 100644 --- a/src/test/js/PolygotTests.js +++ b/src/test/js/PolygotTests.js @@ -15,7 +15,7 @@ */ /* eslint-disable import/no-extraneous-dependencies */ const test = require('tape-catch'); -const { randomBytes } = require('tweetnacl'); +const { randomBytes } = require('crypto'); /* eslint-disable prefer-arrow-callback */ /* eslint-disable func-names */ diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index c99d6d6..0e76681 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -18,7 +18,7 @@ const test = require('tape'); const { split, join } = require('../../main/js/Scheme.js'); -const { randomBytes } = require('tweetnacl'); +const { randomBytes } = require('crypto'); /* eslint-disable prefer-arrow-callback */ /* eslint-disable func-names */ From 428881bb9233ef2abb64b9c2b507cef2f5de7849 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Mon, 1 Jul 2019 07:01:17 +0100 Subject: [PATCH 54/78] better example --- README.md | 19 +++++++++++++++---- src/test/js/SchemeTests.js | 7 +++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index de2aa46..c5fa570 100644 --- a/README.md +++ b/README.md @@ -38,17 +38,28 @@ class Example { ## Use the thing in JavaScript -```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 string to Uint8Array const utf8Encoder = new TextEncoder(); const utf8Decoder = new TextDecoder(); - const secret = utf8Encoder.encode('hello there'); - const parts = split(randomBytes, 5, 3 secret); + const secretBytes = utf8Encoder.encode('hello there'); + // parts is a object whos keys are the part number and values are an 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); - console.log(utf8Decoder.decode()); + // prints 'hello there' + console.log(utf8Decoder.decode(recovered)); } ``` diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index 0e76681..601b315 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -46,8 +46,8 @@ function stringToBytes(str) { } test('SchemeTests roundtrip', function (t) { - const parts = 3; - const quorum = 2; + const parts = 5; + const quorum = 3; // http://kermitproject.org/utf8.html // From the Anglo-Saxon Rune Poem (Rune version) @@ -59,6 +59,9 @@ test('SchemeTests roundtrip', function (t) { const secret = stringToBytes(secretUtf8); const splits = split(randomBytes, parts, quorum, secret); + // only quorum parts are necessary + delete parts[2]; + delete parts[3]; t.equal(Object.keys(splits).length, parts); const joined = join(splits); t.equal(joined[200], secret[200]); From 8a826730bc594c4f2c7d2a80aedfe9022a2bbbc9 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Mon, 1 Jul 2019 07:09:40 +0100 Subject: [PATCH 55/78] match version number to upstream --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a272924..4d96c0d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "shamir", - "version": "1.0.0", + "version": "0.7.0", "description": "A JavaScript implementation of Shamir's Secret Sharing algorithm over GF(256).", "main": "src/main/js/Scheme.js", "scripts": { From 6ad363b5fc4222bafe80e7fe65359e5e756e4c93 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Mon, 1 Jul 2019 07:10:33 +0100 Subject: [PATCH 56/78] fix circleci link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c5fa570..b354b00 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Shamir's Secret Sharing -[![CircleCI](https://circleci.com/gh/codahale/shamir.svg?style=svg)](https://circleci.com/gh/codahale/shamir) +[![CircleCI](https://circleci.com/gh/simbo1905/shamir.svg?style=svg)](https://circleci.com/gh/simbo1905/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. From e1a32d3b26134831b076df52602e1dd77b29eefe Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Mon, 1 Jul 2019 20:13:16 +0100 Subject: [PATCH 57/78] fixing lint being broken by license headers in local docker build --- Dockerfile.graaljs | 4 ++-- pom.xml | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Dockerfile.graaljs b/Dockerfile.graaljs index 4af8925..7432d7d 100644 --- a/Dockerfile.graaljs +++ b/Dockerfile.graaljs @@ -8,5 +8,5 @@ RUN mvn package FROM oracle/graalvm-ce:latest AS graal COPY --from=build /src /src WORKDIR src -RUN npm test && npm run testwithjava && npm run lint - +#RUN npm test && npm run testwithjava && npm run lint +CMD /bin/bash diff --git a/pom.xml b/pom.xml index d5eab5c..25a8e9b 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,36 @@ + + + + com.mycila + license-maven-plugin + 3.0 + +

com/mycila/maven/plugin/license/templates/APACHE-2.txt
+ + Coda Hale + coda.hale@gmail.com + + + SLASHSTAR_STYLE + + + + + LICENSE + + **/*.txt + **/*.js + + src/main/resources/** + src/test/resources/** + node_modules/** + + + + From 100634624592aeeaabf4dc9b996532b8e379db92 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Mon, 1 Jul 2019 20:55:04 +0100 Subject: [PATCH 58/78] fixed eslint rules in docker build --- Dockerfile.graaljs | 3 +-- src/test/js/GF256Tests.js | 2 +- src/test/js/PolygotTests.js | 2 +- src/test/js/SchemeTests.js | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Dockerfile.graaljs b/Dockerfile.graaljs index 7432d7d..f733b1e 100644 --- a/Dockerfile.graaljs +++ b/Dockerfile.graaljs @@ -8,5 +8,4 @@ RUN mvn package FROM oracle/graalvm-ce:latest AS graal COPY --from=build /src /src WORKDIR src -#RUN npm test && npm run testwithjava && npm run lint -CMD /bin/bash +RUN npm test && npm run testwithjava && npm run lint diff --git a/src/test/js/GF256Tests.js b/src/test/js/GF256Tests.js index 1f82979..45784f5 100644 --- a/src/test/js/GF256Tests.js +++ b/src/test/js/GF256Tests.js @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* eslint-disable import/no-extraneous-dependencies */ + const test = require('tape'); const { randomBytes } = require('crypto'); diff --git a/src/test/js/PolygotTests.js b/src/test/js/PolygotTests.js index ee966f4..1e1a8d4 100644 --- a/src/test/js/PolygotTests.js +++ b/src/test/js/PolygotTests.js @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* eslint-disable import/no-extraneous-dependencies */ + const test = require('tape-catch'); const { randomBytes } = require('crypto'); diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index 601b315..ee2eb6a 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* eslint-disable import/no-extraneous-dependencies */ + const test = require('tape'); const { split, join } = require('../../main/js/Scheme.js'); From 0bf58cc2fde7ee565798cd6902b1d57692cecfbc Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Mon, 1 Jul 2019 22:33:16 +0100 Subject: [PATCH 59/78] benchmarks for js --- README.md | 19 ++++++++++++++ src/test/js/Benchmark.js | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/test/js/Benchmark.js diff --git a/README.md b/README.md index b354b00..9ed9c24 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,24 @@ 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. +## 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 get random polynomials per 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 1024 200 0.083 ms/op +Benchmarks.split 5 1024 200 0.081 ms/op +``` + ## Tiered sharing Some usages of secret sharing involve levels of access: e.g. recovering a secret requires two admin @@ -177,6 +195,7 @@ users agree. ## License Copyright © 2017 Coda Hale + Copyright © 2019 Simon Massey Distributed under the Apache License 2.0. diff --git a/src/test/js/Benchmark.js b/src/test/js/Benchmark.js new file mode 100644 index 0000000..f90493b --- /dev/null +++ b/src/test/js/Benchmark.js @@ -0,0 +1,53 @@ +const { split, join } = require('../../main/js/Scheme.js'); + +const { randomBytes } = require('crypto'); + +const secret = new Uint8Array(16); + +for (let i = 0; i < secret.length; i++) { + secret[i] = i % 255; +} + +const mainrun = 200; + +const parts = 4; +const quorum = 3; + +var splits = split(randomBytes, parts, quorum, secret); + +function benchmarkSplit() { + for( let i = 0; i < mainrun; i++ ) { + splits = split(randomBytes, parts, quorum, secret); + } +} + +// https://nodejs.org/docs/latest-v10.x/api/perf_hooks.html#perf_hooks_performance_now +const { + performance, + PerformanceObserver +} = require('perf_hooks'); +const wrappedSplit = performance.timerify(benchmarkSplit); +const obsSplit = new PerformanceObserver((list) => { + const timed = list.getEntries()[0].duration / mainrun; + console.log(`split ${timed} ms`); + obsSplit.disconnect(); +}); +obsSplit.observe({ entryTypes: ['function'] }); +wrappedSplit(); + +var recovered = join(splits); + +function benchmarkJoin() { + for( let i = 0; i < mainrun; i++ ) { + recovered = join(splits); + } +} + +const wrappedJoin = performance.timerify(benchmarkJoin); +const obsJoin = new PerformanceObserver((list) => { + const timed = list.getEntries()[0].duration / mainrun + console.log(`join ${timed} ms`); + obsJoin.disconnect(); +}); +obsJoin.observe({ entryTypes: ['function'] }); +wrappedJoin(); From e99a0b6e70e8b1f653e89b48f02574b1e4449406 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Mon, 1 Jul 2019 22:36:22 +0100 Subject: [PATCH 60/78] updated urls in package.json --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4d96c0d..3cf6ce7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "shamir", - "version": "0.7.0", + "version": "0.7.0.1", "description": "A JavaScript implementation of Shamir's Secret Sharing algorithm over GF(256).", "main": "src/main/js/Scheme.js", "scripts": { @@ -10,7 +10,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/codahale/shamir.git" + "url": "git+https://github.com/simbo1905/shamir.git" }, "keywords": [ "sss", @@ -23,9 +23,9 @@ "author": "Simon Massey", "license": "Apache-2.0", "bugs": { - "url": "https://github.com/codahale/shamir/issues" + "url": "https://github.com/simbo1905/shamir/issues" }, - "homepage": "https://github.com/codahale/shamir#readme", + "homepage": "https://github.com/simbo1905/shamir#readme", "devDependencies": { "eslint": "^6.0.1", "eslint-config-prettier": "^6.0.0", From 54861aab6d4eeaf92276d915903e059e6c29669d Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Mon, 1 Jul 2019 22:38:40 +0100 Subject: [PATCH 61/78] fixed version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3cf6ce7..534fd97 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "shamir", - "version": "0.7.0.1", + "version": "0.7.1", "description": "A JavaScript implementation of Shamir's Secret Sharing algorithm over GF(256).", "main": "src/main/js/Scheme.js", "scripts": { From 4698dc1bdc7acaa9be18cdc27728bf086207c67c Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Mon, 1 Jul 2019 22:41:30 +0100 Subject: [PATCH 62/78] fixed figure in bench mark --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9ed9c24..47fd87a 100644 --- a/README.md +++ b/README.md @@ -145,12 +145,12 @@ 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 get random polynomials per byte of the secet. Using a more realistic 128 bit secret with `n=4,k=3` scheme running on NodeJS v10.16.0: +Split is dominated by the calls to get secure random polynomials for 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 1024 200 0.083 ms/op -Benchmarks.split 5 1024 200 0.081 ms/op +Benchmarks.join 5 16 200 0.083 ms/op +Benchmarks.split 5 16 200 0.081 ms/op ``` ## Tiered sharing From df7d24ea2797f72b9d71938ddfe4c3e59baac7c1 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Mon, 1 Jul 2019 22:56:56 +0100 Subject: [PATCH 63/78] tidy up of sample code --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 47fd87a..51cd73d 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,12 @@ algorithm](http://en.wikipedia.org/wiki/Shamir's_Secret_Sharing) over GF(256) in *Note: module name for Java 9+ is `com.codahale.shamir`.* +## Add to your JavaScript project + +```sh +npm i shamir +``` + ## Use the thing in Java ```java @@ -47,11 +53,11 @@ const QUORUM = 3; function doIt() { const secret = 'hello there'; - // you can use any polyfill to covert string to Uint8Array + // you can use any polyfill to covert between strings and Uint8Array const utf8Encoder = new TextEncoder(); const utf8Decoder = new TextDecoder(); const secretBytes = utf8Encoder.encode('hello there'); - // parts is a object whos keys are the part number and values are an Uint8Array + // 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]; From ff4709e00aad25bcc5ec215d20438b2e7bc3165f Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Mon, 1 Jul 2019 22:58:11 +0100 Subject: [PATCH 64/78] tidy up of sample code --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 51cd73d..3f256d3 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ function doIt() { // you can use any polyfill to covert between strings and Uint8Array const utf8Encoder = new TextEncoder(); const utf8Decoder = new TextDecoder(); - const secretBytes = utf8Encoder.encode('hello there'); + 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 From bc783ac50a0d1e4301abd40f3f924aa26a86d5ca Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Mon, 1 Jul 2019 22:58:58 +0100 Subject: [PATCH 65/78] tidy up of sample code --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3f256d3..6934540 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,8 @@ function doIt() { // 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]; + delete parts['2']; + delete parts['3']; // recovered is an Unit8Array const recovered = join(parts); // prints 'hello there' From 48b80a343526d60fb513014600d9c71fc60ed806 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Mon, 1 Jul 2019 23:03:01 +0100 Subject: [PATCH 66/78] made test like the example code --- src/test/js/SchemeTests.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/js/SchemeTests.js b/src/test/js/SchemeTests.js index ee2eb6a..373c4ae 100644 --- a/src/test/js/SchemeTests.js +++ b/src/test/js/SchemeTests.js @@ -60,9 +60,10 @@ test('SchemeTests roundtrip', function (t) { const splits = split(randomBytes, parts, quorum, secret); // only quorum parts are necessary - delete parts[2]; - delete parts[3]; - t.equal(Object.keys(splits).length, parts); + + delete splits['2']; + delete splits['3']; + const joined = join(splits); t.equal(joined[200], secret[200]); t.equal(joined[201], secret[201]); From 4487075e58fdf7ddd9bb69f2b61743c68a722976 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Tue, 2 Jul 2019 20:11:05 +0100 Subject: [PATCH 67/78] Tiered Sharing JavaScript --- README.md | 42 ++++++++++++++++- package.json | 5 +- src/test/js/TieredSharing.js | 91 ++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 4 deletions(-) create mode 100644 src/test/js/TieredSharing.js diff --git a/README.md b/README.md index 6934540..b14775d 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ Benchmarks.join 5 16 200 0.083 ms/op Benchmarks.split 5 16 200 0.081 ms/op ``` -## Tiered sharing +## 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 @@ -171,7 +171,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 admins = adminScheme.split(secret); // tier 2 of the tree @@ -198,6 +198,44 @@ 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 + +Recovering a secret requires two admin shares and three user shares: + +```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 } ); +``` + ## License Copyright © 2017 Coda Hale diff --git a/package.json b/package.json index 534fd97..29172f4 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A JavaScript implementation of Shamir's Secret Sharing algorithm over GF(256).", "main": "src/main/js/Scheme.js", "scripts": { - "test": "tape src/test/js/GF256Tests.js src/test/js/SchemeTests.js", + "test": "tape src/test/js/GF256Tests.js src/test/js/SchemeTests.js src/test/js/TieredSharing.js", "testwithjava": "node --jvm --vm.cp=./target/classes:./target/test-classes src/test/js/PolygotTests.js", "lint": "eslint ./src/main/js/GF256.js ./src/main/js/Scheme.js ./src/test/js/GF256Tests.js ./src/test/js/SchemeTests.js ./src/test/js/PolygotTests.js && echo 'Lint complete.'" }, @@ -18,7 +18,8 @@ "secrets", "sharing", "crypto", - "nuclear-codes" + "nuclear-codes", + "shamir-secret-sharing" ], "author": "Simon Massey", "license": "Apache-2.0", diff --git a/src/test/js/TieredSharing.js b/src/test/js/TieredSharing.js new file mode 100644 index 0000000..195660c --- /dev/null +++ b/src/test/js/TieredSharing.js @@ -0,0 +1,91 @@ +/* + * Copyright © 2019 Simon Massey (massey1905@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const test = require('tape'); + +const { split, join } = require('../../main/js/Scheme.js'); + +const { randomBytes } = require('crypto'); + +/* eslint-disable prefer-arrow-callback */ +/* eslint-disable func-names */ +/* eslint-disable no-plusplus */ +/* eslint-disable no-bitwise */ + +// https://codereview.stackexchange.com/a/3589/75693 +function bytesToSring(bytes) { + const chars = []; + for (let i = 0, n = bytes.length; i < n;) { + chars.push(((bytes[i++] & 0xff) << 8) | (bytes[i++] & 0xff)); + } + return String.fromCharCode.apply(null, chars); +} + + +// https://codereview.stackexchange.com/a/3589/75693 +function stringToBytes(str) { + const bytes = []; + for (let i = 0, n = str.length; i < n; i++) { + const char = str.charCodeAt(i); + bytes.push(char >>> 8, char & 0xff); + } + return bytes; +} + +test('TieredSharing roundtrip', function (t) { + + const secretUtf8 = 'ᚠᛇᚻ'; + const secret = stringToBytes(secretUtf8); + + 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']}`); + + // reconstruct the secret with two admin shares + const joinedAdminShares = join(adminSplits); + t.equal(secretUtf8, bytesToSring(joinedAdminShares)); + + // throw away second admin share we only have one remaining + delete adminSplits['2']; + // throw away one user share as we only need three + delete usersSplits['1']; + + // reconstruct the third admin share from the three user shares + const joinedUserShares = join(usersSplits); + + // use the first admin share and the recovered third share + const mixedShares = { '1': adminSplits['1'], '3': joinedUserShares }; + const joinedMixedShares = join(mixedShares); + t.equal(secretUtf8, bytesToSring(joinedMixedShares)); + t.end(); +}); From 8b7f874f139072a31f310dc7f3471569443d862b Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Tue, 2 Jul 2019 20:14:17 +0100 Subject: [PATCH 68/78] wording around performance of js --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b14775d..2272d51 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ 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 get secure random polynomials for each byte of the secet. Using a more realistic 128 bit secret with `n=4,k=3` scheme running on NodeJS v10.16.0: +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 From 5d9502716910b7ceeb57670acb588d7d3f4d4333 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Tue, 2 Jul 2019 20:17:54 +0100 Subject: [PATCH 69/78] tidy up of TieredSharing example --- README.md | 2 ++ src/test/js/TieredSharing.js | 10 ---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2272d51..eb54862 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,8 @@ Recovering a secret requires two admin shares and three user shares: 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 diff --git a/src/test/js/TieredSharing.js b/src/test/js/TieredSharing.js index 195660c..a59665d 100644 --- a/src/test/js/TieredSharing.js +++ b/src/test/js/TieredSharing.js @@ -61,16 +61,6 @@ test('TieredSharing roundtrip', function (t) { // 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']}`); - // reconstruct the secret with two admin shares const joinedAdminShares = join(adminSplits); t.equal(secretUtf8, bytesToSring(joinedAdminShares)); From 4144409f2bf716a980a9ba29dd24fe002808882d Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Tue, 2 Jul 2019 20:22:04 +0100 Subject: [PATCH 70/78] clarity --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb54862..87e77e3 100644 --- a/README.md +++ b/README.md @@ -200,7 +200,7 @@ users agree. ## Tiered Sharing JavaScript -Recovering a secret requires two admin shares and three user shares: +Sharing a secret requiring either two admins or one admin and three users to recover: ```javascript const secret = new Unit8Array([1, 2, 3]); From 545dcc328dc6a650a60067df42acd8f49944b284 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Wed, 5 Jul 2023 20:01:46 +0100 Subject: [PATCH 71/78] Update README.md --- README.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/README.md b/README.md index 87e77e3..4933680 100644 --- a/README.md +++ b/README.md @@ -5,18 +5,6 @@ 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. -## Add to your Java project - -```xml - - com.codahale - shamir - 0.7.0 - -``` - -*Note: module name for Java 9+ is `com.codahale.shamir`.* - ## Add to your JavaScript project ```sh From b4cc321155d231bb8024f32594a7f4f32f419067 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 12 Nov 2023 20:16:06 +0000 Subject: [PATCH 72/78] Tests under Docker runs on latest GraalVM --- .circleci/config.yml | 71 ------------------- Dockerfile.graaljs | 8 +-- README.md | 66 +++++++++-------- .../shamir/polygot/JavaScriptUtils.java | 14 ++-- .../shamir/polygot/NotRandomSource.java | 7 +- .../codahale/shamir/polygot/package-info.java | 19 ++++- test_js_against_java.sh | 16 +++++ 7 files changed, 81 insertions(+), 120 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 74b9e0f..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,71 +0,0 @@ -# -# Copyright © 2017 Coda Hale (coda.hale@gmail.com) -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -version: 2 -jobs: - build: - docker: - - image: maven:3-jdk-12-alpine - working_directory: ~/repo - environment: - MAVEN_OPTS: -Xmx3200m - steps: - - checkout - - restore_cache: - keys: - - v1-dependencies-{{ checksum ".circleci/config.yml" }}-{{ checksum "pom.xml" }} - # fallback to using the latest cache if no exact match is found - - v1-dependencies- - - run: mvn clean verify - - save_cache: - paths: - - ~/.m2 - key: v1-dependencies-{{ checksum ".circleci/config.yml" }}-{{ checksum "pom.xml" }} - - run: - name: Save test results - command: | - mkdir -p ~/junit/ - find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} ~/junit/ \; - when: always - - store_test_results: - path: ~/junit - - store_artifacts: - path: ~/junit - - persist_to_workspace: - root: ~/repo - paths: - - src - - target - - package.json - - package-lock.json - - testjs: - docker: - - image: oracle/graalvm-ce:latest - working_directory: ~/repo - steps: - - attach_workspace: - at: ~/repo - - run: npm install tape --save-dev - - run: npm test && npm run testwithjava -workflows: - version: 2 - build_and_test: - jobs: - - build - - testjs: - requires: - - build \ No newline at end of file diff --git a/Dockerfile.graaljs b/Dockerfile.graaljs index f733b1e..cd87f5c 100644 --- a/Dockerfile.graaljs +++ b/Dockerfile.graaljs @@ -1,11 +1,11 @@ # Run the stand java build on openjdk -FROM maven:3-jdk-12-alpine AS build +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 oracle/graalvm-ce:latest AS graal -COPY --from=build /src /src +# 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 diff --git a/README.md b/README.md index 87e77e3..b402dc6 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,13 @@ # Shamir's Secret Sharing -[![CircleCI](https://circleci.com/gh/simbo1905/shamir.svg?style=svg)](https://circleci.com/gh/simbo1905/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. +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. -## Add to your Java project +You can use docker build both codebases and run cross-checks between them using: -```xml - - com.codahale - shamir - 0.7.0 - -``` +`docker build -f Dockerfile.graaljs . ` *Note: module name for Java 9+ is `com.codahale.shamir`.* @@ -23,25 +17,6 @@ algorithm](http://en.wikipedia.org/wiki/Shamir's_Secret_Sharing) over GF(256) in npm i shamir ``` -## Use the thing in Java - -```java -import com.codahale.shamir.Scheme; -import java.nio.charset.StandardCharsets; -import java.security.SecureRandom; -import java.util.Map; - -class Example { - void doIt() { - final Scheme scheme = new Scheme(new SecureRandom(), 5, 3); - final byte[] secret = "hello there".getBytes(StandardCharsets.UTF_8); - final Map parts = scheme.split(secret); - final byte[] recovered = scheme.join(parts); - System.out.println(new String(recovered, StandardCharsets.UTF_8)); - } -} -``` - ## Use the thing in JavaScript ```javascript @@ -69,6 +44,37 @@ function doIt() { } ``` +## [Optional] Add to your Java project + +The Java version is available as the orginal Codahale distribution: + +```xml + + com.codahale + shamir + 0.7.0 + +``` + +## Use the thing in Java + +```java +import com.codahale.shamir.Scheme; +import java.nio.charset.StandardCharsets; +import java.security.SecureRandom; +import java.util.Map; + +class Example { + void doIt() { + final Scheme scheme = new Scheme(new SecureRandom(), 5, 3); + final byte[] secret = "hello there".getBytes(StandardCharsets.UTF_8); + final Map parts = scheme.split(secret); + final byte[] recovered = scheme.join(parts); + System.out.println(new String(recovered, StandardCharsets.UTF_8)); + } +} +``` + ## How it works Shamir's Secret Sharing algorithm is a way to split an arbitrary secret `S` into `N` parts, of which diff --git a/src/test/java/com/codahale/shamir/polygot/JavaScriptUtils.java b/src/test/java/com/codahale/shamir/polygot/JavaScriptUtils.java index 3f673fb..dbff7a1 100644 --- a/src/test/java/com/codahale/shamir/polygot/JavaScriptUtils.java +++ b/src/test/java/com/codahale/shamir/polygot/JavaScriptUtils.java @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Simon Massey (massey1905@gmail.com) + * Copyright © 2017 Coda Hale (coda.hale@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +22,10 @@ import java.util.stream.Collectors; /** - * The GraalJS internals cannot be fooled into casting between unsigned - * JavaScript bytes and signed Java bytes. We only ever want to - * do this within unit tests to compare arrays in-memory. This class uses - * an inefficent workaround of building bidirectional maps. The keys are - * Integer to fit a signed byte. + * The GraalJS internals cannot be fooled into casting between unsigned JavaScript bytes and signed + * Java bytes. We only ever want to do this within unit tests to compare arrays in-memory. This + * class uses an inefficent workaround of building bidirectional maps. The keys are Integer to fit a + * signed byte. */ public class JavaScriptUtils { // https://stackoverflow.com/a/12310078/329496 @@ -39,7 +38,7 @@ static Map signedToUnsignedByteMap() { for (byte b = Byte.MIN_VALUE; ; b++) { final String bits = byteToBinaryString(b); final Integer i = Integer.parseInt(bits, 2) & 0xff; - result.put((int)b, i); + result.put((int) b, i); // here we avoid overflow on b++ causing an infinit loop if (b == Byte.MAX_VALUE) break; } @@ -51,5 +50,4 @@ static Map signedToUnsignedByteMap() { public static Map unsignedToSignedByteMap = signedToUnsignedByteMap.entrySet().stream() .collect(Collectors.toMap(Entry::getValue, Entry::getKey));; - } diff --git a/src/test/java/com/codahale/shamir/polygot/NotRandomSource.java b/src/test/java/com/codahale/shamir/polygot/NotRandomSource.java index 0d4bb52..51798aa 100644 --- a/src/test/java/com/codahale/shamir/polygot/NotRandomSource.java +++ b/src/test/java/com/codahale/shamir/polygot/NotRandomSource.java @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Simon Massey (massey1905@gmail.com) + * Copyright © 2017 Coda Hale (coda.hale@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,10 +17,7 @@ import java.security.SecureRandom; -/** - * This class ensures that unit tests can repeatedly initalise with - * the same polynomial. - */ +/** This class ensures that unit tests can repeatedly initalise with the same polynomial. */ public class NotRandomSource extends SecureRandom { @Override diff --git a/src/test/java/com/codahale/shamir/polygot/package-info.java b/src/test/java/com/codahale/shamir/polygot/package-info.java index 766d31d..064fdde 100644 --- a/src/test/java/com/codahale/shamir/polygot/package-info.java +++ b/src/test/java/com/codahale/shamir/polygot/package-info.java @@ -1,5 +1,20 @@ /* - * This package provides classes to aid testing JavaScript against Java within - * the same JVM using GraalJS. + * Copyright © 2017 Coda Hale (coda.hale@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * This package provides classes to aid testing JavaScript against Java within + * the same JVM using GraalJS. */ package com.codahale.shamir.polygot; diff --git a/test_js_against_java.sh b/test_js_against_java.sh index 6f84f09..08e25bf 100755 --- a/test_js_against_java.sh +++ b/test_js_against_java.sh @@ -1,3 +1,19 @@ #!/bin/sh +# +# Copyright © 2017 Coda Hale (coda.hale@gmail.com) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + # This tests the docker build -f Dockerfile.graaljs . \ No newline at end of file From 873977012540545181d3b0527cfa3765318815d7 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 12 Nov 2023 20:22:16 +0000 Subject: [PATCH 73/78] restore circleci --- .circleci/config.yml | 72 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 74 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..9417e4e --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,72 @@ +# +# Copyright © 2017 Coda Hale (coda.hale@gmail.com) +# Copyright © 2019 Simon Massey +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +version: 2 +jobs: + build: + docker: + - image: maven + working_directory: ~/repo + environment: + MAVEN_OPTS: -Xmx3200m + steps: + - checkout + - restore_cache: + keys: + - v1-dependencies-{{ checksum ".circleci/config.yml" }}-{{ checksum "pom.xml" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + - run: mvn clean verify + - save_cache: + paths: + - ~/.m2 + key: v1-dependencies-{{ checksum ".circleci/config.yml" }}-{{ checksum "pom.xml" }} + - run: + name: Save test results + command: | + mkdir -p ~/junit/ + find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} ~/junit/ \; + when: always + - store_test_results: + path: ~/junit + - store_artifacts: + path: ~/junit + - persist_to_workspace: + root: ~/repo + paths: + - src + - target + - package.json + - package-lock.json + + testjs: + docker: + - image: ghcr.io/graalvm/nodejs-community:23.0.2-jvm17-ol9-20231024 + working_directory: ~/repo + steps: + - attach_workspace: + at: ~/repo + - run: npm install tape --save-dev + - run: npm test && npm run testwithjava +workflows: + version: 2 + build_and_test: + jobs: + - build + - testjs: + requires: + - build diff --git a/README.md b/README.md index b402dc6..258af20 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Shamir's Secret Sharing +[![CircleCI](https://circleci.com/gh/simbo1905/shamir.svg?style=svg)](https://circleci.com/gh/simbo1905/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 From b241d65b169a856f1a954117b145d78ba76a5223 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 12 Nov 2023 20:30:27 +0000 Subject: [PATCH 74/78] touch --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9417e4e..ad56480 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - version: 2 jobs: build: From 9c74a58951abeccef189954389c2a95e29c20815 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 12 Nov 2023 20:50:31 +0000 Subject: [PATCH 75/78] getting circleci to build --- .circleci/config.yml | 2 +- pom.xml | 182 +++++++++++++++++++++++++------------------ 2 files changed, 109 insertions(+), 75 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ad56480..7721085 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,5 @@ # # Copyright © 2017 Coda Hale (coda.hale@gmail.com) -# Copyright © 2019 Simon Massey # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # + version: 2 jobs: build: diff --git a/pom.xml b/pom.xml index 25a8e9b..db941d9 100644 --- a/pom.xml +++ b/pom.xml @@ -16,84 +16,118 @@ limitations under the License. --> - - 4.0.0 - - com.codahale - common-pom - 0.0.19 - + + 4.0.0 - shamir - 0.7.1-SNAPSHOT - Shamir's Secret Sharing - https://github.com/codahale/shamir - - An implementation of Shamir's Secret Sharing algorithm over GF(256). - - 2017 - - scm:git:https://github.com/codahale/shamir.git - scm:git:https://github.com/codahale/shamir.git + shamir + com.codahale + 0.7.1-SNAPSHOT + Shamir's Secret Sharing https://github.com/codahale/shamir - HEAD - + + An implementation of Shamir's Secret Sharing algorithm over GF(256). + + + 2017 + + scm:git:https://github.com/codahale/shamir.git + scm:git:https://github.com/codahale/shamir.git + https://github.com/codahale/shamir + HEAD + + + 17 + 17 + 1.21 + + + + com.google.guava + guava + 27.0.1-jre + test + + + + org.quicktheories + quicktheories + 0.26 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.9.2 + test + + + org.assertj + assertj-core + 3.24.2 + test + + + org.openjdk.jmh + jmh-core + ${jmh.version} - - - com.google.guava - guava - test - - + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + test + + - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - com.codahale.shamir - - - - - - - - - - com.mycila - license-maven-plugin - 3.0 - -
com/mycila/maven/plugin/license/templates/APACHE-2.txt
- - Coda Hale - coda.hale@gmail.com - - - SLASHSTAR_STYLE - - - - - LICENSE - - **/*.txt - **/*.js - - src/main/resources/** - src/test/resources/** - node_modules/** - -
-
-
-
+ + + + + org.apache.maven.plugins + maven-jar-plugin + + + + com.codahale.shamir + + + + + + + + + + com.mycila + license-maven-plugin + 3.0 + +
com/mycila/maven/plugin/license/templates/APACHE-2.txt
+ + Coda Hale + coda.hale@gmail.com + + + SLASHSTAR_STYLE + + + + + LICENSE + + **/*.txt + **/*.js + + src/main/resources/** + src/test/resources/** + node_modules/** + +
+
+
+
From 6fc4a0680703a93424733e66d47e1a6ea192210c Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 12 Nov 2023 21:12:58 +0000 Subject: [PATCH 76/78] Create docker-image.yml --- .github/workflows/docker-image.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..eac633f --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,18 @@ +name: Docker Image CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build the Docker image + run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) From 59bb032e228adb619e232f7b17c780ea720ddea7 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 12 Nov 2023 21:14:42 +0000 Subject: [PATCH 77/78] gh action --- .circleci/config.yml | 71 ------------------------------ .github/workflows/docker-image.yml | 2 +- Dockerfile.graaljs => Dockerfile | 0 README.md | 2 +- 4 files changed, 2 insertions(+), 73 deletions(-) delete mode 100644 .circleci/config.yml rename Dockerfile.graaljs => Dockerfile (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 7721085..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,71 +0,0 @@ -# -# Copyright © 2017 Coda Hale (coda.hale@gmail.com) -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -version: 2 -jobs: - build: - docker: - - image: maven - working_directory: ~/repo - environment: - MAVEN_OPTS: -Xmx3200m - steps: - - checkout - - restore_cache: - keys: - - v1-dependencies-{{ checksum ".circleci/config.yml" }}-{{ checksum "pom.xml" }} - # fallback to using the latest cache if no exact match is found - - v1-dependencies- - - run: mvn clean verify - - save_cache: - paths: - - ~/.m2 - key: v1-dependencies-{{ checksum ".circleci/config.yml" }}-{{ checksum "pom.xml" }} - - run: - name: Save test results - command: | - mkdir -p ~/junit/ - find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} ~/junit/ \; - when: always - - store_test_results: - path: ~/junit - - store_artifacts: - path: ~/junit - - persist_to_workspace: - root: ~/repo - paths: - - src - - target - - package.json - - package-lock.json - - testjs: - docker: - - image: ghcr.io/graalvm/nodejs-community:23.0.2-jvm17-ol9-20231024 - working_directory: ~/repo - steps: - - attach_workspace: - at: ~/repo - - run: npm install tape --save-dev - - run: npm test && npm run testwithjava -workflows: - version: 2 - build_and_test: - jobs: - - build - - testjs: - requires: - - build diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index eac633f..1f7d116 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -15,4 +15,4 @@ jobs: steps: - uses: actions/checkout@v3 - name: Build the Docker image - run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) + run: docker build . --file Dockerfile --tag shamir-js-$(date +%s) diff --git a/Dockerfile.graaljs b/Dockerfile similarity index 100% rename from Dockerfile.graaljs rename to Dockerfile diff --git a/README.md b/README.md index 258af20..dc8ca9a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Javascript version is original and is crossed checked against the Java version. You can use docker build both codebases and run cross-checks between them using: -`docker build -f Dockerfile.graaljs . ` +`docker build . ` *Note: module name for Java 9+ is `com.codahale.shamir`.* From 7ad6270ed0f34a39ed3c55244387d277bd0c1bda Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Sun, 12 Nov 2023 21:21:01 +0000 Subject: [PATCH 78/78] abandon ci --- .github/workflows/docker-image.yml | 18 ------------------ README.md | 2 -- 2 files changed, 20 deletions(-) delete mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index 1f7d116..0000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Docker Image CI - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -jobs: - - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag shamir-js-$(date +%s) diff --git a/README.md b/README.md index dc8ca9a..248caa1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # Shamir's Secret Sharing -[![CircleCI](https://circleci.com/gh/simbo1905/shamir.svg?style=svg)](https://circleci.com/gh/simbo1905/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