Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-99108: Add HACL* Blake2 implementation to hashlib #119316

Merged
merged 64 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
81b42f2
Refresh HACL*; update modules accordingly; fix namespacing
msprotz Mar 25, 2024
9514fb4
make regen-sbom
msprotz Mar 25, 2024
b6b8ea9
wip
msprotz Apr 19, 2024
94bb7aa
Initial prototype of hashlib running atop HACL*'s blake2
msprotz Apr 19, 2024
e8a3060
All hashlib tests pass
msprotz Apr 19, 2024
3896560
Merge remote-tracking branch 'upstream/main' into hacl_blake2
msprotz Jun 24, 2024
d9e5568
Import more files, now to figure out the build system...
msprotz Jun 25, 2024
0d7a2ce
No need to repeat those flags in configure -- they are set in Setup.s…
msprotz Jul 18, 2024
b00af13
Try some AC stuff
msprotz Jul 18, 2024
cd3782a
Merge remote-tracking branch 'upstream/main' into hacl_blake2
msprotz Jul 18, 2024
36f7193
Every single AX_CHECK_COMPILE_FLAG returns false because PY_BUILTIN_H…
msprotz Jul 18, 2024
102dbbf
And another pyconfig.h flag for the second variant -- doing this prop…
msprotz Jul 18, 2024
a61aa04
Getting there with the build
msprotz Jul 18, 2024
11d7c76
Multiplex everything
msprotz Jul 18, 2024
9e0df3c
Defeat unused variable warning
msprotz Jul 18, 2024
d959d6d
We seem to be down to a linking problem
msprotz Jul 18, 2024
8958943
Making progress on autoconf / make
msprotz Jul 19, 2024
538401e
Refresh HACL*
msprotz Jul 19, 2024
cfc7053
Fix a few more typos, build now seems ok
msprotz Jul 19, 2024
d564d3a
Eliminate trailing whitespace when importing HACL*
msprotz Jul 19, 2024
505e8c1
No GNU-isms (hopefully)
msprotz Jul 19, 2024
cc70e6a
Fix some typos
msprotz Jul 19, 2024
4b9e84e
Update the namespacing mechanism, and write down in a comment how to …
msprotz Jul 19, 2024
314f962
NEWS
msprotz Jul 19, 2024
def45e4
Update SBOM
msprotz Jul 19, 2024
97ddafd
Remove GNU-isms
msprotz Jul 22, 2024
2abfcc1
Remove libb2 from SBOM (thanks @sethmlarson)
msprotz Jul 22, 2024
a49343b
Merge branch 'hacl_blake2' of pro.github.com:msprotz/cpython into hac…
msprotz Jul 22, 2024
49cdab5
Regenerate SBOM
msprotz Jul 22, 2024
eb4c3bd
Merge branch 'main' into hacl_blake2
msprotz Jul 22, 2024
cc91e72
Refresh HACL* again, for whitespace
msprotz Jul 22, 2024
873c446
Fix Windows build
msprotz Jul 23, 2024
e3112cc
Merge branch 'hacl_blake2' of pro.github.com:msprotz/cpython into hac…
msprotz Jul 23, 2024
cf70288
Update SBOM
msprotz Jul 23, 2024
50325c2
Deal with ARM64
msprotz Jul 23, 2024
48c4bd0
Match statements in opcode need more recent Python
msprotz Jul 23, 2024
59bcdb9
Fix Windows build
msprotz Jul 23, 2024
22ee262
make regen-sbom
msprotz Jul 23, 2024
550ca99
Try to fix C analysis
msprotz Jul 23, 2024
278bc6c
Tweak Windows build
msprotz Jul 23, 2024
578494a
Build tweaks
msprotz Jul 23, 2024
24ed962
Bring blake2 in line with other hash modules for Py_MOD_GIL_NOT_USED
msprotz Jul 23, 2024
e54bc8e
Move CPU flags detection to per-module state
msprotz Jul 24, 2024
abaf42b
Update Modules/blake2module.c
msprotz Jul 24, 2024
7495a88
Update Modules/blake2module.c
msprotz Jul 24, 2024
fce0cc2
Update Modules/blake2module.c
msprotz Jul 24, 2024
5610b25
Update Modules/blake2module.c
msprotz Jul 24, 2024
38233db
Address various review comments
msprotz Jul 24, 2024
e0e8636
Merge branch 'main' into hacl_blake2
msprotz Jul 24, 2024
b8b943c
Add test_blake2_update_over_4gb.
gpshead Aug 1, 2024
503fb34
Update Modules/blake2module.c
msprotz Aug 1, 2024
0b6dba1
Update Modules/blake2module.c
msprotz Aug 1, 2024
2eccf53
Update Modules/blake2module.c
msprotz Aug 1, 2024
04e9b45
Update Modules/blake2module.c
msprotz Aug 1, 2024
a616575
Add missing includes
msprotz Aug 1, 2024
af0d73b
Every single AX_CHECK_COMPILE_FLAG returns false because PY_BUILTIN_H…
msprotz Jul 18, 2024
f3f95a2
Merge branch 'main' into hacl_blake2
gpshead Aug 5, 2024
f9089fd
Fix configure.ac
msprotz Aug 5, 2024
15db7c1
Merge remote-tracking branch 'origin/double_define' into hacl_blake2
msprotz Aug 5, 2024
bb1cf00
Merge branch 'main' into hacl_blake2
msprotz Aug 6, 2024
07853a5
Merge branch 'main' into hacl_blake2
msprotz Aug 7, 2024
b09d92f
Keep the runtime CPU flags and static compilation flags in check
msprotz Aug 10, 2024
53dfa81
Merge branch 'main' into hacl_blake2
gpshead Aug 13, 2024
40374ac
Merge branch 'main' into hacl_blake2
gpshead Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
We seem to be down to a linking problem
  • Loading branch information
msprotz committed Jul 18, 2024
commit d959d6d8b714f433c99c23bf9148a530d41312e2
24 changes: 18 additions & 6 deletions Modules/blake2module.c
picnixz marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,19 @@ static inline bool has_simd256(void) {
return avx && avx2;
}

// Small mismatch between the variable names Python defines as part of configure
// at the ones HACL* expects to be set in order to enable those headers.
#define HACL_CAN_COMPILE_VEC128 HACL_CAN_COMPILE_SIMD128
#define HACL_CAN_COMPILE_VEC256 HACL_CAN_COMPILE_SIMD256

#include "_hacl/Hacl_Hash_Blake2b.h"
#include "_hacl/Hacl_Hash_Blake2s.h"
#if HACL_CAN_COMPILE_SIMD256
#include "_hacl/Hacl_Hash_Blake2b_Simd256.h"
#endif
#if HACL_CAN_COMPILE_SIMD128
#include "_hacl/Hacl_Hash_Blake2s_Simd128.h"
#endif

// MODULE TYPE SLOTS

Expand Down Expand Up @@ -292,22 +303,23 @@ static inline bool is_blake2s(blake2_impl impl) {
}

static inline blake2_impl type_to_impl(PyTypeObject *type) {
if (!strcmp(type->tp_name, blake2b_type_spec.name))
if (!strcmp(type->tp_name, blake2b_type_spec.name)) {
#ifdef HACL_CAN_COMPILE_SIMD256
if (has_simd256())
return Blake2b_256;
else
#endif
return Blake2b;
else if (!strcmp(type->tp_name, blake2s_type_spec.name))
} else if (!strcmp(type->tp_name, blake2s_type_spec.name)) {
#ifdef HACL_CAN_COMPILE_SIMD128
if (has_simd128())
return Blake2s_128;
else
#endif
return Blake2s;
else
Py_UNREACHABLE();
} else {
Py_UNREACHABLE();
}
}

typedef struct {
Expand All @@ -319,7 +331,7 @@ typedef struct {
Hacl_Hash_Blake2s_Simd128_state_t *blake2s_128_state;
#endif
#ifdef HACL_CAN_COMPILE_SIMD256
Hacl_Hash_Blake2b_SImd256_state_t *blake2b_256_state;
Hacl_Hash_Blake2b_Simd256_state_t *blake2b_256_state;
#endif
};
blake2_impl impl;
Expand Down Expand Up @@ -652,7 +664,7 @@ _blake2_blake2b_copy_impl(Blake2Object *self)
break;
#endif
#if HACL_CAN_COMPILE_SIMD128
case Blake2s:
case Blake2s_128:
cpy->blake2s_128_state = Hacl_Hash_Blake2s_Simd128_copy(self->blake2s_128_state);
break;
#endif
Expand Down
4 changes: 2 additions & 2 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7700,12 +7700,12 @@ PY_STDLIB_MOD([_blake2], [test "$with_builtin_blake2" = yes])

AX_CHECK_COMPILE_FLAG([-mavx],[
LIBHACL_SIMD128_FLAGS="-mavx"
AC_DEFINE([LIBHACL_CAN_COMPILE_SIMD128], [1], [HACL* library can compile SIMD128 implementations])
AC_DEFINE([HACL_CAN_COMPILE_SIMD128], [1], [HACL* library can compile SIMD128 implementations])
], [], [-Werror])

AX_CHECK_COMPILE_FLAG([-mavx2],[
LIBHACL_SIMD256_FLAGS="-mavx2"
AC_DEFINE([LIBHACL_CAN_COMPILE_SIMD256], [1], [HACL* library can compile SIMD256 implementations])
AC_DEFINE([HACL_CAN_COMPILE_SIMD256], [1], [HACL* library can compile SIMD256 implementations])
], [], [-Werror])

PY_STDLIB_MOD([_ctypes],
Expand Down
4 changes: 2 additions & 2 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1605,10 +1605,10 @@
#undef HAVE___UINT128_T

/* HACL* library can compile SIMD128 implementations */
#undef LIBHACL_CAN_COMPILE_SIMD128
#undef HACL_CAN_COMPILE_SIMD128

/* HACL* library can compile SIMD256 implementations */
#undef LIBHACL_CAN_COMPILE_SIMD256
#undef HACL_CAN_COMPILE_SIMD256

/* Define to 1 if `major', `minor', and `makedev' are declared in <mkdev.h>.
*/
Expand Down
Loading