Skip to content

Commit 10c5bae

Browse files
Merge pull request #9442 from SparkiDev/lms_192_8bit_checksum
LMS - check sum fix for SHA-256-192
2 parents 46a7719 + da0e4f5 commit 10c5bae

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

wolfcrypt/src/wc_lms_impl.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,6 @@ static WC_INLINE int wc_lmots_q_expand(byte* q, word8 n, word8 w, word8 ls,
671671
/* For each byte of the hash. */
672672
for (i = 0; i < n; i++) {
673673
/* Get coefficients. */
674-
qe[0] = (q[i] >> 4) ;
675674
qe[0] = (q[i] >> 6) ;
676675
qe[1] = (q[i] >> 4) & 0x3;
677676
qe[2] = (q[i] >> 2) & 0x3;
@@ -697,7 +696,6 @@ static WC_INLINE int wc_lmots_q_expand(byte* q, word8 n, word8 w, word8 ls,
697696
/* For each byte of the hash. */
698697
for (i = 0; i < n; i++) {
699698
/* Get coefficients. */
700-
qe[0] = (q[i] >> 4) ;
701699
qe[0] = (q[i] >> 7) ;
702700
qe[1] = (q[i] >> 6) & 0x1;
703701
qe[2] = (q[i] >> 5) & 0x1;
@@ -719,15 +717,21 @@ static WC_INLINE int wc_lmots_q_expand(byte* q, word8 n, word8 w, word8 ls,
719717
qe += 8;
720718
}
721719
/* Put coefficients of checksum on the end. */
722-
qe[0] = (word8)((sum >> 8) );
723-
qe[1] = (word8)((sum >> 7) & 0x1);
724-
qe[2] = (word8)((sum >> 6) & 0x1);
725-
qe[3] = (word8)((sum >> 5) & 0x1);
726-
qe[4] = (word8)((sum >> 4) & 0x1);
727-
qe[5] = (word8)((sum >> 3) & 0x1);
728-
qe[6] = (word8)((sum >> 2) & 0x1);
729-
qe[7] = (word8)((sum >> 1) & 0x1);
730-
qe[8] = (word8)((sum ) & 0x1);
720+
#ifdef WOLFSSL_LMS_SHA256_192
721+
if (ls == 7)
722+
#endif
723+
{
724+
qe[0] = (word8)((sum >> 8) );
725+
qe++;
726+
}
727+
qe[0] = (word8)((sum >> 7) & 0x1);
728+
qe[1] = (word8)((sum >> 6) & 0x1);
729+
qe[2] = (word8)((sum >> 5) & 0x1);
730+
qe[3] = (word8)((sum >> 4) & 0x1);
731+
qe[4] = (word8)((sum >> 3) & 0x1);
732+
qe[5] = (word8)((sum >> 2) & 0x1);
733+
qe[6] = (word8)((sum >> 1) & 0x1);
734+
qe[7] = (word8)((sum ) & 0x1);
731735
break;
732736
default:
733737
ret = BAD_FUNC_ARG;
@@ -763,7 +767,7 @@ static WC_INLINE int wc_lmots_q_expand(byte* q, word8 n, word8 w, word8 ls,
763767
}
764768
/* Shift sum up as required to pack it on the end of hash. */
765769
sum <<= ls;
766-
/* For each width buts of checksum. */
770+
/* For each width bit of checksum. */
767771
for (j = 16 - w; j >= ls; j--) {
768772
/* Get coefficient. */
769773
*(qe++) = sum >> (16 - w);

0 commit comments

Comments
 (0)