Commit f80df385 authored by Eric Biggers's avatar Eric Biggers Committed by Herbert Xu
Browse files

ubifs: use crypto_shash_tfm_digest()



Instead of manually allocating a 'struct shash_desc' on the stack and
calling crypto_shash_digest(), switch to using the new helper function
crypto_shash_tfm_digest() which does this for us.

Cc: linux-mtd@lists.infradead.org
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent ea794db2
Loading
Loading
Loading
Loading
+3 −17
Original line number Diff line number Diff line
@@ -31,15 +31,9 @@ int __ubifs_node_calc_hash(const struct ubifs_info *c, const void *node,
			    u8 *hash)
{
	const struct ubifs_ch *ch = node;
	SHASH_DESC_ON_STACK(shash, c->hash_tfm);
	int err;

	shash->tfm = c->hash_tfm;

	err = crypto_shash_digest(shash, node, le32_to_cpu(ch->len), hash);
	if (err < 0)
		return err;
	return 0;
	return crypto_shash_tfm_digest(c->hash_tfm, node, le32_to_cpu(ch->len),
				       hash);
}

/**
@@ -53,15 +47,7 @@ int __ubifs_node_calc_hash(const struct ubifs_info *c, const void *node,
static int ubifs_hash_calc_hmac(const struct ubifs_info *c, const u8 *hash,
				 u8 *hmac)
{
	SHASH_DESC_ON_STACK(shash, c->hmac_tfm);
	int err;

	shash->tfm = c->hmac_tfm;

	err = crypto_shash_digest(shash, hash, c->hash_len, hmac);
	if (err < 0)
		return err;
	return 0;
	return crypto_shash_tfm_digest(c->hmac_tfm, hash, c->hash_len, hmac);
}

/**
+3 −6
Original line number Diff line number Diff line
@@ -68,12 +68,9 @@ static int mst_node_check_hash(const struct ubifs_info *c,
	u8 calc[UBIFS_MAX_HASH_LEN];
	const void *node = mst;

	SHASH_DESC_ON_STACK(shash, c->hash_tfm);

	shash->tfm = c->hash_tfm;

	crypto_shash_digest(shash, node + sizeof(struct ubifs_ch),
			    UBIFS_MST_NODE_SZ - sizeof(struct ubifs_ch), calc);
	crypto_shash_tfm_digest(c->hash_tfm, node + sizeof(struct ubifs_ch),
				UBIFS_MST_NODE_SZ - sizeof(struct ubifs_ch),
				calc);

	if (ubifs_check_hash(c, expected, calc))
		return -EPERM;
+3 −11
Original line number Diff line number Diff line
@@ -558,7 +558,7 @@ static int is_last_bud(struct ubifs_info *c, struct ubifs_bud *bud)
	return data == 0xFFFFFFFF;
}

/* authenticate_sleb_hash and authenticate_sleb_hmac are split out for stack usage */
/* authenticate_sleb_hash is split out for stack usage */
static int authenticate_sleb_hash(struct ubifs_info *c, struct shash_desc *log_hash, u8 *hash)
{
	SHASH_DESC_ON_STACK(hash_desc, c->hash_tfm);
@@ -569,15 +569,6 @@ static int authenticate_sleb_hash(struct ubifs_info *c, struct shash_desc *log_h
	return crypto_shash_final(hash_desc, hash);
}

static int authenticate_sleb_hmac(struct ubifs_info *c, u8 *hash, u8 *hmac)
{
	SHASH_DESC_ON_STACK(hmac_desc, c->hmac_tfm);

	hmac_desc->tfm = c->hmac_tfm;

	return crypto_shash_digest(hmac_desc, hash, c->hash_len, hmac);
}

/**
 * authenticate_sleb - authenticate one scan LEB
 * @c: UBIFS file-system description object
@@ -624,7 +615,8 @@ static int authenticate_sleb(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
			if (err)
				goto out;

			err = authenticate_sleb_hmac(c, hash, hmac);
			err = crypto_shash_tfm_digest(c->hmac_tfm, hash,
						      c->hash_len, hmac);
			if (err)
				goto out;