22 out[0] = (v >> 24) & 0xFF;
23 out[1] = (v >> 16) & 0xFF;
24 out[2] = (v >> 8) & 0xFF;
28uint32_t
readBe32(
const uint8_t* in) {
29 return (
static_cast<uint32_t
>(in[0]) << 24) |
30 (
static_cast<uint32_t
>(in[1]) << 16) |
31 (
static_cast<uint32_t
>(in[2]) << 8) |
32 static_cast<uint32_t
>(in[3]);
47 uint8_t pubkey[64] = {0};
57 uint8_t dec_pubkey[64] = {0};
58 uint32_t dec_created_at = 0;
59 uint8_t self_sig[64] = {0};
60 uint8_t binding_sig[64] = {0};
65 const size_t uid_len = strnlen(status.
user_id,
sizeof(status.
user_id));
66 const size_t total = 1 + 1 + pubkey_len + 4 + 20 + 1 + uid_len +
kGpgKeyDecBlock;
67 if (total > out_size)
return 0;
71 out[off++] = pubkey_len;
72 std::memcpy(out + off, pubkey, pubkey_len);
78 out[off++] =
static_cast<uint8_t
>(uid_len);
79 std::memcpy(out + off, status.
user_id, uid_len);
81 writeBe32(out + off, dec_created_at);
83 std::memcpy(out + off, dec_pubkey, 64);
85 std::memcpy(out + off, self_sig, 64);
87 std::memcpy(out + off, binding_sig, 64);
94 if (pubkey_len != 32 && pubkey_len != 64)
return 0;
97 const size_t total = 1 + 1 + pubkey_len + 4 + 20 + 1 + uid_len +
kGpgKeyDecBlock;
98 if (total > out_size)
return 0;
101 out[off++] = key.
curve;
102 out[off++] = pubkey_len;
103 std::memcpy(out + off, key.
pubkey, pubkey_len);
109 out[off++] =
static_cast<uint8_t
>(uid_len);
110 std::memcpy(out + off, key.
user_id, uid_len);
124 if (!data || !out)
return false;
128 const uint8_t
curve = data[off++];
131 const uint8_t pubkey_len = data[off++];
134 if (off + pubkey_len + 4 + 20 + 1 > len)
return false;
136 std::memset(out, 0,
sizeof(*out));
139 std::memcpy(out->
pubkey, data + off, pubkey_len);
146 const uint8_t uid_len = data[off++];
147 if (uid_len > 63 || off + uid_len > len)
return false;
148 std::memcpy(out->
user_id, data + off, uid_len);
167 uint8_t recomputed_fp[20] = {0};
172 if (std::memcmp(recomputed_fp, out->
fingerprint_v4, 20) != 0)
return false;
174 out->
received_at =
static_cast<uint32_t
>(std::time(
nullptr));
Transport-agnostic (de)serialisation of a GPG public key.
uint8_t gpg_storage_sig_slot(void)
#define CDC_CURVE_ED25519
bool gpg_get_status(gpg_status_t *status)
Fills status from the OpenPGP card-application state.
uint32_t readBe32(const uint8_t *in)
Reads a 32-bit value from a buffer in big-endian order.
void writeBe32(uint8_t *out, uint32_t v)
Writes a 32-bit value to a buffer in big-endian order.
ISecureElement * getSecureElementInstance()
Returns singleton secure-element stub instance.
constexpr size_t kGpgKeyDecBlock
Fixed-size trailing DEC encryption-subkey block.
bool gpgBuildOwnSubkeyMaterial(uint8_t dec_pubkey[64], uint32_t *dec_created_at, uint8_t self_sig[64], uint8_t binding_sig[64])
Gather the badge's own encryption-subkey material for transfer.
bool calculateFingerprintV4(uint8_t curve, const uint8_t *pubkey, size_t pubkey_len, uint32_t created_at, uint8_t out_fp[20])
Compute the RFC 4880 V4 OpenPGP fingerprint (SHA-1, 20 bytes).
size_t gpgBuildRecvKeyPayload(const gpg_recv_key_t &key, uint8_t *out, size_t out_size)
Serialise a stored received key into the wire payload (for forwarding).
size_t gpgBuildOwnKeyPayload(uint8_t *out, size_t out_size)
Serialise the badge's own public key into the wire payload.
constexpr size_t kGpgKeyPayloadMin
Minimum payload size (Ed25519 + empty user id + DEC block).
bool gpgParseKeyPayload(const uint8_t *data, size_t len, gpg_recv_key_t *out)
Parse a wire payload into a key record, computing the V5 fingerprint.
bool calculateFingerprintV5(uint8_t curve, const uint8_t *pubkey, size_t pubkey_len, uint32_t created_at, uint8_t out_fp[32])
Compute the V5 / RFC 9580 OpenPGP fingerprint (SHA-256, 32 bytes).
One GPG public key received from another badge.
uint8_t fingerprint_v4[20]
uint8_t owner_self_sig[64]
uint8_t fingerprint_v5[32]
uint8_t dec_binding_sig[64]
Snapshot of the current OpenPGP card-application state for UI display.