Template Class desfire::key_storage< KeyLength, true >

Inheritance Relationships

Derived Type

Class Documentation

template<std::size_t KeyLength>
class key_storage<KeyLength, true>

Mixin used for holding the key body where the parity bits of the body are the version.

Note

This is also used to provide most of the methods of key_storage<KeyLength,false> and key_base.

Template Parameters:

KeyLength – Length of the key.

Subclassed by desfire::key_storage< KeyLength, false >

Public Types

using key_body_t = key_body<KeyLength>

Key body alias.

Public Functions

constexpr mlab::range<std::uint8_t const*> as_range() const

Access the key body as a byte range.

key_storage() = default

Constructs a key filled with zeroes and version 0.

inline explicit key_storage(random_oracle rng)

Constructs a random key body (and a random version).

Parameters:

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

key_storage(random_oracle rng, std::uint8_t v)

Constructs a random key body with a pre-defined version.

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

  • v – Version of this key.

explicit constexpr key_storage(key_body_t k)

Constructs a key storage containing the given key body and version k.

Parameters:

k – Key body.

constexpr key_storage(key_body_t k, std::uint8_t v)

Constructs a key storage containing the given key body k and the version v.

Parameters:
  • k – Key body.

  • v – Version (takes over what can be extracted from k).

constexpr std::uint8_t version() const

Version of the key. The version is encoded in the parity bits of the key body.

Returns:

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

inline void set_version(std::uint8_t v)

Changes the key version to v. The version is encoded in the parity bits of the key body.

Parameters:

v – A byte.

constexpr key_body_t const &body() const

Accesses the internal key body.

inline void set_body(key_body_t k)

Changes the key body.

Note

This will change the key version. The rationale is that the incoming data is from a known key, therefore it is ok to carry on the version. If you are generating a random key, use randomize.

Parameters:

k – Key body.

void randomize(random_oracle rng)

Randomizes the key.

Note

This does not change the key version.

Parameters:

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

Public Static Attributes

static constexpr std::size_t size = KeyLength

Key length alias.

Protected Attributes

key_body_t _body = {}