Python hashlib and libopenssl

I am currently running a python3.9 app in a TP-Link RE200v3 which attemps to import hashlib but I get this exception messages:

ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/usr/gauchomesh/external/hashlib.py", line 238, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/gauchomesh/external/hashlib.py", line 108, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
  File "/usr/gauchomesh/external/hashlib.py", line 238, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/gauchomesh/external/hashlib.py", line 108, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha1
ERROR:root:code for hash sha224 was not found.
Traceback (most recent call last):
  File "/usr/gauchomesh/external/hashlib.py", line 238, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/gauchomesh/external/hashlib.py", line 108, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha224
ERROR:root:code for hash sha256 was not found.
Traceback (most recent call last):
  File "/usr/gauchomesh/external/hashlib.py", line 238, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/gauchomesh/external/hashlib.py", line 108, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha256
ERROR:root:code for hash blake2b was not found.
Traceback (most recent call last):
  File "/usr/gauchomesh/external/hashlib.py", line 238, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/gauchomesh/external/hashlib.py", line 108, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type blake2b
ERROR:root:code for hash blake2s was not found.
Traceback (most recent call last):
  File "/usr/gauchomesh/external/hashlib.py", line 238, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/gauchomesh/external/hashlib.py", line 108, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type blake2s
ERROR:root:code for hash sha3_224 was not found.
Traceback (most recent call last):
  File "/usr/gauchomesh/external/hashlib.py", line 238, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/gauchomesh/external/hashlib.py", line 108, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha3_224
ERROR:root:code for hash sha3_256 was not found.
Traceback (most recent call last):
  File "/usr/gauchomesh/external/hashlib.py", line 238, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/gauchomesh/external/hashlib.py", line 108, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha3_256
ERROR:root:code for hash sha3_384 was not found.
Traceback (most recent call last):
  File "/usr/gauchomesh/external/hashlib.py", line 238, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/gauchomesh/external/hashlib.py", line 108, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha3_384
ERROR:root:code for hash sha3_512 was not found.
Traceback (most recent call last):
  File "/usr/gauchomesh/external/hashlib.py", line 238, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/gauchomesh/external/hashlib.py", line 108, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha3_512
ERROR:root:code for hash shake_128 was not found.
Traceback (most recent call last):
  File "/usr/gauchomesh/external/hashlib.py", line 238, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/gauchomesh/external/hashlib.py", line 108, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type shake_128
ERROR:root:code for hash shake_256 was not found.
Traceback (most recent call last):
  File "/usr/gauchomesh/external/hashlib.py", line 238, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/gauchomesh/external/hashlib.py", line 108, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type shake_256

So the obvious situation seems to go about this module searching system libraries which seems to not be installed. I have found that probably installing libopenssl (opkg install libopenssl1.1) can fix the problem. But the new problem by doing that is libopenssl is way too heavy to install in small flash devices. Also I noticed that another devices (like Archer C7v5) do not have this issue, but they seems to do not have libopenssl installed too, so there should be another best effective way to fix this.

So, in short, I want to find the specific component I need to include to make this work.

Any comment or advice will be well received.

Thanks in advance!

You may be able to use pure Python implementations of any specific hashes you need rather than relying on hashlib, such as Pysha2, however:

  • you'll probably need to do modify your code; and
  • performance may be a problem.

An alternative approach might be to see whether you can build Python for your device with one of the other SSL libraries (e.g. WolfSSL) provided that such libraries provide the routines hashlib requires.

1 Like

Thank you, at the moment I didn't find another library which can solve the issue. But I am almost sure that there are something.

As i just needed sha256 and the software do not use this often I have solved via de "pure python" way.

Here is what I have used https://gist.github.com/prokls/41e82472bd4968720d1482f81235e0ac

BUT I needed to add this method to the class in order to work well with hmac.py:

    def copy(self):

        return copy.deepcopy(self) # added to fix usage with hmac.py

Thanks for your assistance! Solved.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.