ntc-rcrypto 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rcrypto/sss.rb +14 -19
- data/lib/rcrypto/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 014b37d0b14bd5a1bc2472553a24f4e9096dae19961305e7a86bca2494ac88e0
|
4
|
+
data.tar.gz: f6b09ae301d179227725b6a98ac22b37fd0a81a188c49a64f4c7d11fdbe16497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b816de8c6bdbf36c91925ff3f33cb9e10456088743242c2c36fb41415d802dc35d33fe0dc479269ff109f6996f339910c4ea85beecd50a71c2ad0412fe2dc8a3
|
7
|
+
data.tar.gz: 83fbb70f907106e4f25e56e360061d410cf75bd0d0b8af0067083888043f82e0825e0988534e8af2e1f1ddf97459fd9ffb07df33fab0a69977feb3e76b6780ea
|
data/lib/rcrypto/sss.rb
CHANGED
@@ -163,6 +163,7 @@ module Rcrypto
|
|
163
163
|
result
|
164
164
|
end
|
165
165
|
|
166
|
+
# Remove right character '0'
|
166
167
|
def trim_right(s)
|
167
168
|
i = s.length - 1
|
168
169
|
while i >= 0 && s[i] == '0'
|
@@ -315,9 +316,13 @@ module Rcrypto
|
|
315
316
|
# Verify minimum isn't greater than shares; there is no way to recreate
|
316
317
|
# the original polynomial in our current setup, therefore it doesn't make
|
317
318
|
# sense to generate fewer shares than are needed to reconstruct the secrets.
|
319
|
+
if minimum <= 0 || shares <= 0
|
320
|
+
raise Exception('minimum or shares is invalid')
|
321
|
+
end
|
318
322
|
if minimum > shares
|
319
323
|
raise Exception('cannot require more shares then existing')
|
320
324
|
end
|
325
|
+
raise Exception('secret is NULL or empty') if secret.empty?
|
321
326
|
|
322
327
|
# Convert the secrets to its respective 256-bit Int representation.
|
323
328
|
secrets = split_secret_to_int(secret)
|
@@ -340,13 +345,13 @@ module Rcrypto
|
|
340
345
|
j = 1
|
341
346
|
while j < minimum
|
342
347
|
# Each coefficient should be unique
|
343
|
-
|
344
|
-
while in_numbers(numbers,
|
345
|
-
|
348
|
+
x = random_number()
|
349
|
+
while in_numbers(numbers, x)
|
350
|
+
x = random_number()
|
346
351
|
end
|
347
352
|
|
348
|
-
numbers.append(
|
349
|
-
subpoly.push(
|
353
|
+
numbers.append(x)
|
354
|
+
subpoly.push(x)
|
350
355
|
j += 1
|
351
356
|
end
|
352
357
|
polynomial.push(subpoly)
|
@@ -359,23 +364,15 @@ module Rcrypto
|
|
359
364
|
#
|
360
365
|
# Note: this array is technically unnecessary due to creating result
|
361
366
|
# in the inner loop. Can disappear later if desired.
|
362
|
-
#
|
363
|
-
# points[shares][parts][2]
|
364
|
-
points = []
|
365
367
|
for i in 0...shares
|
366
368
|
s = ''
|
367
|
-
arrsh = []
|
368
369
|
for j in 0...secrets.length
|
369
|
-
arrxy = []
|
370
370
|
# generate a new x-coordinate.
|
371
|
-
|
372
|
-
while in_numbers(numbers,
|
373
|
-
|
371
|
+
x = random_number()
|
372
|
+
while in_numbers(numbers, x)
|
373
|
+
x = random_number()
|
374
374
|
end
|
375
|
-
|
376
|
-
y = evaluate_polynomial(polynomial, j, number)
|
377
|
-
arrxy.push(x)
|
378
|
-
arrxy.push(y)
|
375
|
+
y = evaluate_polynomial(polynomial, j, x)
|
379
376
|
if is_base64
|
380
377
|
s += to_base64(x)
|
381
378
|
s += to_base64(y)
|
@@ -383,9 +380,7 @@ module Rcrypto
|
|
383
380
|
s += to_hex(x)
|
384
381
|
s += to_hex(y)
|
385
382
|
end
|
386
|
-
arrsh.push(arrxy)
|
387
383
|
end
|
388
|
-
points.push(arrsh)
|
389
384
|
result.push(s)
|
390
385
|
end
|
391
386
|
result
|
data/lib/rcrypto/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ntc-rcrypto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nghiatc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ntc-rcrypto is module ruby cryptography.
|
14
14
|
email:
|