diff options
author | David Howells <dhowells@redhat.com> | 2013-08-30 11:15:30 -0400 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2013-09-25 12:17:00 -0400 |
commit | 3d167d68e3805ee45ed2e8412fc03ed919c54c24 (patch) | |
tree | baa5b411cb71f72ee855883d5a3fefbaf142f23b /crypto | |
parent | 67f7d60b3a08a3e3ec51c29c25767a9d9d0bd2b1 (diff) |
KEYS: Split public_key_verify_signature() and make available
Modify public_key_verify_signature() so that it now takes a public_key struct
rather than a key struct and supply a wrapper that takes a key struct. The
wrapper is then used by the asymmetric key subtype and the modified function is
used by X.509 self-signature checking and can be used by other things also.
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Josh Boyer <jwboyer@redhat.com>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/asymmetric_keys/public_key.c | 40 | ||||
-rw-r--r-- | crypto/asymmetric_keys/public_key.h | 6 | ||||
-rw-r--r-- | crypto/asymmetric_keys/x509_public_key.c | 2 |
3 files changed, 39 insertions, 9 deletions
diff --git a/crypto/asymmetric_keys/public_key.c b/crypto/asymmetric_keys/public_key.c index 796ce0802aa0..49ac8d848ed1 100644 --- a/crypto/asymmetric_keys/public_key.c +++ b/crypto/asymmetric_keys/public_key.c | |||
@@ -86,21 +86,45 @@ EXPORT_SYMBOL_GPL(public_key_destroy); | |||
86 | /* | 86 | /* |
87 | * Verify a signature using a public key. | 87 | * Verify a signature using a public key. |
88 | */ | 88 | */ |
89 | static int public_key_verify_signature(const struct key *key, | 89 | int public_key_verify_signature(const struct public_key *pk, |
90 | const struct public_key_signature *sig) | 90 | const struct public_key_signature *sig) |
91 | { | 91 | { |
92 | const struct public_key *pk = key->payload.data; | 92 | const struct public_key_algorithm *algo; |
93 | |||
94 | BUG_ON(!pk); | ||
95 | BUG_ON(!pk->mpi[0]); | ||
96 | BUG_ON(!pk->mpi[1]); | ||
97 | BUG_ON(!sig); | ||
98 | BUG_ON(!sig->digest); | ||
99 | BUG_ON(!sig->mpi[0]); | ||
100 | |||
101 | algo = pk->algo; | ||
102 | if (!algo) { | ||
103 | if (pk->pkey_algo >= PKEY_ALGO__LAST) | ||
104 | return -ENOPKG; | ||
105 | algo = pkey_algo[pk->pkey_algo]; | ||
106 | if (!algo) | ||
107 | return -ENOPKG; | ||
108 | } | ||
93 | 109 | ||
94 | if (!pk->algo->verify_signature) | 110 | if (!algo->verify_signature) |
95 | return -ENOTSUPP; | 111 | return -ENOTSUPP; |
96 | 112 | ||
97 | if (sig->nr_mpi != pk->algo->n_sig_mpi) { | 113 | if (sig->nr_mpi != algo->n_sig_mpi) { |
98 | pr_debug("Signature has %u MPI not %u\n", | 114 | pr_debug("Signature has %u MPI not %u\n", |
99 | sig->nr_mpi, pk->algo->n_sig_mpi); | 115 | sig->nr_mpi, algo->n_sig_mpi); |
100 | return -EINVAL; | 116 | return -EINVAL; |
101 | } | 117 | } |
102 | 118 | ||
103 | return pk->algo->verify_signature(pk, sig); | 119 | return algo->verify_signature(pk, sig); |
120 | } | ||
121 | EXPORT_SYMBOL_GPL(public_key_verify_signature); | ||
122 | |||
123 | static int public_key_verify_signature_2(const struct key *key, | ||
124 | const struct public_key_signature *sig) | ||
125 | { | ||
126 | const struct public_key *pk = key->payload.data; | ||
127 | return public_key_verify_signature(pk, sig); | ||
104 | } | 128 | } |
105 | 129 | ||
106 | /* | 130 | /* |
@@ -111,6 +135,6 @@ struct asymmetric_key_subtype public_key_subtype = { | |||
111 | .name = "public_key", | 135 | .name = "public_key", |
112 | .describe = public_key_describe, | 136 | .describe = public_key_describe, |
113 | .destroy = public_key_destroy, | 137 | .destroy = public_key_destroy, |
114 | .verify_signature = public_key_verify_signature, | 138 | .verify_signature = public_key_verify_signature_2, |
115 | }; | 139 | }; |
116 | EXPORT_SYMBOL_GPL(public_key_subtype); | 140 | EXPORT_SYMBOL_GPL(public_key_subtype); |
diff --git a/crypto/asymmetric_keys/public_key.h b/crypto/asymmetric_keys/public_key.h index 5e5e35626899..5c37a22a0637 100644 --- a/crypto/asymmetric_keys/public_key.h +++ b/crypto/asymmetric_keys/public_key.h | |||
@@ -28,3 +28,9 @@ struct public_key_algorithm { | |||
28 | }; | 28 | }; |
29 | 29 | ||
30 | extern const struct public_key_algorithm RSA_public_key_algorithm; | 30 | extern const struct public_key_algorithm RSA_public_key_algorithm; |
31 | |||
32 | /* | ||
33 | * public_key.c | ||
34 | */ | ||
35 | extern int public_key_verify_signature(const struct public_key *pk, | ||
36 | const struct public_key_signature *sig); | ||
diff --git a/crypto/asymmetric_keys/x509_public_key.c b/crypto/asymmetric_keys/x509_public_key.c index fac574c457b3..8cb2f7075479 100644 --- a/crypto/asymmetric_keys/x509_public_key.c +++ b/crypto/asymmetric_keys/x509_public_key.c | |||
@@ -76,7 +76,7 @@ static int x509_check_signature(const struct public_key *pub, | |||
76 | if (ret < 0) | 76 | if (ret < 0) |
77 | goto error_mpi; | 77 | goto error_mpi; |
78 | 78 | ||
79 | ret = pub->algo->verify_signature(pub, sig); | 79 | ret = public_key_verify_signature(pub, sig); |
80 | 80 | ||
81 | pr_debug("Cert Verification: %d\n", ret); | 81 | pr_debug("Cert Verification: %d\n", ret); |
82 | 82 | ||