From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-eopbgr700060.outbound.protection.outlook.com [40.107.70.60]) by dpdk.org (Postfix) with ESMTP id CC87A5F51 for ; Fri, 8 Jun 2018 18:49:02 +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=ldTWjNoVL7TvTh5D4TY90xAllWKgl3P2AtEB0VejBX0=; b=LRfb12HJXbRInyonyHPyMFSff0SlafKPsNyh1KMg2FPxsI/mSnz8pz/S4YGvS8bF1052hwaHgFydJ8jGlJoheHYJ31eBvlv45HY0Km3HCH18vnC91MI8ZQ/3WuEKKtcgOPHUxUVYM1s6s5PkhDpqGfdnpqk5FdxzjNDIfESa6mo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Anoob.Joseph@cavium.com; Received: from ajoseph83.caveonetworks.com.caveonetworks.com (115.113.156.2) by SN6PR07MB4911.namprd07.prod.outlook.com (2603:10b6:805:3c::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.820.15; Fri, 8 Jun 2018 16:48:57 +0000 From: Anoob Joseph To: Akhil Goyal , Pablo de Lara , Thomas Monjalon Cc: Ankur Dwivedi , Jerin Jacob , Murthy NSSR , Narayana Prasad , Nithin Dabilpuram , Ragothaman Jayaraman , Srisivasubramanian Srinivasan , dev@dpdk.org Date: Fri, 8 Jun 2018 22:15:14 +0530 Message-Id: <1528476325-15585-6-git-send-email-anoob.joseph@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528476325-15585-1-git-send-email-anoob.joseph@caviumnetworks.com> References: <1528476325-15585-1-git-send-email-anoob.joseph@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [115.113.156.2] X-ClientProxiedBy: BM1PR01CA0071.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:1::11) To SN6PR07MB4911.namprd07.prod.outlook.com (2603:10b6:805:3c::29) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:SN6PR07MB4911; X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4911; 3:MfLz9YIwKsbIiGJ0NbiT6tmOpSXFbatbgvdqRwGqouy7nqf8HL1N18ho3gXAWxCtfnsi71bCLw5FW3YJmv8nuszqxVFgzxjU5Rd65Qj08RHHHogLNQ3pieBAqknKNsGR7Kfp91OJOlnfhgWiEnBJ1g9UzB+KPnZPed0HYJECyXny+DP+vkyXz63C7KBWTwhWEibDPL/lb5OSCGfmPzPPxLb6IAEzmJhEVb3p2agyVxo8Iu0gARQxPS711CWINYZZ; 25:8DHggaIU2KBJXPxf6/tjUjaqKy/seX0WCHe/US4JC1qRIEakfHu0jC6293hYVDe7qzUKkoMkEIvRc9tfb3oacPtUXDfggMz+qwxRm1HxC/cNda5nH0vvjNtrwh12uB/MUDymNm8QWWY5g4tmu8y1CrmWZwUUrRjs5KiZacy7elYgidVeBFzXoIVBUsOhU7FAADVKvZweVw9N3zhWiGlSmH5pckOcu7cSOel7lVBrQrq4jqKzHvMXr2i2d3YEWWt+tOyU8RzoBckFS+5LBVi7ZMphdAV0CiqZJ79raY0bhd7goHfwaW/xNZCEvyeSznYI7Un+asHjuQ8rRlgx9aGzsQ==; 31:SQ6XYuy5ffyIyPRXh2xG4CZ0fUY/bd9f67orjpF0cWDFRRBs+dC8oDZpO/j0ofZgn56wvCk6BYB6i2TbtHfWUOx7omtkri4dj1jQDP1oc8/uqgo/YaK/gqSP4tWzdRoo7aPA6XGr9m3hqrG0x9B+qL3tZC0caaCBrT6Lra6/yPX4w6E/uDo5S/DSlvHeNNXV3Wj4ERHyK2LW9hyu8PD5l8AR9PUITfYEwIJabc2v5QM= X-MS-TrafficTypeDiagnostic: SN6PR07MB4911: X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4911; 20:YulIAc3qkXt4B2o+8BkLLDWum12NssoDZFH7ldoo3TzN9BCytseoHyYwbd/Ltt1MowlXThzHNFugCZbvKKtte7Dmpk4NTKVHTRfCDn/yR6OCXC04LTuMLrgM1GfHxDsWeBrai4gFRWqQXYvYLyvZXJDrwhqJ/BD/Vdz4E7WLNKaJxKL69G6k0IVL8R5eixbFrYY8cpnztVbPcTIM3UK3Ekic/4J4J+h8GTAcbu10aNP2pSqW9YC3bKeyBZ7rKIXHiE7qv+uyH6jBg8yryVe5p9U8r3gtku+BLXf+dXnF7Loll3YG252DYZB76xq8msjE6M+8XbhdUCkVo1udWCLmLKfaBvpDedGtyx3gpi/xHzwCK6ZRZMgSsu3ADB5CVXXBLgDPpM0gvw9xxVHDU5aYHOhQKwAIeZkTJVe8W9u+/JrEArH/OqeQi6PulB3DzS5gZbumu0gM6Xmq4LtjFR4A/0ON0z+nRdd6sBka51Xkwy/JlNjub0Mi76/BkW66PVfOz8DDE8JoJi3SM21+KlEbQSq87Dn4R0F6asEjHoIZkHV0V/sfW16aP3mapZSQtq2mMs20/lXl40c1H+ND12R2XLxmhmJvBxstozh464jBjoE=; 4:p3Bkb4Q/xTkv2iuOx6jjqA4NP5NdthIeyQarRfsZz9LDm2LPQS4A4sSTP/9vSlVcqWTx+8nPcm0+Oqe/gGT5cPu8s6VzEHv5VXeeC4SADw0fl4qfiAD3H0Qvi/8dsou0IDkfvJpwadTqrJAacx1yUK2iXTCDrDwwEMfClz3H+ffj01ZxD4vLizvYCGeJmXkDI+S9X2uNRahO665QdWPRgCWGtI3duqS1Y6svtC9JtiIV8JU98iNbz2ZZ09vKTrACBVkca2wOZqeEAtmp/TdDpQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(93006095)(3002001)(3231254)(944501410)(52105095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:SN6PR07MB4911; BCL:0; PCL:0; RULEID:; SRVR:SN6PR07MB4911; X-Forefront-PRVS: 06973FFAD3 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(396003)(346002)(39380400002)(366004)(39860400002)(189003)(199004)(26005)(52116002)(956004)(305945005)(8676002)(81156014)(50226002)(8936002)(81166006)(7736002)(68736007)(105586002)(106356001)(3846002)(6116002)(72206003)(478600001)(6486002)(97736004)(6506007)(16586007)(6512007)(53936002)(47776003)(486006)(25786009)(5660300001)(50466002)(48376002)(6666003)(4326008)(54906003)(76176011)(36756003)(110136005)(66066001)(8656006)(2906002)(316002)(55236004)(11346002)(16526019)(386003)(186003)(59450400001)(446003)(476003)(42882007)(44832011)(2616005)(51416003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR07MB4911; H:ajoseph83.caveonetworks.com.caveonetworks.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN6PR07MB4911; 23:4dbpgOY8A/ueP8U2NCXnTIYRZWYFa+1UsSh2nt1y8?= =?us-ascii?Q?PqOdYqZZ+z9/SsEP39H9wJQz3CrZ7OcNw+QkXWzVI/Yvt+RP928ssw6oZ4Ee?= =?us-ascii?Q?v+9YWNgxszXCnQqWOZmiefDwtFLaz7co/LRUNzOpPW3/k3eIZk+zDOtjO6Kl?= =?us-ascii?Q?m+hZbdmUCiHIonRsA35q0whAAGMGYVLU3/PXOwTJy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LnY45xBrwl6mAuW9j/o1vh5/P/DarvpjAX2JXkzoq4RHa1EegKmq/HrmDR0edu2Ztu3U1R2FhOIaL9yOX4H6f/yBc2McWD4vWFA65e5B97gNfBZ/ovbECZJRPgabvSO+ARgJRXTDQ=; 24:hYeULtQS6r/vGnOFHysM/FRzy0/Qj1XcgvMOAIBVGqsCBXjV3KBE64UZoHjZ4IgLXFyKUdS2xzkthE10D4dwnBv355jktsxSxPnkE0ALQqw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4911; 7:klE71pnF6bte4bjFYi/R8iA2gpTWhdtI+QDXcaMROyk7WL6MBUR+A4wA+osuQMCC7LaTSciV5znasIPs9Bz7mlbHOau9nBOR8S+lkFshefOfCl1LHGPUy+beBC9Uuw//8jUxg2tfDrLNkrwk9ZgOKRL/lpaimKOZBqAJd7cKuaTwYeh4DyRI4r09pJDCB92kkJ6qUv6NBcftaSJZ+okJCTCmCDjTy04T4ouIAzHhvc7x1l2HFBxynUcRk9ciY9Sh X-MS-Office365-Filtering-Correlation-Id: 74802a8b-7ef5-4637-5242-08d5cd5fbc85 X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2018 16:48:57.4638 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 74802a8b-7ef5-4637-5242-08d5cd5fbc85 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR07MB4911 Subject: [dpdk-dev] [PATCH 05/16] crypto/cpt/base: add sym crypto session init API for CPT 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, 08 Jun 2018 16:49:03 -0000 From: Ankur Dwivedi Adds symmetric crypto session init API dependent on hardware/microcode. Signed-off-by: Ankur Dwivedi Signed-off-by: Murthy NSSR Signed-off-by: Nithin Dabilpuram Signed-off-by: Ragothaman Jayaraman Signed-off-by: Srisivasubramanian Srinivasan --- drivers/crypto/cpt/base/cpt_ops.c | 308 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 308 insertions(+) create mode 100644 drivers/crypto/cpt/base/cpt_ops.c diff --git a/drivers/crypto/cpt/base/cpt_ops.c b/drivers/crypto/cpt/base/cpt_ops.c new file mode 100644 index 0000000..e340006 --- /dev/null +++ b/drivers/crypto/cpt/base/cpt_ops.c @@ -0,0 +1,308 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2017 Cavium, Inc + */ + +#include "cpt_request_mgr.h" + +#define __hot __attribute__((hot)) + +#define FC_GEN 0x1 +#define ZUC_SNOW3G 0x2 +#define KASUMI 0x3 +#define HASH_HMAC 0x4 + +struct cpt_ctx { + /* Below fields are accessed by sw */ + uint64_t enc_cipher :8; + uint64_t hash_type :8; + uint64_t mac_len :8; + uint64_t auth_key_len :8; + uint64_t fc_type :4; + uint64_t hmac :1; + uint64_t zsk_flags :3; + uint64_t k_ecb :1; + uint64_t snow3g :1; /* Set if it is snow3g and not ZUC */ + uint64_t rsvd :22; + /* Below fields are accessed by hardware */ + union { + mc_fc_context_t fctx; + mc_zuc_snow3g_ctx_t zs_ctx; + mc_kasumi_ctx_t k_ctx; + }; + uint8_t auth_key[64]; +}; + +static uint8_t zuc_d[32] = { + 0x44, 0xD7, 0x26, 0xBC, 0x62, 0x6B, 0x13, 0x5E, + 0x57, 0x89, 0x35, 0xE2, 0x71, 0x35, 0x09, 0xAF, + 0x4D, 0x78, 0x2F, 0x13, 0x6B, 0xC4, 0x1A, 0xF1, + 0x5E, 0x26, 0x3C, 0x4D, 0x78, 0x9A, 0x47, 0xAC +}; + +static void gen_key_snow3g(uint8_t *ck, uint32_t *keyx) +{ + int i, base; + + for (i = 0; i < 4; i++) { + base = 4 * i; + keyx[3 - i] = (ck[base] << 24) | (ck[base + 1] << 16) | + (ck[base + 2] << 8) | (ck[base + 3]); + keyx[3 - i] = htobe32(keyx[3 - i]); + } +} + +#define MAX_IV_LEN 16 + +int cpt_fc_get_op_meta_len(void) +{ + uint32_t len = 0; + + len += sizeof(cpt_request_info_t); + len += OFFSET_CONTROL_BYTES + MAX_IV_LEN; + len += ROUNDUP8(SG_LIST_HDR_SIZE + + (ROUNDUP4(MAX_SG_IN_OUT_CNT) >> 2) * SG_ENTRY_SIZE); + len += 2 * COMPLETION_CODE_SIZE; + len += 2 * sizeof(cpt_res_s_t); + return len; +} + +/* Provides meta length required when it is + * direct mode i.e single buf inplace + */ +int32_t cpt_fc_get_op_sb_meta_len(void) +{ + uint32_t len = 0; + + /* Request structure */ + len = sizeof(cpt_request_info_t); + /* CPT HW result structure plus extra as it is aligned */ + len += 2*sizeof(cpt_res_s_t); + + return len; +} + +int32_t cpt_fc_get_ctx_len(void) +{ + return sizeof(struct cpt_ctx); +} + +int +cpt_fc_ciph_set_key(cpt_instance_t *instance, + void *ctx, cipher_type_t type, uint8_t *key, + uint16_t key_len, uint8_t *salt) +{ + struct cpt_ctx *cpt_ctx = ctx; + mc_fc_context_t *fctx = &cpt_ctx->fctx; + mc_aes_type_t aes_key_type = 0; + uint64_t *ctrl_flags; + + (void) instance; + + if (!type) { + /* to support passthrough case */ + + cpt_ctx->fc_type = FC_GEN; + ctrl_flags = (uint64_t *)&(fctx->enc.enc_ctrl.flags); + cpt_ctx->enc_cipher = 0; + + *ctrl_flags = be64toh(*ctrl_flags); + P_ENC_CTRL(fctx).enc_cipher = 0; + *ctrl_flags = htobe64(*ctrl_flags); + + return 0; + } + + if ((type >= ZUC_EEA3) && (type <= KASUMI_F8_ECB)) { + uint32_t keyx[4]; + + if (key_len != 16) + return -1; + + /* No support for AEAD yet */ + if (cpt_ctx->hash_type) + return -1; + + /* For ZUC/SNOW3G/Kasumi */ + switch (type) { + case SNOW3G_UEA2: + cpt_ctx->snow3g = 1; + gen_key_snow3g(key, keyx); + memcpy(cpt_ctx->zs_ctx.ci_key, keyx, key_len); + cpt_ctx->fc_type = ZUC_SNOW3G; + cpt_ctx->zsk_flags = 0; + break; + case ZUC_EEA3: + cpt_ctx->snow3g = 0; + memcpy(cpt_ctx->zs_ctx.ci_key, key, key_len); + memcpy(cpt_ctx->zs_ctx.zuc_const, zuc_d, 32); + cpt_ctx->fc_type = ZUC_SNOW3G; + cpt_ctx->zsk_flags = 0; + break; + case KASUMI_F8_ECB: + /* Kasumi ECB mode */ + cpt_ctx->k_ecb = 1; + memcpy(cpt_ctx->k_ctx.ci_key, key, key_len); + cpt_ctx->zsk_flags = 0; + cpt_ctx->fc_type = KASUMI; + break; + case KASUMI_F8_CBC: + memcpy(cpt_ctx->k_ctx.ci_key, key, key_len); + cpt_ctx->zsk_flags = 0; + cpt_ctx->fc_type = KASUMI; + break; + default: + return -1; + } + cpt_ctx->enc_cipher = type; + return 0; + } + + fctx = &cpt_ctx->fctx; + /* Even though iv source is from dptr, + * aes_gcm salt is taken from ctx + */ + if (salt && (type == AES_GCM)) { + memcpy(fctx->enc.encr_iv, salt, 4); + /* Assuming it was just salt update + * and nothing else + */ + if (!key) + return 0; + } + + cpt_ctx->fc_type = FC_GEN; + ctrl_flags = (uint64_t *)&(fctx->enc.enc_ctrl.flags); + *ctrl_flags = be64toh(*ctrl_flags); + + cpt_ctx->enc_cipher = type; + /* For GMAC auth, cipher must be NULL */ + if (cpt_ctx->hash_type != GMAC_TYPE) + P_ENC_CTRL(fctx).enc_cipher = type; + + if (type == AES_XTS) + key_len = key_len / 2; + + /* key len only for AES */ + if ((type != DES3_CBC) && + (type != DES3_ECB)) { + switch (key_len) { + case BYTE_16: + aes_key_type = AES_128_BIT; + break; + case BYTE_24: + aes_key_type = AES_192_BIT; + if (type == AES_XTS) { + PMD_DRV_LOG(ERR, "Invalid AES key len for" + " XTS\n"); + return -1; + } + break; + case BYTE_32: + aes_key_type = AES_256_BIT; + break; + default: + PMD_DRV_LOG(ERR, "Invalid AES key len\n"); + return -1; + } + + P_ENC_CTRL(fctx).aes_key = aes_key_type; + } + /* + * We need to always say iv is from DPTR as user can + * sometimes override IV per operation + */ + P_ENC_CTRL(fctx).iv_source = FROM_DPTR; + + memcpy(fctx->enc.encr_key, key, key_len); + if (type == AES_XTS) { + /* Copy key2 for XTS into ipad */ + memset(fctx->hmac.ipad, 0, sizeof(fctx->hmac.ipad)); + memcpy(fctx->hmac.ipad, &key[key_len], key_len); + } + + *ctrl_flags = htobe64(*ctrl_flags); + + return 0; +} + +int +cpt_fc_auth_set_key(cpt_instance_t *instance, + void *ctx, auth_type_t type, uint8_t *key, + uint16_t key_len, uint16_t mac_len) +{ + struct cpt_ctx *cpt_ctx = ctx; + mc_fc_context_t *fctx = &cpt_ctx->fctx; + uint64_t *ctrl_flags = NULL; + + (void) instance; + + if ((type >= ZUC_EIA3) && (type <= KASUMI_F9_ECB)) { + uint32_t keyx[4]; + + if (key_len != 16) + return -1; + /* No support for AEAD yet */ + if (cpt_ctx->enc_cipher) + return -1; + /* For ZUC/SNOW3G/Kasumi */ + switch (type) { + case SNOW3G_UIA2: + cpt_ctx->snow3g = 1; + gen_key_snow3g(key, keyx); + memcpy(cpt_ctx->zs_ctx.ci_key, keyx, key_len); + cpt_ctx->fc_type = ZUC_SNOW3G; + cpt_ctx->zsk_flags = 0x1; + break; + case ZUC_EIA3: + cpt_ctx->snow3g = 0; + memcpy(cpt_ctx->zs_ctx.ci_key, key, key_len); + memcpy(cpt_ctx->zs_ctx.zuc_const, zuc_d, 32); + cpt_ctx->fc_type = ZUC_SNOW3G; + cpt_ctx->zsk_flags = 0x1; + break; + case KASUMI_F9_ECB: + /* Kasumi ECB mode */ + cpt_ctx->k_ecb = 1; + memcpy(cpt_ctx->k_ctx.ci_key, key, key_len); + cpt_ctx->fc_type = KASUMI; + cpt_ctx->zsk_flags = 0x1; + break; + case KASUMI_F9_CBC: + memcpy(cpt_ctx->k_ctx.ci_key, key, key_len); + cpt_ctx->fc_type = KASUMI; + cpt_ctx->zsk_flags = 0x1; + break; + default: + return -1; + } + cpt_ctx->mac_len = 4; + cpt_ctx->hash_type = type; + return 0; + } + + if (!cpt_ctx->fc_type || !cpt_ctx->enc_cipher) + cpt_ctx->fc_type = HASH_HMAC; + + ctrl_flags = (uint64_t *)&fctx->enc.enc_ctrl.flags; + *ctrl_flags = be64toh(*ctrl_flags); + + /* For GMAC auth, cipher must be NULL */ + if (type == GMAC_TYPE) + P_ENC_CTRL(fctx).enc_cipher = 0; + + P_ENC_CTRL(fctx).hash_type = cpt_ctx->hash_type = type; + P_ENC_CTRL(fctx).mac_len = cpt_ctx->mac_len = mac_len; + + if (key_len) { + cpt_ctx->hmac = 1; + memset(cpt_ctx->auth_key, 0, sizeof(cpt_ctx->auth_key)); + memcpy(cpt_ctx->auth_key, key, key_len); + cpt_ctx->auth_key_len = key_len; + memset(fctx->hmac.ipad, 0, sizeof(fctx->hmac.ipad)); + memset(fctx->hmac.opad, 0, sizeof(fctx->hmac.opad)); + memcpy(fctx->hmac.opad, key, key_len); + P_ENC_CTRL(fctx).auth_input_type = 1; + } + *ctrl_flags = htobe64(*ctrl_flags); + return 0; +} -- 1.9.3