【发布时间】:2016-07-12 09:07:13
【问题描述】:
今天在浏览 Python HMAC 模块源代码时,发现其中包含全局变量_secret_backdoor_key。然后检查该变量以中断对象初始化。
代码如下所示
# A unique object passed by HMAC.copy() to the HMAC constructor, in order
# that the latter return very quickly. HMAC("") in contrast is quite
# expensive.
_secret_backdoor_key = []
class HMAC:
"""RFC 2104 HMAC class. Also complies with RFC 4231.
This supports the API for Cryptographic Hash Functions (PEP 247).
"""
blocksize = 64 # 512-bit HMAC; can be changed in subclasses.
def __init__(self, key, msg = None, digestmod = None):
"""Create a new HMAC object.
key: key for the keyed hash object.
msg: Initial input for the hash, if provided.
digestmod: A module supporting PEP 247. *OR*
A hashlib constructor returning a new hash object.
Defaults to hashlib.md5.
"""
if key is _secret_backdoor_key: # cheap
return
完整的code is here。
有谁知道这个变量的原因是什么?评论说 HMAC 比空白字符串(“”)返回得更快。但是为什么用户想要将空密钥传递给 HMAC 函数呢?变量命名只是 HMAC 开发者的玩笑还是真的是某种后门?
【问题讨论】:
标签: python hash python-internals