Closed trofi closed 1 year ago
The following hack makes tests pass on avx2 system:
--- a/cbits/decaf/include/constant_time.h
+++ b/cbits/decaf/include/constant_time.h
@@ -150,7 +150,7 @@ constant_time_lookup (
for (j=0; j<n_table; j++, big_i-=big_one) {
big_register_t br_mask = br_is_zero(big_i);
for (k=0; k<=elem_bytes-sizeof(big_register_t); k+=sizeof(big_register_t)) {
- if (elem_bytes % sizeof(big_register_t)) {
+ if (1) {
/* unaligned */
((unaligned_br_t *)(out+k))->unaligned
|= br_mask & ((const unaligned_br_t*)(&table[k+j*elem_bytes]))->unaligned;
Likely related to modifications I did that rely on the fact that AVX2 is not enabled. See here: https://github.com/haskell-crypto/cryptonite/blob/8698c9fd940403f39387291a377aefc4bb1f1d7d/cbits/decaf/tools/generate.sh#L25
Feel free to revisit the compatibility requirements.
Aha,
- aligned(32) attributes used for stack alignment are replaced by aligned(16). This removes warnings on OpenBSD with GCC 4.2.1, and makes sure we get at least 16-byte alignment. 32-byte alignment is necessary only for AVX2 and arch_x86_64, which we don't have.
makes it effectively incompatible with clients who pass -m*
options to C compiler to leverage ISA extensions if compiler manages to find the code patterns where those could be used.
In my case --ghc-option=-optc-march=znver3
allows gcc using AVX2
and relies on according alignment to be present.
My suggestion would be to never relax aligned(32)
down to aligned(16)
to preserve correctness.
Just stumbled upon this, too.
Noticed unaligned stores in
cryptonite-0.29
testsuite:Looking at the details it's the store path that is unaligned (code seems to check only table load part):