Skip to content

Commit 3b76456

Browse files
committed
KEYS: Allow authentication data to be stored in an asymmetric key
Allow authentication data to be stored in an asymmetric key in the 4th element of the key payload and provide a way for it to be destroyed. For the public key subtype, this will be a public_key_signature struct. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 864e7a8 commit 3b76456

File tree

7 files changed

+43
-14
lines changed

7 files changed

+43
-14
lines changed

crypto/asymmetric_keys/asymmetric_type.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ static void asymmetric_key_free_preparse(struct key_preparsed_payload *prep)
331331
pr_devel("==>%s()\n", __func__);
332332

333333
if (subtype) {
334-
subtype->destroy(prep->payload.data[asym_crypto]);
334+
subtype->destroy(prep->payload.data[asym_crypto],
335+
prep->payload.data[asym_auth]);
335336
module_put(subtype->owner);
336337
}
337338
asymmetric_key_free_kids(kids);
@@ -346,13 +347,15 @@ static void asymmetric_key_destroy(struct key *key)
346347
struct asymmetric_key_subtype *subtype = asymmetric_key_subtype(key);
347348
struct asymmetric_key_ids *kids = key->payload.data[asym_key_ids];
348349
void *data = key->payload.data[asym_crypto];
350+
void *auth = key->payload.data[asym_auth];
349351

350352
key->payload.data[asym_crypto] = NULL;
351353
key->payload.data[asym_subtype] = NULL;
352354
key->payload.data[asym_key_ids] = NULL;
355+
key->payload.data[asym_auth] = NULL;
353356

354357
if (subtype) {
355-
subtype->destroy(data);
358+
subtype->destroy(data, auth);
356359
module_put(subtype->owner);
357360
}
358361

crypto/asymmetric_keys/public_key.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,23 @@ static void public_key_describe(const struct key *asymmetric_key,
3939
/*
4040
* Destroy a public key algorithm key.
4141
*/
42-
void public_key_destroy(void *payload)
42+
void public_key_free(struct public_key *key)
4343
{
44-
struct public_key *key = payload;
45-
46-
if (key)
44+
if (key) {
4745
kfree(key->key);
48-
kfree(key);
46+
kfree(key);
47+
}
48+
}
49+
EXPORT_SYMBOL_GPL(public_key_free);
50+
51+
/*
52+
* Destroy a public key algorithm key.
53+
*/
54+
static void public_key_destroy(void *payload0, void *payload3)
55+
{
56+
public_key_free(payload0);
57+
public_key_signature_free(payload3);
4958
}
50-
EXPORT_SYMBOL_GPL(public_key_destroy);
5159

5260
struct public_key_completion {
5361
struct completion completion;

crypto/asymmetric_keys/signature.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,23 @@
1515
#include <keys/asymmetric-subtype.h>
1616
#include <linux/export.h>
1717
#include <linux/err.h>
18+
#include <linux/slab.h>
1819
#include <crypto/public_key.h>
1920
#include "asymmetric_keys.h"
2021

22+
/*
23+
* Destroy a public key signature.
24+
*/
25+
void public_key_signature_free(struct public_key_signature *sig)
26+
{
27+
if (sig) {
28+
kfree(sig->s);
29+
kfree(sig->digest);
30+
kfree(sig);
31+
}
32+
}
33+
EXPORT_SYMBOL_GPL(public_key_signature_free);
34+
2135
/**
2236
* verify_signature - Initiate the use of an asymmetric key to verify a signature
2337
* @key: The asymmetric key to verify against

crypto/asymmetric_keys/x509_cert_parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct x509_parse_context {
4747
void x509_free_certificate(struct x509_certificate *cert)
4848
{
4949
if (cert) {
50-
public_key_destroy(cert->pub);
50+
public_key_free(cert->pub);
5151
kfree(cert->issuer);
5252
kfree(cert->subject);
5353
kfree(cert->id);

include/crypto/public_key.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct public_key {
4141
const char *pkey_algo;
4242
};
4343

44-
extern void public_key_destroy(void *payload);
44+
extern void public_key_free(struct public_key *key);
4545

4646
/*
4747
* Public key cryptography signature data
@@ -55,7 +55,10 @@ struct public_key_signature {
5555
const char *hash_algo;
5656
};
5757

58+
extern void public_key_signature_free(struct public_key_signature *sig);
59+
5860
extern struct asymmetric_key_subtype public_key_subtype;
61+
5962
struct key;
6063
extern int verify_signature(const struct key *key,
6164
const struct public_key_signature *sig);

include/keys/asymmetric-subtype.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct asymmetric_key_subtype {
3232
void (*describe)(const struct key *key, struct seq_file *m);
3333

3434
/* Destroy a key of this subtype */
35-
void (*destroy)(void *payload);
35+
void (*destroy)(void *payload_crypto, void *payload_auth);
3636

3737
/* Verify the signature on a key of this subtype (optional) */
3838
int (*verify_signature)(const struct key *key,

include/keys/asymmetric-type.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ extern struct key_type key_type_asymmetric;
2323
* follows:
2424
*/
2525
enum asymmetric_payload_bits {
26-
asym_crypto,
27-
asym_subtype,
28-
asym_key_ids,
26+
asym_crypto, /* The data representing the key */
27+
asym_subtype, /* Pointer to an asymmetric_key_subtype struct */
28+
asym_key_ids, /* Pointer to an asymmetric_key_ids struct */
29+
asym_auth /* The key's authorisation (signature, parent key ID) */
2930
};
3031

3132
/*

0 commit comments

Comments
 (0)