Skip to content

IntModInv

Usage example (Cross-references)

Usage examples (Cross-references)
        bool ok      = false;
    
        ok = IntModInv(&inverse, b, modulus);
        if (!ok) {
            IntDeinit(&inverse);
    }
    
    bool IntModInv(Int *result, const Int *value, const Int *modulus) {
        ValidateInt(result);
        ValidateInt(value);
    
    bool test_int_mod_inv(void) {
        WriteFmt("Testing IntModInv\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int check        = IntInit(&alloc.base);
    
        bool result = IntModInv(&result_value, &value, &mod);
        result      = result && (IntToU64(&result_value) == 4);
    
    bool test_int_mod_inv_no_solution(void) {
        WriteFmt("Testing IntModInv no-solution case\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int result_value = IntFrom(99, &alloc.base);
    
        bool result = !IntModInv(&result_value, &value, &mod);
        result      = result && (IntToU64(&result_value) == 99);
     */
    bool test_m3_mod_inv_success_sets_ok(void) {
        WriteFmt("Testing IntModInv returns true on a valid inverse\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int check  = IntInit(&alloc.base);
    
        bool ok = IntModInv(&result, &value, &mod);
    
        /* Real code: ok == true. Mutant flipping `ok = true`: ok == false. */
     */
    bool test_m3_mod_inv_negative_t_branch(void) {
        WriteFmt("Testing IntModInv negative-coefficient normalization returns true\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Int check  = IntInit(&alloc.base);
    
        bool ok = IntModInv(&result, &value, &mod);
    
        bool pass = ok;
        Int r = IntFrom(7u, a);
    
        bool ok = IntModInv(&r, &v, &m);
        ok      = ok && (IntToU64(&r) * 17u) % 3120u == 1u;
        Int r = IntFrom(9u, a);
    
        bool ok = IntModInv(&r, &v, &m);
        ok      = ok && IntToU64(&r) == 5u;
        Int r = IntFrom(7u, a);
    
        bool ok = !IntModInv(&r, &v, &m); // returns false
    
        IntDeinit(&v);
        Int inverse = IntFrom(0u, alloc);
    
        bool ok = IntModInv(&inverse, &value, &modulus);
        ok      = ok && IntCompare(&inverse, 23u) == 0;
Last updated on