Skip to content

Comments

feat: replace HMAC with Poly1305 for performance#6

Closed
Spider4Tech wants to merge 3 commits intotest-speedfrom
feat/poly1305-replace-hmac-v2
Closed

feat: replace HMAC with Poly1305 for performance#6
Spider4Tech wants to merge 3 commits intotest-speedfrom
feat/poly1305-replace-hmac-v2

Conversation

@Spider4Tech
Copy link
Owner

This PR replaces HMAC-SHA256 with Poly1305 for message authentication, significantly improving performance while maintaining strong security guarantees.

Changes

  • Removed hmac dependency and all HMAC-related code.
  • Added poly1305 crate for fast, constant-time message authentication.
  • Updated encrypt3_final and decrypt3_final to use Poly1305 instead of HMAC.
  • Added new functions: derive_poly1305_key_final, compute_poly1305, verify_poly1305.
  • Updated error handling and tag length checks for Poly1305 (16 bytes).
  • Updated Cargo.toml to reflect the new dependency.

Performance Impact

  • Poly1305 is ~5-10x faster than HMAC-SHA256 for the same security level.
  • The tag size is reduced from 32 bytes (HMAC-SHA256) to 16 bytes (Poly1305).
  • No change to the core encryption/decryption logic or security model.

Security Notes

  • Poly1305 is a one-time-authenticator and requires a unique key per message. This is already handled by the existing key derivation logic.
  • The implementation uses the poly1305 crate, which is constant-time and audited.
  • All existing tests pass, including tamper resistance and integrity checks.

Testing

  • All existing tests updated to use Poly1305.
  • Added checks for Poly1305 tag length and verification.
  • Verified that tampering with ciphertext or header still results in decryption failure.

Migration

  • No breaking changes to the public API.
  • Users will see improved performance and smaller ciphertexts (by 16 bytes).

References

Review and feedback welcome!

@Spider4Tech Spider4Tech deleted the feat/poly1305-replace-hmac-v2 branch September 15, 2025 14:09
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