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

BIP340 Schnorr should accept arbitrary length messages #1040

Closed
randombit opened this issue Apr 11, 2024 · 6 comments · Fixed by #1041
Closed

BIP340 Schnorr should accept arbitrary length messages #1040

randombit opened this issue Apr 11, 2024 · 6 comments · Fixed by #1041

Comments

@randombit
Copy link
Contributor

BIP340 was modified last year to allow arbitrary length inputs instead of just 32 bytes. But verify_prehash continues to require the message be exactly 32 bytes. Curiously (IIUC) it's already possible to sign messages longer than 32 bytes, as I don't see any length check in that code. As I understand it all that's required is to remove the line

let prehash: [u8; 32] = prehash.try_into().map_err(|_| Error::new())?;

and pass the arbitrarily sized prehash to the inner tagged hash.

@tarcieri
Copy link
Member

tarcieri commented Apr 11, 2024

We can support this, but I wonder if verify_prehash is perhaps the wrong method name in that case, since its contract is the input must be the output of a cryptographic digest function: https://docs.rs/signature/latest/signature/hazmat/trait.PrehashVerifier.html#tymethod.verify_prehash

Or that is to say, we can add another method verify_prehash calls, if only to preserve the existing trait impl. Possibly verify_raw?

Curiously (IIUC) it's already possible to sign messages longer than 32 bytes, as I don't see any length check in that code.

Huh? How?

@randombit
Copy link
Contributor Author

Huh? How?

Sorry, that's not the case - I misread the signing code.

@tarcieri
Copy link
Member

This is an odd detail in the section of BIP340 you linked above:

If large messages are not pre-hashed, the algorithms of the signature scheme will perform more hashing internally.

So this is in fact some separate signing/verification mode that conditionally hashes depending on the input length?

@randombit
Copy link
Contributor Author

I'm assuming that's referring to the inner tagged hash that actually generates the Schnorr challenge and by "more hashing" they mean "more iterations of the compression function"

@tarcieri
Copy link
Member

But all those things remain the same for small messages as well?

@tarcieri
Copy link
Member

@randombit if you're familiar with the specific semantics of this (I'm still a bit unclear) perhaps you could open a PR which implements this?

tarcieri pushed a commit that referenced this issue Apr 24, 2024
This was an extension to BIP340 that was introduced in 2022.

The official BIP340 test vectors do contain data for this case (tests 15-18) which are included here.

Fixes #1040
altkdf pushed a commit to altkdf/elliptic-curves that referenced this issue Jun 5, 2024
This was an extension to BIP340 that was introduced in 2022.

The official BIP340 test vectors do contain data for this case (tests 15-18) which are included here.

Fixes RustCrypto#1040
randombit added a commit to randombit/elliptic-curves that referenced this issue Aug 29, 2024
This is a backport of RustCrypto#1041 onto the 0.13 branch, with some
small changes to accomodate SemVer.

Fixes RustCrypto#1040
tarcieri pushed a commit that referenced this issue Sep 20, 2024
This is a backport of #1041 onto the 0.13 branch, with some
small changes to accomodate SemVer.

Fixes #1040
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants