Bladeren bron

crypto blake2: don't release the GIL during key hashing

Marian Beermann 8 jaren geleden
bovenliggende
commit
76c93bb80b
2 gewijzigde bestanden met toevoegingen van 5 en 2 verwijderingen
  1. 0 0
      src/borg/blake2/openssl-b2.c
  2. 5 2
      src/borg/crypto.pyx

+ 0 - 0
src/borg/blake2/openssl-b2.c


+ 5 - 2
src/borg/crypto.pyx

@@ -218,7 +218,7 @@ cdef blake2b_update_from_buffer(blake2b_state *state, obj):
         with nogil:
             rc = blake2b_update(state, buf.buf, buf.len)
         if rc == -1:
-            raise Exception('blake2b_update(key) failed')
+            raise Exception('blake2b_update() failed')
     finally:
         PyBuffer_Release(&buf)
 
@@ -230,13 +230,16 @@ def blake2b_256(key, data):
 
     md = bytes(32)
     cdef unsigned char *md_ptr = md
+    cdef unsigned char *key_ptr = key
 
     # This is secure, because BLAKE2 is not vulnerable to length-extension attacks (unlike SHA-1/2, MD-5 and others).
     # See the BLAKE2 paper section 2.9 "Keyed hashing (MAC and PRF)" for details.
     # A nice benefit is that this simpler prefix-MAC mode has less overhead than the more complex HMAC mode.
     # We don't use the BLAKE2 parameter block (via blake2s_init_key) for this to
     # avoid incompatibility with the limited API of OpenSSL.
-    blake2b_update_from_buffer(&state, key)
+    rc = blake2b_update(&state, key_ptr, len(key))
+    if rc == -1:
+        raise Exception('blake2b_update() failed')
     blake2b_update_from_buffer(&state, data)
 
     rc = blake2b_final(&state, md_ptr, 32)