Magnitude in field implementation #240

issue jhoenicke openend this issue on April 15, 2015
  1. jhoenicke commented at 12:59 pm on April 15, 2015: none

    Hello,

    I started to dig deeper into the implementation and stumbled over a small issue with the magnitudes.

    From field_10x26_impl.h, the function secp256k1_fe_verify

    0    r &= (a->magnitude >= 0);
    1    r &= (a->magnitude <= 32);
    

    while in field_5x52_impl.h the function is

    0    r &= (a->magnitude >= 0);
    1    r &= (a->magnitude <= 2048);
    

    This means that multiplying a number with the constant value 100 is totally fine on a 64-bit machine, but will lead to an error on 32-bit machines, which IMHO is bad. The two implementation should have the same external interface.

    Finally, is there a good reason for the 2 * in the second line of secp256k1_fe_verify? Why is the magnitude given in multiple of 2’s? Doesn’t the code work with odd magnitudes? This also means that one cannot express that magnitude should be 1 without having a fully normalized number.

  2. real-or-random commented at 9:59 pm on February 8, 2022: contributor
    The first part is tracked in #1060, the second is now answered by comments in the code.
  3. real-or-random closed this on Feb 8, 2022


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-22 01:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me