|
noexcept |
Multiplies two arbitrary-precision integers specified by vectors of bytes in the Big-Endian byte order.
[out] | pResult | A pointer to a buffer which on output receives the result of multiplication. |
cbResult | The 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] | pX | A pointer to the first multiplicand. |
cbX | A byte size of the first multiplicand. | |
[in] | pY | A pointer to the second multiplicand. |
cbY | A 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 Big-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_{n_x - i}\cdot b^i\) and \(Y = \sum_{i=0}^{n_y} y_{n_y-i}\cdot b^i\) with respect to the Big-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_{n_x-i}\), otherwise \(x'_i = 0\), and likewise \(0\le i \le n_y \Rightarrow y'_i = y_{n_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 Big-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 Little-Endian integers use memmul_LE.