Skip to content

ChaCha and incorrect result when using AVX2 #1069

Description

@noloader

Reported on the mailing list at Flipped bit in chacha encrypted file, avx vs sse. The following test script produces different results pivoting around AVX2. The test data file run_459_file_76.bin is significant.

#!/usr/bin/env bash

make distclean &>/dev/null

CXXFLAGS="-DNDEBUG -g2 -O3 -std=c++17" make -j 5

wget -O main.cxx --quiet https://raw.githubusercontent.com/austin-clifton/cryptopp-chacha-asm-test/main/src/main.cpp

wget -O run_459_file_76.bin --quiet https://github.com/austin-clifton/cryptopp-chacha-asm-test/blob/main/run/run_459_file_76.bin?raw=true

sed -i 's/cryptopp\///g' main.cxx

g++ -DNDEBUG -g2 -O3 -std=c++17 -I. main.cxx ./libcryptopp.a -o main.exe

./main.exe

Here are the results from several different machines. I believe the C++ and SSE2 one 8F16077454F8477594CAD4304126B0A6F30C8C4D2536E2441FFFD320656E1DF1 is correct. The AVX2 one is incorrect.

Core i7-8700 (Intel, AVX2, no SHA):
sha256: 0FC0FADCDF82770086C9DA8513A16FC785620D7B1C187CDD828E433EB0979847
encsha: 6FBEE484EE64A2AB02235DDF29CA0B61EE3B811D227C2729836D3BD6161C9B18

Celeron J3455 (Intel, no AVX, SHA):
sha256: 0FC0FADCDF82770086C9DA8513A16FC785620D7B1C187CDD828E433EB0979847
encsha: 8F16077454F8477594CAD4304126B0A6F30C8C4D2536E2441FFFD320656E1DF1

Ryzen 3 3300U (AMD, AVX2, SHA)
sha256: 0FC0FADCDF82770086C9DA8513A16FC785620D7B1C187CDD828E433EB0979847
encsha: 6FBEE484EE64A2AB02235DDF29CA0B61EE3B811D227C2729836D3BD6161C9B18

CRYPTOPP_DISABLE_ASM:
sha256: 0FC0FADCDF82770086C9DA8513A16FC785620D7B1C187CDD828E433EB0979847
encsha: 8F16077454F8477594CAD4304126B0A6F30C8C4D2536E2441FFFD320656E1DF1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions