From patchwork Fri Jul 24 16:50:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ahmed Soliman X-Patchwork-Id: 6861971 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 8B2909F1D4 for ; Fri, 24 Jul 2015 16:50:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4CE80205BD for ; Fri, 24 Jul 2015 16:50:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D3C6C205B7 for ; Fri, 24 Jul 2015 16:50:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752266AbbGXQuV (ORCPT ); Fri, 24 Jul 2015 12:50:21 -0400 Received: from mail-wi0-f177.google.com ([209.85.212.177]:35581 "EHLO mail-wi0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751424AbbGXQuU (ORCPT ); Fri, 24 Jul 2015 12:50:20 -0400 Received: by wibxm9 with SMTP id xm9so36895975wib.0; Fri, 24 Jul 2015 09:50:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:content-type:mime-version :content-transfer-encoding; bh=3Uie9ZiVouTY5mgg4sggMo3NUHevh9ml6p8qORtKjp8=; b=SRt4YiXELBTCAD/M8MjNzd9KLcKpvXS+3QNtobyzmDfbVQ7z5FTv3loGsHu9YIP8KV Xoa0HVhTaV7NA9/P045hCp6ShQGde/WwvCVMRsyC4yTNznxF9+1oGtq9qO+KdR9aj6Av snI0IGp8TSHw+dd88SaeJjJEN4EI5GxxTW0VLf+A6EkSdsYHTI1tx0msVnDnQZ+7Dt9c ZQNczql4dZohN3AXfFs8Lbn6OnVNm1k9uywKHn0/VSwtcsmuIwaRYzMwB3d4dKPTDiMV DPh00iz3v3+FxsGBseYnHYrW2cb1jnIg6lZEyIFMSu9TYtOoTOvW9S+8XYaq0D8P3xwr 82VQ== X-Received: by 10.194.219.231 with SMTP id pr7mr1951761wjc.81.1437756619364; Fri, 24 Jul 2015 09:50:19 -0700 (PDT) Received: from [192.168.1.4] ([41.234.164.160]) by smtp.googlemail.com with ESMTPSA id ex8sm13482894wjc.34.2015.07.24.09.50.16 (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128/128); Fri, 24 Jul 2015 09:50:18 -0700 (PDT) Message-ID: <1437756615.27636.2.camel@My-Computer> Subject: [PATCH] cleanups for crypto/wp512.c From: Ahmed Mohamed Abd EL Mawgood To: herbert@gondor.apana.org.au, davem@davemloft.net Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 24 Jul 2015 18:50:15 +0200 X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-8.0 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 fixing all errors and warning of checkpatch.pl for crypto/wp512.c Signed-off-by: Ahmed Mohamed --- crypto/wp512.c | 120 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/crypto/wp512.c b/crypto/wp512.c index 7ee5a04..8a26965 100644 --- a/crypto/wp512.c +++ b/crypto/wp512.c @@ -779,7 +779,8 @@ static const u64 rc[WHIRLPOOL_ROUNDS] = { * The core Whirlpool transform. */ -static void wp512_process_buffer(struct wp512_ctx *wctx) { +static void wp512_process_buffer(struct wp512_ctx *wctx) +{ int i, r; u64 K[8]; /* the round key */ u64 block[8]; /* mu(buffer) */ @@ -801,78 +802,78 @@ static void wp512_process_buffer(struct wp512_ctx *wctx) { for (r = 0; r < WHIRLPOOL_ROUNDS; r++) { - L[0] = C0[(int)(K[0] >> 56) ] ^ + L[0] = C0[(int)(K[0] >> 56)] ^ C1[(int)(K[7] >> 48) & 0xff] ^ C2[(int)(K[6] >> 40) & 0xff] ^ C3[(int)(K[5] >> 32) & 0xff] ^ C4[(int)(K[4] >> 24) & 0xff] ^ C5[(int)(K[3] >> 16) & 0xff] ^ C6[(int)(K[2] >> 8) & 0xff] ^ - C7[(int)(K[1] ) & 0xff] ^ + C7[(int)(K[1]) & 0xff] ^ rc[r]; - L[1] = C0[(int)(K[1] >> 56) ] ^ + L[1] = C0[(int)(K[1] >> 56)] ^ C1[(int)(K[0] >> 48) & 0xff] ^ C2[(int)(K[7] >> 40) & 0xff] ^ C3[(int)(K[6] >> 32) & 0xff] ^ C4[(int)(K[5] >> 24) & 0xff] ^ C5[(int)(K[4] >> 16) & 0xff] ^ C6[(int)(K[3] >> 8) & 0xff] ^ - C7[(int)(K[2] ) & 0xff]; + C7[(int)(K[2]) & 0xff]; - L[2] = C0[(int)(K[2] >> 56) ] ^ + L[2] = C0[(int)(K[2] >> 56)] ^ C1[(int)(K[1] >> 48) & 0xff] ^ C2[(int)(K[0] >> 40) & 0xff] ^ C3[(int)(K[7] >> 32) & 0xff] ^ C4[(int)(K[6] >> 24) & 0xff] ^ C5[(int)(K[5] >> 16) & 0xff] ^ C6[(int)(K[4] >> 8) & 0xff] ^ - C7[(int)(K[3] ) & 0xff]; + C7[(int)(K[3]) & 0xff]; - L[3] = C0[(int)(K[3] >> 56) ] ^ + L[3] = C0[(int)(K[3] >> 56)] ^ C1[(int)(K[2] >> 48) & 0xff] ^ C2[(int)(K[1] >> 40) & 0xff] ^ C3[(int)(K[0] >> 32) & 0xff] ^ C4[(int)(K[7] >> 24) & 0xff] ^ C5[(int)(K[6] >> 16) & 0xff] ^ C6[(int)(K[5] >> 8) & 0xff] ^ - C7[(int)(K[4] ) & 0xff]; + C7[(int)(K[4]) & 0xff]; - L[4] = C0[(int)(K[4] >> 56) ] ^ + L[4] = C0[(int)(K[4] >> 56)] ^ C1[(int)(K[3] >> 48) & 0xff] ^ C2[(int)(K[2] >> 40) & 0xff] ^ C3[(int)(K[1] >> 32) & 0xff] ^ C4[(int)(K[0] >> 24) & 0xff] ^ C5[(int)(K[7] >> 16) & 0xff] ^ C6[(int)(K[6] >> 8) & 0xff] ^ - C7[(int)(K[5] ) & 0xff]; + C7[(int)(K[5]) & 0xff]; - L[5] = C0[(int)(K[5] >> 56) ] ^ + L[5] = C0[(int)(K[5] >> 56)] ^ C1[(int)(K[4] >> 48) & 0xff] ^ C2[(int)(K[3] >> 40) & 0xff] ^ C3[(int)(K[2] >> 32) & 0xff] ^ C4[(int)(K[1] >> 24) & 0xff] ^ C5[(int)(K[0] >> 16) & 0xff] ^ C6[(int)(K[7] >> 8) & 0xff] ^ - C7[(int)(K[6] ) & 0xff]; + C7[(int)(K[6]) & 0xff]; - L[6] = C0[(int)(K[6] >> 56) ] ^ + L[6] = C0[(int)(K[6] >> 56)] ^ C1[(int)(K[5] >> 48) & 0xff] ^ C2[(int)(K[4] >> 40) & 0xff] ^ C3[(int)(K[3] >> 32) & 0xff] ^ C4[(int)(K[2] >> 24) & 0xff] ^ C5[(int)(K[1] >> 16) & 0xff] ^ C6[(int)(K[0] >> 8) & 0xff] ^ - C7[(int)(K[7] ) & 0xff]; + C7[(int)(K[7]) & 0xff]; - L[7] = C0[(int)(K[7] >> 56) ] ^ + L[7] = C0[(int)(K[7] >> 56)] ^ C1[(int)(K[6] >> 48) & 0xff] ^ C2[(int)(K[5] >> 40) & 0xff] ^ C3[(int)(K[4] >> 32) & 0xff] ^ C4[(int)(K[3] >> 24) & 0xff] ^ C5[(int)(K[2] >> 16) & 0xff] ^ C6[(int)(K[1] >> 8) & 0xff] ^ - C7[(int)(K[0] ) & 0xff]; + C7[(int)(K[0]) & 0xff]; K[0] = L[0]; K[1] = L[1]; @@ -883,84 +884,84 @@ static void wp512_process_buffer(struct wp512_ctx *wctx) { K[6] = L[6]; K[7] = L[7]; - L[0] = C0[(int)(state[0] >> 56) ] ^ + L[0] = C0[(int)(state[0] >> 56)] ^ C1[(int)(state[7] >> 48) & 0xff] ^ C2[(int)(state[6] >> 40) & 0xff] ^ C3[(int)(state[5] >> 32) & 0xff] ^ C4[(int)(state[4] >> 24) & 0xff] ^ C5[(int)(state[3] >> 16) & 0xff] ^ C6[(int)(state[2] >> 8) & 0xff] ^ - C7[(int)(state[1] ) & 0xff] ^ + C7[(int)(state[1]) & 0xff] ^ K[0]; - L[1] = C0[(int)(state[1] >> 56) ] ^ + L[1] = C0[(int)(state[1] >> 56)] ^ C1[(int)(state[0] >> 48) & 0xff] ^ C2[(int)(state[7] >> 40) & 0xff] ^ C3[(int)(state[6] >> 32) & 0xff] ^ C4[(int)(state[5] >> 24) & 0xff] ^ C5[(int)(state[4] >> 16) & 0xff] ^ C6[(int)(state[3] >> 8) & 0xff] ^ - C7[(int)(state[2] ) & 0xff] ^ + C7[(int)(state[2]) & 0xff] ^ K[1]; - L[2] = C0[(int)(state[2] >> 56) ] ^ + L[2] = C0[(int)(state[2] >> 56)] ^ C1[(int)(state[1] >> 48) & 0xff] ^ C2[(int)(state[0] >> 40) & 0xff] ^ C3[(int)(state[7] >> 32) & 0xff] ^ C4[(int)(state[6] >> 24) & 0xff] ^ C5[(int)(state[5] >> 16) & 0xff] ^ C6[(int)(state[4] >> 8) & 0xff] ^ - C7[(int)(state[3] ) & 0xff] ^ + C7[(int)(state[3]) & 0xff] ^ K[2]; - L[3] = C0[(int)(state[3] >> 56) ] ^ + L[3] = C0[(int)(state[3] >> 56)] ^ C1[(int)(state[2] >> 48) & 0xff] ^ C2[(int)(state[1] >> 40) & 0xff] ^ C3[(int)(state[0] >> 32) & 0xff] ^ C4[(int)(state[7] >> 24) & 0xff] ^ C5[(int)(state[6] >> 16) & 0xff] ^ C6[(int)(state[5] >> 8) & 0xff] ^ - C7[(int)(state[4] ) & 0xff] ^ + C7[(int)(state[4]) & 0xff] ^ K[3]; - L[4] = C0[(int)(state[4] >> 56) ] ^ + L[4] = C0[(int)(state[4] >> 56)] ^ C1[(int)(state[3] >> 48) & 0xff] ^ C2[(int)(state[2] >> 40) & 0xff] ^ C3[(int)(state[1] >> 32) & 0xff] ^ C4[(int)(state[0] >> 24) & 0xff] ^ C5[(int)(state[7] >> 16) & 0xff] ^ C6[(int)(state[6] >> 8) & 0xff] ^ - C7[(int)(state[5] ) & 0xff] ^ + C7[(int)(state[5]) & 0xff] ^ K[4]; - L[5] = C0[(int)(state[5] >> 56) ] ^ + L[5] = C0[(int)(state[5] >> 56)] ^ C1[(int)(state[4] >> 48) & 0xff] ^ C2[(int)(state[3] >> 40) & 0xff] ^ C3[(int)(state[2] >> 32) & 0xff] ^ C4[(int)(state[1] >> 24) & 0xff] ^ C5[(int)(state[0] >> 16) & 0xff] ^ C6[(int)(state[7] >> 8) & 0xff] ^ - C7[(int)(state[6] ) & 0xff] ^ + C7[(int)(state[6]) & 0xff] ^ K[5]; - L[6] = C0[(int)(state[6] >> 56) ] ^ + L[6] = C0[(int)(state[6] >> 56)] ^ C1[(int)(state[5] >> 48) & 0xff] ^ C2[(int)(state[4] >> 40) & 0xff] ^ C3[(int)(state[3] >> 32) & 0xff] ^ C4[(int)(state[2] >> 24) & 0xff] ^ C5[(int)(state[1] >> 16) & 0xff] ^ C6[(int)(state[0] >> 8) & 0xff] ^ - C7[(int)(state[7] ) & 0xff] ^ + C7[(int)(state[7]) & 0xff] ^ K[6]; - L[7] = C0[(int)(state[7] >> 56) ] ^ + L[7] = C0[(int)(state[7] >> 56)] ^ C1[(int)(state[6] >> 48) & 0xff] ^ C2[(int)(state[5] >> 40) & 0xff] ^ C3[(int)(state[4] >> 32) & 0xff] ^ C4[(int)(state[3] >> 24) & 0xff] ^ C5[(int)(state[2] >> 16) & 0xff] ^ C6[(int)(state[1] >> 8) & 0xff] ^ - C7[(int)(state[0] ) & 0xff] ^ + C7[(int)(state[0]) & 0xff] ^ K[7]; state[0] = L[0]; @@ -986,17 +987,16 @@ static void wp512_process_buffer(struct wp512_ctx *wctx) { } -static int wp512_init(struct shash_desc *desc) { +static int wp512_init(struct shash_desc *desc) +{ struct wp512_ctx *wctx = shash_desc_ctx(desc); int i; memset(wctx->bitLength, 0, 32); wctx->bufferBits = wctx->bufferPos = 0; wctx->buffer[0] = 0; - for (i = 0; i < 8; i++) { + for (i = 0; i < 8; i++) wctx->hash[i] = 0L; - } - return 0; } @@ -1005,7 +1005,7 @@ static int wp512_update(struct shash_desc *desc, const u8 *source, { struct wp512_ctx *wctx = shash_desc_ctx(desc); int sourcePos = 0; - unsigned int bits_len = len * 8; // convert to number of bits + unsigned int bits_len = len * 8; /* convert to number of bits */ int sourceGap = (8 - ((int)bits_len & 7)) & 7; int bufferRem = wctx->bufferBits & 7; int i; @@ -1014,8 +1014,8 @@ static int wp512_update(struct shash_desc *desc, const u8 *source, u8 *bitLength = wctx->bitLength; int bufferBits = wctx->bufferBits; int bufferPos = wctx->bufferPos; - u64 value = bits_len; + for (i = 31, carry = 0; i >= 0 && (carry != 0 || value != 0ULL); i--) { carry += bitLength[i] + ((u32)value & 0xff); bitLength[i] = (u8)carry; @@ -1066,33 +1066,33 @@ static int wp512_final(struct shash_desc *desc, u8 *out) { struct wp512_ctx *wctx = shash_desc_ctx(desc); int i; - u8 *buffer = wctx->buffer; - u8 *bitLength = wctx->bitLength; - int bufferBits = wctx->bufferBits; - int bufferPos = wctx->bufferPos; + u8 *buffer = wctx->buffer; + u8 *bitLength = wctx->bitLength; + int bufferBits = wctx->bufferBits; + int bufferPos = wctx->bufferPos; __be64 *digest = (__be64 *)out; - buffer[bufferPos] |= 0x80U >> (bufferBits & 7); - bufferPos++; - if (bufferPos > WP512_BLOCK_SIZE - WP512_LENGTHBYTES) { - if (bufferPos < WP512_BLOCK_SIZE) { - memset(&buffer[bufferPos], 0, WP512_BLOCK_SIZE - bufferPos); - } - wp512_process_buffer(wctx); - bufferPos = 0; - } - if (bufferPos < WP512_BLOCK_SIZE - WP512_LENGTHBYTES) { - memset(&buffer[bufferPos], 0, + buffer[bufferPos] |= 0x80U >> (bufferBits & 7); + bufferPos++; + if (bufferPos > WP512_BLOCK_SIZE - WP512_LENGTHBYTES) { + if (bufferPos < WP512_BLOCK_SIZE) + memset(&buffer[bufferPos], 0, + WP512_BLOCK_SIZE - bufferPos); + wp512_process_buffer(wctx); + bufferPos = 0; + } + if (bufferPos < WP512_BLOCK_SIZE - WP512_LENGTHBYTES) { + memset(&buffer[bufferPos], 0, (WP512_BLOCK_SIZE - WP512_LENGTHBYTES) - bufferPos); - } - bufferPos = WP512_BLOCK_SIZE - WP512_LENGTHBYTES; - memcpy(&buffer[WP512_BLOCK_SIZE - WP512_LENGTHBYTES], + } + bufferPos = WP512_BLOCK_SIZE - WP512_LENGTHBYTES; + memcpy(&buffer[WP512_BLOCK_SIZE - WP512_LENGTHBYTES], bitLength, WP512_LENGTHBYTES); - wp512_process_buffer(wctx); + wp512_process_buffer(wctx); for (i = 0; i < WP512_DIGEST_SIZE/8; i++) digest[i] = cpu_to_be64(wctx->hash[i]); - wctx->bufferBits = bufferBits; - wctx->bufferPos = bufferPos; + wctx->bufferBits = bufferBits; + wctx->bufferPos = bufferPos; return 0; }