Skip to content

Commit 206ce59

Browse files
committed
KEYS: Move the algorithm pointer array from x509 to public_key.c
Move the public-key algorithm pointer array from x509_public_key.c to public_key.c as it isn't X.509 specific. Note that to make this configure correctly, the public key part must be dependent on the RSA module rather than the other way round. This needs a further patch to make use of the crypto module loading stuff rather than using a fixed table. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: Josh Boyer <jwboyer@redhat.com>
1 parent 9abc4e6 commit 206ce59

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎crypto/asymmetric_keys/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ if ASYMMETRIC_KEY_TYPE
1212
config ASYMMETRIC_PUBLIC_KEY_SUBTYPE
1313
tristate "Asymmetric public-key crypto algorithm subtype"
1414
select MPILIB
15+
select PUBLIC_KEY_ALGO_RSA
1516
help
1617
This option provides support for asymmetric public key type handling.
1718
If signature generation and/or verification are to be used,
@@ -20,7 +21,6 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE
2021

2122
config PUBLIC_KEY_ALGO_RSA
2223
tristate "RSA public-key algorithm"
23-
depends on ASYMMETRIC_PUBLIC_KEY_SUBTYPE
2424
select MPILIB_EXTRA
2525
help
2626
This option enables support for the RSA algorithm (PKCS#1, RFC3447).

‎crypto/asymmetric_keys/public_key.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ const char *const pkey_algo_name[PKEY_ALGO__LAST] = {
2828
};
2929
EXPORT_SYMBOL_GPL(pkey_algo_name);
3030

31+
const struct public_key_algorithm *pkey_algo[PKEY_ALGO__LAST] = {
32+
#if defined(CONFIG_PUBLIC_KEY_ALGO_RSA) || \
33+
defined(CONFIG_PUBLIC_KEY_ALGO_RSA_MODULE)
34+
[PKEY_ALGO_RSA] = &RSA_public_key_algorithm,
35+
#endif
36+
};
37+
EXPORT_SYMBOL_GPL(pkey_algo);
38+
3139
const char *const pkey_hash_algo_name[PKEY_HASH__LAST] = {
3240
[PKEY_HASH_MD4] = "md4",
3341
[PKEY_HASH_MD5] = "md5",

‎crypto/asymmetric_keys/x509_public_key.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@
2323
#include "public_key.h"
2424
#include "x509_parser.h"
2525

26-
static const
27-
struct public_key_algorithm *x509_public_key_algorithms[PKEY_ALGO__LAST] = {
28-
[PKEY_ALGO_DSA] = NULL,
29-
#if defined(CONFIG_PUBLIC_KEY_ALGO_RSA) || \
30-
defined(CONFIG_PUBLIC_KEY_ALGO_RSA_MODULE)
31-
[PKEY_ALGO_RSA] = &RSA_public_key_algorithm,
32-
#endif
33-
};
34-
3526
/*
3627
* Check the signature on a certificate using the provided public key
3728
*/
@@ -174,7 +165,7 @@ static int x509_key_preparse(struct key_preparsed_payload *prep)
174165
goto error_free_cert;
175166
}
176167

177-
cert->pub->algo = x509_public_key_algorithms[cert->pkey_algo];
168+
cert->pub->algo = pkey_algo[cert->pkey_algo];
178169
cert->pub->id_type = PKEY_ID_X509;
179170

180171
/* Check the signature on the key */

‎include/crypto/public_key.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ enum pkey_algo {
2323
};
2424

2525
extern const char *const pkey_algo_name[PKEY_ALGO__LAST];
26+
extern const struct public_key_algorithm *pkey_algo[PKEY_ALGO__LAST];
2627

2728
enum pkey_hash_algo {
2829
PKEY_HASH_MD4,

0 commit comments

Comments
 (0)