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

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

crypto: hash - annotate algorithms taking optional key



We need to consistently enforce that keyed hashes cannot be used without
setting the key.  To do this we need a reliable way to determine whether
a given hash algorithm is keyed or not.  AF_ALG currently does this by
checking for the presence of a ->setkey() method.  However, this is
actually slightly broken because the CRC-32 algorithms implement
->setkey() but can also be used without a key.  (The CRC-32 "key" is not
actually a cryptographic key but rather represents the initial state.
If not overridden, then a default initial state is used.)

Prepare to fix this by introducing a flag CRYPTO_ALG_OPTIONAL_KEY which
indicates that the algorithm has a ->setkey() method, but it is not
required to be called.  Then set it on all the CRC-32 algorithms.

The same also applies to the Adler-32 implementation in Lustre.

Also, the cryptd and mcryptd templates have to pass through the flag
from their underlying algorithm.

Cc: stable@vger.kernel.org
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent a16e772e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -188,6 +188,7 @@ static struct shash_alg crc32_pmull_algs[] = { {
	.base.cra_name		= "crc32",
	.base.cra_driver_name	= "crc32-arm-ce",
	.base.cra_priority	= 200,
	.base.cra_flags		= CRYPTO_ALG_OPTIONAL_KEY,
	.base.cra_blocksize	= 1,
	.base.cra_module	= THIS_MODULE,
}, {
@@ -203,6 +204,7 @@ static struct shash_alg crc32_pmull_algs[] = { {
	.base.cra_name		= "crc32c",
	.base.cra_driver_name	= "crc32c-arm-ce",
	.base.cra_priority	= 200,
	.base.cra_flags		= CRYPTO_ALG_OPTIONAL_KEY,
	.base.cra_blocksize	= 1,
	.base.cra_module	= THIS_MODULE,
} };
+2 −0
Original line number Diff line number Diff line
@@ -185,6 +185,7 @@ static struct shash_alg crc32_pmull_algs[] = { {
	.base.cra_name		= "crc32",
	.base.cra_driver_name	= "crc32-arm64-ce",
	.base.cra_priority	= 200,
	.base.cra_flags		= CRYPTO_ALG_OPTIONAL_KEY,
	.base.cra_blocksize	= 1,
	.base.cra_module	= THIS_MODULE,
}, {
@@ -200,6 +201,7 @@ static struct shash_alg crc32_pmull_algs[] = { {
	.base.cra_name		= "crc32c",
	.base.cra_driver_name	= "crc32c-arm64-ce",
	.base.cra_priority	= 200,
	.base.cra_flags		= CRYPTO_ALG_OPTIONAL_KEY,
	.base.cra_blocksize	= 1,
	.base.cra_module	= THIS_MODULE,
} };
+1 −0
Original line number Diff line number Diff line
@@ -141,6 +141,7 @@ static struct shash_alg alg = {
		.cra_name		= "crc32c",
		.cra_driver_name	= "crc32c-vpmsum",
		.cra_priority		= 200,
		.cra_flags		= CRYPTO_ALG_OPTIONAL_KEY,
		.cra_blocksize		= CHKSUM_BLOCK_SIZE,
		.cra_ctxsize		= sizeof(u32),
		.cra_module		= THIS_MODULE,
+3 −0
Original line number Diff line number Diff line
@@ -239,6 +239,7 @@ static struct shash_alg crc32_vx_algs[] = {
			.cra_name	 = "crc32",
			.cra_driver_name = "crc32-vx",
			.cra_priority	 = 200,
			.cra_flags	 = CRYPTO_ALG_OPTIONAL_KEY,
			.cra_blocksize	 = CRC32_BLOCK_SIZE,
			.cra_ctxsize	 = sizeof(struct crc_ctx),
			.cra_module	 = THIS_MODULE,
@@ -259,6 +260,7 @@ static struct shash_alg crc32_vx_algs[] = {
			.cra_name	 = "crc32be",
			.cra_driver_name = "crc32be-vx",
			.cra_priority	 = 200,
			.cra_flags	 = CRYPTO_ALG_OPTIONAL_KEY,
			.cra_blocksize	 = CRC32_BLOCK_SIZE,
			.cra_ctxsize	 = sizeof(struct crc_ctx),
			.cra_module	 = THIS_MODULE,
@@ -279,6 +281,7 @@ static struct shash_alg crc32_vx_algs[] = {
			.cra_name	 = "crc32c",
			.cra_driver_name = "crc32c-vx",
			.cra_priority	 = 200,
			.cra_flags	 = CRYPTO_ALG_OPTIONAL_KEY,
			.cra_blocksize	 = CRC32_BLOCK_SIZE,
			.cra_ctxsize	 = sizeof(struct crc_ctx),
			.cra_module	 = THIS_MODULE,
+1 −0
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ static struct shash_alg alg = {
		.cra_name		=	"crc32c",
		.cra_driver_name	=	"crc32c-sparc64",
		.cra_priority		=	SPARC_CR_OPCODE_PRIORITY,
		.cra_flags		=	CRYPTO_ALG_OPTIONAL_KEY,
		.cra_blocksize		=	CHKSUM_BLOCK_SIZE,
		.cra_ctxsize		=	sizeof(u32),
		.cra_alignmask		=	7,
Loading