misc.c: introduce ctMaskCopy()

This commit is contained in:
Marco Oliverio
2022-07-25 17:48:26 +02:00
parent a98642ba61
commit 2e1e8d2789
2 changed files with 13 additions and 0 deletions

View File

@@ -544,6 +544,17 @@ WC_STATIC WC_INLINE byte ctSetLTE(int a, int b)
{
return (byte)(((word32)a - b - 1) >> 31);
}
/* Constant time - copy size bytes from left to dst if mask is set, size bytes
* from right to dst if mask is not set */
WC_STATIC WC_INLINE void ctMaskCopy(byte m, byte* dst, byte* left, byte* right,
word16 size)
{
int i;
for (i = 0; i < size; ++i)
dst[i] = ctMaskSel(m, left[i], right[i]);
}
#endif
#if defined(WOLFSSL_W64_WRAPPER)

View File

@@ -126,6 +126,8 @@ WOLFSSL_LOCAL byte ctMaskNotEq(int a, int b);
WOLFSSL_LOCAL byte ctMaskSel(byte m, byte a, byte b);
WOLFSSL_LOCAL int ctMaskSelInt(byte m, int a, int b);
WOLFSSL_LOCAL byte ctSetLTE(int a, int b);
WOLFSSL_LOCAL void ctMaskCopy(byte m, byte* dst, byte* left, byte* right,
word16 size);
#endif /* NO_INLINE */