From patchwork Mon Mar 21 13:26:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 8633071 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 66788C0553 for ; Mon, 21 Mar 2016 13:29:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7D2F3202E5 for ; Mon, 21 Mar 2016 13:29:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 93F782026F for ; Mon, 21 Mar 2016 13:29:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755598AbcCUN0u (ORCPT ); Mon, 21 Mar 2016 09:26:50 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:34710 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755500AbcCUN0m (ORCPT ); Mon, 21 Mar 2016 09:26:42 -0400 Received: by mail-wm0-f67.google.com with SMTP id p65so22326493wmp.1; Mon, 21 Mar 2016 06:26:41 -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=P3RLuIdJb8hn50V2BbsnwJBthntkRE9VTItcIngCWxw=; b=NJaKfGnz0fTQXQAsu+l2AxxSvnqx9Wse3lYRIZ7sNbhrHa1ZW2N+oJU+MRBGeG2l0k rvWEuuF0a2jiJmsCMZFdbE9Lqe/Z+FygJHQFuatbXM+qWga7njYOffs7DjZ5xoRRvQS5 Pa2MgnDhp8zDRjQhH2K43Qx4qeYEpEGNLfTe6GT85e8mzNGZhOtMR5xgdw9BtwA9JgZU flCABwLiRbiu004+g0Hea6RWZ+zr22hFpeDpx2o6Deou/YOPtkEUDWTs1OSTcfQ8fIyo PthuY3FlbZ1iY63E5Rx8T2d1gfjoYroLFYgEtg3LR0j5BnlANSf/IHoH5Uhcv55Apsrd 7Qlg== 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=P3RLuIdJb8hn50V2BbsnwJBthntkRE9VTItcIngCWxw=; b=S8aNwfXKc/9j+x+5eMrUkZOrU39kn117VYjuuai8IIzLN8elUxPPYRfLIRj9uTbww5 tPss7Ta/Y6tCLr5GwgoXUMSXLekW7b3hFzGeALnNnJ09tXntt0Mzl+fifmFoGrhl7ezL IpcHXIDsjUckCzhZC4MEe2LaZPxxGWToftspioIAFMJmW8w7OjNtX2OGmBH7A33qi6dP GBLImcTHs3/FGJ+SBqFTnM0vpULvs/R5xoQcFr1JyfaXN4BgkPikBz1AWvg4UEQPiTkX lqAaA4pKRBPuuzjZRSNStq/Uz94mBz1Di5zZw076LapXY/dXhry3yoP3HJxuEqKu2ojD XcOw== X-Gm-Message-State: AD7BkJJHA2yeb+832IKwu6JzaZHv1Wf+rYYW/+L1IgrnlUTqKsKQcd59/en1K+SYpQKt0g== X-Received: by 10.194.5.36 with SMTP id p4mr30829566wjp.167.1458566800934; Mon, 21 Mar 2016 06:26:40 -0700 (PDT) Received: from localhost (x55b18fc0.dyn.telefonica.de. [85.177.143.192]) by smtp.gmail.com with ESMTPSA id et11sm25457466wjc.30.2016.03.21.06.26.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Mar 2016 06:26:40 -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 RESEND v2 05/14] lib/mpi: mpi_write_sgl(): replace open coded endian conversion Date: Mon, 21 Mar 2016 14:26:06 +0100 Message-Id: <1458566775-5239-6-git-send-email-nicstange@gmail.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1458566775-5239-1-git-send-email-nicstange@gmail.com> References: <1458566775-5239-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, RP_MATCHES_RCVD, T_DKIM_INVALID, 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) {