2015-10-26 14:54:21 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* Copyright (c) 2013, 2014 Pieter Wuille *
|
|
|
|
* Distributed under the MIT software license, see the accompanying *
|
|
|
|
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
|
|
|
|
**********************************************************************/
|
|
|
|
|
2018-07-09 11:17:44 +00:00
|
|
|
#ifndef SECP256K1_FIELD_REPR_H
|
|
|
|
#define SECP256K1_FIELD_REPR_H
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
typedef struct {
|
2019-05-28 12:23:28 +00:00
|
|
|
/* X = sum(i=0..9, n[i]*2^(i*26)) mod p
|
|
|
|
* where p = 2^256 - 0x1000003D1
|
|
|
|
*/
|
2015-10-26 14:54:21 +00:00
|
|
|
uint32_t n[10];
|
|
|
|
#ifdef VERIFY
|
|
|
|
int magnitude;
|
|
|
|
int normalized;
|
|
|
|
#endif
|
2020-08-26 17:35:27 +00:00
|
|
|
} rustsecp256k1_v0_2_0_fe;
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
/* Unpacks a constant into a overlapping multi-limbed FE element. */
|
|
|
|
#define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \
|
|
|
|
(d0) & 0x3FFFFFFUL, \
|
|
|
|
(((uint32_t)d0) >> 26) | (((uint32_t)(d1) & 0xFFFFFUL) << 6), \
|
|
|
|
(((uint32_t)d1) >> 20) | (((uint32_t)(d2) & 0x3FFFUL) << 12), \
|
|
|
|
(((uint32_t)d2) >> 14) | (((uint32_t)(d3) & 0xFFUL) << 18), \
|
|
|
|
(((uint32_t)d3) >> 8) | (((uint32_t)(d4) & 0x3UL) << 24), \
|
|
|
|
(((uint32_t)d4) >> 2) & 0x3FFFFFFUL, \
|
|
|
|
(((uint32_t)d4) >> 28) | (((uint32_t)(d5) & 0x3FFFFFUL) << 4), \
|
|
|
|
(((uint32_t)d5) >> 22) | (((uint32_t)(d6) & 0xFFFFUL) << 10), \
|
|
|
|
(((uint32_t)d6) >> 16) | (((uint32_t)(d7) & 0x3FFUL) << 16), \
|
|
|
|
(((uint32_t)d7) >> 10) \
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef VERIFY
|
|
|
|
#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}
|
|
|
|
#else
|
|
|
|
#define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0))}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t n[8];
|
2020-08-26 17:35:27 +00:00
|
|
|
} rustsecp256k1_v0_2_0_fe_storage;
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
#define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }}
|
|
|
|
#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]
|
2018-07-09 11:17:44 +00:00
|
|
|
|
|
|
|
#endif /* SECP256K1_FIELD_REPR_H */
|