<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family: "IntelOne Text"; font-size: 10pt; color: rgb(0, 0, 0);">
Acked-by: Kai Ji <kai.ji@intel.com></div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Jack Bond-Preston <jack.bond-preston@foss.arm.com><br>
<b>Sent:</b> 07 June 2024 13:47<br>
<b>To:</b> Ji, Kai <kai.ji@intel.com><br>
<b>Cc:</b> dev@dpdk.org <dev@dpdk.org>; Wathsala Vithanage <wathsala.vithanage@arm.com><br>
<b>Subject:</b> [PATCH v4 2/5] crypto/openssl: only init 3DES-CTR key + impl once</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Currently the 3DES-CTR cipher context is initialised for every buffer,<br>
setting the cipher implementation and key - even though for every<br>
buffer in the session these values will be the same.<br>
<br>
Change to initialising the cipher context once, before any buffers are<br>
processed, instead.<br>
<br>
Throughput performance uplift measurements for 3DES-CTR encrypt on<br>
Ampere Altra Max platform:<br>
1 worker lcore<br>
|   buffer sz (B) |   prev (Gbps) |   optimised (Gbps) |   uplift |<br>
|-----------------+---------------+--------------------+----------|<br>
|              64 |          0.16 |               0.21 |    35.3% |<br>
|             256 |          0.20 |               0.22 |     9.4% |<br>
|            1024 |          0.22 |               0.23 |     2.3% |<br>
|            2048 |          0.22 |               0.23 |     0.9% |<br>
|            4096 |          0.22 |               0.23 |     0.9% |<br>
<br>
8 worker lcores<br>
|   buffer sz (B) |   prev (Gbps) |   optimised (Gbps) |   uplift |<br>
|-----------------+---------------+--------------------+----------|<br>
|              64 |          1.01 |               1.34 |    32.9% |<br>
|             256 |          1.51 |               1.66 |     9.9% |<br>
|            1024 |          1.72 |               1.77 |     2.6% |<br>
|            2048 |          1.76 |               1.78 |     1.1% |<br>
|            4096 |          1.79 |               1.80 |     0.6% |<br>
<br>
Signed-off-by: Jack Bond-Preston <jack.bond-preston@foss.arm.com><br>
Reviewed-by: Wathsala Vithanage <wathsala.vithanage@arm.com><br>
---<br>
 drivers/crypto/openssl/rte_openssl_pmd.c | 21 +++++++++++----------<br>
 1 file changed, 11 insertions(+), 10 deletions(-)<br>
<br>
diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c<br>
index 3f7f4d8c37..70f2069985 100644<br>
--- a/drivers/crypto/openssl/rte_openssl_pmd.c<br>
+++ b/drivers/crypto/openssl/rte_openssl_pmd.c<br>
@@ -553,6 +553,15 @@ openssl_set_session_cipher_parameters(struct openssl_session *sess,<br>
                                 sess->cipher.key.length,<br>
                                 sess->cipher.key.data) != 0)<br>
                         return -EINVAL;<br>
+<br>
+<br>
+               /* We use 3DES encryption also for decryption.<br>
+                * IV is not important for 3DES ECB.<br>
+                */<br>
+               if (EVP_EncryptInit_ex(sess->cipher.ctx, EVP_des_ede3_ecb(),<br>
+                               NULL, sess->cipher.key.data,  NULL) != 1)<br>
+                       return -EINVAL;<br>
+<br>
                 break;<br>
 <br>
         case RTE_CRYPTO_CIPHER_DES_CBC:<br>
@@ -1172,8 +1181,7 @@ process_openssl_cipher_decrypt(struct rte_mbuf *mbuf_src, uint8_t *dst,<br>
 /** Process cipher des 3 ctr encryption, decryption algorithm */<br>
 static int<br>
 process_openssl_cipher_des3ctr(struct rte_mbuf *mbuf_src, uint8_t *dst,<br>
-               int offset, uint8_t *iv, uint8_t *key, int srclen,<br>
-               EVP_CIPHER_CTX *ctx)<br>
+               int offset, uint8_t *iv, int srclen, EVP_CIPHER_CTX *ctx)<br>
 {<br>
         uint8_t ebuf[8], ctr[8];<br>
         int unused, n;<br>
@@ -1191,12 +1199,6 @@ process_openssl_cipher_des3ctr(struct rte_mbuf *mbuf_src, uint8_t *dst,<br>
         src = rte_pktmbuf_mtod_offset(m, uint8_t *, offset);<br>
         l = rte_pktmbuf_data_len(m) - offset;<br>
 <br>
-       /* We use 3DES encryption also for decryption.<br>
-        * IV is not important for 3DES ecb<br>
-        */<br>
-       if (EVP_EncryptInit_ex(ctx, EVP_des_ede3_ecb(), NULL, key, NULL) <= 0)<br>
-               goto process_cipher_des3ctr_err;<br>
-<br>
         memcpy(ctr, iv, 8);<br>
 <br>
         for (n = 0; n < srclen; n++) {<br>
@@ -1740,8 +1742,7 @@ process_openssl_cipher_op<br>
                                         srclen, ctx_copy, inplace);<br>
         else<br>
                 status = process_openssl_cipher_des3ctr(mbuf_src, dst,<br>
-                               op->sym->cipher.data.offset, iv,<br>
-                               sess->cipher.key.data, srclen,<br>
+                               op->sym->cipher.data.offset, iv, srclen,<br>
                                 ctx_copy);<br>
 <br>
         EVP_CIPHER_CTX_free(ctx_copy);<br>
-- <br>
2.34.1<br>
<br>
</div>
</span></font></div>
</body>
</html>