Click or drag to resize
gmp_libmpn_cnd_add_n Method
If cnd is non-zero, it produces the same result as a regular mpn_add_n, and if cnd is zero, it copies {s1p, n} to the result area and returns zero.

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 mp_limb_t mpn_cnd_add_n(
	mp_limb_t cnd,
	mp_ptr rp,
	mp_ptr s1p,
	mp_ptr s2p,
	mp_size_t n
)

Parameters

cnd
Type: Math.Gmp.Nativemp_limb_t
Conditonal value: non-zero for true, zero for false.
rp
Type: Math.Gmp.Nativemp_ptr
The result integer.
s1p
Type: Math.Gmp.Nativemp_ptr
The first operand integer.
s2p
Type: Math.Gmp.Nativemp_ptr
The second operand integer.
n
Type: Math.Gmp.Nativemp_size_t
The number of limbs of s1p and s2p.

Return Value

Type: mp_limb_t
If cnd is non-zero, return carry, either 0 or 1, and if cnd is zero, return 0.
Remarks

This function does conditional addition. If cnd is non-zero, it produces the same result as a regular mpn_add_n, and if cnd is zero, it copies {s1p, n} to the result area and returns zero. The functions is designed to have timing and memory access patterns depending only on size and location of the data areas, but independent of the condition cnd. Like for mpn_add_n, on most machines, the timing will also be independent of the actual limb values.

Examples
// Create multi-precision operands, and expected result.
mp_ptr s1p = new mp_ptr(new uint[] { 0xffffffff, 0xffffffff });
mp_ptr s2p = new mp_ptr(new uint[] { 0x00000001, 0x00000000 });
mp_ptr rp = new mp_ptr(new uint[2]);
mp_ptr result = new mp_ptr(new uint[] { 0x00000000, 0x00000000 });

// Set rp = s1 + s2.
mp_limb_t carry = gmp_lib.mpn_cnd_add_n(1, rp, s1p, s2p, rp.Size);

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

// Release unmanaged memory.
gmp_lib.free(rp, s1p, s2p, result);
See Also