Skip to content

Commit

Permalink
Bugfix, use uint8 instead of int8.
Browse files Browse the repository at this point in the history
  • Loading branch information
carter-yagemann committed Mar 27, 2018
1 parent 1a42464 commit ef56d7b
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions fuzzy_extractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
__email__ = '[email protected]'
__copyright__ = 'Copyright (c) 2018 Carter Yagemann'
__license__ = 'GPLv3+'
__version__ = '0.2'
__version__ = '0.3'
__url__ = 'https://github.com/carter-yagemann/python-fuzzy-extractor'
__download_url__ = 'https://github.com/carter-yagemann/python-fuzzy-extractor'
__description__ = 'A Python implementation of fuzzy extractor'
Expand Down Expand Up @@ -87,18 +87,18 @@ def generate(self, value):
:rtype: (key, helper)
"""
if isinstance(value, (bytes, str)):
value = np.fromstring(value, dtype=np.int8)
value = np.fromstring(value, dtype=np.uint8)

key = np.fromstring(urandom(self.length), dtype=np.int8)
key_pad = np.concatenate((key, np.zeros(self.sec_len, dtype=np.int8)))
key = np.fromstring(urandom(self.length), dtype=np.uint8)
key_pad = np.concatenate((key, np.zeros(self.sec_len, dtype=np.uint8)))

nonces = np.zeros((self.num_helpers, self.nonce_len), dtype=np.int8)
masks = np.zeros((self.num_helpers, self.length), dtype=np.int8)
digests = np.zeros((self.num_helpers, self.cipher_len), dtype=np.int8)
nonces = np.zeros((self.num_helpers, self.nonce_len), dtype=np.uint8)
masks = np.zeros((self.num_helpers, self.length), dtype=np.uint8)
digests = np.zeros((self.num_helpers, self.cipher_len), dtype=np.uint8)

for helper in range(self.num_helpers):
nonces[helper] = np.fromstring(urandom(self.nonce_len), dtype=np.int8)
masks[helper] = np.fromstring(urandom(self.length), dtype=np.int8)
nonces[helper] = np.fromstring(urandom(self.nonce_len), dtype=np.uint8)
masks[helper] = np.fromstring(urandom(self.length), dtype=np.uint8)

# By masking the value with random masks, we adjust the probability that given
# another noisy reading of the same source, enough bits will match for the new
Expand All @@ -115,7 +115,7 @@ def generate(self, value):
d_vector = vectors[helper].tobytes()
d_nonce = nonces[helper].tobytes()
digest = pbkdf2_hmac(self.hash_func, d_vector, d_nonce, 1, self.cipher_len)
digests[helper] = np.fromstring(digest, dtype=np.int8)
digests[helper] = np.fromstring(digest, dtype=np.uint8)

ciphers = np.bitwise_xor(digests, key_pad)

Expand All @@ -132,7 +132,7 @@ def reproduce(self, value, helpers):
:rtype: key or None
"""
if isinstance(value, (bytes, str)):
value = np.fromstring(value, dtype=np.int8)
value = np.fromstring(value, dtype=np.uint8)

if self.length != len(value):
raise ValueError('Cannot reproduce key for value of different length')
Expand All @@ -143,12 +143,12 @@ def reproduce(self, value, helpers):

vectors = np.bitwise_and(masks, value)

digests = np.zeros((self.num_helpers, self.cipher_len), dtype=np.int8)
digests = np.zeros((self.num_helpers, self.cipher_len), dtype=np.uint8)
for helper in range(self.num_helpers):
d_vector = vectors[helper].tobytes()
d_nonce = nonces[helper].tobytes()
digest = pbkdf2_hmac(self.hash_func, d_vector, d_nonce, 1, self.cipher_len)
digests[helper] = np.fromstring(digest, dtype=np.int8)
digests[helper] = np.fromstring(digest, dtype=np.uint8)

plains = np.bitwise_xor(digests, ciphers)

Expand Down

0 comments on commit ef56d7b

Please sign in to comment.