From patchwork Mon Apr 26 08:05:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matan Azrad X-Patchwork-Id: 92151 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D6663A0548; Mon, 26 Apr 2021 10:06:05 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B7252411A0; Mon, 26 Apr 2021 10:06:05 +0200 (CEST) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2066.outbound.protection.outlook.com [40.107.94.66]) by mails.dpdk.org (Postfix) with ESMTP id 193464118F for ; Mon, 26 Apr 2021 10:06:04 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HQ3U4T2c8vxc4JcDV4duKTBeNDm4JEF2PmOEnNENakQlqmL6JfcRtl2NF0mehVpmKLHgIMt08+u6qDbh0FcUTCR1IBcRAa5c7ODU3rV9ThAY0V4iDfL+Gg6qLhzJNSQLN1L4k039TlO/SZ4ffyGib81w2EnYMfQ7JIbEpHzZu+51Rs1CDTmNN4lG7gmd+3dylSWQ+ZmG/uVGg8wTi3GTq1kMqc+3ZvKwurLjluXWPdXeyLlTCFEX6yMg1gt8Z5KSVpR0XwZqWI7IO/0CN81FJSLRfjNVj1rhkyJ9L0xZGmXHCOGyQXStYHB39O0CgS0MdJaiR/4+WaNOH0zJnyYYOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JE6SCFOFp4eHq9Bz5dHNqAL5kYe3Qxwq2jHw+4CLWdc=; b=XnS2pq7hC8hQsIil7BeptCRC08DRaT5X+8C9qmJGdC3HUvDT5o/ZG+BgVdSD6JvlLoPu/sa7uMCrnIVrE7wF/ys5w4nmlgb4uMzC1hguU2zDH7Y2sZqP7psl+TVvh0qMPoAxQsMJ6r8kYPko71Xj9GP+ohX3BGlgnKHgtcTyQWhU4LGBlLGzWCX+aD7bym5olzwd/lAPrXgL4u2V///sUtM7ehFCEfMrgbM7A48zJiGY9AMy1PZNGFSqor0pjWXATOZjqiLB3e7oL+VwJOArvJDMRFD1O1u3GIvyd3bjg210T4LJu/1LCtcelaynwE3BxoSTEYL1YcHnXS6paTs6gA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JE6SCFOFp4eHq9Bz5dHNqAL5kYe3Qxwq2jHw+4CLWdc=; b=g0gK+1muPOhQjnd9V+6jPEntmrFfvFJy5is7bMsfp9y5dWR9DvF/Cas+ufjkEg9qvmwROa6t33h7bfMvQAtQowsoEggmtd3ZlpGUkaBkQtnUDy1jC4AlB8V4RuCNHNdEtMDJyAz6Ew9HA3khpuIcAfgnPsi8jGf97R5H6GKz5r3JZLnLD7m6LsO4cJAAcnSaDmhL8ucoY98cDxsCnkJV++vHJMYzF2NmpSZ/fWQmWvXflosnvRgN1d2Th+bgLV12SmlkXpfC1cAxjF/MiZfSlCt8zt3RrjWCdkszGfxNuouBH5IaNBTJlV7hAssmqsmUxM8Y7pmqKA1GeYSnuZpYMw== Received: from MW4PR04CA0341.namprd04.prod.outlook.com (2603:10b6:303:8a::16) by MW2PR12MB4683.namprd12.prod.outlook.com (2603:10b6:302:5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.22; Mon, 26 Apr 2021 08:06:02 +0000 Received: from CO1NAM11FT064.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8a:cafe::11) by MW4PR04CA0341.outlook.office365.com (2603:10b6:303:8a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20 via Frontend Transport; Mon, 26 Apr 2021 08:06:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by CO1NAM11FT064.mail.protection.outlook.com (10.13.175.77) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4065.21 via Frontend Transport; Mon, 26 Apr 2021 08:06:01 +0000 Received: from nvidia.com (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 26 Apr 2021 08:06:00 +0000 From: Matan Azrad To: CC: Akhil Goyal , Declan Doherty , Shiri Kuzin Date: Mon, 26 Apr 2021 11:05:37 +0300 Message-ID: <20210426080537.376693-1-matan@nvidia.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e41e1ced-b98c-4dc8-08b3-08d9088a220d X-MS-TrafficTypeDiagnostic: MW2PR12MB4683: X-Microsoft-Antispam-PRVS: X-MS-Exchange-Transport-Forked: True X-MS-Oob-TLC-OOBClassifiers: OLM:439; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qx7ig7n6ot6z1aUYoVU/Mswnghdr/t9qUc7wszvO2N95ONyFYC5OxW0JVWvop7j0z4fh22X/jVGKt3jjbsXwbGHUfz15pDqpoZsLylSMwOxPPpkq0Zn4WeMK/VMJJUnvptm3uVXUajxFNnVD3EE9LVOHkOPoiAIqWN/wSUWQcwu2lJWdAUxG/3V8pslT9Mg9ppWZM84MbVruPJOKn7Li25aHqry/DD6CYkr22uUJvC921abbRFWkecR0ViMH4mUWw62tgxYcka5nsrRDRS68McVcZyxN1x+lGWgunJti+HA0X2PISxeBmml8QB6n6dYNHx6Ubp0xw/YlRJyU6C47y1iNWWY/F4DwhRG0tZxZ5pVItt0psFYStzyv9Jm2tnLhUkdegB1XZtunNzoypeP9wxcZeloYuRiyLMSM/0wAGfArMtw4U7PdUrTdxhKBtrX8j57IYPHed9l4iYH84YFpirCQxQmLEaZ4ER5DbI9tHHR+/+thXpDYOSLEfBbDkIsV46m8Ua+16fnMlSZRFiBIUVZRllrIcviYlK3kFvbwaugSSnC3vhBSdqhgGyEnlTY9/jOsRJxX/bbEi3JNiqijGJd+pWvoyZg2Jvz+RA0xE1U9QLYppkqJcd7BVxQGUAjQP9eJT6EMzYUoLbFS4dxtdoBrRkhWWRRGxPppZ8ym/F0= X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(136003)(376002)(346002)(396003)(36840700001)(46966006)(1076003)(336012)(426003)(2616005)(6666004)(55016002)(86362001)(6916009)(2906002)(478600001)(186003)(26005)(356005)(16526019)(8676002)(4326008)(70586007)(70206006)(7636003)(6286002)(83380400001)(82740400003)(8936002)(5660300002)(107886003)(47076005)(54906003)(7696005)(36860700001)(36756003)(82310400003)(316002)(36906005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2021 08:06:01.8305 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e41e1ced-b98c-4dc8-08b3-08d9088a220d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT064.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR12MB4683 Subject: [dpdk-dev] [PATCH] examples/l2fwd-crypto: support cipher multiple data-unit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Patch [1] added a new API to support multiple data-units in cipher operations. Add a support for this API: - Add a new command-line argument to provide the data-unit length. - Set the length in the cipher xform. - Validate device capabilities for this feature. - Pad the AES-XTS operation length to be aligned to the defined data-unit. [1]: commit d014dddb2d69 ("cryptodev: support multiple cipher data-units") Signed-off-by: Matan Azrad --- .../sample_app_ug/l2_forward_crypto.rst | 7 ++- examples/l2fwd-crypto/main.c | 61 +++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/doc/guides/sample_app_ug/l2_forward_crypto.rst b/doc/guides/sample_app_ug/l2_forward_crypto.rst index e2c0f9f1ec..cc772aaec4 100644 --- a/doc/guides/sample_app_ug/l2_forward_crypto.rst +++ b/doc/guides/sample_app_ug/l2_forward_crypto.rst @@ -41,8 +41,9 @@ The application requires a number of command line options: .//examples/dpdk-l2fwd-crypto [EAL options] -- [-p PORTMASK] [-q NQ] [-s] [-T PERIOD] / [--cdev_type HW/SW/ANY] [--chain HASH_CIPHER/CIPHER_HASH/CIPHER_ONLY/HASH_ONLY/AEAD] / - [--cipher_algo ALGO] [--cipher_op ENCRYPT/DECRYPT] [--cipher_key KEY] / - [--cipher_key_random_size SIZE] [--cipher_iv IV] [--cipher_iv_random_size SIZE] / + [--cipher_algo ALGO] [--cipher_op ENCRYPT/DECRYPT] [--cipher_dataunit_len SIZE] / + [--cipher_key KEY] [--cipher_key_random_size SIZE] [--cipher_iv IV] / + [--cipher_iv_random_size SIZE] / [--auth_algo ALGO] [--auth_op GENERATE/VERIFY] [--auth_key KEY] / [--auth_key_random_size SIZE] [--auth_iv IV] [--auth_iv_random_size SIZE] / [--aead_algo ALGO] [--aead_op ENCRYPT/DECRYPT] [--aead_key KEY] / @@ -81,6 +82,8 @@ where, (default is ENCRYPT) +* cipher_dataunit_len: set the length of the cipher data-unit. + * cipher_key: set the ciphering key to be used. Bytes has to be separated with ":" * cipher_key_random_size: set the size of the ciphering key, diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c index 4f51616492..22bd47061b 100644 --- a/examples/l2fwd-crypto/main.c +++ b/examples/l2fwd-crypto/main.c @@ -182,6 +182,8 @@ struct l2fwd_crypto_params { unsigned digest_length; unsigned block_size; + uint16_t cipher_dataunit_len; + struct l2fwd_iv cipher_iv; struct l2fwd_iv auth_iv; struct l2fwd_iv aead_iv; @@ -434,6 +436,12 @@ l2fwd_simple_crypto_enqueue(struct rte_mbuf *m, pad_len = cparams->block_size - (data_len % cparams->block_size); break; + case RTE_CRYPTO_CIPHER_AES_XTS: + if (cparams->cipher_dataunit_len != 0 && + (data_len % cparams->cipher_dataunit_len)) + pad_len = cparams->cipher_dataunit_len - + (data_len % cparams->cipher_dataunit_len); + break; default: pad_len = 0; } @@ -827,6 +835,8 @@ l2fwd_main_loop(struct l2fwd_crypto_options *options) port_cparams[i].cipher_iv.length); port_cparams[i].cipher_algo = options->cipher_xform.cipher.algo; + port_cparams[i].cipher_dataunit_len = + options->cipher_xform.cipher.dataunit_len; /* Set IV parameters */ options->cipher_xform.cipher.iv.offset = IV_OFFSET; options->cipher_xform.cipher.iv.length = @@ -989,6 +999,7 @@ l2fwd_crypto_usage(const char *prgname) " --cipher_key_random_size SIZE: size of cipher key when generated randomly\n" " --cipher_iv IV (bytes separated with \":\")\n" " --cipher_iv_random_size SIZE: size of cipher IV when generated randomly\n" + " --cipher_dataunit_len SIZE: length of the algorithm data-unit\n" " --auth_algo ALGO\n" " --auth_op GENERATE / VERIFY\n" @@ -1215,6 +1226,7 @@ l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options, struct option *lgopts, int option_index) { int retval; + int val; if (strcmp(lgopts[option_index].name, "cdev_type") == 0) { retval = parse_cryptodev_type(&options->type, optarg); @@ -1245,6 +1257,16 @@ l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options, return -1; } + else if (strcmp(lgopts[option_index].name, "cipher_dataunit_len") == 0) { + retval = parse_size(&val, optarg); + if (retval == 0 && val >= 0 && val <= UINT16_MAX) { + options->cipher_xform.cipher.dataunit_len = + (uint16_t)val; + return 0; + } else + return -1; + } + else if (strcmp(lgopts[option_index].name, "cipher_key_random_size") == 0) return parse_size(&options->ckey_random_size, optarg); @@ -1469,6 +1491,7 @@ l2fwd_crypto_default_options(struct l2fwd_crypto_options *options) options->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; options->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; + options->cipher_xform.cipher.dataunit_len = 0; /* Authentication Data */ options->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; @@ -1644,6 +1667,7 @@ l2fwd_crypto_parse_args(struct l2fwd_crypto_options *options, { "cipher_key_random_size", required_argument, 0, 0 }, { "cipher_iv", required_argument, 0, 0 }, { "cipher_iv_random_size", required_argument, 0, 0 }, + { "cipher_dataunit_len", required_argument, 0, 0}, { "auth_algo", required_argument, 0, 0 }, { "auth_op", required_argument, 0, 0 }, @@ -2158,6 +2182,43 @@ check_capabilities(struct l2fwd_crypto_options *options, uint8_t cdev_id) return -1; } } + + if (options->cipher_xform.cipher.dataunit_len > 0) { + if (!(dev_info.feature_flags & + RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS)) { + RTE_LOG(DEBUG, USER1, + "Device %u does not support " + "cipher multiple data units\n", + cdev_id); + return -1; + } + if (cap->sym.cipher.dataunit_set != 0) { + int ret = 0; + + switch (options->cipher_xform.cipher.dataunit_len) { + case 512: + if (!(cap->sym.cipher.dataunit_set & + RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_512_BYTES)) + ret = -1; + break; + case 4096: + if (!(cap->sym.cipher.dataunit_set & + RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_4096_BYTES)) + ret = -1; + break; + default: + ret = -1; + } + if (ret == -1) { + RTE_LOG(DEBUG, USER1, + "Device %u does not support " + "data-unit length %u\n", + cdev_id, + options->cipher_xform.cipher.dataunit_len); + return -1; + } + } + } } /* Set auth parameters */