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
Int.Math.c:765:
bool test_int_pow_mod_scalar(void) {
WriteFmt("Testing IntPowMod scalar-exponent dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:773:
Int result_value = IntInit(&alloc.base);
IntPowMod(&result_value, &base, 20u, &mod);
bool result = IntToU64(&result_value) == 3;- In
Int.Math.c:785:
bool test_int_pow_mod_integer_exponent(void) {
WriteFmt("Testing IntPowMod Int-exponent dispatch\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:794:
Int result_value = IntInit(&alloc.base);
IntPowMod(&result_value, &base, &exp, &mod);
bool result = IntToU64(&result_value) == 445;- In
Int.Math.c:1092:
bool test_int_pow_mod_scalar_zero_modulus(void) {
WriteFmt("Testing IntPowMod scalar-exponent zero modulus handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:1100:
Int result_value = IntInit(&alloc.base);
IntPowMod(&result_value, &base, 8u, &mod);
DefaultAllocatorDeinit(&alloc);
return false;- In
Int.Math.c:1106:
bool test_int_pow_mod_integer_zero_modulus(void) {
WriteFmt("Testing IntPowMod Int-exponent zero modulus handling\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Int.Math.c:1115:
Int result_value = IntFrom(99, &alloc.base);
bool result = !IntPowMod(&result_value, &base, &exp, &mod);
result = result && (IntCompare(&result_value, 99) == 0);
Last updated on