mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 19:24:42 +02:00
linuxkm: {SAVE,RESTORE}_VECTOR_REGISTERS() wrappers around RSA, DH, and ECC routines that might use sp-asm.
This commit is contained in:
@@ -8489,6 +8489,8 @@ static void AesGcmAadUpdate_aesni(Aes* aes, const byte* a, word32 aSz, int endA)
|
||||
word32 blocks;
|
||||
int partial;
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
if (aSz != 0 && a != NULL) {
|
||||
/* Total count of AAD updated. */
|
||||
aes->aSz += aSz;
|
||||
|
@@ -1358,6 +1358,8 @@ static int wc_DhGenerateKeyPair_Sync(DhKey* key, WC_RNG* rng,
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
|
||||
ret = GeneratePrivateDh(key, rng, priv, privSz);
|
||||
|
||||
if (ret == 0)
|
||||
@@ -1369,6 +1371,8 @@ static int wc_DhGenerateKeyPair_Sync(DhKey* key, WC_RNG* rng,
|
||||
if (ret == 0)
|
||||
ret = _ffc_pairwise_consistency_test(key, pub, *pubSz, priv, *privSz);
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* !WOLFSSL_KCAPI_DH */
|
||||
@@ -1978,6 +1982,8 @@ static int wc_DhAgree_Sync(DhKey* key, byte* agree, word32* agreeSz,
|
||||
if (mp_init(y) != MP_OKAY)
|
||||
return MP_INIT_E;
|
||||
|
||||
SAVE_VECTOR_REGISTERS();
|
||||
|
||||
if (ret == 0 && mp_read_unsigned_bin(y, otherPub, pubSz) != MP_OKAY)
|
||||
ret = MP_READ_E;
|
||||
|
||||
@@ -1985,6 +1991,9 @@ static int wc_DhAgree_Sync(DhKey* key, byte* agree, word32* agreeSz,
|
||||
ret = sp_DhExp_2048(y, priv, privSz, &key->p, agree, agreeSz);
|
||||
|
||||
mp_clear(y);
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
#if !defined(WOLFSSL_SP_MATH)
|
||||
XFREE(z, key->heap, DYNAMIC_TYPE_DH);
|
||||
@@ -2000,6 +2009,8 @@ static int wc_DhAgree_Sync(DhKey* key, byte* agree, word32* agreeSz,
|
||||
if (mp_init(y) != MP_OKAY)
|
||||
return MP_INIT_E;
|
||||
|
||||
SAVE_VECTOR_REGISTERS();
|
||||
|
||||
if (ret == 0 && mp_read_unsigned_bin(y, otherPub, pubSz) != MP_OKAY)
|
||||
ret = MP_READ_E;
|
||||
|
||||
@@ -2007,6 +2018,9 @@ static int wc_DhAgree_Sync(DhKey* key, byte* agree, word32* agreeSz,
|
||||
ret = sp_DhExp_3072(y, priv, privSz, &key->p, agree, agreeSz);
|
||||
|
||||
mp_clear(y);
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
#if !defined(WOLFSSL_SP_MATH)
|
||||
XFREE(z, key->heap, DYNAMIC_TYPE_DH);
|
||||
@@ -2022,6 +2036,8 @@ static int wc_DhAgree_Sync(DhKey* key, byte* agree, word32* agreeSz,
|
||||
if (mp_init(y) != MP_OKAY)
|
||||
return MP_INIT_E;
|
||||
|
||||
SAVE_VECTOR_REGISTERS();
|
||||
|
||||
if (ret == 0 && mp_read_unsigned_bin(y, otherPub, pubSz) != MP_OKAY)
|
||||
ret = MP_READ_E;
|
||||
|
||||
@@ -2029,6 +2045,9 @@ static int wc_DhAgree_Sync(DhKey* key, byte* agree, word32* agreeSz,
|
||||
ret = sp_DhExp_4096(y, priv, privSz, &key->p, agree, agreeSz);
|
||||
|
||||
mp_clear(y);
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
#if !defined(WOLFSSL_SP_MATH)
|
||||
XFREE(z, key->heap, DYNAMIC_TYPE_DH);
|
||||
@@ -2051,6 +2070,8 @@ static int wc_DhAgree_Sync(DhKey* key, byte* agree, word32* agreeSz,
|
||||
return MP_INIT_E;
|
||||
}
|
||||
|
||||
SAVE_VECTOR_REGISTERS();
|
||||
|
||||
if (mp_read_unsigned_bin(x, priv, privSz) != MP_OKAY)
|
||||
ret = MP_READ_E;
|
||||
|
||||
@@ -2073,6 +2094,9 @@ static int wc_DhAgree_Sync(DhKey* key, byte* agree, word32* agreeSz,
|
||||
mp_clear(z);
|
||||
mp_clear(y);
|
||||
mp_forcezero(x);
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
#else
|
||||
ret = WC_KEY_SIZE_E;
|
||||
#endif
|
||||
@@ -2824,6 +2848,8 @@ int wc_DhGenerateParams(WC_RNG *rng, int modSz, DhKey *dh)
|
||||
}
|
||||
#endif
|
||||
|
||||
SAVE_VECTOR_REGISTERS();
|
||||
|
||||
if (ret == 0) {
|
||||
/* force magnitude */
|
||||
buf[0] |= 0xC0;
|
||||
@@ -2919,6 +2945,8 @@ int wc_DhGenerateParams(WC_RNG *rng, int modSz, DhKey *dh)
|
||||
mp_clear(&dh->g);
|
||||
}
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
if (buf != NULL) {
|
||||
ForceZero(buf, bufSz);
|
||||
if (dh != NULL) {
|
||||
|
@@ -4453,6 +4453,8 @@ static int ecc_make_pub_ex(ecc_key* key, ecc_curve_spec* curveIn,
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
|
||||
#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) \
|
||||
&& !defined(WOLFSSL_SILABS_SE_ACCEL) && !defined(WOLFSSL_KCAPI_ECC)
|
||||
|
||||
@@ -4580,6 +4582,8 @@ static int ecc_make_pub_ex(ecc_key* key, ecc_curve_spec* curveIn,
|
||||
key->type = ECC_PRIVATEKEY;
|
||||
}
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -4843,7 +4847,11 @@ static int _ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key,
|
||||
int wc_ecc_make_key_ex2(WC_RNG* rng, int keysize, ecc_key* key, int curve_id,
|
||||
int flags)
|
||||
{
|
||||
int err = _ecc_make_key_ex(rng, keysize, key, curve_id, flags);
|
||||
int err;
|
||||
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
|
||||
err = _ecc_make_key_ex(rng, keysize, key, curve_id, flags);
|
||||
|
||||
if (err == MP_OKAY) {
|
||||
err = _ecc_validate_public_key(key, 0, 0);
|
||||
@@ -4854,6 +4862,8 @@ int wc_ecc_make_key_ex2(WC_RNG* rng, int keysize, ecc_key* key, int curve_id,
|
||||
}
|
||||
#endif
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -8479,6 +8489,8 @@ static int _ecc_validate_public_key(ecc_key* key, int partial, int priv)
|
||||
!WOLFSSL_CRYPTOCELL && !WOLFSSL_SILABS_SE_ACCEL */
|
||||
#endif /* !WOLFSSL_SP_MATH */
|
||||
|
||||
ASSERT_SAVED_VECTOR_REGISTERS();
|
||||
|
||||
if (key == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
@@ -8637,7 +8649,10 @@ static int _ecc_validate_public_key(ecc_key* key, int partial, int priv)
|
||||
/* perform sanity checks on ecc key validity, 0 on success */
|
||||
int wc_ecc_check_key(ecc_key* key)
|
||||
{
|
||||
return _ecc_validate_public_key(key, 0, 1);
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
int ret = _ecc_validate_public_key(key, 0, 1);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -8683,6 +8698,8 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
|
||||
if (err != MP_OKAY)
|
||||
return MEMORY_E;
|
||||
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
|
||||
/* check for point type (4, 2, or 3) */
|
||||
pointType = in[0];
|
||||
if (pointType != ECC_POINT_UNCOMP && pointType != ECC_POINT_COMP_EVEN &&
|
||||
@@ -8866,6 +8883,8 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
|
||||
mp_clear(&key->k);
|
||||
}
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -9104,6 +9123,10 @@ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz,
|
||||
}
|
||||
#else
|
||||
|
||||
#ifdef WOLFSSL_VALIDATE_ECC_IMPORT
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
#endif
|
||||
|
||||
ret = mp_read_unsigned_bin(&key->k, priv, privSz);
|
||||
#ifdef HAVE_WOLF_BIGINT
|
||||
if (ret == 0 &&
|
||||
@@ -9121,6 +9144,10 @@ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz,
|
||||
ret = _ecc_validate_public_key(key, 1, 1);
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_VALIDATE_ECC_IMPORT
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -9377,6 +9404,10 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx,
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_VALIDATE_ECC_IMPORT
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
#endif
|
||||
|
||||
/* import private key */
|
||||
if (err == MP_OKAY) {
|
||||
if (d != NULL) {
|
||||
@@ -9436,6 +9467,10 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx,
|
||||
err = wc_ecc_check_key(key);
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_VALIDATE_ECC_IMPORT
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
#endif
|
||||
|
||||
if (err != MP_OKAY) {
|
||||
mp_clear(key->pubkey.x);
|
||||
mp_clear(key->pubkey.y);
|
||||
@@ -10898,6 +10933,8 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
|
||||
}
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
SAVE_VECTOR_REGISTERS();
|
||||
|
||||
/* find point */
|
||||
idx1 = find_base(A);
|
||||
|
||||
@@ -10978,7 +11015,9 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
|
||||
} else {
|
||||
err = normal_ecc_mul2add(A, kA, B, kB, C, a, modulus, heap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
#ifndef HAVE_THREAD_LS
|
||||
wc_UnLockMutex(&ecc_fp_lock);
|
||||
@@ -11051,6 +11090,8 @@ int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
||||
got_ecc_fp_lock = 1;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
SAVE_VECTOR_REGISTERS(err = _svr_ret; goto out;);
|
||||
|
||||
/* find point */
|
||||
idx = find_base(G);
|
||||
|
||||
@@ -11097,7 +11138,9 @@ int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
||||
} else {
|
||||
err = normal_ecc_mulmod(k, G, R, a, modulus, NULL, map, heap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
out:
|
||||
|
||||
@@ -11120,12 +11163,20 @@ int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
||||
|
||||
#ifndef WOLFSSL_SP_NO_256
|
||||
if (mp_count_bits(modulus) == 256) {
|
||||
return sp_ecc_mulmod_256(k, G, R, map, heap);
|
||||
int ret;
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret);
|
||||
ret = sp_ecc_mulmod_256(k, G, R, map, heap);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef WOLFSSL_SP_384
|
||||
if (mp_count_bits(modulus) == 384) {
|
||||
return sp_ecc_mulmod_384(k, G, R, map, heap);
|
||||
int ret;
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret);
|
||||
ret = sp_ecc_mulmod_384(k, G, R, map, heap);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
return WC_KEY_SIZE_E;
|
||||
@@ -11191,6 +11242,8 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
||||
got_ecc_fp_lock = 1;
|
||||
#endif /* HAVE_THREAD_LS */
|
||||
|
||||
SAVE_VECTOR_REGISTERS(err = _svr_ret; goto out;);
|
||||
|
||||
/* find point */
|
||||
idx = find_base(G);
|
||||
|
||||
@@ -11237,7 +11290,9 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
||||
} else {
|
||||
err = normal_ecc_mulmod(k, G, R, a, modulus, rng, map, heap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
out:
|
||||
|
||||
@@ -11263,12 +11318,20 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
||||
|
||||
#ifndef WOLFSSL_SP_NO_256
|
||||
if (mp_count_bits(modulus) == 256) {
|
||||
return sp_ecc_mulmod_256(k, G, R, map, heap);
|
||||
int ret;
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret);
|
||||
ret = sp_ecc_mulmod_256(k, G, R, map, heap);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#ifdef WOLFSSL_SP_384
|
||||
if (mp_count_bits(modulus) == 384) {
|
||||
return sp_ecc_mulmod_384(k, G, R, map, heap);
|
||||
int ret;
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret);
|
||||
ret = sp_ecc_mulmod_384(k, G, R, map, heap);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
return WC_KEY_SIZE_E;
|
||||
@@ -11725,6 +11788,8 @@ int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
|
||||
}
|
||||
#endif
|
||||
|
||||
SAVE_VECTOR_REGISTERS();
|
||||
|
||||
#ifdef WOLFSSL_ECIES_ISO18033
|
||||
XMEMCPY(sharedSecret, out - pubKeySz, pubKeySz);
|
||||
sharedSz -= pubKeySz;
|
||||
@@ -11859,6 +11924,8 @@ int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
|
||||
#endif
|
||||
}
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(sharedSecret, ctx->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||
XFREE(keys, ctx->heap, DYNAMIC_TYPE_ECC_BUFFER);
|
||||
@@ -11996,6 +12063,8 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
|
||||
}
|
||||
#endif
|
||||
|
||||
SAVE_VECTOR_REGISTERS();
|
||||
|
||||
#ifndef WOLFSSL_ECIES_OLD
|
||||
if (pubKey == NULL) {
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
@@ -12159,6 +12228,8 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
|
||||
if (ret == 0)
|
||||
*outSz = msgSz - digestSz;
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
#ifndef WOLFSSL_ECIES_OLD
|
||||
if (pubKey == peerKey)
|
||||
wc_ecc_free(peerKey);
|
||||
@@ -12211,6 +12282,8 @@ int mp_jacobi(mp_int* a, mp_int* n, int* c)
|
||||
return res;
|
||||
}
|
||||
|
||||
SAVE_VECTOR_REGISTERS();
|
||||
|
||||
if ((res = mp_mod(a, n, &a1)) != MP_OKAY) {
|
||||
goto done;
|
||||
}
|
||||
@@ -12267,6 +12340,9 @@ int mp_jacobi(mp_int* a, mp_int* n, int* c)
|
||||
*c = s;
|
||||
|
||||
done:
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
/* cleanup */
|
||||
mp_clear(&n1);
|
||||
mp_clear(&a1);
|
||||
@@ -12287,6 +12363,8 @@ int mp_sqrtmod_prime(mp_int* n, mp_int* prime, mp_int* ret)
|
||||
|
||||
mp_int e;
|
||||
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
|
||||
res = mp_init(&e);
|
||||
if (res == MP_OKAY)
|
||||
res = mp_add_d(prime, 1, &e);
|
||||
@@ -12297,6 +12375,8 @@ int mp_sqrtmod_prime(mp_int* n, mp_int* prime, mp_int* ret)
|
||||
|
||||
mp_clear(&e);
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
return res;
|
||||
#else
|
||||
int res, legendre, done = 0;
|
||||
@@ -12315,6 +12395,8 @@ int mp_sqrtmod_prime(mp_int* n, mp_int* prime, mp_int* ret)
|
||||
mp_int t1[1], C[1], Q[1], S[1], Z[1], M[1], T[1], R[1], two[1];
|
||||
#endif
|
||||
|
||||
SAVE_VECTOR_REGISTERS(res = _svr_ret; goto out;);
|
||||
|
||||
if ((mp_init_multi(t1, C, Q, S, Z, M) != MP_OKAY) ||
|
||||
(mp_init_multi(T, R, two, NULL, NULL, NULL) != MP_OKAY)) {
|
||||
res = MP_INIT_E;
|
||||
@@ -12494,6 +12576,8 @@ int mp_sqrtmod_prime(mp_int* n, mp_int* prime, mp_int* ret)
|
||||
|
||||
out:
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
if (t1) {
|
||||
if (res != MP_INIT_E)
|
||||
@@ -12557,8 +12641,8 @@ int mp_sqrtmod_prime(mp_int* n, mp_int* prime, mp_int* ret)
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif /* !WOLFSSL_ATECC508A && !WOLFSSL_CRYPTOCELL */
|
||||
#endif /* !WOLFSSL_SP_MATH */
|
||||
#endif /* !WOLFSSL_ATECC508A && !WOLFSSL_ATECC608A && !WOLFSSL_CRYPTOCELL */
|
||||
|
||||
|
||||
/* export public ECC key in ANSI X9.63 format compressed */
|
||||
|
@@ -697,6 +697,9 @@ int wc_CheckRsaKey(RsaKey* key)
|
||||
|
||||
ret = wc_InitRng(rng);
|
||||
|
||||
if (ret == 0)
|
||||
SAVE_VECTOR_REGISTERS(ret = _svr_ret;);
|
||||
|
||||
if (ret == 0) {
|
||||
if (mp_init(tmp) != MP_OKAY)
|
||||
ret = MP_INIT_E;
|
||||
@@ -795,6 +798,9 @@ int wc_CheckRsaKey(RsaKey* key)
|
||||
|
||||
mp_forcezero(tmp);
|
||||
mp_clear(tmp);
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
wc_FreeRng(rng);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(tmp, NULL, DYNAMIC_TYPE_RSA);
|
||||
@@ -2855,6 +2861,8 @@ int wc_RsaFunction(const byte* in, word32 inLen, byte* out,
|
||||
}
|
||||
#endif
|
||||
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
|
||||
#ifndef WOLFSSL_RSA_VERIFY_ONLY
|
||||
#ifndef TEST_UNPAD_CONSTANT_TIME
|
||||
#ifndef NO_RSA_BOUNDS_CHECK
|
||||
@@ -2901,8 +2909,10 @@ int wc_RsaFunction(const byte* in, word32 inLen, byte* out,
|
||||
XFREE(c, key->heap, DYNAMIC_TYPE_RSA);
|
||||
#endif
|
||||
|
||||
if (ret != 0)
|
||||
if (ret != 0) {
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
#endif /* NO_RSA_BOUNDS_CHECK */
|
||||
#endif
|
||||
@@ -2925,6 +2935,8 @@ int wc_RsaFunction(const byte* in, word32 inLen, byte* out,
|
||||
ret = wc_RsaFunctionSync(in, inLen, out, outLen, type, key, rng);
|
||||
}
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
/* handle error */
|
||||
if (ret < 0 && ret != WC_PENDING_E
|
||||
#ifdef WC_RSA_NONBLOCK
|
||||
@@ -3304,9 +3316,13 @@ static int RsaPrivateDecryptEx(const byte* in, word32 inLen, byte* out,
|
||||
int wc_RsaPublicEncrypt(const byte* in, word32 inLen, byte* out, word32 outLen,
|
||||
RsaKey* key, WC_RNG* rng)
|
||||
{
|
||||
return RsaPublicEncryptEx(in, inLen, out, outLen, key,
|
||||
int ret;
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
ret = RsaPublicEncryptEx(in, inLen, out, outLen, key,
|
||||
RSA_PUBLIC_ENCRYPT, RSA_BLOCK_TYPE_2, WC_RSA_PKCSV15_PAD,
|
||||
WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0, 0, rng);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -3316,8 +3332,12 @@ int wc_RsaPublicEncrypt_ex(const byte* in, word32 inLen, byte* out,
|
||||
enum wc_HashType hash, int mgf, byte* label,
|
||||
word32 labelSz)
|
||||
{
|
||||
return RsaPublicEncryptEx(in, inLen, out, outLen, key, RSA_PUBLIC_ENCRYPT,
|
||||
int ret;
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
ret = RsaPublicEncryptEx(in, inLen, out, outLen, key, RSA_PUBLIC_ENCRYPT,
|
||||
RSA_BLOCK_TYPE_2, type, hash, mgf, label, labelSz, 0, rng);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
#endif /* WC_NO_RSA_OAEP */
|
||||
#endif
|
||||
@@ -3327,14 +3347,18 @@ int wc_RsaPublicEncrypt_ex(const byte* in, word32 inLen, byte* out,
|
||||
int wc_RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out, RsaKey* key)
|
||||
{
|
||||
WC_RNG* rng;
|
||||
int ret;
|
||||
#ifdef WC_RSA_BLINDING
|
||||
rng = key->rng;
|
||||
#else
|
||||
rng = NULL;
|
||||
#endif
|
||||
return RsaPrivateDecryptEx(in, inLen, in, inLen, out, key,
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
ret = RsaPrivateDecryptEx(in, inLen, in, inLen, out, key,
|
||||
RSA_PRIVATE_DECRYPT, RSA_BLOCK_TYPE_2, WC_RSA_PKCSV15_PAD,
|
||||
WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0, 0, rng);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -3344,14 +3368,18 @@ int wc_RsaPrivateDecryptInline_ex(byte* in, word32 inLen, byte** out,
|
||||
int mgf, byte* label, word32 labelSz)
|
||||
{
|
||||
WC_RNG* rng;
|
||||
int ret;
|
||||
#ifdef WC_RSA_BLINDING
|
||||
rng = key->rng;
|
||||
#else
|
||||
rng = NULL;
|
||||
#endif
|
||||
return RsaPrivateDecryptEx(in, inLen, in, inLen, out, key,
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
ret = RsaPrivateDecryptEx(in, inLen, in, inLen, out, key,
|
||||
RSA_PRIVATE_DECRYPT, RSA_BLOCK_TYPE_2, type, hash,
|
||||
mgf, label, labelSz, 0, rng);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
#endif /* WC_NO_RSA_OAEP */
|
||||
|
||||
@@ -3360,14 +3388,18 @@ int wc_RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out,
|
||||
word32 outLen, RsaKey* key)
|
||||
{
|
||||
WC_RNG* rng;
|
||||
int ret;
|
||||
#ifdef WC_RSA_BLINDING
|
||||
rng = key->rng;
|
||||
#else
|
||||
rng = NULL;
|
||||
#endif
|
||||
return RsaPrivateDecryptEx(in, inLen, out, outLen, NULL, key,
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
ret = RsaPrivateDecryptEx(in, inLen, out, outLen, NULL, key,
|
||||
RSA_PRIVATE_DECRYPT, RSA_BLOCK_TYPE_2, WC_RSA_PKCSV15_PAD,
|
||||
WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0, 0, rng);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if !defined(WC_NO_RSA_OAEP) || defined(WC_RSA_NO_PADDING)
|
||||
@@ -3377,14 +3409,18 @@ int wc_RsaPrivateDecrypt_ex(const byte* in, word32 inLen, byte* out,
|
||||
word32 labelSz)
|
||||
{
|
||||
WC_RNG* rng;
|
||||
int ret;
|
||||
#ifdef WC_RSA_BLINDING
|
||||
rng = key->rng;
|
||||
#else
|
||||
rng = NULL;
|
||||
#endif
|
||||
return RsaPrivateDecryptEx(in, inLen, out, outLen, NULL, key,
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
ret = RsaPrivateDecryptEx(in, inLen, out, outLen, NULL, key,
|
||||
RSA_PRIVATE_DECRYPT, RSA_BLOCK_TYPE_2, type, hash, mgf, label,
|
||||
labelSz, 0, rng);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
#endif /* WC_NO_RSA_OAEP || WC_RSA_NO_PADDING */
|
||||
#endif /* WOLFSSL_RSA_PUBLIC_ONLY */
|
||||
@@ -3393,14 +3429,18 @@ int wc_RsaPrivateDecrypt_ex(const byte* in, word32 inLen, byte* out,
|
||||
int wc_RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out, RsaKey* key)
|
||||
{
|
||||
WC_RNG* rng;
|
||||
int ret;
|
||||
#ifdef WC_RSA_BLINDING
|
||||
rng = key->rng;
|
||||
#else
|
||||
rng = NULL;
|
||||
#endif
|
||||
return RsaPrivateDecryptEx(in, inLen, in, inLen, out, key,
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
ret = RsaPrivateDecryptEx(in, inLen, in, inLen, out, key,
|
||||
RSA_PUBLIC_DECRYPT, RSA_BLOCK_TYPE_1, WC_RSA_PKCSV15_PAD,
|
||||
WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0, 0, rng);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -3414,14 +3454,19 @@ int wc_RsaSSL_Verify(const byte* in, word32 inLen, byte* out, word32 outLen,
|
||||
int wc_RsaSSL_Verify_ex(const byte* in, word32 inLen, byte* out, word32 outLen,
|
||||
RsaKey* key, int pad_type)
|
||||
{
|
||||
return wc_RsaSSL_Verify_ex2(in, inLen, out, outLen, key, pad_type,
|
||||
int ret;
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
ret = wc_RsaSSL_Verify_ex2(in, inLen, out, outLen, key, pad_type,
|
||||
WC_HASH_TYPE_NONE);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wc_RsaSSL_Verify_ex2(const byte* in, word32 inLen, byte* out, word32 outLen,
|
||||
RsaKey* key, int pad_type, enum wc_HashType hash)
|
||||
{
|
||||
WC_RNG* rng;
|
||||
int ret;
|
||||
|
||||
if (key == NULL) {
|
||||
return BAD_FUNC_ARG;
|
||||
@@ -3433,15 +3478,18 @@ int wc_RsaSSL_Verify_ex2(const byte* in, word32 inLen, byte* out, word32 outLen
|
||||
rng = NULL;
|
||||
#endif
|
||||
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
#ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
|
||||
return RsaPrivateDecryptEx(in, inLen, out, outLen, NULL, key,
|
||||
ret = RsaPrivateDecryptEx(in, inLen, out, outLen, NULL, key,
|
||||
RSA_PUBLIC_DECRYPT, RSA_BLOCK_TYPE_1, pad_type,
|
||||
hash, wc_hash2mgf(hash), NULL, 0, RSA_PSS_SALT_LEN_DEFAULT, rng);
|
||||
#else
|
||||
return RsaPrivateDecryptEx(in, inLen, out, outLen, NULL, key,
|
||||
ret = RsaPrivateDecryptEx(in, inLen, out, outLen, NULL, key,
|
||||
RSA_PUBLIC_DECRYPT, RSA_BLOCK_TYPE_1, pad_type,
|
||||
hash, wc_hash2mgf(hash), NULL, 0, RSA_PSS_SALT_LEN_DISCOVER, rng);
|
||||
#endif
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -3489,14 +3537,18 @@ int wc_RsaPSS_VerifyInline_ex(byte* in, word32 inLen, byte** out,
|
||||
RsaKey* key)
|
||||
{
|
||||
WC_RNG* rng;
|
||||
int ret;
|
||||
#ifdef WC_RSA_BLINDING
|
||||
rng = key->rng;
|
||||
#else
|
||||
rng = NULL;
|
||||
#endif
|
||||
return RsaPrivateDecryptEx(in, inLen, in, inLen, out, key,
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
ret = RsaPrivateDecryptEx(in, inLen, in, inLen, out, key,
|
||||
RSA_PUBLIC_DECRYPT, RSA_BLOCK_TYPE_1, WC_RSA_PSS_PAD,
|
||||
hash, mgf, NULL, 0, saltLen, rng);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Verify the message signed with RSA-PSS.
|
||||
@@ -3540,14 +3592,18 @@ int wc_RsaPSS_Verify_ex(byte* in, word32 inLen, byte* out, word32 outLen,
|
||||
RsaKey* key)
|
||||
{
|
||||
WC_RNG* rng;
|
||||
int ret;
|
||||
#ifdef WC_RSA_BLINDING
|
||||
rng = key->rng;
|
||||
#else
|
||||
rng = NULL;
|
||||
#endif
|
||||
return RsaPrivateDecryptEx(in, inLen, out, outLen, NULL, key,
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
ret = RsaPrivateDecryptEx(in, inLen, out, outLen, NULL, key,
|
||||
RSA_PUBLIC_DECRYPT, RSA_BLOCK_TYPE_1, WC_RSA_PSS_PAD,
|
||||
hash, mgf, NULL, 0, saltLen, rng);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -3784,9 +3840,13 @@ int wc_RsaPSS_VerifyCheck(byte* in, word32 inLen, byte* out, word32 outLen,
|
||||
int wc_RsaSSL_Sign(const byte* in, word32 inLen, byte* out, word32 outLen,
|
||||
RsaKey* key, WC_RNG* rng)
|
||||
{
|
||||
return RsaPublicEncryptEx(in, inLen, out, outLen, key,
|
||||
int ret;
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
ret = RsaPublicEncryptEx(in, inLen, out, outLen, key,
|
||||
RSA_PRIVATE_ENCRYPT, RSA_BLOCK_TYPE_1, WC_RSA_PKCSV15_PAD,
|
||||
WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0, 0, rng);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef WC_RSA_PSS
|
||||
@@ -3831,9 +3891,13 @@ int wc_RsaPSS_Sign_ex(const byte* in, word32 inLen, byte* out, word32 outLen,
|
||||
enum wc_HashType hash, int mgf, int saltLen, RsaKey* key,
|
||||
WC_RNG* rng)
|
||||
{
|
||||
return RsaPublicEncryptEx(in, inLen, out, outLen, key,
|
||||
int ret;
|
||||
SAVE_VECTOR_REGISTERS(return _svr_ret;);
|
||||
ret = RsaPublicEncryptEx(in, inLen, out, outLen, key,
|
||||
RSA_PRIVATE_ENCRYPT, RSA_BLOCK_TYPE_1, WC_RSA_PSS_PAD,
|
||||
hash, mgf, NULL, 0, saltLen, rng);
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -4228,8 +4292,14 @@ int wc_CheckProbablePrime_ex(const byte* pRaw, word32 pRawSz,
|
||||
if (ret == MP_OKAY)
|
||||
ret = mp_read_unsigned_bin(e, eRaw, eRawSz);
|
||||
|
||||
if (ret == MP_OKAY)
|
||||
ret = _CheckProbablePrime(p, Q, e, nlen, isPrime, rng);
|
||||
if (ret == MP_OKAY) {
|
||||
SAVE_VECTOR_REGISTERS(ret = _svr_ret;);
|
||||
|
||||
if (ret == MP_OKAY)
|
||||
ret = _CheckProbablePrime(p, Q, e, nlen, isPrime, rng);
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
}
|
||||
|
||||
ret = (ret == MP_OKAY) ? 0 : PRIME_GEN_E;
|
||||
|
||||
@@ -4375,6 +4445,8 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
|
||||
err = MEMORY_E;
|
||||
}
|
||||
|
||||
SAVE_VECTOR_REGISTERS(err = _svr_ret;);
|
||||
|
||||
/* make p */
|
||||
if (err == MP_OKAY) {
|
||||
isPrime = 0;
|
||||
@@ -4548,6 +4620,8 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
|
||||
if (err == MP_OKAY)
|
||||
key->type = RSA_PRIVATE;
|
||||
|
||||
RESTORE_VECTOR_REGISTERS();
|
||||
|
||||
mp_clear(tmp1);
|
||||
mp_clear(tmp2);
|
||||
mp_clear(tmp3);
|
||||
|
Reference in New Issue
Block a user