Skip to content

Commit

Permalink
lib_cxng: Add WARN_UNUSED_RESULT on all functions
Browse files Browse the repository at this point in the history
This is an extract of
#443
which includes all the changes on .h files included in lib_cxng
  • Loading branch information
Xavier Chapron committed Dec 5, 2023
1 parent 437446d commit 4e78262
Show file tree
Hide file tree
Showing 38 changed files with 586 additions and 474 deletions.
74 changes: 40 additions & 34 deletions lib_cxng/include/lcx_aead.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ typedef struct {
*
* @return Error code.
*/
cx_err_t cx_aead_init(cx_aead_context_t *ctx);
WARN_UNUSED_RESULT cx_err_t cx_aead_init(cx_aead_context_t *ctx);

/**
* @brief AEAD set up.
Expand All @@ -158,7 +158,7 @@ cx_err_t cx_aead_init(cx_aead_context_t *ctx);
*
* @return Error code
*/
cx_err_t cx_aead_setup(cx_aead_context_t *ctx, cx_aead_type_t type);
WARN_UNUSED_RESULT cx_err_t cx_aead_setup(cx_aead_context_t *ctx, cx_aead_type_t type);

/**
* @brief Sets the cipher key.
Expand All @@ -176,7 +176,10 @@ cx_err_t cx_aead_setup(cx_aead_context_t *ctx, cx_aead_type_t type);
*
* @return Error code
*/
cx_err_t cx_aead_set_key(cx_aead_context_t *ctx, const uint8_t *key, size_t key_len, uint32_t mode);
WARN_UNUSED_RESULT cx_err_t cx_aead_set_key(cx_aead_context_t *ctx,
const uint8_t *key,
size_t key_len,
uint32_t mode);

/**
* @brief Sets the initialization vector.
Expand All @@ -191,7 +194,9 @@ cx_err_t cx_aead_set_key(cx_aead_context_t *ctx, const uint8_t *key, size_t key_
*
* @return Error code.
*/
cx_err_t cx_aead_set_iv(cx_aead_context_t *ctx, const uint8_t *iv, size_t iv_len);
WARN_UNUSED_RESULT cx_err_t cx_aead_set_iv(cx_aead_context_t *ctx,
const uint8_t *iv,
size_t iv_len);

/**
* @brief Adds associated data to the context.
Expand All @@ -207,7 +212,9 @@ cx_err_t cx_aead_set_iv(cx_aead_context_t *ctx, const uint8_t *iv, size_t iv_len
*
* @return Error code.
*/
cx_err_t cx_aead_update_ad(cx_aead_context_t *ctx, const uint8_t *ad, size_t ad_len);
WARN_UNUSED_RESULT cx_err_t cx_aead_update_ad(cx_aead_context_t *ctx,
const uint8_t *ad,
size_t ad_len);

/**
* @brief Updates the data to encrypt or decrypt.
Expand All @@ -229,11 +236,8 @@ cx_err_t cx_aead_update_ad(cx_aead_context_t *ctx, const uint8_t *ad, size_t ad_
* @return Error code.
*
*/
cx_err_t cx_aead_update(cx_aead_context_t *ctx,
uint8_t *in,
size_t in_len,
uint8_t *out,
size_t *out_len);
WARN_UNUSED_RESULT cx_err_t
cx_aead_update(cx_aead_context_t *ctx, uint8_t *in, size_t in_len, uint8_t *out, size_t *out_len);

/**
* @brief Writes the tag of the AEAD cipher.
Expand All @@ -248,7 +252,7 @@ cx_err_t cx_aead_update(cx_aead_context_t *ctx,
*
* @return Error code.
*/
cx_err_t cx_aead_write_tag(cx_aead_context_t *ctx, uint8_t *tag, size_t tag_len);
WARN_UNUSED_RESULT cx_err_t cx_aead_write_tag(cx_aead_context_t *ctx, uint8_t *tag, size_t tag_len);

/**
* @brief Checks the tag of the AEAD cipher.
Expand All @@ -263,7 +267,9 @@ cx_err_t cx_aead_write_tag(cx_aead_context_t *ctx, uint8_t *tag, size_t tag_len)
*
* @return Error code.
*/
cx_err_t cx_aead_check_tag(cx_aead_context_t *ctx, const uint8_t *tag, size_t tag_len);
WARN_UNUSED_RESULT cx_err_t cx_aead_check_tag(cx_aead_context_t *ctx,
const uint8_t *tag,
size_t tag_len);

/**
* @brief All-in-one authenticated encryption.
Expand Down Expand Up @@ -295,17 +301,17 @@ cx_err_t cx_aead_check_tag(cx_aead_context_t *ctx, const uint8_t *tag, size_t ta
*
* @return Error code.
*/
cx_err_t cx_aead_encrypt(cx_aead_context_t *ctx,
const uint8_t *iv,
size_t iv_len,
const uint8_t *ad,
size_t ad_len,
uint8_t *in,
size_t in_len,
uint8_t *out,
size_t *out_len,
uint8_t *tag,
size_t tag_len);
WARN_UNUSED_RESULT cx_err_t cx_aead_encrypt(cx_aead_context_t *ctx,
const uint8_t *iv,
size_t iv_len,
const uint8_t *ad,
size_t ad_len,
uint8_t *in,
size_t in_len,
uint8_t *out,
size_t *out_len,
uint8_t *tag,
size_t tag_len);

/**
* @brief All-in-one authenticated decryption.
Expand Down Expand Up @@ -338,17 +344,17 @@ cx_err_t cx_aead_encrypt(cx_aead_context_t *ctx,
*
* @return Error code.
*/
cx_err_t cx_aead_decrypt(cx_aead_context_t *ctx,
const uint8_t *iv,
size_t iv_len,
const uint8_t *ad,
size_t ad_len,
uint8_t *in,
size_t in_len,
uint8_t *out,
size_t *out_len,
const uint8_t *tag,
size_t tag_len);
WARN_UNUSED_RESULT cx_err_t cx_aead_decrypt(cx_aead_context_t *ctx,
const uint8_t *iv,
size_t iv_len,
const uint8_t *ad,
size_t ad_len,
uint8_t *in,
size_t in_len,
uint8_t *out,
size_t *out_len,
const uint8_t *tag,
size_t tag_len);

#endif // HAVE_AEAD

Expand Down
40 changes: 23 additions & 17 deletions lib_cxng/include/lcx_aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
* - CX_OK on success
* - CX_INVALID_PARAMETER
*/
cx_err_t cx_aes_init_key_no_throw(const uint8_t *rawkey, size_t key_len, cx_aes_key_t *key);
WARN_UNUSED_RESULT cx_err_t cx_aes_init_key_no_throw(const uint8_t *rawkey,
size_t key_len,
cx_aes_key_t *key);

/**
* @deprecated
Expand Down Expand Up @@ -112,14 +114,14 @@ DEPRECATED static inline size_t cx_aes_init_key(const unsigned char *rawkey,
* - CX_INVALID_PARAMETER
* - INVALID_PARAMETER
*/
cx_err_t cx_aes_iv_no_throw(const cx_aes_key_t *key,
uint32_t mode,
const uint8_t *iv,
size_t iv_len,
const uint8_t *in,
size_t in_len,
uint8_t *out,
size_t *out_len);
WARN_UNUSED_RESULT cx_err_t cx_aes_iv_no_throw(const cx_aes_key_t *key,
uint32_t mode,
const uint8_t *iv,
size_t iv_len,
const uint8_t *in,
size_t in_len,
uint8_t *out,
size_t *out_len);

/**
* @deprecated
Expand Down Expand Up @@ -179,12 +181,12 @@ DEPRECATED static inline size_t cx_aes_iv(const cx_aes_key_t *key,
* - CX_INVALID_PARAMETER
* - INVALID_PARAMETER
*/
cx_err_t cx_aes_no_throw(const cx_aes_key_t *key,
uint32_t mode,
const uint8_t *in,
size_t in_len,
uint8_t *out,
size_t *out_len);
WARN_UNUSED_RESULT cx_err_t cx_aes_no_throw(const cx_aes_key_t *key,
uint32_t mode,
const uint8_t *in,
size_t in_len,
uint8_t *out,
size_t *out_len);

/**
* @deprecated
Expand Down Expand Up @@ -216,7 +218,9 @@ DEPRECATED static inline size_t cx_aes(const cx_aes_key_t *key,
* - CX_INVALID_PARAMETER
* - INVALID_PARAMETER
*/
cx_err_t cx_aes_enc_block(const cx_aes_key_t *key, const uint8_t *inblock, uint8_t *outblock);
WARN_UNUSED_RESULT cx_err_t cx_aes_enc_block(const cx_aes_key_t *key,
const uint8_t *inblock,
uint8_t *outblock);

/**
* @brief Decrypts a 16-byte block using AES algorithm.
Expand All @@ -232,7 +236,9 @@ cx_err_t cx_aes_enc_block(const cx_aes_key_t *key, const uint8_t *inblock, uint8
* - CX_INVALID_PARAMETER
* - INVALID_PARAMETER
*/
cx_err_t cx_aes_dec_block(const cx_aes_key_t *key, const uint8_t *inblock, uint8_t *outblock);
WARN_UNUSED_RESULT cx_err_t cx_aes_dec_block(const cx_aes_key_t *key,
const uint8_t *inblock,
uint8_t *outblock);

#endif // HAVE_AES

Expand Down
71 changes: 41 additions & 30 deletions lib_cxng/include/lcx_aes_gcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,47 @@ typedef struct {
uint8_t flag; ///< Indicates either the IV has already been processed or not
} cx_aes_gcm_context_t;

void cx_aes_gcm_init(cx_aes_gcm_context_t *ctx);
cx_err_t cx_aes_gcm_set_key(cx_aes_gcm_context_t *ctx, const uint8_t *raw_key, size_t key_len);
cx_err_t cx_aes_gcm_start(cx_aes_gcm_context_t *ctx,
uint32_t mode,
const uint8_t *iv,
size_t iv_len);
cx_err_t cx_aes_gcm_update_aad(cx_aes_gcm_context_t *ctx, const uint8_t *aad, size_t aad_len);
cx_err_t cx_aes_gcm_update(cx_aes_gcm_context_t *ctx, const uint8_t *in, uint8_t *out, size_t len);
cx_err_t cx_aes_gcm_finish(cx_aes_gcm_context_t *ctx, uint8_t *tag, size_t tag_len);
cx_err_t cx_aes_gcm_encrypt_and_tag(cx_aes_gcm_context_t *ctx,
uint8_t *in,
size_t len,
const uint8_t *iv,
size_t iv_len,
const uint8_t *aad,
size_t aad_len,
uint8_t *out,
uint8_t *tag,
size_t tag_len);
cx_err_t cx_aes_gcm_decrypt_and_auth(cx_aes_gcm_context_t *ctx,
uint8_t *in,
size_t len,
const uint8_t *iv,
size_t iv_len,
const uint8_t *aad,
size_t aad_len,
uint8_t *out,
const uint8_t *tag,
size_t tag_len);
cx_err_t cx_aes_gcm_check_tag(cx_aes_gcm_context_t *ctx, const uint8_t *tag, size_t tag_len);
void cx_aes_gcm_init(cx_aes_gcm_context_t *ctx);
WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_set_key(cx_aes_gcm_context_t *ctx,
const uint8_t *raw_key,
size_t key_len);
WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_start(cx_aes_gcm_context_t *ctx,
uint32_t mode,
const uint8_t *iv,
size_t iv_len);
WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_update_aad(cx_aes_gcm_context_t *ctx,
const uint8_t *aad,
size_t aad_len);
WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_update(cx_aes_gcm_context_t *ctx,
const uint8_t *in,
uint8_t *out,
size_t len);
WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_finish(cx_aes_gcm_context_t *ctx,
uint8_t *tag,
size_t tag_len);
WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_encrypt_and_tag(cx_aes_gcm_context_t *ctx,
uint8_t *in,
size_t len,
const uint8_t *iv,
size_t iv_len,
const uint8_t *aad,
size_t aad_len,
uint8_t *out,
uint8_t *tag,
size_t tag_len);
WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_decrypt_and_auth(cx_aes_gcm_context_t *ctx,
uint8_t *in,
size_t len,
const uint8_t *iv,
size_t iv_len,
const uint8_t *aad,
size_t aad_len,
uint8_t *out,
const uint8_t *tag,
size_t tag_len);
WARN_UNUSED_RESULT cx_err_t cx_aes_gcm_check_tag(cx_aes_gcm_context_t *ctx,
const uint8_t *tag,
size_t tag_len);

#endif // HAVE_AES && HAVE_AES_GCM

Expand Down
Loading

0 comments on commit 4e78262

Please sign in to comment.