Skip to content

MontyForm get MOD from instance #980

@Fethbita

Description

@Fethbita

When having access to a value in ConstMontyForm, getting the MODULO value is difficult. This is the only way I could think of:

use crypto_bigint::{CheckedAdd, U256, Zero, impl_modulus, modular::ConstMontyForm};

impl_modulus!(
    MyModulus,
    U256,
    "73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"
);
pub type ValueUnderMod = ConstMontyForm<MyModulus, { U256::LIMBS }>;

fn main() {
    // ...
    let some_value = ValueUnderMod::new(&U256::from_u8(2));

    let mut zero = some_value.clone();
    zero.set_zero();

    let mut modulo = zero.sub(&ValueUnderMod::new(&U256::from_u8(1))).retrieve();
    modulo = modulo.checked_add(&U256::from_u8(1)).unwrap();

    assert!(modulo.eq(&U256::from_be_hex(
        "73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001"
    )))
}

And it would be good to have a method for the MontyForm to get the modulus from it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions