def test_smix(self): """smix()""" from passlib.crypto.scrypt._builtin import ScryptEngine rng = self.getRandom() #----------------------------------------------------------------------- # test vector from (expired) scrypt rfc draft # (https://tools.ietf.org/html/draft-josefsson-scrypt-kdf-01, section 9) #----------------------------------------------------------------------- input = hb(""" f7 ce 0b 65 3d 2d 72 a4 10 8c f5 ab e9 12 ff dd 77 76 16 db bb 27 a7 0e 82 04 f3 ae 2d 0f 6f ad 89 f6 8f 48 11 d1 e8 7b cc 3b d7 40 0a 9f fd 29 09 4f 01 84 63 95 74 f3 9a e5 a1 31 52 17 bc d7 89 49 91 44 72 13 bb 22 6c 25 b5 4d a8 63 70 fb cd 98 43 80 37 46 66 bb 8f fc b5 bf 40 c2 54 b0 67 d2 7c 51 ce 4a d5 fe d8 29 c9 0b 50 5a 57 1b 7f 4d 1c ad 6a 52 3c da 77 0e 67 bc ea af 7e 89 """) output = hb(""" 79 cc c1 93 62 9d eb ca 04 7f 0b 70 60 4b f6 b6 2c e3 dd 4a 96 26 e3 55 fa fc 61 98 e6 ea 2b 46 d5 84 13 67 3b 99 b0 29 d6 65 c3 57 60 1f b4 26 a0 b2 f4 bb a2 00 ee 9f 0a 43 d1 9b 57 1a 9c 71 ef 11 42 e6 5d 5a 26 6f dd ca 83 2c e5 9f aa 7c ac 0b 9c f1 be 2b ff ca 30 0d 01 ee 38 76 19 c4 ae 12 fd 44 38 f2 03 a0 e4 e1 c4 7e c3 14 86 1f 4e 90 87 cb 33 39 6a 68 73 e8 f9 d2 53 9a 4b 8e """) # NOTE: p value should be ignored, so testing w/ random inputs. engine = ScryptEngine(n=16, r=1, p=rng.randint(1, 1023)) self.assertEqual(engine.smix(input), output)
def test_smix(self): """smix()""" from passlib.crypto.scrypt._builtin import ScryptEngine rng = self.getRandom() # ----------------------------------------------------------------------- # test vector from (expired) scrypt rfc draft # (https://tools.ietf.org/html/draft-josefsson-scrypt-kdf-01, section 9) # ----------------------------------------------------------------------- input = hb(""" f7 ce 0b 65 3d 2d 72 a4 10 8c f5 ab e9 12 ff dd 77 76 16 db bb 27 a7 0e 82 04 f3 ae 2d 0f 6f ad 89 f6 8f 48 11 d1 e8 7b cc 3b d7 40 0a 9f fd 29 09 4f 01 84 63 95 74 f3 9a e5 a1 31 52 17 bc d7 89 49 91 44 72 13 bb 22 6c 25 b5 4d a8 63 70 fb cd 98 43 80 37 46 66 bb 8f fc b5 bf 40 c2 54 b0 67 d2 7c 51 ce 4a d5 fe d8 29 c9 0b 50 5a 57 1b 7f 4d 1c ad 6a 52 3c da 77 0e 67 bc ea af 7e 89 """) output = hb(""" 79 cc c1 93 62 9d eb ca 04 7f 0b 70 60 4b f6 b6 2c e3 dd 4a 96 26 e3 55 fa fc 61 98 e6 ea 2b 46 d5 84 13 67 3b 99 b0 29 d6 65 c3 57 60 1f b4 26 a0 b2 f4 bb a2 00 ee 9f 0a 43 d1 9b 57 1a 9c 71 ef 11 42 e6 5d 5a 26 6f dd ca 83 2c e5 9f aa 7c ac 0b 9c f1 be 2b ff ca 30 0d 01 ee 38 76 19 c4 ae 12 fd 44 38 f2 03 a0 e4 e1 c4 7e c3 14 86 1f 4e 90 87 cb 33 39 6a 68 73 e8 f9 d2 53 9a 4b 8e """) # NOTE: p value should be ignored, so testing w/ random inputs. engine = ScryptEngine(n=16, r=1, p=rng.randint(1, 1023)) self.assertEqual(engine.smix(input), output)
def check_bmix(r, input, output): """helper to check bmix() output against reference""" # NOTE: * n & p values should be ignored, so testing w/ rng inputs. # * target buffer contents should be ignored, so testing w/ random inputs. engine = ScryptEngine(r=r, n=1 << rng.randint(1, 32), p=rng.randint(1, 1023)) target = [rng.randint(0, 1 << 32) for _ in range((2 * r) * 16)] engine.bmix(input, target) self.assertEqual(target, list(output)) # ScryptEngine special-cases bmix() for r=1. # this removes the special case patching, so we also test original bmix function. if r == 1: del engine.bmix target = [rng.randint(0, 1 << 32) for _ in range((2 * r) * 16)] engine.bmix(input, target) self.assertEqual(target, list(output))