How to use the protobuf.dump_message function in protobuf

To help you get started, we’ve selected a few protobuf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github trezor / trezor-firmware / src / apps / monero / signing / step_01_init_transaction.py View on Github external
async def _compute_sec_keys(state: State, tsx_data: MoneroTransactionData):
    """
    Generate master key H( H(TsxData || tx_priv) || rand )
    """
    import protobuf
    from apps.monero.xmr.keccak_hasher import get_keccak_writer

    writer = get_keccak_writer()
    await protobuf.dump_message(writer, tsx_data)
    writer.write(crypto.encodeint(state.tx_priv))

    master_key = crypto.keccak_2hash(
        writer.get_digest() + crypto.encodeint(crypto.random_scalar())
    )
    state.key_hmac = crypto.keccak_2hash(b"hmac" + master_key)
    state.key_enc = crypto.keccak_2hash(b"enc" + master_key)
github trezor / trezor-core / src / apps / monero / protocol / signing / step_01_init_transaction.py View on Github external
async def _compute_sec_keys(state: State, tsx_data: MoneroTransactionData):
    """
    Generate master key H( H(TsxData || tx_priv) || rand )
    """
    import protobuf
    from apps.monero.xmr.sub.keccak_hasher import get_keccak_writer

    writer = get_keccak_writer()
    await protobuf.dump_message(writer, tsx_data)
    writer.write(crypto.encodeint(state.tx_priv))

    master_key = crypto.keccak_2hash(
        writer.get_digest() + crypto.encodeint(crypto.random_scalar())
    )
    state.key_hmac = crypto.keccak_2hash(b"hmac" + master_key)
    state.key_enc = crypto.keccak_2hash(b"enc" + master_key)
github trezor / trezor-firmware / core / src / trezor / wire / __init__.py View on Github external
async def write(self, msg: protobuf.MessageType) -> None:
        writer = self.make_writer()

        if __debug__:
            log.debug(
                __name__, "%s:%x write: %s", self.iface.iface_num(), self.sid, msg
            )

        # get the message size
        fields = msg.get_fields()
        size = protobuf.count_message(msg, fields)

        # write the message
        writer.setheader(msg.MESSAGE_WIRE_TYPE, size)
        await protobuf.dump_message(writer, msg, fields)
        await writer.aclose()
github trezor / trezor-firmware / core / src / apps / monero / signing / offloading_keys.py View on Github external
async def gen_hmac_vouti(key, dst_entr, tx_out_bin, idx: int) -> bytes:
    """
    Generates HMAC for (TxDestinationEntry[i] || tx.vout[i])
    """
    import protobuf
    from apps.monero.xmr.keccak_hasher import get_keccak_writer

    kwriter = get_keccak_writer()
    await protobuf.dump_message(kwriter, dst_entr)
    kwriter.write(tx_out_bin)

    hmac_key_vouti = hmac_key_txout(key, idx)
    hmac_vouti = crypto.compute_hmac(hmac_key_vouti, kwriter.get_digest())
    return hmac_vouti
github trezor / trezor-firmware / core / src / apps / monero / signing / step_01_init_transaction.py View on Github external
async def _compute_sec_keys(state: State, tsx_data: MoneroTransactionData):
    """
    Generate master key H( H(TsxData || tx_priv) || rand )
    """
    import protobuf
    from apps.monero.xmr.keccak_hasher import get_keccak_writer

    writer = get_keccak_writer()
    await protobuf.dump_message(writer, tsx_data)
    writer.write(crypto.encodeint(state.tx_priv))

    master_key = crypto.keccak_2hash(
        writer.get_digest() + crypto.encodeint(crypto.random_scalar())
    )
    state.key_hmac = crypto.keccak_2hash(b"hmac" + master_key)
    state.key_enc = crypto.keccak_2hash(b"enc" + master_key)
github trezor / trezor-firmware / core / src / apps / monero / signing / offloading_keys.py View on Github external
async def gen_hmac_vini(key, src_entr, vini_bin, idx: int) -> bytes:
    """
    Computes hmac (TxSourceEntry[i] || tx.vin[i])
    """
    import protobuf
    from apps.monero.xmr.keccak_hasher import get_keccak_writer

    kwriter = get_keccak_writer()
    await protobuf.dump_message(kwriter, src_entr)
    kwriter.write(vini_bin)

    hmac_key_vini = hmac_key_txin(key, idx)
    hmac_vini = crypto.compute_hmac(hmac_key_vini, kwriter.get_digest())
    return hmac_vini
github trezor / trezor-firmware / src / apps / monero / signing / offloading_keys.py View on Github external
async def gen_hmac_vini(key, src_entr, vini_bin, idx: int) -> bytes:
    """
    Computes hmac (TxSourceEntry[i] || tx.vin[i])
    """
    import protobuf
    from apps.monero.xmr.keccak_hasher import get_keccak_writer

    kwriter = get_keccak_writer()
    await protobuf.dump_message(kwriter, src_entr)
    kwriter.write(vini_bin)

    hmac_key_vini = hmac_key_txin(key, idx)
    hmac_vini = crypto.compute_hmac(hmac_key_vini, kwriter.get_digest())
    return hmac_vini
github trezor / trezor-firmware / src / apps / monero / signing / offloading_keys.py View on Github external
async def gen_hmac_tsxdest(key, dst_entr, idx: int) -> bytes:
    """
    Generates HMAC for TxDestinationEntry[i]
    """
    import protobuf
    from apps.monero.xmr.keccak_hasher import get_keccak_writer

    kwriter = get_keccak_writer()
    await protobuf.dump_message(kwriter, dst_entr)

    hmac_key = hmac_key_txdst(key, idx)
    hmac_tsxdest = crypto.compute_hmac(hmac_key, kwriter.get_digest())
    return hmac_tsxdest