From patchwork Tue Mar 22 12:12:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 8641851 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 491EA9F6E1 for ; Tue, 22 Mar 2016 12:15:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 66B00202FE for ; Tue, 22 Mar 2016 12:15:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7A0612037F for ; Tue, 22 Mar 2016 12:15:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758397AbcCVMOK (ORCPT ); Tue, 22 Mar 2016 08:14:10 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33298 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758265AbcCVMOE (ORCPT ); Tue, 22 Mar 2016 08:14:04 -0400 Received: by mail-wm0-f66.google.com with SMTP id u125so3152637wmg.0; Tue, 22 Mar 2016 05:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GxO2RXTY9ul7MgOuK37qhfx20Hg7b0LzlT0p3Z2QIFY=; b=iLoQ0QxwsBW2qutfHNYZZUZhqvw2gpBdpQdPT2pjFpLU+kpypntVkbzJZLWJBADFU1 hjpPMT4wWsXHwCYsB+P7u+cZ0uYr0SmVArWx8jktEFXLZJyLOqvR6GrfD/pgUPLo1dvg RIGOHCJA7ZVn1R3D3VkBL8iqd1V3qYt1oADJyTn5abBGl39QVd41GtmJT6mvjFa+wNU7 MpkoexgDicoVJEVCaPyEIaBz8itbcSm8YH2dyV0Lv7mEv/kEpiDQQwN4fHHZzLiOZE3z hV0U5IGNLGFCSf6oKBTLWplAcYUI+1qdrxfDHv0LRpcyHFmjK4IJS9nF0h6s6uM+NCoq e5YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GxO2RXTY9ul7MgOuK37qhfx20Hg7b0LzlT0p3Z2QIFY=; b=ItNIcGrVH+7m3TYKN6rp7wPNuxJQXnNEJs2vZGQxMwiejPzJRCvqLUJD7nc4SIa5Z8 yyjLghroA9rsT4adc2CLm8eIisosCzjMRXBhcfqwyo+GjewrprrD85cX2OFBpwdRAmBu fqrZzRZ0yGcx88LgksLqhC6SgOdjjABSHKmlpNkW3LAODaMPums4sh9bC2cIbzOGNerI Nv3IJCLGOiMlLvBYXqCOw7BnNs8Ec3qQdvDonFG6O6UAyqOMFYo/1OUacgk0ePck+te4 swJdCq1PT/QT4wHfJmPNCtVuLAg58AmYFU6soxwzB8MTCBYkc3+8ki6A88uusWOkkoxt nQOQ== X-Gm-Message-State: AD7BkJKxGVhp9afrgfa0l8cN/P+XXAMeCVEloHJ1eHoGxOH1+4D9+SZGpeYwngOPX4AFyw== X-Received: by 10.28.16.206 with SMTP id 197mr19138298wmq.15.1458648841374; Tue, 22 Mar 2016 05:14:01 -0700 (PDT) Received: from localhost (x55b18fc0.dyn.telefonica.de. [85.177.143.192]) by smtp.gmail.com with ESMTPSA id t8sm29938429wjy.41.2016.03.22.05.14.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Mar 2016 05:14:00 -0700 (PDT) From: Nicolai Stange To: Herbert Xu , "David S. Miller" Cc: Tadeusz Struk , Michal Marek , Andrzej Zaborowski , Stephan Mueller , Arnd Bergmann , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange Subject: [PATCH v3 05/14] lib/mpi: mpi_write_sgl(): replace open coded endian conversion Date: Tue, 22 Mar 2016 13:12:39 +0100 Message-Id: <1458648768-1469-6-git-send-email-nicstange@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1458648768-1469-1-git-send-email-nicstange@gmail.com> References: <1458648768-1469-1-git-send-email-nicstange@gmail.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, the endian conversion from CPU order to BE is open coded in mpi_write_sgl(). Replace this by the centrally provided cpu_to_be*() macros. Signed-off-by: Nicolai Stange --- lib/mpi/mpicoder.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c index b05d390..623439e 100644 --- a/lib/mpi/mpicoder.c +++ b/lib/mpi/mpicoder.c @@ -20,6 +20,7 @@ #include #include +#include #include "mpi-internal.h" #define MAX_EXTERN_MPI_BITS 16384 @@ -359,7 +360,13 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes, int *sign) { u8 *p, *p2; - mpi_limb_t alimb, alimb2; +#if BYTES_PER_MPI_LIMB == 4 + __be32 alimb; +#elif BYTES_PER_MPI_LIMB == 8 + __be64 alimb; +#else +#error please implement for this limb size. +#endif unsigned int n = mpi_get_size(a); int i, x, y = 0, lzeros, buf_len; @@ -383,22 +390,10 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes, for (i = a->nlimbs - 1 - lzeros / BYTES_PER_MPI_LIMB, lzeros %= BYTES_PER_MPI_LIMB; i >= 0; i--) { - alimb = a->d[i]; - p = (u8 *)&alimb2; #if BYTES_PER_MPI_LIMB == 4 - *p++ = alimb >> 24; - *p++ = alimb >> 16; - *p++ = alimb >> 8; - *p++ = alimb; + alimb = cpu_to_be32(a->d[i]); #elif BYTES_PER_MPI_LIMB == 8 - *p++ = alimb >> 56; - *p++ = alimb >> 48; - *p++ = alimb >> 40; - *p++ = alimb >> 32; - *p++ = alimb >> 24; - *p++ = alimb >> 16; - *p++ = alimb >> 8; - *p++ = alimb; + alimb = cpu_to_be64(a->d[i]); #else #error please implement for this limb size. #endif @@ -407,7 +402,7 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes, lzeros = 0; } - p = p - sizeof(alimb) + y; + p = (u8 *)&alimb + y; for (x = 0; x < sizeof(alimb) - y; x++) { if (!buf_len) {