question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clarify if we want to prehash before signing messages

See original GitHub issue

NOTE This issue is not to do any coding, but just make a decision on our architecture

The original golang code uses https://godoc.org/golang.org/x/crypto/ed25519 which will produce the ed25519 signature of whatever we enter it. There is no prehashing here.

Every ledger code I have seen does prehashing on the transaction before signing. I am not sure if this is required, or just a convention. Maybe @rudi-cilibrasi knows better.

I did a little investigation and it seems there is a prehash step (using keccack) in ethereum as well:

When I worked on the first demo ledger app for cosmos, we had to use some flag to specify:

  • this public key is in software, verify signature against full sign bytes
  • this public key is in ledger, verify signature against sha256(sign bytes)

Needless to say this was clunky and didn’t seem right. Let’s discuss if we will need this prehashing step, and if so, consider doing it everywhere. This will update the signing algorithm used in weave, weave-js and in web4/@iov-keycontrol. We can pass the unhashed sign bytes to the keyring entries so they can verify the content (eg. ledger app), but then hash before signing them.

I would like some feedback here, especially anyone who has dealt with this issue before.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
webmaster128commented, Jun 28, 2018

According to https://tools.ietf.org/html/rfc8032#section-4, Ed25519 is a PureEdDSA variant, which means that the pre-hash function is the identity (i.e. no prehashing).

However, part of Ed25519 is the ability to handle arbitrary sized input messags (M) because of an internal SHA512 step: https://tools.ietf.org/html/rfc8032#section-5.1.6

Given that, I think we can consider Ed25519 to be a signing mechanism that consumes plain messages M or prehashed messages PH(M). In this case, having an optional prehashing step makes sense.

The situation is different for Secp256k1, where the signing algorithm itself truncates input to be smaller than N (256bit). This must never happen on unprehashed messages.

1reaction
webmaster128commented, Jul 3, 2018

“passing full sign bytes into libsodium” means libsodium does the prehashing for you because the API is designed like that: https://github.com/jedisct1/libsodium/blob/569778b517496861a3880e0e690973bf08a52e08/src/libsodium/crypto_sign/ed25519/ref10/sign.c#L65 You cannot use arbitrary length input data with elliptic curves so the hashing is done somewhere.

~I guess libsodium’s crypto_sign is implemented as Ed25519(SHA512(m)) but I’ll verify that.~

Read more comments on GitHub >

github_iconTop Results From Across the Web

More efficient and just as secure to sign message hash using ...
Of course the hash function is not supposed to have collisions, but if it does, not prehashing gives added protection.
Read more >
Re: [lamps] How do we plan to solve the hash-then-sign ...
With Dilithium, Sphincs+ or Falcon the entire message will have to be sent (unless a pre-hash mode of Signature operation is added to ......
Read more >
Whether to hash-then-sign with Dilithium and Falcon?
If the message to be signed is pre-hashed, for example `m0 = SHA256(m)` and then m0 provided to Dilithium or Falcon to sign,...
Read more >
A Guide to Consistent Hashing - Toptal
Consistent Hashing is a distributed hashing scheme that operates independently of the number of servers or objects in a distributed hash table.
Read more >
EdDSA, Ed25519, Ed25519-IETF, Ed25519ph, Ed25519ctx ...
The Edwards-curve Digital Signature Algorithm (EdDSA) You've heard of EdDSA ... Important: notice that the message here does not need to be hashed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found