From patchwork Tue Dec 15 23:47:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 11976021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2D35C2BBCA for ; Tue, 15 Dec 2020 23:55:10 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 98B0922283 for ; Tue, 15 Dec 2020 23:55:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98B0922283 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Yz84+KQalJkcQY9fTqRyr9QAfFlF33VhYLo1+ypTShY=; b=theyvo0NkjS78Z6lbRMoV4zYN 0bH6q8y+Hf4jmWQn6UkBHF6XJpUYtBDGvdPjh9CTa+GuOHbVr6bKeEaO3VN9m790LZ9PXqPutDISr RnJwA9vpIVma4C0QZxXI/hGP3rMDuRwuynFvHpekRfTUZfAIssKtiOTv41ChWsmua1FsqRi7TmnYu YWNijG2ADX09nicMRuir7pE6zr6tVJlahozIURcoE0rVkwkm2/KMu8LixKyrbo/XaeT2SH9v8PnaQ 9tkq86OQLW1ICTTedZLGO/gCzqG7+mBswRg+NzEzONIG2V9eObky0A11FYZZJcuGGBy3s9KY5vxmz YUKp/FKhw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kpK8j-00027J-0U; Tue, 15 Dec 2020 23:53:57 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kpK8d-000257-L7 for linux-arm-kernel@lists.infradead.org; Tue, 15 Dec 2020 23:53:52 +0000 From: Eric Biggers Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-crypto@vger.kernel.org Subject: [PATCH 1/5] crypto: blake2b - rename constants for consistency with blake2s Date: Tue, 15 Dec 2020 15:47:04 -0800 Message-Id: <20201215234708.105527-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201215234708.105527-1-ebiggers@kernel.org> References: <20201215234708.105527-1-ebiggers@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201215_185351_878263_D3BA08D6 X-CRM114-Status: GOOD ( 13.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason A . Donenfeld" , Herbert Xu , David Sterba , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Paul Crowley Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Eric Biggers Rename some BLAKE2b-related constants to be consistent with the names used in the BLAKE2s implementation (see include/crypto/blake2s.h): BLAKE2B_*_DIGEST_SIZE => BLAKE2B_*_HASH_SIZE BLAKE2B_BLOCKBYTES => BLAKE2B_BLOCK_SIZE BLAKE2B_KEYBYTES => BLAKE2B_KEY_SIZE Signed-off-by: Eric Biggers Reviewed-by: David Sterba --- crypto/blake2b_generic.c | 58 +++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/crypto/blake2b_generic.c b/crypto/blake2b_generic.c index a2ffe60e06d34..83942f511075e 100644 --- a/crypto/blake2b_generic.c +++ b/crypto/blake2b_generic.c @@ -25,21 +25,22 @@ #include #include -#define BLAKE2B_160_DIGEST_SIZE (160 / 8) -#define BLAKE2B_256_DIGEST_SIZE (256 / 8) -#define BLAKE2B_384_DIGEST_SIZE (384 / 8) -#define BLAKE2B_512_DIGEST_SIZE (512 / 8) - -enum blake2b_constant { - BLAKE2B_BLOCKBYTES = 128, - BLAKE2B_KEYBYTES = 64, + +enum blake2b_lengths { + BLAKE2B_BLOCK_SIZE = 128, + BLAKE2B_KEY_SIZE = 64, + + BLAKE2B_160_HASH_SIZE = 20, + BLAKE2B_256_HASH_SIZE = 32, + BLAKE2B_384_HASH_SIZE = 48, + BLAKE2B_512_HASH_SIZE = 64, }; struct blake2b_state { u64 h[8]; u64 t[2]; u64 f[2]; - u8 buf[BLAKE2B_BLOCKBYTES]; + u8 buf[BLAKE2B_BLOCK_SIZE]; size_t buflen; }; @@ -96,7 +97,7 @@ static void blake2b_increment_counter(struct blake2b_state *S, const u64 inc) } while (0) static void blake2b_compress(struct blake2b_state *S, - const u8 block[BLAKE2B_BLOCKBYTES]) + const u8 block[BLAKE2B_BLOCK_SIZE]) { u64 m[16]; u64 v[16]; @@ -140,7 +141,7 @@ static void blake2b_compress(struct blake2b_state *S, #undef ROUND struct blake2b_tfm_ctx { - u8 key[BLAKE2B_KEYBYTES]; + u8 key[BLAKE2B_KEY_SIZE]; unsigned int keylen; }; @@ -149,7 +150,7 @@ static int blake2b_setkey(struct crypto_shash *tfm, const u8 *key, { struct blake2b_tfm_ctx *tctx = crypto_shash_ctx(tfm); - if (keylen == 0 || keylen > BLAKE2B_KEYBYTES) + if (keylen == 0 || keylen > BLAKE2B_KEY_SIZE) return -EINVAL; memcpy(tctx->key, key, keylen); @@ -176,7 +177,7 @@ static int blake2b_init(struct shash_desc *desc) * _final will process it */ memcpy(state->buf, tctx->key, tctx->keylen); - state->buflen = BLAKE2B_BLOCKBYTES; + state->buflen = BLAKE2B_BLOCK_SIZE; } return 0; } @@ -186,7 +187,7 @@ static int blake2b_update(struct shash_desc *desc, const u8 *in, { struct blake2b_state *state = shash_desc_ctx(desc); const size_t left = state->buflen; - const size_t fill = BLAKE2B_BLOCKBYTES - left; + const size_t fill = BLAKE2B_BLOCK_SIZE - left; if (!inlen) return 0; @@ -195,16 +196,16 @@ static int blake2b_update(struct shash_desc *desc, const u8 *in, state->buflen = 0; /* Fill buffer */ memcpy(state->buf + left, in, fill); - blake2b_increment_counter(state, BLAKE2B_BLOCKBYTES); + blake2b_increment_counter(state, BLAKE2B_BLOCK_SIZE); /* Compress */ blake2b_compress(state, state->buf); in += fill; inlen -= fill; - while (inlen > BLAKE2B_BLOCKBYTES) { - blake2b_increment_counter(state, BLAKE2B_BLOCKBYTES); + while (inlen > BLAKE2B_BLOCK_SIZE) { + blake2b_increment_counter(state, BLAKE2B_BLOCK_SIZE); blake2b_compress(state, in); - in += BLAKE2B_BLOCKBYTES; - inlen -= BLAKE2B_BLOCKBYTES; + in += BLAKE2B_BLOCK_SIZE; + inlen -= BLAKE2B_BLOCK_SIZE; } } memcpy(state->buf + state->buflen, in, inlen); @@ -223,7 +224,8 @@ static int blake2b_final(struct shash_desc *desc, u8 *out) /* Set last block */ state->f[0] = (u64)-1; /* Padding */ - memset(state->buf + state->buflen, 0, BLAKE2B_BLOCKBYTES - state->buflen); + memset(state->buf + state->buflen, 0, + BLAKE2B_BLOCK_SIZE - state->buflen); blake2b_compress(state, state->buf); /* Avoid temporary buffer and switch the internal output to LE order */ @@ -240,10 +242,10 @@ static struct shash_alg blake2b_algs[] = { .base.cra_driver_name = "blake2b-160-generic", .base.cra_priority = 100, .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, - .base.cra_blocksize = BLAKE2B_BLOCKBYTES, + .base.cra_blocksize = BLAKE2B_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct blake2b_tfm_ctx), .base.cra_module = THIS_MODULE, - .digestsize = BLAKE2B_160_DIGEST_SIZE, + .digestsize = BLAKE2B_160_HASH_SIZE, .setkey = blake2b_setkey, .init = blake2b_init, .update = blake2b_update, @@ -254,10 +256,10 @@ static struct shash_alg blake2b_algs[] = { .base.cra_driver_name = "blake2b-256-generic", .base.cra_priority = 100, .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, - .base.cra_blocksize = BLAKE2B_BLOCKBYTES, + .base.cra_blocksize = BLAKE2B_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct blake2b_tfm_ctx), .base.cra_module = THIS_MODULE, - .digestsize = BLAKE2B_256_DIGEST_SIZE, + .digestsize = BLAKE2B_256_HASH_SIZE, .setkey = blake2b_setkey, .init = blake2b_init, .update = blake2b_update, @@ -268,10 +270,10 @@ static struct shash_alg blake2b_algs[] = { .base.cra_driver_name = "blake2b-384-generic", .base.cra_priority = 100, .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, - .base.cra_blocksize = BLAKE2B_BLOCKBYTES, + .base.cra_blocksize = BLAKE2B_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct blake2b_tfm_ctx), .base.cra_module = THIS_MODULE, - .digestsize = BLAKE2B_384_DIGEST_SIZE, + .digestsize = BLAKE2B_384_HASH_SIZE, .setkey = blake2b_setkey, .init = blake2b_init, .update = blake2b_update, @@ -282,10 +284,10 @@ static struct shash_alg blake2b_algs[] = { .base.cra_driver_name = "blake2b-512-generic", .base.cra_priority = 100, .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, - .base.cra_blocksize = BLAKE2B_BLOCKBYTES, + .base.cra_blocksize = BLAKE2B_BLOCK_SIZE, .base.cra_ctxsize = sizeof(struct blake2b_tfm_ctx), .base.cra_module = THIS_MODULE, - .digestsize = BLAKE2B_512_DIGEST_SIZE, + .digestsize = BLAKE2B_512_HASH_SIZE, .setkey = blake2b_setkey, .init = blake2b_init, .update = blake2b_update,