From 715a84c6f2683c3111e3fb3450fd1466b493a942 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 7 Jun 2022 12:51:41 +0200 Subject: [PATCH] Moved hashing to native python3 hashlib --- RNS/Destination.py | 6 +----- RNS/Identity.py | 7 ++++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/RNS/Destination.py b/RNS/Destination.py index 7ea5478..90839b2 100755 --- a/RNS/Destination.py +++ b/RNS/Destination.py @@ -26,7 +26,6 @@ import time import RNS from cryptography.fernet import Fernet -from cryptography.hazmat.primitives import hashes from cryptography.hazmat.backends import default_backend class Callbacks: @@ -97,10 +96,7 @@ class Destination: name = Destination.full_name(app_name, *aspects) # Create a digest for the destination - digest = hashes.Hash(hashes.SHA256(), backend=default_backend()) - digest.update(name.encode("UTF-8")) - - return digest.finalize()[:10] + return RNS.Identity.full_hash(name.encode("utf-8"))[:RNS.Reticulum.TRUNCATED_HASHLENGTH//8] @staticmethod def app_and_aspects_from_name(full_name): diff --git a/RNS/Identity.py b/RNS/Identity.py index abf0918..7ed3f26 100644 --- a/RNS/Identity.py +++ b/RNS/Identity.py @@ -27,9 +27,10 @@ import RNS import time import atexit import base64 +import hashlib + from .vendor import umsgpack as umsgpack from cryptography.hazmat.backends import default_backend -from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey, Ed25519PublicKey from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey, X25519PublicKey @@ -158,10 +159,10 @@ class Identity: :param data: Data to be hashed as *bytes*. :returns: SHA-256 hash as *bytes* """ - digest = hashes.Hash(hashes.SHA256(), backend=default_backend()) + digest = hashlib.sha256() digest.update(data) - return digest.finalize() + return digest.digest() @staticmethod def truncated_hash(data):