Skip to content

Commit

Permalink
Linting HAL
Browse files Browse the repository at this point in the history
  • Loading branch information
amendelzon committed May 21, 2024
1 parent a376ddd commit 3432e6e
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 84 deletions.
16 changes: 8 additions & 8 deletions ledger/src/hal/include/hal/communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,32 @@
*
* @param msg_buffer The buffer to use for communication
* @param msg_buffer_size The size of the message buffer in bytes
*
*
* @returns whether the initialisation succeeded
*/
bool communication_init(unsigned char* msg_buffer, size_t msg_buffer_size);

/**
* @brief Get a pointer to the message buffer
*
*
* @returns a pointer to the message buffer
*/
unsigned char* communication_get_msg_buffer();

/**
* @brief Get the message buffer size
*
*
* @returns the message buffer size
*/
size_t communication_get_msg_buffer_size();

/**
* @brief Exchanges bytes with the host. This function blocks until the host sends a
* message.
* @brief Exchanges bytes with the host. This function blocks until the host
* sends a message.
*
* The message exchanges data with the host using the msg_buffer. If there are any bytes
* to transmit, they are transmitted first. After that the function blocks until a new
* message is received from the host.
* The message exchanges data with the host using the msg_buffer. If there are
* any bytes to transmit, they are transmitted first. After that the function
* blocks until a new message is received from the host.
*
* @param tx The number of bytes sent to the host
*
Expand Down
15 changes: 8 additions & 7 deletions ledger/src/hal/include/hal/endorsement.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,39 @@

/**
* @brief Endorses the given message
*
*
* @param msg The message to attest
* @param msg_size The size of the message to attest
* @param signature_out Where the signature should be output
* @param signature_out_length [in/out] the length of the output buffer /
* length of the produced signature
*
*
* @returns whether endorsement succeeded
*/
bool endorsement_sign(uint8_t* msg, size_t msg_size,
bool endorsement_sign(uint8_t* msg,
size_t msg_size,
uint8_t* signature_out,
uint8_t* signature_out_length);

/**
* @brief Grabs the hash of the currently running code
*
*
* @param code_hash_out Where the code hash should be output
* @param code_hash_out_length [in/out] the length of the output buffer /
* length of the produced code hash
*
*
* @returns whether code hash gathering succeeded
*/
bool endorsement_get_code_hash(uint8_t* code_hash_out,
uint8_t* code_hash_out_length);

/**
* @brief Grabs the endorsement public key
*
*
* @param public_key_out Where the public key should be output
* @param public_key_out_length [in/out] the length of the output buffer /
* length of the produced public key
*
*
* @returns whether public key gathering succeeded
*/
bool endorsement_get_public_key(uint8_t* public_key_out,
Expand Down
54 changes: 30 additions & 24 deletions ledger/src/hal/include/hal/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,49 +51,51 @@ typedef SHA3_CTX hash_keccak256_ctx_t;
typedef SHA256_CTX hash_sha256_ms_ctx_t;

#else
#error "HSM Platform undefined"
#error "HSM Platform undefined"
#endif
// END of platform-dependent code

// *** sha256 ***

/**
* @brief Initialize a sha256 hash context
*
*
* @param[inout] ctx the context to initialize
*
*
* @returns whether the initialisation succeeded
*/
bool hash_sha256_init(hash_sha256_ctx_t* ctx);

/**
* @brief Update a sha256 hash context with given data
*
*
* @param[inout] ctx the context to update
* @param[in] data pointer to message to hash
* @param[in] len length of message in bytes
*
* @returns whether the update succeeded
*/
bool hash_sha256_update(hash_sha256_ctx_t* ctx, const uint8_t *data, size_t len);
bool hash_sha256_update(hash_sha256_ctx_t* ctx,
const uint8_t* data,
size_t len);

/**
* @brief Compute the final sha256 hash for the given context
*
*
* @param[inout] ctx the context to finalise
* @param[out] out_hash The final hash obtained from the incremental hash
*
*
* @returns whether the finalisation succeeded
*/
bool hash_sha256_final(hash_sha256_ctx_t* ctx, uint8_t *out_hash);
bool hash_sha256_final(hash_sha256_ctx_t* ctx, uint8_t* out_hash);

// *** sha256 with midstate support ***

/**
* @brief Initialize a sha256 ms hash context
*
*
* @param[inout] ctx the context to initialize
*
*
* @returns whether the initialisation succeeded
*/
bool hash_sha256_ms_init(hash_sha256_ms_ctx_t* ctx);
Expand All @@ -107,65 +109,69 @@ bool hash_sha256_ms_init(hash_sha256_ms_ctx_t* ctx);
* - midstate[8:16]: counter, as a big-endian uint64_t
* - midstate[16:48]: current hash, as 8 big-endian uint32_t integers
* - midstate[48:52]: ignore
*
*
* @param[inout] ctx the context to set
* @param[in] midstate pointer to midstate buffer
*
* @returns whether the midstate succeeded
*/
bool hash_sha256_ms_midstate(hash_sha256_ms_ctx_t* ctx, uint8_t *midstate);
bool hash_sha256_ms_midstate(hash_sha256_ms_ctx_t* ctx, uint8_t* midstate);

/**
* @brief Update a sha256 ms hash context with given data
*
*
* @param[inout] ctx the context to update
* @param[in] data pointer to message to hash
* @param[in] len length of message in bytes
*
* @returns whether the update succeeded
*/
bool hash_sha256_ms_update(hash_sha256_ms_ctx_t* ctx, const uint8_t *data, size_t len);
bool hash_sha256_ms_update(hash_sha256_ms_ctx_t* ctx,
const uint8_t* data,
size_t len);

/**
* @brief Compute the final sha256 ms hash for the given context
*
*
* @param[inout] ctx the context to finalise
* @param[out] out_hash The final hash obtained from the incremental hash
*
*
* @returns whether the finalisation succeeded
*/
bool hash_sha256_ms_final(hash_sha256_ms_ctx_t* ctx, uint8_t *out_hash);
bool hash_sha256_ms_final(hash_sha256_ms_ctx_t* ctx, uint8_t* out_hash);

// *** keccak256 ***

/**
* @brief Initialize a keccak256 hash context
*
*
* @param[inout] ctx the context to initialize
*
*
* @returns whether the initialisation succeeded
*/
bool hash_keccak256_init(hash_keccak256_ctx_t* ctx);

/**
* @brief Update a keccak256 hash context with given data
*
*
* @param[inout] ctx the context to update
* @param[in] data pointer to message to hash
* @param[in] len length of message in bytes
*
* @returns whether the update succeeded
*/
bool hash_keccak256_update(hash_keccak256_ctx_t* ctx, const uint8_t *data, size_t len);
bool hash_keccak256_update(hash_keccak256_ctx_t* ctx,
const uint8_t* data,
size_t len);

/**
* @brief Compute the final keccak256 hash for the given context
*
*
* @param[inout] ctx the context to finalise
* @param[out] out_hash The final hash obtained from the incremental hash
*
*
* @returns whether the finalisation succeeded
*/
bool hash_keccak256_final(hash_keccak256_ctx_t* ctx, uint8_t *out_hash);
bool hash_keccak256_final(hash_keccak256_ctx_t* ctx, uint8_t* out_hash);

#endif // __HAL_HASH_H
4 changes: 2 additions & 2 deletions ledger/src/hal/include/hal/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "srlp.h"

/** Set a prefix for all logs */
void LOG_SET_PREFIX(char* prefix);
void LOG_SET_PREFIX(char *prefix);

/** Works just like printf */
void LOG(const char *format, ...);
Expand All @@ -55,7 +55,7 @@ void LOG_BIGD_HEX(const char *prefix,
#define LOG_BIGD_HEX(...)

#else
#error "HSM Platform undefined"
#error "HSM Platform undefined"
#endif

#endif // __LOG_H
4 changes: 2 additions & 2 deletions ledger/src/hal/include/hal/nvmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@

/**
* @brief Write to non volatile memory
*
*
* @param dst The destination address in non volatile memory
* @param src The source address to write from
* @param length The amount of bytes to write
*
*
* @returns whether the write succeeded
*/
bool nvmem_write(void *dst, void *src, unsigned int length);
Expand Down
6 changes: 3 additions & 3 deletions ledger/src/hal/include/hal/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@

/**
* @brief Perform the platform-specific version of memmove
*
*
* @param dst destination buffer
* @param src source buffer
* @param length number of bytes to copy
*/
*/
void platform_memmove(void *dst, const void *src, unsigned int length);

/**
* @brief Request exiting/closing to the underlying platform
*/
*/
void platform_request_exit();

#endif // __HAL_PLATFORM_H
13 changes: 8 additions & 5 deletions ledger/src/hal/include/hal/seed.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ bool seed_available();
*
* @returns whether the derivation succeeded
*/
bool seed_derive_pubkey(uint32_t* path, uint8_t path_length,
uint8_t* pubkey_out, uint8_t* pubkey_out_length);
bool seed_derive_pubkey(uint32_t* path,
uint8_t path_length,
uint8_t* pubkey_out,
uint8_t* pubkey_out_length);

/**
* @brief Signs the given hash with the private key obtained
Expand All @@ -65,9 +67,10 @@ bool seed_derive_pubkey(uint32_t* path, uint8_t path_length,
*
* @returns whether the signing succeeded
*/
bool seed_sign(uint32_t* path, uint8_t path_length,
bool seed_sign(uint32_t* path,
uint8_t path_length,
uint8_t* hash32,
uint8_t* sig_out, uint8_t* sig_out_length);

uint8_t* sig_out,
uint8_t* sig_out_length);

#endif // __HAL_SEED_H
17 changes: 9 additions & 8 deletions ledger/src/hal/src/ledger/endorsement.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@
// Index of the ledger endorsement scheme
#define ENDORSEMENT_SCHEME_INDEX 2

bool endorsement_sign(uint8_t* msg, size_t msg_size,
uint8_t* signature_out,
bool endorsement_sign(uint8_t* msg,
size_t msg_size,
uint8_t* signature_out,
uint8_t* signature_out_length) {

if (*signature_out_length < MAX_SIGNATURE_LENGTH) {
return false;
}
*signature_out_length = os_endorsement_key2_derive_sign_data(
msg, msg_size, signature_out);

*signature_out_length =
os_endorsement_key2_derive_sign_data(msg, msg_size, signature_out);

return true;
}

Expand All @@ -63,7 +64,7 @@ bool endorsement_get_public_key(uint8_t* public_key_out,
return false;
}

*public_key_out_length = os_endorsement_get_public_key(
ENDORSEMENT_SCHEME_INDEX, public_key_out);
*public_key_out_length =
os_endorsement_get_public_key(ENDORSEMENT_SCHEME_INDEX, public_key_out);
return true;
}
Loading

0 comments on commit 3432e6e

Please sign in to comment.