Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

mod_inverse

Calculate modular inverse using Fermat’s little theorem for prime modulus

For secp256k1 curve order n (which is prime), we use Fermat’s little theorem: If p is prime and a ≢ 0 (mod p), then a^(-1) ≡ a^(p-2) (mod p)

Arguments

  • a - The value to find the modular inverse of
  • m - The modulus (should be prime)

Returns

  • u256 - The modular inverse a^(-1) mod m, or 0 if no inverse exists

Fully qualified path: alexandria_btc::legacy_signature::mod_inverse

pub fn mod_inverse(a: u256, m: u256) -> u256