Skip to content

Commit 66a06d1

Browse files
committed
Fix for miller rabbin less than prime check.
1 parent b51d567 commit 66a06d1

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

wolfcrypt/src/port/intel/quickassist.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,8 @@ int IntelQaGenPrime(WC_ASYNC_DEV* dev, WC_RNG* rng, byte* primeBuf,
10151015
primeData[byteCheck] += 2;
10161016
}
10171017
else {
1018-
/* rollover occurred and we need to increment high order bytes */
1018+
/* if rollover occurred increment high order bytes */
1019+
/* increment by 1 does not affect odd/even */
10191020
int j;
10201021
for (j = primeSz - 2; j >= 0; j--) {
10211022
if (primeData[i] != 0xFF) {
@@ -1029,11 +1030,30 @@ int IntelQaGenPrime(WC_ASYNC_DEV* dev, WC_RNG* rng, byte* primeBuf,
10291030
}
10301031
}
10311032

1032-
#if 0
1033-
/* TODO: */
1034-
/* make sure miller rabbin is less than smallest candidate */
1035-
#endif
1033+
/* make sure miller rabbin must be less than prime candidate */
1034+
for (i = 0; i < QAT_PRIME_GEN_MR_ROUNDS; i++) {
1035+
byte* mrData = pMillerRabinData + (i * primeSz);
1036+
int j;
1037+
for (j = 0; j < (int)primeSz; j++) {
1038+
/* if primeData is less then mrData, and primeData is not 0,
1039+
* then make mrData to be smaller than primeData, and we are done */
1040+
if ((primeData[j] <= mrData[j]) && primeData[j] != 0) {
1041+
mrData[j] = primeData[j] - 1;
1042+
break;
1043+
}
1044+
/* if primeData is 0 then mrData needs to be zero and we check
1045+
* the next index */
1046+
else if (primeData[j] == 0) {
1047+
mrData[j] = 0;
1048+
}
1049+
/* primeData is smaller than mrData so we are done */
1050+
else {
1051+
break;
1052+
}
1053+
}
1054+
}
10361055

1056+
/* setup and run prime tests */
10371057
XMEMSET(dev->qat.op.prime_gen.testStatus, 0,
10381058
sizeof(dev->qat.op.prime_gen.testStatus));
10391059
retryCount = 0;
@@ -1110,6 +1130,10 @@ int IntelQaGenPrime(WC_ASYNC_DEV* dev, WC_RNG* rng, byte* primeBuf,
11101130
ret = ASYNC_OP_E;
11111131
break; /* done with failure */
11121132
}
1133+
1134+
#ifdef QAT_DEBUG
1135+
printf("cpaCyPrimeTest attempt %d\n", attempt);
1136+
#endif
11131137
} /* for (attempt) */
11141138

11151139
exit:

0 commit comments

Comments
 (0)