Skip to content

openssl: avoid resetting the HMAC key on every packet - #1088

Open
dormancygrace wants to merge 1 commit into
OpenVPN:masterfrom
dormancygrace:agent/openssl-hmac-reset
Open

openssl: avoid resetting the HMAC key on every packet#1088
dormancygrace wants to merge 1 commit into
OpenVPN:masterfrom
dormancygrace:agent/openssl-hmac-reset

Conversation

@dormancygrace

Copy link
Copy Markdown

Summary

  • reinitialize OpenSSL 3.0.3+ HMAC contexts with their existing key
  • retain the parameter-based path for OpenSSL 3.0.0 through 3.0.2

Rationale

OpenVPN currently supplies the saved digest and key parameters on every hmac_ctx_reset(). The OpenSSL provider consequently reinstalls the same key and rebuilds the HMAC inner and outer digest states for every packet.

OpenSSL PR #18100, included since 3.0.3, fixed parameterless EVP_MAC_init() reinitialization with an existing key. Using that path avoids the repeated setup without changing the key or output.

Validation

  • SHA-1 and RFC 2202 HMAC-SHA1 known-answer tests passed for repeated resets
  • current and optimized paths produced identical output digests
  • OpenVPN 2.7.5 cross-built successfully as an OpenWrt MIPS 24Kc package
  • five-run median on MT7620A at a 1,500-byte message improved from 16.292 MB/s to 29.155 MB/s in an isolated HMAC benchmark

The existing crypto_test_hmac() also exercises context reset and verifies that changing the original key buffer after initialization does not change the result.

OpenSSL 3.0.3 and newer can reinitialize an EVP_MAC HMAC
context with its existing key when EVP_MAC_init is called without
parameters. Use that path instead of supplying the digest and key
again on every OpenVPN HMAC reset.

Retain the old parameter-based reset for OpenSSL 3.0.0 through
3.0.2, where parameterless EVP_MAC reinitialization did not reset
the underlying HMAC implementation.
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.

1 participant