当回合数=5000时,SHA512 crypt返回*0

2024-04-28 20:53:30 发布

您现在位置:Python中文网/ 问答频道 /正文

由于python程序随后几天返回*0

import crypt
# broken:
>>> crypt.crypt('pw', '$6$rounds=5000$0123456789abcdef')
'*0'
# works:
>>> crypt.crypt("pw", '$6$0123456789abcdef')
'$6$0123456789abcdef$zAYvvEJcrKSqV2KUPTUM1K9eaGv20n9mUjWSDZW0QnwBRk0L...'
>>> crypt.crypt('pw', '$6$rounds=5001$0123456789abcdef')
'$6$rounds=5001$0123456789abcdef$mG98GkftS5iu1VOpowpXm1fgefTbWnRm4rbw...'
>>> crypt.crypt("pw", '$6$rounds=4999$0123456789abcdef')
'$6$rounds=4999$0123456789abcdef$ulXwrQtpwNd/t6NVUJo53AXMpp40IrpCHFyC...'

我对一个使用crypt_r的小型C程序也做了同样的处理,结果是一样的。我在一些帖子中读到,*0和{}将在出现错误时返回。在

{{cd7>中支持第二个参数{cd7>,因为第二个参数在cd7>中是受支持的。为什么我不能把rounds设置为5000?

我用的是Fedora28和Glibc2.27。对于不同的Python版本(甚至Python2和Python3),结果是相同的。在PHP中使用crypt也可以正常工作。但最有趣的是,在Docker容器(fedora:28)中运行相同的命令可以工作:

^{pr2}$

有人知道这种行为的原因吗?在


Tags: import程序参数错误帖子workspwcrypt
1条回答
网友
1楼 · 发布于 2024-04-28 20:53:30

{包含^ a1:

/* Do not allow an explicit setting of zero rounds, nor of the
   default number of rounds, nor leading zeroes on the rounds.  */

这是introduced in a commit “Add more tests based on gaps in line coverage.”的评论:

This change makes us pickier about non-default round parameters to $5$ and $6$ hashes; numbers outside the valid range are now rejected, as are numbers with leading zeroes and an explicit request for the default number of rounds. This is in keeping with the observation, in the Passlib documentation, that allowing more than one valid crypt output string for any given (rounds, salt, phrase) triple is asking for trouble.

我建议打开一个问题,如果这导致太多的兼容性问题。或者,您可以删除rounds=5000规范,但根据快速浏览,我觉得该更改似乎应该恢复。它不是glibc中最初的libcrypt实现的一部分。在

相关问题 更多 >