crypto: KEYS: convert public key and digsig asym to the akcipher api
This patch converts the module verification code to the new akcipher API. Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com> Acked-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David Howells <dhowells@redhat.com>
This commit is contained in:

committed by
David Howells

parent
50d35015ff
commit
db6c43bd21
@@ -18,24 +18,16 @@
|
||||
#include <linux/slab.h>
|
||||
#include <linux/seq_file.h>
|
||||
#include <keys/asymmetric-subtype.h>
|
||||
#include "public_key.h"
|
||||
#include <crypto/public_key.h>
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
const char *const pkey_algo_name[PKEY_ALGO__LAST] = {
|
||||
[PKEY_ALGO_DSA] = "DSA",
|
||||
[PKEY_ALGO_RSA] = "RSA",
|
||||
[PKEY_ALGO_DSA] = "dsa",
|
||||
[PKEY_ALGO_RSA] = "rsa",
|
||||
};
|
||||
EXPORT_SYMBOL_GPL(pkey_algo_name);
|
||||
|
||||
const struct public_key_algorithm *pkey_algo[PKEY_ALGO__LAST] = {
|
||||
#if defined(CONFIG_PUBLIC_KEY_ALGO_RSA) || \
|
||||
defined(CONFIG_PUBLIC_KEY_ALGO_RSA_MODULE)
|
||||
[PKEY_ALGO_RSA] = &RSA_public_key_algorithm,
|
||||
#endif
|
||||
};
|
||||
EXPORT_SYMBOL_GPL(pkey_algo);
|
||||
|
||||
const char *const pkey_id_type_name[PKEY_ID_TYPE__LAST] = {
|
||||
[PKEY_ID_PGP] = "PGP",
|
||||
[PKEY_ID_X509] = "X509",
|
||||
@@ -43,6 +35,12 @@ const char *const pkey_id_type_name[PKEY_ID_TYPE__LAST] = {
|
||||
};
|
||||
EXPORT_SYMBOL_GPL(pkey_id_type_name);
|
||||
|
||||
static int (*alg_verify[PKEY_ALGO__LAST])(const struct public_key *pkey,
|
||||
const struct public_key_signature *sig) = {
|
||||
NULL,
|
||||
rsa_verify_signature
|
||||
};
|
||||
|
||||
/*
|
||||
* Provide a part of a description of the key for /proc/keys.
|
||||
*/
|
||||
@@ -53,7 +51,8 @@ static void public_key_describe(const struct key *asymmetric_key,
|
||||
|
||||
if (key)
|
||||
seq_printf(m, "%s.%s",
|
||||
pkey_id_type_name[key->id_type], key->algo->name);
|
||||
pkey_id_type_name[key->id_type],
|
||||
pkey_algo_name[key->pkey_algo]);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -62,50 +61,31 @@ static void public_key_describe(const struct key *asymmetric_key,
|
||||
void public_key_destroy(void *payload)
|
||||
{
|
||||
struct public_key *key = payload;
|
||||
int i;
|
||||
|
||||
if (key) {
|
||||
for (i = 0; i < ARRAY_SIZE(key->mpi); i++)
|
||||
mpi_free(key->mpi[i]);
|
||||
kfree(key);
|
||||
}
|
||||
if (key)
|
||||
kfree(key->key);
|
||||
kfree(key);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(public_key_destroy);
|
||||
|
||||
/*
|
||||
* Verify a signature using a public key.
|
||||
*/
|
||||
int public_key_verify_signature(const struct public_key *pk,
|
||||
int public_key_verify_signature(const struct public_key *pkey,
|
||||
const struct public_key_signature *sig)
|
||||
{
|
||||
const struct public_key_algorithm *algo;
|
||||
|
||||
BUG_ON(!pk);
|
||||
BUG_ON(!pk->mpi[0]);
|
||||
BUG_ON(!pk->mpi[1]);
|
||||
BUG_ON(!pkey);
|
||||
BUG_ON(!sig);
|
||||
BUG_ON(!sig->digest);
|
||||
BUG_ON(!sig->mpi[0]);
|
||||
BUG_ON(!sig->s);
|
||||
|
||||
algo = pk->algo;
|
||||
if (!algo) {
|
||||
if (pk->pkey_algo >= PKEY_ALGO__LAST)
|
||||
return -ENOPKG;
|
||||
algo = pkey_algo[pk->pkey_algo];
|
||||
if (!algo)
|
||||
return -ENOPKG;
|
||||
}
|
||||
if (pkey->pkey_algo >= PKEY_ALGO__LAST)
|
||||
return -ENOPKG;
|
||||
|
||||
if (!algo->verify_signature)
|
||||
return -ENOTSUPP;
|
||||
if (!alg_verify[pkey->pkey_algo])
|
||||
return -ENOPKG;
|
||||
|
||||
if (sig->nr_mpi != algo->n_sig_mpi) {
|
||||
pr_debug("Signature has %u MPI not %u\n",
|
||||
sig->nr_mpi, algo->n_sig_mpi);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return algo->verify_signature(pk, sig);
|
||||
return alg_verify[pkey->pkey_algo](pkey, sig);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(public_key_verify_signature);
|
||||
|
||||
|
Reference in New Issue
Block a user