IntModMul
Description
Compute (a * b) mod modulus.
Parameters
| Name | Direction | Description |
|---|---|---|
result |
out | Destination for the reduced product |
a |
in | Left operand |
b |
in | Right operand |
modulus |
in | Modulus |
Usage example (from documentation)
IntModMul(&result, &a, &b, &modulus);Success
Returns true. *result holds (a * b) mod modulus.
Failure
Returns false on modulus == 0 or allocator OOM. *result is left untouched.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Int.c:2424:
}
bool IntModMul(Int *result, const Int *a, const Int *b, const Int *modulus) {
ValidateInt(result);
ValidateInt(a);- In
Int.c:2491:
}
if (!IntModMul(&value, a, &inverse, modulus)) {
IntDeinit(&inverse);
IntDeinit(&value);- In
Int.c:2503:
bool IntSquareMod(Int *result, const Int *value, const Int *modulus) {
return IntModMul(result, value, value, modulus);
}- In
Int.c:2532:
while (exponent > 0) {
if (exponent & 1u) {
if (!IntModMul(&scratch, &acc, &base_mod, modulus)) {
IntDeinit(&acc);
IntDeinit(&base_mod);- In
Int.c:2543:
exponent >>= 1u;
if (exponent > 0) {
if (!IntModMul(&scratch, &base_mod, &base_mod, modulus)) {
IntDeinit(&acc);
IntDeinit(&base_mod);- In
Int.c:2586:
while (!IntIsZero(&exp)) {
if (int_is_odd(&exp)) {
if (!IntModMul(&scratch, &acc, &base_mod, modulus)) {
IntDeinit(&acc);
IntDeinit(&base_mod);- In
Int.c:2604:
}
if (!IntIsZero(&exp)) {
if (!IntModMul(&scratch, &base_mod, &base_mod, modulus)) {
IntDeinit(&acc);
IntDeinit(&base_mod);- In
Int.c:2999:
}
if (!IntModMul(&next, &r, &b, modulus)) {
IntDeinit(&b);
IntDeinit(&b_sq);- In
Int.c:3030:
}
next = IntInit(IntAllocator(result));
if (!IntModMul(&next, &t, &b_sq, modulus)) {
IntDeinit(&b);
IntDeinit(&b_sq);- In
Math.c:727:
bool test_int_mod_mul(void) {
WriteFmt("Testing IntModMul\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:736:
Int result_value = IntInit(&alloc.base);
IntModMul(&result_value, &a, &b, &m);
bool result = IntToU64(&result_value) == 22;- In
Math.c:762:
result = result && (IntToU64(&result_value) == 12);
IntModMul(&check, &result_value, &b, &m);
result = result && (IntCompare(&check, 10) == 0);- In
Math.c:829:
result = result && (IntToU64(&result_value) == 4);
IntModMul(&check, &value, &result_value, &mod);
result = result && (IntToU64(&check) == 1);- In
Math.c:1731:
///
static bool test_m14_mod_mul_null_result_deadend(void) {
WriteFmt("Testing IntModMul NULL result validation\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:1739:
Int mod = IntFrom(7, &alloc.base);
IntModMul(NULL, &a, &b, &mod);
DefaultAllocatorDeinit(&alloc);- In
Math.c:2720:
pass = pass && (IntToU64(&result) == 4);
IntModMul(&check, &value, &result, &mod);
pass = pass && (IntToU64(&check) == 1);- In
Math.c:2752:
pass = pass && (IntToU64(&result) == 9);
IntModMul(&check, &value, &result, &mod);
pass = pass && (IntToU64(&check) == 1);- In
Math.c:4251:
Int r = IntFrom(7u, a);
bool ok = IntModMul(&r, &x, &y, &m); // frees ar/br/prod (2126-2128)
ok = ok && IntToU64(&r) == (12345ull * 67890ull) % 1009ull;
Last updated on