Skip to content

Commit

Permalink
More code formatting and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurence Lundblade committed Nov 16, 2023
1 parent a0c1abe commit 157ab33
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions src/t_cose_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,30 +314,26 @@ hmac_bstr(struct t_cose_crypto_hmac *hmac_ctx,
* Public function. See t_cose_util.h
*/
enum t_cose_err_t
create_tbm(const int32_t cose_algorithm_id,
struct t_cose_key mac_key,
bool is_mac0,
const struct t_cose_sign_inputs *mac_inputs,
const struct q_useful_buf tag_buf,
struct q_useful_buf_c *mac_tag)
create_tbm(const int32_t cose_algorithm_id,
struct t_cose_key mac_key,
bool is_mac0,
const struct t_cose_sign_inputs *mac_inputs,
const struct q_useful_buf tag_buf,
struct q_useful_buf_c *mac_tag)
{
enum t_cose_err_t return_value;
struct t_cose_crypto_hmac hmac_ctx;
struct q_useful_buf_c first_part;

enum t_cose_err_t return_value;
struct t_cose_crypto_hmac hmac_ctx;
struct q_useful_buf_c first_part;

/*
* Start the HMAC.
* Calculate the tag of the first part of ToBeMaced and the wrapped
* payload, to save a bigger buffer containing the entire ToBeMaced.
*/
return_value = t_cose_crypto_hmac_setup(&hmac_ctx,
mac_key,
cose_algorithm_id);
if(return_value) {
return return_value;
}

/* Same approach as hash_bstr(). See comments in hash_bstr() */

if(is_mac0) {
/* 0x84 is array of 4, 0x64 is length of a 4 text string in CBOR */
first_part = Q_USEFUL_BUF_FROM_SZ_LITERAL("\x84\x64" COSE_MAC_CONTEXT_STRING_MAC0);
Expand Down Expand Up @@ -397,17 +393,17 @@ create_tbs(const struct t_cose_sign_inputs *sign_inputs,


/**
* \brief Hash an encoded bstr without actually encoding it in memory.
*
* @param hash_ctx Hash context to hash it into.
* @param bstr Bytes of the bstr.
*
* If \c bstr is \c NULL_Q_USEFUL_BUF_C, a zero-length bstr will be
* hashed into the output.
*/
static void hash_bstr(struct t_cose_crypto_hash *hash_ctx,
struct q_useful_buf_c bstr)
{
* \brief Hash an encoded bstr without actually encoding it in memory.
*
* @param hash_ctx Hash context to hash it into.
* @param bstr Bytes of the bstr.
*
* If \c bstr is \c NULL_Q_USEFUL_BUF_C, a zero-length bstr will be
* hashed into the output.
*/
static void hash_bstr(struct t_cose_crypto_hash *hash_ctx,
struct q_useful_buf_c bstr)
{
/* Aproximate stack usage
* 64-bit 32-bit
* buffer_for_encoded 9 9
Expand Down

0 comments on commit 157ab33

Please sign in to comment.