Пример #1
0
    def __init__(self, tree_height, seed=None, _xmssfast=None):
        """
        :param
        tree_height: height of the tree to generate. number of OTS keypairs=2**tree_height
        :param seed:

        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getHeight()
        4
        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getSecretKeySize()
        132
        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getSignatureSize()
        2308
        >>> from qrl.crypto.doctest_data import *; len(XMSS(4, xmss_test_seed1)._xmss.getSK()) == XMSS(4, xmss_test_seed1)._xmss.getSecretKeySize()
        True

        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getPK() )
        '26b3bcc104d686ecfd9fdea7b1963384339121430fbe056cab7c3048ea3e4c4e51ec21420dd061739e4637fd74517a46f86f89e0fb83f2526fafafe356e564ff'
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getSK() ) == xmss_sk_expected1
        True
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getRoot() )
        '26b3bcc104d686ecfd9fdea7b1963384339121430fbe056cab7c3048ea3e4c4e'
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getPKSeed() )
        '51ec21420dd061739e4637fd74517a46f86f89e0fb83f2526fafafe356e564ff'
        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getIndex()
        0
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getSKSeed() )
        '5f2eb95ccf6a0e3e7f472c32d234340c20b3fd379dc28b710affcc0cb2afa57b'
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getSKPRF() )
        '3aa40c0f99459afe7efe72eb9517ee8ded49ccd51dab72ebf6bc37d73240bb3a'
        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getAddress('Q')
        'Q1d651431536359202ce7095757e3ed66f579a6eab488ac1331486f207c91604016b6a443'

        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed2)._xmss.getPK() )         # doctest: +SKIP
        ''
        """

        self._type = 'XMSS'

        if _xmssfast is not None:
            self._xmss = _xmssfast
            self._seed = self._xmss.getSeed()
        else:
            # TODO: This is the old code, probably it should be removed

            if seed is None:
                # FIXME: Improve seed generation
                self._seed = getRandomSeed(48, '')
            else:
                if isinstance(seed, str):
                    self._seed = str2bin(seed)
                else:
                    self._seed = seed

            self._xmss = XmssFast(self._seed, tree_height)

        self.addresses = [(0, self.get_address(), self.get_number_signatures())
                          ]
Пример #2
0
Файл: xmss.py Проект: fanff/QRL
    def __init__(self, tree_height, seed=None, _xmssfast=None):
        """
        :param
        tree_height: height of the tree to generate. number of OTS keypairs=2**tree_height
        :param seed:

        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getHeight()
        4
        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getSecretKeySize()
        132
        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getSignatureSize()
        2308
        >>> from qrl.crypto.doctest_data import *; len(XMSS(4, xmss_test_seed1)._xmss.getSK()) == XMSS(4, xmss_test_seed1)._xmss.getSecretKeySize()
        True

        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getPK() )
        '26b3bcc104d686ecfd9fdea7b1963384339121430fbe056cab7c3048ea3e4c4e51ec21420dd061739e4637fd74517a46f86f89e0fb83f2526fafafe356e564ff'
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getSK() ) == xmss_sk_expected1
        True
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getRoot() )
        '26b3bcc104d686ecfd9fdea7b1963384339121430fbe056cab7c3048ea3e4c4e'
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getPKSeed() )
        '51ec21420dd061739e4637fd74517a46f86f89e0fb83f2526fafafe356e564ff'
        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getIndex()
        0
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getSKSeed() )
        '5f2eb95ccf6a0e3e7f472c32d234340c20b3fd379dc28b710affcc0cb2afa57b'
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getSKPRF() )
        '3aa40c0f99459afe7efe72eb9517ee8ded49ccd51dab72ebf6bc37d73240bb3a'
        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getAddress('Q')
        'Q1d651431536359202ce7095757e3ed66f579a6eab488ac1331486f207c91604016b6a443'

        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed2)._xmss.getPK() )         # doctest: +SKIP
        ''
        """

        self._type = 'XMSS'

        if _xmssfast is not None:
            self._xmss = _xmssfast
            self._seed = self._xmss.getSeed()
        else:
            # TODO: This is the old code, probably it should be removed

            if seed is None:
                # FIXME: Improve seed generation
                self._seed = getRandomSeed(48, '')
            else:
                if isinstance(seed, str):
                    self._seed = str2bin(seed)
                else:
                    self._seed = seed

            self._xmss = XmssFast(self._seed, tree_height)

        self.addresses = [(0, self.get_address(), self.get_number_signatures())]
Пример #3
0
    def encrypt(self, message: bytes, iv=None) -> str:
        if iv is None:
            iv = bytes(getRandomSeed(16, ''))

        cipher = Cipher(AES(self.key_hash), modes.CTR(iv), default_backend())
        enc = cipher.encryptor()
        ciphertext = enc.update(message) + enc.finalize()

        output_message = base64.standard_b64encode(iv + ciphertext)
        return output_message.decode()
Пример #4
0
    def from_height(tree_height: int, hash_function="shake128"):
        if hash_function not in hash_functions:
            raise Exception("XMSS does not support this hash function!")

        seed = getRandomSeed(48, '')
        return XMSS(XmssFast(seed, tree_height, hash_functions[hash_function]))
Пример #5
0
 def from_height(tree_height: int):
     seed = getRandomSeed(48, '')
     return XMSS(XmssFast(seed, tree_height, pyqrllib.SHAKE_128))
Пример #6
0
    def __init__(self, tree_height, seed=None):
        """
        :param
        tree_height: height of the tree to generate. number of OTS keypairs=2**tree_height
        :param seed:
        >>> from qrl.crypto.doctest_data import *; XMSS(4, mnemonic2bin(xmss_mnemonic_test1, wordlist)).get_address()
        'Q572721d2221f1d43b18eecacb945221f1156f1e2f519b71e3def43d761e88f3af72feb52'
        >>> from qrl.crypto.doctest_data import *; XMSS(4, mnemonic2bin(xmss_mnemonic_test2, wordlist)).get_address()
        'Q578230464f0550df33f1bad86b725ce6e6c5e278c5d03a100fb93c1d282daec21b2422f2'
        >>> from qrl.crypto.doctest_data import *; XMSS(4, mnemonic2bin(xmss_mnemonic_test2, wordlist)).get_address()
        'Q578230464f0550df33f1bad86b725ce6e6c5e278c5d03a100fb93c1d282daec21b2422f2'

        # NEW TESTS
        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getHeight()
        4
        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getSecretKeySize()
        132
        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getSignatureSize()
        2308
        >>> from qrl.crypto.doctest_data import *; len(XMSS(4, xmss_test_seed1)._xmss.getSK()) == XMSS(4, xmss_test_seed1)._xmss.getSecretKeySize()
        True

        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getPK() )
        '26b3bcc104d686ecfd9fdea7b1963384339121430fbe056cab7c3048ea3e4c4e51ec21420dd061739e4637fd74517a46f86f89e0fb83f2526fafafe356e564ff'
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getSK() ) == xmss_sk_expected1
        True
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getRoot() )
        '26b3bcc104d686ecfd9fdea7b1963384339121430fbe056cab7c3048ea3e4c4e'
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getPKSeed() )
        '51ec21420dd061739e4637fd74517a46f86f89e0fb83f2526fafafe356e564ff'
        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getIndex()
        0
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getSKSeed() )
        '5f2eb95ccf6a0e3e7f472c32d234340c20b3fd379dc28b710affcc0cb2afa57b'
        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed1)._xmss.getSKPRF() )
        '3aa40c0f99459afe7efe72eb9517ee8ded49ccd51dab72ebf6bc37d73240bb3a'
        >>> from qrl.crypto.doctest_data import *; XMSS(4, xmss_test_seed1)._xmss.getAddress('Q')
        'Q1d651431536359202ce7095757e3ed66f579a6eab488ac1331486f207c91604016b6a443'

        >>> from qrl.crypto.doctest_data import *; bin2hstr( XMSS(4, xmss_test_seed2)._xmss.getPK() )         # doctest: +SKIP
        ''
        """
        self._number_signatures = 2**tree_height

        self._type = 'XMSS'

        # FIXME: Set index to appropiate value after restoring
        self._index = 0

        if seed is None:
            # FIXME: Improve seed generation
            self._seed = getRandomSeed(48, '')
        else:
            if isinstance(seed, str):
                self._seed = str2bin(seed)
            else:
                self._seed = seed

        # TODO: #####################
        # FIXME Seed is fixed!!!!!!!!!!!!!!!!!!!!
        self._xmss = XmssFast(self._seed, tree_height)

        # TODO: Need to set an index

        # data to allow signing of smaller xmss trees/different addresses derived from same SEED..
        # position in wallet denoted by first number and address/tree by signatures
        self.addresses = [(0, self.get_address(), self.get_number_signatures())
                          ]