Class desfire::protocol_legacy

Inheritance Relationships

Base Type

Class Documentation

class protocol_legacy : public desfire::protocol

Mode of operation of DES, 2K3DES legacy ciphers.

Public Types

using block_t = mlab::tagged_array<block_tag, block_size>

One cipher data block.

using mac_t = mlab::tagged_array<mac_tag, mac_size>

Message Authentication Code type.

Public Functions

explicit protocol_legacy(std::unique_ptr<crypto> crypto)

Creates a new protocol using crypto as a underlying crypto primitive.

Parameters:

crypto – Cryptographic primitive wrapper.

virtual void prepare_tx(bin_data &data, std::size_t offset, comm_mode mode) override

See protocol::prepare_tx for a generic description. This implementation does the following:

virtual bool confirm_rx(bin_data &data, comm_mode mode) override

See protocol::confirm_rx for a generic description. This implementation does the following:

  • comm_mode::plain : does nothing.

  • comm_mode::maced : expects a sequence in the form [message] [32-bit MAC] [status]. Extracts the MAC, and compares it to the MAC computed on the message. If the comparison succeeds, removes the MAC from the sequence (keeping the status byte at the end) and returns positively.

  • comm_mode::ciphered : runs a crypto_operation::decrypt on data (excluding the last status byte). It then expects that the plaintext is a sequence [message] [16-bit CRC] [padding] [status]. It searches for the last sequence of 2 bytes that is a CRC on the previous data, and is following only by padding zeroes. If it finds any, and the CRC checks out, it removes the CRC and the padding, returning the message and the status byte.

  • comm_mode::ciphered_no_crc : runs a crypto_operation::decrypt on data (excluding the last status byte).

virtual void init_session(bin_data const &random_data) override

Sets up the session symmetric key used for further communication. This is the first operation that follows a successful authentication. This method calls crypto::init_session with random_data.

Parameters:

random_data – Random data obtained via key exchange

virtual bool is_legacy() const override

As the name says, it is legacy.

Public Static Attributes

static constexpr std::size_t block_size = 8

Supports only 8-byte block ciphers.

static constexpr std::size_t mac_size = 4

The MAC produced is 32 bits.

static constexpr std::size_t crc_size = 2

CRC is 16 bits.