use #if instead of #ifdef for conditional macros

pull/25/head
Pavol Rusnak 11 years ago
parent 3d163fc29b
commit 678e5b1af2

@ -237,10 +237,10 @@ void bn_sqrt(bignum256 *x, const bignum256 *prime)
memcpy(x, &res, sizeof(bignum256));
}
#ifndef INVERSE_FAST
#if ! USE_INVERSE_FAST
#ifdef USE_PRECOMPUTED_IV
#warning USE_PRECOMPUTED_IV will not be used, please undef
#if USE_PRECOMPUTED_IV
#warning USE_PRECOMPUTED_IV will not be used
#endif
// in field G_prime, small but slow
@ -405,7 +405,7 @@ void bn_inverse(bignum256 *x, const bignum256 *prime)
temp >>= 30;
}
int done = 0;
#ifdef USE_PRECOMPUTED_IV
#if USE_PRECOMPUTED_IV
if (prime == &prime256k1) {
for (j = 0; j < 9; j++) {
x->val[j] = r[j];
@ -510,7 +510,6 @@ void bn_divmod58(bignum256 *a, uint32_t *r)
*r = rem;
}
#if 0
void bn_print(const bignum256 *a)
{

@ -27,12 +27,19 @@
#include <stdint.h>
// use precomputed Inverse Values of powers of two
#ifndef USE_PRECOMPUTED_IV
#define USE_PRECOMPUTED_IV 1
#endif
// use precomputed Curve Points (some scalar multiples of curve base point G)
#ifndef USE_PRECOMPUTED_CP
#define USE_PRECOMPUTED_CP 1
#endif
#define INVERSE_FAST 1
// use fast inverse method
#ifndef USE_INVERSE_FAST
#define USE_INVERSE_FAST 1
#endif
// bignum256 are 256 bits stored as 8*30 bit + 1*16 bit
// val[0] are lowest 30 bits, val[8] highest 16 bits

@ -98,7 +98,7 @@ void scalar_multiply(bignum256 *k, curve_point *res)
int i, j;
// result is zero
int is_zero = 1;
#ifdef USE_PRECOMPUTED_CP
#if USE_PRECOMPUTED_CP
int exp = 0;
#else
curve_point curr;
@ -110,21 +110,21 @@ void scalar_multiply(bignum256 *k, curve_point *res)
if (i == 8 && (k->val[i] >> j) == 0) break;
if (k->val[i] & (1u << j)) {
if (is_zero) {
#ifdef USE_PRECOMPUTED_CP
#if USE_PRECOMPUTED_CP
memcpy(res, secp256k1_cp + exp, sizeof(curve_point));
#else
memcpy(res, &curr, sizeof(curve_point));
#endif
is_zero = 0;
} else {
#ifdef USE_PRECOMPUTED_CP
#if USE_PRECOMPUTED_CP
point_add(secp256k1_cp + exp, res);
#else
point_add(&curr, res);
#endif
}
}
#ifdef USE_PRECOMPUTED_CP
#if USE_PRECOMPUTED_CP
exp++;
#else
point_double(&curr);

@ -61,10 +61,6 @@
(c) = ROL((c), 10);\
}
static void compress(uint32_t *MDbuf, uint32_t *X);
static void compress(uint32_t *MDbuf, uint32_t *X)
{
uint32_t aa = MDbuf[0], bb = MDbuf[1], cc = MDbuf[2], dd = MDbuf[3], ee = MDbuf[4];

@ -37,8 +37,7 @@ const bignum256 order256k1 = {
const bignum256 three_over_two256k1 = {
.val = {0x3ffffe19, 0x3ffffffd, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x7fff}};
#ifdef USE_PRECOMPUTED_IV
#if USE_PRECOMPUTED_IV
const bignum256 secp256k1_iv[256] = {
{ .val = {0x868192a, 0x20e02474, 0x24a059d, 0x2c88ffb7, 0x32b761bc, 0x1b0b0a57, 0x383999c4, 0x6414554, 0xc9bd}},
{ .val = {0x4340c95, 0x3070123a, 0x212502ce, 0x16447fdb, 0x395bb0de, 0xd85852b, 0x1c1ccce2, 0x2320a2aa, 0x64de}},
@ -297,11 +296,9 @@ const bignum256 secp256k1_iv[256] = {
{ .val = {0x29c913e4, 0x91b0be0, 0x1fceee6b, 0x215332a, 0x14a31ed9, 0x2e13d0c0, 0x11882581, 0x3d449f71, 0xd708}},
{ .val = {0x14e489f2, 0x248d85f0, 0xfe77735, 0x210a9995, 0xa518f6c, 0x3709e860, 0x28c412c0, 0x1ea24fb8, 0x6b84}},
};
#endif
#ifdef USE_PRECOMPUTED_CP
#if USE_PRECOMPUTED_CP
const curve_point secp256k1_cp[256] = {
{.x = { .val = {0x16f81798, 0x27ca056c, 0x1ce28d95, 0x26ff36cb, 0x70b0702, 0x18a573a, 0xbbac55a, 0x199fbe77, 0x79be}},
.y = { .val = {0x3b10d4b8, 0x311f423f, 0x28554199, 0x5ed1229, 0x1108a8fd, 0x13eff038, 0x3c4655da, 0x369dc9a8, 0x483a}}},
@ -816,5 +813,4 @@ const curve_point secp256k1_cp[256] = {
{.x = { .val = {0x3f8be384, 0x22f4c810, 0x31db6c3e, 0x3b02ab68, 0x1ef07271, 0x2b5b253f, 0x23e1b251, 0x24290af9, 0xb237}},
.y = { .val = {0x2b19880e, 0x4291cf7, 0x9ecb58d, 0x3c013d05, 0x1f94517, 0x143e22aa, 0x15edbe8d, 0x1a524675, 0xfc6b}}},
};
#endif

@ -45,11 +45,11 @@ extern const bignum256 order256k1;
// 3/2 in G_p
extern const bignum256 three_over_two256k1;
#ifdef USE_PRECOMPUTED_IV
#if USE_PRECOMPUTED_IV
extern const bignum256 secp256k1_iv[256];
#endif
#ifdef USE_PRECOMPUTED_CP
#if USE_PRECOMPUTED_CP
extern const curve_point secp256k1_cp[256];
#endif

Loading…
Cancel
Save