How can I get scrypt working with python3?

458 Views Asked by At

I have an embedded system with linux and python3. I just upgraded everything, so I have new versions of the linux kernel, openssl, and python (now 3.9). But python's access to the scrypt algorithm (which I believe is handled through openssl) seems to have broken.

The code trying to access scrypt looks like this:

kdf = Scrypt(salt, UserManager.__hash_len, self.__n, UserManager.__r, UserManager.__p, self.backend)
return kdf.derive(password.encode('utf-8'))

And it gives an exception:

  File "/usr/lib/python3.9/site-packages/cryptography/hazmat/primitives/kdf/scrypt.py", line 32, in __init__
    raise UnsupportedAlgorithm(
cryptography.exceptions.UnsupportedAlgorithm: Backend object does not implement ScryptBackend.

I've also tried the hashlib implementation:

root@intel-corei7-64:~# python3 -c "from hashlib import scrypt"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'scrypt' from 'hashlib' (/usr/lib/python3.9/hashlib.py)

This is despite running a very new version of openssl:

root@intel-corei7-64:~# openssl version
OpenSSL 1.1.1l  24 Aug 2021

How does python know about openssl? How does it find it? How does it call it? Maybe it's just not linking up correctly somehow? Does anyone have any ideas about this?

Edit:

I managed to prove it's talking to openssl, so now I'm even more confused about what is going wrong with scrypt:

>>> from cryptography.hazmat.backends import default_backend
>>> default_backend().openssl_version_text()
'OpenSSL 1.1.1l  24 Aug 2021'

Edit:

I can't get this working. I ended up using python3-scrypt and that works fine.

0

There are 0 best solutions below