1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

use #if instead of #ifdef for conditional macros

This commit is contained in:
Pavol Rusnak 2013-10-03 17:32:27 +02:00
parent 3d163fc29b
commit 678e5b1af2
6 changed files with 20 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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