CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
fido2_common.h
Go to the documentation of this file.
1
// FIDO2 Common Helpers
2
// Shared utility functions used across the FIDO2 module
3
4
#pragma once
5
#include <
cdc_hal/ISecureElement.h
>
6
#include <mbedtls/sha256.h>
7
#include <cstdint>
8
#include <cstddef>
9
#include <cstring>
10
11
// ============================================================================
12
// FIDO2 cryptographic component sizes (NIST P-256 / Ed25519)
13
// - NIST P-256 (secp256r1): 32-byte R and S components, 64-byte raw R||S
14
// - Ed25519: 64-byte signature, 32-byte public key
15
// - SHA-256: 32-byte digest
16
// ============================================================================
17
#define FIDO2_SHA256_DIGEST_SIZE 32
18
#define FIDO2_PUBKEY_COMPONENT_SIZE 32
// Size of single coordinate (X or Y)
19
#define FIDO2_PRIVKEY_SIZE 32
// P-256 / Ed25519 private key size
20
#define FIDO2_SIG_COMPONENT_SIZE 32
// Size of single ECDSA component (R or S)
21
#define FIDO2_SIG_SIZE 64
// Raw ECDSA P-256 (R||S) and Ed25519 signature size
22
#define FIDO2_P256_UNCOMPRESSED_SIZE 65
// 0x04 || X || Y
23
#define FIDO2_P256_PUBKEY_XY_SIZE 64
// X || Y without prefix
24
25
namespace
cdc
{
26
namespace
mod_fido2 {
27
28
// Compute SHA-256 hash
29
inline
void
sha256
(
const
uint8_t* data,
size_t
len, uint8_t out[
FIDO2_SHA256_DIGEST_SIZE
]) {
30
mbedtls_sha256(data, len, out, 0);
31
}
32
33
// Compute SHA-256 of null-terminated string
34
inline
void
sha256_str
(
const
char
* str, uint8_t out[
FIDO2_SHA256_DIGEST_SIZE
]) {
35
sha256
(
reinterpret_cast<
const
uint8_t*
>
(str), std::strlen(str), out);
36
}
37
38
}
// namespace mod_fido2
39
}
// namespace cdc
40
ISecureElement.h
FIDO2_SHA256_DIGEST_SIZE
#define FIDO2_SHA256_DIGEST_SIZE
Definition
fido2_common.h:17
cdc::mod_fido2::sha256_str
void sha256_str(const char *str, uint8_t out[32])
Definition
fido2_common.h:34
cdc::mod_fido2::sha256
void sha256(const uint8_t *data, size_t len, uint8_t out[32])
Definition
fido2_common.h:29
cdc
Definition
AttestationKeyService.h:7
components
mod_fido2
include
mod_fido2
fido2_common.h
Generated by
1.16.1