mirror of
https://github.com/borgbackup/borg.git
synced 2024-11-05 03:25:19 +03:00
hmac_sha256: replace own cython wrapper code by hmac.digest python stdlib (since py38)
i measured performance of both: pretty much the same.
This commit is contained in:
parent
e37a55c5eb
commit
8317698f9b
@ -754,18 +754,7 @@ cdef class AES:
|
||||
|
||||
|
||||
def hmac_sha256(key, data):
|
||||
cdef Py_buffer data_buf = ro_buffer(data)
|
||||
cdef const unsigned char *key_ptr = key
|
||||
cdef int key_len = len(key)
|
||||
cdef unsigned char md[32]
|
||||
try:
|
||||
with nogil:
|
||||
rc = HMAC(EVP_sha256(), key_ptr, key_len, <const unsigned char*> data_buf.buf, data_buf.len, md, NULL)
|
||||
if rc != md:
|
||||
raise CryptoError('HMAC(EVP_sha256) failed')
|
||||
finally:
|
||||
PyBuffer_Release(&data_buf)
|
||||
return PyBytes_FromStringAndSize(<char*> &md[0], 32)
|
||||
return hmac.digest(key, data, 'sha256')
|
||||
|
||||
|
||||
def blake2b_256(key, data):
|
||||
|
Loading…
Reference in New Issue
Block a user