|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
#include <cstdint>#include <cstddef>Go to the source code of this file.
Macros | |
| #define | GPG_RSA_BLOB_MAX 560 |
| Maximum serialized RSA private-key blob (RSA-4096 n_bits||e||p||q). | |
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. | |
| void | gpg_storage_set_rsa_slot_range (uint16_t start, uint16_t end) |
| Sets the dedicated R-Memory range used for RSA private-key blobs. | |
| bool | gpg_storage_save_rsa_key (uint8_t role, const uint8_t *blob, size_t blob_len, const char *pin) |
| Saves an encrypted RSA private-key blob for a key role. | |
| bool | gpg_storage_load_rsa_key (uint8_t role, uint8_t *blob_out, size_t blob_cap, size_t *blob_len_out, const char *pin) |
| Loads and decrypts the RSA private-key blob for a key role. | |
| bool | gpg_storage_has_rsa_key (uint8_t role) |
| Returns true if an RSA private-key blob exists for the role. | |
| bool | gpg_storage_delete_rsa_key (uint8_t role) |
| Deletes the RSA private-key blob for the role (both slots). | |
| 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. | |
| #define GPG_RSA_BLOB_MAX 560 |
Maximum serialized RSA private-key blob (RSA-4096 n_bits||e||p||q).
Definition at line 64 of file GpgStorage.h.
Referenced by build_rsa_pubkey_from_storage(), cmd_generate_keypair(), cmd_internal_authenticate(), cmd_pso_cds(), cmd_pso_decipher(), cmd_put_data_odd(), gpg_storage_load_rsa_key(), and gpg_storage_save_rsa_key().
| uint8_t gpg_storage_aut_slot | ( | void | ) |
Definition at line 210 of file GpgStorage.cpp.
References s_storage.
Referenced by cmd_get_data(), cmd_internal_authenticate(), cmd_put_data_odd(), get_ecc_slot_for_key_ref(), gpg_generate_key(), openpgp_factory_reset(), and wipe_role_key().
| void gpg_storage_clear_session | ( | void | ) |
Clears the cached session key.
Definition at line 659 of file GpgStorage.cpp.
References s_storage.
Referenced by cmd_select(), cmd_verify(), gpg_storage_set_session_pin(), and openpgp_factory_reset().
| uint8_t gpg_storage_dec_slot | ( | void | ) |
Definition at line 209 of file GpgStorage.cpp.
References s_storage.
Referenced by get_ecc_slot_for_key_ref(), and gpg_generate_key().
| bool gpg_storage_delete_aes_key | ( | void | ) |
Deletes the symmetric AES key record.
Definition at line 440 of file GpgStorage.cpp.
References get_se(), cdc::hal::OK, resolve_slot(), and RMEM_SLOT_AES_KEY.
| bool gpg_storage_delete_dec_privkey | ( | void | ) |
Deletes DEC private key record.
Definition at line 379 of file GpgStorage.cpp.
References get_se(), cdc::hal::OK, resolve_slot(), and RMEM_SLOT_DEC_KEY.
Referenced by openpgp_factory_reset(), and wipe_role_key().
| bool gpg_storage_delete_rsa_key | ( | uint8_t | role | ) |
Deletes the RSA private-key blob for the role (both slots).
Definition at line 628 of file GpgStorage.cpp.
References get_se(), cdc::hal::OK, and rsa_role_slots().
Referenced by openpgp_factory_reset(), and wipe_role_key().
| bool gpg_storage_get_session_key | ( | uint8_t * | key_out | ) |
Returns current session key if session is active.
| key_out | 32-byte output buffer. |
Definition at line 651 of file GpgStorage.cpp.
References s_storage.
| bool gpg_storage_has_aes_key | ( | void | ) |
Returns true if a symmetric AES key record exists.
Definition at line 428 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().
| bool gpg_storage_has_dec_privkey | ( | void | ) |
Returns true if encrypted DEC private key record exists.
Definition at line 367 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_get_data(), cmd_pso_decipher(), and read_public_key().
| bool gpg_storage_has_rsa_key | ( | uint8_t | role | ) |
Returns true if an RSA private-key blob exists for the role.
Definition at line 614 of file GpgStorage.cpp.
References get_se(), MAGIC_SIZE, cdc::hal::OK, RSA_KEY_MAGIC, RSA_REC_HEADER, and rsa_role_slots().
Referenced by cmd_get_data().
| 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.
| key_out | Output buffer (must hold at least 32 bytes). |
| key_len_out | Receives the stored key length (16 or 32). |
| pin | Session PIN; nullptr falls back to chip-bound key. |
Definition at line 409 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().
| bool gpg_storage_load_dec_privkey | ( | uint8_t * | privkey_out, |
| const char * | pin ) |
Loads and decrypts the DEC private key from R-Memory.
| privkey_out | 32-byte output buffer. |
| pin | Session PIN; nullptr falls back to chip-bound key. |
Definition at line 361 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(), gpg_get_dec_pubkey(), and read_public_key().
| bool gpg_storage_load_rsa_key | ( | uint8_t | role, |
| uint8_t * | blob_out, | ||
| size_t | blob_cap, | ||
| size_t * | blob_len_out, | ||
| const char * | pin ) |
Loads and decrypts the RSA private-key blob for a key role.
| role | 0 = SIG, 1 = DEC, 2 = AUT. |
| blob_out | Output buffer (>= GPG_RSA_BLOB_MAX bytes). |
| blob_cap | Capacity of blob_out. |
| blob_len_out | Receives the decrypted blob length. |
| pin | Session PIN; nullptr falls back to chip-bound key. |
Definition at line 544 of file GpgStorage.cpp.
References cdc::core::aesGcm256Open(), build_aad(), derive_storage_key(), get_se(), GPG_RSA_BLOB_MAX, MAGIC_SIZE, NONCE_SIZE, cdc::hal::OK, pin_to_hash(), RSA_ENVELOPE, RSA_KEY_MAGIC, RSA_REC_HEADER, rsa_role_slots(), and s_rsa_record.
Referenced by build_rsa_pubkey_from_storage(), cmd_internal_authenticate(), cmd_pso_cds(), and cmd_pso_decipher().
| bool gpg_storage_ready | ( | void | ) |
Definition at line 207 of file GpgStorage.cpp.
References s_storage.
Referenced by gpg_export_pubkey_pem(), gpg_generate_key(), gpg_init(), gpg_reset(), and cdc::mod_gpg::GpgModule::init().
| 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).
| key | AES key bytes (16 or 32). |
| key_len | Key length (16 or 32). |
| pin | Session PIN; nullptr falls back to chip-bound key. |
Definition at line 386 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().
| 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.
| privkey | 32-byte P-256 private key scalar. |
| pin | Session PIN; nullptr falls back to chip-bound key. |
Definition at line 348 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().
| bool gpg_storage_save_rsa_key | ( | uint8_t | role, |
| const uint8_t * | blob, | ||
| size_t | blob_len, | ||
| const char * | pin ) |
Saves an encrypted RSA private-key blob for a key role.
| role | 0 = SIG, 1 = DEC, 2 = AUT. |
| blob | Serialized RSA private material. |
| blob_len | Blob length (<= GPG_RSA_BLOB_MAX). |
| pin | Session PIN; nullptr falls back to chip-bound key. |
Definition at line 483 of file GpgStorage.cpp.
References cdc::core::aesGcm256Seal(), build_aad(), derive_storage_key(), get_se(), GPG_RSA_BLOB_MAX, LOG_E, LOG_I, MAGIC_SIZE, NONCE_SIZE, cdc::hal::OK, pin_to_hash(), RSA_ENVELOPE, RSA_KEY_MAGIC, RSA_REC_HEADER, rsa_role_slots(), RSA_SLOT_CAP, s_rsa_record, and TAG.
Referenced by cmd_generate_keypair(), and cmd_put_data_odd().
| void gpg_storage_set_rmem_range | ( | uint16_t | rmemStart, |
| uint16_t | rmemEnd ) |
Definition at line 202 of file GpgStorage.cpp.
References s_storage.
Referenced by cdc::mod_gpg::GpgModule::init().
| void gpg_storage_set_rsa_slot_range | ( | uint16_t | start, |
| uint16_t | end ) |
Sets the dedicated R-Memory range used for RSA private-key blobs.
Distinct from the primary GPG range; carved as mod_gpg_rsa in the slot map. Each of the three roles occupies two consecutive slots so an RSA-4096 blob can span them.
| start | First absolute R-Memory slot of the RSA pool. |
| end | Last absolute R-Memory slot of the RSA pool. |
Definition at line 462 of file GpgStorage.cpp.
References s_rsa_rmem_end, and s_rsa_rmem_start.
Referenced by cdc::mod_gpg::GpgModule::init().
| void gpg_storage_set_session_pin | ( | const char * | pin | ) |
Stores session PIN-derived key after successful PIN verification.
| pin | Verified PIN string. |
Definition at line 638 of file GpgStorage.cpp.
References gpg_storage_clear_session(), pin_to_hash(), and s_storage.
Referenced by cmd_verify().
| void gpg_storage_set_slot_range | ( | uint16_t | eccStart, |
| uint16_t | eccEnd ) |
Definition at line 187 of file GpgStorage.cpp.
References s_storage.
Referenced by cdc::mod_gpg::GpgModule::init().
| uint8_t gpg_storage_sig_slot | ( | void | ) |
Definition at line 208 of file GpgStorage.cpp.
References s_storage.
Referenced by cmd_get_data(), cmd_pso_cds(), cmd_put_data_odd(), get_ecc_slot_for_key_ref(), gpg_alchemy_fingerprint(), gpg_export_pubkey_pem(), gpg_generate_key(), gpg_get_status(), cdc::mod_gpg::gpgBuildOwnKeyPayload(), cdc::mod_gpg::gpgCrossSign(), openpgp_factory_reset(), and wipe_role_key().