Skip to content

Commit

Permalink
sys/hashes: document ctx != NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
mguetschow committed Nov 28, 2023
1 parent 8e3e1e1 commit 9bdf60d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions sys/hashes/sha512_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ static const unsigned char PAD[128] = {
/* Add padding and terminating bit-count. */
void sha512_common_pad(sha512_common_context_t *ctx)
{
assert(ctx != NULL);

/*
* Convert length to a vector of bytes -- we do this now rather
* than later because the length will change after we pad.
Expand All @@ -184,6 +186,8 @@ void sha512_common_pad(sha512_common_context_t *ctx)
/* Add bytes into the hash */
void sha512_common_update(sha512_common_context_t *ctx, const void *data, size_t len)
{
assert(ctx != NULL);

/* Number of bytes left in the buffer from previous updates */
uint8_t r = (ctx->count[1] >> 3) & 0x7f;
/* Number of bytes free in the buffer from previous updates */
Expand Down Expand Up @@ -233,6 +237,8 @@ void sha512_common_update(sha512_common_context_t *ctx, const void *data, size_t
*/
void sha512_common_final(sha512_common_context_t *ctx, void *dst, size_t dig_len)
{
assert(ctx != NULL);

/* Add padding */
sha512_common_pad(ctx);

Expand Down
6 changes: 3 additions & 3 deletions sys/include/hashes/sha512.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ typedef sha512_common_context_t sha512_context_t;
/**
* @brief SHA-512 initialization. Begins a SHA-512 operation.
*
* @param ctx sha512_context_t handle to init
* @param ctx sha512_context_t handle to init, must not be NULL
*/
void sha512_init(sha512_context_t *ctx);

/**
* @brief Add bytes into the hash
*
* @param ctx sha512_context_t handle to use
* @param ctx sha512_context_t handle to use, must not be NULL
* @param[in] data Input data
* @param[in] len Length of @p data
*/
Expand All @@ -69,7 +69,7 @@ static inline void sha512_update(sha512_context_t *ctx, const void *data, size_t
* @brief SHA-512 finalization. Pads the input data, exports the hash value,
* and clears the context state.
*
* @param ctx sha512_context_t handle to use
* @param ctx sha512_context_t handle to use, must not be NULL
* @param[out] digest pointer to resulting digest, this is the hash of all the bytes.
* Length must be at least SHA512_DIGEST_LENGTH
*/
Expand Down
6 changes: 3 additions & 3 deletions sys/include/hashes/sha512_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ typedef struct {
/**
* @brief SHA-512 initialization. Begins a SHA-512 operation.
*
* @param ctx sha512_common_context_t handle to init
* @param ctx sha512_common_context_t handle to init, must not be NULL
*/
void sha512_common_pad(sha512_common_context_t *ctx);

/**
* @brief Add bytes into the hash
*
* @param ctx sha512_common_context_t handle to use
* @param ctx sha512_common_context_t handle to use, must not be NULL
* @param[in] data Input data
* @param[in] len Length of @p data
*/
Expand All @@ -60,7 +60,7 @@ void sha512_common_update(sha512_common_context_t *ctx, const void *data, size_t
* @brief SHA-512 finalization. Pads the input data, exports the hash value,
* and clears the context state.
*
* @param ctx sha512_common_context_t handle to use
* @param ctx sha512_common_context_t handle to use, must not be NULL
* @param[out] digest resulting digest, this is the hash of all the bytes
* @param[in] dig_len Length of @p digest
*/
Expand Down

0 comments on commit 9bdf60d

Please sign in to comment.