CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
KeyFingerprint.cpp File Reference
#include "cdc_core/KeyFingerprint.h"
#include "cdc_hal/ISecureElement.h"
#include "mbedtls/sha256.h"
#include <string.h>

Go to the source code of this file.

Functions

const char * key_fingerprint_word (uint8_t index)
 Returns alchemical word for 5-bit index.
bool key_fingerprint_from_pubkey (const uint8_t *pubkey, size_t pubkey_len, char *buf, size_t len)
 Generates human-readable fingerprint from public key bytes.
bool key_fingerprint_generate (uint8_t slot, char *buf, size_t len)
 Reads public key from secure element slot and generates fingerprint.

Variables

static constexpr size_t SHA256_DIGEST_SIZE = 32
 Alchemical key fingerprints shared by FIDO and OpenPGP features.
static constexpr size_t P256_PUBKEY_RAW_SIZE = 64
 Uncompressed P-256 public key length in raw X||Y form (no SEC1 prefix).
static constexpr size_t ED25519_PUBKEY_SIZE = 32
 Ed25519 public key length in bytes (raw, RFC 8032).
static const char *const ALCHEMY_WORDS [32]
 Lookup table of 32 alchemical element labels (5-bit index space).

Function Documentation

◆ key_fingerprint_from_pubkey()

bool key_fingerprint_from_pubkey ( const uint8_t * pubkey,
size_t pubkey_len,
char * buf,
size_t len )

Generates human-readable fingerprint from public key bytes.

Parameters
pubkeyPublic key buffer.
pubkey_lenLength of pubkey.
bufOutput string buffer.
lenSize of output buffer.
Returns
true on success.

Definition at line 49 of file KeyFingerprint.cpp.

References ALCHEMY_WORDS, KEY_FINGERPRINT_MAX_LEN, KEY_FINGERPRINT_WORD_COUNT, and SHA256_DIGEST_SIZE.

Referenced by key_fingerprint_generate(), and cdc::mod_fido2::showDetail().

◆ key_fingerprint_generate()

bool key_fingerprint_generate ( uint8_t slot,
char * buf,
size_t len )

Reads public key from secure element slot and generates fingerprint.

Parameters
slotSecure-element slot number.
bufOutput string buffer.
lenSize of output buffer.
Returns
true if a key was read and fingerprint generated.

Definition at line 83 of file KeyFingerprint.cpp.

References curve, cdc::hal::ED25519, ED25519_PUBKEY_SIZE, cdc::hal::getSecureElementInstance(), key_fingerprint_from_pubkey(), KEY_FINGERPRINT_MAX_LEN, cdc::hal::OK, cdc::hal::P256, and P256_PUBKEY_RAW_SIZE.

Referenced by gpg_alchemy_fingerprint().

◆ key_fingerprint_word()

const char * key_fingerprint_word ( uint8_t index)

Returns alchemical word for 5-bit index.

Parameters
indexWord index in range [0,31].
Returns
Word string or "?" for invalid index.

Definition at line 36 of file KeyFingerprint.cpp.

References ALCHEMY_WORDS.

Variable Documentation

◆ ALCHEMY_WORDS

const char* const ALCHEMY_WORDS[32]
static
Initial value:
= {
"Fire", "Water", "Earth", "Air",
"Aether", "Sulfur", "Mercury", "Salt",
"Gold", "Silver", "Copper", "Iron",
"Tin", "Lead", "Antimony", "Arsenic",
"Bismuth", "Phosphorus", "Platinum", "Zinc",
"Magnesium", "Potassium", "Vitriol", "Aquafortis",
"Alkahest", "Azoth", "Cinnabar", "Nitre",
"Calx", "Regulus", "Quintessence","Stone"
}

Lookup table of 32 alchemical element labels (5-bit index space).

Definition at line 20 of file KeyFingerprint.cpp.

Referenced by key_fingerprint_from_pubkey(), and key_fingerprint_word().

◆ ED25519_PUBKEY_SIZE

size_t ED25519_PUBKEY_SIZE = 32
staticconstexpr

Ed25519 public key length in bytes (raw, RFC 8032).

Definition at line 15 of file KeyFingerprint.cpp.

◆ P256_PUBKEY_RAW_SIZE

size_t P256_PUBKEY_RAW_SIZE = 64
staticconstexpr

Uncompressed P-256 public key length in raw X||Y form (no SEC1 prefix).

Definition at line 13 of file KeyFingerprint.cpp.

◆ SHA256_DIGEST_SIZE

size_t SHA256_DIGEST_SIZE = 32
staticconstexpr

Alchemical key fingerprints shared by FIDO and OpenPGP features.

Size of a SHA-256 digest in bytes (FIPS 180-4).

Definition at line 11 of file KeyFingerprint.cpp.