forked from wolfSSL/wolfssl
Fix for ECC encrypt/decrypt with async enabled. Reverts previous change from PR #1101 and adds return code checking for wc_AsyncWait. ECC shared secret needs to be in loop to call again for completion.
This commit is contained in:
@@ -7097,7 +7097,7 @@ static int ecc_get_key_sizes(ecEncCtx* ctx, int* encKeySz, int* ivSz,
|
|||||||
int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
|
int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
|
||||||
word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx)
|
word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = 0;
|
||||||
word32 blockSz;
|
word32 blockSz;
|
||||||
word32 digestSz;
|
word32 digestSz;
|
||||||
ecEncCtx localCtx;
|
ecEncCtx localCtx;
|
||||||
@@ -7168,10 +7168,14 @@ int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = wc_ecc_shared_secret(privKey, pubKey, sharedSecret, &sharedSz);
|
do {
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||||
ret = wc_AsyncWait(ret, &privKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
|
ret = wc_AsyncWait(ret, &privKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
|
||||||
#endif
|
if (ret != 0)
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
ret = wc_ecc_shared_secret(privKey, pubKey, sharedSecret, &sharedSz);
|
||||||
|
} while (ret == WC_PENDING_E);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
switch (ctx->kdfAlgo) {
|
switch (ctx->kdfAlgo) {
|
||||||
case ecHKDF_SHA256 :
|
case ecHKDF_SHA256 :
|
||||||
@@ -7255,7 +7259,7 @@ int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
|
|||||||
int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
|
int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
|
||||||
word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx)
|
word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = 0;
|
||||||
word32 blockSz;
|
word32 blockSz;
|
||||||
word32 digestSz;
|
word32 digestSz;
|
||||||
ecEncCtx localCtx;
|
ecEncCtx localCtx;
|
||||||
@@ -7326,10 +7330,14 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = wc_ecc_shared_secret(privKey, pubKey, sharedSecret, &sharedSz);
|
do {
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT)
|
#if defined(WOLFSSL_ASYNC_CRYPT)
|
||||||
ret = wc_AsyncWait(ret, &privKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
|
ret = wc_AsyncWait(ret, &privKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
|
||||||
#endif
|
if (ret != 0)
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
ret = wc_ecc_shared_secret(privKey, pubKey, sharedSecret, &sharedSz);
|
||||||
|
} while (ret == WC_PENDING_E);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
switch (ctx->kdfAlgo) {
|
switch (ctx->kdfAlgo) {
|
||||||
case ecHKDF_SHA256 :
|
case ecHKDF_SHA256 :
|
||||||
|
Reference in New Issue
Block a user