2021-06-14 14:55:38 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* Copyright (c) 2020 Peter Dettman *
|
|
|
|
* Distributed under the MIT software license, see the accompanying *
|
|
|
|
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef SECP256K1_MODINV32_H
|
|
|
|
#define SECP256K1_MODINV32_H
|
|
|
|
|
|
|
|
#if defined HAVE_CONFIG_H
|
|
|
|
#include "libsecp256k1-config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
/* A signed 30-bit limb representation of integers.
|
|
|
|
*
|
|
|
|
* Its value is sum(v[i] * 2^(30*i), i=0..8). */
|
|
|
|
typedef struct {
|
|
|
|
int32_t v[9];
|
2022-03-08 19:45:41 +00:00
|
|
|
} rustsecp256k1_v0_5_0_modinv32_signed30;
|
2021-06-14 14:55:38 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* The modulus in signed30 notation, must be odd and in [3, 2^256]. */
|
2022-03-08 19:45:41 +00:00
|
|
|
rustsecp256k1_v0_5_0_modinv32_signed30 modulus;
|
2021-06-14 14:55:38 +00:00
|
|
|
|
|
|
|
/* modulus^{-1} mod 2^30 */
|
|
|
|
uint32_t modulus_inv30;
|
2022-03-08 19:45:41 +00:00
|
|
|
} rustsecp256k1_v0_5_0_modinv32_modinfo;
|
2021-06-14 14:55:38 +00:00
|
|
|
|
|
|
|
/* Replace x with its modular inverse mod modinfo->modulus. x must be in range [0, modulus).
|
|
|
|
* If x is zero, the result will be zero as well. If not, the inverse must exist (i.e., the gcd of
|
|
|
|
* x and modulus must be 1). These rules are automatically satisfied if the modulus is prime.
|
|
|
|
*
|
|
|
|
* On output, all of x's limbs will be in [0, 2^30).
|
|
|
|
*/
|
2022-03-08 19:45:41 +00:00
|
|
|
static void rustsecp256k1_v0_5_0_modinv32_var(rustsecp256k1_v0_5_0_modinv32_signed30 *x, const rustsecp256k1_v0_5_0_modinv32_modinfo *modinfo);
|
2021-06-14 14:55:38 +00:00
|
|
|
|
2022-03-08 19:45:41 +00:00
|
|
|
/* Same as rustsecp256k1_v0_5_0_modinv32_var, but constant time in x (not in the modulus). */
|
|
|
|
static void rustsecp256k1_v0_5_0_modinv32(rustsecp256k1_v0_5_0_modinv32_signed30 *x, const rustsecp256k1_v0_5_0_modinv32_modinfo *modinfo);
|
2021-06-14 14:55:38 +00:00
|
|
|
|
|
|
|
#endif /* SECP256K1_MODINV32_H */
|