Exemple #1
0
    def back_encrypt(self, authenticated=True):
        for i in range(5):
            priv_key = crypto.random_scalar()
            data = crypto.cn_fast_hash(crypto.encodeint(
                crypto.random_scalar())) * (i + 1)

            blob = chacha.encrypt_xmr(priv_key,
                                      data,
                                      authenticated=authenticated)
            plaintext = chacha.decrypt_xmr(priv_key,
                                           blob,
                                           authenticated=authenticated)
            self.assertEqual(data, plaintext)

            try:
                plaintext2 = chacha.decrypt_xmr(
                    crypto.sc_add(priv_key, crypto.sc_init(1)),
                    blob,
                    authenticated=authenticated,
                )
                if authenticated:
                    self.fail("Signature error expected")
                else:
                    self.assertNotEqual(data, plaintext2)

            except:
                if not authenticated:
                    raise
Exemple #2
0
async def save_exported_outputs(priv_spend, priv_view, transfers):
    writer = xmrserialize.MemoryReaderWriter()
    ar = xmrboost.Archive(writer, True)

    await ar.root()
    await ar.container(transfers, container_type=ExportedOutputs)
    trans_bin = writer.get_buffer()

    buff_dec = bytearray()
    buff_dec += crypto.encodepoint(crypto.scalarmult_base(priv_spend))
    buff_dec += crypto.encodepoint(crypto.scalarmult_base(priv_view))
    buff_dec += trans_bin

    data_enc = chacha.encrypt_xmr(priv_view, buff_dec, authenticated=True)
    return bytearray(bytes(OUTPUTS_PREFIX) + data_enc)
Exemple #3
0
async def dump_unsigned_tx(priv_key, unsigned_tx):
    """
    Dumps unsigned transaction
    :param priv_key:
    :param unsigned_tx:
    :return:
    """
    writer = xmrserialize.MemoryReaderWriter()
    ar = xmrboost.Archive(writer, True)
    await ar.root()
    await ar.message(unsigned_tx)

    ciphertext = chacha.encrypt_xmr(priv_key,
                                    bytes(writer.get_buffer()),
                                    authenticated=True)
    return UNSIGNED_TX_PREFIX + ciphertext
Exemple #4
0
async def dump_signed_tx(priv_key, signed_tx):
    """
    Dumps signed_tx to a file as wallet produces

    :param priv_key:
    :param signed_tx:
    :return:
    """
    writer = xmrserialize.MemoryReaderWriter()
    ar = xmrboost.Archive(writer, True)
    await ar.root()
    await ar.message(signed_tx)

    ciphertext = chacha.encrypt_xmr(priv_key,
                                    bytes(writer.get_buffer()),
                                    authenticated=True)
    return SIGNED_TX_PREFIX + ciphertext
Exemple #5
0
async def dump_signed_tx(priv_key, signed_tx):
    """
    Dumps signed_tx to a file as wallet produces

    :param priv_key:
    :param signed_tx:
    :return:
    """
    writer = xmrserialize.MemoryReaderWriter()
    ar = xmrboost.Archive(writer, True)
    try:
        await ar.root()
        await ar.message(signed_tx)
    except Exception as e:
        logger.error('Exception in signed tx serialization: %s, field: %s' % (e, ar.tracker))
        raise

    ciphertext = chacha.encrypt_xmr(
        priv_key, bytes(writer.get_buffer()), authenticated=True
    )
    return SIGNED_TX_PREFIX + ciphertext