【问题标题】:Python 3.9.8, hashlib and RIPEMD160Python 3.9.8、hashlib 和 RIPEMD160
【发布时间】:2021-12-23 14:21:25
【问题描述】:

运行 MacOS 10.14.6。刚刚运行 MacPorts 更新。使用 Python 3.9.7 -> 3.9.8 和 OpenSSL 1.1.3 -> 3。

运行现有的 Python 代码显示 hashlib 出现了问题,并且 RIPEMD160 不再可用(Whirlpool 和可能的其他摘要也不可用)。

Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/hashlib.py", line 160, in __hash_new
    return _hashlib.new(name, data, **kwargs)
ValueError: [digital envelope routines] initialization error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "testhash.py", line 3, in <module>
    r160 = hashlib.new('ripemd160')
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/hashlib.py", line 166, in __hash_new
    return __get_builtin_constructor(name)(data)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/hashlib.py", line 123, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type ripemd160

可以简单地复制

import hashlib
r160 = hashlib.new('ripemd160')

方法hashlib.algorithms_available 表明hashlib 认为ripemd160 可用的:

Available:  {'sha512', 'shake_128', 'ripemd160', 'sha224', 'md5', 'whirlpool', 'blake2b', 'sha3_512', 'md4', 'sha3_256', 'sha256', 'shake_256', 'md5-sha1', 'sha1', 'sha512_224', 'sm3', 'mdc2', 'blake2s', 'sha3_384', 'sha3_224', 'sha512_256', 'sha384'} 
Guaranteed: {'sha3_512', 'sha512', 'sha1', 'shake_128', 'sha3_384', 'sha224', 'md5', 'sha256', 'sha3_224', 'sha3_256', 'shake_256', 'blake2b', 'blake2s', 'sha384'} 

并询问openssl 确认它确实具有该功能。

回滚,同样的问题。我宁愿保持最新的安装。 RIPEMD160 的使用不可协商。

我怀疑为ports 提供正确的开关、命令、环境变量会说服重新编译工作,但我不知道是什么。

关于发生了什么,如何解决的任何想法?

【问题讨论】:

  • 不知道为什么 openssl 确认它的可用性,但 RIPEMD160 自 OpenSSL 3.0 以来已被弃用:openssl.org/docs/manmaster/man3/RIPEMD160.html
  • 这是我的理解。不过,准确地说,openssl 报告了rmd160,我认为它是 RIPEMD160。
  • 您确定您正在执行与您的 Python 链接的正确 openssl 吗? MacOS 带有 LibreSSL,它别名为 openssl,这有点令人困惑。 openssl version 说什么?
  • 你是对的。版本和特定库存在一些混淆。
  • 我看到其他人大声抱怨在 OpenSSL 中弃用 RIPEMD,因为它的广泛使用。是否有库可以使 RIPEMD 保持打开状态?

标签: python-3.x openssl macports hashlib


【解决方案1】:

一个不太理想的临时解决方案是:

  1. 回滚 OpenSSL
port activate openssl @1.1_3
  1. 删除 Python 的安装(必要时回滚到以前的版本后)
port uninstall python39
port clean python39
  1. 重新编译 Python
port install -s -f python39

【讨论】:

  • 回滚 openssl 到 1.1.1 为我解决了类似的问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多