github.com/klaytn/klaytn@v1.12.1/crypto/secp256k1/libsecp256k1/src/field_5x52.h (about)

     1  /**********************************************************************
     2   * Copyright (c) 2013, 2014 Pieter Wuille                             *
     3   * Distributed under the MIT software license, see the accompanying   *
     4   * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
     5   **********************************************************************/
     6  
     7  #ifndef _SECP256K1_FIELD_REPR_
     8  #define _SECP256K1_FIELD_REPR_
     9  
    10  #include <stdint.h>
    11  
    12  typedef struct {
    13      /* X = sum(i=0..4, elem[i]*2^52) mod n */
    14      uint64_t n[5];
    15  #ifdef VERIFY
    16      int magnitude;
    17      int normalized;
    18  #endif
    19  } secp256k1_fe;
    20  
    21  /* Unpacks a constant into a overlapping multi-limbed FE element. */
    22  #define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \
    23      (d0) | (((uint64_t)(d1) & 0xFFFFFUL) << 32), \
    24      ((uint64_t)(d1) >> 20) | (((uint64_t)(d2)) << 12) | (((uint64_t)(d3) & 0xFFUL) << 44), \
    25      ((uint64_t)(d3) >> 8) | (((uint64_t)(d4) & 0xFFFFFFFUL) << 24), \
    26      ((uint64_t)(d4) >> 28) | (((uint64_t)(d5)) << 4) | (((uint64_t)(d6) & 0xFFFFUL) << 36), \
    27      ((uint64_t)(d6) >> 16) | (((uint64_t)(d7)) << 16) \
    28  }
    29  
    30  #ifdef VERIFY
    31  #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)), 1, 1}
    32  #else
    33  #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0))}
    34  #endif
    35  
    36  typedef struct {
    37      uint64_t n[4];
    38  } secp256k1_fe_storage;
    39  
    40  #define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ \
    41      (d0) | (((uint64_t)(d1)) << 32), \
    42      (d2) | (((uint64_t)(d3)) << 32), \
    43      (d4) | (((uint64_t)(d5)) << 32), \
    44      (d6) | (((uint64_t)(d7)) << 32) \
    45  }}
    46  
    47  #endif