For most public facing services, you can generally have signin take upwards of 250ms - 400ms before users start getting annoyed.
那么,如果我们考虑一次数据库调用,那么登录/注册中rounds的最佳值(value)是多少?登录尝试,它使用 MongoDB 和非阻塞调用。 (使用 Mongotor ,并使用电子邮件作为 _id,因此默认情况下是 indexed,查询很快:0.00299978256226 和使用具有3 条记录...的数据库测试的类(class)...)
import passlib.hash
import time
hashh = passlib.hash.pbkdf2_sha512
beg1 = time.time()
password = hashh.encrypt("test", salt_size = 32, rounds = 12000)
print time.time()- beg1 # returns 0.142999887466
beg2 = time.time()
hashh.verify("test", password) # returns 0.143000125885
print time.time()- beg2
现在如果我使用一半的值:
password = hashh.encrypt("test", salt_size = 32, rounds = 4000) # returns 0.0720000267029
hashh.verify("test", password) # returns 0.0709998607635
我在 Dell XPS 15 i7 2.0 Ghz 上使用 Windows 7 64 位
注意:已安装 bcrypt ,当然,直接将它用作默认值(rounds = 12)真的很痛苦:
hashh = passlib.hash.bcrypt
beg1 = time.time()
password = hashh.encrypt("test", rounds = 12) # returns 0.406000137329
print time.time()- beg1
beg2 = time.time()
hashh.verify("test", password) # returns 0.40499997139
print time.time()- beg2
半价:
password = hashh.encrypt("test", rounds = 12) # 0.00699996948242 wonderful?
hashh.verify("test", password) # 0.00600004196167
当使用 pbkdf2_sha512 时,你能建议我一个对生产有益的轮值吗?
最佳答案
(此处为 passlib 开发人员)
pbkdf2_sha512 花费的时间与其轮数参数成线性比例(elapsed_time = rounds * native_speed)。使用您系统的数据,native_speed = 12000/.143 = 83916 iterations/second,这意味着您需要大约 83916 * .350 = 29575 rounds 才能获得 ~ 350 毫秒延迟。
对于 bcrypt 来说,事情有点棘手,因为它花费的时间量与其轮数参数成对数比例(elapsed_time = (2 ** rounds) * native_speed)。使用系统的数据,native_speed = (2 ** 12)/.405 = 10113 iterations/second,这意味着您将需要大约 log(10113 * .350, 2) = 11.79 轮以获得约 350 毫秒的延迟。但由于 BCrypt 只接受整数轮次参数,因此您需要选择 rounds=11(~200ms)或 rounds=12(~400ms)。
所有这些都是我希望在 passlib 的 future 版本中解决的问题。作为一项正在进行的工作,passlib 的 mercurial repo 目前包含一个简单的小脚本,choose_rounds.py ,它负责为给定的目标时间选择正确的回合值。可以直接下载运行如下(运行可能需要20s左右):
$ python choose_rounds.py -h
usage: python choose_rounds.py <hash_name> [<target_in_milliseconds>]
$ python choose_rounds.py pbkdf2_sha512 350
hash............: pbkdf2_sha512
speed...........: 83916 iterations/second
target time.....: 350 ms
target rounds...: 29575
$ python choose_rounds.py bcrypt 350
hash............: bcrypt
speed...........: 10113 iterations/second
target time.....: 350 ms
target rounds...: 11 (200ms -- 150ms faster than requested)
target rounds...: 12 (400ms -- 50ms slower than requested)
(编辑:添加了关于安全最小轮次的响应...)
免责声明:确定安全最小值是一个非常棘手的问题 - 有许多难以量化的参数、极少的真实世界数据和一些严格无用的理论。缺乏权威,我一直在研究这个话题;对于即兴计算,我将原始数据归结为一个简短的公式(如下),这通常是我使用的。请注意,其背后是几页假设和粗略估计,使其更像是一个Fermi Estimation。不是一个确切的答案:|
我使用 GPU 攻击 PBKDF2-HMAC-SHA512 的经验法则(2012 年年中)是:
days * dollars = 2**(n-31) * rounds
days 是攻击者有 50/50 的机会猜出密码之前的天数。dollars 是攻击者的硬件预算(以美元计)。n 是您用户密码中的平均熵量(以位为单位)。回答您的脚本小子问题:如果平均密码有 32 位熵,并且攻击者有一个 2000 美元的系统和一个好的 GPU,那么在 30000 轮时他们将需要 30 天( 2**(32-31)*30000/2000) 有 50/50 的机会破解给定的哈希值。我建议您尝试使用这些值,直到找到您满意的轮数/天数权衡。
注意事项:
字典攻击的成功率不是线性的,它更像是“长尾”情况,所以将 50/50 标记看作更像是半衰期。
31 是关键因素,因为它编码了使用特定技术水平攻击特定算法的成本估算。实际值 2**-31 衡量攻击者将花费的“每轮美元天数”。为了比较,使用 ASIC 攻击 PBKDF2-HMAC-SHA512有一个更接近于 46 的因子——更大的数字意味着攻击者的 yield 更大,而你每轮的安全性更低,尽管脚本小子通常没有那种预算:)
关于 python 密码库 : what is the best value for "rounds",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13545677/
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
我在新的Debian6VirtualBoxVM上安装RVM时遇到问题。我已经安装了所有需要的包并使用下载了安装脚本(curl-shttps://rvm.beginrescueend.com/install/rvm)>rvm,但以单个用户身份运行时bashrvm我收到以下错误消息:ERROR:Unabletocheckoutbranch.安装在这里停止,并且(据我所知)没有安装RVM的任何文件。如果我以root身份运行脚本(对于多用户安装),我会收到另一条消息:Successfullycheckedoutbranch''安装程序继续并指示成功,但未添加.rvm目录,甚至在修改我的.bas
下面的代码在我第一次运行它时就可以正常工作:require'rubygems'require'spreadsheet'book=Spreadsheet.open'/Users/me/myruby/Mywks.xls'sheet=book.worksheet0row=sheet.row(1)putsrow[1]book.write'/Users/me/myruby/Mywks.xls'当我再次运行它时,我会收到更多消息,例如:/Library/Ruby/Gems/1.8/gems/spreadsheet-0.6.5.9/lib/spreadsheet/excel/reader.rb:11