gmp_libmpn_sec_mul Method |
Namespace: Math.Gmp.Native
public static void mpn_sec_mul( mp_ptr rp, mp_ptr ap, mp_size_t an, mp_ptr bp, mp_size_t bn, mp_ptr tp )
It is required that an ≥ bn > 0.
No overlapping between R and the input operands is allowed. For A = B, use mpn_sec_sqr(mp_ptr, mp_ptr, mp_size_t, mp_ptr) for optimal performance.
This function requires scratch space of mpn_sec_mul_itch(mp_size_t, mp_size_t)(an, bn) limbs to be passed in the tp parameter. The scratch space requirements are guaranteed to increase monotonously in the operand sizes.
// Create multi-precision operands, and expected result. mp_ptr ap = new mp_ptr(new uint[] { 0xffffffff, 0xffffffff }); mp_ptr bp = new mp_ptr(new uint[] { 0x00000002 }); mp_ptr result = new mp_ptr(new uint[] { 0xfffffffe, 0xffffffff, 0x00000001 }); mp_ptr rp = new mp_ptr(ap.Size + bp.Size); // Create scratch space. mp_size_t size = gmp_lib.mpn_sec_mul_itch(ap.Size, bp.Size); mp_ptr tp = new mp_ptr(size); // Set rp = ap * bp. gmp_lib.mpn_sec_mul(rp, ap, ap.Size, bp, bp.Size, tp); // Assert result of operation. Assert.IsTrue(rp.SequenceEqual(result)); // Release unmanaged memory. gmp_lib.free(rp, ap, bp, tp, result);