diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 336934f9b..eda4ac94a 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -31698,9 +31698,12 @@ int StoreECC_DSA_Sig(byte* out, word32* outLen, mp_int* r, mp_int* s) } if (ret == 0) { /* Encode DSA signature into buffer. */ - SetASN_Items(dsaSigASN, dataASN, dsaSigASN_Length, out); - /* Set the actual encoding size. */ - *outLen = (word32)sz; + ret = SetASN_Items(dsaSigASN, dataASN, dsaSigASN_Length, out); + if ((ret >= 0) && (ret == sz)) { + /* Set the actual encoding size. */ + *outLen = (word32)sz; + ret = 0; + } } return ret;