Documentation

Cryptlib.Primitives.NIKE.Field25519

Arithmetic modulo 2^255 - 19 on ten UInt64 limbs #

An element is Σ hᵢ · 2^⌈25.5·i⌉: limbs alternate 26 and 25 bits, so a product of two limbs fits in 64 bits with room to sum ten of them. Every operation ends with carry, which leaves each limb below 2^26; operations accept any input in that bound. Values are not kept fully reduced: toNat is the represented number and toNat % p its canonical value. The limbs are separate structure fields rather than an array so that they stay unboxed.

Instances For
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      Bit offset of each limb.

      Equations
      Instances For
        Equations
        Instances For

          The number the limbs represent.

          Equations
          Instances For

            Split n < 2^256 into limbs; bits from 255 up are folded back in as multiples of 19.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                Equations
                Instances For
                  Equations
                  Instances For

                    Bring every limb back under its width, folding the overflow of the top limb into the bottom one as a multiple of 19. Accepts limbs up to 2^62.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        f - g as f + 2p - g, so no limb goes negative.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          Multiplication by a constant below 2^30.

                          Equations
                          Instances For

                            hₖ = Σ_{i+j=k} c·fᵢgⱼ + Σ_{i+j=k+10} 19·c·fᵢgⱼ, where c = 2 when i and j are both odd: the offsets of two odd limbs sum to one more than the offset of their product's limb, and 2^255 ≡ 19.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              Equations
                              Instances For

                                f^(2^k).

                                Equations
                                Instances For

                                  f^(p-2), which is f⁻¹ for f ≠ 0 and 0 for f = 0, by the usual addition chain.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For

                                    Swap f and g when swap is 1, without branching on it. swap must be 0 or 1.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For

                                      Little-endian bytes with bit 255 masked, as RFC 7748 decodes a u-coordinate.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For