Skip to content

feat(ecies): implement constant-time comparison for MAC verification #17825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

moricho
Copy link
Contributor

@moricho moricho commented Aug 12, 2025

Summary

This PR changes the MAC verification in the ECIES implementation to use constant-time comparison to prevent timing attacks.

Background

The previous implementation used regular comparison operators (!=) for MAC tag verification. This could potentially cause the following issues:

  • Timing attack vulnerability: Regular comparisons exit early when the first mismatch is detected, which could allow attackers to guess MAC tags by exploiting response time differences.
  • Security risk: Timing attacks on MAC verification pose a serious security risk, especially in encrypted communications.

Implementation Details

  • HMAC-SHA256 Verification Improvement
    • Before: Calculate tag using hmac_sha256() and verify with regular comparison
    • After: Use newly added verify_hmac_sha256() function with HMAC's built-in verify_slice() method for constant-time comparison
  • Ethereum MAC Verification Improvement
    • Before: Calculate MAC using digest() and verify with regular comparison
    • After: Use newly added verify() method with subtle::ConstantTimeEq::ct_eq() for constant-time comparison
      • hmac crate uses subtle in a verification step as well

@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Aug 12, 2025
@moricho moricho marked this pull request as draft August 12, 2025 14:58
@moricho moricho force-pushed the constant-time-eq branch 2 times, most recently from 97b3086 to 75f4520 Compare August 12, 2025 15:28
@moricho moricho marked this pull request as ready for review August 12, 2025 15:50
@mattsse
Copy link
Collaborator

mattsse commented Aug 14, 2025

Timing attack vulnerability: Regular comparisons exit early when the first mismatch is detected, which could allow attackers to guess MAC tags by exploiting response time differences.
Security risk: Timing attacks on MAC verification pose a serious security risk, especially in encrypted communications.

hmm, I don't think these really apply here because this all of this is behind IO anyway

wdyt @Rjected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

2 participants