From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0075.outbound.protection.outlook.com [104.47.32.75]) by dpdk.org (Postfix) with ESMTP id 5021C1B1CE for ; Fri, 5 Jan 2018 10:40:43 +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=1DmznQD6DcBy9QjQB8016M9lO1Mc1W5f5DvDjS/1fmE=; b=Q4rVe5t9Vz1Gt05w4KIyn0HWCBRws8eAVrzAXcXfCiUIIH6gYT78okliNCT/oGBMAGENllTBmc3vRK79nJIGvlL36Y2BoN/Sc8EYX/cTbtCAaoQBqqLt5hdVFNAwgtWjqRhPC6EpsJSE8++ElwvUtBIbo7iYx7u43SqBrbPKMio= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Ravi1.Kumar@amd.com; Received: from wallaby-smavila.amd.com (202.56.249.162) by BN6PR12MB1508.namprd12.prod.outlook.com (10.172.24.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.386.5; Fri, 5 Jan 2018 09:40:40 +0000 From: Ravi Kumar To: dev@dpdk.org Cc: pablo.de.lara.guarch@intel.com Date: Fri, 5 Jan 2018 04:39:50 -0500 Message-Id: <1515145198-97367-12-git-send-email-Ravi1.kumar@amd.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515145198-97367-1-git-send-email-Ravi1.kumar@amd.com> References: <1512047553-118101-1-git-send-email-Ravi1.kumar@amd.com> <1515145198-97367-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: PN1PR01CA0084.INDPRD01.PROD.OUTLOOK.COM (10.174.144.152) To BN6PR12MB1508.namprd12.prod.outlook.com (10.172.24.149) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 73e9abc9-17ca-4c1c-f23b-08d5542062cc X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(48565401081)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060); SRVR:BN6PR12MB1508; X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1508; 3:a4/sXEqBwNVlDflAlJgPDxL/nK5/lMbJEVlEn73jZm0VlGGdugXOIU606NLFZ+c4d1ykPoO8VZgJopnnNhUMTwwcNUGT9rKKmURqzpFCTZ5q6Q+DbpdZYqShWzCF8/cOG1nJ5cCN0/TQjrnGfWXLevxt3TuCRuiuRaCS9TAY90/nfhImRSKYeZkhcR2BLjMVDEQl7lsg7htHUbrnEiq3AAPDbKPGjS23WVtCvpm7MfOjXHl+f8y8vBiT90B6FE44; 25:TISrc26TDjTEc3t9TgQfb3ReahH8PzLsWhDMUEI9BUm0mSbZHuWyuw58JP0FyuHC2FOIVn6kO32SXIS0HLtupSF81mBXxmfwU309Wkn4NnJmHqKOwTQ3UjYJei6QwO9i3itptkervXZjXxI452+pQr/oPSI/lI74gHkOpfZTQxTLGPZpijzY5ko2vtnABGYyHyeNS8IG3IsRs+UyEG1Tr5wOU/o0uYX/pLmBTkPmwFhvcYn4FfVsccsxnHEb2xpAcFHIgYJascGs6rTVOsjkVEFjLj0g5inH+4sunl4Anw3U4/9hXcLVzduYOkW30zfNSBuUoSa+VKP3dxtoUtXJTg==; 31:OWVOEm9gKbeHuQNRWZ4qPLWqRXr50icTXeiKNyCXHCP7FX1wA7k8huxtMD4xsxJ6hUz/93QR096Q3nSE0vGXxq1ev4Pxi0XY2rkoY56fChEAoz0HW0OZZULWXQQvqw98BjRFeweaBaKJkrcsVLvFBdgHEma44QA/cUQ/JaMd5MpUpvPzCSbnZjDj5Bq1i9+cATx3mLrvzH6qg5p76v9w8/8sNfP3PR4qny/5hZjv/dg= X-MS-TrafficTypeDiagnostic: BN6PR12MB1508: X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1508; 20:eYpVRQ437kJkDRDivxye9x3utOpkbeBa3qAfWDKCj3VhUI7+l2nxNsUkQRasqBRN1ncQZRCCcKNo+GKXclQEPnFmn4FcNu77J5gaCdCnGeGL312BxKouJRHNbUqmSIWrCm4dlzMXvnszqoju7+RvU6IC3jo49yAZG7EED8OdABB2Ex6i9s+QbRq0edgXD+3zB9jJs+4E+TEtLK2oxqXIDY5NCPDAn7NR4HkKrQI7/yXuLG7RMCOqM57hmmnAej3taFweGEMFRhKkxQKMaRCZl9bHX8NNKOHb8ZRbvPmKKCnBaVleUZfBZioQ/8EOV2f9JGveIOoEN38gNmIrUcnoWQy/XXmkPzdHruU+6MtwUA8uGYuJYl8veJWPQrwt46k2x/ciKzWWNOqsLnhJRLToY7ZjO0A+XROjoO/lkhn200dIl2VIl0qKt7t8jCUcTGcjKnEZ2yelJYeRiu52BTHZ4iFpfQAPaeEZeqTWhh7nc22KK2NECMwDPwldo0McTDtT; 4:iL7caY8zRjh9qdpV/SLh2w9MvtzD8MabNpSYFD8roN62nNio5W13kiPOTbQiS7vgX5hQm3DhRE9y3Oi6CQ8hdtVsGbYisqtakMVpfPu8aESeCDFi8gPG21Z77BnLIGH3Z6GcxgTqn4MJF9cjmy8PEefjGLrgw4TiCG4kXXbGgS37rBS6A1rdlQ2Emk30SvATxo+EJXHWCVao0avMtbdPUt8wNu/igqns8SOfBYNOUlKDcexfHLbPEueEe47879YS1QgpNYjmVaIjD/EiqOUFN2M3WfOizR7kgT7YExvYfXerd7F7usI5pX7hnmiKAnRM X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231023)(944501075)(6055026)(6041268)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011); SRVR:BN6PR12MB1508; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:BN6PR12MB1508; X-Forefront-PRVS: 05437568AA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(39860400002)(366004)(346002)(39380400002)(376002)(199004)(189003)(6486002)(2361001)(6116002)(106356001)(386003)(105586002)(3846002)(6916009)(2950100002)(16586007)(6666003)(16526018)(36756003)(4326008)(2906002)(316002)(97736004)(25786009)(478600001)(86362001)(68736007)(8676002)(48376002)(51416003)(81166006)(2351001)(81156014)(52116002)(8936002)(53936002)(305945005)(50226002)(76176011)(72206003)(50466002)(53416004)(7696005)(47776003)(66066001)(59450400001)(5660300001)(7736002); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR12MB1508; H:wallaby-smavila.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; BN6PR12MB1508; 23:tccO6Rg/3o6NHquRLYlxrqy6RK/z6sMXsYM2QDo1f?= =?us-ascii?Q?Ku991S1HiGm79DmGTrZ8B43CYdTo8x27KikiROp3BQyn02J6TLER31rb3tzI?= =?us-ascii?Q?c5v/Qil6V0mIWD20ntoIPABru6LP1odCLJYxqRGdD46/zeLayrcHjeIP2jR6?= =?us-ascii?Q?jlS17NNpm0ikdMkz3Uk5WRu6PGf//YhSevG/gKKvc/+CpUzyfo1ZExgN2gOd?= =?us-ascii?Q?ktOTIvAebYJBuEBUW4gVW1XcJwiiQWDas6KBuPgiTjE+FlKlgTwa0I2HvrR7?= =?us-ascii?Q?AWEMuACNepalsGNJ6A0dmIzzt7apWhdcg8pq6ihBgqv/tZNSzY2QMxWOqRku?= =?us-ascii?Q?3v8Rvx5rwDyPL4RdYOkWkSet6q+Dc7aoT9SNg98g3D//WVw2pPTBrbELBVKZ?= =?us-ascii?Q?Nv+OSyWuso6suf5SGoOi/AmWdrrmc6PM6gfe9foaJOmL+knuzFg6QMr687g1?= =?us-ascii?Q?G3LR6qNdy6ULWZgwwk0xYs2MoY/nZ4JL8ZxeZaiUyYlAx1Ku24F0uAlwIO8I?= =?us-ascii?Q?scTobShODGe3F+mFTmJbcfyD8no4hLAZOKeKmTztx+wYo3r+jKuoDW367/6z?= =?us-ascii?Q?meJ7zlnYVY/LVpjwOmIcudcE/ud/FrL91raM9zC341bG27SV8jrJMyYIcQPl?= =?us-ascii?Q?mp/wpcB9X/hC1K1xaxUX643sa29WYFHaBjRJl8qqfDCh1m8Le/zDAc3H+VvW?= =?us-ascii?Q?KeBhMrPYHq21H9eli6KC+MEySGgAffgij6JuHu0OHFujerVncYqUp85eQnYs?= =?us-ascii?Q?xDtQjO0vnUdSu1Sy7AvOwQSwwMDtwxlpBHval/OjaQZenzMw+0Y7byOMeJDx?= =?us-ascii?Q?OOllmymoMTGyzMoqQz2/iCynrUAGuxPWgE115TSB0V3BUJRllAQwGhpHfrW2?= =?us-ascii?Q?MuDcTm9muM2oANDX2rWgHWPjnKB27RVckroPL3KS4zM7HAziwbeAMJWV5Ekl?= =?us-ascii?Q?HgY/AaHeIt8z9ILWaBSIuadLrRZPJ5wHcy/ZSuGuq9slXoZg4jAA9X9OVemz?= =?us-ascii?Q?AHrn5BVzgrZg/jX16Q8Zfxt2c9liXlySWAZlmI/rz2aapgnbFD/9Ax/mhK7g?= =?us-ascii?Q?kGlaTRMVUMoLqhxp/K3P37vB0OWnThJkefgcJFTthSu3Mnrp+WPH1RiwKZcV?= =?us-ascii?Q?SrENeaD2PqiPd+rVv74KcvH9aqiQ2BmMjJXq/hHRGXG7Sb02Dhx1Q=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1508; 6:PStnQDdKqHYcnEkeoWABlAk7ZHCAXMQsBgiDZah3/EDLoHPuh/jssGy8RI6BFu0f4cyjs1goosk6pgli7vyPKGQPdHfz4Hi+YfirLZ10gack8St7Sg9d5NZRPJQYWz7aja8kkx1/LgU2FcdqIkZaeTX375dpJF3xsdpT7Mz83RyUnQpnGlJOmumAvtNiyrfCkMDkRv8gb5ZpCpVV59GbDsF5ApTC61Vh2DRkbCRg4fKgKb3YGbHgTmJGjIhw1PFvajF1qFkRON/jgjVf6w+TCWLR2AGbpx63l0nbsxXNCBMZO+88eF6TmiKJK3elW5Nxp3lRJIAmIsX3CEEe2e298Hna4oxYJ+Ns9xBwUL9jANQ=; 5:iOBrGMFlyFDhWtB45uGq0XtsjPppbNAKcCvdbl3ixi9xzegchoifZa0uA8CHNGmN+vNG0jYwe8lUZQ3GdGPNKvO2IC10yrsyeOlcnd9jOKhvlg68YHm1DRGkPsB+3ZIhI/rn+zyDEmp2nCeXCWqFbCCKX41DNuS3pANdxnsfewI=; 24:h3qm4+MZg0RC7ksJdLyhpC3BSuqEeqFQhqYdWkWxxhXr1Z2AjxHWwahBl0ad1OM1cV4ePD1qE2c2V3lL6/lshYFXpViZEenH/MjYLfmOLx4=; 7:TcQZvdVGxZe9SrIasCEtirip4lg/62i1Pc5hbKeAq3l/8QUCnP9ssHERqG2uptl2Y4Gq8BcKyHGdpXUx2H6auuiFZ6F5Vwzl2FZ+z0dpb+7COlsiCTHPGegnXf5AbFo4ud56iC2TWhtqkiamnbDBzImMHp6jJv7RgEysOmZYLjj10mVz0gmi51lyMrIaGTKqauPNVYwDh+pWgcyy//Y3j/5p852u9ak6UH3imEMnX+OANFlmEzFWm+hoyt3PCZFz SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR12MB1508; 20:N/JO0uvvxuGEouUK3iPIEmIY7vv5qc6BgnHnkeKXMuxgZxDwyhJcd7mJo8KBRFYKiiXa7H55I14DS9nAS8E5bWm95MK1yoGxU34r5gJFH6d1WG49iaFyjx9+Glmw1FC53vPRAVo5ebZKyesCMjQ4g3Yb3ol31GvyKPja7v9LUOkGSTb+/bPPWN1os2ctMOqh5qmr2TWFCQt6HmIezeNZEyI2/76VnxOulghw3wTtpaOTa0jmgbOyLF8vH85TKGaB X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jan 2018 09:40:40.6858 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 73e9abc9-17ca-4c1c-f23b-08d5542062cc X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1508 Subject: [dpdk-dev] [PATCH v2 12/20] crypto/ccp: add aes-cmac auth algo aupport 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: Fri, 05 Jan 2018 09:40:44 -0000 Signed-off-by: Ravi Kumar --- drivers/crypto/ccp/ccp_crypto.c | 277 ++++++++++++++++++++++++++++++++++++++- drivers/crypto/ccp/ccp_pmd_ops.c | 21 +++ 2 files changed, 296 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..59e7285 100644 --- a/drivers/crypto/ccp/ccp_pmd_ops.c +++ b/drivers/crypto/ccp/ccp_pmd_ops.c @@ -39,6 +39,27 @@ #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 + }, + .aad_size = { 0 } + }, } + }, } + }, { /* AES ECB */ .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, {.sym = { -- 2.7.4