chsvlib
chsv helper source code

◆ memmul_LE()

void Chusov::Memory::memmul_LE ( void *restrict  pResult,
std::size_t  cbResult,
const void *restrict  pX,
std::size_t  cbX,
const void *restrict  pY,
std::size_t  cbY 
)
noexcept

Multiplies two arbitrary-precision integers specified by vectors of bytes in the Little-Endian byte order.

Parameters
[out]pResultA pointer to a buffer which on output receives the result of multiplication.
cbResultThe capacity of the buffer pointed to by pResult as well as the byte size of the product which is computed modulo bcbResult, where b = 2CHAR_BIT is a number of values that one byte can represent.
[in]pXA pointer to the first multiplicand.
cbXA byte size of the first multiplicand.
[in]pYA pointer to the second multiplicand.
cbYA byte size of the second multiplicand.

In order to fit the product to the buffer pointed to by pResult, the function can discard high-order bytes of the product effectively returning the product modulo bcbResult. In order to avoid loss of the information, the destination buffer must be sufficient in size to hold cbX + cbY bytes of data.

The operands of the multiplication are Little-Endian integers, that is, assuming nx = cbX - 1, ny = cbY - 1, nR = cbResult - 1, the vectors pointed to by pX and pY are respectively \(V_X = \{x_0,\dots,x_{n_x}\}\) and \(V_Y = \{y_0,\dots,y_{n_y}\}\), in which the bytes \(x_0\) and \(y_0\) are the first elements, represent corresponding unsigned integers \(X = \sum_{i=0}^{n_x} x_i\cdot b^i\) and \(Y = \sum_{i=0}^{n_y} y_i\cdot b^i\) with respect to the Little-Endian order. These integers are contracted or zero-extended to become \(n_R\)-byte integers \(X' = \sum_{i=0}^{n_R}x'_i\cdot b^i\) and \(Y' = \sum_{i=0}^{n_R}y'_i\cdot b^i\) where \(0\le i \le n_x \Rightarrow x'_i = x_i\), otherwise \(x'_i = 0\), and likewise \(0\le i \le n_y \Rightarrow y'_i = y_i\), otherwise \(y'_i = 0\). The product, \(\left(X'\cdot Y'\right)\bmod b^{n_R}\), is then written to pResult, again in the Little-Endian byte order.

The input pointers, pResult, pX and pY, may be equal to one another. In this case the respective sizes must be equal, i.e. if pResult == pX, then cbResult must equal cbX; if pResult == pY, then cbResult must equal cbY; if pX == pY, then cbX must equal cbY.

Other than that, the buffers pointed to by pResult, pX and pY must not overlap.

To multiply Big-Endian integers use memmul_BE.

See also
memmul_BE;
memdiv_LE;
memfmadd_LE;
memfmsub_LE;
memadd_LE;
memsub_LE;
memlsh_LE.