|
noexcept |
The generic form of bitwise XOR of two operands specified in Big-Endian byte order.
[out] | pDest | A pointer to the output buffer receiving the result of bitwise XOR. |
cbDest | The capacity of the destination buffer pDest , in bytes. | |
[in] | pSrc1 | A pointer to one of the operands. |
cbSrc1 | A byte length of the operand pointed to by pSrc1 . | |
[in] | pSrc2 | A pointer to another of the operands. |
cbSrc2 | A byte length of the operand pointed to by pSrc2 . |
The function computes bitwise XOR of arbitrary-precision integers of possibly different byte sizes and stored in possibly overlapping buffers pSrc1
and pSrc2
and writes the result into the buffer pDest
, of a custom size cbDest
, that also can overlap with the buffers of the operands. That is, there are no restrictions on respective values of the sizes or respective positions of the buffers in memory.
Let \(n_1 = \textrm{cbSrc1}\), \(n_2 = \textrm{cbSrc2}\), \(m = \textrm{cbDest}\) and \(n = \min (n_1, n_2)\). Let also \(x\) be the value specified by the first buffer pSrc1
, i.e. \(x=\sum_{i=0}^{n_1 - 1}x_i\cdot b^i\), and \(y\) be the value specified by the second buffer pSrc2
, i.e. \(y=\sum_{i=0}^{n_2 - 1}y_i\cdot b^i\), where b = 2CHAR_BIT
, that is a number of values that can be represented using one byte. Then the function produces the result \(R = \left(\sum_{i=0}^{n-1}(x_i\oplus y_i)\cdot b^i + \sum_{i=n}^{n_1 - 1}x_i\cdot b^i + \sum_{i=n}^{n_2 - 1}y_i\cdot b^i\right)\bmod b^m\), where \(\oplus\) denotes bitwise XOR of two bytes.
That is, if cbSrc1
is greater than cbSrc2
, then the lowest cbSrc2
bytes of the result will actually be the result of bitwise XOR of respective bytes in pSrc1
and pSrc2
; the highest cbSrc1 - cbSrc2
bytes of the result will be copied from the respective bytes of pSrc1
. Irrespective of that, if cbDest
is less than the byte size of the result, i.e. max(cbSrc1, cbSrc2)
, the resulting value will be truncated so that only the lowest part of the result is written into the destination buffer pDest
. If, on the other hand, cbDest
is greater than the byte size of the result, the remaining high-order bytes of the destination buffer will be zeroed out.
The function considers the specified parameters be in the Big-Endian format. That is, using the notation above, the first byte of pSrc1
specifies \(x_{n_1 - 1}\), and the last one specifies \(x_{0}\). Likewise, the first byte of pSrc2
specifies the value of \(y_{n_2 - 1}\), and the last one specifies \(y_0\). The result is also written in the Big-Endian format, therefore the last byte of the destination buffer receives the value \(x_0\oplus y_0\), the penultimate byte receives \(x_1\oplus y_1\) and so on.
To perform a computation of values in the Little-Endian order, use the memxor_LE function.
Compared to memxor_copy and memxor_inplace, the function also performs necessary calculations to match the process with the possibly overlapping buffers and differing sizes. If the operation of the function is known to be conducted with non-overlapping buffers of equal sizes, the preferable faster function for that is memxor_copy. If the operation is done in place with otherwise non-overlapping buffers, the faster alternative is memxor_inplace.