Skip to content

Conversation

@holtrop-wolfssl
Copy link
Contributor

Description

Add Rust wrapper for HMAC-BLAKE2[bs] one-shot and incremental APIs.

Also attempted to avoid a couple coverity messages about overrunning the x_key array (false positives).

Testing

Unit tests and integration with boringtun

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@holtrop-wolfssl holtrop-wolfssl self-assigned this Jan 20, 2026
@holtrop-wolfssl
Copy link
Contributor Author

retest this please (org.jenkinsci.plugins.workflow.support.steps.AgentOfflineException: Unable to create live FilePath for wolf-linux-cloud-node-2zcwho; wolf-linux-cloud-node-2zcwho was marked offline: Connection was broken)

@holtrop-wolfssl holtrop-wolfssl marked this pull request as ready for review January 20, 2026 15:56
dgarske
dgarske previously approved these changes Jan 20, 2026
@dgarske dgarske requested review from gasbytes and mattia-moffa and removed request for mattia-moffa January 20, 2026 18:40
///
/// Returns either Ok(()) on success or Err(e) containing the wolfSSL
/// library error code value.
#[cfg(blake2b_hmac)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not necessary, since the whole impl block is gated (line 177).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, thanks. I originally had the one-shot API in the BLAKE2b impl block instead of making a separate BLAKE2bHmac struct. Removed!

///
/// Returns either Ok(()) on success or Err(e) containing the wolfSSL
/// library error code value.
#[cfg(blake2s_hmac)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not necessary, since the whole impl block is gated (line 451).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

/// let mut mac = [0u8; 64];
/// hmac_blake2b.finalize(&key, &mut mac).expect("Error with finalize()");
/// ```
pub fn finalize(&mut self, key: &[u8], mac: &mut [u8]) -> Result<(), i32> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the docs it says "must be 64 bytes", but there's no check to enforce that.
Maybe you can turn the mac argument to be &mut [u8; 64], or at least document what happens if the length is not respected once the buffer is passed to the C api.

This applies to the finalize function in the HMAC-BLAKE2s module too, but with 32 bytes instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea; I added an exact length requirement.

/// Returns either Ok(()) on success or Err(e) containing the wolfSSL
/// library error code value.
#[cfg(blake2b_hmac)]
pub fn hmac(data: &[u8], key: &[u8], out: &mut [u8]) -> Result<(), i32> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The out parameter doesn't document or enforce its expected size (64 bytes for BLAKE2b, 32 bytes for BLAKE2s). Maybe turn it to &mut [u8; 64] for compile-time enforcement, or at least document what happens if the length is not respected once the buffer is passed to the C API. This applies to both BLAKE2bHmac::hmac() and BLAKE2sHmac::hmac().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea; I added an exact length requirement.

@holtrop-wolfssl
Copy link
Contributor Author

retest this please (org.jenkinsci.plugins.workflow.support.steps.AgentOfflineException: Unable to create live FilePath for wolf-linux-cloud-node-q02z3c; wolf-linux-cloud-node-q02z3c was marked offline: Connection was broken)

@holtrop-wolfssl holtrop-wolfssl removed their assignment Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants