def test_digest_multi(self):
     x = hashlib.blake2s()
     d0 = x.digest()
     d1 = x.digest()
     d2 = x.digest()
     self.assertEqual(d0, d1)
     self.assertEqual(d0, d2)
Пример #2
0
def set_seed(seed):
    from trezor.crypto import bip32
    from trezor.crypto.hashlib import blake2s
    node = bip32.from_seed(seed, 'secp256k1')
    state = blake2s(node.public_key()).digest()
    global _seed, _state
    _seed, _state = seed, state
 def test_digest(self):
     key = unhexlify(
         '000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f')
     for d, h in self.vectors:
         self.assertEqual(
             hashlib.blake2s(unhexlify(d), hashlib.blake2s.digest_size,
                             key).digest(), unhexlify(h))
 def test_update(self):
     key = unhexlify('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f')
     x = hashlib.blake2s(b'', key)
     x.update(bytes(range(10)))
     self.assertEqual(x.digest(), unhexlify('f5c4b2ba1a00781b13aba0425242c69cb1552f3f71a9a3bb22b4a6b4277b46dd'))
     x.update(bytes(range(10, 30)))
     self.assertEqual(x.digest(), unhexlify('3ca989de10cfe609909472c8d35610805b2f977734cf652cc64b3bfc882d5d89'))
     x.update(bytes(range(30, 80)))
     self.assertEqual(x.digest(), unhexlify('30f3548370cfdceda5c37b569b6175e799eef1a62aaa943245ae7669c227a7b5'))
     x.update(bytes(range(80, 111)))
     self.assertEqual(x.digest(), unhexlify('9fe03bbe69ab1834f5219b0da88a08b30a66c5913f0151963c360560db0387b3'))
     x.update(bytes(range(111, 127)))
     self.assertEqual(x.digest(), unhexlify('ddbfea75cc467882eb3483ce5e2e756a4f4701b76b445519e89f22d60fa86e06'))
     x.update(bytes(range(127, 255)))
     self.assertEqual(x.digest(), unhexlify('3fb735061abc519dfe979e54c1ee5bfad0a9d858b3315bad34bde999efd724dd'))