2020-04-22 09:51:28 +00:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import mimcvdf
|
|
|
|
|
|
|
|
from kasten import exceptions
|
|
|
|
from kasten.generator import KastenMimcGenerator
|
2020-12-07 14:47:02 +00:00
|
|
|
from kasten import Kasten
|
2020-04-22 09:51:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestMimcGenerator(unittest.TestCase):
|
|
|
|
def test_mimc_generator(self):
|
2020-12-11 03:27:52 +00:00
|
|
|
k = b'\x95\xa3tst\x00\x00\x92\xc4\x00\xc4\x00\xc0\ntest data'
|
|
|
|
invalid = b'\x95\xa3tst\x00\x00\x92\xc4\x00\xc4\x00\xc0\ntest dat2'
|
2020-04-22 09:51:28 +00:00
|
|
|
K = KastenMimcGenerator.generate(k)
|
|
|
|
#h = sha3_384(k).digest()
|
|
|
|
h = mimcvdf.vdf_create(k, 5000, dec=True)
|
|
|
|
self.assertTrue(len(K.get_packed()) > 0)
|
|
|
|
KastenMimcGenerator.validate_id(h, k)
|
|
|
|
self.assertRaises(exceptions.InvalidID, KastenMimcGenerator.validate_id, h, invalid)
|
|
|
|
self.assertEqual(K.get_packed(), k)
|
|
|
|
|
|
|
|
def test_mimc_generator_wrong_rounds(self):
|
2020-12-11 03:27:52 +00:00
|
|
|
k = b'\x95\xa3tst\x00\x00\x92\xc4\x00\xc4\x00\xc0\ntest data'
|
|
|
|
invalid = b'\x95\xa3tst\x00\x00\xc0\xc0\ntest dat2'
|
2020-04-22 09:51:28 +00:00
|
|
|
K = KastenMimcGenerator.generate(k)
|
|
|
|
#h = sha3_384(k).digest()
|
|
|
|
h = mimcvdf.vdf_create(k, 1000, dec=True)
|
|
|
|
self.assertTrue(len(K.get_packed()) > 0)
|
|
|
|
self.assertRaises(exceptions.InvalidID, KastenMimcGenerator.validate_id, h, k)
|
|
|
|
self.assertRaises(exceptions.InvalidID, KastenMimcGenerator.validate_id, h, invalid)
|
|
|
|
self.assertEqual(K.get_packed(), k)
|
|
|
|
|
2020-12-07 14:47:02 +00:00
|
|
|
def test_mimc_generator_kasten_auto_validate(self):
|
2020-12-11 03:27:52 +00:00
|
|
|
k = b'\x95\xa3tst\x00\x00\x92\xc4\x00\xc4\x00\xc0\ntest data'
|
2020-12-07 14:47:02 +00:00
|
|
|
K = KastenMimcGenerator.generate(k, 1000)
|
|
|
|
|
|
|
|
Kasten(int.from_bytes(K.id, byteorder="big"), K.get_packed(), KastenMimcGenerator, *[1000])
|
|
|
|
self.assertRaises(
|
|
|
|
exceptions.InvalidID,
|
|
|
|
Kasten,
|
|
|
|
int.from_bytes(K.id, byteorder="big"), K.get_packed(), KastenMimcGenerator, *[100]
|
|
|
|
)
|
|
|
|
|
2020-04-22 09:51:28 +00:00
|
|
|
unittest.main()
|