]> Git Repo - secp256k1.git/blame - src/field_5x52.h
Merge #699: Initialize field elements when resulting in infinity
[secp256k1.git] / src / field_5x52.h
CommitLineData
71712b27
GM
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 **********************************************************************/
0a433ea2 6
abe2d3e8
DR
7#ifndef SECP256K1_FIELD_REPR_H
8#define SECP256K1_FIELD_REPR_H
e6d142a8 9
e6d142a8 10#include <stdint.h>
e6d142a8 11
910d0de4 12typedef struct {
deff5edd
RC
13 /* X = sum(i=0..4, n[i]*2^(i*52)) mod p
14 * where p = 2^256 - 0x1000003D1
15 */
e6d142a8 16 uint64_t n[5];
910d0de4 17#ifdef VERIFY
e6d142a8 18 int magnitude;
910d0de4 19 int normalized;
e6d142a8 20#endif
dd891e0e 21} secp256k1_fe;
e6d142a8 22
6efd6e77 23/* Unpacks a constant into a overlapping multi-limbed FE element. */
4732d260 24#define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \
cfe0ed91
GM
25 (d0) | (((uint64_t)(d1) & 0xFFFFFUL) << 32), \
26 ((uint64_t)(d1) >> 20) | (((uint64_t)(d2)) << 12) | (((uint64_t)(d3) & 0xFFUL) << 44), \
27 ((uint64_t)(d3) >> 8) | (((uint64_t)(d4) & 0xFFFFFFFUL) << 24), \
28 ((uint64_t)(d4) >> 28) | (((uint64_t)(d5)) << 4) | (((uint64_t)(d6) & 0xFFFFUL) << 36), \
29 ((uint64_t)(d6) >> 16) | (((uint64_t)(d7)) << 16) \
4732d260
PW
30}
31
32#ifdef VERIFY
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)), 1, 1}
34#else
35#define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0))}
36#endif
37
ff889f7d
PW
38typedef struct {
39 uint64_t n[4];
dd891e0e 40} secp256k1_fe_storage;
ff889f7d
PW
41
42#define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ \
cfe0ed91
GM
43 (d0) | (((uint64_t)(d1)) << 32), \
44 (d2) | (((uint64_t)(d3)) << 32), \
45 (d4) | (((uint64_t)(d5)) << 32), \
46 (d6) | (((uint64_t)(d7)) << 32) \
ff889f7d
PW
47}}
48
0d7727f9
PW
49#define SECP256K1_FE_STORAGE_CONST_GET(d) \
50 (uint32_t)(d.n[3] >> 32), (uint32_t)d.n[3], \
51 (uint32_t)(d.n[2] >> 32), (uint32_t)d.n[2], \
52 (uint32_t)(d.n[1] >> 32), (uint32_t)d.n[1], \
53 (uint32_t)(d.n[0] >> 32), (uint32_t)d.n[0]
54
abe2d3e8 55#endif /* SECP256K1_FIELD_REPR_H */
This page took 0.042295 seconds and 4 git commands to generate.