Improve performance of SP Intel 64-bit asm

RSA: Only constant time copy out when doing private key op
Improve performance of sp_count_bits
This commit is contained in:
Sean Parkinson
2020-01-30 12:23:38 +10:00
parent 695b126a1c
commit 81bebd8e5c
4 changed files with 4248 additions and 2260 deletions

View File

@@ -2951,6 +2951,7 @@ static int RsaPrivateDecryptEx(byte* in, word32 inLen, byte* out,
/* only copy output if not inline */ /* only copy output if not inline */
if (outPtr == NULL) { if (outPtr == NULL) {
#if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_VERIFY_INLINE) #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_VERIFY_INLINE)
if (rsa_type == RSA_PRIVATE_DECRYPT) {
word32 i, j; word32 i, j;
int start = (int)((size_t)pad - (size_t)key->data); int start = (int)((size_t)pad - (size_t)key->data);
@@ -2961,9 +2962,12 @@ static int RsaPrivateDecryptEx(byte* in, word32 inLen, byte* out,
/* 0 - no add, -1 add */ /* 0 - no add, -1 add */
i += (word32)((byte)(-c)); i += (word32)((byte)(-c));
} }
#else }
XMEMCPY(out, pad, ret); else
#endif #endif
{
XMEMCPY(out, pad, ret);
}
} }
else else
*outPtr = pad; *outPtr = pad;

View File

@@ -306,12 +306,21 @@ int sp_count_bits(sp_int* a)
r = 0; r = 0;
else { else {
d = a->dp[r]; d = a->dp[r];
r *= DIGIT_BIT; r *= SP_WORD_SIZE;
if (d >= (1L << (SP_WORD_SIZE / 2))) {
r += SP_WORD_SIZE;
while ((d & (1L << (SP_WORD_SIZE - 1))) == 0) {
r--;
d <<= 1;
}
}
else {
while (d != 0) { while (d != 0) {
r++; r++;
d >>= 1; d >>= 1;
} }
} }
}
return r; return r;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff