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.

Some concerns regarding the overflows in modL function

See original GitHub issue

Hey Dmitry,

I have some troubles convincing myself that the modL function won’t suffer from overflows. If you have any references to a more detailed description of modL that would be really helpful! In particular I am concerned with its use here: https://github.com/dchest/tweetnacl-js/blob/1b61c87b6df9859ac136c3c025cdb974220c333c/nacl.js#L788

Two arrays h and d get multiplied to produce x.

Both h and d are Uint8Array(64) with elements at most 8 bits each and only the first 32 elements non-zero, both elements were reduced mod L.

The resulting x is of type Float64Array(64).

I believe, that the number of bits in each element of the array x is maxed at the following values: [16, 17, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 20, 20, 20, 20, 20, 20, 20, 20, 19, 19, 19, 19, 18, 18, 17, 16, 0], i.e. the bit length |x[0]| <= 16, |x[1]| <= 17, etc.

Now, the modL function is called on x. And in this line https://github.com/dchest/tweetnacl-js/blob/1b61c87b6df9859ac136c3c025cdb974220c333c/nacl.js#L729 it can happen that |x[j]| > 32, since |16 * x[i] * L[j - (i - 32)]| <= 4 + 21 + 8 = 33. But during the bit operation on the next line: https://github.com/dchest/tweetnacl-js/blob/1b61c87b6df9859ac136c3c025cdb974220c333c/nacl.js#L730 (x[j] + 128) will get converted to a 32-bits signed integer (according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators, Section Bitwise shift operators). This will act as expected only if the length of the number being shifted is at most 32 bits, but why now will it be the case?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dchestcommented, Feb 10, 2020

Oh, thanks! Also, my test missed that x contained r. Fixing.

0reactions
dchestcommented, Feb 10, 2020

Awesome, thanks a lot! I’m releasing the update soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is a Buffer Overflow | Attack Types and Prevention Methods
Attackers exploit buffer overflow issues to change execution paths, triggering responses that can damage the applications and exposes private information.
Read more >
overflow - CSS: Cascading Style Sheets - MDN Web Docs
Overflow options include clipping, showing scrollbars, or displaying the content flowing out of its container into the surrounding area.
Read more >
Combined Sewer Overflows (CSOs) | US EPA
Combined sewer overflows (CSOs) contain untreated or partially treated human and industrial waste, toxic materials, and debris as well as ...
Read more >
Buffer Overflow - OWASP Foundation
In a classic buffer overflow exploit, the attacker sends data to a program, which it stores in an undersized stack buffer. The result...
Read more >
issue with loading a model in Keras in Colab - Stack Overflow
When my model is saved: I got this WARNING: WARNING:absl:Found untraced functions such as embeddings_layer_call_fn, ...
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