|
@@ -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)
|