python / python/cpython

HACL* HMAC does not properly use vectorized BLAKE-2

Ouverte
#138,114 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

build extension-modules type-bug
Langage dominant
Python
Étoiles
77.2k
Forks
35.9k
Métriques de merge des PR
Métriques de PR en attente

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par lire configure et l’intégration HACL* HMAC autour de Hacl_HMAC.h, Hacl_Streaming_HMAC.h, Hacl_Streaming_Types.h et du fichier .c HACL* compilé séparément. Suivez la façon dont HACL_CAN_COMPILE_VEC128 et HACL_CAN_COMPILE_VEC256 sont définis ou non définis, puis vérifiez que HMAC-BLAKE-2 utilise l’implémentation vectorisée prise en charge sur les hôtes compatibles sans perturber les autres builds.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
c
Domaine
build-system, cryptography
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.