Skip to content

Commit db6c43b

Browse files
tstrukdhowells
authored andcommitted
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 <[email protected]> Acked-by: Herbert Xu <[email protected]> Signed-off-by: David Howells <[email protected]>
1 parent 50d3501 commit db6c43b

File tree

12 files changed

+134
-295
lines changed

12 files changed

+134
-295
lines changed

crypto/asymmetric_keys/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE
2222

2323
config PUBLIC_KEY_ALGO_RSA
2424
tristate "RSA public-key algorithm"
25-
select MPILIB
25+
select CRYPTO_RSA
2626
help
2727
This option enables support for the RSA algorithm (PKCS#1, RFC3447).
2828

crypto/asymmetric_keys/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,18 @@ obj-$(CONFIG_X509_CERTIFICATE_PARSER) += x509_key_parser.o
1616
x509_key_parser-y := \
1717
x509-asn1.o \
1818
x509_akid-asn1.o \
19-
x509_rsakey-asn1.o \
2019
x509_cert_parser.o \
2120
x509_public_key.o
2221

2322
$(obj)/x509_cert_parser.o: \
2423
$(obj)/x509-asn1.h \
25-
$(obj)/x509_akid-asn1.h \
26-
$(obj)/x509_rsakey-asn1.h
24+
$(obj)/x509_akid-asn1.h
25+
2726
$(obj)/x509-asn1.o: $(obj)/x509-asn1.c $(obj)/x509-asn1.h
2827
$(obj)/x509_akid-asn1.o: $(obj)/x509_akid-asn1.c $(obj)/x509_akid-asn1.h
29-
$(obj)/x509_rsakey-asn1.o: $(obj)/x509_rsakey-asn1.c $(obj)/x509_rsakey-asn1.h
3028

3129
clean-files += x509-asn1.c x509-asn1.h
3230
clean-files += x509_akid-asn1.c x509_akid-asn1.h
33-
clean-files += x509_rsakey-asn1.c x509_rsakey-asn1.h
3431

3532
#
3633
# PKCS#7 message handling

crypto/asymmetric_keys/pkcs7_parser.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <linux/slab.h>
1616
#include <linux/err.h>
1717
#include <linux/oid_registry.h>
18-
#include "public_key.h"
18+
#include <crypto/public_key.h>
1919
#include "pkcs7_parser.h"
2020
#include "pkcs7-asn1.h"
2121

@@ -44,7 +44,7 @@ struct pkcs7_parse_context {
4444
static void pkcs7_free_signed_info(struct pkcs7_signed_info *sinfo)
4545
{
4646
if (sinfo) {
47-
mpi_free(sinfo->sig.mpi[0]);
47+
kfree(sinfo->sig.s);
4848
kfree(sinfo->sig.digest);
4949
kfree(sinfo->signing_cert_id);
5050
kfree(sinfo);
@@ -614,16 +614,14 @@ int pkcs7_sig_note_signature(void *context, size_t hdrlen,
614614
const void *value, size_t vlen)
615615
{
616616
struct pkcs7_parse_context *ctx = context;
617-
MPI mpi;
618617

619618
BUG_ON(ctx->sinfo->sig.pkey_algo != PKEY_ALGO_RSA);
620619

621-
mpi = mpi_read_raw_data(value, vlen);
622-
if (!mpi)
620+
ctx->sinfo->sig.s = kmemdup(value, vlen, GFP_KERNEL);
621+
if (!ctx->sinfo->sig.s)
623622
return -ENOMEM;
624623

625-
ctx->sinfo->sig.mpi[0] = mpi;
626-
ctx->sinfo->sig.nr_mpi = 1;
624+
ctx->sinfo->sig.s_size = vlen;
627625
return 0;
628626
}
629627

crypto/asymmetric_keys/pkcs7_trust.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <linux/asn1.h>
1818
#include <linux/key.h>
1919
#include <keys/asymmetric-type.h>
20-
#include "public_key.h"
20+
#include <crypto/public_key.h>
2121
#include "pkcs7_parser.h"
2222

2323
/**

crypto/asymmetric_keys/pkcs7_verify.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <linux/err.h>
1717
#include <linux/asn1.h>
1818
#include <crypto/hash.h>
19-
#include "public_key.h"
19+
#include <crypto/public_key.h>
2020
#include "pkcs7_parser.h"
2121

2222
/*

crypto/asymmetric_keys/public_key.c

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,29 @@
1818
#include <linux/slab.h>
1919
#include <linux/seq_file.h>
2020
#include <keys/asymmetric-subtype.h>
21-
#include "public_key.h"
21+
#include <crypto/public_key.h>
2222

2323
MODULE_LICENSE("GPL");
2424

2525
const char *const pkey_algo_name[PKEY_ALGO__LAST] = {
26-
[PKEY_ALGO_DSA] = "DSA",
27-
[PKEY_ALGO_RSA] = "RSA",
26+
[PKEY_ALGO_DSA] = "dsa",
27+
[PKEY_ALGO_RSA] = "rsa",
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-
3931
const char *const pkey_id_type_name[PKEY_ID_TYPE__LAST] = {
4032
[PKEY_ID_PGP] = "PGP",
4133
[PKEY_ID_X509] = "X509",
4234
[PKEY_ID_PKCS7] = "PKCS#7",
4335
};
4436
EXPORT_SYMBOL_GPL(pkey_id_type_name);
4537

38+
static int (*alg_verify[PKEY_ALGO__LAST])(const struct public_key *pkey,
39+
const struct public_key_signature *sig) = {
40+
NULL,
41+
rsa_verify_signature
42+
};
43+
4644
/*
4745
* Provide a part of a description of the key for /proc/keys.
4846
*/
@@ -53,7 +51,8 @@ static void public_key_describe(const struct key *asymmetric_key,
5351

5452
if (key)
5553
seq_printf(m, "%s.%s",
56-
pkey_id_type_name[key->id_type], key->algo->name);
54+
pkey_id_type_name[key->id_type],
55+
pkey_algo_name[key->pkey_algo]);
5756
}
5857

5958
/*
@@ -62,50 +61,31 @@ static void public_key_describe(const struct key *asymmetric_key,
6261
void public_key_destroy(void *payload)
6362
{
6463
struct public_key *key = payload;
65-
int i;
6664

67-
if (key) {
68-
for (i = 0; i < ARRAY_SIZE(key->mpi); i++)
69-
mpi_free(key->mpi[i]);
70-
kfree(key);
71-
}
65+
if (key)
66+
kfree(key->key);
67+
kfree(key);
7268
}
7369
EXPORT_SYMBOL_GPL(public_key_destroy);
7470

7571
/*
7672
* Verify a signature using a public key.
7773
*/
78-
int public_key_verify_signature(const struct public_key *pk,
74+
int public_key_verify_signature(const struct public_key *pkey,
7975
const struct public_key_signature *sig)
8076
{
81-
const struct public_key_algorithm *algo;
82-
83-
BUG_ON(!pk);
84-
BUG_ON(!pk->mpi[0]);
85-
BUG_ON(!pk->mpi[1]);
77+
BUG_ON(!pkey);
8678
BUG_ON(!sig);
8779
BUG_ON(!sig->digest);
88-
BUG_ON(!sig->mpi[0]);
89-
90-
algo = pk->algo;
91-
if (!algo) {
92-
if (pk->pkey_algo >= PKEY_ALGO__LAST)
93-
return -ENOPKG;
94-
algo = pkey_algo[pk->pkey_algo];
95-
if (!algo)
96-
return -ENOPKG;
97-
}
80+
BUG_ON(!sig->s);
9881

99-
if (!algo->verify_signature)
100-
return -ENOTSUPP;
82+
if (pkey->pkey_algo >= PKEY_ALGO__LAST)
83+
return -ENOPKG;
10184

102-
if (sig->nr_mpi != algo->n_sig_mpi) {
103-
pr_debug("Signature has %u MPI not %u\n",
104-
sig->nr_mpi, algo->n_sig_mpi);
105-
return -EINVAL;
106-
}
85+
if (!alg_verify[pkey->pkey_algo])
86+
return -ENOPKG;
10787

108-
return algo->verify_signature(pk, sig);
88+
return alg_verify[pkey->pkey_algo](pkey, sig);
10989
}
11090
EXPORT_SYMBOL_GPL(public_key_verify_signature);
11191

crypto/asymmetric_keys/public_key.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)