plugeth/crypto/secp256k1/libsecp256k1/src/field_5x52.h

48 lines
1.7 KiB
C
Raw Normal View History

2015-04-07 10:13:37 +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.*
**********************************************************************/
2015-01-21 23:35:00 +00:00
#ifndef _SECP256K1_FIELD_REPR_
#define _SECP256K1_FIELD_REPR_
#include <stdint.h>
typedef struct {
2015-04-07 10:13:37 +00:00
/* X = sum(i=0..4, elem[i]*2^52) mod n */
2015-01-21 23:35:00 +00:00
uint64_t n[5];
#ifdef VERIFY
int magnitude;
int normalized;
#endif
2015-09-28 15:46:17 +00:00
} secp256k1_fe;
2015-01-21 23:35:00 +00:00
2015-04-07 10:13:37 +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) { \
2015-09-28 15:46:17 +00:00
(d0) | (((uint64_t)(d1) & 0xFFFFFUL) << 32), \
((uint64_t)(d1) >> 20) | (((uint64_t)(d2)) << 12) | (((uint64_t)(d3) & 0xFFUL) << 44), \
((uint64_t)(d3) >> 8) | (((uint64_t)(d4) & 0xFFFFFFFUL) << 24), \
((uint64_t)(d4) >> 28) | (((uint64_t)(d5)) << 4) | (((uint64_t)(d6) & 0xFFFFUL) << 36), \
((uint64_t)(d6) >> 16) | (((uint64_t)(d7)) << 16) \
2015-04-07 10:13:37 +00:00
}
#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 {
uint64_t n[4];
2015-09-28 15:46:17 +00:00
} secp256k1_fe_storage;
2015-04-07 10:13:37 +00:00
#define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ \
2015-09-28 15:46:17 +00:00
(d0) | (((uint64_t)(d1)) << 32), \
(d2) | (((uint64_t)(d3)) << 32), \
(d4) | (((uint64_t)(d5)) << 32), \
(d6) | (((uint64_t)(d7)) << 32) \
2015-04-07 10:13:37 +00:00
}}
2015-01-21 23:35:00 +00:00
#endif