From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0051.outbound.protection.outlook.com [104.47.36.51]) by dpdk.org (Postfix) with ESMTP id EC3F81BF64 for ; Tue, 3 Jul 2018 17:25:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U3wgfoSe+GB6ISyHjvTVFWhq+HnrDaJkF11Dzp/+yTA=; b=kkV37fvSQQCKa6HzSfmzC3NcGdd5Ic/w05sue97ijf3zKdVUFJ7Bw4sUPYV1Bwm1Nw1EvL0ifhxDljFy5zzcaY/yDcMJwHlQzovjaJO7XZQnokdTs6/v92w7WGG4Y2mee4sdkBZXZneZTdsx1GIIZUELWWAyLpFN+fm6J/XAWc0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Shally.Verma@cavium.com; Received: from hyd1sverma-dt.caveonetworks.com (115.113.156.2) by DM5PR0701MB3640.namprd07.prod.outlook.com (2603:10b6:4:7e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.906.24; Tue, 3 Jul 2018 15:25:24 +0000 From: Shally Verma To: pablo.de.lara.guarch@intel.com Cc: dev@dpdk.org, pathreya@caviumnetworks.com, nmurthy@caviumnetworks.com, Sunila Sahu , Ashish Gupta , Umesh Kartha Date: Tue, 3 Jul 2018 20:54:26 +0530 Message-Id: <1530631466-26427-5-git-send-email-shally.verma@caviumnetworks.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1530631466-26427-1-git-send-email-shally.verma@caviumnetworks.com> References: <1530631466-26427-1-git-send-email-shally.verma@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [115.113.156.2] X-ClientProxiedBy: PN1PR0101CA0014.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:e::24) To DM5PR0701MB3640.namprd07.prod.outlook.com (2603:10b6:4:7e::12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 63d819b3-74a7-45fb-d66a-08d5e0f933fa X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(8990107)(5600053)(711020)(2017052603328)(7153060)(7193020); SRVR:DM5PR0701MB3640; X-Microsoft-Exchange-Diagnostics: 1; DM5PR0701MB3640; 3:O12E0g2Wa90GH3WI34gVKj8boCxC3y9bfvuvSuDLTqWTMYpgJ6v2Kr2dqfDKA5OVI8IaNI3F3hXEccAtGSgDF8e+ahJai4LNBFuWJlcvnbYVT5czIXKBQvp7xsbq84J17d2tDaHTxao473mg7L0wm6XmrGG0K2m1TrliBwyHvIQSMhNhV82kXL4xRLnV8VWJCov44xiAzzXgYFjCpsB+DIqGWH0M1pDHarRZCUgcx+Ze9JV8XXjd8B4bMkiinEvp; 25:ea7IwJiAVxEGHJnwpI43VuaQlfw4jzhqOvK9eQFY/YKX7V3Qe7QvdpUHENIKugCoNAkp/pDjCt/5XUsD4mW3l3WNAp3Egt+trGCZ8RQs7s+28ErdAFwwSIFqN72DTeevwgS/YoHtzR+/cJFuDj9Dcz8rLh/8LKkHjd2Fv00p500ecoEtZXK+ZIwh2sCWokCV/eohvqfRhYQbap5SCVI909QRdU2pRUPgyQ/B/ot22rU1Wnn7y4lnXuwPprOqPt5OwB//4yH5x8IfCpmKB1wjR7atc9Dkz9zrQZDgThr7KhjNoJzwnKIQvMsvJNmRj9haRa4y1Viz1UIf5A3EZguwFg==; 31:fGdgkCINnwUXTBsSONX/VW7K5VomEit7Id+t5hXvt7VNmDcbQHpqAgYdGD4q2lyiQjuViIMtLAjMfjct4fVOTrXfxsQkT5U4uIduKppe0v2igqn+mRza6tqlhWYMNW8DEaQq2vRlxuaCh0c731t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qVjNuqwkeJM974q/E5Zhfgb5sCrFm2VbtR2Aq X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(17755550239193); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(10201501046)(3231254)(944501410)(52105095)(3002001)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:DM5PR0701MB3640; BCL:0; PCL:0; RULEID:; SRVR:DM5PR0701MB3640; X-Forefront-PRVS: 0722981D2A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(136003)(346002)(376002)(39860400002)(396003)(366004)(199004)(189003)(50226002)(53936002)(55236004)(316002)(6506007)(107886003)(54906003)(53376002)(42882007)(305945005)(386003)(68736007)(51416003)(575784001)(7736002)(4326008)(72206003)(8676002)(6486002)(478600001)(6306002)(25786009)(81156014)(81166006)(76176011)(2361001)(6512007)(97736004)(69596002)(6116002)(16526019)(3846002)(186003)(2351001)(44832011)(5660300001)(6916009)(53416004)(8936002)(66066001)(47776003)(476003)(106356001)(16586007)(956004)(2616005)(11346002)(105586002)(2906002)(52116002)(446003)(50466002)(5024004)(14444005)(26005)(48376002)(36756003)(486006)(21314002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR0701MB3640; H:hyd1sverma-dt.caveonetworks.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR0701MB3640; 23:nAelsieaumcEqRVoww20YEtOzyDtg9qcl+OkEDE?= =?us-ascii?Q?c5Rx9IJ241DXwPVBzq30DlCb0RhFWqXrfsmAg09AqA4pJxlLewMaIw0weeBz?= =?us-ascii?Q?4sX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yN8PKS8FbCYE2mNOU4lBn4rhTvST?= =?us-ascii?Q?IsOso8qCK+jgEZ5E1S3rwembRYZxvAtfdbEnutq3voTKjZnh0Wohuv1Pvz+r?= =?us-ascii?Q?5s3+mmsAinAT3i+yMnRtR4a+bL59G/ZdajUcnUUo17OXVSVNjcg06T2yqhQB?= =?us-ascii?Q?qyqVlbg3/Gw+YvMqf8lZG8ZtEoJYGU+XOujMBfui7HDy2iUuiydIjzTME989?= =?us-ascii?Q?n9TMutpKJ1lgLd3EmOYRLJWDzR1WfXsRzcg8267SLDN8yQptO16fxvamiDoH?= =?us-ascii?Q?t1i0D9PP9RtGc6b/nJlR1scEyGsYD6E//xnjHbChe4iFROkkiT7aUpyn3Zpw?= =?us-ascii?Q?sxPRvHOYhHl8cKFGA2TSF443WWNQR2fPrdgUlWt6dAuCYd7Ann7ukhEr1GSd?= =?us-ascii?Q?J8xt2inEdFcB2ZIuGwZSjQLobySWB5WPIjOvzLdCoxIzpxQimohHKQW1Lq71?= =?us-ascii?Q?ANtbB095EBjlabkTGdB3jg0q18gcpJSKTf9t5YZ3obCmVRBRfEqfG?= X-Microsoft-Antispam-Message-Info: RWxd9S8rBjwRbIwEcXBBLpw9W5UqGEQ+qFGjh9sqsFTZN69tLGIjlCy7JknNTHaGmWvSZxeOOA2zXIStDPRFV45pMnPdZfS5Tu+coC0IsYuD+9g1u6L/Jhtdlqs596thOEhdVYz4UAvbD4oDiFgXVLUrr9VNOpZ8TKkjsrPcMnRThv+W4AsaOgeyC2GwmimLcuM71PQqeqfCj5gKMfE2XPtDtBb5Ih7DKWNvI9cyfZD4z7SzUG/H4bnqHE/1mc8D/J1IlzH8Gk+EjyDDpOzukZS0g40nC3XDGmtc8kiOpz7DLD8PyCM9hFRedBikANu/b1l9qyzOvpQwd45o75XXob6+0UA2RNY/73rDt+iqyQM= X-Microsoft-Exchange-Diagnostics: 1; DM5PR0701MB3640; 6:fzbB14vuGeUYfmS2p2xk4h8VmuUcOOVDrP2hBbeI7v+xCsiBThpUbW9O4Have9rqEtSbbRNvPqSUuyN/McyOpdsKYxi5LquF1QfTKCRqtCZjGURy/XSDML0bUcItsLKXv8TlJiisI8XTco8qdnx4i62Cpcc0iism4miOdud0Qu7zYl5fl6NIaFqk6GeWkijMAo1bmnOQT4SUdDItJvfbFUnK3/AIzLzwfqhKbGGM78YgDUPbShiEpRyRnwlrB7un56WYewMRisyJ5c2HL1STgOIMNJePXjLmAPzozYMhpBexFWr/LDnBRqxVs1EZ5uBzwaSA2R1nLy1wjSUhLFeyDtrM46I1IytxO+pL5CPxXM1wZczBEUOR5LoI/iubG3BGG4IT7lbutyHcA+LkkpDnSo0jmrTlhFWKO0Jy5OylofcD0/9W6p6OalWzUq084N7L67dhuZytK7g+4x3/Sul5mQ==; 5:uKI1XzhNzjWShoFP2yiEucaPuq1v5+VGetP1go6Qp8iHefn+XYOmkr6Yzo+K/J+ddhX9o6HDA0SYPJxVvp6OOxbnlH268MRRGkwFDP2O0JEah5BG0JKtv0ywxkT8y3joHFeZXKR939AhCiyYuXHf0HBn7mzfp9SSDJVCTt3VAYM=; 24:fm7OHDZ37LQu4JBmZbmFhTTnOlipTh3Gy6RyASzzGFtiSvzmNta2ZfCKb9ItlTU8/RUmQleNXdGT8i543WDXodst2Kkq0lxFrgVzEAM66zc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR0701MB3640; 7:M3bo/ecp7y+2k8w6g+FuHuZXxzrHFPwyfnN0J7mzSBVfnUf/y4yoq2Mj7K7OGvt8Dy5ES5XP2YRWdVkJKMmqcuLHOj9AOUBO0DSpOB9MlQAyhzlrfkYf/rB7pUvXKu0pLpPz+e3WqaKwlVKmIizGKImuY6maPO9QFHxjrvWNTn4wzINAzHjtF5nX4aewyAxgYyQCUhePtnEuYGIfkc3sGHkHCPdAwD1TfwORke0+rynYmqqXH82vLJfmEFQM9/wM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2018 15:25:24.2311 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63d819b3-74a7-45fb-d66a-08d5e0f933fa X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR0701MB3640 Subject: [dpdk-dev] [PATCH v4 4/4] doc: add asym crypto in cryptodev programmer guide X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Jul 2018 15:25:28 -0000 From: Sunila Sahu Update cryptodev programmer guide with description of asymmetric crypto framework in lib cryptodev. Signed-off-by: Shally Verma Signed-off-by: Sunila Sahu Signed-off-by: Ashish Gupta Signed-off-by: Umesh Kartha --- doc/guides/prog_guide/cryptodev_lib.rst | 290 ++++++++++++++++++++++++++++++-- 1 file changed, 279 insertions(+), 11 deletions(-) diff --git a/doc/guides/prog_guide/cryptodev_lib.rst b/doc/guides/prog_guide/cryptodev_lib.rst index 30f0bcf..f6f0405 100644 --- a/doc/guides/prog_guide/cryptodev_lib.rst +++ b/doc/guides/prog_guide/cryptodev_lib.rst @@ -8,7 +8,7 @@ The cryptodev library provides a Crypto device framework for management and provisioning of hardware and software Crypto poll mode drivers, defining generic APIs which support a number of different Crypto operations. The framework currently only supports cipher, authentication, chained cipher/authentication -and AEAD symmetric Crypto operations. +and AEAD symmetric and asymmetric Crypto operations. Design Principles @@ -159,8 +159,8 @@ Device Features and Capabilities Crypto devices define their functionality through two mechanisms, global device features and algorithm capabilities. Global devices features identify device wide level features which are applicable to the whole device such as -the device having hardware acceleration or supporting symmetric Crypto -operations, +the device having hardware acceleration or supporting symmetric and/or asymmetric +Crypto operations, The capabilities mechanism defines the individual algorithms/functions which the device supports, such as a specific symmetric Crypto cipher, @@ -199,7 +199,7 @@ scope of the Crypto capability see the definition of the structure in the Each Crypto poll mode driver defines its own private array of capabilities for the operations it supports. Below is an example of the capabilities for a PMD which supports the authentication algorithm SHA1_HMAC and the cipher -algorithm AES_CBC. +algorithm AES_CBC and RSA operations. .. code-block:: c @@ -245,7 +245,29 @@ algorithm AES_CBC. } } } - } + }, + { /* RSA */ + .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC, + {.asym = { + .xform_type = RTE_CRYPTO_ASYM_XFORM_RSA, + .xfrm_capa = { + .xform_type = RTE_CRYPTO_ASYM_XFORM_RSA, + .op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) | + (1 << RTE_CRYPTO_ASYM_OP_VERIFY) | + (1 << RTE_CRYPTO_ASYM_OP_ENCRYPT) | + (1 << RTE_CRYPTO_ASYM_OP_DECRYPT)), + { + .modlen = { + /* min length is based on openssl rsa keygen */ + .min = 30, + /* value 0 symbolizes no limit on max length */ + .max = 0, + .increment = 1 + }, } + } + }, + } + } } @@ -446,7 +468,7 @@ Crypto workloads. .. figure:: img/cryptodev_sym_sess.* -The Crypto device framework provides APIs to allocate and initizalize sessions +The Crypto device framework provides APIs to allocate and initialize sessions for crypto devices, where sessions are mempool objects. It is the application's responsibility to create and manage the session mempools. This approach allows for different scenarios such as having a single session @@ -788,14 +810,260 @@ using one of the crypto PMDs available in DPDK. num_dequeued_ops); } while (total_num_dequeued_ops < num_enqueued_ops); - Asymmetric Cryptography ----------------------- -Asymmetric functionality is currently not supported by the cryptodev API. +The cryptodev library currently provides support for the following asymmetric +Crypto operations; RSA, Modular exponentiation and inversion, Deffie-hellman +public and/or private key generation and shared secret compute, DSA Signature +generation and verification. + +Session and Session Management +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Sessions are used in asymmetric cryptographic processing to store the immutable +data defined in asymmetric cryptographic transform which is further used in the +operation processing. Sessions typically stores information, such as, public +and private key information or domain params or prime modulus data i.e. immutable +across data sets. Crypto sessions cache this immutable data in a optimal way for the +underlying PMD and this allows further acceleration of the offload of Crypto workloads. + +Like symmetric, the Crypto device framework provides APIs to allocate and initialize +asymmetric sessions for crypto devices, where sessions are mempool objects. +It is the application's responsibility to create and manage the session mempools. +Application using both symmetric and asymmetric sessions should allocate and maintain +different sessions pools for each type. + +An application can use ``rte_cryptodev_get_asym_session_private_size()`` to +get the private size of asymmetric session on a given crypto device. This +function would allow an application to calculate the max device asymmetric +session size of all crypto devices to create a single session mempool. +If instead an application creates multiple asymmetric session mempools, +the Crypto device framework also provides ``rte_cryptodev_asym_get_header_session_size()`` to get +the size of an uninitialized session. + +Once the session mempools have been created, ``rte_cryptodev_asym_session_create()`` +is used to allocate an uninitialized asymmetric session from the given mempool. +The session then must be initialized using ``rte_cryptodev_asym_session_init()`` +for each of the required crypto devices. An asymmetric transform chain +is used to specify the operation and its parameters. See the section below for +details on transforms. + +When a session is no longer used, user must call ``rte_cryptodev_asym_session_clear()`` +for each of the crypto devices that are using the session, to free all driver +private asymmetric session data. Once this is done, session should be freed using +``rte_cryptodev_asym_session_free()`` which returns them to their mempool. + +Asymmetric Sessionless Support +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Currently asymmetric crypto framework does not support sessionless. + +Transforms and Transform Chaining +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Asymmetric Crypto transforms (``rte_crypto_asym_xform``) are the mechanism used +to specify the details of the asymmetric Crypto operation. Next pointer within +xform allows transform to be chained together. Also it is important to note that +the order in which the transforms are passed indicates the order of the chaining. + +Not all asymmetric crypto xforms are supported for chaining. Currently supported +asymmetric crypto chaining is Deffie-hellman private key generation followed by +public generation. Also, currently API does not support chaining of symmetric and +asymmetric crypto xfroms. + +Each xform defines specific asymmetric crypto algo. Currently supported are: +* RSA +* Modular operations (Exponentiation and Inverse) +* Deffie-hellman +* DSA +* None - special case where PMD may support a passthrough mode. More for diagnostic purpose + +See *DPDK API Reference* for details on each rte_crypto_xxx_xform struct + +Asymmetric Operations +~~~~~~~~~~~~~~~~~~~~~ + +The asymmetric Crypto operation structure contains all the mutable data relating +to asymmetric cryptographic processing on an input data buffer. It uses either +RSA, Modular, Deffie-hellman or DSA operations depending upon session it is attached +to. + +Every operation must carry a valid session handle which further carries information +on xform or xform-chain to be performed on op. Every xform type defines its own set +of operational params in their respective rte_crypto_xxx_op_param struct. Depending +on xform information within session, PMD picks up and process respective op_param +struct. +Unlike symmetric, asymmetric operations do not use mbufs for input/output. +They operate on data buffer of type ``rte_crypto_param``. + +See *DPDK API Reference* for details on each rte_crypto_xxx_op_param struct + +Asymmetric crypto Sample code +----------------------------- + +There's a unit test application test_cryptodev_asym.c inside unit test framework that +show how to setup and process asymmetric operations using cryptodev library. + +The following sample code shows the basic steps to compute modular exponentiation +using 1024-bit modulus length using openssl PMD available in DPDK (performing other +crypto operations is similar except change to respective op and xform setup). + +.. code-block:: c + + /* + * Simple example to compute modular exponentiation with 1024-bit key + * + */ + #define MAX_ASYM_SESSIONS 10 + #define NUM_ASYM_BUFS 10 + + struct rte_mempool *crypto_op_pool, *asym_session_pool; + unsigned int asym_session_size; + int ret; + + /* Initialize EAL. */ + ret = rte_eal_init(argc, argv); + if (ret < 0) + rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n"); + + uint8_t socket_id = rte_socket_id(); + + /* Create crypto operation pool. */ + crypto_op_pool = rte_crypto_op_pool_create( + "crypto_op_pool", + RTE_CRYPTO_OP_TYPE_ASYMMETRIC, + NUM_ASYM_BUFS, 0, 0, + socket_id); + if (crypto_op_pool == NULL) + rte_exit(EXIT_FAILURE, "Cannot create crypto op pool\n"); + + /* Create the virtual crypto device. */ + char args[128]; + const char *crypto_name = "crypto_openssl"; + snprintf(args, sizeof(args), "socket_id=%d", socket_id); + ret = rte_vdev_init(crypto_name, args); + if (ret != 0) + rte_exit(EXIT_FAILURE, "Cannot create virtual device"); + + uint8_t cdev_id = rte_cryptodev_get_dev_id(crypto_name); + + /* Get private asym session data size. */ + asym_session_size = rte_cryptodev_get_asym_private_session_size(cdev_id); + + /* + * Create session mempool, with two objects per session, + * one for the session header and another one for the + * private asym session data for the crypto device. + */ + asym_session_pool = rte_mempool_create("asym_session_pool", + MAX_ASYM_SESSIONS * 2, + asym_session_size, + 0, + 0, NULL, NULL, NULL, + NULL, socket_id, + 0); + + /* Configure the crypto device. */ + struct rte_cryptodev_config conf = { + .nb_queue_pairs = 1, + .socket_id = socket_id + }; + struct rte_cryptodev_qp_conf qp_conf = { + .nb_descriptors = 2048 + }; + + if (rte_cryptodev_configure(cdev_id, &conf) < 0) + rte_exit(EXIT_FAILURE, "Failed to configure cryptodev %u", cdev_id); + + if (rte_cryptodev_queue_pair_setup(cdev_id, 0, &qp_conf, + socket_id, asym_session_pool) < 0) + rte_exit(EXIT_FAILURE, "Failed to setup queue pair\n"); + + if (rte_cryptodev_start(cdev_id) < 0) + rte_exit(EXIT_FAILURE, "Failed to start device\n"); + + /* Setup crypto xform to do modular exponentiation with 1024 bit + * length modulus + */ + struct rte_crypto_asym_xform modex_xform = { + .next = NULL, + .xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX, + .modex = { + .modulus = { + .data = + (uint8_t *) + ("\xb3\xa1\xaf\xb7\x13\x08\x00\x0a\x35\xdc\x2b\x20\x8d" + "\xa1\xb5\xce\x47\x8a\xc3\x80\xf4\x7d\x4a\xa2\x62\xfd\x61\x7f" + "\xb5\xa8\xde\x0a\x17\x97\xa0\xbf\xdf\x56\x5a\x3d\x51\x56\x4f" + "\x70\x70\x3f\x63\x6a\x44\x5b\xad\x84\x0d\x3f\x27\x6e\x3b\x34" + "\x91\x60\x14\xb9\xaa\x72\xfd\xa3\x64\xd2\x03\xa7\x53\x87\x9e" + "\x88\x0b\xc1\x14\x93\x1a\x62\xff\xb1\x5d\x74\xcd\x59\x63\x18" + "\x11\x3d\x4f\xba\x75\xd4\x33\x4e\x23\x6b\x7b\x57\x44\xe1\xd3" + "\x03\x13\xa6\xf0\x8b\x60\xb0\x9e\xee\x75\x08\x9d\x71\x63\x13" + "\xcb\xa6\x81\x92\x14\x03\x22\x2d\xde\x55"), + .length = 128 + }, + .exponent = { + .data = (uint8_t *)("\x01\x00\x01"), + .length = 3 + } + } + }; + /* Create asym crypto session and initialize it for the crypto device. */ + struct rte_cryptodev_asym_session *asym_session; + asym_session = rte_cryptodev_asym_session_create(asym_session_pool); + if (asym_session == NULL) + rte_exit(EXIT_FAILURE, "Session could not be created\n"); + + if (rte_cryptodev_asym_session_init(cdev_id, asym_session, + &modex_xform, asym_session_pool) < 0) + rte_exit(EXIT_FAILURE, "Session could not be initialized " + "for the crypto device\n"); + + /* Get a burst of crypto operations. */ + struct rte_crypto_op *crypto_ops[1]; + if (rte_crypto_op_bulk_alloc(crypto_op_pool, + RTE_CRYPTO_OP_TYPE_ASYMMETRIC, + crypto_ops, 1) == 0) + rte_exit(EXIT_FAILURE, "Not enough crypto operations available\n"); + + /* Set up the crypto operations. */ + struct rte_crypto_asym_op *asym_op = crypto_ops[0]->asym; + + /* calculate mod exp of value 0xf8 */ + static unsigned char base[] = {0xF8}; + asym_op->modex.base.data = base; + asym_op->modex.base.length = sizeof(base); + asym_op->modex.base.iova = base; + + /* Attach the asym crypto session to the operation */ + rte_crypto_op_attach_asym_session(op, asym_session); + + /* Enqueue the crypto operations in the crypto device. */ + uint16_t num_enqueued_ops = rte_cryptodev_enqueue_burst(cdev_id, 0, + crypto_ops, 1); + + /* + * Dequeue the crypto operations until all the operations + * are processed in the crypto device. + */ + uint16_t num_dequeued_ops, total_num_dequeued_ops = 0; + do { + struct rte_crypto_op *dequeued_ops[1]; + num_dequeued_ops = rte_cryptodev_dequeue_burst(cdev_id, 0, + dequeued_ops, 1); + total_num_dequeued_ops += num_dequeued_ops; + /* Check if operation was processed successfully */ + if (dequeued_ops[0]->status != RTE_CRYPTO_OP_STATUS_SUCCESS) + rte_exit(EXIT_FAILURE, + "Some operations were not processed correctly"); -Crypto Device API -~~~~~~~~~~~~~~~~~ + } while (total_num_dequeued_ops < num_enqueued_ops); + + +Asymmetric Crypto Device API +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The cryptodev Library API is described in the *DPDK API Reference* document. +The cryptodev Library API is described in the +`DPDK API Reference `_ -- 2.9.5