python / python/cpython

HACL* HMAC does not properly use vectorized BLAKE-2

Open
#138,114 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

build extension-modules type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

First of all, it doesn't really make sense to support HMAC-BLAKE-2 because BLAKE-2 is already a keyed hash function so it already has the properties expected by HMAC. Since HACL* provides it (I don't remember if I actually asked them to, so if I did, it's my fault), I decided to expose it anyway.

HACL* provides SIMD-accelerated implementation for BLAKE-2 which is exposed if the HACL_CAN_COMPILE_VEC128 and HACL_CAN_COMPILE_VEC256 macros are defined. CPython, however, needs to do a bit more work to be able to know whether we can define those macros or not. The work is achieved in two steps:

  • In configure, depending on the host capabilities, the macros are defined.
  • When compiling, depending on the host capabilities once again, the macros are undefined.

The generic headers are afterwards included, e.g.:

#define HACL_CAN_COMPILE_VEC128 _Py_HACL_CAN_COMPILE_VEC128
#define HACL_CAN_COMPILE_VEC256 _Py_HACL_CAN_COMPILE_VEC256

#include "_hacl/Hacl_HMAC.h"
#include "_hacl/Hacl_Streaming_HMAC.h"  // Hacl_Agile_Hash_* identifiers
#include "_hacl/Hacl_Streaming_Types.h" // Hacl_Streaming_Types_error_code

Now, there is a slight issue. The conditional code is actually inside the .c file and not the .h. However, that .c file is an HACL* file that is compiled separately and doesn't have any defines. It also unconditionally includes Hacl_Hash_Blake2s_Simd128.h and Hacl_Hash_Blake2s_Simd256.h files. So I'm not entirely sure about what to do :(

Am I incorrectly using the files @msprotz?

CPython versions tested on:

CPython main branch, 3.14, 3.15

Operating systems tested on:

No response

Linked PRs
  • gh-146118

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading configure and the HACL* HMAC integration around Hacl_HMAC.h, Hacl_Streaming_HMAC.h, Hacl_Streaming_Types.h, and the separately compiled HACL* .c file. Trace how HACL_CAN_COMPILE_VEC128 and HACL_CAN_COMPILE_VEC256 are defined or undefined, then verify that HMAC-BLAKE-2 uses the supported vectorized implementation on capable hosts without breaking other builds.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
build-system, cryptography
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.