For faster navigation, this Iframe is preloading the Wikiwand page for PBKDF2.

PBKDF2

密码学中, PBKDF1PBKDF2基于密码的密钥派生函数 12 ,英語:Password-Based Key Derivation Function 1 and 2)是具有可变计算成本的密钥派生函数,可以降低面对蛮力攻击的脆弱性。[1]

PBKDF2是RSA 实验室公钥密码学标准(PKCS)系列的一部分,即 PKCS #5 v2.0,同时也作为互联网工程任务组的 RFC 2898发布。它取代了只能生成最长160位派生密钥的PBKDF1。[2]2017年发布的RFC 8018(PKCS #5 v2.1)推荐使用PBKDF2进行密码哈希处理。[3]

目的和运作

PBKDF2 将伪随机函数英语Pseudorandom function family(例如基于散列的消息身份验证码,HMAC)与值一起应用于输入密码密码词组,并多次重复该过程以生成派生密钥,然后可以将其用作后续过程的加密密钥。增加的计算工作使密码破解英语Password cracking变得更加困难,这被称为密钥延伸

在2000年编写的标准建议最小迭代次数为1,000次,但随CPU性能的提高,该参数会随着时间的推移而增加。2005年的Kerberos标准推荐4,096次迭代;[1]据报道,蘋果公司iOS 3中使用了2,000次,在iOS 4中使用了10,000次;[4]LastPass在2011年对JavaScript客户端使用了5,000次迭代,对服务器端哈希使用了100,000次迭代。[5] 2023 年,OWASP建议PBKDF2-HMAC-SHA256使用600,000次迭代,PBKDF2-HMAC-SHA512使用210,000 次迭代。[6]

PBKDF 2迭代过程的算法表示。

在密码中添加盐会降低使用预计算的哈希值(彩虹表)进行攻击的能力,并且意味着必须单独测试多个密码,而不是一次测试所有密码。该标准建议盐长度至少为64位。[7]美国国家标准与技术研究所推荐的长度为128位。 [8]

密钥推导过程

PBKDF2密钥推导函数有五个输入参数:[9]

DK = PBKDF2(PRF, Password, Salt, c, dkLen)

其中

  • PRF 是一个有两个输入参数的伪随机函数(例如一个有密钥的HMAC),输出长度hLen
  • Password 是主密码,推导密钥由它生成
  • Salt 是一个比特序列,即
  • c 是希望进行的迭代次数
  • dkLen 是希望生成推导密钥的长度(位)
  • DK 是生成的推导密钥

派生密钥DK的每个hLen位的块Ti计算如下(使用+表示字符串拼接):

DK = T1 + T2 + ⋯ + Tdklen/hlen
Ti = F(Password, Salt, c, i)

函数F是链式PRF的c次迭代的异或( ^ )。PRF的第一次迭代使用Password作为PRF密钥,并将Salt与编码为大端序32位整数的i(索引i从1开始)拼接,作为输入。 PRF的后续迭代使用Password作为 PRF 密钥,并将先前PRF计算的输出作为输入:

F(Password, Salt, c, i) = U1 ^ U2 ^ ⋯ ^ Uc

其中

U1 = PRF(Password, Salt + INT_32_BE(i))
U2 = PRF(Password, U1)
Uc = PRF(Password, Uc−1)

例如, WPA2使用:

DK = PBKDF2(HMAC−SHA1, passphrase, ssid, 4096, 256)

PBKDF1过程更简单:初始U (在这个版本中称为T )由PRF(Password + Salt)创建,后面只是将上一轮的U作为下一轮PRF的输入,即PRF(Uprevious) 。最后提取最终哈希的前dkLen位作为密钥。因此PBKDF1存在大小限制。[9]

HMAC冲突

当使用 HMAC 作为其伪随机函数时,PBKDF2 有一个有趣的特性。可以简单地构造任意数量的不同密码对,并且每对密码对都存在冲突。[10]如果提供的密码长于底层HMAC散列函数的块大小,则密码首先被预散列为摘要,然后该摘要用作密码。例如,以下密码太长:

  • 密码: plnlrtfpijpuhqylxbgqiiyipieyxvfsavzgxbbcfusqkozwpngsyejqlmjsytrmd

因此,在使用 HMAC-SHA1 时,使用 SHA-1 将其预散列为:

  • SHA1 (十六进制): 65426b585154667542717027635463617226672a

可以用 ASCII 表示为:

  • SHA1 (ASCII): eBkXQTfuBqp'cTcar&g*

这意味着无论盐或迭代次数如何,PBKDF2-HMAC-SHA1 都会为下列密码生成相同的密钥字节:

  • "plnlrtfpijpuhqylxbgqiiyipieyxvfsavzgxbbcfusqkozwpngsyejqlmjsytrmd"
  • "eBkXQTfuBqp'cTcar&g*"

例如,使用:

  • PRF : HMAC-SHA1
  • 盐: A009C1A485912C6AE630D3E744240B04
  • 迭代次数: 1,000
  • 派生密钥长度: 16 字节

下面两个函数调用:

PBKDF2-HMAC-SHA1("plnlrtfpijpuhqylxbgqiiyipieyxvfsavzgxbbcfusqkozwpngsyejqlmjsytrmd", ...)
PBKDF2-HMAC-SHA1("eBkXQTfuBqp'cTcar&g*", ...) 

将生成相同的派生密钥字节 ( 17EB4014C8C461C300E9B61518B9A18B )。这些派生密钥冲突并不代表存在安全漏洞,因为仍然必须知道原始密码才能生成密码的哈希值。[11]利用这一性质,对于一些ZIP格式的加密压缩文件,可能存在两个可行的密码。[12][13]

PBKDF2的替代算法

PBKDF2 的一个缺点是,尽管可以通过改变迭代次数来任意调整所需的计算时间,但它可以用一个小电路和很少的RAM来实现,这使得使用特殊應用積體電路(ASIC)或图形处理器(GPU)进行暴力攻击相对低廉。[14]Bcrypt密码散列函数需要更大的RAM(但仍然不能单独调整,由给定的CPU时间决定)并且对此类攻击的抵抗力稍强, [15]而更现代的Scrypt密钥派生函数可以任意使用大量内存,因此更能抵抗ASIC和GPU攻击。[14]

2013年举行的密码哈希竞赛英语Password Hashing Competition(PHC)鼓励开发一种更具抵抗力的密码哈希方法。2015年7月20日,Argon2英语Argon2被选为最终的获胜者,PHC还特别表彰了其他四种密码哈希方案:Catena、Lyra2英语Lyra2、yescrypt和Makwa。[16]另一种替代方法是气球哈希英语Balloon hashing,这是NIST密码指南英语Password_policy#NIST guidelines中推荐的方法。[17]

参见

参考资料

  1. ^ 1.0 1.1 Raeburn, Kenneth. Advanced Encryption Standard (AES) Encryption for Kerberos 5. tools.ietf.org. 2005 [2015-10-23]. doi:10.17487/RFC3962可免费查阅. RFC 3962. (原始内容存档于2019-03-21). 
  2. ^ Kaliski, Burt. PKCS #5: Password-Based Cryptography Specification, Version 2.0. tools.ietf.org. 2000 [2015-10-23]. doi:10.17487/RFC2898可免费查阅. RFC 2898. (原始内容存档于2019-03-27). 
  3. ^ Moriarty, Kathleen; et al. PKCS #5: Password-Based Cryptography Specification, Version 2.1. tools.ietf.org. 2017 [2023-02-12]. doi:10.17487/RFC8018. RFC 8018. (原始内容存档于2019-03-27). 
  4. ^ Smartphone Forensics: Cracking BlackBerry Backup Passwords. Advanced Password Cracking – Insight. ElcomSoft. 2010-09-30 [2015-10-23]. (原始内容存档于2019-04-07). 
  5. ^ LastPass Security Notification. The LastPass Blog. 2011-05-05 [2023-01-31]. (原始内容存档于2023-01-31). 
  6. ^ Password Storage Cheat Sheet. OWASP Cheat Sheet Series. 2021-08-15 [2023-01-23]. (原始内容存档于2023-01-23). 
  7. ^ Moriarty, Kathleen; et al. PKCS #5: Password-Based Cryptography Specification, Version 2.1: Section 4. Salt and Iteration Count. tools.ietf.org. 2017 [2018-01-24]. doi:10.17487/RFC8018. RFC 8018. (原始内容存档于2019-03-27). 
  8. ^ Sönmez Turan, Meltem; Barker, Elaine; Burr, William; Chen, Lily. Recommendation for Password-Based Key Derivation Part 1: Storage Applications (PDF). NIST. [2018-12-20]. SP 800-132. (原始内容存档 (PDF)于2018-06-02). 
  9. ^ 9.0 9.1 Password-Based Cryptography Specification RFC 2898
  10. ^ Bynens, Mathias. PBKDF2+HMAC hash collisions explained. mathiasbynens.be. [2023-02-12]. (原始内容存档于2019-02-13). 
  11. ^ Iuorio, Andrea Francesco; Visconti, Andrea. Understanding Optimizations and Measuring Performances of PBKDF2. Woungang, Isaac (编). 2nd International Conference on Wireless Intelligent and Distributed Environment for Communication 27. Cham: Springer International Publishing. 2019: 101–114. ISBN 978-3-030-11436-7. doi:10.1007/978-3-030-11437-4_8 (英语). 
  12. ^ An encrypted ZIP file can have two correct passwords — here's why. BleepingComputer. [2023-02-12]. (原始内容存档于2023-05-25) (美国英语). 
  13. ^ 加密 ZIP 文件可以存在两个正确的密码 - OSCHINA - 中文开源技术交流社区. www.oschina.net. [2023-02-12]. (原始内容存档于2023-04-15). 
  14. ^ 14.0 14.1 Colin Percival. scrypt页面存档备份,存于互联网档案馆). As presented in "Stronger Key Derivation via Sequential Memory-Hard Functions"页面存档备份,存于互联网档案馆). presented at BSDCan'09, May 2009.
  15. ^ New 25 GPU Monster Devours Passwords In Seconds. The Security Ledger. 2012-12-04 [2013-09-07]. (原始内容存档于2013-04-24). 
  16. ^ Password Hashing Competition. password-hashing.net. [2023-02-12]. (原始内容存档于2019-04-07) (英语). 
  17. ^ Digital Identity Guidelines Authentication and Lifecycle Management Section 5.1.1.2 (PDF). NIST. [2021-06-18]. SP 800-63B. (原始内容存档 (PDF)于2019-04-01). 

外部链接

{{bottomLinkPreText}} {{bottomLinkText}}
PBKDF2
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?