1
0

fast hmac on python 3.7+

This commit is contained in:
SomberNight
2018-06-28 11:42:47 +02:00
committed by ThomasV
parent 2b93593e3f
commit bc0036297b
3 changed files with 17 additions and 8 deletions

View File

@@ -26,6 +26,7 @@
import base64
import os
import hashlib
import hmac
import pyaes
@@ -140,3 +141,11 @@ def hash_160(x: bytes) -> bytes:
from . import ripemd
md = ripemd.new(sha256(x))
return md.digest()
def hmac_oneshot(key: bytes, msg: bytes, digest) -> bytes:
if hasattr(hmac, 'digest'):
# requires python 3.7+; faster
return hmac.digest(key, msg, digest)
else:
return hmac.new(key, msg, digest).digest()