def test_params(self): opps = 1500000 # memory limited self.failUnlessEqual(pick_params(MiB, 1.0, opps), (1024,8,45)) self.failUnlessEqual(pick_params(MiB, 2.0, opps), (1024,8,91)) self.failUnlessEqual(pick_params(MiB, 3.0, opps), (1024,8,137)) self.failUnlessEqual(pick_params(MiB, 4.0, opps), (1024,8,183)) self.failUnlessEqual(pick_params(100*MiB, 3.0, opps), (65536,8,2)) # cpu limited self.failUnlessEqual(pick_params(100*MiB, 1.0, opps), (32768,8,1)) self.failUnlessEqual(pick_params(100*MiB, 2.0, opps), (65536,8,1)) # and check that it can measure the CPU time itself N,r,p = pick_params(MiB, 1.0) self.failUnlessEqual(r, 8) # this one is hard-coded memory = 128*N*r self.failUnless(memory <= MiB, (memory, MiB))
class Oops(Exception): pass KW1 = "[email protected]:1" KW2 = "[email protected]:2" KW3 = "[email protected]:3" MB = 1000*1000 def netstring(s): return "%d:%s." % (len(s), s) def plus(*strings): return "".join([netstring(s) for s in strings]) c1 = 10000 c2 = 10000 N,r,p = pick_params(maxmem=100*MB, maxtime=1.0) print N,r,p dkLen = 256/8 email = "*****@*****.**" password = "******" if False: Tstart = time.time() A = PBKDF2(password=password, salt=plus(KW1, email), c=c1, dkLen=dkLen) Ta = time.time() print "time[A]:", Ta-Tstart B = scrypt(password=A, salt=plus(KW2, email), N=N,r=r,p=p, dkLen=256/8) Tb = time.time() print "time[B]:", Tb-Ta C = PBKDF2(password=plus(password,B), salt=plus(KW3, email), c=c2, dkLen=3*dkLen)