IntPowMod
Description
Generic modular exponentiation convenience macro.
Parameters
| Name | Direction | Description |
|---|---|---|
result |
out | Destination for the reduced power |
base |
in | Base value |
exponent |
in | Exponent selected through generic dispatch |
modulus |
in | Modulus |
Usage example (from documentation)
IntPowMod(&result, &base, 65537u, &modulus);Success
Returns true; *result holds base ** exponent mod modulus computed via repeated-squaring with intermediate reduction.
Failure
Returns false when modulus is zero (logged), when exponent is negative, or when an intermediate allocation fails; *result is unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Math.c:775:
bool test_int_pow_mod_scalar(void) {
WriteFmt("Testing IntPowMod scalar-exponent dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:783:
Int result_value = IntInit(&alloc.base);
IntPowMod(&result_value, &base, 20u, &mod);
bool result = IntToU64(&result_value) == 3;- In
Math.c:795:
bool test_int_pow_mod_integer_exponent(void) {
WriteFmt("Testing IntPowMod Int-exponent dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:804:
Int result_value = IntInit(&alloc.base);
IntPowMod(&result_value, &base, &exp, &mod);
bool result = IntToU64(&result_value) == 445;- In
Math.c:1102:
bool test_int_pow_mod_scalar_zero_modulus(void) {
WriteFmt("Testing IntPowMod scalar-exponent zero modulus handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:1110:
Int result_value = IntInit(&alloc.base);
IntPowMod(&result_value, &base, 8u, &mod);
DefaultAllocatorDeinit(&alloc);
return false;- In
Math.c:1116:
bool test_int_pow_mod_integer_zero_modulus(void) {
WriteFmt("Testing IntPowMod Int-exponent zero modulus handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Math.c:1125:
Int result_value = IntFrom(99, &alloc.base);
bool result = !IntPowMod(&result_value, &base, &exp, &mod);
result = result && (IntCompare(&result_value, 99) == 0);- In
Math.c:3578:
Int result_value = IntInit(&alloc.base);
bool ok = IntPowMod(&result_value, &base, 13u, &mod);
bool result = ok && (IntToU64(&result_value) == 12);- In
Math.c:3600:
Int result_value = IntInit(&alloc.base);
bool ok = IntPowMod(&result_value, &base, 0u, &mod);
bool result = ok && (IntToU64(&result_value) == 1);- In
Math.c:3624:
Int result_value = IntInit(&alloc.base);
bool ok = IntPowMod(&result_value, &base, 64u, &mod);
bool result = ok && (IntToU64(&result_value) == 582344008);- In
Math.c:3644:
Int mod = IntFrom(7, &alloc.base);
IntPowMod((Int *)NULL, &base, 5u, &mod);
DefaultAllocatorDeinit(&alloc);- In
Math.c:3659:
Int mod = IntFrom(7, &alloc.base);
IntPowMod(&result_value, (Int *)NULL, 5u, &mod);
DefaultAllocatorDeinit(&alloc);- In
Math.c:3674:
Int base = IntFrom(2, &alloc.base);
IntPowMod(&result_value, &base, 5u, (Int *)NULL);
DefaultAllocatorDeinit(&alloc);- In
Math.c:4313:
Int r = IntFrom(9u, a);
bool ok = IntPowMod(&r, &base, 13u, &m);
ok = ok && IntToU64(&r) == 96889010407ull % 1000000007ull; // 7^13 mod m
- In
Math.c:4334:
Int r = IntFrom(9u, a);
bool ok = IntPowMod(&r, &base, &exp, &m);
ok = ok && IntToU64(&r) == 96889010407ull % 1000000007ull;- In
Access.c:359:
Int result_value = IntInit(&alloc.base);
bool ok = IntPowMod(&result_value, &base, 20u, &mod);
bool result = ok && (IntToU64(&result_value) == 3);
Last updated on