Template Class desfire::key_base

Inheritance Relationships

Base Type

Class Documentation

template<std::size_t KeyLength, bool ParityBitsAreVersion, class CRTPSubclass>
class key_base : public desfire::key_storage<KeyLength, ParityBitsAreVersion>

A Desfire key; this extends key_storage. All subclasses only specialize some of the templated arguments so that they can be used with mlab::any_of. Other than that, they are perfectly identical. This glues together the methods from key_storage<KeyLength,false> and key_storage<KeyLength,true>.

Template Parameters:
  • KeyLength – Length of the key in bytes.

  • ParityBitsAreVersion – Whether the parity bits store the key version or not (DES-based keys)

  • CRTPSubclass – Subclass type: used in conjunction with CRTP to implement with_key_number.

Comparison operators

inline bool operator==(key_base const &other) const
inline bool operator!=(key_base const &other) const

Public Types

using storage = key_storage<KeyLength, ParityBitsAreVersion>

Storage type (the base class)

Public Functions

constexpr key_base() = default

Default constructs a key with index 0 and body 0.

explicit key_base(random_oracle rng)

Constructs a random key 0 (with a random version if parity_bits_are_version).

Parameters:

rng – Random number generator function to use for filling the key body.

key_base(std::uint8_t key_no, random_oracle rng)

Constructs a random key with the given key_no (with a random version if parity_bits_are_version).

Parameters:
  • key_no – Key number, integer in the range 0..13 (included).

  • rng – Random number generator function to use for filling the key body.

constexpr key_base(std::uint8_t key_no, key_body_t k)

Constructs a key of index key_no with body k.

Parameters:
  • key_no – Key number, integer in the range 0..13 (included).

  • k – Key body.

key_base(std::uint8_t key_no, random_oracle rng, std::uint8_t v)

Constructs a random key with the given key_no and version v.

Parameters:
  • key_no – Key number, integer in the range 0..13 (included).

  • rng – Random number generator function to use for filling the key body.

  • v – Key version.

constexpr key_base(std::uint8_t key_no, key_body_t k, std::uint8_t v)

Constructs a key of index key_no with body k and version v.

Parameters:
  • key_no – Key number, integer in the range 0..13 (included).

  • k – Key body.

  • v – Key version.

CRTPSubclass with_key_number(std::uint8_t key_no) const

Copies the same key but changes the key_number.

Parameters:

key_no – Number of the key, in the range 0..13 (included).

Returns:

An identical key, with different key_number.

constexpr std::uint8_t key_number() const

Key number of the key.

Returns:

A number in the range 0..13 (included).

inline void set_key_number(std::uint8_t key_no)

Changes the key number to key_no.

Parameters:

key_no – A number in the range 0..13 (included).

Public Static Attributes

static constexpr bool parity_bits_are_version = ParityBitsAreVersion

Whether the parity bits store the version byte or not.