CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
GpgStorage.h File Reference
#include <cstdint>
#include <cstddef>

Go to the source code of this file.

Functions

void gpg_storage_set_slot_range (uint16_t eccStart, uint16_t eccEnd)
void gpg_storage_set_rmem_range (uint16_t rmemStart, uint16_t rmemEnd)
bool gpg_storage_ready (void)
uint8_t gpg_storage_sig_slot (void)
uint8_t gpg_storage_dec_slot (void)
uint8_t gpg_storage_aut_slot (void)
bool gpg_storage_save_dec_privkey (const uint8_t *privkey, const char *pin)
 Saves a DEC private key into R-Memory using PIN-bound AES-GCM.
bool gpg_storage_load_dec_privkey (uint8_t *privkey_out, const char *pin)
 Loads and decrypts the DEC private key from R-Memory.
bool gpg_storage_has_dec_privkey (void)
 Returns true if encrypted DEC private key record exists.
bool gpg_storage_delete_dec_privkey (void)
 Deletes DEC private key record.
bool gpg_storage_save_aes_key (const uint8_t *key, size_t key_len, const char *pin)
 Saves the symmetric AES key for PSO:DECIPHER (DO 0xD5).
bool gpg_storage_load_aes_key (uint8_t *key_out, size_t *key_len_out, const char *pin)
 Loads the symmetric AES key from R-Memory.
bool gpg_storage_has_aes_key (void)
 Returns true if a symmetric AES key record exists.
bool gpg_storage_delete_aes_key (void)
 Deletes the symmetric AES key record.
bool gpg_storage_get_session_key (uint8_t *key_out)
 Returns current session key if session is active.
void gpg_storage_set_session_pin (const char *pin)
 Stores session PIN-derived key after successful PIN verification.
void gpg_storage_clear_session (void)
 Clears the cached session key.

Function Documentation

◆ gpg_storage_aut_slot()

uint8_t gpg_storage_aut_slot ( void )

◆ gpg_storage_clear_session()

void gpg_storage_clear_session ( void )

Clears the cached session key.

Definition at line 467 of file GpgStorage.cpp.

References s_storage.

Referenced by cmd_select(), gpg_storage_set_session_pin(), and openpgp_factory_reset().

◆ gpg_storage_dec_slot()

uint8_t gpg_storage_dec_slot ( void )

Definition at line 208 of file GpgStorage.cpp.

References s_storage.

Referenced by cmd_get_data(), get_ecc_slot_for_key_ref(), and gpg_generate_key().

◆ gpg_storage_delete_aes_key()

bool gpg_storage_delete_aes_key ( void )

Deletes the symmetric AES key record.

Definition at line 439 of file GpgStorage.cpp.

References get_se(), cdc::hal::OK, resolve_slot(), and RMEM_SLOT_AES_KEY.

◆ gpg_storage_delete_dec_privkey()

bool gpg_storage_delete_dec_privkey ( void )

Deletes DEC private key record.

Definition at line 378 of file GpgStorage.cpp.

References get_se(), cdc::hal::OK, resolve_slot(), and RMEM_SLOT_DEC_KEY.

Referenced by openpgp_factory_reset().

◆ gpg_storage_get_session_key()

bool gpg_storage_get_session_key ( uint8_t * key_out)

Returns current session key if session is active.

Parameters
key_out32-byte output buffer.
Returns
true if session key is available.

Definition at line 459 of file GpgStorage.cpp.

References s_storage.

◆ gpg_storage_has_aes_key()

bool gpg_storage_has_aes_key ( void )

Returns true if a symmetric AES key record exists.

Definition at line 427 of file GpgStorage.cpp.

References AES_KEY_MAGIC, get_se(), MAGIC_SIZE, cdc::hal::OK, resolve_slot(), and RMEM_SLOT_AES_KEY.

Referenced by cmd_pso_decipher_aes().

◆ gpg_storage_has_dec_privkey()

bool gpg_storage_has_dec_privkey ( void )

Returns true if encrypted DEC private key record exists.

Definition at line 366 of file GpgStorage.cpp.

References DEC_KEY_MAGIC, DEC_TOTAL_SIZE, get_se(), MAGIC_SIZE, cdc::hal::OK, resolve_slot(), and RMEM_SLOT_DEC_KEY.

Referenced by cmd_pso_decipher(), and read_public_key().

◆ gpg_storage_load_aes_key()

bool gpg_storage_load_aes_key ( uint8_t * key_out,
size_t * key_len_out,
const char * pin )

Loads the symmetric AES key from R-Memory.

Parameters
key_outOutput buffer (must hold at least 32 bytes).
key_len_outReceives the stored key length (16 or 32).
pinSession PIN; nullptr falls back to chip-bound key.
Returns
true on success.

Definition at line 408 of file GpgStorage.cpp.

References AES_KEY_MAGIC, AES_RECORD_PAYLOAD, load_slot_decrypted(), resolve_slot(), and RMEM_SLOT_AES_KEY.

Referenced by cmd_pso_decipher_aes().

◆ gpg_storage_load_dec_privkey()

bool gpg_storage_load_dec_privkey ( uint8_t * privkey_out,
const char * pin )

Loads and decrypts the DEC private key from R-Memory.

Parameters
privkey_out32-byte output buffer.
pinSession PIN; nullptr falls back to chip-bound key.
Returns
true on success.

Definition at line 360 of file GpgStorage.cpp.

References DEC_KEY_MAGIC, load_slot_decrypted(), PRIVKEY_SIZE, resolve_slot(), and RMEM_SLOT_DEC_KEY.

Referenced by cmd_pso_decipher(), and read_public_key().

◆ gpg_storage_ready()

bool gpg_storage_ready ( void )

◆ gpg_storage_save_aes_key()

bool gpg_storage_save_aes_key ( const uint8_t * key,
size_t key_len,
const char * pin )

Saves the symmetric AES key for PSO:DECIPHER (DO 0xD5).

Parameters
keyAES key bytes (16 or 32).
key_lenKey length (16 or 32).
pinSession PIN; nullptr falls back to chip-bound key.
Returns
true on success.

Definition at line 385 of file GpgStorage.cpp.

References AES_KEY_MAGIC, AES_MAX_KEY_SIZE, AES_RECORD_PAYLOAD, AES_TOTAL_SIZE, LOG_I, resolve_slot(), RMEM_SLOT_AES_KEY, save_slot_encrypted(), and TAG.

Referenced by cmd_put_data().

◆ gpg_storage_save_dec_privkey()

bool gpg_storage_save_dec_privkey ( const uint8_t * privkey,
const char * pin )

Saves a DEC private key into R-Memory using PIN-bound AES-GCM.

Parameters
privkey32-byte P-256 private key scalar.
pinSession PIN; nullptr falls back to chip-bound key.
Returns
true on success.

Definition at line 347 of file GpgStorage.cpp.

References DEC_KEY_MAGIC, DEC_TOTAL_SIZE, LOG_I, PRIVKEY_SIZE, resolve_slot(), RMEM_SLOT_DEC_KEY, save_slot_encrypted(), and TAG.

Referenced by cmd_put_data_odd(), generate_dec_key(), and gpg_generate_key().

◆ gpg_storage_set_rmem_range()

void gpg_storage_set_rmem_range ( uint16_t rmemStart,
uint16_t rmemEnd )

Definition at line 201 of file GpgStorage.cpp.

References s_storage.

Referenced by cdc::mod_gpg::GpgModule::init().

◆ gpg_storage_set_session_pin()

void gpg_storage_set_session_pin ( const char * pin)

Stores session PIN-derived key after successful PIN verification.

Parameters
pinVerified PIN string.

Definition at line 446 of file GpgStorage.cpp.

References gpg_storage_clear_session(), pin_to_hash(), and s_storage.

Referenced by cmd_verify().

◆ gpg_storage_set_slot_range()

void gpg_storage_set_slot_range ( uint16_t eccStart,
uint16_t eccEnd )

Definition at line 186 of file GpgStorage.cpp.

References s_storage.

Referenced by cdc::mod_gpg::GpgModule::init().

◆ gpg_storage_sig_slot()