hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/crypto/akcipher.c
....@@ -1,14 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Public Key Encryption
34 *
45 * Copyright (c) 2015, Intel Corporation
56 * Authors: Tadeusz Struk <tadeusz.struk@intel.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify it
8
- * under the terms of the GNU General Public License as published by the Free
9
- * Software Foundation; either version 2 of the License, or (at your option)
10
- * any later version.
11
- *
127 */
138 #include <linux/errno.h>
149 #include <linux/kernel.h>
....@@ -30,15 +25,12 @@
3025 {
3126 struct crypto_report_akcipher rakcipher;
3227
33
- strncpy(rakcipher.type, "akcipher", sizeof(rakcipher.type));
28
+ memset(&rakcipher, 0, sizeof(rakcipher));
3429
35
- if (nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER,
36
- sizeof(struct crypto_report_akcipher), &rakcipher))
37
- goto nla_put_failure;
38
- return 0;
30
+ strscpy(rakcipher.type, "akcipher", sizeof(rakcipher.type));
3931
40
-nla_put_failure:
41
- return -EMSGSIZE;
32
+ return nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER,
33
+ sizeof(rakcipher), &rakcipher);
4234 }
4335 #else
4436 static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
....@@ -98,11 +90,12 @@
9890 .tfmsize = offsetof(struct crypto_akcipher, base),
9991 };
10092
101
-int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn, const char *name,
102
- u32 type, u32 mask)
93
+int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn,
94
+ struct crypto_instance *inst,
95
+ const char *name, u32 type, u32 mask)
10396 {
10497 spawn->base.frontend = &crypto_akcipher_type;
105
- return crypto_grab_spawn(&spawn->base, name, type, mask);
98
+ return crypto_grab_spawn(&spawn->base, inst, name, type, mask);
10699 }
107100 EXPORT_SYMBOL_GPL(crypto_grab_akcipher);
108101
....@@ -122,9 +115,31 @@
122115 base->cra_flags |= CRYPTO_ALG_TYPE_AKCIPHER;
123116 }
124117
118
+static int akcipher_default_op(struct akcipher_request *req)
119
+{
120
+ return -ENOSYS;
121
+}
122
+
123
+static int akcipher_default_set_key(struct crypto_akcipher *tfm,
124
+ const void *key, unsigned int keylen)
125
+{
126
+ return -ENOSYS;
127
+}
128
+
125129 int crypto_register_akcipher(struct akcipher_alg *alg)
126130 {
127131 struct crypto_alg *base = &alg->base;
132
+
133
+ if (!alg->sign)
134
+ alg->sign = akcipher_default_op;
135
+ if (!alg->verify)
136
+ alg->verify = akcipher_default_op;
137
+ if (!alg->encrypt)
138
+ alg->encrypt = akcipher_default_op;
139
+ if (!alg->decrypt)
140
+ alg->decrypt = akcipher_default_op;
141
+ if (!alg->set_priv_key)
142
+ alg->set_priv_key = akcipher_default_set_key;
128143
129144 akcipher_prepare_alg(alg);
130145 return crypto_register_alg(base);
....@@ -140,6 +155,8 @@
140155 int akcipher_register_instance(struct crypto_template *tmpl,
141156 struct akcipher_instance *inst)
142157 {
158
+ if (WARN_ON(!inst->free))
159
+ return -EINVAL;
143160 akcipher_prepare_alg(&inst->alg);
144161 return crypto_register_instance(tmpl, akcipher_crypto_instance(inst));
145162 }