Skip to content

Commit

Permalink
got rid of math.ceil
Browse files Browse the repository at this point in the history
  • Loading branch information
miketery committed Jan 20, 2022
1 parent 45e55e9 commit 9192d77
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/Crypto/Protocol/SecretSharing.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# ===================================================================
from math import ceil

from Crypto.Util.py3compat import is_native_int
from Crypto.Util import number
from Crypto.Util.number import long_to_bytes, bytes_to_long
Expand Down Expand Up @@ -286,11 +284,11 @@ def split_large(k, n, secret, ssss=False):
when len(key) > SHAMIR_BLOCK_SIZE (16)
"""
if isinstance(secret, bytes) is not True:
raise TypeError("secret must be bytes")
raise TypeError("Secret must be bytes")
if len(secret) % 16 != 0:
raise ValueError("secret size must be in 16 byte increments")
raise ValueError("Secret size must be in 16 byte increments")

blocks = ceil(len(secret) / 16)
blocks = len(secret) // SHAMIR_BLOCK_SIZE
shares = [b'' for _ in range(n)]
for i in range(blocks):
block_shares = Shamir.split(k, n,
Expand All @@ -306,7 +304,12 @@ def combine_large(shares, ssss=False):
when len(key) > SHAMIR_BLOCK_SIZE (16)
"""
share_len = len(shares[0][1])
blocks = ceil(share_len / SHAMIR_BLOCK_SIZE)
for share in shares:
if len(share[1]) % 16 != 0:
raise ValueError(f"Share #{share[0]} is not in 16 byte increments")
if len(share[1]) != share_len:
raise ValueError(f"Share sizes are inconsistant")
blocks = share_len // SHAMIR_BLOCK_SIZE
result = b''
for i in range(blocks):
block_shares = [
Expand Down

0 comments on commit 9192d77

Please sign in to comment.