Skip to content

Commit

Permalink
[dice,cwt] Add more wrappers for cbor library
Browse files Browse the repository at this point in the history
It requires more wrappers to generate CDI

Bug: 356532759
Signed-off-by: Tommy Chiu <tommychiu@google.com>
  • Loading branch information
tommychiu-github authored and timothytrippel committed Oct 23, 2024
1 parent 6b4f055 commit 9d93ac1
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions sw/device/silicon_creator/lib/cert/cbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ static inline rom_error_t cbor_map_init(struct CborOut *p,
CBOR_CHECK_OVERFLOWED_AND_RETURN(p);
}

static inline rom_error_t cbor_array_init(struct CborOut *p,
const size_t num_elements) {
CborWriteArray(num_elements, p);
CBOR_CHECK_OVERFLOWED_AND_RETURN(p);
}

static inline rom_error_t cbor_write_string(struct CborOut *p,
const char *str) {
CborWriteTstr(str, p);
CBOR_CHECK_OVERFLOWED_AND_RETURN(p);
}

static inline rom_error_t cbor_write_bytes(struct CborOut *p,
const uint8_t *data,
const size_t data_size) {
CborWriteBstr(data_size, data, p);
CBOR_CHECK_OVERFLOWED_AND_RETURN(p);
}

// Wrappers to encode a pair of data for cbor-map
static inline rom_error_t cbor_write_pair_uint_uint(struct CborOut *p,
uint64_t key,
Expand All @@ -57,13 +76,30 @@ static inline rom_error_t cbor_write_pair_uint_int(struct CborOut *p,
}

static inline rom_error_t cbor_write_pair_int_bytes(struct CborOut *p,
int64_t key, uint8_t *value,
size_t value_size) {
int64_t key,
const uint8_t *value,
const size_t value_size) {
CborWriteInt(key, p);
CborWriteBstr(value_size, value, p);
CBOR_CHECK_OVERFLOWED_AND_RETURN(p);
}

static inline rom_error_t cbor_write_pair_uint_tstr(struct CborOut *p,
uint64_t key,
const char *value) {
CborWriteUint(key, p);
CborWriteTstr(value, p);
CBOR_CHECK_OVERFLOWED_AND_RETURN(p);
}

static inline rom_error_t cbor_write_pair_int_tstr(struct CborOut *p,
int64_t key,
const char *value) {
CborWriteInt(key, p);
CborWriteTstr(value, p);
CBOR_CHECK_OVERFLOWED_AND_RETURN(p);
}

#undef CBOR_CHECK_OVERFLOWED_AND_RETURN

#endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_CERT_CBOR_H_

0 comments on commit 9d93ac1

Please sign in to comment.