Skip to content

Commit ee11049

Browse files
committed
add hacl_get_blake2_info to extract static BLAKE-2 information
- use this new helper in `py_blake2b_get_digest_size` - in the future, exposing `key_length` will be easier
1 parent ff9e872 commit ee11049

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Modules/blake2module.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -918,29 +918,37 @@ py_blake2b_get_block_size(PyObject *op, void *Py_UNUSED(closure))
918918
}
919919

920920

921-
static PyObject *
922-
py_blake2b_get_digest_size(PyObject *op, void *Py_UNUSED(closure))
921+
static Hacl_Hash_Blake2b_index
922+
hacl_get_blake2_info(Blake2Object *self)
923923
{
924-
Blake2Object *self = _Blake2Object_CAST(op);
925924
switch (self->impl) {
926925
#if HACL_CAN_COMPILE_SIMD256
927926
case Blake2b_256:
928-
return PyLong_FromLong(Hacl_Hash_Blake2b_Simd256_info(self->blake2b_256_state).digest_length);
927+
return Hacl_Hash_Blake2b_Simd256_info(self->blake2b_256_state);
929928
#endif
930929
#if HACL_CAN_COMPILE_SIMD128
931930
case Blake2s_128:
932-
return PyLong_FromLong(Hacl_Hash_Blake2s_Simd128_info(self->blake2s_128_state).digest_length);
931+
return Hacl_Hash_Blake2s_Simd128_info(self->blake2s_128_state);
933932
#endif
934933
case Blake2b:
935-
return PyLong_FromLong(Hacl_Hash_Blake2b_info(self->blake2b_state).digest_length);
934+
return Hacl_Hash_Blake2b_info(self->blake2b_state);
936935
case Blake2s:
937-
return PyLong_FromLong(Hacl_Hash_Blake2s_info(self->blake2s_state).digest_length);
936+
return Hacl_Hash_Blake2s_info(self->blake2s_state);
938937
default:
939938
Py_UNREACHABLE();
940939
}
941940
}
942941

943942

943+
static PyObject *
944+
py_blake2b_get_digest_size(PyObject *op, void *Py_UNUSED(closure))
945+
{
946+
Blake2Object *self = _Blake2Object_CAST(op);
947+
Hacl_Hash_Blake2b_index info = hacl_get_blake2_info(self);
948+
return PyLong_FromLong(info.digest_length);
949+
}
950+
951+
944952
static PyGetSetDef py_blake2b_getsetters[] = {
945953
{"name", py_blake2b_get_name, NULL, NULL, NULL},
946954
{"block_size", py_blake2b_get_block_size, NULL, NULL, NULL},

0 commit comments

Comments
 (0)