Class desfire::protocol
Defined in File protocol.hpp
Inheritance Relationships
Derived Types
public desfire::protocol_default
(Class desfire::protocol_default)public desfire::protocol_dummy
(Class desfire::protocol_dummy)public desfire::protocol_legacy
(Class desfire::protocol_legacy)
Class Documentation
-
class protocol
Class capturing the secure communication mode over some cryptographic primitive (crypto).
A protocol instance is responsible to secure the data for transmission and decode it in reception. It works by operating a crypto object in an appropriate way; in general, it is a stateful object.
Subclassed by desfire::protocol_default, desfire::protocol_dummy, desfire::protocol_legacy
Public Functions
-
virtual void prepare_tx(bin_data &data, std::size_t offset, comm_mode mode) = 0
Prepares data for transmission. This method is responsible for securing, in-place, all data starting at
offset
using the specifiedmode
.- Parameters:
data – Data to secure; it is modified in-place.
offset – Offset in
data
of the sensitive data.mode – Mode in which to operate the underlying crypto.
-
virtual bool confirm_rx(bin_data &data, comm_mode mode) = 0
Post-processes data after reception.
- Parameters:
data – Received data. The data must include a
bits::status
byte, which must come last in this sequence. The caller is responsible for shifting it to the last position. The data is modified in-place.mode – Mode in which to operate the underlying crypto.
- Returns:
A boolean representing whether
data
was successfully validated. A return value of false indicates invalid MAC, invalid key, or session, or invalidmode
, or any unlikely but possible attempt of tampering.
-
virtual void init_session(bin_data const &random_data) = 0
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 = 0
A boolean indicating whether this class uses a legacy scheme.
Note
Currently there are only two schemes, protocol_legacy and protocol_default, so this is just a way to know whether it is legacy or not.
-
virtual ~protocol() = default
-
virtual void prepare_tx(bin_data &data, std::size_t offset, comm_mode mode) = 0