Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f03f8096 authored by David Sterba's avatar David Sterba Committed by Alistair Delva
Browse files

UPSTREAM: crypto: blake2b - simplify key init



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: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>

(cherry picked from commit e87e484d60b0da8302b45f27fe32af1cea02c8d2)
Bug: 178411248
Change-Id: I90652bb41d252af9503d5976ce32b93e2610debf
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
parent fdb0b246
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -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;
}