到2022年为止,使用带有<#>Is和100000次迭代的AES GCM的PBKDF2仍然被认为是安全的。
在我们的威胁模型中,如果我们忽略与量子计算相关的风险,这是否安全?
下面是一个使用Python实现的示例:
import Crypto.Random, Crypto.Protocol.KDF, Crypto.Cipher.AES
plaintext = b"hello world hello world hello world hello world hello world"
password = b"correct horse battery staple"
nonce = Crypto.Random.new().read(16)
key = Crypto.Protocol.KDF.PBKDF2(password, nonce, count=100000)
cipher = Crypto.Cipher.AES.new(key, Crypto.Cipher.AES.MODE_GCM, nonce=nonce, mac_len=16)
ciphertext = (nonce,) + cipher.encrypt_and_digest(plaintext) # nonce | ciphertext | tag
print(ciphertext)注意:使用相同的nonce进行PBKDF2和AES.new(...)似乎不是一个问题,如果我们永远不会在未来的加密中重复使用这个nonce,请参阅将PBKDF2 2盐用于AES/GCM作为IV:危险吗?。
发布于 2022-05-02 23:47:06
这完全取决于密码的强度。对于一个具有给定哈希的密码,100,000轮PBKDF2将与该哈希的一轮哈希相比,添加相当于\log_2(100000) \approx 16.6比特的熵。如果密码本身已经非常强,那么您甚至不需要PBKDF2。一个缓慢的KDF的唯一目的是提高边缘强度密码的安全性。如果您的密码只有64位熵,那么1000,000次迭代可能会使拥有100万美元资产的攻击者无法访问它,因为64 + 16.6 = 80.6位,这可能要花费超过100万美元。
最好是用一个记忆硬的KDF。这并不是因为PBKDF2本身就被破坏了,而是因为攻击者可以更容易地扩展攻击,因为哈希将自己借给极端的并行性。
https://crypto.stackexchange.com/questions/99817
复制相似问题