csecp256k1

Haskell FFI bindings to bitcoin-core/secp256k1 (docs.ppad.tech/csecp256k1).
git clone git://git.ppad.tech/csecp256k1.git
Log | Files | Refs | README | LICENSE

field_10x26.h (2366B)


      1 /***********************************************************************
      2  * Copyright (c) 2013, 2014 Pieter Wuille                              *
      3  * Distributed under the MIT software license, see the accompanying    *
      4  * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
      5  ***********************************************************************/
      6 
      7 #ifndef SECP256K1_FIELD_REPR_H
      8 #define SECP256K1_FIELD_REPR_H
      9 
     10 #include <stdint.h>
     11 
     12 /** This field implementation represents the value as 10 uint32_t limbs in base
     13  *  2^26. */
     14 typedef struct {
     15    /* A field element f represents the sum(i=0..9, f.n[i] << (i*26)) mod p,
     16     * where p is the field modulus, 2^256 - 2^32 - 977.
     17     *
     18     * The individual limbs f.n[i] can exceed 2^26; the field's magnitude roughly
     19     * corresponds to how much excess is allowed. The value
     20     * sum(i=0..9, f.n[i] << (i*26)) may exceed p, unless the field element is
     21     * normalized. */
     22     uint32_t n[10];
     23     /*
     24      * Magnitude m requires:
     25      *     n[i] <= 2 * m * (2^26 - 1) for i=0..8
     26      *     n[9] <= 2 * m * (2^22 - 1)
     27      *
     28      * Normalized requires:
     29      *     n[i] <= (2^26 - 1) for i=0..8
     30      *     sum(i=0..9, n[i] << (i*26)) < p
     31      *     (together these imply n[9] <= 2^22 - 1)
     32      */
     33     SECP256K1_FE_VERIFY_FIELDS
     34 } haskellsecp256k1_v0_1_0_fe;
     35 
     36 /* Unpacks a constant into a overlapping multi-limbed FE element. */
     37 #define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \
     38     (d0) & 0x3FFFFFFUL, \
     39     (((uint32_t)d0) >> 26) | (((uint32_t)(d1) & 0xFFFFFUL) << 6), \
     40     (((uint32_t)d1) >> 20) | (((uint32_t)(d2) & 0x3FFFUL) << 12), \
     41     (((uint32_t)d2) >> 14) | (((uint32_t)(d3) & 0xFFUL) << 18), \
     42     (((uint32_t)d3) >> 8) | (((uint32_t)(d4) & 0x3UL) << 24), \
     43     (((uint32_t)d4) >> 2) & 0x3FFFFFFUL, \
     44     (((uint32_t)d4) >> 28) | (((uint32_t)(d5) & 0x3FFFFFUL) << 4), \
     45     (((uint32_t)d5) >> 22) | (((uint32_t)(d6) & 0xFFFFUL) << 10), \
     46     (((uint32_t)d6) >> 16) | (((uint32_t)(d7) & 0x3FFUL) << 16), \
     47     (((uint32_t)d7) >> 10) \
     48 }
     49 
     50 typedef struct {
     51     uint32_t n[8];
     52 } haskellsecp256k1_v0_1_0_fe_storage;
     53 
     54 #define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }}
     55 #define SECP256K1_FE_STORAGE_CONST_GET(d) d.n[7], d.n[6], d.n[5], d.n[4],d.n[3], d.n[2], d.n[1], d.n[0]
     56 
     57 #endif /* SECP256K1_FIELD_REPR_H */