Skip to content
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

fix: mod reduce msg_hash as input of the HMAC function #102

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

obatirou
Copy link

@obatirou obatirou commented Dec 7, 2024

What was wrong?

Eth-keys did not fully respect RFC6979 3.2.d.
The message digest should be modulo reduced before being passed as input of HMAC function.
This issue was found after this analysis.

According to the RFC, it should pass through a bits2octets function:

 K = HMAC_K(V || 0x01 || int2octets(x) || bits2octets(h1))

By looking into the definition of bits2octets, it states that the message digest needs to be reduced:

2.3.4.  Bit String to Octet String

   The bits2octets transform takes as input a sequence of blen bits and
   outputs a sequence of rlen bits.  It consists of the following steps:

   1.  The input sequence b is converted into an integer value z1
       through the bits2int transform:

          z1 = bits2int(b)

   2.  z1 is reduced modulo q, yielding z2 (an integer between 0 and
       q-1, inclusive):

          z2 = z1 mod q
   ...

Closes #101

How was it fixed?

Todo:

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

The message digest needs to be modulo reduced
before being passed as input of the HMAC
function. See RFC6979 3.2.d and bits2octets
definition.
@obatirou obatirou marked this pull request as draft December 7, 2024 18:11
@obatirou
Copy link
Author

obatirou commented Dec 7, 2024

Test are failing for coincurve < 17: those versions use libsecp256k1 prior to commit d8a246324650c3df8d54d133a8ac3c1b857a7a4e which do not include the PR of the fix for the modulo reduction bitcoin-core/secp256k1#1064

ofek/coincurve@v16.0.0...v17.0.0

@obatirou obatirou marked this pull request as ready for review December 8, 2024 10:27
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.

RFC 6979 nonce (k) generation should be modulo-reduced
1 participant