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.

Verification of ed25519 signature in prod app takes 3-5x more time

See original GitHub issue

Current Behavior

Vanilla JS check script like https://gist.github.com/ukstv/5038bcb000808e2b349f8b6f7956d6b3 reports it takes about 20ms for signature verification. If run inside a full application like https://github.com/ceramicnetwork/js-ceramic (if similarly wrapped in console.time/console.timeEnd) it takes 70-100ms to do the same. I find it odd that verification time depends on the application so much.

Expected Behavior

Time required for verification should be similar, not 3-5x larger.

Environment Details

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • node/browser version: v14.17.1
  • OS Version: macOS Big Sur (Darwin feather 20.5.0 Darwin Kernel Version 20.5.0: Sat May 8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64)
  • Device details: Intel MBP

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ukstvcommented, Jul 15, 2021

@kdenhartog Simplest way to expose this:

  1. git clone js-ceramic,
  2. npm install && npm run build
  3. Go to node_modules/dids/lib/did.js, line 132: did_jwt_1.verifyJWS(jws, publicKeys);
  4. Wrap the line with console.time('did-jwt.verifyJWS') ... console.timeEnd('did-jwt.verifyJWS')
  5. cd core && npm run test.

There you can see the time it takes for the function to complete. Note, DID resolution happens few lines above and does not affect did-jwt.verifyJWS in any way.

0reactions
mirceaniscommented, Jul 15, 2021

Thanks for the examples and for finding the “culprit” code 😃

This behavior of iterating through possible verification methods and checking each one has been there from the early days, and will likely always remain (possibly only as a fallback).

Using the verification method identified by a kid is a planned improvement to this library. Essentially, if there is a kid present in a header, then it must be used to filter through the publicKeys and only pick a matching key id for the actual cryptographic verification. (tracking this in #191)

I’ll close this issue now since the “slowness” has been identified.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to check runtime of e.g. Ed25519 signature algorithm
You can see why it takes a longer time by looking where Ed25519 sign and verify differ on RFC 8032 for example. Basically,...
Read more >
ED25519 Verification fails in Golang for payload signed in Java
This signature needs to be verified using the public key. The verification always fails in golang app. However, I'm able to successfully verify...
Read more >
RFC 8032: Edwards-Curve Digital Signature Algorithm (EdDSA)
It is more resilient to side-channel attacks; 4. EdDSA uses small public keys (32 or 57 bytes) and signatures (64 or 114 bytes)...
Read more >
Edwards-curve Digital Signature Algorithm (EdDSA) - IETF
EdDSA uses an elliptic curve over the finite field GF(p). 2. ... Verify To verify a PureEdDSA signature ENC(R) || ENC(S) on a...
Read more >
EdDSA and Ed25519 - Practical Cryptography for Developers
EdDSA (Edwards-curve Digital Signature Algorithm) is a modern and secure digital signature algorithm based on performance-optimized elliptic curves, ...
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