Botan 3.11.0
Crypto and TLS for C&
Botan::Stateful_Key_Index_Registry Class Referencefinal

#include <stateful_key_index_registry.h>

Classes

class  KeyId

Public Member Functions

uint64_t current_index (const KeyId &key_id)
Stateful_Key_Index_Registryoperator= (const Stateful_Key_Index_Registry &)=delete
Stateful_Key_Index_Registryoperator= (Stateful_Key_Index_Registry &&)=delete
uint64_t remaining_operations (const KeyId &key_id, uint64_t max)
uint64_t reserve_next_index (const KeyId &key_id)
void set_index_lower_bound (const KeyId &key_id, uint64_t min)
 Stateful_Key_Index_Registry (const Stateful_Key_Index_Registry &)=delete
 Stateful_Key_Index_Registry (Stateful_Key_Index_Registry &&)=delete
 ~Stateful_Key_Index_Registry ()

Static Public Member Functions

static Stateful_Key_Index_Registryglobal ()

Detailed Description

A process-wide registry mapping stateful key identity to a shared atomic counter. Ensures that independent copies of the same key material (e.g. deserialized separately) share a single leaf index, preventing catastrophic one-time signature reuse.

Used by XMSS and HSS-LMS.

Definition at line 28 of file stateful_key_index_registry.h.

Constructor & Destructor Documentation

◆ Stateful_Key_Index_Registry() [1/2]

Botan::Stateful_Key_Index_Registry::Stateful_Key_Index_Registry ( const Stateful_Key_Index_Registry & )
delete

◆ Stateful_Key_Index_Registry() [2/2]

Botan::Stateful_Key_Index_Registry::Stateful_Key_Index_Registry ( Stateful_Key_Index_Registry && )
delete

◆ ~Stateful_Key_Index_Registry()

Botan::Stateful_Key_Index_Registry::~Stateful_Key_Index_Registry ( )
default

Member Function Documentation

◆ current_index()

uint64_t Botan::Stateful_Key_Index_Registry::current_index ( const KeyId & key_id)

Return the current counter

Definition at line 51 of file stateful_key_index_registry.cpp.

51 {
52 const lock_guard_type<mutex_type> lock(m_mutex);
53 auto idx = this->lookup(key_id);
54 return idx->second;
55}
secure_vector< T > lock(const std::vector< T > &in)
Definition secmem.h:80
lock_guard< T > lock_guard_type
Definition mutex.h:55

References Botan::lock().

Referenced by Botan::HSS_LMS_PrivateKeyInternal::to_bytes().

◆ global()

Stateful_Key_Index_Registry & Botan::Stateful_Key_Index_Registry::global ( )
static

Retrieve the process-wide instance

Definition at line 15 of file stateful_key_index_registry.cpp.

15 {
16 static Stateful_Key_Index_Registry g_registry;
17 return g_registry;
18}
Stateful_Key_Index_Registry(const Stateful_Key_Index_Registry &)=delete

References Stateful_Key_Index_Registry().

Referenced by Botan::HSS_LMS_PrivateKeyInternal::remaining_operations(), Botan::HSS_LMS_PrivateKeyInternal::set_idx(), and Botan::HSS_LMS_PrivateKeyInternal::to_bytes().

◆ operator=() [1/2]

Stateful_Key_Index_Registry & Botan::Stateful_Key_Index_Registry::operator= ( const Stateful_Key_Index_Registry & )
delete

◆ operator=() [2/2]

Stateful_Key_Index_Registry & Botan::Stateful_Key_Index_Registry::operator= ( Stateful_Key_Index_Registry && )
delete

◆ remaining_operations()

uint64_t Botan::Stateful_Key_Index_Registry::remaining_operations ( const KeyId & key_id,
uint64_t max )

If the current counter is >= max returns 0, otherwise max - counter

Definition at line 71 of file stateful_key_index_registry.cpp.

71 {
72 const lock_guard_type<mutex_type> lock(m_mutex);
73 const uint64_t idx = this->lookup(key_id)->second;
74
75 if(idx >= max) {
76 return 0;
77 } else {
78 return max - idx;
79 }
80}

References Botan::lock().

◆ reserve_next_index()

uint64_t Botan::Stateful_Key_Index_Registry::reserve_next_index ( const KeyId & key_id)

Return a new counter

Definition at line 57 of file stateful_key_index_registry.cpp.

57 {
58 const lock_guard_type<mutex_type> lock(m_mutex);
59 auto idx = this->lookup(key_id);
60 const uint64_t cur = idx->second;
61 idx->second += 1;
62 return cur;
63}

References Botan::lock().

◆ set_index_lower_bound()

void Botan::Stateful_Key_Index_Registry::set_index_lower_bound ( const KeyId & key_id,
uint64_t min )

Set the counter to at least min (but if already higher it will retain its current value)

Definition at line 65 of file stateful_key_index_registry.cpp.

65 {
66 const lock_guard_type<mutex_type> lock(m_mutex);
67 auto idx = this->lookup(key_id);
68 idx->second = std::max(idx->second, min);
69}

References Botan::lock().

Referenced by Botan::HSS_LMS_PrivateKeyInternal::set_idx().


The documentation for this class was generated from the following files: