forked from wolfSSL/wolfssl
tidying suggested by Sean in review.
This commit is contained in:
@@ -1355,11 +1355,11 @@ end:
|
|||||||
*/
|
*/
|
||||||
word32 TimeNowInMilliseconds(void)
|
word32 TimeNowInMilliseconds(void)
|
||||||
{
|
{
|
||||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
|
||||||
return (word32)(ktime_get_real_ns() / (s64)1000000);
|
return (word32)(ktime_get_real_ns() / (s64)1000000);
|
||||||
#else
|
#else
|
||||||
return (word32)(ktime_get_real_ns() / (ktime_t)1000000);
|
return (word32)(ktime_get_real_ns() / (ktime_t)1000000);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* The time in milliseconds.
|
/* The time in milliseconds.
|
||||||
|
@@ -4510,17 +4510,17 @@ static void bench_rsa_helper(int doAsync, RsaKey rsaKey[BENCH_MAX_PENDING],
|
|||||||
!defined(WOLFSSL_RSA_PUBLIC_ONLY)
|
!defined(WOLFSSL_RSA_PUBLIC_ONLY)
|
||||||
DECLARE_ARRAY_DYNAMIC_EXE(out, byte, BENCH_MAX_PENDING, rsaKeySz, HEAP_HINT);
|
DECLARE_ARRAY_DYNAMIC_EXE(out, byte, BENCH_MAX_PENDING, rsaKeySz, HEAP_HINT);
|
||||||
if (out[0] == NULL) {
|
if (out[0] == NULL) {
|
||||||
printf("malloc failed\n");
|
ret = MEMORY_E;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (enc[0] == NULL) {
|
if (enc[0] == NULL) {
|
||||||
printf("malloc failed\n");
|
ret = MEMORY_E;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
#ifdef DECLARE_VAR_IS_HEAP_ALLOC
|
#ifdef DECLARE_VAR_IS_HEAP_ALLOC
|
||||||
if (message == NULL) {
|
if (message == NULL) {
|
||||||
printf("malloc failed\n");
|
ret = MEMORY_E;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -4871,7 +4871,7 @@ void bench_dh(int doAsync)
|
|||||||
DECLARE_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
|
DECLARE_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
|
||||||
#ifdef DECLARE_VAR_IS_HEAP_ALLOC
|
#ifdef DECLARE_VAR_IS_HEAP_ALLOC
|
||||||
if ((pub[0] == NULL) || (pub2 == NULL) || (agree[0] == NULL) || (priv[0] == NULL) || (priv2 == NULL)) {
|
if ((pub[0] == NULL) || (pub2 == NULL) || (agree[0] == NULL) || (priv[0] == NULL) || (priv2 == NULL)) {
|
||||||
printf("malloc failed\n");
|
ret = MEMORY_E;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -5315,13 +5315,13 @@ void bench_ecc(int doAsync)
|
|||||||
#ifdef DECLARE_VAR_IS_HEAP_ALLOC
|
#ifdef DECLARE_VAR_IS_HEAP_ALLOC
|
||||||
#ifdef HAVE_ECC_DHE
|
#ifdef HAVE_ECC_DHE
|
||||||
if (shared[0] == NULL) {
|
if (shared[0] == NULL) {
|
||||||
printf("malloc failed\n");
|
ret = MEMORY_E;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
|
#if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
|
||||||
if ((sig[0] == NULL) || (digest[0] == NULL)) {
|
if ((sig[0] == NULL) || (digest[0] == NULL)) {
|
||||||
printf("malloc failed\n");
|
ret = MEMORY_E;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1707,12 +1707,12 @@ static void wc_AesEncrypt(Aes* aes, const byte* inBlock, byte* outBlock)
|
|||||||
|
|
||||||
tmp_align = tmp + (AESNI_ALIGN - ((size_t)tmp % AESNI_ALIGN));
|
tmp_align = tmp + (AESNI_ALIGN - ((size_t)tmp % AESNI_ALIGN));
|
||||||
|
|
||||||
SAVE_VECTOR_REGISTERS();
|
|
||||||
XMEMCPY(tmp_align, inBlock, AES_BLOCK_SIZE);
|
XMEMCPY(tmp_align, inBlock, AES_BLOCK_SIZE);
|
||||||
|
SAVE_VECTOR_REGISTERS();
|
||||||
AES_ECB_encrypt(tmp_align, tmp_align, AES_BLOCK_SIZE,
|
AES_ECB_encrypt(tmp_align, tmp_align, AES_BLOCK_SIZE,
|
||||||
(byte*)aes->key, aes->rounds);
|
(byte*)aes->key, aes->rounds);
|
||||||
XMEMCPY(outBlock, tmp_align, AES_BLOCK_SIZE);
|
|
||||||
RESTORE_VECTOR_REGISTERS();
|
RESTORE_VECTOR_REGISTERS();
|
||||||
|
XMEMCPY(outBlock, tmp_align, AES_BLOCK_SIZE);
|
||||||
XFREE(tmp, aes->heap, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(tmp, aes->heap, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
@@ -2006,9 +2006,9 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* if input and output same will overwrite input iv */
|
/* if input and output same will overwrite input iv */
|
||||||
SAVE_VECTOR_REGISTERS();
|
|
||||||
if ((const byte*)aes->tmp != inBlock)
|
if ((const byte*)aes->tmp != inBlock)
|
||||||
XMEMCPY(aes->tmp, inBlock, AES_BLOCK_SIZE);
|
XMEMCPY(aes->tmp, inBlock, AES_BLOCK_SIZE);
|
||||||
|
SAVE_VECTOR_REGISTERS();
|
||||||
AES_ECB_decrypt(inBlock, outBlock, AES_BLOCK_SIZE, (byte*)aes->key,
|
AES_ECB_decrypt(inBlock, outBlock, AES_BLOCK_SIZE, (byte*)aes->key,
|
||||||
aes->rounds);
|
aes->rounds);
|
||||||
RESTORE_VECTOR_REGISTERS();
|
RESTORE_VECTOR_REGISTERS();
|
||||||
@@ -3683,8 +3683,8 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
aes->rounds);
|
aes->rounds);
|
||||||
#endif /* WOLFSSL_AESNI_BYx */
|
#endif /* WOLFSSL_AESNI_BYx */
|
||||||
/* store iv for next call */
|
/* store iv for next call */
|
||||||
XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE);
|
|
||||||
RESTORE_VECTOR_REGISTERS();
|
RESTORE_VECTOR_REGISTERS();
|
||||||
|
XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -6299,10 +6299,8 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
if (haveAESNI) {
|
if (haveAESNI) {
|
||||||
SAVE_VECTOR_REGISTERS();
|
|
||||||
AES_GCM_encrypt(in, out, authIn, iv, authTag, sz, authInSz, ivSz,
|
AES_GCM_encrypt(in, out, authIn, iv, authTag, sz, authInSz, ivSz,
|
||||||
authTagSz, (const byte*)aes->key, aes->rounds);
|
authTagSz, (const byte*)aes->key, aes->rounds);
|
||||||
RESTORE_VECTOR_REGISTERS();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -6779,10 +6777,8 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
if (haveAESNI) {
|
if (haveAESNI) {
|
||||||
SAVE_VECTOR_REGISTERS();
|
|
||||||
AES_GCM_decrypt(in, out, authIn, iv, authTag, sz, authInSz, ivSz,
|
AES_GCM_decrypt(in, out, authIn, iv, authTag, sz, authInSz, ivSz,
|
||||||
authTagSz, (byte*)aes->key, aes->rounds, &res);
|
authTagSz, (byte*)aes->key, aes->rounds, &res);
|
||||||
RESTORE_VECTOR_REGISTERS();
|
|
||||||
if (res == 0)
|
if (res == 0)
|
||||||
return AES_GCM_AUTH_E;
|
return AES_GCM_AUTH_E;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -7279,17 +7275,16 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
|
|||||||
#ifdef WOLFSSL_AESNI
|
#ifdef WOLFSSL_AESNI
|
||||||
if (haveAESNI && aes->use_aesni) {
|
if (haveAESNI && aes->use_aesni) {
|
||||||
while (inSz >= AES_BLOCK_SIZE * 4) {
|
while (inSz >= AES_BLOCK_SIZE * 4) {
|
||||||
SAVE_VECTOR_REGISTERS();
|
|
||||||
|
|
||||||
AesCcmCtrIncSet4(B, lenSz);
|
AesCcmCtrIncSet4(B, lenSz);
|
||||||
|
|
||||||
|
SAVE_VECTOR_REGISTERS();
|
||||||
AES_ECB_encrypt(B, A, AES_BLOCK_SIZE * 4, (byte*)aes->key,
|
AES_ECB_encrypt(B, A, AES_BLOCK_SIZE * 4, (byte*)aes->key,
|
||||||
aes->rounds);
|
aes->rounds);
|
||||||
|
RESTORE_VECTOR_REGISTERS();
|
||||||
|
|
||||||
xorbuf(A, in, AES_BLOCK_SIZE * 4);
|
xorbuf(A, in, AES_BLOCK_SIZE * 4);
|
||||||
XMEMCPY(out, A, AES_BLOCK_SIZE * 4);
|
XMEMCPY(out, A, AES_BLOCK_SIZE * 4);
|
||||||
|
|
||||||
RESTORE_VECTOR_REGISTERS();
|
|
||||||
|
|
||||||
inSz -= AES_BLOCK_SIZE * 4;
|
inSz -= AES_BLOCK_SIZE * 4;
|
||||||
in += AES_BLOCK_SIZE * 4;
|
in += AES_BLOCK_SIZE * 4;
|
||||||
out += AES_BLOCK_SIZE * 4;
|
out += AES_BLOCK_SIZE * 4;
|
||||||
@@ -7365,18 +7360,16 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
|
|||||||
#ifdef WOLFSSL_AESNI
|
#ifdef WOLFSSL_AESNI
|
||||||
if (haveAESNI && aes->use_aesni) {
|
if (haveAESNI && aes->use_aesni) {
|
||||||
while (oSz >= AES_BLOCK_SIZE * 4) {
|
while (oSz >= AES_BLOCK_SIZE * 4) {
|
||||||
SAVE_VECTOR_REGISTERS();
|
|
||||||
|
|
||||||
AesCcmCtrIncSet4(B, lenSz);
|
AesCcmCtrIncSet4(B, lenSz);
|
||||||
|
|
||||||
|
SAVE_VECTOR_REGISTERS();
|
||||||
AES_ECB_encrypt(B, A, AES_BLOCK_SIZE * 4, (byte*)aes->key,
|
AES_ECB_encrypt(B, A, AES_BLOCK_SIZE * 4, (byte*)aes->key,
|
||||||
aes->rounds);
|
aes->rounds);
|
||||||
|
RESTORE_VECTOR_REGISTERS();
|
||||||
|
|
||||||
xorbuf(A, in, AES_BLOCK_SIZE * 4);
|
xorbuf(A, in, AES_BLOCK_SIZE * 4);
|
||||||
XMEMCPY(o, A, AES_BLOCK_SIZE * 4);
|
XMEMCPY(o, A, AES_BLOCK_SIZE * 4);
|
||||||
|
|
||||||
RESTORE_VECTOR_REGISTERS();
|
|
||||||
|
|
||||||
oSz -= AES_BLOCK_SIZE * 4;
|
oSz -= AES_BLOCK_SIZE * 4;
|
||||||
in += AES_BLOCK_SIZE * 4;
|
in += AES_BLOCK_SIZE * 4;
|
||||||
o += AES_BLOCK_SIZE * 4;
|
o += AES_BLOCK_SIZE * 4;
|
||||||
|
@@ -10672,10 +10672,9 @@ int ge448_double_scalarmult_vartime(ge448_p2 *r, const uint8_t *a,
|
|||||||
int8_t aslide[GE448_WINDOW_BUF_SIZE];
|
int8_t aslide[GE448_WINDOW_BUF_SIZE];
|
||||||
int8_t bslide[GE448_WINDOW_BUF_SIZE];
|
int8_t bslide[GE448_WINDOW_BUF_SIZE];
|
||||||
ge448_p2 pi[16]; /* p,3p,..,31p */
|
ge448_p2 pi[16]; /* p,3p,..,31p */
|
||||||
ge448_p2 p2;
|
ge448_p2 p2_data, *p2 = &p2_data;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
#define PI_PTR(pi) (&(pi))
|
|
||||||
#else
|
#else
|
||||||
int8_t *aslide = NULL;
|
int8_t *aslide = NULL;
|
||||||
int8_t *bslide = NULL;
|
int8_t *bslide = NULL;
|
||||||
@@ -10683,8 +10682,6 @@ int ge448_double_scalarmult_vartime(ge448_p2 *r, const uint8_t *a,
|
|||||||
ge448_p2 *p2 = NULL;
|
ge448_p2 *p2 = NULL;
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
|
||||||
#define PI_PTR(pi) (pi)
|
|
||||||
|
|
||||||
aslide = (int8_t *)XMALLOC(GE448_WINDOW_BUF_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
aslide = (int8_t *)XMALLOC(GE448_WINDOW_BUF_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
if (! aslide) {
|
if (! aslide) {
|
||||||
ret = MEMORY_E;
|
ret = MEMORY_E;
|
||||||
@@ -10713,22 +10710,22 @@ int ge448_double_scalarmult_vartime(ge448_p2 *r, const uint8_t *a,
|
|||||||
fe448_copy(pi[0].X, p->X);
|
fe448_copy(pi[0].X, p->X);
|
||||||
fe448_copy(pi[0].Y, p->Y);
|
fe448_copy(pi[0].Y, p->Y);
|
||||||
fe448_copy(pi[0].Z, p->Z);
|
fe448_copy(pi[0].Z, p->Z);
|
||||||
ge448_dbl(PI_PTR(p2), p);
|
ge448_dbl(p2, p);
|
||||||
ge448_add(&pi[1], PI_PTR(p2), &pi[0]);
|
ge448_add(&pi[1], p2, &pi[0]);
|
||||||
ge448_add(&pi[2], PI_PTR(p2), &pi[1]);
|
ge448_add(&pi[2], p2, &pi[1]);
|
||||||
ge448_add(&pi[3], PI_PTR(p2), &pi[2]);
|
ge448_add(&pi[3], p2, &pi[2]);
|
||||||
ge448_add(&pi[4], PI_PTR(p2), &pi[3]);
|
ge448_add(&pi[4], p2, &pi[3]);
|
||||||
ge448_add(&pi[5], PI_PTR(p2), &pi[4]);
|
ge448_add(&pi[5], p2, &pi[4]);
|
||||||
ge448_add(&pi[6], PI_PTR(p2), &pi[5]);
|
ge448_add(&pi[6], p2, &pi[5]);
|
||||||
ge448_add(&pi[7], PI_PTR(p2), &pi[6]);
|
ge448_add(&pi[7], p2, &pi[6]);
|
||||||
ge448_add(&pi[8], PI_PTR(p2), &pi[7]);
|
ge448_add(&pi[8], p2, &pi[7]);
|
||||||
ge448_add(&pi[9], PI_PTR(p2), &pi[8]);
|
ge448_add(&pi[9], p2, &pi[8]);
|
||||||
ge448_add(&pi[10], PI_PTR(p2), &pi[9]);
|
ge448_add(&pi[10], p2, &pi[9]);
|
||||||
ge448_add(&pi[11], PI_PTR(p2), &pi[10]);
|
ge448_add(&pi[11], p2, &pi[10]);
|
||||||
ge448_add(&pi[12], PI_PTR(p2), &pi[11]);
|
ge448_add(&pi[12], p2, &pi[11]);
|
||||||
ge448_add(&pi[13], PI_PTR(p2), &pi[12]);
|
ge448_add(&pi[13], p2, &pi[12]);
|
||||||
ge448_add(&pi[14], PI_PTR(p2), &pi[13]);
|
ge448_add(&pi[14], p2, &pi[13]);
|
||||||
ge448_add(&pi[15], PI_PTR(p2), &pi[14]);
|
ge448_add(&pi[15], p2, &pi[14]);
|
||||||
|
|
||||||
ge448_0(r);
|
ge448_0(r);
|
||||||
|
|
||||||
@@ -10772,7 +10769,6 @@ int ge448_double_scalarmult_vartime(ge448_p2 *r, const uint8_t *a,
|
|||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#undef PI_PTR
|
|
||||||
#undef GE448_WINDOW_BUF_SIZE
|
#undef GE448_WINDOW_BUF_SIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3953,17 +3953,17 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
|
|||||||
{
|
{
|
||||||
#ifndef WC_NO_RNG
|
#ifndef WC_NO_RNG
|
||||||
#ifdef WOLFSSL_SMALL_STACK
|
#ifdef WOLFSSL_SMALL_STACK
|
||||||
mp_int *p = (mp_int *)XMALLOC(sizeof *p, key->heap, DYNAMIC_TYPE_RSA),
|
mp_int *p = (mp_int *)XMALLOC(sizeof *p, key->heap, DYNAMIC_TYPE_RSA);
|
||||||
*q = (mp_int *)XMALLOC(sizeof *q, key->heap, DYNAMIC_TYPE_RSA),
|
mp_int *q = (mp_int *)XMALLOC(sizeof *q, key->heap, DYNAMIC_TYPE_RSA);
|
||||||
*tmp1 = (mp_int *)XMALLOC(sizeof *tmp1, key->heap, DYNAMIC_TYPE_RSA),
|
mp_int *tmp1 = (mp_int *)XMALLOC(sizeof *tmp1, key->heap, DYNAMIC_TYPE_RSA);
|
||||||
*tmp2 = (mp_int *)XMALLOC(sizeof *tmp2, key->heap, DYNAMIC_TYPE_RSA),
|
mp_int *tmp2 = (mp_int *)XMALLOC(sizeof *tmp2, key->heap, DYNAMIC_TYPE_RSA);
|
||||||
*tmp3 = (mp_int *)XMALLOC(sizeof *tmp3, key->heap, DYNAMIC_TYPE_RSA);
|
mp_int *tmp3 = (mp_int *)XMALLOC(sizeof *tmp3, key->heap, DYNAMIC_TYPE_RSA);
|
||||||
#else
|
#else
|
||||||
mp_int p_buf, *p = &p_buf,
|
mp_int p_buf, *p = &p_buf;
|
||||||
q_buf, *q = &q_buf,
|
mp_int q_buf, *q = &q_buf;
|
||||||
tmp1_buf, *tmp1 = &tmp1_buf,
|
mp_int tmp1_buf, *tmp1 = &tmp1_buf;
|
||||||
tmp2_buf, *tmp2 = &tmp2_buf,
|
mp_int tmp2_buf, *tmp2 = &tmp2_buf;
|
||||||
tmp3_buf, *tmp3 = &tmp3_buf;
|
mp_int tmp3_buf, *tmp3 = &tmp3_buf;
|
||||||
#endif
|
#endif
|
||||||
int err, i, failCount, primeSz, isPrime = 0;
|
int err, i, failCount, primeSz, isPrime = 0;
|
||||||
byte* buf = NULL;
|
byte* buf = NULL;
|
||||||
|
Reference in New Issue
Block a user