From: David Sterba <dsterba@suse.com>
To: linux-crypto@vger.kernel.org
Cc: ebiggers@kernel.org, David Sterba <dsterba@suse.com>
Subject: [PATCH 3/7] crypto: blake2b: simplify key init
Date: Wed, 6 Nov 2019 14:48:27 +0100 [thread overview]
Message-ID: <15b9fcb26351a1bb3242ce0c4819391f38545648.1573047517.git.dsterba@suse.com> (raw)
In-Reply-To: <cover.1573047517.git.dsterba@suse.com>
The keyed init writes the key bytes to the input buffer and does an
update. We can do that in two ways: fill the buffer and update
immediatelly. This is what current blake2b_init_key does. Any other
following _update or _final will continue from the updated state.
The other way is to write the key and set the number of bytes to process
at the next _update or _final, lazy evaluation. Which leads to the the
simplified code in this patch.
Signed-off-by: David Sterba <dsterba@suse.com>
---
crypto/blake2b_generic.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/crypto/blake2b_generic.c b/crypto/blake2b_generic.c
index d3da6113a96a..fd0fbb076058 100644
--- a/crypto/blake2b_generic.c
+++ b/crypto/blake2b_generic.c
@@ -85,8 +85,6 @@ static const u8 blake2b_sigma[12][16] = {
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }
};
-static void blake2b_update(struct blake2b_state *S, const void *pin, size_t inlen);
-
static void blake2b_set_lastnode(struct blake2b_state *S)
{
S->f[1] = (u64)-1;
@@ -235,12 +233,12 @@ static int blake2b_init(struct shash_desc *desc)
state->h[0] ^= 0x01010000 | mctx->keylen << 8 | digestsize;
if (mctx->keylen) {
- u8 block[BLAKE2B_BLOCKBYTES];
-
- memset(block, 0, BLAKE2B_BLOCKBYTES);
- memcpy(block, mctx->key, mctx->keylen);
- blake2b_update(state, block, BLAKE2B_BLOCKBYTES);
- memzero_explicit(block, BLAKE2B_BLOCKBYTES);
+ /*
+ * Prefill the buffer with the key, next call to _update or
+ * _final will process it
+ */
+ memcpy(state->buf, mctx->key, mctx->keylen);
+ state->buflen = BLAKE2B_BLOCKBYTES;
}
return 0;
}
--
2.23.0
next prev parent reply other threads:[~2019-11-06 13:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-06 13:48 [PATCH 0/7] BLAKE2b cleanups David Sterba
2019-11-06 13:48 ` [PATCH 1/7] crypto: blake2b: merge _final implementation to callback David Sterba
2019-11-06 13:48 ` [PATCH 2/7] crypto: blake2b: merge blake2 init to api callback David Sterba
2019-11-06 13:48 ` David Sterba [this message]
2019-11-06 13:48 ` [PATCH 4/7] crypto: blake2b: delete unused structs or members David Sterba
2019-11-06 13:48 ` [PATCH 5/7] crypto: blake2b: open code set last block helper David Sterba
2019-11-06 13:48 ` [PATCH 6/7] crypto: blake2b: merge _update to api callback David Sterba
2019-11-06 13:48 ` [PATCH 7/7] crypto: blake2b: rename tfm context David Sterba
2019-11-08 2:13 ` [PATCH 0/7] BLAKE2b cleanups Eric Biggers
2019-11-09 23:05 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=15b9fcb26351a1bb3242ce0c4819391f38545648.1573047517.git.dsterba@suse.com \
--to=dsterba@suse.com \
--cc=ebiggers@kernel.org \
--cc=linux-crypto@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).