Skip to content

Commit 2207326

Browse files
authored
Merge pull request #27 from wolfSSL/dhe_agree
Fix for QuickAssist DH Agree issue with leading zero bytes
2 parents b8f3164 + 320d9ba commit 2207326

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

wolfcrypt/src/port/intel/quickassist.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3983,17 +3983,30 @@ static void IntelQaDhAgreeCallback(void *pCallbackTag, CpaStatus status,
39833983
#endif
39843984

39853985
if (status == CPA_STATUS_SUCCESS) {
3986-
/* validate returned output */
3986+
word32 idxTrim = 0;
3987+
byte* out = (byte*)pOut->pData;
3988+
3989+
/* check output size */
39873990
if (dev->qat.outLenPtr) {
39883991
if (pOut->dataLenInBytes > *dev->qat.outLenPtr) {
39893992
pOut->dataLenInBytes = *dev->qat.outLenPtr;
39903993
}
3991-
*dev->qat.outLenPtr = pOut->dataLenInBytes;
39923994
}
39933995

3994-
/* return data */
3995-
if (dev->qat.out && dev->qat.out != pOut->pData) {
3996-
XMEMCPY(dev->qat.out, pOut->pData, pOut->dataLenInBytes);
3996+
/* count leading zeros */
3997+
while (out[idxTrim] == 0 && idxTrim < pOut->dataLenInBytes) {
3998+
idxTrim++;
3999+
}
4000+
pOut->dataLenInBytes -= idxTrim;
4001+
4002+
/* return data and trim leading zeros */
4003+
if (dev->qat.out && (dev->qat.out != pOut->pData || idxTrim > 0)) {
4004+
XMEMCPY(dev->qat.out, &out[idxTrim], pOut->dataLenInBytes);
4005+
}
4006+
4007+
/* return final length */
4008+
if (dev->qat.outLenPtr) {
4009+
*dev->qat.outLenPtr = pOut->dataLenInBytes;
39974010
}
39984011

39994012
/* mark event result */

0 commit comments

Comments
 (0)