This source file includes following definitions.
- public_key_signature_free
- query_asymmetric_key
- encrypt_blob
- decrypt_blob
- create_signature
- verify_signature
1
2
3
4
5
6
7
8
9
10 #define pr_fmt(fmt) "SIG: "fmt
11 #include <keys/asymmetric-subtype.h>
12 #include <linux/export.h>
13 #include <linux/err.h>
14 #include <linux/slab.h>
15 #include <linux/keyctl.h>
16 #include <crypto/public_key.h>
17 #include <keys/user-type.h>
18 #include "asymmetric_keys.h"
19
20
21
22
23 void public_key_signature_free(struct public_key_signature *sig)
24 {
25 int i;
26
27 if (sig) {
28 for (i = 0; i < ARRAY_SIZE(sig->auth_ids); i++)
29 kfree(sig->auth_ids[i]);
30 kfree(sig->s);
31 kfree(sig->digest);
32 kfree(sig);
33 }
34 }
35 EXPORT_SYMBOL_GPL(public_key_signature_free);
36
37
38
39
40
41
42 int query_asymmetric_key(const struct kernel_pkey_params *params,
43 struct kernel_pkey_query *info)
44 {
45 const struct asymmetric_key_subtype *subtype;
46 struct key *key = params->key;
47 int ret;
48
49 pr_devel("==>%s()\n", __func__);
50
51 if (key->type != &key_type_asymmetric)
52 return -EINVAL;
53 subtype = asymmetric_key_subtype(key);
54 if (!subtype ||
55 !key->payload.data[0])
56 return -EINVAL;
57 if (!subtype->query)
58 return -ENOTSUPP;
59
60 ret = subtype->query(params, info);
61
62 pr_devel("<==%s() = %d\n", __func__, ret);
63 return ret;
64 }
65 EXPORT_SYMBOL_GPL(query_asymmetric_key);
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 int encrypt_blob(struct kernel_pkey_params *params,
81 const void *data, void *enc)
82 {
83 params->op = kernel_pkey_encrypt;
84 return asymmetric_key_eds_op(params, data, enc);
85 }
86 EXPORT_SYMBOL_GPL(encrypt_blob);
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101 int decrypt_blob(struct kernel_pkey_params *params,
102 const void *enc, void *data)
103 {
104 params->op = kernel_pkey_decrypt;
105 return asymmetric_key_eds_op(params, enc, data);
106 }
107 EXPORT_SYMBOL_GPL(decrypt_blob);
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122 int create_signature(struct kernel_pkey_params *params,
123 const void *data, void *enc)
124 {
125 params->op = kernel_pkey_sign;
126 return asymmetric_key_eds_op(params, data, enc);
127 }
128 EXPORT_SYMBOL_GPL(create_signature);
129
130
131
132
133
134
135
136
137 int verify_signature(const struct key *key,
138 const struct public_key_signature *sig)
139 {
140 const struct asymmetric_key_subtype *subtype;
141 int ret;
142
143 pr_devel("==>%s()\n", __func__);
144
145 if (key->type != &key_type_asymmetric)
146 return -EINVAL;
147 subtype = asymmetric_key_subtype(key);
148 if (!subtype ||
149 !key->payload.data[0])
150 return -EINVAL;
151 if (!subtype->verify_signature)
152 return -ENOTSUPP;
153
154 ret = subtype->verify_signature(key, sig);
155
156 pr_devel("<==%s() = %d\n", __func__, ret);
157 return ret;
158 }
159 EXPORT_SYMBOL_GPL(verify_signature);