From 8317698f9bce2ff879acead9f5b02d5959ca8fa2 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 5 Mar 2022 21:22:24 +0100 Subject: [PATCH] hmac_sha256: replace own cython wrapper code by hmac.digest python stdlib (since py38) i measured performance of both: pretty much the same. --- src/borg/crypto/low_level.pyx | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/borg/crypto/low_level.pyx b/src/borg/crypto/low_level.pyx index f726f3150..b43d4a79f 100644 --- a/src/borg/crypto/low_level.pyx +++ b/src/borg/crypto/low_level.pyx @@ -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, 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( &md[0], 32) + return hmac.digest(key, data, 'sha256') def blake2b_256(key, data):