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 --- drv/hisi_hpre.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c index 637c3bf5..7c652d10 100644 --- a/drv/hisi_hpre.c +++ b/drv/hisi_hpre.c @@ -967,7 +967,7 @@ static int ecc_prepare_prikey(struct wd_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;
@@ -981,6 +981,10 @@ static int ecc_prepare_prikey(struct wd_ecc_key *key, void **data, int id) if (ret) return ret;
+ /* X448 will do specific offset */ + if (id != WD_X448) + d->dsize = d->bsize; + /* * This is a pretreatment of X25519/X448, as described in RFC 7748: * For X25519, in order to decode 32 random bytes as an integer @@ -1010,12 +1014,6 @@ static int ecc_prepare_prikey(struct wd_ecc_key *key, void **data, int id) return -WD_EINVAL; }
- if (id != WD_X25519 && id != WD_X448 && - !less_than_latter(d, n)) { - WD_ERR("failed to prepare ecc prikey: d >= n!\n"); - return -WD_EINVAL; - } - *data = p->data;
return WD_SUCCESS;