From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0051.outbound.protection.outlook.com [104.47.42.51]) by dpdk.org (Postfix) with ESMTP id A9F261B217 for ; Wed, 10 Jan 2018 10:43:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=RogvdWgX66dCBVrzGZSo9SOlbBkQ4KystSBd8lX4Ltk=; b=Iru5Dbzb240lLp0NeCxiPzhAtpYV3zLzGmJ+YX7qf9QrHp0qYT6LIlJhqJm1qRqeAoOhAU7O23qzvyfduGuL9duvp6zv+sG5TPhlEE1J0Im7rCXaKNF4QO9RQZ3b8XcOi7o40/kWURlZsQJRFC0qrXYU5YYWYKTdWCWH1qSLwHY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Ravi1.Kumar@amd.com; Received: from wallaby-smavila.amd.com (202.56.249.162) by CY4PR12MB1509.namprd12.prod.outlook.com (10.172.68.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.386.5; Wed, 10 Jan 2018 09:43:37 +0000 From: Ravi Kumar To: dev@dpdk.org Cc: pablo.de.lara.guarch@intel.com Date: Wed, 10 Jan 2018 04:42:52 -0500 Message-Id: <1515577379-18453-12-git-send-email-Ravi1.kumar@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515577379-18453-1-git-send-email-Ravi1.kumar@amd.com> References: <1515145198-97367-1-git-send-email-Ravi1.kumar@amd.com> <1515577379-18453-1-git-send-email-Ravi1.kumar@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [202.56.249.162] X-ClientProxiedBy: MAXPR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (10.174.62.34) To CY4PR12MB1509.namprd12.prod.outlook.com (10.172.68.22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5fda9689-ff2c-499a-d77c-08d5580ea06a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020049)(4652020)(48565401081)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:CY4PR12MB1509; X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1509; 3:bf1PGCXxewzr+tnEz9/mv+WeYH0D3+EwkAExdcGhPlN3PsjCmnArh59NsK6utN2qGxauQRhSCyrcWdPpAkugI7FbBx2rE582/jgsmJBAYIgTmvqwGeLno172rtpobqqeXqk4Q4XFpk4iDZ7ohoPXqFkSdkmsBEc0sRbb4cddGGXX3GItd/N+/ajWCbI3sFv1h22bHA3rgUcWbm/bkknUwHLRwU77648e2FSBndZ9HgG36yZYpBuJWxn9eYdvhpBC; 25:0338KkLMsY6zDGJ5HrErv0BL4d9hscFbjKs3suTzE4etlKNEA3YUtQIPkxi0iHtZrGnp6t8PsIxebAX6IGF+BSPIloxeqAWoYIFPKIFdv+Je6MHUm+8aPhEhNnkXszQzm+Pax0pHviRMllNOhIcxuQ0bF2+vegPofDeAJ/foqSfcSMsrxm1FyMx0m8Fol1THxYFQ5jkjklNbBNFazpMrL1WmMNBZSM6gThggivN0K/t6lXn1yzww0hlnhikbDR/4QxofZ7xj3NpKOeGvAHoC4EQsT8dKvKQcAq0J+ibQGowBnWNPCYHFBw/i7rj1qp0iFVgUVKqFcGLm5clK+NuWwg==; 31:7FDsnQ5Pdza6QnGXaAoO1fglBUbDzfoIQcRylV4AvhwbCu/3+eO6U9ESD7fFOjJrTQBxa2dn3TslcuACnY8R52IfgPn/spykHqmvZWZHUfeLp1Z5zLOgGSSwlZKvXFc5IpiOsyxezkBvnOBoPEAXHQ+0yF2WLURs/w89UdteRAIh5p2xiP8MLf8xa4EMIWszuiKfCcmtJpUeq8soC3OeFAerr+glkLqnNsOH0L7EMaU= X-MS-TrafficTypeDiagnostic: CY4PR12MB1509: X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1509; 20:Iso402vnOKdEAGeoRnvK+fZHbH6k3Du2vmLl5+Cuy/7dUBvCdoMhVHzJ8QFJi3xqcdqH5IOITor38qhuQ0h97f2I4wZcRa8+NCW9Wontlapeb7Lr5UsWJw6KBm0AyaHWBUO9lcgNhpEFC7L/d94Kko4MezLquCv9NT4Zir3wC4GhTsjJ5AmkJ7WSAYbEqrcdutuU1ln+LKK4i/pCieFFUCO7IiJ88udos5kkpZ8AMt3FMUSmPDKKZx0PCPknJxmjFav4utWFEEwpYgKoVbEDLeeVS8K/l4TviSh8czxQcccRDYKjc/vh6jtLHpS+uZP/+QcsMimUwkNv+tFcJ4xf8OdfsnKk59R4PSOwn9+vRMcgFcUFZFvSpBkPq1bfyhMDCsFuTY5HPiE6Pvz87/PehWhkuJkx0/qWG62y8GmOWlDlvJc5KuoeqK9WzrPkAqcZli+Da6ez7CwVZYSC3DZDn6SZP29CN/JhaCJ/pzSQLQhJdhi3GiBk2ILiYe5DQqze; 4:Jgzkl7KeCJFyl6VChsSElt2kxEJKp2Qd2TlJx9Dxlx93otYnhY1KXQcEXju5Ll/M55zDnUtNEmVappE1/w9eLVjtiKT4twdV2cAkr+beaAwy0gfI/r7c7AfKYp00PECWYrHKoRvIbk5L9QM/5PamqMYRBWDHEcX3HEKpNav44CI/u+HS0iFCRQEtx+bQCkP3/HG8JatBBCMgdHfRcSWbiAUDvf2E4KMucK51Yt3m7mDYPJm5SA5tuKAas01ihHjF9SKnqlkMFFhriWCK7Q5vmMOhxM6vWnpZqXoGCbWupEYTJfFOi3TGLOhc5KCt+EoK X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(3231023)(944501119)(6055026)(6041268)(20161123562045)(20161123558120)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:CY4PR12MB1509; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:CY4PR12MB1509; X-Forefront-PRVS: 0548586081 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(39860400002)(396003)(346002)(376002)(39380400002)(189003)(199004)(25786009)(8676002)(81166006)(47776003)(48376002)(6666003)(2950100002)(81156014)(6916009)(66066001)(50226002)(68736007)(36756003)(8936002)(16586007)(72206003)(50466002)(16526018)(316002)(53936002)(478600001)(5660300001)(86362001)(4326008)(386003)(2361001)(2351001)(6486002)(53416004)(97736004)(51416003)(76176011)(106356001)(105586002)(7736002)(6116002)(3846002)(2906002)(59450400001)(305945005)(7696005)(52116002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR12MB1509; H:wallaby-smavila.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR12MB1509; 23:uAw6az53T7R4U15yRfTQE7m9R0wBK0siRBGlIKfwM?= =?us-ascii?Q?BUojB7aGWZ36lWl2q8/OuZ2s7p5UHqNRUEnEh4SpAcWX8Cy6+y8r8Cg4BQTd?= =?us-ascii?Q?Kd+ToiI1tmIFfj4jh0EikBDB5BtY/N32xfDz/wDVVxZ9AaACv9A/WceSXkHs?= =?us-ascii?Q?yhPCTvqNKi0symuDaLORRUjRbv9ygEgDIHHm19qJQhPUCBZwjERvmzOQV6BE?= =?us-ascii?Q?En18RmaQJ8DGD36AwAgML7nmc3FfIiyBURkSMEFyfzmISJI5G7lk3M7E+MAt?= =?us-ascii?Q?vbO1BG2XmGoB2AmmeyyoV0ZpcmJCUz+zJ9l8FDQpovrS9UIParXNcUs85aP6?= =?us-ascii?Q?GYJg59PVmCy7eHSuliCG+dl12uVWaa00IXUvThCBkUimvXMMFXHQymsWYrdw?= =?us-ascii?Q?Ual07SvqQrMbIspnLMAX91B0YooH5NFq2h1QXmRtbDEzrig+IBqfGStn82IN?= =?us-ascii?Q?deMYgKDhdXp3xnNlIjAPYqTNg+nn52/pJEo1EJPplEbgPZMkB2RykibE4wx0?= =?us-ascii?Q?NQ0z3ze38mKAVY+N1673/7lJQ3mNm3kMJWPEfll71aeTa5dc+XU61nTYqBdB?= =?us-ascii?Q?9hhNsJVFICkOZIMGYzm6b918PeF0zjNsQOpDEfEDa3IMz4cKzkCR8t1oz6Vi?= =?us-ascii?Q?CqjVZ+28YcYng0pMDi1R8/tz4h7CuEPTTMWepiR9kB8WU+c2VEJSTJ8X4no4?= =?us-ascii?Q?GaOoHNoMRPf7YA6Obf3jOgFDv3qqFqf7gSqdNfhqvDEbbuWUzsnZJvJ8QuxW?= =?us-ascii?Q?j+fnAKSbarz6yhqgbQwFaa1QpIlyKbHYPoNk3Mjj7zxdFjRoYxzv5g+sY3Wh?= =?us-ascii?Q?O9NZSVAV79KPJnHtpmjLzNJDTKo3XfAWFnkKr6X7hTuT54NTLwMZSwX8KP/f?= =?us-ascii?Q?TUJL4T7iJUq7K3+0n9GEHDiVSq9r3zMB+fsaOcYZh6hNUNUAU05harLp6Rnm?= =?us-ascii?Q?kzyqalsh5G6J0qiITXYHEkQxomm/qY+ltfpjLUZ3OxmR8lyJAU5LIsYdeOtX?= =?us-ascii?Q?lbeO6ZPzBxvE8jBC+2bLAPQzlokRNVa2AqLGwlFo6vEO9StQX4yLuJeQ2lFo?= =?us-ascii?Q?276yMeyNukwr6TGc5tkN4i54kFcQA8pItSauC/61e9F6hfJaBw1gPEipoflc?= =?us-ascii?Q?xordlyQu4ERlLSon7QlYfKE3wtbN8AtN3V4EXY0rBCKITZ6yt0WHA=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1509; 6:dDSJNHb5cpilF8D77LRTmcOoaLnRy8Un43Sqm48jetQZoua79utgLe/zxC8g3dGXNa7CbUhdx/TiwGZxgASjFkofzcBCZbDBMTXZooRZggZEbBIWYyMhAD/kK/ZUITd24WcfwdaRAzsFs/2NfGGhRZIhr964KE1x82DlS3+VJ8Azu0cYQGq+mxrhACh67pOfTeBATCNemBG6XyAhtSqMRpsI5O79Vxnyttp9zIAMdR7O+raYG0q4+cZuVYdyrM7oqKDnSY8oXcUMgFovsH2o2pIK6fVWFsPaMJxElntK86+1PAb2A6hABK5u7yddmEJ1+extFbhumKaqa1Mrv2E6QeL+CsEDeoifQleWtFIPRfI=; 5:83fQMjiFR775reYOFu0cMETrxR3fLVmmpePoOwkX6DLRLgTdRJd/ypRsDZR41vkgd4uyB0SWAeMFYCY5K9AEYUjnzmIN6L7Zp/QE7URiPRovNSfVm54nNw3hAUMsgvmc0RSB4bUKIUATPMYyjIH/1iBwrItggV/luKW0/nuQu+g=; 24:vODJSHZoq6CJpEjcoh+GFuruxDgW8zu7ykErgybO/gyZPCilYZJJe81ID0K8xhj32i0EnlN2kpJ1RxENnVNuClNoPBZcdcwtFP2UC/JUhMA=; 7:UJGjh5QVi+rqbm80IO83tK1sxWjZw+zFUBJvgWZSwm7pn843BT6Z6VD23xM64Jio/tUS5YctPCJwKjB7d+9u1dYnN6UMVEses7WVI7mz6wi1kNV/Ww8lJAoW2kx/gpYuW5CvySn75d6ljG3DUHvaOzqLlFV0DLjOT0sRv4NiVlUurwxTvVwfunPVb1WJ8a0a7zjwAaH5sIlqPvcmwId8kekWIP2puM7reuHXBzxubZLwlQ+MYAwCzJt8ZmljGZwp SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY4PR12MB1509; 20:/WQhJ1OaBPBR/Bt26+f5o1ALJd9wae+FCscjVvmgipsaLIuVTygyQhLGsaoTbhlSB1hinW4K258qM9RlP6A/pKBrt3n/+8EjtPELhNasBgzktef/6pEJGG8ytDt7jmopQve8PTti1jQyDL00/gNrMGm0B59o+BZpH/kyScmH5Ci+Sfuc2eIq9I0TAWTDCXatYT90cyuJUNTazMCwG3xo1xcAUd2Q604/VUulhNinaI9Cg4HYET2HXmYWcZeo13// X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2018 09:43:37.7717 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5fda9689-ff2c-499a-d77c-08d5580ea06a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1509 Subject: [dpdk-dev] [PATCH v3 12/19] crypto/ccp: support aes-cmac auth algo 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: Wed, 10 Jan 2018 09:43:41 -0000 Signed-off-by: Ravi Kumar --- drivers/crypto/ccp/ccp_crypto.c | 277 ++++++++++++++++++++++++++++++++++++++- drivers/crypto/ccp/ccp_pmd_ops.c | 20 +++ 2 files changed, 295 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/ccp/ccp_crypto.c b/drivers/crypto/ccp/ccp_crypto.c index 0660761..6e593d8 100644 --- a/drivers/crypto/ccp/ccp_crypto.c +++ b/drivers/crypto/ccp/ccp_crypto.c @@ -36,6 +36,8 @@ #include #include #include +#include /*sub key apis*/ +#include /*sub key apis*/ #include #include @@ -74,6 +76,84 @@ ccp_get_cmd_id(const struct rte_crypto_sym_xform *xform) return res; } +/* prepare temporary keys K1 and K2 */ +static void prepare_key(unsigned char *k, unsigned char *l, int bl) +{ + int i; + /* Shift block to left, including carry */ + for (i = 0; i < bl; i++) { + k[i] = l[i] << 1; + if (i < bl - 1 && l[i + 1] & 0x80) + k[i] |= 1; + } + /* If MSB set fixup with R */ + if (l[0] & 0x80) + k[bl - 1] ^= bl == 16 ? 0x87 : 0x1b; +} + +/* subkeys K1 and K2 generation for CMAC */ +static int +generate_cmac_subkeys(struct ccp_session *sess) +{ + const EVP_CIPHER *algo; + EVP_CIPHER_CTX *ctx; + unsigned char *ccp_ctx; + size_t i; + int dstlen, totlen; + unsigned char zero_iv[AES_BLOCK_SIZE] = {0}; + unsigned char dst[2 * AES_BLOCK_SIZE] = {0}; + unsigned char k1[AES_BLOCK_SIZE] = {0}; + unsigned char k2[AES_BLOCK_SIZE] = {0}; + + if (sess->auth.ut.aes_type == CCP_AES_TYPE_128) + algo = EVP_aes_128_cbc(); + else if (sess->auth.ut.aes_type == CCP_AES_TYPE_192) + algo = EVP_aes_192_cbc(); + else if (sess->auth.ut.aes_type == CCP_AES_TYPE_256) + algo = EVP_aes_256_cbc(); + else { + CCP_LOG_ERR("Invalid CMAC type length"); + return -1; + } + + ctx = EVP_CIPHER_CTX_new(); + if (!ctx) { + CCP_LOG_ERR("ctx creation failed"); + return -1; + } + if (EVP_EncryptInit(ctx, algo, (unsigned char *)sess->auth.key, + (unsigned char *)zero_iv) <= 0) + goto key_generate_err; + if (EVP_CIPHER_CTX_set_padding(ctx, 0) <= 0) + goto key_generate_err; + if (EVP_EncryptUpdate(ctx, dst, &dstlen, zero_iv, + AES_BLOCK_SIZE) <= 0) + goto key_generate_err; + if (EVP_EncryptFinal_ex(ctx, dst + dstlen, &totlen) <= 0) + goto key_generate_err; + + memset(sess->auth.pre_compute, 0, CCP_SB_BYTES * 2); + + ccp_ctx = (unsigned char *)(sess->auth.pre_compute + CCP_SB_BYTES - 1); + prepare_key(k1, dst, AES_BLOCK_SIZE); + for (i = 0; i < AES_BLOCK_SIZE; i++, ccp_ctx--) + *ccp_ctx = k1[i]; + + ccp_ctx = (unsigned char *)(sess->auth.pre_compute + + (2 * CCP_SB_BYTES) - 1); + prepare_key(k2, k1, AES_BLOCK_SIZE); + for (i = 0; i < AES_BLOCK_SIZE; i++, ccp_ctx--) + *ccp_ctx = k2[i]; + + EVP_CIPHER_CTX_free(ctx); + + return 0; + +key_generate_err: + CCP_LOG_ERR("CMAC Init failed"); + return -1; +} + /* configure session */ static int ccp_configure_session_cipher(struct ccp_session *sess, @@ -170,6 +250,7 @@ ccp_configure_session_auth(struct ccp_session *sess, const struct rte_crypto_sym_xform *xform) { const struct rte_crypto_auth_xform *auth_xform = NULL; + size_t i; auth_xform = &xform->auth; @@ -179,6 +260,33 @@ ccp_configure_session_auth(struct ccp_session *sess, else sess->auth.op = CCP_AUTH_OP_VERIFY; switch (auth_xform->algo) { + case RTE_CRYPTO_AUTH_AES_CMAC: + sess->auth.algo = CCP_AUTH_ALGO_AES_CMAC; + sess->auth.engine = CCP_ENGINE_AES; + sess->auth.um.aes_mode = CCP_AES_MODE_CMAC; + sess->auth.key_length = auth_xform->key.length; + /**auth.ctx_len = CCP_SB_BYTES << 1; + sess->auth.offset = AES_BLOCK_SIZE; + sess->auth.block_size = AES_BLOCK_SIZE; + if (sess->auth.key_length == 16) + sess->auth.ut.aes_type = CCP_AES_TYPE_128; + else if (sess->auth.key_length == 24) + sess->auth.ut.aes_type = CCP_AES_TYPE_192; + else if (sess->auth.key_length == 32) + sess->auth.ut.aes_type = CCP_AES_TYPE_256; + else { + CCP_LOG_ERR("Invalid CMAC key length"); + return -1; + } + rte_memcpy(sess->auth.key, auth_xform->key.data, + sess->auth.key_length); + for (i = 0; i < sess->auth.key_length; i++) + sess->auth.key_ccp[sess->auth.key_length - i - 1] = + sess->auth.key[i]; + if (generate_cmac_subkeys(sess)) + return -1; + break; default: CCP_LOG_ERR("Unsupported hash algo"); return -ENOTSUP; @@ -316,6 +424,15 @@ ccp_auth_slot(struct ccp_session *session) int count = 0; switch (session->auth.algo) { + case CCP_AUTH_ALGO_AES_CMAC: + count = 4; + /** + * op + * extra descriptor in padding case + * (k1/k2(255:128) with iv(127:0)) + * Retrieve result + */ + break; default: CCP_LOG_ERR("Unsupported auth algo %d", session->auth.algo); @@ -415,6 +532,158 @@ ccp_perform_passthru(struct ccp_passthru *pst, } static int +ccp_perform_aes_cmac(struct rte_crypto_op *op, + struct ccp_queue *cmd_q) +{ + struct ccp_session *session; + union ccp_function function; + struct ccp_passthru pst; + struct ccp_desc *desc; + uint32_t tail; + uint8_t *src_tb, *append_ptr, *ctx_addr; + phys_addr_t src_addr, dest_addr, key_addr; + int length, non_align_len; + + session = (struct ccp_session *)get_session_private_data( + op->sym->session, + ccp_cryptodev_driver_id); + key_addr = rte_mem_virt2phy(session->auth.key_ccp); + + src_addr = rte_pktmbuf_mtophys_offset(op->sym->m_src, + op->sym->auth.data.offset); + append_ptr = (uint8_t *)rte_pktmbuf_append(op->sym->m_src, + session->auth.ctx_len); + dest_addr = (phys_addr_t)rte_mem_virt2phy((void *)append_ptr); + + function.raw = 0; + CCP_AES_ENCRYPT(&function) = CCP_CIPHER_DIR_ENCRYPT; + CCP_AES_MODE(&function) = session->auth.um.aes_mode; + CCP_AES_TYPE(&function) = session->auth.ut.aes_type; + + if (op->sym->auth.data.length % session->auth.block_size == 0) { + + ctx_addr = session->auth.pre_compute; + memset(ctx_addr, 0, AES_BLOCK_SIZE); + pst.src_addr = (phys_addr_t)rte_mem_virt2phy((void *)ctx_addr); + pst.dest_addr = (phys_addr_t)(cmd_q->sb_iv * CCP_SB_BYTES); + pst.len = CCP_SB_BYTES; + pst.dir = 1; + pst.bit_mod = CCP_PASSTHRU_BITWISE_NOOP; + pst.byte_swap = CCP_PASSTHRU_BYTESWAP_NOOP; + ccp_perform_passthru(&pst, cmd_q); + + desc = &cmd_q->qbase_desc[cmd_q->qidx]; + memset(desc, 0, Q_DESC_SIZE); + + /* prepare desc for aes-cmac command */ + CCP_CMD_ENGINE(desc) = CCP_ENGINE_AES; + CCP_CMD_EOM(desc) = 1; + CCP_CMD_FUNCTION(desc) = function.raw; + + CCP_CMD_LEN(desc) = op->sym->auth.data.length; + CCP_CMD_SRC_LO(desc) = ((uint32_t)src_addr); + CCP_CMD_SRC_HI(desc) = high32_value(src_addr); + CCP_CMD_SRC_MEM(desc) = CCP_MEMTYPE_SYSTEM; + + CCP_CMD_KEY_LO(desc) = ((uint32_t)key_addr); + CCP_CMD_KEY_HI(desc) = high32_value(key_addr); + CCP_CMD_KEY_MEM(desc) = CCP_MEMTYPE_SYSTEM; + CCP_CMD_LSB_ID(desc) = cmd_q->sb_iv; + + cmd_q->qidx = (cmd_q->qidx + 1) % COMMANDS_PER_QUEUE; + + rte_wmb(); + + tail = + (uint32_t)(cmd_q->qbase_phys_addr + cmd_q->qidx * Q_DESC_SIZE); + CCP_WRITE_REG(cmd_q->reg_base, CMD_Q_TAIL_LO_BASE, tail); + CCP_WRITE_REG(cmd_q->reg_base, CMD_Q_CONTROL_BASE, + cmd_q->qcontrol | CMD_Q_RUN); + } else { + ctx_addr = session->auth.pre_compute + CCP_SB_BYTES; + memset(ctx_addr, 0, AES_BLOCK_SIZE); + pst.src_addr = (phys_addr_t)rte_mem_virt2phy((void *)ctx_addr); + pst.dest_addr = (phys_addr_t)(cmd_q->sb_iv * CCP_SB_BYTES); + pst.len = CCP_SB_BYTES; + pst.dir = 1; + pst.bit_mod = CCP_PASSTHRU_BITWISE_NOOP; + pst.byte_swap = CCP_PASSTHRU_BYTESWAP_NOOP; + ccp_perform_passthru(&pst, cmd_q); + + length = (op->sym->auth.data.length / AES_BLOCK_SIZE); + length *= AES_BLOCK_SIZE; + non_align_len = op->sym->auth.data.length - length; + /* prepare desc for aes-cmac command */ + /*Command 1*/ + desc = &cmd_q->qbase_desc[cmd_q->qidx]; + memset(desc, 0, Q_DESC_SIZE); + + CCP_CMD_ENGINE(desc) = CCP_ENGINE_AES; + CCP_CMD_INIT(desc) = 1; + CCP_CMD_FUNCTION(desc) = function.raw; + + CCP_CMD_LEN(desc) = length; + CCP_CMD_SRC_LO(desc) = ((uint32_t)src_addr); + CCP_CMD_SRC_HI(desc) = high32_value(src_addr); + CCP_CMD_SRC_MEM(desc) = CCP_MEMTYPE_SYSTEM; + + CCP_CMD_KEY_LO(desc) = ((uint32_t)key_addr); + CCP_CMD_KEY_HI(desc) = high32_value(key_addr); + CCP_CMD_KEY_MEM(desc) = CCP_MEMTYPE_SYSTEM; + CCP_CMD_LSB_ID(desc) = cmd_q->sb_iv; + + cmd_q->qidx = (cmd_q->qidx + 1) % COMMANDS_PER_QUEUE; + + /*Command 2*/ + append_ptr = append_ptr + CCP_SB_BYTES; + memset(append_ptr, 0, AES_BLOCK_SIZE); + src_tb = rte_pktmbuf_mtod_offset(op->sym->m_src, + uint8_t *, + op->sym->auth.data.offset + + length); + rte_memcpy(append_ptr, src_tb, non_align_len); + append_ptr[non_align_len] = CMAC_PAD_VALUE; + + desc = &cmd_q->qbase_desc[cmd_q->qidx]; + memset(desc, 0, Q_DESC_SIZE); + + CCP_CMD_ENGINE(desc) = CCP_ENGINE_AES; + CCP_CMD_EOM(desc) = 1; + CCP_CMD_FUNCTION(desc) = function.raw; + CCP_CMD_LEN(desc) = AES_BLOCK_SIZE; + + CCP_CMD_SRC_LO(desc) = ((uint32_t)(dest_addr + CCP_SB_BYTES)); + CCP_CMD_SRC_HI(desc) = high32_value(dest_addr + CCP_SB_BYTES); + CCP_CMD_SRC_MEM(desc) = CCP_MEMTYPE_SYSTEM; + + CCP_CMD_KEY_LO(desc) = ((uint32_t)key_addr); + CCP_CMD_KEY_HI(desc) = high32_value(key_addr); + CCP_CMD_KEY_MEM(desc) = CCP_MEMTYPE_SYSTEM; + CCP_CMD_LSB_ID(desc) = cmd_q->sb_iv; + + cmd_q->qidx = (cmd_q->qidx + 1) % COMMANDS_PER_QUEUE; + + rte_wmb(); + tail = + (uint32_t)(cmd_q->qbase_phys_addr + cmd_q->qidx * Q_DESC_SIZE); + CCP_WRITE_REG(cmd_q->reg_base, CMD_Q_TAIL_LO_BASE, tail); + CCP_WRITE_REG(cmd_q->reg_base, CMD_Q_CONTROL_BASE, + cmd_q->qcontrol | CMD_Q_RUN); + } + /* Retrieve result */ + pst.dest_addr = dest_addr; + pst.src_addr = (phys_addr_t)(cmd_q->sb_iv * CCP_SB_BYTES); + pst.len = CCP_SB_BYTES; + pst.dir = 0; + pst.bit_mod = CCP_PASSTHRU_BITWISE_NOOP; + pst.byte_swap = CCP_PASSTHRU_BYTESWAP_256BIT; + ccp_perform_passthru(&pst, cmd_q); + + op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; + return 0; +} + +static int ccp_perform_aes(struct rte_crypto_op *op, struct ccp_queue *cmd_q, struct ccp_batch_info *b_info) @@ -643,8 +912,8 @@ ccp_crypto_cipher(struct rte_crypto_op *op, static inline int ccp_crypto_auth(struct rte_crypto_op *op, - struct ccp_queue *cmd_q __rte_unused, - struct ccp_batch_info *b_info __rte_unused) + struct ccp_queue *cmd_q, + struct ccp_batch_info *b_info) { int result = 0; @@ -655,6 +924,10 @@ ccp_crypto_auth(struct rte_crypto_op *op, ccp_cryptodev_driver_id); switch (session->auth.algo) { + case CCP_AUTH_ALGO_AES_CMAC: + result = ccp_perform_aes_cmac(op, cmd_q); + b_info->desccnt += 4; + break; default: CCP_LOG_ERR("Unsupported auth algo %d", session->auth.algo); diff --git a/drivers/crypto/ccp/ccp_pmd_ops.c b/drivers/crypto/ccp/ccp_pmd_ops.c index 3a16be8..1fb6a6d 100644 --- a/drivers/crypto/ccp/ccp_pmd_ops.c +++ b/drivers/crypto/ccp/ccp_pmd_ops.c @@ -39,6 +39,26 @@ #include "ccp_crypto.h" static const struct rte_cryptodev_capabilities ccp_pmd_capabilities[] = { + { /*AES-CMAC */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, + {.auth = { + .algo = RTE_CRYPTO_AUTH_AES_CMAC, + .block_size = 16, + .key_size = { + .min = 16, + .max = 32, + .increment = 8 + }, + .digest_size = { + .min = 16, + .max = 16, + .increment = 0 + }, + }, } + }, } + }, { /* AES ECB */ .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, {.sym = { -- 2.7.4