Changeset - b9f1f39cd7af
[Not reviewed]
default
0 2 0
Laman - 4 years ago 2020-04-13 13:53:07

check for non-unique shares on joining
2 files changed with 6 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/condensed.py
Show inline comments
 
@@ -57,12 +57,15 @@ class SException(Exception): pass
 

	
 
def reconstruct_raw(*shares):
 
	"""Tries to recover the secret from its shares.
 

	
 
	:param shares: (((int) i, (bytes) share), ...)
 
	:return: (bytes) reconstructed secret. Too few shares returns garbage."""
 
	if len({x for (x, _) in shares}) < len(shares):
 
		raise SException("Found a non-unique share. Please check your inputs.")
 

	
 
	secret_len = len(shares[0][1])
 
	res = [None]*secret_len
 
	for i in range(secret_len):
 
		points = [(x, s[i]) for (x, s) in shares]
 
		res[i] = (get_constant_coef(*points))
 
	return bytes(res)
src/shamira.py
Show inline comments
 
@@ -37,12 +37,15 @@ def generate_raw(secret, k, n):
 

	
 
def reconstruct_raw(*shares):
 
	"""Tries to recover the secret from its shares.
 

	
 
	:param shares: (((int) i, (bytes) share), ...)
 
	:return: (bytes) reconstructed secret. Too few shares return garbage."""
 
	if len({x for (x, _) in shares}) < len(shares):
 
		raise MalformedShare("Found a non-unique share. Please check your inputs.")
 

	
 
	secret_len = len(shares[0][1])
 
	res = [None]*secret_len
 
	for i in range(secret_len):
 
		points = [(x, s[i]) for (x, s) in shares]
 
		res[i] = (gf256.get_constant_coef(*points))
 
	return bytes(res)
0 comments (0 inline, 0 general)