コード例 #1
0
ファイル: eph.py プロジェクト: surg0r/eph
class Dil():
    def __init__(self, PK=None, SK=None):
        if not PK or not SK:
            self.d = Dilithium()
        else:
            self.d = Dilithium(PK, SK)
        self.PK = self.d.getPK()
        self.SK = self.d.getSK()

    def sign(self, message):  #message should be bytes
        signature = self.d.sign(message)
        return signature

    def verify(self, message, signature, PK):
        data_out = ucharVector(len(signature))
        self.d.sign_open(data_out, signature, PK)
        message_out = bytes(self.d.extract_message(data_out))
        signature_out = self.d.extract_signature(data_out)
        if message_out != message:
            return False
        if len(signature_out) != 2701:
            return False
        return True
コード例 #2
0
ファイル: test_dilithium.py プロジェクト: theQRL/qrllib
    def test_dilithium_reference2(self):
        pk = bytes(hstr2bin(self.PK1_HSTR))
        sk = bytes(hstr2bin(self.SK1_HSTR))

        dilithium = Dilithium(pk, sk)

        self.assertEqual(1472, len(dilithium.getPK()))
        self.assertEqual(3504, len(dilithium.getSK()))

        message = bytes(b"This is a test")
        message_signed = dilithium.sign(message)
        data_out = ucharVector(len(message_signed))

        Dilithium.sign_open(data_out, message_signed, dilithium.getPK())

        message_out = Dilithium.extract_message(data_out)
        signature_out = Dilithium.extract_signature(data_out)

        self.assertEqual(2715, len(data_out))
        self.assertEqual(len(message_out), len(message_out))
        self.assertEqual(2701, len(signature_out))

        self.assertEqual(message, bytes(message_out))
        self.assertEqual(b"This is a test", bytes(message_out))
コード例 #3
0
ファイル: test_dilithium.py プロジェクト: theQRL/qrllib
    def test_dilithium_reference(self):
        dilithium = Dilithium()

        self.assertEqual(1472, len(dilithium.getPK()))
        self.assertEqual(3504, len(dilithium.getSK()))

        message = bytes(b"This is a test")
        message_signed = dilithium.sign(message)
        data_out = ucharVector(len(message_signed))

        Dilithium.sign_open(data_out, message_signed, dilithium.getPK())

        message_out = Dilithium.extract_message(data_out)
        signature_out = Dilithium.extract_signature(data_out)

        self.assertEqual(2715, len(data_out))
        self.assertEqual(len(message_out), len(message_out))
        self.assertEqual(2701, len(signature_out))

        self.assertEqual(message, bytes(message_out))
        self.assertEqual(b"This is a test", bytes(message_out))

        print(bin2hstr(dilithium.getPK()))
        print(bin2hstr(dilithium.getSK()))