Click or drag to resize
gmp_libmpn_sec_powm Method
Set R to (B^E) modulo M, where R = {rp, n}, M = {mp, n}, and E = {ep, ceil(enb / mp_bits_per_limb)}.

Namespace:  Math.Gmp.Native
Assembly:  Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static void mpn_sec_powm(
	mp_ptr rp,
	mp_ptr bp,
	mp_size_t bn,
	mp_ptr ep,
	mp_bitcnt_t enb,
	mp_ptr mp,
	mp_size_t n,
	mp_ptr tp
)

Parameters

rp
Type: Math.Gmp.Nativemp_ptr
The result operand.
bp
Type: Math.Gmp.Nativemp_ptr
The first operand integer.
bn
Type: Math.Gmp.Nativemp_size_t
The number of limbs of bp.
ep
Type: Math.Gmp.Nativemp_ptr
The second operand integer.
enb
Type: Math.Gmp.Nativemp_bitcnt_t
The number of limbs of ep.
mp
Type: Math.Gmp.Nativemp_ptr
The third operand integer.
n
Type: Math.Gmp.Nativemp_size_t
The number of limbs of mp.
tp
Type: Math.Gmp.Nativemp_ptr
The scratch operand integer.
Remarks

It is required that B > 0, that M > 0 is odd, and that E < 2^enb.

No overlapping between R and the input operands is allowed.

This function requires scratch space of mpn_sec_powm_itch(bn, enb, n) limbs to be passed in the tp parameter. The scratch space requirements are guaranteed to increase monotonously in the operand sizes.

Examples
// Create multi-precision operands, and expected result.
mp_ptr bp = new mp_ptr(new uint[] { 0x00000002 });
mp_ptr ep = new mp_ptr(new uint[] { 0x00000004 });
mp_ptr mp = new mp_ptr(new uint[] { 0x00000003 });
mp_ptr result = new mp_ptr(new uint[] { 0x00000001 });
mp_ptr rp = new mp_ptr(bp.Size);

// Create scratch space.
mp_size_t size = gmp_lib.mpn_sec_powm_itch(bp.Size, 3, mp.Size);
mp_ptr tp = new mp_ptr(size);

// Set rp = bp^ep mod mp.
gmp_lib.mpn_sec_powm(rp, bp, bp.Size, ep, 3, mp, mp.Size, tp);

// Assert result of operation.
Assert.IsTrue(rp.SequenceEqual(result));

// Release unmanaged memory.
gmp_lib.free(rp, bp, ep, mp, tp, result);
See Also