mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 03:07:29 +02:00
Try to XOR as many words as possible in xorbuf APIs
This commit is contained in:
@ -256,42 +256,50 @@ WC_MISC_STATIC WC_INLINE void ByteReverseWords64(word64* out, const word64* in,
|
|||||||
#ifndef WOLFSSL_NO_XOR_OPS
|
#ifndef WOLFSSL_NO_XOR_OPS
|
||||||
/* This routine performs a bitwise XOR operation of <*r> and <*a> for <n> number
|
/* This routine performs a bitwise XOR operation of <*r> and <*a> for <n> number
|
||||||
of wolfssl_words, placing the result in <*r>. */
|
of wolfssl_words, placing the result in <*r>. */
|
||||||
WC_MISC_STATIC WC_INLINE void XorWordsOut(wolfssl_word* r,
|
WC_MISC_STATIC WC_INLINE void XorWordsOut(wolfssl_word** r,
|
||||||
const wolfssl_word* a, const wolfssl_word* b, word32 n)
|
const wolfssl_word** a, const wolfssl_word** b, word32 n)
|
||||||
{
|
{
|
||||||
word32 i;
|
word32 i;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) r[i] = a[i] ^ b[i];
|
for (i = 0; i < n; i++)
|
||||||
|
*(*r)++ = *(*a)++ ^ *(*b)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This routine performs a bitwise XOR operation of <*buf> and <*mask> of n
|
/* This routine performs a bitwise XOR operation of <*buf> and <*mask> of n
|
||||||
counts, placing the result in <*buf>. */
|
counts, placing the result in <*buf>. */
|
||||||
|
|
||||||
WC_MISC_STATIC WC_INLINE void xorbufout(void*out, const void* buf,
|
WC_MISC_STATIC WC_INLINE void xorbufout(void* out, const void* buf,
|
||||||
const void* mask, word32 count)
|
const void* mask, word32 count)
|
||||||
{
|
{
|
||||||
if (((wc_ptr_t)out | (wc_ptr_t)buf | (wc_ptr_t)mask | count) %
|
word32 i;
|
||||||
WOLFSSL_WORD_SIZE == 0)
|
byte* o;
|
||||||
XorWordsOut( (wolfssl_word*)out, (wolfssl_word*)buf,
|
byte* b;
|
||||||
(const wolfssl_word*)mask, count / WOLFSSL_WORD_SIZE);
|
const byte* m;
|
||||||
else {
|
|
||||||
word32 i;
|
|
||||||
byte* o = (byte*)out;
|
|
||||||
byte* b = (byte*)buf;
|
|
||||||
const byte* m = (const byte*)mask;
|
|
||||||
|
|
||||||
for (i = 0; i < count; i++) o[i] = b[i] ^ m[i];
|
if (((wc_ptr_t)buf | (wc_ptr_t)mask) % WOLFSSL_WORD_SIZE == 0) {
|
||||||
|
/* Alignment checks out. Possible to XOR words. */
|
||||||
|
XorWordsOut( (wolfssl_word**)&out, (const wolfssl_word**)&buf,
|
||||||
|
(const wolfssl_word**)&mask, count / WOLFSSL_WORD_SIZE);
|
||||||
|
count %= WOLFSSL_WORD_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
o = (byte*)out;
|
||||||
|
b = (byte*)buf;
|
||||||
|
m = (const byte*)mask;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
o[i] = b[i] ^ m[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This routine performs a bitwise XOR operation of <*r> and <*a> for <n> number
|
/* This routine performs a bitwise XOR operation of <*r> and <*a> for <n> number
|
||||||
of wolfssl_words, placing the result in <*r>. */
|
of wolfssl_words, placing the result in <*r>. */
|
||||||
WC_MISC_STATIC WC_INLINE void XorWords(wolfssl_word* r, const wolfssl_word* a,
|
WC_MISC_STATIC WC_INLINE void XorWords(wolfssl_word** r, const wolfssl_word** a,
|
||||||
word32 n)
|
word32 n)
|
||||||
{
|
{
|
||||||
word32 i;
|
word32 i;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) r[i] ^= a[i];
|
for (i = 0; i < n; i++)
|
||||||
|
*(*r)++ ^= *(*a)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This routine performs a bitwise XOR operation of <*buf> and <*mask> of n
|
/* This routine performs a bitwise XOR operation of <*buf> and <*mask> of n
|
||||||
@ -299,16 +307,22 @@ counts, placing the result in <*buf>. */
|
|||||||
|
|
||||||
WC_MISC_STATIC WC_INLINE void xorbuf(void* buf, const void* mask, word32 count)
|
WC_MISC_STATIC WC_INLINE void xorbuf(void* buf, const void* mask, word32 count)
|
||||||
{
|
{
|
||||||
if (((wc_ptr_t)buf | (wc_ptr_t)mask | count) % WOLFSSL_WORD_SIZE == 0)
|
word32 i;
|
||||||
XorWords( (wolfssl_word*)buf,
|
byte* b;
|
||||||
(const wolfssl_word*)mask, count / WOLFSSL_WORD_SIZE);
|
const byte* m;
|
||||||
else {
|
|
||||||
word32 i;
|
|
||||||
byte* b = (byte*)buf;
|
|
||||||
const byte* m = (const byte*)mask;
|
|
||||||
|
|
||||||
for (i = 0; i < count; i++) b[i] ^= m[i];
|
if (((wc_ptr_t)buf | (wc_ptr_t)mask) % WOLFSSL_WORD_SIZE == 0) {
|
||||||
|
/* Alignment checks out. Possible to XOR words. */
|
||||||
|
XorWords( (wolfssl_word**)&buf,
|
||||||
|
(const wolfssl_word**)&mask, count / WOLFSSL_WORD_SIZE);
|
||||||
|
count %= WOLFSSL_WORD_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b = (byte*)buf;
|
||||||
|
m = (const byte*)mask;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
b[i] ^= m[i];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -59,12 +59,12 @@ WOLFSSL_LOCAL
|
|||||||
void ByteReverseWords(word32* out, const word32* in, word32 byteCount);
|
void ByteReverseWords(word32* out, const word32* in, word32 byteCount);
|
||||||
|
|
||||||
WOLFSSL_LOCAL
|
WOLFSSL_LOCAL
|
||||||
void XorWordsOut(wolfssl_word* r, const wolfssl_word* a, const wolfssl_word* b,
|
void XorWordsOut(wolfssl_word** r, const wolfssl_word** a,
|
||||||
word32 n);
|
const wolfssl_word** b, word32 n);
|
||||||
WOLFSSL_LOCAL
|
WOLFSSL_LOCAL
|
||||||
void xorbufout(void* out, const void* buf, const void* mask, word32 count);
|
void xorbufout(void* out, const void* buf, const void* mask, word32 count);
|
||||||
WOLFSSL_LOCAL
|
WOLFSSL_LOCAL
|
||||||
void XorWords(wolfssl_word* r, const wolfssl_word* a, word32 n);
|
void XorWords(wolfssl_word** r, const wolfssl_word** a, word32 n);
|
||||||
WOLFSSL_LOCAL
|
WOLFSSL_LOCAL
|
||||||
void xorbuf(void* buf, const void* mask, word32 count);
|
void xorbuf(void* buf, const void* mask, word32 count);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user