Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

pycryptodome-3.15.0 fails test test_negate (Crypto.SelfTest.PublicKey.test_ECC_25519.TestEccPoint_Ed25519) #653

Closed
PPed72 opened this issue Jul 26, 2022 · 6 comments

Comments

@PPed72
Copy link

PPed72 commented Jul 26, 2022

Originally reported in Gentoo Linux Bugzilla: https://bugs.gentoo.org/861206

======================================================================
FAIL: test_negate (Crypto.SelfTest.PublicKey.test_ECC_25519.TestEccPoint_Ed25519)

Traceback (most recent call last):
File "/var/tmp/portage/dev-python/pycryptodome-3.15.0/work/pycryptodome-3.15.0-python3_10/install/usr/lib/python3.10/site-packages/Crypto/SelfTest/PublicKey/test_ECC_25519.py", line 114, in test_negate
self.failUnless(sum.is_point_at_infinity())
AssertionError: False is not true


Ran 7213 tests in 28.050s

FAILED (failures=1)
Traceback (most recent call last):
File "", line 3, in
File "/var/tmp/portage/dev-python/pycryptodome-3.15.0/work/pycryptodome-3.15.0-python3_10/install/usr/lib/python3.10/site-packages/Crypto/SelfTest/init.py", line 77, in run
raise SelfTestError("Self-test failed", result)
Crypto.SelfTest.SelfTestError: ('Self-test failed', <unittest.runner.TextTestResult run=7213 errors=0 failures=1>)

  • ERROR: dev-python/pycryptodome-3.15.0::gentoo failed (test phase):
  • (no error message)
@ivan
Copy link

ivan commented Sep 25, 2022

I saw this on NixOS master as well after compiling everything with -march=haswell -mtune=haswell / gcc 11.3.0. I tried to reproduce on Debian 11.5 (gcc (Debian 10.2.1-6) 10.2.1 20210110) by compiling just Python 3.10.7 and pycryptodome with -march=haswell -mtune=haswell, but I could not; the tests passed.

@ivan
Copy link

ivan commented Sep 26, 2022

Oh, -march=haswell with gcc 11.3.0 does cause this test to fail; here are some repro instructions for Debian sid / unstable:

apt update
apt install wget ca-certificates git build-essential gcc-11 libssl-dev zlib1g-dev libbz2-dev libsqlite3-dev libxml2-dev libxslt1-dev libreadline-dev libffi-dev pkg-config

non-root:

wget https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer
chmod +x pyenv-installer
./pyenv-installer
CC=gcc-11 CFLAGS="-march=haswell -mtune=haswell" ~/.pyenv/bin/pyenv install 3.10.7

git clone https://github.com/Legrandin/pycryptodome
cd pycryptodome
CC=gcc-11 CFLAGS="-march=haswell -mtune=haswell" ~/.pyenv/versions/3.10.7/bin/python3 setup.py test

I observe:

....................................................................................................................................................................................
======================================================================
FAIL: test_negate (Crypto.SelfTest.PublicKey.test_ECC_25519.TestEccPoint_Ed25519)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/at/pycryptodome/build/lib.linux-x86_64-cpython-310/Crypto/SelfTest/PublicKey/test_ECC_25519.py", line 114, in test_negate
    self.failUnless(sum.is_point_at_infinity())
AssertionError: False is not true

----------------------------------------------------------------------
Ran 3501 tests in 31.933s

FAILED (failures=1)
Traceback (most recent call last):
  File "/home/at/pycryptodome/setup.py", line 498, in <module>
    setup(
  File "/home/at/.pyenv/versions/3.10.7/lib/python3.10/site-packages/setuptools/__init__.py", line 87, in setup
    return distutils.core.setup(**attrs)
  File "/home/at/.pyenv/versions/3.10.7/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 177, in setup
    return run_commands(dist)
  File "/home/at/.pyenv/versions/3.10.7/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 193, in run_commands
    dist.run_commands()
  File "/home/at/.pyenv/versions/3.10.7/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 968, in run_commands
    self.run_command(cmd)
  File "/home/at/.pyenv/versions/3.10.7/lib/python3.10/site-packages/setuptools/dist.py", line 1217, in run_command
    super().run_command(command)
  File "/home/at/.pyenv/versions/3.10.7/lib/python3.10/site-packages/setuptools/_distutils/dist.py", line 987, in run_command
    cmd_obj.run()
  File "/home/at/pycryptodome/setup.py", line 189, in run
    SelfTest.run(module=moduleObj, verbosity=self.verbose, stream=sys.stdout, config=self.config)
  File "/home/at/pycryptodome/build/lib.linux-x86_64-cpython-310/Crypto/SelfTest/__init__.py", line 77, in run
    raise SelfTestError("Self-test failed", result)
Crypto.SelfTest.SelfTestError: ('Self-test failed', <unittest.runner.TextTestResult run=3501 errors=0 failures=1>)
# gcc-11 --version
gcc-11 (Debian 11.3.0-6) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@SuperSandro2000
Copy link

I saw this on NixOS master as well after compiling everything with -march=haswell -mtune=haswell / gcc 11.3.0. I tried to reproduce on Debian 11.5 (gcc (Debian 10.2.1-6) 10.2.1 20210110) by compiling just Python 3.10.7 and pycryptodome with -march=haswell -mtune=haswell, but I could not; the tests passed.

I encountered the same with march skylake.

@Legrandin
Copy link
Owner

I can confirm I can reproduce it with the combination described by @ivan.

It looks like a compiler bug because the issue disappears if I mark add_25519() with __attribute__((noinline)). However, that is not an acceptable workaround... It also disappears by using uint32_t instead of uint64_t in add_25519() which is an overdue optimization that should have been done in any case, so that it what 1c043ab (also) does.

@SuperSandro2000
Copy link

The patch fixes my problem.

@Legrandin
Copy link
Owner

Fixed in v3.17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants