> For the complete documentation index, see [llms.txt](https://thias-organization.gitbook.io/p256-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://thias-organization.gitbook.io/p256-documentation/risc-zero-p256-accelerator/scalar.md).

# Scalar

For scalar arithmetic, we can simply use the `BigInt` accelerator `modmul_u256_denormalized` as we are not concerned with any Montgomery form representation unlike in field arithmetic.&#x20;

```rust
/// Returns self * rhs mod n
pub fn multiply(&self, rhs: &Self) -> Self {
    cfg_if::cfg_if! {
        if #[cfg(all(target_os = "zkvm", target_arch = "riscv32"))] {
            let result = Self(risc0::modmul_u256_denormalized(&self.0, &rhs.0, &NistP256::ORDER));
            assert!(bool::from(result.0.ct_lt(&NistP256::ORDER)));
            result
        } else {
            let (lo, hi) = self.0.mul_wide(&rhs.0);
            Self(scalar_impl::barrett_reduce(lo, hi))
        }
    }
}

//...

fn invert_vartime(&self) -> CtOption<Self> {
    if cfg!(all(target_os = "zkvm", target_arch = "riscv32")) {
        // Constant time algorithm is faster in the RISC Zero zkVM.
        return self.invert();
    }
    // ... Original implementation
}
```
