18constexpr uint8_t kOidP256[] = { 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07 };
19constexpr uint8_t kOidEd25519[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01 };
20constexpr uint8_t kOidX25519[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x97, 0x55, 0x01, 0x05, 0x01 };
22constexpr size_t kP256Len =
sizeof(kOidP256);
23constexpr size_t kEd25519Len =
sizeof(kOidEd25519);
24constexpr size_t kX25519Len =
sizeof(kOidX25519);
38 default:
return false;
42bool is_known_algo(uint8_t
id) {
47bool is_rsa_modulus_bits(uint16_t n_bits) {
48 return n_bits == 2048 || n_bits == 3072 || n_bits == 4096;
57 memset(out, 0,
sizeof(*out));
64 out->
rsa_n_bits =
static_cast<uint16_t
>((bytes[1] << 8) | bytes[2]);
65 out->
rsa_e_bits =
static_cast<uint16_t
>((bytes[3] << 8) | bytes[4]);
75 const uint8_t *oid = bytes + 1;
76 size_t oid_len = len - 1;
77 if (oid_len > 0 && oid[oid_len - 1] == 0xFF) {
82 out->
curve = classify_oid(oid, oid_len);
87 size_t out_cap,
size_t *out_len) {
95 out[1] =
static_cast<uint8_t
>((attr->
rsa_n_bits >> 8) & 0xFF);
96 out[2] =
static_cast<uint8_t
>(attr->
rsa_n_bits & 0xFF);
97 out[3] =
static_cast<uint8_t
>((attr->
rsa_e_bits >> 8) & 0xFF);
98 out[4] =
static_cast<uint8_t
>(attr->
rsa_e_bits & 0xFF);
104 const uint8_t *oid =
nullptr;
111 memcpy(out + 1, oid, oid_len);
139 bool rsa_supported) {
144 switch (attr->
curve) {
algo_attr_status_t algo_attr_validate_role(const algo_attr_t *attr, algo_attr_role_t role)
Check whether the parsed attribute is compatible with the key role it will be installed into.
algo_attr_status_t algo_attr_parse(const uint8_t *bytes, size_t len, algo_attr_t *out)
Parse a raw algorithm-attribute byte sequence into structured form.
algo_attr_status_t algo_attr_validate_capability(const algo_attr_t *attr, bool rsa_supported)
Check whether the badge's secure element / mbedTLS combination can actually execute this algorithm.
algo_attr_status_t algo_attr_build(const algo_attr_t *attr, uint8_t *out, size_t out_cap, size_t *out_len)
Serialise an algorithm-attribute structure to bytes.
algo_attr_role_t
Key role (selects which DO tag is being parsed / built).
algo_attr_curve_t
Curves the firmware recognises. UNKNOWN flags unsupported OIDs.
@ ALGO_ATTR_CURVE_UNKNOWN
@ ALGO_ATTR_CURVE_ED25519
algo_attr_status_t
Outcome of algo-attribute operations.
@ ALGO_ATTR_ERR_BAD_CURVE
@ ALGO_ATTR_ERR_BUF_TOO_SMALL
@ ALGO_ATTR_ERR_TOO_SHORT
@ ALGO_ATTR_ERR_ROLE_MISMATCH
Parsed algorithm-attribute payload.