From patchwork Thu May 26 11:05:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 9136927 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 850756075C for ; Thu, 26 May 2016 11:06:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7890D27B90 for ; Thu, 26 May 2016 11:06:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D0E228278; Thu, 26 May 2016 11:06:11 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 2065B27B90 for ; Thu, 26 May 2016 11:06:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753649AbcEZLGE (ORCPT ); Thu, 26 May 2016 07:06:04 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33340 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753647AbcEZLGC (ORCPT ); Thu, 26 May 2016 07:06:02 -0400 Received: by mail-wm0-f67.google.com with SMTP id a136so4270046wme.0; Thu, 26 May 2016 04:06:01 -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=7dVHB/ymQuRClmlFsUkOg43Z3kKVkO+Q0ymLiR+0OFo=; b=vMBidZ1kSNtppQNHB+WT6IonbXKW1lKQOys7qgD7HrqH+RH0ppjuWn1Y+/B4aU5utx UL788v+4YmCV/M1Rf0YryQ8FHxJmsQUm8idFLB17/MGfdP1akTAQeEqffBlSCbzMZqWa 8ziXzdRcs3WvJvK1Snt6NSuqhuK6eVmxuQquZsHmhv91xfei3QOQqjGwPho31tSoMsuM bd6fCzr7Uw2h0GNvje3RjHOtOYR0ndQ4IU/uW5E4e6nRFsFRDWF9qjS4gKqB4BWWTM92 RXCBbmDbzlIIp4DvDwkFMTJDMQ+C06JaQbIzTts4KVHI6v1D/IRSCOou1/Y5G40BNw3d FEFA== 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=7dVHB/ymQuRClmlFsUkOg43Z3kKVkO+Q0ymLiR+0OFo=; b=ZN9JUaAqobZ905W67atAqBCt1sXnYEdAT8WKMKUJ2Qk8MLN5rKMYsKj52Cw252r/9i nmu4UughBevs3IVjOj+wsPFmUILAR/WfN2saAwKaGQN7jqMzmqDpYDiedW1/GVNrKkc9 Yyj44OmyjSLIQBx+jo9oMV8R6pcy6LKOrsrGrmhesmJyAMU7Dex/4k/RjcZH1EYC1EIn S0Ot8AMH9Ox1WKHHWGBbS73lTquzjYKXgQEbiKNAFeMyKkY5q2DyIg0oNIa+zWJGLQ95 kZRW3Vqgm+KwgMDvCrR8qa2e93nLt5UJ1JoHCY4Ulfyu5fhBd50I+Liue4M/DdOmNZFG UtPA== X-Gm-Message-State: ALyK8tIX/cc0MqM10BhqlIeqV6CwxqqGznQpIEuEeokk6pudpi5w0dNh4+kzG6W5LO1t+g== X-Received: by 10.194.110.137 with SMTP id ia9mr8826117wjb.107.1464260760629; Thu, 26 May 2016 04:06:00 -0700 (PDT) Received: from localhost (x4e361809.dyn.telefonica.de. [78.54.24.9]) by smtp.gmail.com with ESMTPSA id u4sm13778274wjz.4.2016.05.26.04.05.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 May 2016 04:06:00 -0700 (PDT) From: Nicolai Stange To: Herbert Xu Cc: Tadeusz Struk , Michal Marek , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolai Stange Subject: [PATCH 2/2] lib/mpi: mpi_read_raw_data(): fix nbits calculation Date: Thu, 26 May 2016 13:05:32 +0200 Message-Id: <1464260732-4446-2-git-send-email-nicstange@gmail.com> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1464260732-4446-1-git-send-email-nicstange@gmail.com> References: <1464260732-4446-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-Virus-Scanned: ClamAV using ClamSMTP The number of bits, nbits, is calculated in mpi_read_raw_data() as follows: nbits = nbytes * 8; Afterwards, the number of leading zero bits of the first byte get subtracted: nbits -= count_leading_zeros(buffer[0]); However, count_leading_zeros() takes an unsigned long and thus, the u8 gets promoted to an unsigned long. Thus, the above doesn't subtract the number of leading zeros in the most significant nonzero input byte from nbits, but the number of leading zeros of the most significant nonzero input byte promoted to unsigned long, i.e. BITS_PER_LONG - 8 too many. Fix this by subtracting count_leading_zeros(...) - (BITS_PER_LONG - 8) from nbits only. Fixes: e1045992949 ("MPILIB: Provide a function to read raw data into an MPI") Signed-off-by: Nicolai Stange --- Applicable to linux-next-20150525. lib/mpi/mpicoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c index c160393..d197210 100644 --- a/lib/mpi/mpicoder.c +++ b/lib/mpi/mpicoder.c @@ -50,7 +50,7 @@ MPI mpi_read_raw_data(const void *xbuffer, size_t nbytes) return NULL; } if (nbytes > 0) - nbits -= count_leading_zeros(buffer[0]); + nbits -= count_leading_zeros(buffer[0]) - (BITS_PER_LONG - 8); nlimbs = DIV_ROUND_UP(nbytes, BYTES_PER_MPI_LIMB); val = mpi_alloc(nlimbs);