@@ -147,6 +147,16 @@ struct hpre_asym_request {
147147 struct timespec64 req_time ;
148148};
149149
150+ static inline unsigned int hpre_align_sz (void )
151+ {
152+ return ((crypto_dma_align () - 1 ) | (HPRE_ALIGN_SZ - 1 )) + 1 ;
153+ }
154+
155+ static inline unsigned int hpre_align_pd (void )
156+ {
157+ return (hpre_align_sz () - 1 ) & ~(crypto_tfm_ctx_alignment () - 1 );
158+ }
159+
150160static int hpre_alloc_req_id (struct hpre_ctx * ctx )
151161{
152162 unsigned long flags ;
@@ -517,7 +527,7 @@ static int hpre_msg_request_set(struct hpre_ctx *ctx, void *req, bool is_rsa)
517527 }
518528
519529 tmp = akcipher_request_ctx (akreq );
520- h_req = PTR_ALIGN (tmp , HPRE_ALIGN_SZ );
530+ h_req = PTR_ALIGN (tmp , hpre_align_sz () );
521531 h_req -> cb = hpre_rsa_cb ;
522532 h_req -> areq .rsa = akreq ;
523533 msg = & h_req -> req ;
@@ -531,7 +541,7 @@ static int hpre_msg_request_set(struct hpre_ctx *ctx, void *req, bool is_rsa)
531541 }
532542
533543 tmp = kpp_request_ctx (kreq );
534- h_req = PTR_ALIGN (tmp , HPRE_ALIGN_SZ );
544+ h_req = PTR_ALIGN (tmp , hpre_align_sz () );
535545 h_req -> cb = hpre_dh_cb ;
536546 h_req -> areq .dh = kreq ;
537547 msg = & h_req -> req ;
@@ -582,7 +592,7 @@ static int hpre_dh_compute_value(struct kpp_request *req)
582592 struct crypto_kpp * tfm = crypto_kpp_reqtfm (req );
583593 struct hpre_ctx * ctx = kpp_tfm_ctx (tfm );
584594 void * tmp = kpp_request_ctx (req );
585- struct hpre_asym_request * hpre_req = PTR_ALIGN (tmp , HPRE_ALIGN_SZ );
595+ struct hpre_asym_request * hpre_req = PTR_ALIGN (tmp , hpre_align_sz () );
586596 struct hpre_sqe * msg = & hpre_req -> req ;
587597 int ret ;
588598
@@ -740,7 +750,7 @@ static int hpre_dh_init_tfm(struct crypto_kpp *tfm)
740750{
741751 struct hpre_ctx * ctx = kpp_tfm_ctx (tfm );
742752
743- kpp_set_reqsize (tfm , sizeof (struct hpre_asym_request ) + HPRE_ALIGN_SZ );
753+ kpp_set_reqsize (tfm , sizeof (struct hpre_asym_request ) + hpre_align_pd () );
744754
745755 return hpre_ctx_init (ctx , HPRE_V2_ALG_TYPE );
746756}
@@ -785,7 +795,7 @@ static int hpre_rsa_enc(struct akcipher_request *req)
785795 struct crypto_akcipher * tfm = crypto_akcipher_reqtfm (req );
786796 struct hpre_ctx * ctx = akcipher_tfm_ctx (tfm );
787797 void * tmp = akcipher_request_ctx (req );
788- struct hpre_asym_request * hpre_req = PTR_ALIGN (tmp , HPRE_ALIGN_SZ );
798+ struct hpre_asym_request * hpre_req = PTR_ALIGN (tmp , hpre_align_sz () );
789799 struct hpre_sqe * msg = & hpre_req -> req ;
790800 int ret ;
791801
@@ -833,7 +843,7 @@ static int hpre_rsa_dec(struct akcipher_request *req)
833843 struct crypto_akcipher * tfm = crypto_akcipher_reqtfm (req );
834844 struct hpre_ctx * ctx = akcipher_tfm_ctx (tfm );
835845 void * tmp = akcipher_request_ctx (req );
836- struct hpre_asym_request * hpre_req = PTR_ALIGN (tmp , HPRE_ALIGN_SZ );
846+ struct hpre_asym_request * hpre_req = PTR_ALIGN (tmp , hpre_align_sz () );
837847 struct hpre_sqe * msg = & hpre_req -> req ;
838848 int ret ;
839849
@@ -1168,7 +1178,7 @@ static int hpre_rsa_init_tfm(struct crypto_akcipher *tfm)
11681178 }
11691179
11701180 akcipher_set_reqsize (tfm , sizeof (struct hpre_asym_request ) +
1171- HPRE_ALIGN_SZ );
1181+ hpre_align_pd () );
11721182
11731183 ret = hpre_ctx_init (ctx , HPRE_V2_ALG_TYPE );
11741184 if (ret )
@@ -1490,7 +1500,7 @@ static int hpre_ecdh_msg_request_set(struct hpre_ctx *ctx,
14901500 }
14911501
14921502 tmp = kpp_request_ctx (req );
1493- h_req = PTR_ALIGN (tmp , HPRE_ALIGN_SZ );
1503+ h_req = PTR_ALIGN (tmp , hpre_align_sz () );
14941504 h_req -> cb = hpre_ecdh_cb ;
14951505 h_req -> areq .ecdh = req ;
14961506 msg = & h_req -> req ;
@@ -1571,7 +1581,7 @@ static int hpre_ecdh_compute_value(struct kpp_request *req)
15711581 struct hpre_ctx * ctx = kpp_tfm_ctx (tfm );
15721582 struct device * dev = ctx -> dev ;
15731583 void * tmp = kpp_request_ctx (req );
1574- struct hpre_asym_request * hpre_req = PTR_ALIGN (tmp , HPRE_ALIGN_SZ );
1584+ struct hpre_asym_request * hpre_req = PTR_ALIGN (tmp , hpre_align_sz () );
15751585 struct hpre_sqe * msg = & hpre_req -> req ;
15761586 int ret ;
15771587
@@ -1622,7 +1632,7 @@ static int hpre_ecdh_nist_p192_init_tfm(struct crypto_kpp *tfm)
16221632
16231633 ctx -> curve_id = ECC_CURVE_NIST_P192 ;
16241634
1625- kpp_set_reqsize (tfm , sizeof (struct hpre_asym_request ) + HPRE_ALIGN_SZ );
1635+ kpp_set_reqsize (tfm , sizeof (struct hpre_asym_request ) + hpre_align_pd () );
16261636
16271637 return hpre_ctx_init (ctx , HPRE_V3_ECC_ALG_TYPE );
16281638}
@@ -1633,7 +1643,7 @@ static int hpre_ecdh_nist_p256_init_tfm(struct crypto_kpp *tfm)
16331643
16341644 ctx -> curve_id = ECC_CURVE_NIST_P256 ;
16351645
1636- kpp_set_reqsize (tfm , sizeof (struct hpre_asym_request ) + HPRE_ALIGN_SZ );
1646+ kpp_set_reqsize (tfm , sizeof (struct hpre_asym_request ) + hpre_align_pd () );
16371647
16381648 return hpre_ctx_init (ctx , HPRE_V3_ECC_ALG_TYPE );
16391649}
@@ -1644,7 +1654,7 @@ static int hpre_ecdh_nist_p384_init_tfm(struct crypto_kpp *tfm)
16441654
16451655 ctx -> curve_id = ECC_CURVE_NIST_P384 ;
16461656
1647- kpp_set_reqsize (tfm , sizeof (struct hpre_asym_request ) + HPRE_ALIGN_SZ );
1657+ kpp_set_reqsize (tfm , sizeof (struct hpre_asym_request ) + hpre_align_pd () );
16481658
16491659 return hpre_ctx_init (ctx , HPRE_V3_ECC_ALG_TYPE );
16501660}
@@ -1802,7 +1812,7 @@ static int hpre_curve25519_msg_request_set(struct hpre_ctx *ctx,
18021812 }
18031813
18041814 tmp = kpp_request_ctx (req );
1805- h_req = PTR_ALIGN (tmp , HPRE_ALIGN_SZ );
1815+ h_req = PTR_ALIGN (tmp , hpre_align_sz () );
18061816 h_req -> cb = hpre_curve25519_cb ;
18071817 h_req -> areq .curve25519 = req ;
18081818 msg = & h_req -> req ;
@@ -1923,7 +1933,7 @@ static int hpre_curve25519_compute_value(struct kpp_request *req)
19231933 struct hpre_ctx * ctx = kpp_tfm_ctx (tfm );
19241934 struct device * dev = ctx -> dev ;
19251935 void * tmp = kpp_request_ctx (req );
1926- struct hpre_asym_request * hpre_req = PTR_ALIGN (tmp , HPRE_ALIGN_SZ );
1936+ struct hpre_asym_request * hpre_req = PTR_ALIGN (tmp , hpre_align_sz () );
19271937 struct hpre_sqe * msg = & hpre_req -> req ;
19281938 int ret ;
19291939
@@ -1972,7 +1982,7 @@ static int hpre_curve25519_init_tfm(struct crypto_kpp *tfm)
19721982{
19731983 struct hpre_ctx * ctx = kpp_tfm_ctx (tfm );
19741984
1975- kpp_set_reqsize (tfm , sizeof (struct hpre_asym_request ) + HPRE_ALIGN_SZ );
1985+ kpp_set_reqsize (tfm , sizeof (struct hpre_asym_request ) + hpre_align_pd () );
19761986
19771987 return hpre_ctx_init (ctx , HPRE_V3_ECC_ALG_TYPE );
19781988}
0 commit comments