diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index 7995da012858245..d31339d13e76a2b 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -1299,6 +1299,14 @@ Build changes (Contributed by Stan Ulbrych, Florian Mayer and AnnaAr321 in :gh:`156049`.) +* Remove SIMD support for the HACL\* implementation of BLAKE-2 used by + :mod:`hashlib` and :mod:`hmac`. The vectorized implementations were only + enabled on some x86-64 platforms and caused build failures on many others. + The :program:`configure` script no longer checks for the compiler flags + needed to build them. + + (Contributed by Bénédikt Tran in :gh:`160333`.) + C API changes ============= diff --git a/Makefile.pre.in b/Makefile.pre.in index 3d971ddc8cd1326..562d9d53a99cf0c 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -238,8 +238,6 @@ LIBEXPAT_A= Modules/expat/libexpat.a # HACL* build configuration LIBHACL_CFLAGS=@LIBHACL_CFLAGS@ LIBHACL_LDFLAGS=@LIBHACL_LDFLAGS@ -LIBHACL_BLAKE2_SIMD128_CFLAGS=@LIBHACL_SIMD128_FLAGS@ -DHACL_CAN_COMPILE_VEC128 -LIBHACL_BLAKE2_SIMD256_CFLAGS=@LIBHACL_SIMD256_FLAGS@ -DHACL_CAN_COMPILE_VEC256 # Module state, compiler flags and linker flags # Empty CFLAGS and LDFLAGS are omitted. @@ -673,14 +671,10 @@ LIBHACL_SHA3_OBJS= \ LIBHACL_SHA3_LIB_STATIC=Modules/_hacl/libHacl_Hash_SHA3.a LIBHACL_SHA3_LIB_SHARED=$(LIBHACL_SHA3_OBJS) -LIBHACL_BLAKE2_SIMD128_OBJS=@LIBHACL_BLAKE2_SIMD128_OBJS@ -LIBHACL_BLAKE2_SIMD256_OBJS=@LIBHACL_BLAKE2_SIMD256_OBJS@ LIBHACL_BLAKE2_OBJS= \ Modules/_hacl/Hacl_Hash_Blake2s.o \ Modules/_hacl/Hacl_Hash_Blake2b.o \ - Modules/_hacl/Lib_Memzero0.o \ - $(LIBHACL_BLAKE2_SIMD128_OBJS) \ - $(LIBHACL_BLAKE2_SIMD256_OBJS) + Modules/_hacl/Lib_Memzero0.o LIBHACL_BLAKE2_LIB_STATIC=Modules/_hacl/libHacl_Hash_BLAKE2.a LIBHACL_BLAKE2_LIB_SHARED=$(LIBHACL_BLAKE2_OBJS) @@ -1530,14 +1524,6 @@ Modules/_hacl/Hacl_Hash_Blake2s.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s.c $ $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s.c Modules/_hacl/Hacl_Hash_Blake2b.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b.c $(LIBHACL_BLAKE2_HEADERS) $(CC) -c $(LIBHACL_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b.c -Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c $(LIBHACL_BLAKE2_HEADERS) - $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_BLAKE2_SIMD128_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c -Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.c $(LIBHACL_BLAKE2_HEADERS) - $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_BLAKE2_SIMD128_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.c -Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c $(LIBHACL_BLAKE2_HEADERS) - $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_BLAKE2_SIMD256_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c -Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o: $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c $(LIBHACL_BLAKE2_HEADERS) - $(CC) -c $(LIBHACL_CFLAGS) $(LIBHACL_BLAKE2_SIMD256_CFLAGS) -o $@ $(srcdir)/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c $(LIBHACL_BLAKE2_LIB_STATIC): $(LIBHACL_BLAKE2_OBJS) -rm -f $@ $(AR) $(ARFLAGS) $@ $(LIBHACL_BLAKE2_OBJS) diff --git a/Misc/NEWS.d/next/Build/2026-10-22-13-09-58.gh-issue-160333.QqQUOt.rst b/Misc/NEWS.d/next/Build/2026-10-22-13-09-58.gh-issue-160333.QqQUOt.rst new file mode 100644 index 000000000000000..e3ea5b9658561c6 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-10-22-13-09-58.gh-issue-160333.QqQUOt.rst @@ -0,0 +1,4 @@ +Remove SIMD support for the HACL\* implementation of BLAKE-2 used by +:mod:`hashlib` and :mod:`hmac`. The vectorized implementations were only +enabled on some x86-64 platforms and caused build failures on many others. +Patch by Bénédikt Tran. diff --git a/Misc/sbom.spdx.json b/Misc/sbom.spdx.json index 0923602b2f1d871..3a65c9d57825b0b 100644 --- a/Misc/sbom.spdx.json +++ b/Misc/sbom.spdx.json @@ -407,20 +407,6 @@ ], "fileName": "Modules/_hacl/Hacl_Hash_Blake2b.h" }, - { - "SPDXID": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-Blake2b-Simd256.c", - "checksums": [ - { - "algorithm": "SHA1", - "checksumValue": "1bb072f2be9e5d194274fdcc87825cb094e4b32e" - }, - { - "algorithm": "SHA256", - "checksumValue": "9eb22953ce60dde9dc970fec9dfce9d94235f4b7ccd8f0151cad4707dc835d1d" - } - ], - "fileName": "Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c" - }, { "SPDXID": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-Blake2b-Simd256.h", "checksums": [ @@ -435,20 +421,6 @@ ], "fileName": "Modules/_hacl/Hacl_Hash_Blake2b_Simd256.h" }, - { - "SPDXID": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-Blake2b-Simd256-universal2.c", - "checksums": [ - { - "algorithm": "SHA1", - "checksumValue": "5afc433179d71abd6649596797a7e8953e89172d" - }, - { - "algorithm": "SHA256", - "checksumValue": "db42da82d18641d68d3670e6201e0cbb43415daaa84f29770b8f0ebf33562975" - } - ], - "fileName": "Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c" - }, { "SPDXID": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-Blake2s.c", "checksums": [ @@ -477,20 +449,6 @@ ], "fileName": "Modules/_hacl/Hacl_Hash_Blake2s.h" }, - { - "SPDXID": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-Blake2s-Simd128.c", - "checksums": [ - { - "algorithm": "SHA1", - "checksumValue": "4056bb6e3ed184400d1610bdfd4260b3fd05ccbb" - }, - { - "algorithm": "SHA256", - "checksumValue": "c93746df2f219cbb1634ee6fb0ab1c4cbd381d1f36c637114c68346c9935326d" - } - ], - "fileName": "Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c" - }, { "SPDXID": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-Blake2s-Simd128.h", "checksums": [ @@ -505,20 +463,6 @@ ], "fileName": "Modules/_hacl/Hacl_Hash_Blake2s_Simd128.h" }, - { - "SPDXID": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-Blake2s-Simd128-universal2.c", - "checksums": [ - { - "algorithm": "SHA1", - "checksumValue": "d70c6dbcb91d56bbd80f7bf860e508a748042d0d" - }, - { - "algorithm": "SHA256", - "checksumValue": "5b132ab850a5e0fe6f27e08a955f8989ea3aae8e5b3115f0195039034ece8c04" - } - ], - "fileName": "Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.c" - }, { "SPDXID": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-MD5.c", "checksums": [ @@ -1280,21 +1224,11 @@ "relationshipType": "CONTAINS", "spdxElementId": "SPDXRef-PACKAGE-hacl-star" }, - { - "relatedSpdxElement": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-Blake2b-Simd256.c", - "relationshipType": "CONTAINS", - "spdxElementId": "SPDXRef-PACKAGE-hacl-star" - }, { "relatedSpdxElement": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-Blake2b-Simd256.h", "relationshipType": "CONTAINS", "spdxElementId": "SPDXRef-PACKAGE-hacl-star" }, - { - "relatedSpdxElement": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-Blake2b-Simd256-universal2.c", - "relationshipType": "CONTAINS", - "spdxElementId": "SPDXRef-PACKAGE-hacl-star" - }, { "relatedSpdxElement": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-Blake2s.c", "relationshipType": "CONTAINS", @@ -1305,21 +1239,11 @@ "relationshipType": "CONTAINS", "spdxElementId": "SPDXRef-PACKAGE-hacl-star" }, - { - "relatedSpdxElement": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-Blake2s-Simd128.c", - "relationshipType": "CONTAINS", - "spdxElementId": "SPDXRef-PACKAGE-hacl-star" - }, { "relatedSpdxElement": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-Blake2s-Simd128.h", "relationshipType": "CONTAINS", "spdxElementId": "SPDXRef-PACKAGE-hacl-star" }, - { - "relatedSpdxElement": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-Blake2s-Simd128-universal2.c", - "relationshipType": "CONTAINS", - "spdxElementId": "SPDXRef-PACKAGE-hacl-star" - }, { "relatedSpdxElement": "SPDXRef-FILE-Modules-hacl-Hacl-Hash-MD5.c", "relationshipType": "CONTAINS", diff --git a/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c b/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c deleted file mode 100644 index f955f1c6115b1e6..000000000000000 --- a/Modules/_hacl/Hacl_Hash_Blake2b_Simd256.c +++ /dev/null @@ -1,1599 +0,0 @@ -/* MIT License - * - * Copyright (c) 2016-2022 INRIA, CMU and Microsoft Corporation - * Copyright (c) 2022-2023 HACL* Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - - -#include "internal/Hacl_Hash_Blake2b_Simd256.h" - -#include "Hacl_Streaming_Types.h" - -#include "Hacl_Hash_Blake2b.h" -#include "internal/Hacl_Streaming_Types.h" -#include "internal/Hacl_Impl_Blake2_Constants.h" -#include "internal/Hacl_Hash_Blake2b.h" -#include "lib_memzero0.h" - -static inline void -update_block( - Lib_IntVector_Intrinsics_vec256 *wv, - Lib_IntVector_Intrinsics_vec256 *hash, - bool flag, - bool last_node, - FStar_UInt128_uint128 totlen, - uint8_t *d -) -{ - uint64_t m_w[16U] = { 0U }; - KRML_MAYBE_FOR16(i, - 0U, - 16U, - 1U, - uint64_t *os = m_w; - uint8_t *bj = d + i * 8U; - uint64_t u = load64_le(bj); - uint64_t r = u; - uint64_t x = r; - os[i] = x;); - Lib_IntVector_Intrinsics_vec256 mask = Lib_IntVector_Intrinsics_vec256_zero; - uint64_t wv_14; - if (flag) - { - wv_14 = 0xFFFFFFFFFFFFFFFFULL; - } - else - { - wv_14 = 0ULL; - } - uint64_t wv_15; - if (last_node) - { - wv_15 = 0xFFFFFFFFFFFFFFFFULL; - } - else - { - wv_15 = 0ULL; - } - mask = - Lib_IntVector_Intrinsics_vec256_load64s(FStar_UInt128_uint128_to_uint64(totlen), - FStar_UInt128_uint128_to_uint64(FStar_UInt128_shift_right(totlen, 64U)), - wv_14, - wv_15); - memcpy(wv, hash, 4U * sizeof (Lib_IntVector_Intrinsics_vec256)); - Lib_IntVector_Intrinsics_vec256 *wv3 = wv + 3U; - wv3[0U] = Lib_IntVector_Intrinsics_vec256_xor(wv3[0U], mask); - KRML_MAYBE_FOR12(i, - 0U, - 12U, - 1U, - uint32_t start_idx = i % 10U * 16U; - KRML_PRE_ALIGN(32) Lib_IntVector_Intrinsics_vec256 m_st[4U] KRML_POST_ALIGN(32) = { 0U }; - Lib_IntVector_Intrinsics_vec256 *r0 = m_st; - Lib_IntVector_Intrinsics_vec256 *r1 = m_st + 1U; - Lib_IntVector_Intrinsics_vec256 *r20 = m_st + 2U; - Lib_IntVector_Intrinsics_vec256 *r30 = m_st + 3U; - uint32_t s0 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 0U]; - uint32_t s1 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 1U]; - uint32_t s2 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 2U]; - uint32_t s3 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 3U]; - uint32_t s4 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 4U]; - uint32_t s5 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 5U]; - uint32_t s6 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 6U]; - uint32_t s7 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 7U]; - uint32_t s8 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 8U]; - uint32_t s9 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 9U]; - uint32_t s10 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 10U]; - uint32_t s11 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 11U]; - uint32_t s12 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 12U]; - uint32_t s13 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 13U]; - uint32_t s14 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 14U]; - uint32_t s15 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 15U]; - r0[0U] = Lib_IntVector_Intrinsics_vec256_load64s(m_w[s0], m_w[s2], m_w[s4], m_w[s6]); - r1[0U] = Lib_IntVector_Intrinsics_vec256_load64s(m_w[s1], m_w[s3], m_w[s5], m_w[s7]); - r20[0U] = Lib_IntVector_Intrinsics_vec256_load64s(m_w[s8], m_w[s10], m_w[s12], m_w[s14]); - r30[0U] = Lib_IntVector_Intrinsics_vec256_load64s(m_w[s9], m_w[s11], m_w[s13], m_w[s15]); - Lib_IntVector_Intrinsics_vec256 *x = m_st; - Lib_IntVector_Intrinsics_vec256 *y = m_st + 1U; - Lib_IntVector_Intrinsics_vec256 *z = m_st + 2U; - Lib_IntVector_Intrinsics_vec256 *w = m_st + 3U; - uint32_t a = 0U; - uint32_t b0 = 1U; - uint32_t c0 = 2U; - uint32_t d10 = 3U; - Lib_IntVector_Intrinsics_vec256 *wv_a0 = wv + a * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b0 = wv + b0 * 1U; - wv_a0[0U] = Lib_IntVector_Intrinsics_vec256_add64(wv_a0[0U], wv_b0[0U]); - wv_a0[0U] = Lib_IntVector_Intrinsics_vec256_add64(wv_a0[0U], x[0U]); - Lib_IntVector_Intrinsics_vec256 *wv_a1 = wv + d10 * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b1 = wv + a * 1U; - wv_a1[0U] = Lib_IntVector_Intrinsics_vec256_xor(wv_a1[0U], wv_b1[0U]); - wv_a1[0U] = Lib_IntVector_Intrinsics_vec256_rotate_right64(wv_a1[0U], 32U); - Lib_IntVector_Intrinsics_vec256 *wv_a2 = wv + c0 * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b2 = wv + d10 * 1U; - wv_a2[0U] = Lib_IntVector_Intrinsics_vec256_add64(wv_a2[0U], wv_b2[0U]); - Lib_IntVector_Intrinsics_vec256 *wv_a3 = wv + b0 * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b3 = wv + c0 * 1U; - wv_a3[0U] = Lib_IntVector_Intrinsics_vec256_xor(wv_a3[0U], wv_b3[0U]); - wv_a3[0U] = Lib_IntVector_Intrinsics_vec256_rotate_right64(wv_a3[0U], 24U); - Lib_IntVector_Intrinsics_vec256 *wv_a4 = wv + a * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b4 = wv + b0 * 1U; - wv_a4[0U] = Lib_IntVector_Intrinsics_vec256_add64(wv_a4[0U], wv_b4[0U]); - wv_a4[0U] = Lib_IntVector_Intrinsics_vec256_add64(wv_a4[0U], y[0U]); - Lib_IntVector_Intrinsics_vec256 *wv_a5 = wv + d10 * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b5 = wv + a * 1U; - wv_a5[0U] = Lib_IntVector_Intrinsics_vec256_xor(wv_a5[0U], wv_b5[0U]); - wv_a5[0U] = Lib_IntVector_Intrinsics_vec256_rotate_right64(wv_a5[0U], 16U); - Lib_IntVector_Intrinsics_vec256 *wv_a6 = wv + c0 * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b6 = wv + d10 * 1U; - wv_a6[0U] = Lib_IntVector_Intrinsics_vec256_add64(wv_a6[0U], wv_b6[0U]); - Lib_IntVector_Intrinsics_vec256 *wv_a7 = wv + b0 * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b7 = wv + c0 * 1U; - wv_a7[0U] = Lib_IntVector_Intrinsics_vec256_xor(wv_a7[0U], wv_b7[0U]); - wv_a7[0U] = Lib_IntVector_Intrinsics_vec256_rotate_right64(wv_a7[0U], 63U); - Lib_IntVector_Intrinsics_vec256 *r10 = wv + 1U; - Lib_IntVector_Intrinsics_vec256 *r21 = wv + 2U; - Lib_IntVector_Intrinsics_vec256 *r31 = wv + 3U; - Lib_IntVector_Intrinsics_vec256 v00 = r10[0U]; - Lib_IntVector_Intrinsics_vec256 - v1 = Lib_IntVector_Intrinsics_vec256_rotate_right_lanes64(v00, 1U); - r10[0U] = v1; - Lib_IntVector_Intrinsics_vec256 v01 = r21[0U]; - Lib_IntVector_Intrinsics_vec256 - v10 = Lib_IntVector_Intrinsics_vec256_rotate_right_lanes64(v01, 2U); - r21[0U] = v10; - Lib_IntVector_Intrinsics_vec256 v02 = r31[0U]; - Lib_IntVector_Intrinsics_vec256 - v11 = Lib_IntVector_Intrinsics_vec256_rotate_right_lanes64(v02, 3U); - r31[0U] = v11; - uint32_t a0 = 0U; - uint32_t b = 1U; - uint32_t c = 2U; - uint32_t d1 = 3U; - Lib_IntVector_Intrinsics_vec256 *wv_a = wv + a0 * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b8 = wv + b * 1U; - wv_a[0U] = Lib_IntVector_Intrinsics_vec256_add64(wv_a[0U], wv_b8[0U]); - wv_a[0U] = Lib_IntVector_Intrinsics_vec256_add64(wv_a[0U], z[0U]); - Lib_IntVector_Intrinsics_vec256 *wv_a8 = wv + d1 * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b9 = wv + a0 * 1U; - wv_a8[0U] = Lib_IntVector_Intrinsics_vec256_xor(wv_a8[0U], wv_b9[0U]); - wv_a8[0U] = Lib_IntVector_Intrinsics_vec256_rotate_right64(wv_a8[0U], 32U); - Lib_IntVector_Intrinsics_vec256 *wv_a9 = wv + c * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b10 = wv + d1 * 1U; - wv_a9[0U] = Lib_IntVector_Intrinsics_vec256_add64(wv_a9[0U], wv_b10[0U]); - Lib_IntVector_Intrinsics_vec256 *wv_a10 = wv + b * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b11 = wv + c * 1U; - wv_a10[0U] = Lib_IntVector_Intrinsics_vec256_xor(wv_a10[0U], wv_b11[0U]); - wv_a10[0U] = Lib_IntVector_Intrinsics_vec256_rotate_right64(wv_a10[0U], 24U); - Lib_IntVector_Intrinsics_vec256 *wv_a11 = wv + a0 * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b12 = wv + b * 1U; - wv_a11[0U] = Lib_IntVector_Intrinsics_vec256_add64(wv_a11[0U], wv_b12[0U]); - wv_a11[0U] = Lib_IntVector_Intrinsics_vec256_add64(wv_a11[0U], w[0U]); - Lib_IntVector_Intrinsics_vec256 *wv_a12 = wv + d1 * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b13 = wv + a0 * 1U; - wv_a12[0U] = Lib_IntVector_Intrinsics_vec256_xor(wv_a12[0U], wv_b13[0U]); - wv_a12[0U] = Lib_IntVector_Intrinsics_vec256_rotate_right64(wv_a12[0U], 16U); - Lib_IntVector_Intrinsics_vec256 *wv_a13 = wv + c * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b14 = wv + d1 * 1U; - wv_a13[0U] = Lib_IntVector_Intrinsics_vec256_add64(wv_a13[0U], wv_b14[0U]); - Lib_IntVector_Intrinsics_vec256 *wv_a14 = wv + b * 1U; - Lib_IntVector_Intrinsics_vec256 *wv_b = wv + c * 1U; - wv_a14[0U] = Lib_IntVector_Intrinsics_vec256_xor(wv_a14[0U], wv_b[0U]); - wv_a14[0U] = Lib_IntVector_Intrinsics_vec256_rotate_right64(wv_a14[0U], 63U); - Lib_IntVector_Intrinsics_vec256 *r11 = wv + 1U; - Lib_IntVector_Intrinsics_vec256 *r2 = wv + 2U; - Lib_IntVector_Intrinsics_vec256 *r3 = wv + 3U; - Lib_IntVector_Intrinsics_vec256 v0 = r11[0U]; - Lib_IntVector_Intrinsics_vec256 - v12 = Lib_IntVector_Intrinsics_vec256_rotate_right_lanes64(v0, 3U); - r11[0U] = v12; - Lib_IntVector_Intrinsics_vec256 v03 = r2[0U]; - Lib_IntVector_Intrinsics_vec256 - v13 = Lib_IntVector_Intrinsics_vec256_rotate_right_lanes64(v03, 2U); - r2[0U] = v13; - Lib_IntVector_Intrinsics_vec256 v04 = r3[0U]; - Lib_IntVector_Intrinsics_vec256 - v14 = Lib_IntVector_Intrinsics_vec256_rotate_right_lanes64(v04, 1U); - r3[0U] = v14;); - Lib_IntVector_Intrinsics_vec256 *s0 = hash; - Lib_IntVector_Intrinsics_vec256 *s1 = hash + 1U; - Lib_IntVector_Intrinsics_vec256 *r0 = wv; - Lib_IntVector_Intrinsics_vec256 *r1 = wv + 1U; - Lib_IntVector_Intrinsics_vec256 *r2 = wv + 2U; - Lib_IntVector_Intrinsics_vec256 *r3 = wv + 3U; - s0[0U] = Lib_IntVector_Intrinsics_vec256_xor(s0[0U], r0[0U]); - s0[0U] = Lib_IntVector_Intrinsics_vec256_xor(s0[0U], r2[0U]); - s1[0U] = Lib_IntVector_Intrinsics_vec256_xor(s1[0U], r1[0U]); - s1[0U] = Lib_IntVector_Intrinsics_vec256_xor(s1[0U], r3[0U]); -} - -void -Hacl_Hash_Blake2b_Simd256_init(Lib_IntVector_Intrinsics_vec256 *hash, uint32_t kk, uint32_t nn) -{ - uint8_t salt[16U] = { 0U }; - uint8_t personal[16U] = { 0U }; - Hacl_Hash_Blake2b_blake2_params - p = - { - .digest_length = 64U, .key_length = 0U, .fanout = 1U, .depth = 1U, .leaf_length = 0U, - .node_offset = 0ULL, .node_depth = 0U, .inner_length = 0U, .salt = salt, .personal = personal - }; - uint64_t tmp[8U] = { 0U }; - Lib_IntVector_Intrinsics_vec256 *r0 = hash; - Lib_IntVector_Intrinsics_vec256 *r1 = hash + 1U; - Lib_IntVector_Intrinsics_vec256 *r2 = hash + 2U; - Lib_IntVector_Intrinsics_vec256 *r3 = hash + 3U; - uint64_t iv0 = Hacl_Hash_Blake2b_ivTable_B[0U]; - uint64_t iv1 = Hacl_Hash_Blake2b_ivTable_B[1U]; - uint64_t iv2 = Hacl_Hash_Blake2b_ivTable_B[2U]; - uint64_t iv3 = Hacl_Hash_Blake2b_ivTable_B[3U]; - uint64_t iv4 = Hacl_Hash_Blake2b_ivTable_B[4U]; - uint64_t iv5 = Hacl_Hash_Blake2b_ivTable_B[5U]; - uint64_t iv6 = Hacl_Hash_Blake2b_ivTable_B[6U]; - uint64_t iv7 = Hacl_Hash_Blake2b_ivTable_B[7U]; - r2[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv0, iv1, iv2, iv3); - r3[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv4, iv5, iv6, iv7); - uint8_t kk1 = (uint8_t)kk; - uint8_t nn1 = (uint8_t)nn; - KRML_MAYBE_FOR2(i, - 0U, - 2U, - 1U, - uint64_t *os = tmp + 4U; - uint8_t *bj = p.salt + i * 8U; - uint64_t u = load64_le(bj); - uint64_t r = u; - uint64_t x = r; - os[i] = x;); - KRML_MAYBE_FOR2(i, - 0U, - 2U, - 1U, - uint64_t *os = tmp + 6U; - uint8_t *bj = p.personal + i * 8U; - uint64_t u = load64_le(bj); - uint64_t r = u; - uint64_t x = r; - os[i] = x;); - tmp[0U] = - (uint64_t)nn1 ^ - ((uint64_t)kk1 << 8U ^ - ((uint64_t)p.fanout << 16U ^ ((uint64_t)p.depth << 24U ^ (uint64_t)p.leaf_length << 32U))); - tmp[1U] = p.node_offset; - tmp[2U] = (uint64_t)p.node_depth ^ (uint64_t)p.inner_length << 8U; - tmp[3U] = 0ULL; - uint64_t tmp0 = tmp[0U]; - uint64_t tmp1 = tmp[1U]; - uint64_t tmp2 = tmp[2U]; - uint64_t tmp3 = tmp[3U]; - uint64_t tmp4 = tmp[4U]; - uint64_t tmp5 = tmp[5U]; - uint64_t tmp6 = tmp[6U]; - uint64_t tmp7 = tmp[7U]; - uint64_t iv0_ = iv0 ^ tmp0; - uint64_t iv1_ = iv1 ^ tmp1; - uint64_t iv2_ = iv2 ^ tmp2; - uint64_t iv3_ = iv3 ^ tmp3; - uint64_t iv4_ = iv4 ^ tmp4; - uint64_t iv5_ = iv5 ^ tmp5; - uint64_t iv6_ = iv6 ^ tmp6; - uint64_t iv7_ = iv7 ^ tmp7; - r0[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv0_, iv1_, iv2_, iv3_); - r1[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv4_, iv5_, iv6_, iv7_); -} - -static void -update_key( - Lib_IntVector_Intrinsics_vec256 *wv, - Lib_IntVector_Intrinsics_vec256 *hash, - uint32_t kk, - uint8_t *k, - uint32_t ll -) -{ - FStar_UInt128_uint128 lb = FStar_UInt128_uint64_to_uint128((uint64_t)128U); - uint8_t b[128U] = { 0U }; - memcpy(b, k, kk * sizeof (uint8_t)); - if (ll == 0U) - { - update_block(wv, hash, true, false, lb, b); - } - else - { - update_block(wv, hash, false, false, lb, b); - } - Lib_Memzero0_memzero(b, 128U, uint8_t, void *); -} - -void -Hacl_Hash_Blake2b_Simd256_update_multi( - uint32_t len, - Lib_IntVector_Intrinsics_vec256 *wv, - Lib_IntVector_Intrinsics_vec256 *hash, - FStar_UInt128_uint128 prev, - uint8_t *blocks, - uint32_t nb -) -{ - KRML_MAYBE_UNUSED_VAR(len); - for (uint32_t i = 0U; i < nb; i++) - { - FStar_UInt128_uint128 - totlen = - FStar_UInt128_add_mod(prev, - FStar_UInt128_uint64_to_uint128((uint64_t)((i + 1U) * 128U))); - uint8_t *b = blocks + i * 128U; - update_block(wv, hash, false, false, totlen, b); - } -} - -void -Hacl_Hash_Blake2b_Simd256_update_last( - uint32_t len, - Lib_IntVector_Intrinsics_vec256 *wv, - Lib_IntVector_Intrinsics_vec256 *hash, - bool last_node, - FStar_UInt128_uint128 prev, - uint32_t rem, - uint8_t *d -) -{ - uint8_t b[128U] = { 0U }; - uint8_t *last = d + len - rem; - memcpy(b, last, rem * sizeof (uint8_t)); - FStar_UInt128_uint128 - totlen = FStar_UInt128_add_mod(prev, FStar_UInt128_uint64_to_uint128((uint64_t)len)); - update_block(wv, hash, true, last_node, totlen, b); - Lib_Memzero0_memzero(b, 128U, uint8_t, void *); -} - -static inline void -update_blocks( - uint32_t len, - Lib_IntVector_Intrinsics_vec256 *wv, - Lib_IntVector_Intrinsics_vec256 *hash, - FStar_UInt128_uint128 prev, - uint8_t *blocks -) -{ - uint32_t nb0 = len / 128U; - uint32_t rem0 = len % 128U; - uint32_t nb; - if (rem0 == 0U && nb0 > 0U) - { - nb = nb0 - 1U; - } - else - { - nb = nb0; - } - uint32_t rem; - if (rem0 == 0U && nb0 > 0U) - { - rem = 128U; - } - else - { - rem = rem0; - } - Hacl_Hash_Blake2b_Simd256_update_multi(len, wv, hash, prev, blocks, nb); - Hacl_Hash_Blake2b_Simd256_update_last(len, wv, hash, false, prev, rem, blocks); -} - -static inline void -update( - Lib_IntVector_Intrinsics_vec256 *wv, - Lib_IntVector_Intrinsics_vec256 *hash, - uint32_t kk, - uint8_t *k, - uint32_t ll, - uint8_t *d -) -{ - FStar_UInt128_uint128 lb = FStar_UInt128_uint64_to_uint128((uint64_t)128U); - if (kk > 0U) - { - update_key(wv, hash, kk, k, ll); - if (!(ll == 0U)) - { - update_blocks(ll, wv, hash, lb, d); - return; - } - return; - } - update_blocks(ll, wv, hash, FStar_UInt128_uint64_to_uint128((uint64_t)0U), d); -} - -void -Hacl_Hash_Blake2b_Simd256_finish( - uint32_t nn, - uint8_t *output, - Lib_IntVector_Intrinsics_vec256 *hash -) -{ - uint8_t b[64U] = { 0U }; - uint8_t *first = b; - uint8_t *second = b + 32U; - Lib_IntVector_Intrinsics_vec256 *row0 = hash; - Lib_IntVector_Intrinsics_vec256 *row1 = hash + 1U; - Lib_IntVector_Intrinsics_vec256_store64_le(first, row0[0U]); - Lib_IntVector_Intrinsics_vec256_store64_le(second, row1[0U]); - uint8_t *final = b; - memcpy(output, final, nn * sizeof (uint8_t)); - Lib_Memzero0_memzero(b, 64U, uint8_t, void *); -} - -void -Hacl_Hash_Blake2b_Simd256_load_state256b_from_state32( - Lib_IntVector_Intrinsics_vec256 *st, - uint64_t *st32 -) -{ - Lib_IntVector_Intrinsics_vec256 *r0 = st; - Lib_IntVector_Intrinsics_vec256 *r1 = st + 1U; - Lib_IntVector_Intrinsics_vec256 *r2 = st + 2U; - Lib_IntVector_Intrinsics_vec256 *r3 = st + 3U; - uint64_t *b0 = st32; - uint64_t *b1 = st32 + 4U; - uint64_t *b2 = st32 + 8U; - uint64_t *b3 = st32 + 12U; - r0[0U] = Lib_IntVector_Intrinsics_vec256_load64s(b0[0U], b0[1U], b0[2U], b0[3U]); - r1[0U] = Lib_IntVector_Intrinsics_vec256_load64s(b1[0U], b1[1U], b1[2U], b1[3U]); - r2[0U] = Lib_IntVector_Intrinsics_vec256_load64s(b2[0U], b2[1U], b2[2U], b2[3U]); - r3[0U] = Lib_IntVector_Intrinsics_vec256_load64s(b3[0U], b3[1U], b3[2U], b3[3U]); -} - -void -Hacl_Hash_Blake2b_Simd256_store_state256b_to_state32( - uint64_t *st32, - Lib_IntVector_Intrinsics_vec256 *st -) -{ - Lib_IntVector_Intrinsics_vec256 *r0 = st; - Lib_IntVector_Intrinsics_vec256 *r1 = st + 1U; - Lib_IntVector_Intrinsics_vec256 *r2 = st + 2U; - Lib_IntVector_Intrinsics_vec256 *r3 = st + 3U; - uint64_t *b0 = st32; - uint64_t *b1 = st32 + 4U; - uint64_t *b2 = st32 + 8U; - uint64_t *b3 = st32 + 12U; - uint8_t b8[32U] = { 0U }; - Lib_IntVector_Intrinsics_vec256_store64_le(b8, r0[0U]); - KRML_MAYBE_FOR4(i, - 0U, - 4U, - 1U, - uint64_t *os = b0; - uint8_t *bj = b8 + i * 8U; - uint64_t u = load64_le(bj); - uint64_t r = u; - uint64_t x = r; - os[i] = x;); - uint8_t b80[32U] = { 0U }; - Lib_IntVector_Intrinsics_vec256_store64_le(b80, r1[0U]); - KRML_MAYBE_FOR4(i, - 0U, - 4U, - 1U, - uint64_t *os = b1; - uint8_t *bj = b80 + i * 8U; - uint64_t u = load64_le(bj); - uint64_t r = u; - uint64_t x = r; - os[i] = x;); - uint8_t b81[32U] = { 0U }; - Lib_IntVector_Intrinsics_vec256_store64_le(b81, r2[0U]); - KRML_MAYBE_FOR4(i, - 0U, - 4U, - 1U, - uint64_t *os = b2; - uint8_t *bj = b81 + i * 8U; - uint64_t u = load64_le(bj); - uint64_t r = u; - uint64_t x = r; - os[i] = x;); - uint8_t b82[32U] = { 0U }; - Lib_IntVector_Intrinsics_vec256_store64_le(b82, r3[0U]); - KRML_MAYBE_FOR4(i, - 0U, - 4U, - 1U, - uint64_t *os = b3; - uint8_t *bj = b82 + i * 8U; - uint64_t u = load64_le(bj); - uint64_t r = u; - uint64_t x = r; - os[i] = x;); -} - -Lib_IntVector_Intrinsics_vec256 *Hacl_Hash_Blake2b_Simd256_malloc_internal_state_with_key(void) -{ - Lib_IntVector_Intrinsics_vec256 - *buf = - (Lib_IntVector_Intrinsics_vec256 *)KRML_ALIGNED_MALLOC(32, - sizeof (Lib_IntVector_Intrinsics_vec256) * 4U); - if (buf != NULL) - { - memset(buf, 0U, 4U * sizeof (Lib_IntVector_Intrinsics_vec256)); - } - return buf; -} - -void -Hacl_Hash_Blake2b_Simd256_update_multi_no_inline( - Lib_IntVector_Intrinsics_vec256 *s, - FStar_UInt128_uint128 ev, - uint8_t *blocks, - uint32_t n -) -{ - KRML_PRE_ALIGN(32) Lib_IntVector_Intrinsics_vec256 wv[4U] KRML_POST_ALIGN(32) = { 0U }; - Hacl_Hash_Blake2b_Simd256_update_multi(n * 128U, wv, s, ev, blocks, n); -} - -void -Hacl_Hash_Blake2b_Simd256_update_last_no_inline( - Lib_IntVector_Intrinsics_vec256 *s, - FStar_UInt128_uint128 prev, - uint8_t *input, - uint32_t input_len -) -{ - KRML_PRE_ALIGN(32) Lib_IntVector_Intrinsics_vec256 wv[4U] KRML_POST_ALIGN(32) = { 0U }; - Hacl_Hash_Blake2b_Simd256_update_last(input_len, wv, s, false, prev, input_len, input); -} - -void -Hacl_Hash_Blake2b_Simd256_copy_internal_state( - Lib_IntVector_Intrinsics_vec256 *src, - Lib_IntVector_Intrinsics_vec256 *dst -) -{ - memcpy(dst, src, 4U * sizeof (Lib_IntVector_Intrinsics_vec256)); -} - -typedef struct -option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec256_____Lib_IntVector_Intrinsics_vec256____s -{ - Hacl_Streaming_Types_optional tag; - Hacl_Hash_Blake2b_Simd256_block_state_t v; -} -option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec256_____Lib_IntVector_Intrinsics_vec256___; - -static Hacl_Hash_Blake2b_Simd256_state_t -*malloc_raw(Hacl_Hash_Blake2b_index kk, Hacl_Hash_Blake2b_params_and_key key) -{ - uint8_t *buf = (uint8_t *)KRML_HOST_CALLOC(128U, sizeof (uint8_t)); - if (buf == NULL) - { - return NULL; - } - uint8_t *buf1 = buf; - Lib_IntVector_Intrinsics_vec256 - *wv0 = - (Lib_IntVector_Intrinsics_vec256 *)KRML_ALIGNED_MALLOC(32, - sizeof (Lib_IntVector_Intrinsics_vec256) * 4U); - if (wv0 != NULL) - { - memset(wv0, 0U, 4U * sizeof (Lib_IntVector_Intrinsics_vec256)); - } - option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec256_____Lib_IntVector_Intrinsics_vec256___ - block_state; - if (wv0 == NULL) - { - block_state = - ( - (option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec256_____Lib_IntVector_Intrinsics_vec256___){ - .tag = Hacl_Streaming_Types_None - } - ); - } - else - { - Lib_IntVector_Intrinsics_vec256 - *b = - (Lib_IntVector_Intrinsics_vec256 *)KRML_ALIGNED_MALLOC(32, - sizeof (Lib_IntVector_Intrinsics_vec256) * 4U); - if (b != NULL) - { - memset(b, 0U, 4U * sizeof (Lib_IntVector_Intrinsics_vec256)); - } - if (b == NULL) - { - KRML_ALIGNED_FREE(wv0); - block_state = - ( - (option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec256_____Lib_IntVector_Intrinsics_vec256___){ - .tag = Hacl_Streaming_Types_None - } - ); - } - else - { - block_state = - ( - (option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec256_____Lib_IntVector_Intrinsics_vec256___){ - .tag = Hacl_Streaming_Types_Some, - .v = { - .fst = kk.key_length, - .snd = kk.digest_length, - .thd = kk.last_node, - .f3 = { .fst = wv0, .snd = b } - } - } - ); - } - } - if (block_state.tag == Hacl_Streaming_Types_None) - { - KRML_HOST_FREE(buf1); - return NULL; - } - if (block_state.tag == Hacl_Streaming_Types_Some) - { - Hacl_Hash_Blake2b_Simd256_block_state_t block_state1 = block_state.v; - Hacl_Streaming_Types_optional k_ = Hacl_Streaming_Types_Some; - switch (k_) - { - case Hacl_Streaming_Types_None: - { - return NULL; - } - case Hacl_Streaming_Types_Some: - { - uint8_t kk10 = kk.key_length; - uint32_t ite; - if (kk10 != 0U) - { - ite = 128U; - } - else - { - ite = 0U; - } - Hacl_Hash_Blake2b_Simd256_state_t - s = { .block_state = block_state1, .buf = buf1, .total_len = (uint64_t)ite }; - Hacl_Hash_Blake2b_Simd256_state_t - *p = - (Hacl_Hash_Blake2b_Simd256_state_t *)KRML_HOST_MALLOC(sizeof ( - Hacl_Hash_Blake2b_Simd256_state_t - )); - if (p != NULL) - { - p[0U] = s; - } - if (p == NULL) - { - Lib_IntVector_Intrinsics_vec256 *b = block_state1.f3.snd; - Lib_IntVector_Intrinsics_vec256 *wv = block_state1.f3.fst; - KRML_ALIGNED_FREE(wv); - KRML_ALIGNED_FREE(b); - KRML_HOST_FREE(buf1); - return NULL; - } - Hacl_Hash_Blake2b_blake2_params *p1 = key.fst; - uint8_t kk1 = p1->key_length; - uint8_t nn = p1->digest_length; - bool last_node = block_state1.thd; - Hacl_Hash_Blake2b_index - i = { .key_length = kk1, .digest_length = nn, .last_node = last_node }; - Lib_IntVector_Intrinsics_vec256 *h = block_state1.f3.snd; - uint32_t kk20 = (uint32_t)i.key_length; - uint8_t *k_2 = key.snd; - if (!(kk20 == 0U)) - { - uint8_t *sub_b = buf1 + kk20; - memset(sub_b, 0U, (128U - kk20) * sizeof (uint8_t)); - memcpy(buf1, k_2, kk20 * sizeof (uint8_t)); - } - Hacl_Hash_Blake2b_blake2_params pv = p1[0U]; - uint64_t tmp[8U] = { 0U }; - Lib_IntVector_Intrinsics_vec256 *r0 = h; - Lib_IntVector_Intrinsics_vec256 *r1 = h + 1U; - Lib_IntVector_Intrinsics_vec256 *r2 = h + 2U; - Lib_IntVector_Intrinsics_vec256 *r3 = h + 3U; - uint64_t iv0 = Hacl_Hash_Blake2b_ivTable_B[0U]; - uint64_t iv1 = Hacl_Hash_Blake2b_ivTable_B[1U]; - uint64_t iv2 = Hacl_Hash_Blake2b_ivTable_B[2U]; - uint64_t iv3 = Hacl_Hash_Blake2b_ivTable_B[3U]; - uint64_t iv4 = Hacl_Hash_Blake2b_ivTable_B[4U]; - uint64_t iv5 = Hacl_Hash_Blake2b_ivTable_B[5U]; - uint64_t iv6 = Hacl_Hash_Blake2b_ivTable_B[6U]; - uint64_t iv7 = Hacl_Hash_Blake2b_ivTable_B[7U]; - r2[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv0, iv1, iv2, iv3); - r3[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv4, iv5, iv6, iv7); - uint8_t kk2 = pv.key_length; - uint8_t nn1 = pv.digest_length; - KRML_MAYBE_FOR2(i0, - 0U, - 2U, - 1U, - uint64_t *os = tmp + 4U; - uint8_t *bj = pv.salt + i0 * 8U; - uint64_t u = load64_le(bj); - uint64_t r4 = u; - uint64_t x = r4; - os[i0] = x;); - KRML_MAYBE_FOR2(i0, - 0U, - 2U, - 1U, - uint64_t *os = tmp + 6U; - uint8_t *bj = pv.personal + i0 * 8U; - uint64_t u = load64_le(bj); - uint64_t r4 = u; - uint64_t x = r4; - os[i0] = x;); - tmp[0U] = - (uint64_t)nn1 ^ - ((uint64_t)kk2 << 8U ^ - ((uint64_t)pv.fanout << 16U ^ - ((uint64_t)pv.depth << 24U ^ (uint64_t)pv.leaf_length << 32U))); - tmp[1U] = pv.node_offset; - tmp[2U] = (uint64_t)pv.node_depth ^ (uint64_t)pv.inner_length << 8U; - tmp[3U] = 0ULL; - uint64_t tmp0 = tmp[0U]; - uint64_t tmp1 = tmp[1U]; - uint64_t tmp2 = tmp[2U]; - uint64_t tmp3 = tmp[3U]; - uint64_t tmp4 = tmp[4U]; - uint64_t tmp5 = tmp[5U]; - uint64_t tmp6 = tmp[6U]; - uint64_t tmp7 = tmp[7U]; - uint64_t iv0_ = iv0 ^ tmp0; - uint64_t iv1_ = iv1 ^ tmp1; - uint64_t iv2_ = iv2 ^ tmp2; - uint64_t iv3_ = iv3 ^ tmp3; - uint64_t iv4_ = iv4 ^ tmp4; - uint64_t iv5_ = iv5 ^ tmp5; - uint64_t iv6_ = iv6 ^ tmp6; - uint64_t iv7_ = iv7 ^ tmp7; - r0[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv0_, iv1_, iv2_, iv3_); - r1[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv4_, iv5_, iv6_, iv7_); - return p; - } - default: - { - KRML_HOST_EPRINTF("KaRaMeL incomplete match at %s:%d\n", __FILE__, __LINE__); - KRML_HOST_EXIT(253U); - } - } - } - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); -} - -/** - General-purpose allocation function that gives control over all -Blake2 parameters, including the key. Further resettings of the state SHALL be -done with `reset_with_params_and_key`, and SHALL feature the exact same values -for the `key_length` and `digest_length` fields as passed here. In other words, -once you commit to a digest and key length, the only way to change these -parameters is to allocate a new object. - -The caller must satisfy the following requirements. -- The length of the key k MUST match the value of the field key_length in the - parameters. -- The key_length must not exceed 256 for S, 64 for B. -- The digest_length must not exceed 256 for S, 64 for B. - -*/ -Hacl_Hash_Blake2b_Simd256_state_t -*Hacl_Hash_Blake2b_Simd256_malloc_with_params_and_key( - Hacl_Hash_Blake2b_blake2_params *p, - bool last_node, - uint8_t *k -) -{ - Hacl_Hash_Blake2b_blake2_params pv = p[0U]; - Hacl_Hash_Blake2b_index - i1 = { .key_length = pv.key_length, .digest_length = pv.digest_length, .last_node = last_node }; - return malloc_raw(i1, ((Hacl_Hash_Blake2b_params_and_key){ .fst = p, .snd = k })); -} - -/** - Specialized allocation function that picks default values for all -parameters, except for the key_length. Further resettings of the state SHALL be -done with `reset_with_key`, and SHALL feature the exact same key length `kk` as -passed here. In other words, once you commit to a key length, the only way to -change this parameter is to allocate a new object. - -The caller must satisfy the following requirements. -- The key_length must not exceed 256 for S, 64 for B. - -*/ -Hacl_Hash_Blake2b_Simd256_state_t -*Hacl_Hash_Blake2b_Simd256_malloc_with_key(uint8_t *k, uint8_t kk) -{ - uint8_t nn = 64U; - Hacl_Hash_Blake2b_index i = { .key_length = kk, .digest_length = nn, .last_node = false }; - uint8_t salt[16U] = { 0U }; - uint8_t personal[16U] = { 0U }; - Hacl_Hash_Blake2b_blake2_params - p = - { - .digest_length = i.digest_length, .key_length = i.key_length, .fanout = 1U, .depth = 1U, - .leaf_length = 0U, .node_offset = 0ULL, .node_depth = 0U, .inner_length = 0U, .salt = salt, - .personal = personal - }; - Hacl_Hash_Blake2b_blake2_params p0 = p; - Hacl_Hash_Blake2b_Simd256_state_t - *s = Hacl_Hash_Blake2b_Simd256_malloc_with_params_and_key(&p0, false, k); - return s; -} - -/** - Specialized allocation function that picks default values for all -parameters, and has no key. Effectively, this is what you want if you intend to -use Blake2 as a hash function. Further resettings of the state SHALL be done with `reset`. -*/ -Hacl_Hash_Blake2b_Simd256_state_t *Hacl_Hash_Blake2b_Simd256_malloc(void) -{ - return Hacl_Hash_Blake2b_Simd256_malloc_with_key(NULL, 0U); -} - -static Hacl_Hash_Blake2b_index index_of_state(Hacl_Hash_Blake2b_Simd256_state_t *s) -{ - Hacl_Hash_Blake2b_Simd256_block_state_t block_state = (*s).block_state; - bool last_node = block_state.thd; - uint8_t nn = block_state.snd; - uint8_t kk1 = block_state.fst; - return - ((Hacl_Hash_Blake2b_index){ .key_length = kk1, .digest_length = nn, .last_node = last_node }); -} - -static void -reset_raw(Hacl_Hash_Blake2b_Simd256_state_t *state, Hacl_Hash_Blake2b_params_and_key key) -{ - Hacl_Hash_Blake2b_Simd256_state_t scrut = *state; - uint8_t *buf = scrut.buf; - Hacl_Hash_Blake2b_Simd256_block_state_t block_state = scrut.block_state; - bool last_node0 = block_state.thd; - uint8_t nn0 = block_state.snd; - uint8_t kk10 = block_state.fst; - Hacl_Hash_Blake2b_index - i = { .key_length = kk10, .digest_length = nn0, .last_node = last_node0 }; - KRML_MAYBE_UNUSED_VAR(i); - Hacl_Hash_Blake2b_blake2_params *p = key.fst; - uint8_t kk1 = p->key_length; - uint8_t nn = p->digest_length; - bool last_node = block_state.thd; - Hacl_Hash_Blake2b_index - i1 = { .key_length = kk1, .digest_length = nn, .last_node = last_node }; - Lib_IntVector_Intrinsics_vec256 *h = block_state.f3.snd; - uint32_t kk20 = (uint32_t)i1.key_length; - uint8_t *k_1 = key.snd; - if (!(kk20 == 0U)) - { - uint8_t *sub_b = buf + kk20; - memset(sub_b, 0U, (128U - kk20) * sizeof (uint8_t)); - memcpy(buf, k_1, kk20 * sizeof (uint8_t)); - } - Hacl_Hash_Blake2b_blake2_params pv = p[0U]; - uint64_t tmp[8U] = { 0U }; - Lib_IntVector_Intrinsics_vec256 *r0 = h; - Lib_IntVector_Intrinsics_vec256 *r1 = h + 1U; - Lib_IntVector_Intrinsics_vec256 *r2 = h + 2U; - Lib_IntVector_Intrinsics_vec256 *r3 = h + 3U; - uint64_t iv0 = Hacl_Hash_Blake2b_ivTable_B[0U]; - uint64_t iv1 = Hacl_Hash_Blake2b_ivTable_B[1U]; - uint64_t iv2 = Hacl_Hash_Blake2b_ivTable_B[2U]; - uint64_t iv3 = Hacl_Hash_Blake2b_ivTable_B[3U]; - uint64_t iv4 = Hacl_Hash_Blake2b_ivTable_B[4U]; - uint64_t iv5 = Hacl_Hash_Blake2b_ivTable_B[5U]; - uint64_t iv6 = Hacl_Hash_Blake2b_ivTable_B[6U]; - uint64_t iv7 = Hacl_Hash_Blake2b_ivTable_B[7U]; - r2[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv0, iv1, iv2, iv3); - r3[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv4, iv5, iv6, iv7); - uint8_t kk2 = pv.key_length; - uint8_t nn1 = pv.digest_length; - KRML_MAYBE_FOR2(i0, - 0U, - 2U, - 1U, - uint64_t *os = tmp + 4U; - uint8_t *bj = pv.salt + i0 * 8U; - uint64_t u = load64_le(bj); - uint64_t r = u; - uint64_t x = r; - os[i0] = x;); - KRML_MAYBE_FOR2(i0, - 0U, - 2U, - 1U, - uint64_t *os = tmp + 6U; - uint8_t *bj = pv.personal + i0 * 8U; - uint64_t u = load64_le(bj); - uint64_t r = u; - uint64_t x = r; - os[i0] = x;); - tmp[0U] = - (uint64_t)nn1 ^ - ((uint64_t)kk2 << 8U ^ - ((uint64_t)pv.fanout << 16U ^ ((uint64_t)pv.depth << 24U ^ (uint64_t)pv.leaf_length << 32U))); - tmp[1U] = pv.node_offset; - tmp[2U] = (uint64_t)pv.node_depth ^ (uint64_t)pv.inner_length << 8U; - tmp[3U] = 0ULL; - uint64_t tmp0 = tmp[0U]; - uint64_t tmp1 = tmp[1U]; - uint64_t tmp2 = tmp[2U]; - uint64_t tmp3 = tmp[3U]; - uint64_t tmp4 = tmp[4U]; - uint64_t tmp5 = tmp[5U]; - uint64_t tmp6 = tmp[6U]; - uint64_t tmp7 = tmp[7U]; - uint64_t iv0_ = iv0 ^ tmp0; - uint64_t iv1_ = iv1 ^ tmp1; - uint64_t iv2_ = iv2 ^ tmp2; - uint64_t iv3_ = iv3 ^ tmp3; - uint64_t iv4_ = iv4 ^ tmp4; - uint64_t iv5_ = iv5 ^ tmp5; - uint64_t iv6_ = iv6 ^ tmp6; - uint64_t iv7_ = iv7 ^ tmp7; - r0[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv0_, iv1_, iv2_, iv3_); - r1[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv4_, iv5_, iv6_, iv7_); - uint8_t kk11 = i.key_length; - uint32_t ite; - if (kk11 != 0U) - { - ite = 128U; - } - else - { - ite = 0U; - } - Hacl_Hash_Blake2b_Simd256_state_t - tmp8 = { .block_state = block_state, .buf = buf, .total_len = (uint64_t)ite }; - state[0U] = tmp8; -} - -/** - General-purpose re-initialization function with parameters and -key. You cannot change digest_length, key_length, or last_node, meaning those values in -the parameters object must be the same as originally decided via one of the -malloc functions. All other values of the parameter can be changed. The behavior -is unspecified if you violate this precondition. -*/ -void -Hacl_Hash_Blake2b_Simd256_reset_with_key_and_params( - Hacl_Hash_Blake2b_Simd256_state_t *s, - Hacl_Hash_Blake2b_blake2_params *p, - uint8_t *k -) -{ - Hacl_Hash_Blake2b_index i1 = index_of_state(s); - KRML_MAYBE_UNUSED_VAR(i1); - reset_raw(s, ((Hacl_Hash_Blake2b_params_and_key){ .fst = p, .snd = k })); -} - -/** - Specialized-purpose re-initialization function with no parameters, -and a key. The key length must be the same as originally decided via your choice -of malloc function. All other parameters are reset to their default values. The -original call to malloc MUST have set digest_length to the default value. The -behavior is unspecified if you violate this precondition. -*/ -void Hacl_Hash_Blake2b_Simd256_reset_with_key(Hacl_Hash_Blake2b_Simd256_state_t *s, uint8_t *k) -{ - Hacl_Hash_Blake2b_index idx = index_of_state(s); - uint8_t salt[16U] = { 0U }; - uint8_t personal[16U] = { 0U }; - Hacl_Hash_Blake2b_blake2_params - p = - { - .digest_length = idx.digest_length, .key_length = idx.key_length, .fanout = 1U, .depth = 1U, - .leaf_length = 0U, .node_offset = 0ULL, .node_depth = 0U, .inner_length = 0U, .salt = salt, - .personal = personal - }; - Hacl_Hash_Blake2b_blake2_params p0 = p; - reset_raw(s, ((Hacl_Hash_Blake2b_params_and_key){ .fst = &p0, .snd = k })); -} - -/** - Specialized-purpose re-initialization function with no parameters -and no key. This is what you want if you intend to use Blake2 as a hash -function. The key length and digest length must have been set to their -respective default values via your choice of malloc function (always true if you -used `malloc`). All other parameters are reset to their default values. The -behavior is unspecified if you violate this precondition. -*/ -void Hacl_Hash_Blake2b_Simd256_reset(Hacl_Hash_Blake2b_Simd256_state_t *s) -{ - Hacl_Hash_Blake2b_Simd256_reset_with_key(s, NULL); -} - -/** - Update function; 0 = success, 1 = max length exceeded -*/ -Hacl_Streaming_Types_error_code -Hacl_Hash_Blake2b_Simd256_update( - Hacl_Hash_Blake2b_Simd256_state_t *state, - uint8_t *chunk, - uint32_t chunk_len -) -{ - Hacl_Hash_Blake2b_Simd256_state_t s = *state; - uint64_t total_len = s.total_len; - if ((uint64_t)chunk_len > 0xffffffffffffffffULL - total_len) - { - return Hacl_Streaming_Types_MaximumLengthExceeded; - } - uint32_t sz; - if (total_len % (uint64_t)128U == 0ULL && total_len > 0ULL) - { - sz = 128U; - } - else - { - sz = (uint32_t)(total_len % (uint64_t)128U); - } - if (chunk_len <= 128U - sz) - { - Hacl_Hash_Blake2b_Simd256_state_t s1 = *state; - Hacl_Hash_Blake2b_Simd256_block_state_t block_state1 = s1.block_state; - uint8_t *buf = s1.buf; - uint64_t total_len1 = s1.total_len; - uint32_t sz1; - if (total_len1 % (uint64_t)128U == 0ULL && total_len1 > 0ULL) - { - sz1 = 128U; - } - else - { - sz1 = (uint32_t)(total_len1 % (uint64_t)128U); - } - uint8_t *buf2 = buf + sz1; - memcpy(buf2, chunk, chunk_len * sizeof (uint8_t)); - uint64_t total_len2 = total_len1 + (uint64_t)chunk_len; - *state = - ( - (Hacl_Hash_Blake2b_Simd256_state_t){ - .block_state = block_state1, - .buf = buf, - .total_len = total_len2 - } - ); - } - else if (sz == 0U) - { - Hacl_Hash_Blake2b_Simd256_state_t s1 = *state; - Hacl_Hash_Blake2b_Simd256_block_state_t block_state1 = s1.block_state; - uint8_t *buf = s1.buf; - uint64_t total_len1 = s1.total_len; - uint32_t sz1; - if (total_len1 % (uint64_t)128U == 0ULL && total_len1 > 0ULL) - { - sz1 = 128U; - } - else - { - sz1 = (uint32_t)(total_len1 % (uint64_t)128U); - } - if (!(sz1 == 0U)) - { - uint64_t prevlen = total_len1 - (uint64_t)sz1; - Hacl_Hash_Blake2b_Simd256_two_2b_256 acc = block_state1.f3; - Lib_IntVector_Intrinsics_vec256 *wv = acc.fst; - Lib_IntVector_Intrinsics_vec256 *hash = acc.snd; - uint32_t nb = 1U; - Hacl_Hash_Blake2b_Simd256_update_multi(128U, - wv, - hash, - FStar_UInt128_uint64_to_uint128(prevlen), - buf, - nb); - } - uint32_t ite; - if ((uint64_t)chunk_len % (uint64_t)128U == 0ULL && (uint64_t)chunk_len > 0ULL) - { - ite = 128U; - } - else - { - ite = (uint32_t)((uint64_t)chunk_len % (uint64_t)128U); - } - uint32_t n_blocks = (chunk_len - ite) / 128U; - uint32_t data1_len = n_blocks * 128U; - uint32_t data2_len = chunk_len - data1_len; - uint8_t *data1 = chunk; - uint8_t *data2 = chunk + data1_len; - Hacl_Hash_Blake2b_Simd256_two_2b_256 acc = block_state1.f3; - Lib_IntVector_Intrinsics_vec256 *wv = acc.fst; - Lib_IntVector_Intrinsics_vec256 *hash = acc.snd; - uint32_t nb = data1_len / 128U; - Hacl_Hash_Blake2b_Simd256_update_multi(data1_len, - wv, - hash, - FStar_UInt128_uint64_to_uint128(total_len1), - data1, - nb); - uint8_t *dst = buf; - memcpy(dst, data2, data2_len * sizeof (uint8_t)); - *state = - ( - (Hacl_Hash_Blake2b_Simd256_state_t){ - .block_state = block_state1, - .buf = buf, - .total_len = total_len1 + (uint64_t)chunk_len - } - ); - } - else - { - uint32_t diff = 128U - sz; - uint8_t *chunk1 = chunk; - uint8_t *chunk2 = chunk + diff; - Hacl_Hash_Blake2b_Simd256_state_t s1 = *state; - Hacl_Hash_Blake2b_Simd256_block_state_t block_state10 = s1.block_state; - uint8_t *buf0 = s1.buf; - uint64_t total_len10 = s1.total_len; - uint32_t sz10; - if (total_len10 % (uint64_t)128U == 0ULL && total_len10 > 0ULL) - { - sz10 = 128U; - } - else - { - sz10 = (uint32_t)(total_len10 % (uint64_t)128U); - } - uint8_t *buf2 = buf0 + sz10; - memcpy(buf2, chunk1, diff * sizeof (uint8_t)); - uint64_t total_len2 = total_len10 + (uint64_t)diff; - *state = - ( - (Hacl_Hash_Blake2b_Simd256_state_t){ - .block_state = block_state10, - .buf = buf0, - .total_len = total_len2 - } - ); - Hacl_Hash_Blake2b_Simd256_state_t s10 = *state; - Hacl_Hash_Blake2b_Simd256_block_state_t block_state1 = s10.block_state; - uint8_t *buf = s10.buf; - uint64_t total_len1 = s10.total_len; - uint32_t sz1; - if (total_len1 % (uint64_t)128U == 0ULL && total_len1 > 0ULL) - { - sz1 = 128U; - } - else - { - sz1 = (uint32_t)(total_len1 % (uint64_t)128U); - } - if (!(sz1 == 0U)) - { - uint64_t prevlen = total_len1 - (uint64_t)sz1; - Hacl_Hash_Blake2b_Simd256_two_2b_256 acc = block_state1.f3; - Lib_IntVector_Intrinsics_vec256 *wv = acc.fst; - Lib_IntVector_Intrinsics_vec256 *hash = acc.snd; - uint32_t nb = 1U; - Hacl_Hash_Blake2b_Simd256_update_multi(128U, - wv, - hash, - FStar_UInt128_uint64_to_uint128(prevlen), - buf, - nb); - } - uint32_t ite; - if - ((uint64_t)(chunk_len - diff) % (uint64_t)128U == 0ULL && (uint64_t)(chunk_len - diff) > 0ULL) - { - ite = 128U; - } - else - { - ite = (uint32_t)((uint64_t)(chunk_len - diff) % (uint64_t)128U); - } - uint32_t n_blocks = (chunk_len - diff - ite) / 128U; - uint32_t data1_len = n_blocks * 128U; - uint32_t data2_len = chunk_len - diff - data1_len; - uint8_t *data1 = chunk2; - uint8_t *data2 = chunk2 + data1_len; - Hacl_Hash_Blake2b_Simd256_two_2b_256 acc = block_state1.f3; - Lib_IntVector_Intrinsics_vec256 *wv = acc.fst; - Lib_IntVector_Intrinsics_vec256 *hash = acc.snd; - uint32_t nb = data1_len / 128U; - Hacl_Hash_Blake2b_Simd256_update_multi(data1_len, - wv, - hash, - FStar_UInt128_uint64_to_uint128(total_len1), - data1, - nb); - uint8_t *dst = buf; - memcpy(dst, data2, data2_len * sizeof (uint8_t)); - *state = - ( - (Hacl_Hash_Blake2b_Simd256_state_t){ - .block_state = block_state1, - .buf = buf, - .total_len = total_len1 + (uint64_t)(chunk_len - diff) - } - ); - } - return Hacl_Streaming_Types_Success; -} - -/** - Digest function. This function expects the `output` array to hold -at least `digest_length` bytes, where `digest_length` was determined by your -choice of `malloc` function. Concretely, if you used `malloc` or -`malloc_with_key`, then the expected length is 256 for S, or 64 for B (default -digest length). If you used `malloc_with_params_and_key`, then the expected -length is whatever you chose for the `digest_length` field of your parameters. -For convenience, this function returns `digest_length`. When in doubt, callers -can pass an array of size HACL_BLAKE2B_256_OUT_BYTES, then use the return value -to see how many bytes were actually written. -*/ -uint8_t Hacl_Hash_Blake2b_Simd256_digest(Hacl_Hash_Blake2b_Simd256_state_t *s, uint8_t *dst) -{ - Hacl_Hash_Blake2b_Simd256_block_state_t block_state0 = (*s).block_state; - bool last_node0 = block_state0.thd; - uint8_t nn0 = block_state0.snd; - uint8_t kk0 = block_state0.fst; - Hacl_Hash_Blake2b_index - i1 = { .key_length = kk0, .digest_length = nn0, .last_node = last_node0 }; - Hacl_Hash_Blake2b_Simd256_state_t scrut = *s; - Hacl_Hash_Blake2b_Simd256_block_state_t block_state = scrut.block_state; - uint8_t *buf_ = scrut.buf; - uint64_t total_len = scrut.total_len; - uint32_t r; - if (total_len % (uint64_t)128U == 0ULL && total_len > 0ULL) - { - r = 128U; - } - else - { - r = (uint32_t)(total_len % (uint64_t)128U); - } - uint8_t *buf_1 = buf_; - KRML_PRE_ALIGN(32) Lib_IntVector_Intrinsics_vec256 wv0[4U] KRML_POST_ALIGN(32) = { 0U }; - KRML_PRE_ALIGN(32) Lib_IntVector_Intrinsics_vec256 b[4U] KRML_POST_ALIGN(32) = { 0U }; - Hacl_Hash_Blake2b_Simd256_block_state_t - tmp_block_state = - { - .fst = i1.key_length, - .snd = i1.digest_length, - .thd = i1.last_node, - .f3 = { .fst = wv0, .snd = b } - }; - Lib_IntVector_Intrinsics_vec256 *src_b = block_state.f3.snd; - Lib_IntVector_Intrinsics_vec256 *dst_b = tmp_block_state.f3.snd; - memcpy(dst_b, src_b, 4U * sizeof (Lib_IntVector_Intrinsics_vec256)); - uint64_t prev_len = total_len - (uint64_t)r; - uint32_t ite; - if (r % 128U == 0U && r > 0U) - { - ite = 128U; - } - else - { - ite = r % 128U; - } - uint8_t *buf_last = buf_1 + r - ite; - uint8_t *buf_multi = buf_1; - Hacl_Hash_Blake2b_Simd256_two_2b_256 acc0 = tmp_block_state.f3; - Lib_IntVector_Intrinsics_vec256 *wv1 = acc0.fst; - Lib_IntVector_Intrinsics_vec256 *hash0 = acc0.snd; - uint32_t nb = 0U; - Hacl_Hash_Blake2b_Simd256_update_multi(0U, - wv1, - hash0, - FStar_UInt128_uint64_to_uint128(prev_len), - buf_multi, - nb); - uint64_t prev_len_last = total_len - (uint64_t)r; - Hacl_Hash_Blake2b_Simd256_two_2b_256 acc = tmp_block_state.f3; - bool last_node1 = tmp_block_state.thd; - Lib_IntVector_Intrinsics_vec256 *wv = acc.fst; - Lib_IntVector_Intrinsics_vec256 *hash = acc.snd; - Hacl_Hash_Blake2b_Simd256_update_last(r, - wv, - hash, - last_node1, - FStar_UInt128_uint64_to_uint128(prev_len_last), - r, - buf_last); - uint8_t nn1 = tmp_block_state.snd; - Hacl_Hash_Blake2b_Simd256_finish((uint32_t)nn1, dst, tmp_block_state.f3.snd); - Hacl_Hash_Blake2b_Simd256_block_state_t block_state1 = (*s).block_state; - bool last_node = block_state1.thd; - uint8_t nn = block_state1.snd; - uint8_t kk = block_state1.fst; - return - ((Hacl_Hash_Blake2b_index){ .key_length = kk, .digest_length = nn, .last_node = last_node }).digest_length; -} - -Hacl_Hash_Blake2b_index Hacl_Hash_Blake2b_Simd256_info(Hacl_Hash_Blake2b_Simd256_state_t *s) -{ - Hacl_Hash_Blake2b_Simd256_block_state_t block_state = (*s).block_state; - bool last_node = block_state.thd; - uint8_t nn = block_state.snd; - uint8_t kk = block_state.fst; - return - ((Hacl_Hash_Blake2b_index){ .key_length = kk, .digest_length = nn, .last_node = last_node }); -} - -/** - Free state function when there is no key -*/ -void Hacl_Hash_Blake2b_Simd256_free(Hacl_Hash_Blake2b_Simd256_state_t *state) -{ - Hacl_Hash_Blake2b_Simd256_state_t scrut = *state; - uint8_t *buf = scrut.buf; - Hacl_Hash_Blake2b_Simd256_block_state_t block_state = scrut.block_state; - Lib_IntVector_Intrinsics_vec256 *b = block_state.f3.snd; - Lib_IntVector_Intrinsics_vec256 *wv = block_state.f3.fst; - KRML_ALIGNED_FREE(wv); - KRML_ALIGNED_FREE(b); - KRML_HOST_FREE(buf); - KRML_HOST_FREE(state); -} - -/** - Copying. This preserves all parameters. -*/ -Hacl_Hash_Blake2b_Simd256_state_t -*Hacl_Hash_Blake2b_Simd256_copy(Hacl_Hash_Blake2b_Simd256_state_t *state) -{ - Hacl_Hash_Blake2b_Simd256_state_t scrut = *state; - Hacl_Hash_Blake2b_Simd256_block_state_t block_state0 = scrut.block_state; - uint8_t *buf0 = scrut.buf; - uint64_t total_len0 = scrut.total_len; - bool last_node = block_state0.thd; - uint8_t nn = block_state0.snd; - uint8_t kk1 = block_state0.fst; - Hacl_Hash_Blake2b_index i = { .key_length = kk1, .digest_length = nn, .last_node = last_node }; - uint8_t *buf = (uint8_t *)KRML_HOST_CALLOC(128U, sizeof (uint8_t)); - if (buf == NULL) - { - return NULL; - } - memcpy(buf, buf0, 128U * sizeof (uint8_t)); - Lib_IntVector_Intrinsics_vec256 - *wv0 = - (Lib_IntVector_Intrinsics_vec256 *)KRML_ALIGNED_MALLOC(32, - sizeof (Lib_IntVector_Intrinsics_vec256) * 4U); - if (wv0 != NULL) - { - memset(wv0, 0U, 4U * sizeof (Lib_IntVector_Intrinsics_vec256)); - } - option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec256_____Lib_IntVector_Intrinsics_vec256___ - block_state; - if (wv0 == NULL) - { - block_state = - ( - (option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec256_____Lib_IntVector_Intrinsics_vec256___){ - .tag = Hacl_Streaming_Types_None - } - ); - } - else - { - Lib_IntVector_Intrinsics_vec256 - *b = - (Lib_IntVector_Intrinsics_vec256 *)KRML_ALIGNED_MALLOC(32, - sizeof (Lib_IntVector_Intrinsics_vec256) * 4U); - if (b != NULL) - { - memset(b, 0U, 4U * sizeof (Lib_IntVector_Intrinsics_vec256)); - } - if (b == NULL) - { - KRML_ALIGNED_FREE(wv0); - block_state = - ( - (option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec256_____Lib_IntVector_Intrinsics_vec256___){ - .tag = Hacl_Streaming_Types_None - } - ); - } - else - { - block_state = - ( - (option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec256_____Lib_IntVector_Intrinsics_vec256___){ - .tag = Hacl_Streaming_Types_Some, - .v = { - .fst = i.key_length, - .snd = i.digest_length, - .thd = i.last_node, - .f3 = { .fst = wv0, .snd = b } - } - } - ); - } - } - if (block_state.tag == Hacl_Streaming_Types_None) - { - KRML_HOST_FREE(buf); - return NULL; - } - if (block_state.tag == Hacl_Streaming_Types_Some) - { - Hacl_Hash_Blake2b_Simd256_block_state_t block_state1 = block_state.v; - Lib_IntVector_Intrinsics_vec256 *src_b = block_state0.f3.snd; - Lib_IntVector_Intrinsics_vec256 *dst_b = block_state1.f3.snd; - memcpy(dst_b, src_b, 4U * sizeof (Lib_IntVector_Intrinsics_vec256)); - Hacl_Streaming_Types_optional k_ = Hacl_Streaming_Types_Some; - switch (k_) - { - case Hacl_Streaming_Types_None: - { - return NULL; - } - case Hacl_Streaming_Types_Some: - { - Hacl_Hash_Blake2b_Simd256_state_t - s = { .block_state = block_state1, .buf = buf, .total_len = total_len0 }; - Hacl_Hash_Blake2b_Simd256_state_t - *p = - (Hacl_Hash_Blake2b_Simd256_state_t *)KRML_HOST_MALLOC(sizeof ( - Hacl_Hash_Blake2b_Simd256_state_t - )); - if (p != NULL) - { - p[0U] = s; - } - if (p == NULL) - { - Lib_IntVector_Intrinsics_vec256 *b = block_state1.f3.snd; - Lib_IntVector_Intrinsics_vec256 *wv = block_state1.f3.fst; - KRML_ALIGNED_FREE(wv); - KRML_ALIGNED_FREE(b); - KRML_HOST_FREE(buf); - return NULL; - } - return p; - } - default: - { - KRML_HOST_EPRINTF("KaRaMeL incomplete match at %s:%d\n", __FILE__, __LINE__); - KRML_HOST_EXIT(253U); - } - } - } - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); -} - -/** -Write the BLAKE2b digest of message `input` using key `key` into `output`. - -@param output Pointer to `output_len` bytes of memory where the digest is written to. -@param output_len Length of the to-be-generated digest with 1 <= `output_len` <= 64. -@param input Pointer to `input_len` bytes of memory where the input message is read from. -@param input_len Length of the input message. -@param key Pointer to `key_len` bytes of memory where the key is read from. -@param key_len Length of the key. Can be 0. -*/ -void -Hacl_Hash_Blake2b_Simd256_hash_with_key( - uint8_t *output, - uint32_t output_len, - uint8_t *input, - uint32_t input_len, - uint8_t *key, - uint32_t key_len -) -{ - KRML_PRE_ALIGN(32) Lib_IntVector_Intrinsics_vec256 b[4U] KRML_POST_ALIGN(32) = { 0U }; - KRML_PRE_ALIGN(32) Lib_IntVector_Intrinsics_vec256 b1[4U] KRML_POST_ALIGN(32) = { 0U }; - Hacl_Hash_Blake2b_Simd256_init(b, key_len, output_len); - update(b1, b, key_len, key, input_len, input); - Hacl_Hash_Blake2b_Simd256_finish(output_len, output, b); - Lib_Memzero0_memzero(b1, 4U, Lib_IntVector_Intrinsics_vec256, void *); - Lib_Memzero0_memzero(b, 4U, Lib_IntVector_Intrinsics_vec256, void *); -} - -/** -Write the BLAKE2b digest of message `input` using key `key` and -parameters `params` into `output`. The `key` array must be of length -`params.key_length`. The `output` array must be of length -`params.digest_length`. -*/ -void -Hacl_Hash_Blake2b_Simd256_hash_with_key_and_params( - uint8_t *output, - uint8_t *input, - uint32_t input_len, - Hacl_Hash_Blake2b_blake2_params params, - uint8_t *key -) -{ - KRML_PRE_ALIGN(32) Lib_IntVector_Intrinsics_vec256 b[4U] KRML_POST_ALIGN(32) = { 0U }; - KRML_PRE_ALIGN(32) Lib_IntVector_Intrinsics_vec256 b1[4U] KRML_POST_ALIGN(32) = { 0U }; - uint64_t tmp[8U] = { 0U }; - Lib_IntVector_Intrinsics_vec256 *r0 = b; - Lib_IntVector_Intrinsics_vec256 *r1 = b + 1U; - Lib_IntVector_Intrinsics_vec256 *r2 = b + 2U; - Lib_IntVector_Intrinsics_vec256 *r3 = b + 3U; - uint64_t iv0 = Hacl_Hash_Blake2b_ivTable_B[0U]; - uint64_t iv1 = Hacl_Hash_Blake2b_ivTable_B[1U]; - uint64_t iv2 = Hacl_Hash_Blake2b_ivTable_B[2U]; - uint64_t iv3 = Hacl_Hash_Blake2b_ivTable_B[3U]; - uint64_t iv4 = Hacl_Hash_Blake2b_ivTable_B[4U]; - uint64_t iv5 = Hacl_Hash_Blake2b_ivTable_B[5U]; - uint64_t iv6 = Hacl_Hash_Blake2b_ivTable_B[6U]; - uint64_t iv7 = Hacl_Hash_Blake2b_ivTable_B[7U]; - r2[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv0, iv1, iv2, iv3); - r3[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv4, iv5, iv6, iv7); - uint8_t kk = params.key_length; - uint8_t nn = params.digest_length; - KRML_MAYBE_FOR2(i, - 0U, - 2U, - 1U, - uint64_t *os = tmp + 4U; - uint8_t *bj = params.salt + i * 8U; - uint64_t u = load64_le(bj); - uint64_t r = u; - uint64_t x = r; - os[i] = x;); - KRML_MAYBE_FOR2(i, - 0U, - 2U, - 1U, - uint64_t *os = tmp + 6U; - uint8_t *bj = params.personal + i * 8U; - uint64_t u = load64_le(bj); - uint64_t r = u; - uint64_t x = r; - os[i] = x;); - tmp[0U] = - (uint64_t)nn ^ - ((uint64_t)kk << 8U ^ - ((uint64_t)params.fanout << 16U ^ - ((uint64_t)params.depth << 24U ^ (uint64_t)params.leaf_length << 32U))); - tmp[1U] = params.node_offset; - tmp[2U] = (uint64_t)params.node_depth ^ (uint64_t)params.inner_length << 8U; - tmp[3U] = 0ULL; - uint64_t tmp0 = tmp[0U]; - uint64_t tmp1 = tmp[1U]; - uint64_t tmp2 = tmp[2U]; - uint64_t tmp3 = tmp[3U]; - uint64_t tmp4 = tmp[4U]; - uint64_t tmp5 = tmp[5U]; - uint64_t tmp6 = tmp[6U]; - uint64_t tmp7 = tmp[7U]; - uint64_t iv0_ = iv0 ^ tmp0; - uint64_t iv1_ = iv1 ^ tmp1; - uint64_t iv2_ = iv2 ^ tmp2; - uint64_t iv3_ = iv3 ^ tmp3; - uint64_t iv4_ = iv4 ^ tmp4; - uint64_t iv5_ = iv5 ^ tmp5; - uint64_t iv6_ = iv6 ^ tmp6; - uint64_t iv7_ = iv7 ^ tmp7; - r0[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv0_, iv1_, iv2_, iv3_); - r1[0U] = Lib_IntVector_Intrinsics_vec256_load64s(iv4_, iv5_, iv6_, iv7_); - update(b1, b, (uint32_t)params.key_length, key, input_len, input); - Hacl_Hash_Blake2b_Simd256_finish((uint32_t)params.digest_length, output, b); - Lib_Memzero0_memzero(b1, 4U, Lib_IntVector_Intrinsics_vec256, void *); - Lib_Memzero0_memzero(b, 4U, Lib_IntVector_Intrinsics_vec256, void *); -} - diff --git a/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c b/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c deleted file mode 100644 index 116499fedb3bd01..000000000000000 --- a/Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.c +++ /dev/null @@ -1,15 +0,0 @@ -// This file isn't part of a standard HACL source tree. -// -// It is required for compatibility with universal2 macOS builds. The code in -// Hacl_Hash_Blake2b_Simd256.c *will* compile on macOS x86_64, but *won't* -// compile on ARM64. However, because universal2 builds are compiled in a -// single pass, autoconf detects that the required compiler features *are* -// available, and tries to compile this file, which then fails because of the -// lack of support on ARM64. -// -// To compensate for this, autoconf will include *this* file instead of -// Hacl_Hash_Blake2b_Simd256.c when compiling for universal. This allows the -// underlying source code of HACL to remain unmodified. -#if !(defined(__APPLE__) && defined(__arm64__)) -#include "Hacl_Hash_Blake2b_Simd256.c" -#endif diff --git a/Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c b/Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c deleted file mode 100644 index fa46be045f34412..000000000000000 --- a/Modules/_hacl/Hacl_Hash_Blake2s_Simd128.c +++ /dev/null @@ -1,1559 +0,0 @@ -/* MIT License - * - * Copyright (c) 2016-2022 INRIA, CMU and Microsoft Corporation - * Copyright (c) 2022-2023 HACL* Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - - -#include "internal/Hacl_Hash_Blake2s_Simd128.h" - -#include "Hacl_Streaming_Types.h" -#include "Hacl_Hash_Blake2b.h" -#include "internal/Hacl_Streaming_Types.h" -#include "internal/Hacl_Impl_Blake2_Constants.h" -#include "internal/Hacl_Hash_Blake2b.h" -#include "lib_memzero0.h" - -static inline void -update_block( - Lib_IntVector_Intrinsics_vec128 *wv, - Lib_IntVector_Intrinsics_vec128 *hash, - bool flag, - bool last_node, - uint64_t totlen, - uint8_t *d -) -{ - uint32_t m_w[16U] = { 0U }; - KRML_MAYBE_FOR16(i, - 0U, - 16U, - 1U, - uint32_t *os = m_w; - uint8_t *bj = d + i * 4U; - uint32_t u = load32_le(bj); - uint32_t r = u; - uint32_t x = r; - os[i] = x;); - Lib_IntVector_Intrinsics_vec128 mask = Lib_IntVector_Intrinsics_vec128_zero; - uint32_t wv_14; - if (flag) - { - wv_14 = 0xFFFFFFFFU; - } - else - { - wv_14 = 0U; - } - uint32_t wv_15; - if (last_node) - { - wv_15 = 0xFFFFFFFFU; - } - else - { - wv_15 = 0U; - } - mask = - Lib_IntVector_Intrinsics_vec128_load32s((uint32_t)totlen, - (uint32_t)(totlen >> 32U), - wv_14, - wv_15); - memcpy(wv, hash, 4U * sizeof (Lib_IntVector_Intrinsics_vec128)); - Lib_IntVector_Intrinsics_vec128 *wv3 = wv + 3U; - wv3[0U] = Lib_IntVector_Intrinsics_vec128_xor(wv3[0U], mask); - KRML_MAYBE_FOR10(i, - 0U, - 10U, - 1U, - uint32_t start_idx = i % 10U * 16U; - KRML_PRE_ALIGN(16) Lib_IntVector_Intrinsics_vec128 m_st[4U] KRML_POST_ALIGN(16) = { 0U }; - Lib_IntVector_Intrinsics_vec128 *r0 = m_st; - Lib_IntVector_Intrinsics_vec128 *r1 = m_st + 1U; - Lib_IntVector_Intrinsics_vec128 *r20 = m_st + 2U; - Lib_IntVector_Intrinsics_vec128 *r30 = m_st + 3U; - uint32_t s0 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 0U]; - uint32_t s1 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 1U]; - uint32_t s2 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 2U]; - uint32_t s3 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 3U]; - uint32_t s4 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 4U]; - uint32_t s5 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 5U]; - uint32_t s6 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 6U]; - uint32_t s7 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 7U]; - uint32_t s8 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 8U]; - uint32_t s9 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 9U]; - uint32_t s10 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 10U]; - uint32_t s11 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 11U]; - uint32_t s12 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 12U]; - uint32_t s13 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 13U]; - uint32_t s14 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 14U]; - uint32_t s15 = Hacl_Hash_Blake2b_sigmaTable[start_idx + 15U]; - r0[0U] = Lib_IntVector_Intrinsics_vec128_load32s(m_w[s0], m_w[s2], m_w[s4], m_w[s6]); - r1[0U] = Lib_IntVector_Intrinsics_vec128_load32s(m_w[s1], m_w[s3], m_w[s5], m_w[s7]); - r20[0U] = Lib_IntVector_Intrinsics_vec128_load32s(m_w[s8], m_w[s10], m_w[s12], m_w[s14]); - r30[0U] = Lib_IntVector_Intrinsics_vec128_load32s(m_w[s9], m_w[s11], m_w[s13], m_w[s15]); - Lib_IntVector_Intrinsics_vec128 *x = m_st; - Lib_IntVector_Intrinsics_vec128 *y = m_st + 1U; - Lib_IntVector_Intrinsics_vec128 *z = m_st + 2U; - Lib_IntVector_Intrinsics_vec128 *w = m_st + 3U; - uint32_t a = 0U; - uint32_t b0 = 1U; - uint32_t c0 = 2U; - uint32_t d10 = 3U; - Lib_IntVector_Intrinsics_vec128 *wv_a0 = wv + a * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b0 = wv + b0 * 1U; - wv_a0[0U] = Lib_IntVector_Intrinsics_vec128_add32(wv_a0[0U], wv_b0[0U]); - wv_a0[0U] = Lib_IntVector_Intrinsics_vec128_add32(wv_a0[0U], x[0U]); - Lib_IntVector_Intrinsics_vec128 *wv_a1 = wv + d10 * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b1 = wv + a * 1U; - wv_a1[0U] = Lib_IntVector_Intrinsics_vec128_xor(wv_a1[0U], wv_b1[0U]); - wv_a1[0U] = Lib_IntVector_Intrinsics_vec128_rotate_right32(wv_a1[0U], 16U); - Lib_IntVector_Intrinsics_vec128 *wv_a2 = wv + c0 * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b2 = wv + d10 * 1U; - wv_a2[0U] = Lib_IntVector_Intrinsics_vec128_add32(wv_a2[0U], wv_b2[0U]); - Lib_IntVector_Intrinsics_vec128 *wv_a3 = wv + b0 * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b3 = wv + c0 * 1U; - wv_a3[0U] = Lib_IntVector_Intrinsics_vec128_xor(wv_a3[0U], wv_b3[0U]); - wv_a3[0U] = Lib_IntVector_Intrinsics_vec128_rotate_right32(wv_a3[0U], 12U); - Lib_IntVector_Intrinsics_vec128 *wv_a4 = wv + a * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b4 = wv + b0 * 1U; - wv_a4[0U] = Lib_IntVector_Intrinsics_vec128_add32(wv_a4[0U], wv_b4[0U]); - wv_a4[0U] = Lib_IntVector_Intrinsics_vec128_add32(wv_a4[0U], y[0U]); - Lib_IntVector_Intrinsics_vec128 *wv_a5 = wv + d10 * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b5 = wv + a * 1U; - wv_a5[0U] = Lib_IntVector_Intrinsics_vec128_xor(wv_a5[0U], wv_b5[0U]); - wv_a5[0U] = Lib_IntVector_Intrinsics_vec128_rotate_right32(wv_a5[0U], 8U); - Lib_IntVector_Intrinsics_vec128 *wv_a6 = wv + c0 * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b6 = wv + d10 * 1U; - wv_a6[0U] = Lib_IntVector_Intrinsics_vec128_add32(wv_a6[0U], wv_b6[0U]); - Lib_IntVector_Intrinsics_vec128 *wv_a7 = wv + b0 * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b7 = wv + c0 * 1U; - wv_a7[0U] = Lib_IntVector_Intrinsics_vec128_xor(wv_a7[0U], wv_b7[0U]); - wv_a7[0U] = Lib_IntVector_Intrinsics_vec128_rotate_right32(wv_a7[0U], 7U); - Lib_IntVector_Intrinsics_vec128 *r10 = wv + 1U; - Lib_IntVector_Intrinsics_vec128 *r21 = wv + 2U; - Lib_IntVector_Intrinsics_vec128 *r31 = wv + 3U; - Lib_IntVector_Intrinsics_vec128 v00 = r10[0U]; - Lib_IntVector_Intrinsics_vec128 - v1 = Lib_IntVector_Intrinsics_vec128_rotate_right_lanes32(v00, 1U); - r10[0U] = v1; - Lib_IntVector_Intrinsics_vec128 v01 = r21[0U]; - Lib_IntVector_Intrinsics_vec128 - v10 = Lib_IntVector_Intrinsics_vec128_rotate_right_lanes32(v01, 2U); - r21[0U] = v10; - Lib_IntVector_Intrinsics_vec128 v02 = r31[0U]; - Lib_IntVector_Intrinsics_vec128 - v11 = Lib_IntVector_Intrinsics_vec128_rotate_right_lanes32(v02, 3U); - r31[0U] = v11; - uint32_t a0 = 0U; - uint32_t b = 1U; - uint32_t c = 2U; - uint32_t d1 = 3U; - Lib_IntVector_Intrinsics_vec128 *wv_a = wv + a0 * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b8 = wv + b * 1U; - wv_a[0U] = Lib_IntVector_Intrinsics_vec128_add32(wv_a[0U], wv_b8[0U]); - wv_a[0U] = Lib_IntVector_Intrinsics_vec128_add32(wv_a[0U], z[0U]); - Lib_IntVector_Intrinsics_vec128 *wv_a8 = wv + d1 * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b9 = wv + a0 * 1U; - wv_a8[0U] = Lib_IntVector_Intrinsics_vec128_xor(wv_a8[0U], wv_b9[0U]); - wv_a8[0U] = Lib_IntVector_Intrinsics_vec128_rotate_right32(wv_a8[0U], 16U); - Lib_IntVector_Intrinsics_vec128 *wv_a9 = wv + c * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b10 = wv + d1 * 1U; - wv_a9[0U] = Lib_IntVector_Intrinsics_vec128_add32(wv_a9[0U], wv_b10[0U]); - Lib_IntVector_Intrinsics_vec128 *wv_a10 = wv + b * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b11 = wv + c * 1U; - wv_a10[0U] = Lib_IntVector_Intrinsics_vec128_xor(wv_a10[0U], wv_b11[0U]); - wv_a10[0U] = Lib_IntVector_Intrinsics_vec128_rotate_right32(wv_a10[0U], 12U); - Lib_IntVector_Intrinsics_vec128 *wv_a11 = wv + a0 * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b12 = wv + b * 1U; - wv_a11[0U] = Lib_IntVector_Intrinsics_vec128_add32(wv_a11[0U], wv_b12[0U]); - wv_a11[0U] = Lib_IntVector_Intrinsics_vec128_add32(wv_a11[0U], w[0U]); - Lib_IntVector_Intrinsics_vec128 *wv_a12 = wv + d1 * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b13 = wv + a0 * 1U; - wv_a12[0U] = Lib_IntVector_Intrinsics_vec128_xor(wv_a12[0U], wv_b13[0U]); - wv_a12[0U] = Lib_IntVector_Intrinsics_vec128_rotate_right32(wv_a12[0U], 8U); - Lib_IntVector_Intrinsics_vec128 *wv_a13 = wv + c * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b14 = wv + d1 * 1U; - wv_a13[0U] = Lib_IntVector_Intrinsics_vec128_add32(wv_a13[0U], wv_b14[0U]); - Lib_IntVector_Intrinsics_vec128 *wv_a14 = wv + b * 1U; - Lib_IntVector_Intrinsics_vec128 *wv_b = wv + c * 1U; - wv_a14[0U] = Lib_IntVector_Intrinsics_vec128_xor(wv_a14[0U], wv_b[0U]); - wv_a14[0U] = Lib_IntVector_Intrinsics_vec128_rotate_right32(wv_a14[0U], 7U); - Lib_IntVector_Intrinsics_vec128 *r11 = wv + 1U; - Lib_IntVector_Intrinsics_vec128 *r2 = wv + 2U; - Lib_IntVector_Intrinsics_vec128 *r3 = wv + 3U; - Lib_IntVector_Intrinsics_vec128 v0 = r11[0U]; - Lib_IntVector_Intrinsics_vec128 - v12 = Lib_IntVector_Intrinsics_vec128_rotate_right_lanes32(v0, 3U); - r11[0U] = v12; - Lib_IntVector_Intrinsics_vec128 v03 = r2[0U]; - Lib_IntVector_Intrinsics_vec128 - v13 = Lib_IntVector_Intrinsics_vec128_rotate_right_lanes32(v03, 2U); - r2[0U] = v13; - Lib_IntVector_Intrinsics_vec128 v04 = r3[0U]; - Lib_IntVector_Intrinsics_vec128 - v14 = Lib_IntVector_Intrinsics_vec128_rotate_right_lanes32(v04, 1U); - r3[0U] = v14;); - Lib_IntVector_Intrinsics_vec128 *s0 = hash; - Lib_IntVector_Intrinsics_vec128 *s1 = hash + 1U; - Lib_IntVector_Intrinsics_vec128 *r0 = wv; - Lib_IntVector_Intrinsics_vec128 *r1 = wv + 1U; - Lib_IntVector_Intrinsics_vec128 *r2 = wv + 2U; - Lib_IntVector_Intrinsics_vec128 *r3 = wv + 3U; - s0[0U] = Lib_IntVector_Intrinsics_vec128_xor(s0[0U], r0[0U]); - s0[0U] = Lib_IntVector_Intrinsics_vec128_xor(s0[0U], r2[0U]); - s1[0U] = Lib_IntVector_Intrinsics_vec128_xor(s1[0U], r1[0U]); - s1[0U] = Lib_IntVector_Intrinsics_vec128_xor(s1[0U], r3[0U]); -} - -void -Hacl_Hash_Blake2s_Simd128_init(Lib_IntVector_Intrinsics_vec128 *hash, uint32_t kk, uint32_t nn) -{ - uint8_t salt[8U] = { 0U }; - uint8_t personal[8U] = { 0U }; - Hacl_Hash_Blake2b_blake2_params - p = - { - .digest_length = 32U, .key_length = 0U, .fanout = 1U, .depth = 1U, .leaf_length = 0U, - .node_offset = 0ULL, .node_depth = 0U, .inner_length = 0U, .salt = salt, .personal = personal - }; - uint32_t tmp[8U] = { 0U }; - Lib_IntVector_Intrinsics_vec128 *r0 = hash; - Lib_IntVector_Intrinsics_vec128 *r1 = hash + 1U; - Lib_IntVector_Intrinsics_vec128 *r2 = hash + 2U; - Lib_IntVector_Intrinsics_vec128 *r3 = hash + 3U; - uint32_t iv0 = Hacl_Hash_Blake2b_ivTable_S[0U]; - uint32_t iv1 = Hacl_Hash_Blake2b_ivTable_S[1U]; - uint32_t iv2 = Hacl_Hash_Blake2b_ivTable_S[2U]; - uint32_t iv3 = Hacl_Hash_Blake2b_ivTable_S[3U]; - uint32_t iv4 = Hacl_Hash_Blake2b_ivTable_S[4U]; - uint32_t iv5 = Hacl_Hash_Blake2b_ivTable_S[5U]; - uint32_t iv6 = Hacl_Hash_Blake2b_ivTable_S[6U]; - uint32_t iv7 = Hacl_Hash_Blake2b_ivTable_S[7U]; - r2[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv0, iv1, iv2, iv3); - r3[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv4, iv5, iv6, iv7); - KRML_MAYBE_FOR2(i, - 0U, - 2U, - 1U, - uint32_t *os = tmp + 4U; - uint8_t *bj = p.salt + i * 4U; - uint32_t u = load32_le(bj); - uint32_t r = u; - uint32_t x = r; - os[i] = x;); - KRML_MAYBE_FOR2(i, - 0U, - 2U, - 1U, - uint32_t *os = tmp + 6U; - uint8_t *bj = p.personal + i * 4U; - uint32_t u = load32_le(bj); - uint32_t r = u; - uint32_t x = r; - os[i] = x;); - tmp[0U] = - (uint32_t)(uint8_t)nn ^ - ((uint32_t)(uint8_t)kk << 8U ^ ((uint32_t)p.fanout << 16U ^ (uint32_t)p.depth << 24U)); - tmp[1U] = p.leaf_length; - tmp[2U] = (uint32_t)p.node_offset; - tmp[3U] = - (uint32_t)(p.node_offset >> 32U) ^ - ((uint32_t)p.node_depth << 16U ^ (uint32_t)p.inner_length << 24U); - uint32_t tmp0 = tmp[0U]; - uint32_t tmp1 = tmp[1U]; - uint32_t tmp2 = tmp[2U]; - uint32_t tmp3 = tmp[3U]; - uint32_t tmp4 = tmp[4U]; - uint32_t tmp5 = tmp[5U]; - uint32_t tmp6 = tmp[6U]; - uint32_t tmp7 = tmp[7U]; - uint32_t iv0_ = iv0 ^ tmp0; - uint32_t iv1_ = iv1 ^ tmp1; - uint32_t iv2_ = iv2 ^ tmp2; - uint32_t iv3_ = iv3 ^ tmp3; - uint32_t iv4_ = iv4 ^ tmp4; - uint32_t iv5_ = iv5 ^ tmp5; - uint32_t iv6_ = iv6 ^ tmp6; - uint32_t iv7_ = iv7 ^ tmp7; - r0[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv0_, iv1_, iv2_, iv3_); - r1[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv4_, iv5_, iv6_, iv7_); -} - -static void -update_key( - Lib_IntVector_Intrinsics_vec128 *wv, - Lib_IntVector_Intrinsics_vec128 *hash, - uint32_t kk, - uint8_t *k, - uint32_t ll -) -{ - uint64_t lb = (uint64_t)64U; - uint8_t b[64U] = { 0U }; - memcpy(b, k, kk * sizeof (uint8_t)); - if (ll == 0U) - { - update_block(wv, hash, true, false, lb, b); - } - else - { - update_block(wv, hash, false, false, lb, b); - } - Lib_Memzero0_memzero(b, 64U, uint8_t, void *); -} - -void -Hacl_Hash_Blake2s_Simd128_update_multi( - uint32_t len, - Lib_IntVector_Intrinsics_vec128 *wv, - Lib_IntVector_Intrinsics_vec128 *hash, - uint64_t prev, - uint8_t *blocks, - uint32_t nb -) -{ - KRML_MAYBE_UNUSED_VAR(len); - for (uint32_t i = 0U; i < nb; i++) - { - uint64_t totlen = prev + (uint64_t)((i + 1U) * 64U); - uint8_t *b = blocks + i * 64U; - update_block(wv, hash, false, false, totlen, b); - } -} - -void -Hacl_Hash_Blake2s_Simd128_update_last( - uint32_t len, - Lib_IntVector_Intrinsics_vec128 *wv, - Lib_IntVector_Intrinsics_vec128 *hash, - bool last_node, - uint64_t prev, - uint32_t rem, - uint8_t *d -) -{ - uint8_t b[64U] = { 0U }; - uint8_t *last = d + len - rem; - memcpy(b, last, rem * sizeof (uint8_t)); - uint64_t totlen = prev + (uint64_t)len; - update_block(wv, hash, true, last_node, totlen, b); - Lib_Memzero0_memzero(b, 64U, uint8_t, void *); -} - -static inline void -update_blocks( - uint32_t len, - Lib_IntVector_Intrinsics_vec128 *wv, - Lib_IntVector_Intrinsics_vec128 *hash, - uint64_t prev, - uint8_t *blocks -) -{ - uint32_t nb0 = len / 64U; - uint32_t rem0 = len % 64U; - uint32_t nb; - if (rem0 == 0U && nb0 > 0U) - { - nb = nb0 - 1U; - } - else - { - nb = nb0; - } - uint32_t rem; - if (rem0 == 0U && nb0 > 0U) - { - rem = 64U; - } - else - { - rem = rem0; - } - Hacl_Hash_Blake2s_Simd128_update_multi(len, wv, hash, prev, blocks, nb); - Hacl_Hash_Blake2s_Simd128_update_last(len, wv, hash, false, prev, rem, blocks); -} - -static inline void -update( - Lib_IntVector_Intrinsics_vec128 *wv, - Lib_IntVector_Intrinsics_vec128 *hash, - uint32_t kk, - uint8_t *k, - uint32_t ll, - uint8_t *d -) -{ - uint64_t lb = (uint64_t)64U; - if (kk > 0U) - { - update_key(wv, hash, kk, k, ll); - if (!(ll == 0U)) - { - update_blocks(ll, wv, hash, lb, d); - return; - } - return; - } - update_blocks(ll, wv, hash, (uint64_t)0U, d); -} - -void -Hacl_Hash_Blake2s_Simd128_finish( - uint32_t nn, - uint8_t *output, - Lib_IntVector_Intrinsics_vec128 *hash -) -{ - uint8_t b[32U] = { 0U }; - uint8_t *first = b; - uint8_t *second = b + 16U; - Lib_IntVector_Intrinsics_vec128 *row0 = hash; - Lib_IntVector_Intrinsics_vec128 *row1 = hash + 1U; - Lib_IntVector_Intrinsics_vec128_store32_le(first, row0[0U]); - Lib_IntVector_Intrinsics_vec128_store32_le(second, row1[0U]); - uint8_t *final = b; - memcpy(output, final, nn * sizeof (uint8_t)); - Lib_Memzero0_memzero(b, 32U, uint8_t, void *); -} - -void -Hacl_Hash_Blake2s_Simd128_store_state128s_to_state32( - uint32_t *st32, - Lib_IntVector_Intrinsics_vec128 *st -) -{ - Lib_IntVector_Intrinsics_vec128 *r0 = st; - Lib_IntVector_Intrinsics_vec128 *r1 = st + 1U; - Lib_IntVector_Intrinsics_vec128 *r2 = st + 2U; - Lib_IntVector_Intrinsics_vec128 *r3 = st + 3U; - uint32_t *b0 = st32; - uint32_t *b1 = st32 + 4U; - uint32_t *b2 = st32 + 8U; - uint32_t *b3 = st32 + 12U; - uint8_t b8[16U] = { 0U }; - Lib_IntVector_Intrinsics_vec128_store32_le(b8, r0[0U]); - KRML_MAYBE_FOR4(i, - 0U, - 4U, - 1U, - uint32_t *os = b0; - uint8_t *bj = b8 + i * 4U; - uint32_t u = load32_le(bj); - uint32_t r = u; - uint32_t x = r; - os[i] = x;); - uint8_t b80[16U] = { 0U }; - Lib_IntVector_Intrinsics_vec128_store32_le(b80, r1[0U]); - KRML_MAYBE_FOR4(i, - 0U, - 4U, - 1U, - uint32_t *os = b1; - uint8_t *bj = b80 + i * 4U; - uint32_t u = load32_le(bj); - uint32_t r = u; - uint32_t x = r; - os[i] = x;); - uint8_t b81[16U] = { 0U }; - Lib_IntVector_Intrinsics_vec128_store32_le(b81, r2[0U]); - KRML_MAYBE_FOR4(i, - 0U, - 4U, - 1U, - uint32_t *os = b2; - uint8_t *bj = b81 + i * 4U; - uint32_t u = load32_le(bj); - uint32_t r = u; - uint32_t x = r; - os[i] = x;); - uint8_t b82[16U] = { 0U }; - Lib_IntVector_Intrinsics_vec128_store32_le(b82, r3[0U]); - KRML_MAYBE_FOR4(i, - 0U, - 4U, - 1U, - uint32_t *os = b3; - uint8_t *bj = b82 + i * 4U; - uint32_t u = load32_le(bj); - uint32_t r = u; - uint32_t x = r; - os[i] = x;); -} - -void -Hacl_Hash_Blake2s_Simd128_load_state128s_from_state32( - Lib_IntVector_Intrinsics_vec128 *st, - uint32_t *st32 -) -{ - Lib_IntVector_Intrinsics_vec128 *r0 = st; - Lib_IntVector_Intrinsics_vec128 *r1 = st + 1U; - Lib_IntVector_Intrinsics_vec128 *r2 = st + 2U; - Lib_IntVector_Intrinsics_vec128 *r3 = st + 3U; - uint32_t *b0 = st32; - uint32_t *b1 = st32 + 4U; - uint32_t *b2 = st32 + 8U; - uint32_t *b3 = st32 + 12U; - r0[0U] = Lib_IntVector_Intrinsics_vec128_load32s(b0[0U], b0[1U], b0[2U], b0[3U]); - r1[0U] = Lib_IntVector_Intrinsics_vec128_load32s(b1[0U], b1[1U], b1[2U], b1[3U]); - r2[0U] = Lib_IntVector_Intrinsics_vec128_load32s(b2[0U], b2[1U], b2[2U], b2[3U]); - r3[0U] = Lib_IntVector_Intrinsics_vec128_load32s(b3[0U], b3[1U], b3[2U], b3[3U]); -} - -Lib_IntVector_Intrinsics_vec128 *Hacl_Hash_Blake2s_Simd128_malloc_internal_state_with_key(void) -{ - Lib_IntVector_Intrinsics_vec128 - *buf = - (Lib_IntVector_Intrinsics_vec128 *)KRML_ALIGNED_MALLOC(16, - sizeof (Lib_IntVector_Intrinsics_vec128) * 4U); - if (buf != NULL) - { - memset(buf, 0U, 4U * sizeof (Lib_IntVector_Intrinsics_vec128)); - } - return buf; -} - -void -Hacl_Hash_Blake2s_Simd128_update_multi_no_inline( - Lib_IntVector_Intrinsics_vec128 *s, - uint64_t ev, - uint8_t *blocks, - uint32_t n -) -{ - KRML_PRE_ALIGN(16) Lib_IntVector_Intrinsics_vec128 wv[4U] KRML_POST_ALIGN(16) = { 0U }; - Hacl_Hash_Blake2s_Simd128_update_multi(n * 64U, wv, s, ev, blocks, n); -} - -void -Hacl_Hash_Blake2s_Simd128_update_last_no_inline( - Lib_IntVector_Intrinsics_vec128 *s, - uint64_t prev, - uint8_t *input, - uint32_t input_len -) -{ - KRML_PRE_ALIGN(16) Lib_IntVector_Intrinsics_vec128 wv[4U] KRML_POST_ALIGN(16) = { 0U }; - Hacl_Hash_Blake2s_Simd128_update_last(input_len, wv, s, false, prev, input_len, input); -} - -void -Hacl_Hash_Blake2s_Simd128_copy_internal_state( - Lib_IntVector_Intrinsics_vec128 *src, - Lib_IntVector_Intrinsics_vec128 *dst -) -{ - memcpy(dst, src, 4U * sizeof (Lib_IntVector_Intrinsics_vec128)); -} - -typedef struct -option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec128_____Lib_IntVector_Intrinsics_vec128____s -{ - Hacl_Streaming_Types_optional tag; - Hacl_Hash_Blake2s_Simd128_block_state_t v; -} -option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec128_____Lib_IntVector_Intrinsics_vec128___; - -static Hacl_Hash_Blake2s_Simd128_state_t -*malloc_raw(Hacl_Hash_Blake2b_index kk, Hacl_Hash_Blake2b_params_and_key key) -{ - uint8_t *buf = (uint8_t *)KRML_HOST_CALLOC(64U, sizeof (uint8_t)); - if (buf == NULL) - { - return NULL; - } - uint8_t *buf1 = buf; - Lib_IntVector_Intrinsics_vec128 - *wv0 = - (Lib_IntVector_Intrinsics_vec128 *)KRML_ALIGNED_MALLOC(16, - sizeof (Lib_IntVector_Intrinsics_vec128) * 4U); - if (wv0 != NULL) - { - memset(wv0, 0U, 4U * sizeof (Lib_IntVector_Intrinsics_vec128)); - } - option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec128_____Lib_IntVector_Intrinsics_vec128___ - block_state; - if (wv0 == NULL) - { - block_state = - ( - (option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec128_____Lib_IntVector_Intrinsics_vec128___){ - .tag = Hacl_Streaming_Types_None - } - ); - } - else - { - Lib_IntVector_Intrinsics_vec128 - *b = - (Lib_IntVector_Intrinsics_vec128 *)KRML_ALIGNED_MALLOC(16, - sizeof (Lib_IntVector_Intrinsics_vec128) * 4U); - if (b != NULL) - { - memset(b, 0U, 4U * sizeof (Lib_IntVector_Intrinsics_vec128)); - } - if (b == NULL) - { - KRML_ALIGNED_FREE(wv0); - block_state = - ( - (option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec128_____Lib_IntVector_Intrinsics_vec128___){ - .tag = Hacl_Streaming_Types_None - } - ); - } - else - { - block_state = - ( - (option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec128_____Lib_IntVector_Intrinsics_vec128___){ - .tag = Hacl_Streaming_Types_Some, - .v = { - .fst = kk.key_length, - .snd = kk.digest_length, - .thd = kk.last_node, - .f3 = { .fst = wv0, .snd = b } - } - } - ); - } - } - if (block_state.tag == Hacl_Streaming_Types_None) - { - KRML_HOST_FREE(buf1); - return NULL; - } - if (block_state.tag == Hacl_Streaming_Types_Some) - { - Hacl_Hash_Blake2s_Simd128_block_state_t block_state1 = block_state.v; - Hacl_Streaming_Types_optional k_ = Hacl_Streaming_Types_Some; - switch (k_) - { - case Hacl_Streaming_Types_None: - { - return NULL; - } - case Hacl_Streaming_Types_Some: - { - uint8_t kk10 = kk.key_length; - uint32_t ite; - if (kk10 != 0U) - { - ite = 64U; - } - else - { - ite = 0U; - } - Hacl_Hash_Blake2s_Simd128_state_t - s = { .block_state = block_state1, .buf = buf1, .total_len = (uint64_t)ite }; - Hacl_Hash_Blake2s_Simd128_state_t - *p = - (Hacl_Hash_Blake2s_Simd128_state_t *)KRML_HOST_MALLOC(sizeof ( - Hacl_Hash_Blake2s_Simd128_state_t - )); - if (p != NULL) - { - p[0U] = s; - } - if (p == NULL) - { - Lib_IntVector_Intrinsics_vec128 *b = block_state1.f3.snd; - Lib_IntVector_Intrinsics_vec128 *wv = block_state1.f3.fst; - KRML_ALIGNED_FREE(wv); - KRML_ALIGNED_FREE(b); - KRML_HOST_FREE(buf1); - return NULL; - } - Hacl_Hash_Blake2b_blake2_params *p1 = key.fst; - uint8_t kk1 = p1->key_length; - uint8_t nn = p1->digest_length; - bool last_node = block_state1.thd; - Hacl_Hash_Blake2b_index - i = { .key_length = kk1, .digest_length = nn, .last_node = last_node }; - Lib_IntVector_Intrinsics_vec128 *h = block_state1.f3.snd; - uint32_t kk2 = (uint32_t)i.key_length; - uint8_t *k_2 = key.snd; - if (!(kk2 == 0U)) - { - uint8_t *sub_b = buf1 + kk2; - memset(sub_b, 0U, (64U - kk2) * sizeof (uint8_t)); - memcpy(buf1, k_2, kk2 * sizeof (uint8_t)); - } - Hacl_Hash_Blake2b_blake2_params pv = p1[0U]; - uint32_t tmp[8U] = { 0U }; - Lib_IntVector_Intrinsics_vec128 *r0 = h; - Lib_IntVector_Intrinsics_vec128 *r1 = h + 1U; - Lib_IntVector_Intrinsics_vec128 *r2 = h + 2U; - Lib_IntVector_Intrinsics_vec128 *r3 = h + 3U; - uint32_t iv0 = Hacl_Hash_Blake2b_ivTable_S[0U]; - uint32_t iv1 = Hacl_Hash_Blake2b_ivTable_S[1U]; - uint32_t iv2 = Hacl_Hash_Blake2b_ivTable_S[2U]; - uint32_t iv3 = Hacl_Hash_Blake2b_ivTable_S[3U]; - uint32_t iv4 = Hacl_Hash_Blake2b_ivTable_S[4U]; - uint32_t iv5 = Hacl_Hash_Blake2b_ivTable_S[5U]; - uint32_t iv6 = Hacl_Hash_Blake2b_ivTable_S[6U]; - uint32_t iv7 = Hacl_Hash_Blake2b_ivTable_S[7U]; - r2[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv0, iv1, iv2, iv3); - r3[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv4, iv5, iv6, iv7); - KRML_MAYBE_FOR2(i0, - 0U, - 2U, - 1U, - uint32_t *os = tmp + 4U; - uint8_t *bj = pv.salt + i0 * 4U; - uint32_t u = load32_le(bj); - uint32_t r4 = u; - uint32_t x = r4; - os[i0] = x;); - KRML_MAYBE_FOR2(i0, - 0U, - 2U, - 1U, - uint32_t *os = tmp + 6U; - uint8_t *bj = pv.personal + i0 * 4U; - uint32_t u = load32_le(bj); - uint32_t r4 = u; - uint32_t x = r4; - os[i0] = x;); - tmp[0U] = - (uint32_t)pv.digest_length ^ - ((uint32_t)pv.key_length << 8U ^ - ((uint32_t)pv.fanout << 16U ^ (uint32_t)pv.depth << 24U)); - tmp[1U] = pv.leaf_length; - tmp[2U] = (uint32_t)pv.node_offset; - tmp[3U] = - (uint32_t)(pv.node_offset >> 32U) ^ - ((uint32_t)pv.node_depth << 16U ^ (uint32_t)pv.inner_length << 24U); - uint32_t tmp0 = tmp[0U]; - uint32_t tmp1 = tmp[1U]; - uint32_t tmp2 = tmp[2U]; - uint32_t tmp3 = tmp[3U]; - uint32_t tmp4 = tmp[4U]; - uint32_t tmp5 = tmp[5U]; - uint32_t tmp6 = tmp[6U]; - uint32_t tmp7 = tmp[7U]; - uint32_t iv0_ = iv0 ^ tmp0; - uint32_t iv1_ = iv1 ^ tmp1; - uint32_t iv2_ = iv2 ^ tmp2; - uint32_t iv3_ = iv3 ^ tmp3; - uint32_t iv4_ = iv4 ^ tmp4; - uint32_t iv5_ = iv5 ^ tmp5; - uint32_t iv6_ = iv6 ^ tmp6; - uint32_t iv7_ = iv7 ^ tmp7; - r0[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv0_, iv1_, iv2_, iv3_); - r1[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv4_, iv5_, iv6_, iv7_); - return p; - } - default: - { - KRML_HOST_EPRINTF("KaRaMeL incomplete match at %s:%d\n", __FILE__, __LINE__); - KRML_HOST_EXIT(253U); - } - } - } - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); -} - -/** - General-purpose allocation function that gives control over all -Blake2 parameters, including the key. Further resettings of the state SHALL be -done with `reset_with_params_and_key`, and SHALL feature the exact same values -for the `key_length` and `digest_length` fields as passed here. In other words, -once you commit to a digest and key length, the only way to change these -parameters is to allocate a new object. - -The caller must satisfy the following requirements. -- The length of the key k MUST match the value of the field key_length in the - parameters. -- The key_length must not exceed 128 for S, 64 for B. -- The digest_length must not exceed 128 for S, 64 for B. - -*/ -Hacl_Hash_Blake2s_Simd128_state_t -*Hacl_Hash_Blake2s_Simd128_malloc_with_params_and_key( - Hacl_Hash_Blake2b_blake2_params *p, - bool last_node, - uint8_t *k -) -{ - Hacl_Hash_Blake2b_blake2_params pv = p[0U]; - Hacl_Hash_Blake2b_index - i1 = { .key_length = pv.key_length, .digest_length = pv.digest_length, .last_node = last_node }; - return malloc_raw(i1, ((Hacl_Hash_Blake2b_params_and_key){ .fst = p, .snd = k })); -} - -/** - Specialized allocation function that picks default values for all -parameters, except for the key_length. Further resettings of the state SHALL be -done with `reset_with_key`, and SHALL feature the exact same key length `kk` as -passed here. In other words, once you commit to a key length, the only way to -change this parameter is to allocate a new object. - -The caller must satisfy the following requirements. -- The key_length must not exceed 128 for S, 64 for B. - -*/ -Hacl_Hash_Blake2s_Simd128_state_t -*Hacl_Hash_Blake2s_Simd128_malloc_with_key(uint8_t *k, uint8_t kk) -{ - uint8_t nn = 32U; - Hacl_Hash_Blake2b_index i = { .key_length = kk, .digest_length = nn, .last_node = false }; - uint8_t salt[8U] = { 0U }; - uint8_t personal[8U] = { 0U }; - Hacl_Hash_Blake2b_blake2_params - p = - { - .digest_length = i.digest_length, .key_length = i.key_length, .fanout = 1U, .depth = 1U, - .leaf_length = 0U, .node_offset = 0ULL, .node_depth = 0U, .inner_length = 0U, .salt = salt, - .personal = personal - }; - Hacl_Hash_Blake2b_blake2_params p0 = p; - Hacl_Hash_Blake2s_Simd128_state_t - *s = Hacl_Hash_Blake2s_Simd128_malloc_with_params_and_key(&p0, false, k); - return s; -} - -/** - Specialized allocation function that picks default values for all -parameters, and has no key. Effectively, this is what you want if you intend to -use Blake2 as a hash function. Further resettings of the state SHALL be done with `reset`. -*/ -Hacl_Hash_Blake2s_Simd128_state_t *Hacl_Hash_Blake2s_Simd128_malloc(void) -{ - return Hacl_Hash_Blake2s_Simd128_malloc_with_key(NULL, 0U); -} - -static Hacl_Hash_Blake2b_index index_of_state(Hacl_Hash_Blake2s_Simd128_state_t *s) -{ - Hacl_Hash_Blake2s_Simd128_block_state_t block_state = (*s).block_state; - bool last_node = block_state.thd; - uint8_t nn = block_state.snd; - uint8_t kk1 = block_state.fst; - return - ((Hacl_Hash_Blake2b_index){ .key_length = kk1, .digest_length = nn, .last_node = last_node }); -} - -static void -reset_raw(Hacl_Hash_Blake2s_Simd128_state_t *state, Hacl_Hash_Blake2b_params_and_key key) -{ - Hacl_Hash_Blake2s_Simd128_state_t scrut = *state; - uint8_t *buf = scrut.buf; - Hacl_Hash_Blake2s_Simd128_block_state_t block_state = scrut.block_state; - bool last_node0 = block_state.thd; - uint8_t nn0 = block_state.snd; - uint8_t kk10 = block_state.fst; - Hacl_Hash_Blake2b_index - i = { .key_length = kk10, .digest_length = nn0, .last_node = last_node0 }; - KRML_MAYBE_UNUSED_VAR(i); - Hacl_Hash_Blake2b_blake2_params *p = key.fst; - uint8_t kk1 = p->key_length; - uint8_t nn = p->digest_length; - bool last_node = block_state.thd; - Hacl_Hash_Blake2b_index - i1 = { .key_length = kk1, .digest_length = nn, .last_node = last_node }; - Lib_IntVector_Intrinsics_vec128 *h = block_state.f3.snd; - uint32_t kk2 = (uint32_t)i1.key_length; - uint8_t *k_1 = key.snd; - if (!(kk2 == 0U)) - { - uint8_t *sub_b = buf + kk2; - memset(sub_b, 0U, (64U - kk2) * sizeof (uint8_t)); - memcpy(buf, k_1, kk2 * sizeof (uint8_t)); - } - Hacl_Hash_Blake2b_blake2_params pv = p[0U]; - uint32_t tmp[8U] = { 0U }; - Lib_IntVector_Intrinsics_vec128 *r0 = h; - Lib_IntVector_Intrinsics_vec128 *r1 = h + 1U; - Lib_IntVector_Intrinsics_vec128 *r2 = h + 2U; - Lib_IntVector_Intrinsics_vec128 *r3 = h + 3U; - uint32_t iv0 = Hacl_Hash_Blake2b_ivTable_S[0U]; - uint32_t iv1 = Hacl_Hash_Blake2b_ivTable_S[1U]; - uint32_t iv2 = Hacl_Hash_Blake2b_ivTable_S[2U]; - uint32_t iv3 = Hacl_Hash_Blake2b_ivTable_S[3U]; - uint32_t iv4 = Hacl_Hash_Blake2b_ivTable_S[4U]; - uint32_t iv5 = Hacl_Hash_Blake2b_ivTable_S[5U]; - uint32_t iv6 = Hacl_Hash_Blake2b_ivTable_S[6U]; - uint32_t iv7 = Hacl_Hash_Blake2b_ivTable_S[7U]; - r2[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv0, iv1, iv2, iv3); - r3[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv4, iv5, iv6, iv7); - KRML_MAYBE_FOR2(i0, - 0U, - 2U, - 1U, - uint32_t *os = tmp + 4U; - uint8_t *bj = pv.salt + i0 * 4U; - uint32_t u = load32_le(bj); - uint32_t r = u; - uint32_t x = r; - os[i0] = x;); - KRML_MAYBE_FOR2(i0, - 0U, - 2U, - 1U, - uint32_t *os = tmp + 6U; - uint8_t *bj = pv.personal + i0 * 4U; - uint32_t u = load32_le(bj); - uint32_t r = u; - uint32_t x = r; - os[i0] = x;); - tmp[0U] = - (uint32_t)pv.digest_length ^ - ((uint32_t)pv.key_length << 8U ^ ((uint32_t)pv.fanout << 16U ^ (uint32_t)pv.depth << 24U)); - tmp[1U] = pv.leaf_length; - tmp[2U] = (uint32_t)pv.node_offset; - tmp[3U] = - (uint32_t)(pv.node_offset >> 32U) ^ - ((uint32_t)pv.node_depth << 16U ^ (uint32_t)pv.inner_length << 24U); - uint32_t tmp0 = tmp[0U]; - uint32_t tmp1 = tmp[1U]; - uint32_t tmp2 = tmp[2U]; - uint32_t tmp3 = tmp[3U]; - uint32_t tmp4 = tmp[4U]; - uint32_t tmp5 = tmp[5U]; - uint32_t tmp6 = tmp[6U]; - uint32_t tmp7 = tmp[7U]; - uint32_t iv0_ = iv0 ^ tmp0; - uint32_t iv1_ = iv1 ^ tmp1; - uint32_t iv2_ = iv2 ^ tmp2; - uint32_t iv3_ = iv3 ^ tmp3; - uint32_t iv4_ = iv4 ^ tmp4; - uint32_t iv5_ = iv5 ^ tmp5; - uint32_t iv6_ = iv6 ^ tmp6; - uint32_t iv7_ = iv7 ^ tmp7; - r0[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv0_, iv1_, iv2_, iv3_); - r1[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv4_, iv5_, iv6_, iv7_); - uint8_t kk11 = i.key_length; - uint32_t ite; - if (kk11 != 0U) - { - ite = 64U; - } - else - { - ite = 0U; - } - Hacl_Hash_Blake2s_Simd128_state_t - tmp8 = { .block_state = block_state, .buf = buf, .total_len = (uint64_t)ite }; - state[0U] = tmp8; -} - -/** - General-purpose re-initialization function with parameters and -key. You cannot change digest_length, key_length, or last_node, meaning those values in -the parameters object must be the same as originally decided via one of the -malloc functions. All other values of the parameter can be changed. The behavior -is unspecified if you violate this precondition. -*/ -void -Hacl_Hash_Blake2s_Simd128_reset_with_key_and_params( - Hacl_Hash_Blake2s_Simd128_state_t *s, - Hacl_Hash_Blake2b_blake2_params *p, - uint8_t *k -) -{ - Hacl_Hash_Blake2b_index i1 = index_of_state(s); - KRML_MAYBE_UNUSED_VAR(i1); - reset_raw(s, ((Hacl_Hash_Blake2b_params_and_key){ .fst = p, .snd = k })); -} - -/** - Specialized-purpose re-initialization function with no parameters, -and a key. The key length must be the same as originally decided via your choice -of malloc function. All other parameters are reset to their default values. The -original call to malloc MUST have set digest_length to the default value. The -behavior is unspecified if you violate this precondition. -*/ -void Hacl_Hash_Blake2s_Simd128_reset_with_key(Hacl_Hash_Blake2s_Simd128_state_t *s, uint8_t *k) -{ - Hacl_Hash_Blake2b_index idx = index_of_state(s); - uint8_t salt[8U] = { 0U }; - uint8_t personal[8U] = { 0U }; - Hacl_Hash_Blake2b_blake2_params - p = - { - .digest_length = idx.digest_length, .key_length = idx.key_length, .fanout = 1U, .depth = 1U, - .leaf_length = 0U, .node_offset = 0ULL, .node_depth = 0U, .inner_length = 0U, .salt = salt, - .personal = personal - }; - Hacl_Hash_Blake2b_blake2_params p0 = p; - reset_raw(s, ((Hacl_Hash_Blake2b_params_and_key){ .fst = &p0, .snd = k })); -} - -/** - Specialized-purpose re-initialization function with no parameters -and no key. This is what you want if you intend to use Blake2 as a hash -function. The key length and digest length must have been set to their -respective default values via your choice of malloc function (always true if you -used `malloc`). All other parameters are reset to their default values. The -behavior is unspecified if you violate this precondition. -*/ -void Hacl_Hash_Blake2s_Simd128_reset(Hacl_Hash_Blake2s_Simd128_state_t *s) -{ - Hacl_Hash_Blake2s_Simd128_reset_with_key(s, NULL); -} - -/** - Update function; 0 = success, 1 = max length exceeded -*/ -Hacl_Streaming_Types_error_code -Hacl_Hash_Blake2s_Simd128_update( - Hacl_Hash_Blake2s_Simd128_state_t *state, - uint8_t *chunk, - uint32_t chunk_len -) -{ - Hacl_Hash_Blake2s_Simd128_state_t s = *state; - uint64_t total_len = s.total_len; - if ((uint64_t)chunk_len > 0xffffffffffffffffULL - total_len) - { - return Hacl_Streaming_Types_MaximumLengthExceeded; - } - uint32_t sz; - if (total_len % (uint64_t)64U == 0ULL && total_len > 0ULL) - { - sz = 64U; - } - else - { - sz = (uint32_t)(total_len % (uint64_t)64U); - } - if (chunk_len <= 64U - sz) - { - Hacl_Hash_Blake2s_Simd128_state_t s1 = *state; - Hacl_Hash_Blake2s_Simd128_block_state_t block_state1 = s1.block_state; - uint8_t *buf = s1.buf; - uint64_t total_len1 = s1.total_len; - uint32_t sz1; - if (total_len1 % (uint64_t)64U == 0ULL && total_len1 > 0ULL) - { - sz1 = 64U; - } - else - { - sz1 = (uint32_t)(total_len1 % (uint64_t)64U); - } - uint8_t *buf2 = buf + sz1; - memcpy(buf2, chunk, chunk_len * sizeof (uint8_t)); - uint64_t total_len2 = total_len1 + (uint64_t)chunk_len; - *state = - ( - (Hacl_Hash_Blake2s_Simd128_state_t){ - .block_state = block_state1, - .buf = buf, - .total_len = total_len2 - } - ); - } - else if (sz == 0U) - { - Hacl_Hash_Blake2s_Simd128_state_t s1 = *state; - Hacl_Hash_Blake2s_Simd128_block_state_t block_state1 = s1.block_state; - uint8_t *buf = s1.buf; - uint64_t total_len1 = s1.total_len; - uint32_t sz1; - if (total_len1 % (uint64_t)64U == 0ULL && total_len1 > 0ULL) - { - sz1 = 64U; - } - else - { - sz1 = (uint32_t)(total_len1 % (uint64_t)64U); - } - if (!(sz1 == 0U)) - { - uint64_t prevlen = total_len1 - (uint64_t)sz1; - Hacl_Hash_Blake2s_Simd128_two_2s_128 acc = block_state1.f3; - Lib_IntVector_Intrinsics_vec128 *wv = acc.fst; - Lib_IntVector_Intrinsics_vec128 *hash = acc.snd; - uint32_t nb = 1U; - Hacl_Hash_Blake2s_Simd128_update_multi(64U, wv, hash, prevlen, buf, nb); - } - uint32_t ite; - if ((uint64_t)chunk_len % (uint64_t)64U == 0ULL && (uint64_t)chunk_len > 0ULL) - { - ite = 64U; - } - else - { - ite = (uint32_t)((uint64_t)chunk_len % (uint64_t)64U); - } - uint32_t n_blocks = (chunk_len - ite) / 64U; - uint32_t data1_len = n_blocks * 64U; - uint32_t data2_len = chunk_len - data1_len; - uint8_t *data1 = chunk; - uint8_t *data2 = chunk + data1_len; - Hacl_Hash_Blake2s_Simd128_two_2s_128 acc = block_state1.f3; - Lib_IntVector_Intrinsics_vec128 *wv = acc.fst; - Lib_IntVector_Intrinsics_vec128 *hash = acc.snd; - uint32_t nb = data1_len / 64U; - Hacl_Hash_Blake2s_Simd128_update_multi(data1_len, wv, hash, total_len1, data1, nb); - uint8_t *dst = buf; - memcpy(dst, data2, data2_len * sizeof (uint8_t)); - *state = - ( - (Hacl_Hash_Blake2s_Simd128_state_t){ - .block_state = block_state1, - .buf = buf, - .total_len = total_len1 + (uint64_t)chunk_len - } - ); - } - else - { - uint32_t diff = 64U - sz; - uint8_t *chunk1 = chunk; - uint8_t *chunk2 = chunk + diff; - Hacl_Hash_Blake2s_Simd128_state_t s1 = *state; - Hacl_Hash_Blake2s_Simd128_block_state_t block_state10 = s1.block_state; - uint8_t *buf0 = s1.buf; - uint64_t total_len10 = s1.total_len; - uint32_t sz10; - if (total_len10 % (uint64_t)64U == 0ULL && total_len10 > 0ULL) - { - sz10 = 64U; - } - else - { - sz10 = (uint32_t)(total_len10 % (uint64_t)64U); - } - uint8_t *buf2 = buf0 + sz10; - memcpy(buf2, chunk1, diff * sizeof (uint8_t)); - uint64_t total_len2 = total_len10 + (uint64_t)diff; - *state = - ( - (Hacl_Hash_Blake2s_Simd128_state_t){ - .block_state = block_state10, - .buf = buf0, - .total_len = total_len2 - } - ); - Hacl_Hash_Blake2s_Simd128_state_t s10 = *state; - Hacl_Hash_Blake2s_Simd128_block_state_t block_state1 = s10.block_state; - uint8_t *buf = s10.buf; - uint64_t total_len1 = s10.total_len; - uint32_t sz1; - if (total_len1 % (uint64_t)64U == 0ULL && total_len1 > 0ULL) - { - sz1 = 64U; - } - else - { - sz1 = (uint32_t)(total_len1 % (uint64_t)64U); - } - if (!(sz1 == 0U)) - { - uint64_t prevlen = total_len1 - (uint64_t)sz1; - Hacl_Hash_Blake2s_Simd128_two_2s_128 acc = block_state1.f3; - Lib_IntVector_Intrinsics_vec128 *wv = acc.fst; - Lib_IntVector_Intrinsics_vec128 *hash = acc.snd; - uint32_t nb = 1U; - Hacl_Hash_Blake2s_Simd128_update_multi(64U, wv, hash, prevlen, buf, nb); - } - uint32_t ite; - if - ((uint64_t)(chunk_len - diff) % (uint64_t)64U == 0ULL && (uint64_t)(chunk_len - diff) > 0ULL) - { - ite = 64U; - } - else - { - ite = (uint32_t)((uint64_t)(chunk_len - diff) % (uint64_t)64U); - } - uint32_t n_blocks = (chunk_len - diff - ite) / 64U; - uint32_t data1_len = n_blocks * 64U; - uint32_t data2_len = chunk_len - diff - data1_len; - uint8_t *data1 = chunk2; - uint8_t *data2 = chunk2 + data1_len; - Hacl_Hash_Blake2s_Simd128_two_2s_128 acc = block_state1.f3; - Lib_IntVector_Intrinsics_vec128 *wv = acc.fst; - Lib_IntVector_Intrinsics_vec128 *hash = acc.snd; - uint32_t nb = data1_len / 64U; - Hacl_Hash_Blake2s_Simd128_update_multi(data1_len, wv, hash, total_len1, data1, nb); - uint8_t *dst = buf; - memcpy(dst, data2, data2_len * sizeof (uint8_t)); - *state = - ( - (Hacl_Hash_Blake2s_Simd128_state_t){ - .block_state = block_state1, - .buf = buf, - .total_len = total_len1 + (uint64_t)(chunk_len - diff) - } - ); - } - return Hacl_Streaming_Types_Success; -} - -/** - Digest function. This function expects the `output` array to hold -at least `digest_length` bytes, where `digest_length` was determined by your -choice of `malloc` function. Concretely, if you used `malloc` or -`malloc_with_key`, then the expected length is 128 for S, or 64 for B (default -digest length). If you used `malloc_with_params_and_key`, then the expected -length is whatever you chose for the `digest_length` field of your parameters. -For convenience, this function returns `digest_length`. When in doubt, callers -can pass an array of size HACL_BLAKE2S_128_OUT_BYTES, then use the return value -to see how many bytes were actually written. -*/ -uint8_t Hacl_Hash_Blake2s_Simd128_digest(Hacl_Hash_Blake2s_Simd128_state_t *s, uint8_t *dst) -{ - Hacl_Hash_Blake2s_Simd128_block_state_t block_state0 = (*s).block_state; - bool last_node0 = block_state0.thd; - uint8_t nn0 = block_state0.snd; - uint8_t kk0 = block_state0.fst; - Hacl_Hash_Blake2b_index - i1 = { .key_length = kk0, .digest_length = nn0, .last_node = last_node0 }; - Hacl_Hash_Blake2s_Simd128_state_t scrut = *s; - Hacl_Hash_Blake2s_Simd128_block_state_t block_state = scrut.block_state; - uint8_t *buf_ = scrut.buf; - uint64_t total_len = scrut.total_len; - uint32_t r; - if (total_len % (uint64_t)64U == 0ULL && total_len > 0ULL) - { - r = 64U; - } - else - { - r = (uint32_t)(total_len % (uint64_t)64U); - } - uint8_t *buf_1 = buf_; - KRML_PRE_ALIGN(16) Lib_IntVector_Intrinsics_vec128 wv0[4U] KRML_POST_ALIGN(16) = { 0U }; - KRML_PRE_ALIGN(16) Lib_IntVector_Intrinsics_vec128 b[4U] KRML_POST_ALIGN(16) = { 0U }; - Hacl_Hash_Blake2s_Simd128_block_state_t - tmp_block_state = - { - .fst = i1.key_length, - .snd = i1.digest_length, - .thd = i1.last_node, - .f3 = { .fst = wv0, .snd = b } - }; - Lib_IntVector_Intrinsics_vec128 *src_b = block_state.f3.snd; - Lib_IntVector_Intrinsics_vec128 *dst_b = tmp_block_state.f3.snd; - memcpy(dst_b, src_b, 4U * sizeof (Lib_IntVector_Intrinsics_vec128)); - uint64_t prev_len = total_len - (uint64_t)r; - uint32_t ite; - if (r % 64U == 0U && r > 0U) - { - ite = 64U; - } - else - { - ite = r % 64U; - } - uint8_t *buf_last = buf_1 + r - ite; - uint8_t *buf_multi = buf_1; - Hacl_Hash_Blake2s_Simd128_two_2s_128 acc0 = tmp_block_state.f3; - Lib_IntVector_Intrinsics_vec128 *wv1 = acc0.fst; - Lib_IntVector_Intrinsics_vec128 *hash0 = acc0.snd; - uint32_t nb = 0U; - Hacl_Hash_Blake2s_Simd128_update_multi(0U, wv1, hash0, prev_len, buf_multi, nb); - uint64_t prev_len_last = total_len - (uint64_t)r; - Hacl_Hash_Blake2s_Simd128_two_2s_128 acc = tmp_block_state.f3; - bool last_node1 = tmp_block_state.thd; - Lib_IntVector_Intrinsics_vec128 *wv = acc.fst; - Lib_IntVector_Intrinsics_vec128 *hash = acc.snd; - Hacl_Hash_Blake2s_Simd128_update_last(r, wv, hash, last_node1, prev_len_last, r, buf_last); - uint8_t nn1 = tmp_block_state.snd; - Hacl_Hash_Blake2s_Simd128_finish((uint32_t)nn1, dst, tmp_block_state.f3.snd); - Hacl_Hash_Blake2s_Simd128_block_state_t block_state1 = (*s).block_state; - bool last_node = block_state1.thd; - uint8_t nn = block_state1.snd; - uint8_t kk = block_state1.fst; - return - ((Hacl_Hash_Blake2b_index){ .key_length = kk, .digest_length = nn, .last_node = last_node }).digest_length; -} - -Hacl_Hash_Blake2b_index Hacl_Hash_Blake2s_Simd128_info(Hacl_Hash_Blake2s_Simd128_state_t *s) -{ - Hacl_Hash_Blake2s_Simd128_block_state_t block_state = (*s).block_state; - bool last_node = block_state.thd; - uint8_t nn = block_state.snd; - uint8_t kk = block_state.fst; - return - ((Hacl_Hash_Blake2b_index){ .key_length = kk, .digest_length = nn, .last_node = last_node }); -} - -/** - Free state function when there is no key -*/ -void Hacl_Hash_Blake2s_Simd128_free(Hacl_Hash_Blake2s_Simd128_state_t *state) -{ - Hacl_Hash_Blake2s_Simd128_state_t scrut = *state; - uint8_t *buf = scrut.buf; - Hacl_Hash_Blake2s_Simd128_block_state_t block_state = scrut.block_state; - Lib_IntVector_Intrinsics_vec128 *b = block_state.f3.snd; - Lib_IntVector_Intrinsics_vec128 *wv = block_state.f3.fst; - KRML_ALIGNED_FREE(wv); - KRML_ALIGNED_FREE(b); - KRML_HOST_FREE(buf); - KRML_HOST_FREE(state); -} - -/** - Copying. This preserves all parameters. -*/ -Hacl_Hash_Blake2s_Simd128_state_t -*Hacl_Hash_Blake2s_Simd128_copy(Hacl_Hash_Blake2s_Simd128_state_t *state) -{ - Hacl_Hash_Blake2s_Simd128_state_t scrut = *state; - Hacl_Hash_Blake2s_Simd128_block_state_t block_state0 = scrut.block_state; - uint8_t *buf0 = scrut.buf; - uint64_t total_len0 = scrut.total_len; - bool last_node = block_state0.thd; - uint8_t nn = block_state0.snd; - uint8_t kk1 = block_state0.fst; - Hacl_Hash_Blake2b_index i = { .key_length = kk1, .digest_length = nn, .last_node = last_node }; - uint8_t *buf = (uint8_t *)KRML_HOST_CALLOC(64U, sizeof (uint8_t)); - if (buf == NULL) - { - return NULL; - } - memcpy(buf, buf0, 64U * sizeof (uint8_t)); - Lib_IntVector_Intrinsics_vec128 - *wv0 = - (Lib_IntVector_Intrinsics_vec128 *)KRML_ALIGNED_MALLOC(16, - sizeof (Lib_IntVector_Intrinsics_vec128) * 4U); - if (wv0 != NULL) - { - memset(wv0, 0U, 4U * sizeof (Lib_IntVector_Intrinsics_vec128)); - } - option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec128_____Lib_IntVector_Intrinsics_vec128___ - block_state; - if (wv0 == NULL) - { - block_state = - ( - (option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec128_____Lib_IntVector_Intrinsics_vec128___){ - .tag = Hacl_Streaming_Types_None - } - ); - } - else - { - Lib_IntVector_Intrinsics_vec128 - *b = - (Lib_IntVector_Intrinsics_vec128 *)KRML_ALIGNED_MALLOC(16, - sizeof (Lib_IntVector_Intrinsics_vec128) * 4U); - if (b != NULL) - { - memset(b, 0U, 4U * sizeof (Lib_IntVector_Intrinsics_vec128)); - } - if (b == NULL) - { - KRML_ALIGNED_FREE(wv0); - block_state = - ( - (option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec128_____Lib_IntVector_Intrinsics_vec128___){ - .tag = Hacl_Streaming_Types_None - } - ); - } - else - { - block_state = - ( - (option___uint8_t___uint8_t___bool_____Lib_IntVector_Intrinsics_vec128_____Lib_IntVector_Intrinsics_vec128___){ - .tag = Hacl_Streaming_Types_Some, - .v = { - .fst = i.key_length, - .snd = i.digest_length, - .thd = i.last_node, - .f3 = { .fst = wv0, .snd = b } - } - } - ); - } - } - if (block_state.tag == Hacl_Streaming_Types_None) - { - KRML_HOST_FREE(buf); - return NULL; - } - if (block_state.tag == Hacl_Streaming_Types_Some) - { - Hacl_Hash_Blake2s_Simd128_block_state_t block_state1 = block_state.v; - Lib_IntVector_Intrinsics_vec128 *src_b = block_state0.f3.snd; - Lib_IntVector_Intrinsics_vec128 *dst_b = block_state1.f3.snd; - memcpy(dst_b, src_b, 4U * sizeof (Lib_IntVector_Intrinsics_vec128)); - Hacl_Streaming_Types_optional k_ = Hacl_Streaming_Types_Some; - switch (k_) - { - case Hacl_Streaming_Types_None: - { - return NULL; - } - case Hacl_Streaming_Types_Some: - { - Hacl_Hash_Blake2s_Simd128_state_t - s = { .block_state = block_state1, .buf = buf, .total_len = total_len0 }; - Hacl_Hash_Blake2s_Simd128_state_t - *p = - (Hacl_Hash_Blake2s_Simd128_state_t *)KRML_HOST_MALLOC(sizeof ( - Hacl_Hash_Blake2s_Simd128_state_t - )); - if (p != NULL) - { - p[0U] = s; - } - if (p == NULL) - { - Lib_IntVector_Intrinsics_vec128 *b = block_state1.f3.snd; - Lib_IntVector_Intrinsics_vec128 *wv = block_state1.f3.fst; - KRML_ALIGNED_FREE(wv); - KRML_ALIGNED_FREE(b); - KRML_HOST_FREE(buf); - return NULL; - } - return p; - } - default: - { - KRML_HOST_EPRINTF("KaRaMeL incomplete match at %s:%d\n", __FILE__, __LINE__); - KRML_HOST_EXIT(253U); - } - } - } - KRML_HOST_EPRINTF("KaRaMeL abort at %s:%d\n%s\n", - __FILE__, - __LINE__, - "unreachable (pattern matches are exhaustive in F*)"); - KRML_HOST_EXIT(255U); -} - -/** -Write the BLAKE2s digest of message `input` using key `key` into `output`. - -@param output Pointer to `output_len` bytes of memory where the digest is written to. -@param output_len Length of the to-be-generated digest with 1 <= `output_len` <= 64. -@param input Pointer to `input_len` bytes of memory where the input message is read from. -@param input_len Length of the input message. -@param key Pointer to `key_len` bytes of memory where the key is read from. -@param key_len Length of the key. Can be 0. -*/ -void -Hacl_Hash_Blake2s_Simd128_hash_with_key( - uint8_t *output, - uint32_t output_len, - uint8_t *input, - uint32_t input_len, - uint8_t *key, - uint32_t key_len -) -{ - KRML_PRE_ALIGN(16) Lib_IntVector_Intrinsics_vec128 b[4U] KRML_POST_ALIGN(16) = { 0U }; - KRML_PRE_ALIGN(16) Lib_IntVector_Intrinsics_vec128 b1[4U] KRML_POST_ALIGN(16) = { 0U }; - Hacl_Hash_Blake2s_Simd128_init(b, key_len, output_len); - update(b1, b, key_len, key, input_len, input); - Hacl_Hash_Blake2s_Simd128_finish(output_len, output, b); - Lib_Memzero0_memzero(b1, 4U, Lib_IntVector_Intrinsics_vec128, void *); - Lib_Memzero0_memzero(b, 4U, Lib_IntVector_Intrinsics_vec128, void *); -} - -/** -Write the BLAKE2s digest of message `input` using key `key` and -parameters `params` into `output`. The `key` array must be of length -`params.key_length`. The `output` array must be of length -`params.digest_length`. -*/ -void -Hacl_Hash_Blake2s_Simd128_hash_with_key_and_params( - uint8_t *output, - uint8_t *input, - uint32_t input_len, - Hacl_Hash_Blake2b_blake2_params params, - uint8_t *key -) -{ - KRML_PRE_ALIGN(16) Lib_IntVector_Intrinsics_vec128 b[4U] KRML_POST_ALIGN(16) = { 0U }; - KRML_PRE_ALIGN(16) Lib_IntVector_Intrinsics_vec128 b1[4U] KRML_POST_ALIGN(16) = { 0U }; - uint32_t tmp[8U] = { 0U }; - Lib_IntVector_Intrinsics_vec128 *r0 = b; - Lib_IntVector_Intrinsics_vec128 *r1 = b + 1U; - Lib_IntVector_Intrinsics_vec128 *r2 = b + 2U; - Lib_IntVector_Intrinsics_vec128 *r3 = b + 3U; - uint32_t iv0 = Hacl_Hash_Blake2b_ivTable_S[0U]; - uint32_t iv1 = Hacl_Hash_Blake2b_ivTable_S[1U]; - uint32_t iv2 = Hacl_Hash_Blake2b_ivTable_S[2U]; - uint32_t iv3 = Hacl_Hash_Blake2b_ivTable_S[3U]; - uint32_t iv4 = Hacl_Hash_Blake2b_ivTable_S[4U]; - uint32_t iv5 = Hacl_Hash_Blake2b_ivTable_S[5U]; - uint32_t iv6 = Hacl_Hash_Blake2b_ivTable_S[6U]; - uint32_t iv7 = Hacl_Hash_Blake2b_ivTable_S[7U]; - r2[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv0, iv1, iv2, iv3); - r3[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv4, iv5, iv6, iv7); - KRML_MAYBE_FOR2(i, - 0U, - 2U, - 1U, - uint32_t *os = tmp + 4U; - uint8_t *bj = params.salt + i * 4U; - uint32_t u = load32_le(bj); - uint32_t r = u; - uint32_t x = r; - os[i] = x;); - KRML_MAYBE_FOR2(i, - 0U, - 2U, - 1U, - uint32_t *os = tmp + 6U; - uint8_t *bj = params.personal + i * 4U; - uint32_t u = load32_le(bj); - uint32_t r = u; - uint32_t x = r; - os[i] = x;); - tmp[0U] = - (uint32_t)params.digest_length ^ - ((uint32_t)params.key_length << 8U ^ - ((uint32_t)params.fanout << 16U ^ (uint32_t)params.depth << 24U)); - tmp[1U] = params.leaf_length; - tmp[2U] = (uint32_t)params.node_offset; - tmp[3U] = - (uint32_t)(params.node_offset >> 32U) ^ - ((uint32_t)params.node_depth << 16U ^ (uint32_t)params.inner_length << 24U); - uint32_t tmp0 = tmp[0U]; - uint32_t tmp1 = tmp[1U]; - uint32_t tmp2 = tmp[2U]; - uint32_t tmp3 = tmp[3U]; - uint32_t tmp4 = tmp[4U]; - uint32_t tmp5 = tmp[5U]; - uint32_t tmp6 = tmp[6U]; - uint32_t tmp7 = tmp[7U]; - uint32_t iv0_ = iv0 ^ tmp0; - uint32_t iv1_ = iv1 ^ tmp1; - uint32_t iv2_ = iv2 ^ tmp2; - uint32_t iv3_ = iv3 ^ tmp3; - uint32_t iv4_ = iv4 ^ tmp4; - uint32_t iv5_ = iv5 ^ tmp5; - uint32_t iv6_ = iv6 ^ tmp6; - uint32_t iv7_ = iv7 ^ tmp7; - r0[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv0_, iv1_, iv2_, iv3_); - r1[0U] = Lib_IntVector_Intrinsics_vec128_load32s(iv4_, iv5_, iv6_, iv7_); - update(b1, b, (uint32_t)params.key_length, key, input_len, input); - Hacl_Hash_Blake2s_Simd128_finish((uint32_t)params.digest_length, output, b); - Lib_Memzero0_memzero(b1, 4U, Lib_IntVector_Intrinsics_vec128, void *); - Lib_Memzero0_memzero(b, 4U, Lib_IntVector_Intrinsics_vec128, void *); -} - diff --git a/Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.c b/Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.c deleted file mode 100644 index 951306db494833a..000000000000000 --- a/Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.c +++ /dev/null @@ -1,14 +0,0 @@ -// This file isn't part of a standard HACL source tree. -// -// It is required for compatibility with universal2 macOS builds. The code in -// Hacl_Hash_Blake2s_Simd128.c will compile on macOS ARM64, but performance -// isn't great, so it's disabled. However, because universal2 builds are -// compiled in a single pass, autoconf detects that the required compiler -// features *are* available, and tries to include this file. -// -// To compensate for this, autoconf will include *this* file instead of -// Hacl_Hash_Blake2s_Simd128.c when compiling for universal. This allows the -// underlying source code of HACL to remain unmodified. -#if !(defined(__APPLE__) && defined(__arm64__)) -#include "Hacl_Hash_Blake2s_Simd128.c" -#endif diff --git a/Modules/_hacl/refresh.sh b/Modules/_hacl/refresh.sh index c73bd4ee90f4c55..7b9a72179d7fdf1 100755 --- a/Modules/_hacl/refresh.sh +++ b/Modules/_hacl/refresh.sh @@ -38,6 +38,11 @@ fi # Step 1: copy files +# The SIMD implementations of BLAKE-2 (Hacl_Hash_Blake2b_Simd256.c and +# Hacl_Hash_Blake2s_Simd128.c) are not vendored. Their headers are kept +# because Hacl_Streaming_HMAC.c includes them unconditionally; the SIMD +# code paths of Hacl_Streaming_HMAC.c are not compiled since neither +# HACL_CAN_COMPILE_VEC128 nor HACL_CAN_COMPILE_VEC256 is defined. declare -a dist_files dist_files=( Hacl_Streaming_Types.h @@ -74,8 +79,6 @@ dist_files=( Hacl_Hash_SHA3.c Hacl_Hash_Blake2b.c Hacl_Hash_Blake2s.c - Hacl_Hash_Blake2b_Simd256.c - Hacl_Hash_Blake2s_Simd128.c # Cryptographic Primitives (sources) Hacl_HMAC.c Hacl_Streaming_HMAC.c diff --git a/Modules/blake2module.c b/Modules/blake2module.c index 551ebd7cd052af9..517c439f4e8032b 100644 --- a/Modules/blake2module.c +++ b/Modules/blake2module.c @@ -19,52 +19,11 @@ #include "pycore_moduleobject.h" #include "pycore_object.h" // _PyObject_VisitType() #include "pycore_strhex.h" // _Py_strhex() -#include "pycore_typeobject.h" - -// QUICK CPU AUTODETECTION -// -// See https://github.com/python/cpython/pull/119316 -- we only enable -// vectorized versions for Intel CPUs, even though HACL*'s "vec128" modules also -// run on ARM NEON. (We could enable them on POWER -- but I don't have access to -// a test machine to see if that speeds anything up.) -// -// Note that configure.ac and the rest of the build are written in such a way -// that if the configure script finds suitable flags to compile HACL's SIMD128 -// (resp. SIMD256) files, then Hacl_Hash_Blake2b_Simd128.c (resp. ...) will be -// pulled into the build automatically, and then only the CPU autodetection will -// need to be updated here. - -#if defined(__x86_64__) && defined(__GNUC__) -#include -#elif defined(_M_X64) -#include -#endif #include -// SIMD256 can't be compiled on macOS ARM64, and performance of SIMD128 isn't -// great; but when compiling a universal2 binary, autoconf will set -// _Py_HACL_CAN_COMPILE_VEC{128,256} because they *can* be compiled on x86_64. -// If we're on macOS ARM64, we however disable these preprocessor symbols. -#if defined(__APPLE__) && defined(__arm64__) -# undef _Py_HACL_CAN_COMPILE_VEC128 -# undef _Py_HACL_CAN_COMPILE_VEC256 -#endif - -// HACL* expects HACL_CAN_COMPILE_VEC* macros to be set in order to enable -// the corresponding SIMD instructions so we need to "forward" the values -// we just deduced above. -#define HACL_CAN_COMPILE_VEC128 _Py_HACL_CAN_COMPILE_VEC128 -#define HACL_CAN_COMPILE_VEC256 _Py_HACL_CAN_COMPILE_VEC256 - #include "_hacl/Hacl_Hash_Blake2s.h" #include "_hacl/Hacl_Hash_Blake2b.h" -#if _Py_HACL_CAN_COMPILE_VEC128 -#include "_hacl/Hacl_Hash_Blake2s_Simd128.h" -#endif -#if _Py_HACL_CAN_COMPILE_VEC256 -#include "_hacl/Hacl_Hash_Blake2b_Simd256.h" -#endif // MODULE TYPE SLOTS @@ -77,8 +36,6 @@ PyDoc_STRVAR(blake2mod__doc__, typedef struct { PyTypeObject *blake2b_type; PyTypeObject *blake2s_type; - bool can_run_simd128; - bool can_run_simd256; } Blake2State; static inline Blake2State * @@ -89,16 +46,6 @@ blake2_get_state(PyObject *module) return (Blake2State *)state; } -#if defined(_Py_HACL_CAN_COMPILE_VEC128) || defined(_Py_HACL_CAN_COMPILE_VEC256) -static inline Blake2State * -blake2_get_state_from_type(PyTypeObject *module) -{ - void *state = _PyType_GetModuleState(module); - assert(state != NULL); - return (Blake2State *)state; -} -#endif - static struct PyMethodDef blake2mod_functions[] = { {NULL, NULL} }; @@ -127,87 +74,10 @@ _blake2_free(void *module) (void)_blake2_clear((PyObject *)module); } -static void -blake2module_init_cpu_features(Blake2State *state) -{ - /* This must be kept in sync with hmacmodule_init_cpu_features() - * in hmacmodule.c */ - int eax1 = 0, ebx1 = 0, ecx1 = 0, edx1 = 0; - int eax7 = 0, ebx7 = 0, ecx7 = 0, edx7 = 0; -#if defined(__x86_64__) && defined(__GNUC__) - __cpuid_count(1, 0, eax1, ebx1, ecx1, edx1); - __cpuid_count(7, 0, eax7, ebx7, ecx7, edx7); -#elif defined(_M_X64) - int info1[4] = {0}; - __cpuidex(info1, 1, 0); - eax1 = info1[0], ebx1 = info1[1], ecx1 = info1[2], edx1 = info1[3]; - - int info7[4] = {0}; - __cpuidex(info7, 7, 0); - eax7 = info7[0], ebx7 = info7[1], ecx7 = info7[2], edx7 = info7[3]; -#endif - // fmt: off - (void)eax1; (void)ebx1; (void)ecx1; (void)edx1; - (void)eax7; (void)ebx7; (void)ecx7; (void)edx7; - // fmt: on - -#define EBX_AVX2 (1 << 5) -#define ECX_SSE3 (1 << 0) -#define ECX_SSSE3 (1 << 9) -#define ECX_SSE4_1 (1 << 19) -#define ECX_SSE4_2 (1 << 20) -#define ECX_AVX (1 << 28) -#define EDX_SSE (1 << 25) -#define EDX_SSE2 (1 << 26) -#define EDX_CMOV (1 << 15) - - bool avx = (ecx1 & ECX_AVX) != 0; - bool avx2 = (ebx7 & EBX_AVX2) != 0; - - bool sse = (edx1 & EDX_SSE) != 0; - bool sse2 = (edx1 & EDX_SSE2) != 0; - bool cmov = (edx1 & EDX_CMOV) != 0; - - bool sse3 = (ecx1 & ECX_SSE3) != 0; - bool sse41 = (ecx1 & ECX_SSE4_1) != 0; - bool sse42 = (ecx1 & ECX_SSE4_2) != 0; - -#undef EDX_CMOV -#undef EDX_SSE2 -#undef EDX_SSE -#undef ECX_AVX -#undef ECX_SSE4_2 -#undef ECX_SSE4_1 -#undef ECX_SSSE3 -#undef ECX_SSE3 -#undef EBX_AVX2 - -#if _Py_HACL_CAN_COMPILE_VEC128 - // TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection - state->can_run_simd128 = sse && sse2 && sse3 && sse41 && sse42 && cmov; -#else - // fmt: off - (void)sse; (void)sse2; (void)sse3; (void)sse41; (void)sse42; (void)cmov; - // fmt: on - state->can_run_simd128 = false; -#endif - -#if _Py_HACL_CAN_COMPILE_VEC256 - // TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection - state->can_run_simd256 = state->can_run_simd128 && avx && avx2; -#else - // fmt: off - (void)avx; (void)avx2; - // fmt: on - state->can_run_simd256 = false; -#endif -} - static int blake2_exec(PyObject *m) { Blake2State *st = blake2_get_state(m); - blake2module_init_cpu_features(st); #define ADD_INT(DICT, NAME, VALUE) \ do { \ @@ -313,43 +183,28 @@ PyInit__blake2(void) // correctly dispatch. Note that the previous incarnation of this code // transformed the Blake2b implementation into the Blake2s one using a script, // so this is an improvement. -// -// The 128 and 256 versions are only available if i) we were able to compile -// them, and ii) if the CPU we run on also happens to have the right instruction -// set. -typedef enum { Blake2s, Blake2b, Blake2s_128, Blake2b_256 } blake2_impl; +typedef enum { Blake2s, Blake2b } blake2_impl; static inline bool is_blake2b(blake2_impl impl) { - return impl == Blake2b || impl == Blake2b_256; + return impl == Blake2b; } static inline bool is_blake2s(blake2_impl impl) { - return impl == Blake2s || impl == Blake2s_128; + return impl == Blake2s; } static inline blake2_impl type_to_impl(PyTypeObject *type) { -#if defined(_Py_HACL_CAN_COMPILE_VEC128) || defined(_Py_HACL_CAN_COMPILE_VEC256) - Blake2State *st = blake2_get_state_from_type(type); -#endif if (!strcmp(type->tp_name, blake2b_type_spec.name)) { -#if _Py_HACL_CAN_COMPILE_VEC256 - return st->can_run_simd256 ? Blake2b_256 : Blake2b; -#else return Blake2b; -#endif } else if (!strcmp(type->tp_name, blake2s_type_spec.name)) { -#if _Py_HACL_CAN_COMPILE_VEC128 - return st->can_run_simd128 ? Blake2s_128 : Blake2s; -#else return Blake2s; -#endif } Py_UNREACHABLE(); } @@ -359,12 +214,6 @@ typedef struct { union { Hacl_Hash_Blake2s_state_t *blake2s_state; Hacl_Hash_Blake2b_state_t *blake2b_state; -#if _Py_HACL_CAN_COMPILE_VEC128 - Hacl_Hash_Blake2s_Simd128_state_t *blake2s_128_state; -#endif -#if _Py_HACL_CAN_COMPILE_VEC256 - Hacl_Hash_Blake2b_Simd256_state_t *blake2b_256_state; -#endif }; blake2_impl impl; } Blake2Object; @@ -396,16 +245,6 @@ new_Blake2Object(PyTypeObject *type) // Ensure that the states are NULL-initialized in case of an error. // See: py_blake2_clear() for more details. switch (self->impl) { -#if _Py_HACL_CAN_COMPILE_VEC256 - case Blake2b_256: - self->blake2b_256_state = NULL; - break; -#endif -#if _Py_HACL_CAN_COMPILE_VEC128 - case Blake2s_128: - self->blake2s_128_state = NULL; - break; -#endif case Blake2b: self->blake2b_state = NULL; break; @@ -452,20 +291,6 @@ static void blake2_update_unlocked(Blake2Object *self, uint8_t *buf, Py_ssize_t len) { switch (self->impl) { - // blake2b_256_state and blake2s_128_state must be if'd since - // otherwise this results in an unresolved symbol at link-time. -#if _Py_HACL_CAN_COMPILE_VEC256 - case Blake2b_256: - HACL_UPDATE(Hacl_Hash_Blake2b_Simd256_update, - self->blake2b_256_state, buf, len); - return; -#endif -#if _Py_HACL_CAN_COMPILE_VEC128 - case Blake2s_128: - HACL_UPDATE(Hacl_Hash_Blake2s_Simd128_update, - self->blake2s_128_state, buf, len); - return; -#endif case Blake2b: HACL_UPDATE(Hacl_Hash_Blake2b_update, self->blake2b_state, buf, len); @@ -624,16 +449,6 @@ py_blake2_new(PyTypeObject *type, PyObject *data, int digest_size, } while (0) switch (self->impl) { -#if _Py_HACL_CAN_COMPILE_VEC256 - case Blake2b_256: - BLAKE2_MALLOC(Blake2b_Simd256, self->blake2b_256_state); - break; -#endif -#if _Py_HACL_CAN_COMPILE_VEC128 - case Blake2s_128: - BLAKE2_MALLOC(Blake2s_Simd128, self->blake2s_128_state); - break; -#endif case Blake2b: BLAKE2_MALLOC(Blake2b, self->blake2b_state); break; @@ -761,16 +576,6 @@ blake2_blake2b_copy_unlocked(Blake2Object *self, Blake2Object *cpy) cpy->impl = self->impl; switch (self->impl) { -#if _Py_HACL_CAN_COMPILE_VEC256 - case Blake2b_256: - BLAKE2_COPY(Blake2b_Simd256, blake2b_256_state); - break; -#endif -#if _Py_HACL_CAN_COMPILE_VEC128 - case Blake2s_128: - BLAKE2_COPY(Blake2s_Simd128, blake2s_128_state); - break; -#endif case Blake2b: BLAKE2_COPY(Blake2b, blake2b_state); break; @@ -844,16 +649,6 @@ static uint8_t blake2_blake2b_compute_digest(Blake2Object *self, uint8_t *digest) { switch (self->impl) { -#if _Py_HACL_CAN_COMPILE_VEC256 - case Blake2b_256: - return Hacl_Hash_Blake2b_Simd256_digest( - self->blake2b_256_state, digest); -#endif -#if _Py_HACL_CAN_COMPILE_VEC128 - case Blake2s_128: - return Hacl_Hash_Blake2s_Simd128_digest( - self->blake2s_128_state, digest); -#endif case Blake2b: return Hacl_Hash_Blake2b_digest(self->blake2b_state, digest); case Blake2s: @@ -927,14 +722,6 @@ static Hacl_Hash_Blake2b_index hacl_get_blake2_info(Blake2Object *self) { switch (self->impl) { -#if _Py_HACL_CAN_COMPILE_VEC256 - case Blake2b_256: - return Hacl_Hash_Blake2b_Simd256_info(self->blake2b_256_state); -#endif -#if _Py_HACL_CAN_COMPILE_VEC128 - case Blake2s_128: - return Hacl_Hash_Blake2s_Simd128_info(self->blake2s_128_state); -#endif case Blake2b: return Hacl_Hash_Blake2b_info(self->blake2b_state); case Blake2s: @@ -981,16 +768,6 @@ py_blake2_clear(PyObject *op) } while (0) switch (self->impl) { -#if _Py_HACL_CAN_COMPILE_VEC256 - case Blake2b_256: - BLAKE2_FREE(Blake2b_Simd256, self->blake2b_256_state); - break; -#endif -#if _Py_HACL_CAN_COMPILE_VEC128 - case Blake2s_128: - BLAKE2_FREE(Blake2s_Simd128, self->blake2s_128_state); - break; -#endif case Blake2b: BLAKE2_FREE(Blake2b, self->blake2b_state); break; diff --git a/Modules/hmacmodule.c b/Modules/hmacmodule.c index a76a7056e494437..099e0f27eecd635 100644 --- a/Modules/hmacmodule.c +++ b/Modules/hmacmodule.c @@ -20,27 +20,6 @@ #include "pycore_hashtable.h" #include "pycore_strhex.h" // _Py_strhex() -/* - * Taken from blake2module.c. In the future, detection of SIMD support - * should be delegated to https://github.com/python/cpython/pull/125011. - */ -#if defined(__x86_64__) && defined(__GNUC__) -# include -#elif defined(_M_X64) -# include -#endif - -#if defined(__APPLE__) && defined(__arm64__) -# undef _Py_HACL_CAN_COMPILE_VEC128 -# undef _Py_HACL_CAN_COMPILE_VEC256 -#endif - -// HACL* expects HACL_CAN_COMPILE_VEC* macros to be set in order to enable -// the corresponding SIMD instructions so we need to "forward" the values -// we just deduced above. -#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 @@ -173,9 +152,6 @@ typedef enum HMAC_Hash_Kind { /* Blake family */ DECL_HACL_HMAC_HASH_KIND(blake2s_32, Blake2S_32) DECL_HACL_HMAC_HASH_KIND(blake2b_32, Blake2B_32) - /* Blake runtime family (should not be used statically) */ - DECL_HACL_HMAC_HASH_KIND(vectorized_blake2s_32, Blake2S_128) - DECL_HACL_HMAC_HASH_KIND(vectorized_blake2b_32, Blake2B_256) #undef DECL_HACL_HMAC_HASH_KIND } HMAC_Hash_Kind; @@ -258,9 +234,6 @@ typedef struct hmacmodule_state { PyTypeObject *hmac_type; /* interned strings */ PyObject *str_lower; - - bool can_run_simd128; - bool can_run_simd256; } hmacmodule_state; static inline hmacmodule_state * @@ -316,25 +289,14 @@ class _hmac.HMAC "HMACObject *" "clinic_state()->hmac_type" /* * Assert that a HMAC hash kind is a static kind. * - * A "static" kind is specified in the 'py_hmac_static_hinfo' - * table and is always independent of the host CPUID features. + * A "static" kind is specified in the 'py_hmac_static_hinfo' table. */ #ifndef NDEBUG static void assert_is_static_hmac_hash_kind(HMAC_Hash_Kind kind) { - switch (kind) { - case Py_hmac_kind_hash_unknown: { - Py_FatalError("HMAC hash kind must be a known kind"); - return; - } - case Py_hmac_kind_hmac_vectorized_blake2s_32: - case Py_hmac_kind_hmac_vectorized_blake2b_32: { - Py_FatalError("HMAC hash kind must not be a vectorized kind"); - return; - } - default: - return; + if (kind == Py_hmac_kind_hash_unknown) { + Py_FatalError("HMAC hash kind must be a known kind"); } } #else @@ -342,38 +304,6 @@ static inline void assert_is_static_hmac_hash_kind(HMAC_Hash_Kind Py_UNUSED(kind)) {} #endif -/* - * Convert a HMAC hash static kind into a runtime kind. - * - * A "runtime" kind is derived from a static kind and depends - * on the host CPUID features. In particular, this is the kind - * that a HMAC object internally stores. - */ -static HMAC_Hash_Kind -narrow_hmac_hash_kind(hmacmodule_state *state, HMAC_Hash_Kind kind) -{ - switch (kind) { - case Py_hmac_kind_hmac_blake2s_32: { -#if _Py_HACL_CAN_COMPILE_VEC128 - if (state->can_run_simd128) { - return Py_hmac_kind_hmac_vectorized_blake2s_32; - } -#endif - return kind; - } - case Py_hmac_kind_hmac_blake2b_32: { -#if _Py_HACL_CAN_COMPILE_VEC256 - if (state->can_run_simd256) { - return Py_hmac_kind_hmac_vectorized_blake2b_32; - } -#endif - return kind; - } - default: - return kind; - } -} - /* * Handle the HACL* exit code. * @@ -682,18 +612,14 @@ hmac_new_object(PyTypeObject *tp) /* * Use the HMAC information 'info' to populate the corresponding fields. - * - * The real 'kind' for BLAKE-2 is obtained once and depends on both static - * capabilities (supported compiler flags) and runtime CPUID features. */ static void -hmac_set_hinfo(hmacmodule_state *state, - HMACObject *self, const py_hmac_hinfo *info) +hmac_set_hinfo(HMACObject *self, const py_hmac_hinfo *info) { assert(info->display_name != NULL); Py_XSETREF(self->name, Py_NewRef(info->display_name)); assert_is_static_hmac_hash_kind(info->kind); - self->kind = narrow_hmac_hash_kind(state, info->kind); + self->kind = info->kind; assert(info->block_size <= Py_hmac_hash_max_block_size); self->block_size = info->block_size; assert(info->digest_size <= Py_hmac_hash_max_digest_size); @@ -764,7 +690,7 @@ _hmac_new_impl(PyObject *module, PyObject *keyobj, PyObject *msgobj, if (self == NULL) { return NULL; } - hmac_set_hinfo(state, self, info); + hmac_set_hinfo(self, info); int rc; // Create the HACL* internal state with the given key. Py_buffer key; @@ -1432,9 +1358,6 @@ py_hmac_hinfo_ht_new(void) * The real kind of a HMAC object is obtained only once and is * derived from the kind of the 'py_hmac_hinfo' that could be * found by its name. - * - * Since 'vectorized_blake2{s,b}_32' depend on the runtime CPUID - * features, we should not create 'py_hmac_hinfo' entries for them. */ assert_is_static_hmac_hash_kind(e->kind); @@ -1557,80 +1480,6 @@ hmacmodule_init_globals(PyObject *module, hmacmodule_state *state) return 0; } -static void -hmacmodule_init_cpu_features(hmacmodule_state *state) -{ - int eax1 = 0, ebx1 = 0, ecx1 = 0, edx1 = 0; - int eax7 = 0, ebx7 = 0, ecx7 = 0, edx7 = 0; -#if defined(__x86_64__) && defined(__GNUC__) - __cpuid_count(1, 0, eax1, ebx1, ecx1, edx1); - __cpuid_count(7, 0, eax7, ebx7, ecx7, edx7); -#elif defined(_M_X64) - int info1[4] = {0}; - __cpuidex(info1, 1, 0); - eax1 = info1[0], ebx1 = info1[1], ecx1 = info1[2], edx1 = info1[3]; - - int info7[4] = {0}; - __cpuidex(info7, 7, 0); - eax7 = info7[0], ebx7 = info7[1], ecx7 = info7[2], edx7 = info7[3]; -#endif - // fmt: off - (void)eax1; (void)ebx1; (void)ecx1; (void)edx1; - (void)eax7; (void)ebx7; (void)ecx7; (void)edx7; - // fmt: on - -#define EBX_AVX2 (1 << 5) -#define ECX_SSE3 (1 << 0) -#define ECX_SSSE3 (1 << 9) -#define ECX_SSE4_1 (1 << 19) -#define ECX_SSE4_2 (1 << 20) -#define ECX_AVX (1 << 28) -#define EDX_SSE (1 << 25) -#define EDX_SSE2 (1 << 26) -#define EDX_CMOV (1 << 15) - - bool avx = (ecx1 & ECX_AVX) != 0; - bool avx2 = (ebx7 & EBX_AVX2) != 0; - - bool sse = (edx1 & EDX_SSE) != 0; - bool sse2 = (edx1 & EDX_SSE2) != 0; - bool cmov = (edx1 & EDX_CMOV) != 0; - - bool sse3 = (ecx1 & ECX_SSE3) != 0; - bool sse41 = (ecx1 & ECX_SSE4_1) != 0; - bool sse42 = (ecx1 & ECX_SSE4_2) != 0; - -#undef EDX_CMOV -#undef EDX_SSE2 -#undef EDX_SSE -#undef ECX_AVX -#undef ECX_SSE4_2 -#undef ECX_SSE4_1 -#undef ECX_SSSE3 -#undef ECX_SSE3 -#undef EBX_AVX2 - -#if _Py_HACL_CAN_COMPILE_VEC128 - // TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection - state->can_run_simd128 = sse && sse2 && sse3 && sse41 && sse42 && cmov; -#else - // fmt: off - (void)sse; (void)sse2; (void)sse3; (void)sse41; (void)sse42; (void)cmov; - // fmt: on - state->can_run_simd128 = false; -#endif - -#if _Py_HACL_CAN_COMPILE_VEC256 - // TODO(picnixz): use py_cpuid_features (gh-125022) to improve detection - state->can_run_simd256 = state->can_run_simd128 && avx && avx2; -#else - // fmt: off - (void)avx; (void)avx2; - // fmt: on - state->can_run_simd256 = false; -#endif -} - static int hmacmodule_exec(PyObject *module) { @@ -1650,7 +1499,6 @@ hmacmodule_exec(PyObject *module) if (hmacmodule_init_globals(module, state) < 0) { return -1; } - hmacmodule_init_cpu_features(state); return 0; } diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 51d18739d7c93fd..1efcc1a3b311550 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -441,14 +441,7 @@ - - - _Py_HACL_CAN_COMPILE_VEC128;%(PreprocessorDefinitions) - - - _Py_HACL_CAN_COMPILE_VEC256;%(PreprocessorDefinitions) - - + @@ -462,14 +455,6 @@ - - HACL_CAN_COMPILE_VEC256;%(PreprocessorDefinitions) - /arch:AVX2 %(AdditionalOptions) - - - HACL_CAN_COMPILE_VEC128;%(PreprocessorDefinitions) - /arch:AVX %(AdditionalOptions) - diff --git a/configure b/configure index 81af3fa0402a20f..5cfb8c9d705d8b4 100755 --- a/configure +++ b/configure @@ -724,10 +724,6 @@ MODULE__SHA1_TRUE MODULE__MD5_FALSE MODULE__MD5_TRUE LIBHACL_LDEPS_LIBTYPE -LIBHACL_BLAKE2_SIMD256_OBJS -LIBHACL_SIMD256_FLAGS -LIBHACL_BLAKE2_SIMD128_OBJS -LIBHACL_SIMD128_FLAGS LIBHACL_LDFLAGS LIBHACL_CFLAGS MODULE_UNICODEDATA_FALSE @@ -37406,163 +37402,6 @@ LIBHACL_CFLAGS="${LIBHACL_FLAG_I} ${LIBHACL_FLAG_D} \$(PY_STDMODULE_CFLAGS) \$(C LIBHACL_LDFLAGS= # for now, no specific linker flags are needed - -if test "$UNIVERSAL_ARCHS" = "universal2" -o \ - \( "$build_cpu" = "aarch64" -a "$build_vendor" = "apple" \) -then - use_hacl_universal2_impl=yes -else - use_hacl_universal2_impl=no -fi - -# The SIMD files use aligned_alloc, which is not available on older versions of -# Android. -# The *mmintrin.h headers are x86-family-specific, so can't be used on WASI. -if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \ - { test -n "$ANDROID_API_LEVEL" && test "$ANDROID_API_LEVEL" -ge 28; } -then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -msse -msse2 -msse3 -msse4.1 -msse4.2" >&5 -printf %s "checking whether C compiler accepts -msse -msse2 -msse3 -msse4.1 -msse4.2... " >&6; } -if test ${ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2+y} -then : - printf %s "(cached) " >&6 -else case e in #( - e) - ax_check_save_flags=$CFLAGS - CFLAGS="$CFLAGS -Werror -msse -msse2 -msse3 -msse4.1 -msse4.2" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main (void) -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO" -then : - ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2=yes -else case e in #( - e) ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2=no ;; -esac -fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext - CFLAGS=$ax_check_save_flags ;; -esac -fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2" >&5 -printf "%s\n" "$ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2" >&6; } -if test "x$ax_cv_check_cflags__Werror__msse__msse2__msse3__msse4_1__msse4_2" = xyes -then : - - LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2" - - -printf "%s\n" "#define _Py_HACL_CAN_COMPILE_VEC128 1" >>confdefs.h - - - # macOS universal2 builds *support* the -msse etc flags because they're - # available on x86_64. However, performance of the HACL SIMD128 implementation - # isn't great, so it's disabled on ARM64. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for HACL* SIMD128 implementation" >&5 -printf %s "checking for HACL* SIMD128 implementation... " >&6; } - if test "$use_hacl_universal2_impl" = "yes"; then - LIBHACL_BLAKE2_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: universal2" >&5 -printf "%s\n" "universal2" >&6; } - else - LIBHACL_BLAKE2_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: standard" >&5 -printf "%s\n" "standard" >&6; } - fi - - -else case e in #( - e) : ;; -esac -fi - -fi - - - -# The SIMD files use aligned_alloc, which is not available on older versions of -# Android. -# The *mmintrin.h headers are x86-family-specific, so can't be used on WASI. -# -# Although AVX support is not guaranteed on Android -# (https://developer.android.com/ndk/guides/abis#86-64), this is safe because we do a -# runtime CPUID check. -if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \ - { test -n "$ANDROID_API_LEVEL" && test "$ANDROID_API_LEVEL" -ge 28; } -then - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -mavx2" >&5 -printf %s "checking whether C compiler accepts -mavx2... " >&6; } -if test ${ax_cv_check_cflags__Werror__mavx2+y} -then : - printf %s "(cached) " >&6 -else case e in #( - e) - ax_check_save_flags=$CFLAGS - CFLAGS="$CFLAGS -Werror -mavx2" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main (void) -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO" -then : - ax_cv_check_cflags__Werror__mavx2=yes -else case e in #( - e) ax_cv_check_cflags__Werror__mavx2=no ;; -esac -fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext - CFLAGS=$ax_check_save_flags ;; -esac -fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags__Werror__mavx2" >&5 -printf "%s\n" "$ax_cv_check_cflags__Werror__mavx2" >&6; } -if test "x$ax_cv_check_cflags__Werror__mavx2" = xyes -then : - - LIBHACL_SIMD256_FLAGS="-mavx2" - -printf "%s\n" "#define _Py_HACL_CAN_COMPILE_VEC256 1" >>confdefs.h - - - # macOS universal2 builds *support* the -mavx2 compiler flag because it's - # available on x86_64; but the HACL SIMD256 build then fails because the - # implementation requires symbols that aren't available on ARM64. Use a - # wrapped implementation if we're building for universal2. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for HACL* SIMD256 implementation" >&5 -printf %s "checking for HACL* SIMD256 implementation... " >&6; } - if test "$use_hacl_universal2_impl" = "yes"; then - LIBHACL_BLAKE2_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: universal2" >&5 -printf "%s\n" "universal2" >&6; } - else - LIBHACL_BLAKE2_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o" - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: standard" >&5 -printf "%s\n" "standard" >&6; } - fi - -else case e in #( - e) : ;; -esac -fi - -fi - - ### end(HACL* configuration) ############################################################################### diff --git a/configure.ac b/configure.ac index a55276ed5e6e8f8..ecc0f1b39f73a3a 100644 --- a/configure.ac +++ b/configure.ac @@ -8699,77 +8699,6 @@ LIBHACL_CFLAGS="${LIBHACL_FLAG_I} ${LIBHACL_FLAG_D} \$(PY_STDMODULE_CFLAGS) \$(C AC_SUBST([LIBHACL_CFLAGS]) LIBHACL_LDFLAGS= # for now, no specific linker flags are needed AC_SUBST([LIBHACL_LDFLAGS]) - -dnl Check if universal2 HACL* implementation should be used. -if test "$UNIVERSAL_ARCHS" = "universal2" -o \ - \( "$build_cpu" = "aarch64" -a "$build_vendor" = "apple" \) -then - use_hacl_universal2_impl=yes -else - use_hacl_universal2_impl=no -fi - -# The SIMD files use aligned_alloc, which is not available on older versions of -# Android. -# The *mmintrin.h headers are x86-family-specific, so can't be used on WASI. -if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \ - { test -n "$ANDROID_API_LEVEL" && test "$ANDROID_API_LEVEL" -ge 28; } -then - dnl This can be extended here to detect e.g. Power8, which HACL* should also support. - AX_CHECK_COMPILE_FLAG([-msse -msse2 -msse3 -msse4.1 -msse4.2],[ - [LIBHACL_SIMD128_FLAGS="-msse -msse2 -msse3 -msse4.1 -msse4.2"] - - AC_DEFINE([_Py_HACL_CAN_COMPILE_VEC128], [1], [ - HACL* library can compile SIMD128 implementations]) - - # macOS universal2 builds *support* the -msse etc flags because they're - # available on x86_64. However, performance of the HACL SIMD128 implementation - # isn't great, so it's disabled on ARM64. - AC_MSG_CHECKING([for HACL* SIMD128 implementation]) - if test "$use_hacl_universal2_impl" = "yes"; then - [LIBHACL_BLAKE2_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128_universal2.o"] - AC_MSG_RESULT([universal2]) - else - [LIBHACL_BLAKE2_SIMD128_OBJS="Modules/_hacl/Hacl_Hash_Blake2s_Simd128.o"] - AC_MSG_RESULT([standard]) - fi - - ], [], [-Werror]) -fi -AC_SUBST([LIBHACL_SIMD128_FLAGS]) -AC_SUBST([LIBHACL_BLAKE2_SIMD128_OBJS]) - -# The SIMD files use aligned_alloc, which is not available on older versions of -# Android. -# The *mmintrin.h headers are x86-family-specific, so can't be used on WASI. -# -# Although AVX support is not guaranteed on Android -# (https://developer.android.com/ndk/guides/abis#86-64), this is safe because we do a -# runtime CPUID check. -if test "$ac_sys_system" != "Linux-android" -a "$ac_sys_system" != "WASI" || \ - { test -n "$ANDROID_API_LEVEL" && test "$ANDROID_API_LEVEL" -ge 28; } -then - AX_CHECK_COMPILE_FLAG([-mavx2],[ - [LIBHACL_SIMD256_FLAGS="-mavx2"] - AC_DEFINE([_Py_HACL_CAN_COMPILE_VEC256], [1], [ - HACL* library can compile SIMD256 implementations]) - - # macOS universal2 builds *support* the -mavx2 compiler flag because it's - # available on x86_64; but the HACL SIMD256 build then fails because the - # implementation requires symbols that aren't available on ARM64. Use a - # wrapped implementation if we're building for universal2. - AC_MSG_CHECKING([for HACL* SIMD256 implementation]) - if test "$use_hacl_universal2_impl" = "yes"; then - [LIBHACL_BLAKE2_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256_universal2.o"] - AC_MSG_RESULT([universal2]) - else - [LIBHACL_BLAKE2_SIMD256_OBJS="Modules/_hacl/Hacl_Hash_Blake2b_Simd256.o"] - AC_MSG_RESULT([standard]) - fi - ], [], [-Werror]) -fi -AC_SUBST([LIBHACL_SIMD256_FLAGS]) -AC_SUBST([LIBHACL_BLAKE2_SIMD256_OBJS]) ### end(HACL* configuration) ############################################################################### diff --git a/pyconfig.h.in b/pyconfig.h.in index 0c8c7989a95f972..c8d5279c43d9a7f 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -2176,12 +2176,6 @@ /* Defined if _Complex C type can be used with libffi. */ #undef _Py_FFI_SUPPORT_C_COMPLEX -/* HACL* library can compile SIMD128 implementations */ -#undef _Py_HACL_CAN_COMPILE_VEC128 - -/* HACL* library can compile SIMD256 implementations */ -#undef _Py_HACL_CAN_COMPILE_VEC256 - /* Define if you have the 'acospi' function. */ #undef _Py_HAVE_ACOSPI