From patchwork Fri May 12 10:11:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tudor Ambarus X-Patchwork-Id: 9723835 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E9805600CB for ; Fri, 12 May 2017 10:11:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE5E126CFF for ; Fri, 12 May 2017 10:11:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3610287FB; Fri, 12 May 2017 10:11:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8221E26CFF for ; Fri, 12 May 2017 10:11:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757821AbdELKL5 (ORCPT ); Fri, 12 May 2017 06:11:57 -0400 Received: from esa2.microchip.iphmx.com ([68.232.149.84]:27442 "EHLO esa2.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757671AbdELKL4 (ORCPT ); Fri, 12 May 2017 06:11:56 -0400 X-IronPort-AV: E=Sophos;i="5.38,329,1491289200"; d="scan'208";a="2788005" Received: from exsmtp01.microchip.com (HELO email.microchip.com) ([198.175.253.37]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES128-SHA; 12 May 2017 03:11:56 -0700 Received: from rob-ult-M18064.microchip.com (10.10.76.4) by CHN-SV-EXCH01.mchp-main.com (10.10.76.37) with Microsoft SMTP Server id 14.3.181.6; Fri, 12 May 2017 03:11:55 -0700 From: Tudor Ambarus To: CC: , Tudor Ambarus Subject: [PATCH 3/8] crypto: ecc - remove casts in ecdh_make_pub_key Date: Fri, 12 May 2017 13:11:41 +0300 Message-ID: <1494583906-15472-4-git-send-email-tudor.ambarus@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494583906-15472-1-git-send-email-tudor.ambarus@microchip.com> References: <1494583906-15472-1-git-send-email-tudor.ambarus@microchip.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ecc software implementation works with chunks of u64 data. There were some unnecessary casts to u8 and then back to u64 for the ecc keys. This patch removes the unnecessary casts. Signed-off-by: Tudor Ambarus --- crypto/ecc.c | 10 ++++------ crypto/ecc.h | 2 +- crypto/ecdh.c | 3 +-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/crypto/ecc.c b/crypto/ecc.c index 69b4cc4..0d88cec 100644 --- a/crypto/ecc.c +++ b/crypto/ecc.c @@ -928,12 +928,11 @@ int ecc_is_key_valid(unsigned int curve_id, unsigned int ndigits, } int ecdh_make_pub_key(unsigned int curve_id, unsigned int ndigits, - const u8 *private_key, u8 *public_key) + const u64 *private_key, u64 *public_key) { int ret = 0; struct ecc_point *pk; u64 priv[ndigits]; - unsigned int nbytes; const struct ecc_curve *curve = ecc_get_curve(curve_id); if (!private_key || !curve) { @@ -941,7 +940,7 @@ int ecdh_make_pub_key(unsigned int curve_id, unsigned int ndigits, goto out; } - ecc_swap_digits((const u64 *)private_key, priv, ndigits); + ecc_swap_digits(private_key, priv, ndigits); pk = ecc_alloc_point(ndigits); if (!pk) { @@ -955,9 +954,8 @@ int ecdh_make_pub_key(unsigned int curve_id, unsigned int ndigits, goto err_free_point; } - nbytes = ndigits << ECC_DIGITS_TO_BYTES_SHIFT; - ecc_swap_digits(pk->x, (u64 *)public_key, ndigits); - ecc_swap_digits(pk->y, (u64 *)&public_key[nbytes], ndigits); + ecc_swap_digits(pk->x, public_key, ndigits); + ecc_swap_digits(pk->y, &public_key[ndigits], ndigits); err_free_point: ecc_free_point(pk); diff --git a/crypto/ecc.h b/crypto/ecc.h index 1ca9bf7..0d1a2a6 100644 --- a/crypto/ecc.h +++ b/crypto/ecc.h @@ -55,7 +55,7 @@ int ecc_is_key_valid(unsigned int curve_id, unsigned int ndigits, * if an error occurred. */ int ecdh_make_pub_key(const unsigned int curve_id, unsigned int ndigits, - const u8 *private_key, u8 *public_key); + const u64 *private_key, u64 *public_key); /** * crypto_ecdh_shared_secret() - Compute a shared secret diff --git a/crypto/ecdh.c b/crypto/ecdh.c index 69c3951..848a141 100644 --- a/crypto/ecdh.c +++ b/crypto/ecdh.c @@ -88,8 +88,7 @@ static int ecdh_compute_value(struct kpp_request *req) buf = ctx->shared_secret; } else { ret = ecdh_make_pub_key(ctx->curve_id, ctx->ndigits, - (const u8 *)ctx->private_key, - (u8 *)ctx->public_key); + ctx->private_key, ctx->public_key); buf = ctx->public_key; /* Public part is a point thus it has both coordinates */ nbytes *= 2;