From c55c0302e78bebda87283dcd22f8e4ed31fabafb Mon Sep 17 00:00:00 2001 From: jMyles Date: Tue, 19 Sep 2017 16:13:33 -0700 Subject: [PATCH] Using keccak-256 for hashing. Closes #45. --- nkms/crypto/hash.py | 8 ++++---- nkms/policy/models.py | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/nkms/crypto/hash.py b/nkms/crypto/hash.py index ddfea31ff..41583023e 100644 --- a/nkms/crypto/hash.py +++ b/nkms/crypto/hash.py @@ -1,10 +1,10 @@ -import random +import sha3 + # TODO: Replace these with actual hash functions. - def signature_hash(hash_input): - return random.getrandbits(128) + return sha3.keccak_256(hash_input).digest() def content_hash(hash_input): - return random.getrandbits(128) \ No newline at end of file + return sha3.keccak_256(hash_input).digest() \ No newline at end of file diff --git a/nkms/policy/models.py b/nkms/policy/models.py index 57f2f6a94..d17ea9817 100644 --- a/nkms/policy/models.py +++ b/nkms/policy/models.py @@ -79,8 +79,9 @@ class Policy(object): return policy def hash(self, pubkey_sig_alice, hash_input): + hash_input = str(hash_input).encode() self.hashed_part = content_hash(hash_input) - hash_input_for_id = (pubkey_sig_alice, self.hashed_part) + hash_input_for_id = str(pubkey_sig_alice).encode() + str(self.hashed_part).encode() self.id = content_hash(hash_input_for_id) return self.id