mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 12:28:09 +00:00
style(crypto): cleanup unused functions
This commit is contained in:
parent
b50f1e0b89
commit
d6d1cd7b4c
@ -966,6 +966,7 @@ void bn_divide_base(bignum256 *x, const bignum256 *prime) {
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !USE_INVERSE_FAST
|
||||||
// x = 1/x % prime if x != 0 else 0
|
// x = 1/x % prime if x != 0 else 0
|
||||||
// Assumes x is normalized
|
// Assumes x is normalized
|
||||||
// Assumes prime is a prime number
|
// Assumes prime is a prime number
|
||||||
@ -973,7 +974,7 @@ void bn_divide_base(bignum256 *x, const bignum256 *prime) {
|
|||||||
// Assumes prime is normalized, 2**256 - 2**224 <= prime <= 2**256
|
// Assumes prime is normalized, 2**256 - 2**224 <= prime <= 2**256
|
||||||
// The function doesn't have neither constant control flow nor constant memory
|
// The function doesn't have neither constant control flow nor constant memory
|
||||||
// access flow with regard to prime
|
// access flow with regard to prime
|
||||||
void bn_inverse_slow(bignum256 *x, const bignum256 *prime) {
|
static void bn_inverse_slow(bignum256 *x, const bignum256 *prime) {
|
||||||
// Uses formula 1/x % prime == x**(prime - 2) % prime
|
// Uses formula 1/x % prime == x**(prime - 2) % prime
|
||||||
// See https://en.wikipedia.org/wiki/Fermat%27s_little_theorem
|
// See https://en.wikipedia.org/wiki/Fermat%27s_little_theorem
|
||||||
|
|
||||||
@ -989,6 +990,7 @@ void bn_inverse_slow(bignum256 *x, const bignum256 *prime) {
|
|||||||
|
|
||||||
memzero(&e, sizeof(e));
|
memzero(&e, sizeof(e));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if false
|
#if false
|
||||||
// x = 1/x % prime if x != 0 else 0
|
// x = 1/x % prime if x != 0 else 0
|
||||||
@ -998,7 +1000,7 @@ void bn_inverse_slow(bignum256 *x, const bignum256 *prime) {
|
|||||||
// Assumes prime is odd, normalized, 2**256 - 2**224 <= prime <= 2**256
|
// Assumes prime is odd, normalized, 2**256 - 2**224 <= prime <= 2**256
|
||||||
// The function doesn't have neither constant control flow nor constant memory
|
// The function doesn't have neither constant control flow nor constant memory
|
||||||
// access flow with regard to prime and x
|
// access flow with regard to prime and x
|
||||||
void bn_inverse_fast(bignum256 *x, const bignum256 *prime) {
|
static void bn_inverse_fast(bignum256 *x, const bignum256 *prime) {
|
||||||
// "The Almost Montgomery Inverse" from the section 3 of "Constant Time
|
// "The Almost Montgomery Inverse" from the section 3 of "Constant Time
|
||||||
// Modular Inversion" by Joppe W. Bos
|
// Modular Inversion" by Joppe W. Bos
|
||||||
// See http://www.joppebos.com/files/CTInversion.pdf
|
// See http://www.joppebos.com/files/CTInversion.pdf
|
||||||
@ -1084,6 +1086,7 @@ void bn_inverse_fast(bignum256 *x, const bignum256 *prime) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if USE_INVERSE_FAST
|
||||||
// x = 1/x % prime if x != 0 else 0
|
// x = 1/x % prime if x != 0 else 0
|
||||||
// Assumes x is is_normalized
|
// Assumes x is is_normalized
|
||||||
// Assumes GCD(x, prime) = 1
|
// Assumes GCD(x, prime) = 1
|
||||||
@ -1091,7 +1094,7 @@ void bn_inverse_fast(bignum256 *x, const bignum256 *prime) {
|
|||||||
// Assumes prime is odd, normalized, 2**256 - 2**224 <= prime <= 2**256
|
// Assumes prime is odd, normalized, 2**256 - 2**224 <= prime <= 2**256
|
||||||
// The function has constant control flow but not constant memory access flow
|
// The function has constant control flow but not constant memory access flow
|
||||||
// with regard to prime and x
|
// with regard to prime and x
|
||||||
void bn_inverse_fast(bignum256 *x, const bignum256 *prime) {
|
static void bn_inverse_fast(bignum256 *x, const bignum256 *prime) {
|
||||||
// Custom constant time version of "The Almost Montgomery Inverse" from the
|
// Custom constant time version of "The Almost Montgomery Inverse" from the
|
||||||
// section 3 of "Constant Time Modular Inversion" by Joppe W. Bos
|
// section 3 of "Constant Time Modular Inversion" by Joppe W. Bos
|
||||||
// See http://www.joppebos.com/files/CTInversion.pdf
|
// See http://www.joppebos.com/files/CTInversion.pdf
|
||||||
@ -1196,6 +1199,7 @@ void bn_inverse_fast(bignum256 *x, const bignum256 *prime) {
|
|||||||
memzero(&r, sizeof(s));
|
memzero(&r, sizeof(s));
|
||||||
memzero(&s, sizeof(s));
|
memzero(&s, sizeof(s));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if false
|
#if false
|
||||||
// x = 1/x % prime if x != 0 else 0
|
// x = 1/x % prime if x != 0 else 0
|
||||||
@ -1203,7 +1207,7 @@ void bn_inverse_fast(bignum256 *x, const bignum256 *prime) {
|
|||||||
// Assumes GCD(x, prime) = 1
|
// Assumes GCD(x, prime) = 1
|
||||||
// Guarantees x is normalized and fully reduced modulo prime
|
// Guarantees x is normalized and fully reduced modulo prime
|
||||||
// Assumes prime is odd, normalized, 2**256 - 2**224 <= prime <= 2**256
|
// Assumes prime is odd, normalized, 2**256 - 2**224 <= prime <= 2**256
|
||||||
void bn_inverse_fast(bignum256 *x, const bignum256 *prime) {
|
static void bn_inverse_fast(bignum256 *x, const bignum256 *prime) {
|
||||||
// Custom constant time version of "The Almost Montgomery Inverse" from the
|
// Custom constant time version of "The Almost Montgomery Inverse" from the
|
||||||
// section 3 of "Constant Time Modular Inversion" by Joppe W. Bos
|
// section 3 of "Constant Time Modular Inversion" by Joppe W. Bos
|
||||||
// See http://www.joppebos.com/files/CTInversion.pdf
|
// See http://www.joppebos.com/files/CTInversion.pdf
|
||||||
|
@ -94,18 +94,12 @@ void bn_mult_half(bignum256 *x, const bignum256 *prime);
|
|||||||
void bn_mult_k(bignum256 *x, uint8_t k, const bignum256 *prime);
|
void bn_mult_k(bignum256 *x, uint8_t k, const bignum256 *prime);
|
||||||
void bn_mod(bignum256 *x, const bignum256 *prime);
|
void bn_mod(bignum256 *x, const bignum256 *prime);
|
||||||
void bn_multiply(const bignum256 *k, bignum256 *x, const bignum256 *prime);
|
void bn_multiply(const bignum256 *k, bignum256 *x, const bignum256 *prime);
|
||||||
void bn_fast_mod_old(bignum256 *x, const bignum256 *prime);
|
|
||||||
void bn_fast_mod(bignum256 *x, const bignum256 *prime);
|
void bn_fast_mod(bignum256 *x, const bignum256 *prime);
|
||||||
void bn_power_mod(const bignum256 *x, const bignum256 *e,
|
void bn_power_mod(const bignum256 *x, const bignum256 *e,
|
||||||
const bignum256 *prime, bignum256 *res);
|
const bignum256 *prime, bignum256 *res);
|
||||||
void bn_sqrt(bignum256 *x, const bignum256 *prime);
|
void bn_sqrt(bignum256 *x, const bignum256 *prime);
|
||||||
uint32_t inverse_mod_power_two(uint32_t a, uint32_t n);
|
uint32_t inverse_mod_power_two(uint32_t a, uint32_t n);
|
||||||
void bn_divide_base(bignum256 *x, const bignum256 *prime);
|
void bn_divide_base(bignum256 *x, const bignum256 *prime);
|
||||||
void bn_inverse_slow(bignum256 *x, const bignum256 *prime);
|
|
||||||
void bn_inverse_fast_1(bignum256 *x, const bignum256 *prime);
|
|
||||||
void bn_inverse_fast_2(bignum256 *x, const bignum256 *prime);
|
|
||||||
void bn_inverse_fast_3(bignum256 *x, const bignum256 *prime);
|
|
||||||
void bn_inverse_old(bignum256 *x, const bignum256 *prime);
|
|
||||||
void bn_normalize(bignum256 *x);
|
void bn_normalize(bignum256 *x);
|
||||||
void bn_add(bignum256 *x, const bignum256 *y);
|
void bn_add(bignum256 *x, const bignum256 *y);
|
||||||
void bn_addmod(bignum256 *x, const bignum256 *y, const bignum256 *prime);
|
void bn_addmod(bignum256 *x, const bignum256 *y, const bignum256 *prime);
|
||||||
|
Loading…
Reference in New Issue
Block a user