From: Zhiqi Song songzhiqi1@huawei.com
The key data sent by the user may be non-byte aligned and the low-order byte is 0x00. Use original 'dsize' will make the key data be truncated after being transformed. Therefore, 'dsize' should be changned after the key format is transformed.
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- v1/drv/hisi_hpre_udrv.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c index 9a1c5ee6..4cd030f4 100644 --- a/v1/drv/hisi_hpre_udrv.c +++ b/v1/drv/hisi_hpre_udrv.c @@ -889,7 +889,7 @@ static int ecc_prepare_prikey(struct wcrypto_ecc_key *key, void **data, int id) struct wd_dtb *b = NULL; struct wd_dtb *n = NULL; struct wd_dtb *d = NULL; - char bsize, dsize; + __u32 bsize, dsize; char *dat; int ret;
@@ -903,6 +903,10 @@ static int ecc_prepare_prikey(struct wcrypto_ecc_key *key, void **data, int id) if (unlikely(ret)) return ret;
+ /* X448 will do specific offset */ + if (id != WCRYPTO_X448) + d->dsize = d->bsize; + dat = d->data; bsize = d->bsize; dsize = d->dsize; @@ -928,12 +932,6 @@ static int ecc_prepare_prikey(struct wcrypto_ecc_key *key, void **data, int id) dat[0 + bsize - dsize] |= 128; }
- if (id != WCRYPTO_X25519 && id != WCRYPTO_X448 && - !less_than_latter(d, n)) { - WD_ERR("failed to prepare ecc prikey: d >= n!\n"); - return -WD_EINVAL; - } - *data = p->data;
return 0;