From patchwork Thu Jun 1 09:03:24 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: 100845 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp707862qge; Thu, 1 Jun 2017 02:09:57 -0700 (PDT) X-Received: by 10.200.45.247 with SMTP id q52mr447300qta.177.1496308197885; Thu, 01 Jun 2017 02:09:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496308197; cv=none; d=google.com; s=arc-20160816; b=xz6RiVQGficUZQzV7MhAEE4/kUCTl+mDSjSbqgfKLZiqQvGcmEUna2KD+7PoFhqXKI jD1is2kxG/o1/45eFGJ0/Wy31MoI03Wmd84FagnvxKqsI7gLkhkezknSRwaxGu7eSyz7 IN5oPKCtHxkIAj6uUaICV5+QYP43Z9bCqN25dtpB0Cw26e/6I1e0SXyb+Ty56Khbfco1 x7WaSYK3n6Mpk2FCuAPd6rLNVXhB9hmJ+kUT+xqy3Nen6JXhLIv91b3h8H9mai2LYBZU J1Q+ao6wVyzFS/wkChOddFrY4/X3raZy5bm1EePkJF97QUD51WhBC8hm23tVDO6PeZeg XnNg== 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=jNU6UZOQJPKz0HitIz/4eXut5NeLQX0LQKtWV6R9hl7hvy9YO26Eew6ugQ4CgLKKcX W2T8vrmQaWjABJhG//HyVIRyxfKYZ8+lm8i9wb3Gx2h7qVbm9AxGZIGbzgD9vmY/A1yt /W/fljXwja5JRr4+eO3fpGgRnbztz5zKRMiuyLqsXjRb6K/HyrADAwcuhpba2MgeS9us fsFdamUrX0D3Q6J9kDAug8kveXVlyP5wDcYm3PoV6Ry+cTNwxS0j04CZya9QfRGxaYpS syPOtoCTCaqNLA9zJzQ1twdLRj6SCJcydV0DIrUg8sU42Y3b/WZr0yQTSvRskf2/3OkR ZRAw== 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 z2si19088326qke.253.2017.06.01.02.09.57; Thu, 01 Jun 2017 02:09:57 -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 1E0AA608C4; Thu, 1 Jun 2017 09:09:57 +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 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 3251160D6B; Thu, 1 Jun 2017 09:05:02 +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 B9C4B60D5E; Thu, 1 Jun 2017 09:04:56 +0000 (UTC) Received: from mail-lf0-f44.google.com (mail-lf0-f44.google.com [209.85.215.44]) by lists.linaro.org (Postfix) with ESMTPS id 30F3A60825 for ; Thu, 1 Jun 2017 09:03:52 +0000 (UTC) Received: by mail-lf0-f44.google.com with SMTP id h4so22652060lfj.3 for ; Thu, 01 Jun 2017 02:03:52 -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=KmT64nmjSS39PObt3M7FQevdNtTNR4FLHZUl5/BgUUEShpSRtBDWrJqyqGJwIw24mt m6NcKPT0pBOTtmuoAjAEqCGfmc4VsscKUWYwWTr5rVEDseQaGNPr7zvsIP+HLbAcZsoz LunffGHF0ZhSsDAAhUT9whq0UboU2GrgEcJO8/k6nNk/Jx2lfmnzXWMu8DItAa1A7X7e 2Nk2usih5REoHKlnXjPr6fy1m0H1OjJKVltkhdcl7IMm0QewdZ0F5u33AUohWi1FqFbn acFEdN3ZkEq0jOrruvguQHDkcCIerX0wrrSYyJ1JrRZ0pIfIIF5/a2GwAEktNRsQxVy8 SDtQ== X-Gm-Message-State: AODbwcCVb7dAZuwX93sOuCX7pJ0oKfM2iXFQinj0pm5AuAz10YqR8iS0 kGBskDn2XrMIYxaS9y2SHSm0 X-Received: by 10.25.196.207 with SMTP id u198mr204990lff.20.1496307830852; Thu, 01 Jun 2017 02:03:50 -0700 (PDT) Received: from forlindon.lumag.auriga.ru ([188.162.64.12]) by smtp.gmail.com with ESMTPSA id 129sm4232819ljf.36.2017.06.01.02.03.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 02:03:50 -0700 (PDT) From: Dmitry Eremin-Solenikov To: lng-odp@lists.linaro.org Date: Thu, 1 Jun 2017 12:03:24 +0300 Message-Id: <20170601090339.9313-9-dmitry.ereminsolenikov@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170601090339.9313-1-dmitry.ereminsolenikov@linaro.org> References: <20170601090339.9313-1-dmitry.ereminsolenikov@linaro.org> Subject: [lng-odp] [PATCH API-NEXT v5 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);