2022-06-08 19:03:58 +00:00
|
|
|
import importlib
|
|
|
|
if importlib.util.find_spec('hashlib') != None:
|
|
|
|
import hashlib
|
|
|
|
else:
|
|
|
|
hashlib = None
|
|
|
|
|
|
|
|
if hasattr(hashlib, "sha512"):
|
|
|
|
from hashlib import sha512 as ext_sha512
|
|
|
|
else:
|
|
|
|
from .SHA512 import sha512 as ext_sha512
|
|
|
|
|
|
|
|
if hasattr(hashlib, "sha256"):
|
|
|
|
from hashlib import sha256 as ext_sha256
|
|
|
|
else:
|
|
|
|
from .SHA256 import sha256 as ext_sha256
|
2022-06-07 13:21:19 +00:00
|
|
|
|
2022-06-08 17:47:09 +00:00
|
|
|
"""
|
|
|
|
The SHA primitives are abstracted here to allow platform-
|
|
|
|
aware hardware acceleration in the future. Currently only
|
|
|
|
uses Python's internal SHA-256 implementation. All SHA-256
|
|
|
|
calls in RNS end up here.
|
|
|
|
"""
|
2022-06-07 13:21:19 +00:00
|
|
|
|
|
|
|
def sha256(data):
|
2022-06-08 19:03:58 +00:00
|
|
|
digest = ext_sha256()
|
2022-06-07 13:21:19 +00:00
|
|
|
digest.update(data)
|
|
|
|
|
2022-06-08 17:47:09 +00:00
|
|
|
return digest.digest()
|
|
|
|
|
|
|
|
def sha512(data):
|
2022-06-08 19:03:58 +00:00
|
|
|
digest = ext_sha512()
|
2022-06-08 17:47:09 +00:00
|
|
|
digest.update(data)
|
|
|
|
|
|
|
|
return digest.digest()
|