Squashed 'src/secp256k1/' changes from 84973d393..0b7024185
[bitcoinplatinum.git] / src / field_5x52.h
blobbccd8feb4dde63dc0e9d2197fa5e9943882e2069
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 **********************************************************************/
7 #ifndef SECP256K1_FIELD_REPR_H
8 #define SECP256K1_FIELD_REPR_H
10 #include <stdint.h>
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;
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) \
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
36 typedef struct {
37 uint64_t n[4];
38 } secp256k1_fe_storage;
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) \
47 #endif /* SECP256K1_FIELD_REPR_H */