From: Longfang Liu <liulongfang@huawei.com> In the HPRE module's big number comparison, the previous implementation used memcmp to compare big numbers of the same length. On little-endian platforms, this approach compares data starting from the Least Significant Bit (LSB), which can lead to incorrect results—such as a larger value in the lower bits being misinterpreted as greater overall, even if the higher bits are smaller. To address this, the comparison logic must be modified to consistently start from the Most Significant Bit (MSB). Signed-off-by: Longfang Liu <liulongfang@huawei.com> --- drv/hisi_hpre.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 83d8195..07ebe92 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -1168,19 +1168,25 @@ static bool big_than_one(const char *data, __u32 data_sz) static bool less_than_latter(struct wd_dtb *d, struct wd_dtb *n) { - int ret, shift; + unsigned char *d_data, *n_data; + int shift, i; if (d->dsize > n->dsize) return false; else if (d->dsize < n->dsize) return true; + /* d->dsize == n->dsize */ shift = n->bsize - n->dsize; - ret = memcmp_consttime(d->data + shift, n->data + shift, n->dsize); - if (ret < 0) - return true; - else - return false; + d_data = d->data + shift; + n_data = n->data + shift; + for (i = d->dsize - 1; i >= 0; i--) { + if (d_data[i] < n_data[i]) + return true; + else if (d_data[i] > n_data[i]) + return false; + } + return false; } static int ecc_prepare_prikey(struct wd_ecc_key *key, void **data, int id) -- 2.33.0