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

Use Cryptodome.cipher instead of Crypto.cipher #169

Open
gandalth opened this issue Feb 10, 2024 · 4 comments
Open

Use Cryptodome.cipher instead of Crypto.cipher #169

gandalth opened this issue Feb 10, 2024 · 4 comments

Comments

@gandalth
Copy link

gandalth commented Feb 10, 2024

I am a new user of NSZ v4.6 on Linux (Debian Testing).

In order to run NSZ, I need to make this change in nsz/nsz/nut/aes128.py:

-from Crypto.Cipher import AES
-from Crypto.Util import Counter

+from Cryptodome.Cipher import AES
+from Cryptodome.Util import Counter

I suggest pulling this change into the sources.

@nicoboss
Copy link
Owner

For me only from Crypto.Cipher import AES and from Crypto.Util import Counter works while your succestion does not:

>>> from Cryptodome.Cipher import AES
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'Cryptodome'

Are you sure you have pycryptodome installed? If not please execute pip install pycryptodome What version Python and pycryptodome have you installed? With Debian Testing I assume you mean Debian 12 with the SID repository. I only test NSZ on LTS versions of popular Linux Distributions so if something in SID changed it's quite likely you are the first that would notice. I will install a Debian SID VM and try to reproduce this next weekend.

@gandalth
Copy link
Author

I am using Debian Testing, which is different from Sid. The codename for testing is currently trixie. Testing is not as bleeding-edge as Sid is. Example: Sid already has the 6.7-series kernel, whereas Testing currently has 6.6. Stable is still on 6.1.

I do have pycryptodome installed. Whenever I can, I use Debian's package system instead of pip. I only use pip if I have to, e.g. if I desperately need a newer version of a package. But with Debian Testing being very much up to date, that almost never happens.

Here's a quick summary of my config:

Python version: Python 3.11.7 (main, Dec 8 2023, 14:22:46) [GCC 13.2.0] on linux
Installed version of pycrptodome: ii python3-pycryptodome 3.11.0+dfsg1-4 amd64 cryptographic Python libra

Here's a snippet of dpkg's file listing for the installed package:

dpkg -L python3-pycryptodome
..
/usr/lib/python3/dist-packages/Cryptodome/Cipher
/usr/lib/python3/dist-packages/Cryptodome/Cipher/AES.py
/usr/lib/python3/dist-packages/Cryptodome/Cipher/AES.pyi
/usr/lib/python3/dist-packages/Cryptodome/Cipher/ARC2.py
..

As all files are placed in the subfolder Cryptodome, it seems quite natural to me, that I need to call the package accordingly. Maybe pip places these files differently?

@nicoboss
Copy link
Owner

I just did some testing regarding this issue. I was able to reproduce it on latest Debian Testing. The issue seems to have to do with the difference how apt and pip are installing PyCryptodome. If the dependencies are installed using apt I'm experiencing the same issue but when I create a venv and use pip to install them everything works as expected. To solve this, I conserver using try/except to first try importing from Crypto and fallback on trying to import from Cryptodome if that fails and so correctly handle booth cases. Thanks a lot for reporting this. I don’t think I would ever have discovered this myself.

@gandalth
Copy link
Author

Much appreciated! It is me who has to thank you for this great tool!

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

No branches or pull requests

2 participants