gmp_lib.mpz_powm_sec Method

GMP Native Interface for .NET

gmp_libmpz_powm_sec Method
Set rop to (base^exp) modulo mod.

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 mpz_powm_sec(
	mpz_t rop,
	mpz_t base,
	mpz_t exp,
	mpz_t mod
)
Public Shared Sub mpz_powm_sec ( 
	rop As mpz_t,
	base As mpz_t,
	exp As mpz_t,
	mod As mpz_t
)
public:
static void mpz_powm_sec(
	mpz_t^ rop, 
	mpz_t^ base, 
	mpz_t^ exp, 
	mpz_t^ mod
)
static member mpz_powm_sec : 
        rop : mpz_t * 
        base : mpz_t * 
        exp : mpz_t * 
        mod : mpz_t -> unit 

Parameters

rop
Type: Math.Gmp.Nativempz_t
The result integer.
base
Type: Math.Gmp.Nativempz_t
The base integer.
exp
Type: Math.Gmp.Nativempz_t
The exponent integer.
mod
Type: Math.Gmp.Nativempz_t
The modulo integer.
Remarks

It is required that exp > 0 and that mod is odd.

This function is designed to take the same time and have the same cache access patterns for any two same-size arguments, assuming that function arguments are placed at the same position and that the machine state is identical upon function entry. This function is intended for cryptographic purposes, where resilience to side-channel attacks is desired.

Examples
// Create, initialize, and set the value of base to 2.
mpz_t @base = new mpz_t();
gmp_lib.mpz_init_set_ui(@base, 2U);

// Create, initialize, and set the value of exp to 4.
mpz_t exp = new mpz_t();
gmp_lib.mpz_init_set_ui(exp, 4U);

// Create, initialize, and set the value of mod to 3.
mpz_t mod = new mpz_t();
gmp_lib.mpz_init_set_ui(mod, 3U);

// Create, initialize, and set the value of rop to 0.
mpz_t rop = new mpz_t();
gmp_lib.mpz_init(rop);

// Set rop = base^exp mod mod.
gmp_lib.mpz_powm_sec(rop, @base, exp, mod);

// Assert that rop is 1.
Assert.IsTrue(gmp_lib.mpz_get_si(rop) == 1);

// Release unmanaged memory allocated for rop, base, exp, and mod.
gmp_lib.mpz_clears(rop, @base, exp, mod, null);
' Create, initialize, and set the value of base to 2.
Dim base As New mpz_t()
gmp_lib.mpz_init_set_ui(base, 2UI)

' Create, initialize, and set the value of exp to 4.
Dim exp As New mpz_t()
gmp_lib.mpz_init_set_ui(exp, 4UI)

' Create, initialize, and set the value of mod to 3.
Dim[mod] As New mpz_t()
gmp_lib.mpz_init_set_ui([mod], 3UI)

' Create, initialize, and set the value of rop to 0.
Dim rop As New mpz_t()
gmp_lib.mpz_init(rop)

' Set rop = base^exp mod mod.
gmp_lib.mpz_powm_sec(rop, base, exp, [mod])

' Assert that rop is 1.
Assert.IsTrue(gmp_lib.mpz_get_si(rop) = 1)

' Release unmanaged memory allocated for rop, base, exp, and mod.
gmp_lib.mpz_clears(rop, base, exp, [mod], Nothing)

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also