.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Public Key Encryption |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2015, Intel Corporation |
---|
5 | 6 | * 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 | | - * |
---|
12 | 7 | */ |
---|
13 | 8 | #include <linux/errno.h> |
---|
14 | 9 | #include <linux/kernel.h> |
---|
.. | .. |
---|
30 | 25 | { |
---|
31 | 26 | struct crypto_report_akcipher rakcipher; |
---|
32 | 27 | |
---|
33 | | - strncpy(rakcipher.type, "akcipher", sizeof(rakcipher.type)); |
---|
| 28 | + memset(&rakcipher, 0, sizeof(rakcipher)); |
---|
34 | 29 | |
---|
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)); |
---|
39 | 31 | |
---|
40 | | -nla_put_failure: |
---|
41 | | - return -EMSGSIZE; |
---|
| 32 | + return nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER, |
---|
| 33 | + sizeof(rakcipher), &rakcipher); |
---|
42 | 34 | } |
---|
43 | 35 | #else |
---|
44 | 36 | static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg) |
---|
.. | .. |
---|
98 | 90 | .tfmsize = offsetof(struct crypto_akcipher, base), |
---|
99 | 91 | }; |
---|
100 | 92 | |
---|
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) |
---|
103 | 96 | { |
---|
104 | 97 | 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); |
---|
106 | 99 | } |
---|
107 | 100 | EXPORT_SYMBOL_GPL(crypto_grab_akcipher); |
---|
108 | 101 | |
---|
.. | .. |
---|
122 | 115 | base->cra_flags |= CRYPTO_ALG_TYPE_AKCIPHER; |
---|
123 | 116 | } |
---|
124 | 117 | |
---|
| 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 | + |
---|
125 | 129 | int crypto_register_akcipher(struct akcipher_alg *alg) |
---|
126 | 130 | { |
---|
127 | 131 | 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; |
---|
128 | 143 | |
---|
129 | 144 | akcipher_prepare_alg(alg); |
---|
130 | 145 | return crypto_register_alg(base); |
---|
.. | .. |
---|
140 | 155 | int akcipher_register_instance(struct crypto_template *tmpl, |
---|
141 | 156 | struct akcipher_instance *inst) |
---|
142 | 157 | { |
---|
| 158 | + if (WARN_ON(!inst->free)) |
---|
| 159 | + return -EINVAL; |
---|
143 | 160 | akcipher_prepare_alg(&inst->alg); |
---|
144 | 161 | return crypto_register_instance(tmpl, akcipher_crypto_instance(inst)); |
---|
145 | 162 | } |
---|