From patchwork Thu Jun 1 08:22:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Eremin-Solenikov X-Patchwork-Id: 100830 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp697522qge; Thu, 1 Jun 2017 01:34:12 -0700 (PDT) X-Received: by 10.200.36.15 with SMTP id c15mr367737qtc.124.1496306052356; Thu, 01 Jun 2017 01:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496306052; cv=none; d=google.com; s=arc-20160816; b=AV4B5Rod22vxdZrER38n1tNZtK+WhWn9p8TBLZZphC6EE1oT+ei3hTRnx1dGQcblo/ qkewzWA5Ziwf47ZsEWM/7PS82FNahnTB02A35hwivWiWjRovYsuisjT+r3N/16sR1P1M co/1lzGYn7/fWkfdRhe8dyy49atdr+MXf2GUBsx3YFTdjOO8hqG8ldegPTxSYRQBXrgu 3W7HPTiGK3k9V6OGALgU6enHfasUgCijJMFytXiAzlWjkSpxOEBnwP8b++yN7Wmu6FB/ I2K1692gH8hPQB8w/XZQVV8i5PrVhn8rPAPGMPj5n89u8OOjCa3h/YWRz7jTHB0HNXlU dYqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:delivered-to:arc-authentication-results; bh=lXRuTsmTIk1n3DInJwZPw1OX1Gl409JG1HSJbtCjgr8=; b=bAy1TbUzu767r5LjyXcIyP+Ho3f+s7Ppv/JpJ4UfswsRZ6x/h97a6UAtqKWGEb/iqD j+BJLVdGc8Mm0M3uh6IfpBMIKO7HTkgW9g9OCkHHHoXXEEg9EoRtfp9XNCFxqfwTiqXb jj6e+9sWJHnlMQ2mw8S6zlSDp59AGiFqaVqBqLehi/xMtoKv0wav6gRxJiUKqLD+iibF eiL7miV7WmWJCTnChpkBXJlrA0rt25qKRk2BaY5Zz0rrees3nHm9SVvCz4S3/Fc/WA3H dHw0508wawFCoNAS4BXLSo1xQ3D6/yH+YSOaCaBMF78Wj7cjWQQOqqjqD8rsFeWDoE// a6mw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id e67si19097480qkd.81.2017.06.01.01.34.11; Thu, 01 Jun 2017 01:34:12 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 813C0609F0; Thu, 1 Jun 2017 08:34:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 4F77960D43; Thu, 1 Jun 2017 08:26:00 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 5CDF760D7D; Thu, 1 Jun 2017 08:25:54 +0000 (UTC) Received: from mail-lf0-f51.google.com (mail-lf0-f51.google.com [209.85.215.51]) by lists.linaro.org (Postfix) with ESMTPS id E73D060CCF for ; Thu, 1 Jun 2017 08:23:38 +0000 (UTC) Received: by mail-lf0-f51.google.com with SMTP id c184so17269976lfe.2 for ; Thu, 01 Jun 2017 01:23:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=lXRuTsmTIk1n3DInJwZPw1OX1Gl409JG1HSJbtCjgr8=; b=cD+evJFVeBeBXLK9l2jmejRd/GqRFDGWRaGfFHoxSdQgxXccz+bSBKrI7T1ig4pTL6 ZDA3O5F5KGAaZtKGEPOM0SOn3K2UpYb19Af2YWrRTbIs1tB4e/g8fHHP2lhqXvjIae2R WG98wSzm5kEc/GgaKLylxep2XqHQgRQjjsq+Cmn7Ll9a+Bc1KS0Qf5nhGlY2pZeU8R0J j/9XmiboMesRzkmkSBvtslMPznBAkvedhi82znOFh36cqd9rT2M+FmsQK8KgLoIoHasi GMe5srgb5LvEs6crjHybNry/02VJ2cdSK/NV+TyvZc8Wo/amwRbJP5mwYoD53WaCjD6i 5a8g== X-Gm-Message-State: AODbwcDK+kzeBOIlE/ZHL4uv0zdge7rZX9cm5SrAqE8IenfmRUh02N/a nqiZNawVOmmUGthRqq/XaSQ5 X-Received: by 10.46.84.21 with SMTP id i21mr94675ljb.125.1496305417569; Thu, 01 Jun 2017 01:23:37 -0700 (PDT) Received: from forlindon.lumag.auriga.ru ([188.162.64.12]) by smtp.gmail.com with ESMTPSA id c78sm4185837lfh.25.2017.06.01.01.23.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 01:23:37 -0700 (PDT) From: Dmitry Eremin-Solenikov To: lng-odp@lists.linaro.org Date: Thu, 1 Jun 2017 11:22:54 +0300 Message-Id: <20170601082320.4673-15-dmitry.ereminsolenikov@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170601082320.4673-1-dmitry.ereminsolenikov@linaro.org> References: <20170601082320.4673-1-dmitry.ereminsolenikov@linaro.org> Subject: [lng-odp] [PATCH API-NEXT v4 08/23] linux-generic: crypto: remote extra memcpy in AES-GCM X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" There is no need to memcpy IV if it gets passed to EVP functions. Signed-off-by: Dmitry Eremin-Solenikov --- platform/linux-generic/odp_crypto.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) -- 2.11.0 diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 352cfa536268..3f298485caef 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -269,7 +269,6 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, uint32_t plain_len = param->cipher_range.length; const uint8_t *aad_head = param->aad.ptr; uint32_t aad_len = param->aad.length; - unsigned char iv_enc[AES_BLOCK_SIZE]; void *iv_ptr; uint8_t *tag = data + param->hash_result_offset; @@ -280,13 +279,6 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID; - /* - * Create a copy of the IV. The DES library modifies IV - * and if we are processing packets on parallel threads - * we could get corruption. - */ - memcpy(iv_enc, iv_ptr, AES_BLOCK_SIZE); - /* Adjust pointer for beginning of area to cipher/auth */ uint8_t *plaindata = data + param->cipher_range.offset; @@ -294,7 +286,7 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, EVP_CIPHER_CTX *ctx = session->cipher.data.aes_gcm.ctx; int cipher_len = 0; - EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_enc); + EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); /* Authenticate header data (if any) without encrypting them */ if (aad_len > 0) @@ -319,7 +311,6 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, uint32_t cipher_len = param->cipher_range.length; const uint8_t *aad_head = param->aad.ptr; uint32_t aad_len = param->aad.length; - unsigned char iv_enc[AES_BLOCK_SIZE]; void *iv_ptr; uint8_t *tag = data + param->hash_result_offset; @@ -330,20 +321,13 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID; - /* - * Create a copy of the IV. The DES library modifies IV - * and if we are processing packets on parallel threads - * we could get corruption. - */ - memcpy(iv_enc, iv_ptr, AES_BLOCK_SIZE); - /* Adjust pointer for beginning of area to cipher/auth */ uint8_t *cipherdata = data + param->cipher_range.offset; /* Encrypt it */ EVP_CIPHER_CTX *ctx = session->cipher.data.aes_gcm.ctx; int plain_len = 0; - EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_enc); + EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, session->p.auth_digest_len, tag);