.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Cryptographic API. |
---|
3 | 4 | * |
---|
4 | 5 | * Support for VIA PadLock hardware crypto engine. |
---|
5 | 6 | * |
---|
6 | 7 | * Copyright (c) 2006 Michal Ludvig <michal@logix.cz> |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License as published by |
---|
10 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
11 | | - * (at your option) any later version. |
---|
12 | | - * |
---|
13 | 8 | */ |
---|
14 | 9 | |
---|
15 | 10 | #include <crypto/internal/hash.h> |
---|
.. | .. |
---|
39 | 34 | struct padlock_sha_ctx *ctx = crypto_shash_ctx(desc->tfm); |
---|
40 | 35 | |
---|
41 | 36 | dctx->fallback.tfm = ctx->fallback; |
---|
42 | | - dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; |
---|
43 | 37 | return crypto_shash_init(&dctx->fallback); |
---|
44 | 38 | } |
---|
45 | 39 | |
---|
.. | .. |
---|
48 | 42 | { |
---|
49 | 43 | struct padlock_sha_desc *dctx = shash_desc_ctx(desc); |
---|
50 | 44 | |
---|
51 | | - dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; |
---|
52 | 45 | return crypto_shash_update(&dctx->fallback, data, length); |
---|
53 | 46 | } |
---|
54 | 47 | |
---|
.. | .. |
---|
65 | 58 | struct padlock_sha_ctx *ctx = crypto_shash_ctx(desc->tfm); |
---|
66 | 59 | |
---|
67 | 60 | dctx->fallback.tfm = ctx->fallback; |
---|
68 | | - dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; |
---|
69 | 61 | return crypto_shash_import(&dctx->fallback, in); |
---|
70 | 62 | } |
---|
71 | 63 | |
---|
.. | .. |
---|
91 | 83 | unsigned int leftover; |
---|
92 | 84 | int err; |
---|
93 | 85 | |
---|
94 | | - dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; |
---|
95 | 86 | err = crypto_shash_export(&dctx->fallback, &state); |
---|
96 | 87 | if (err) |
---|
97 | 88 | goto out; |
---|
.. | .. |
---|
153 | 144 | unsigned int leftover; |
---|
154 | 145 | int err; |
---|
155 | 146 | |
---|
156 | | - dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP; |
---|
157 | 147 | err = crypto_shash_export(&dctx->fallback, &state); |
---|
158 | 148 | if (err) |
---|
159 | 149 | goto out; |
---|
.. | .. |
---|
200 | 190 | return padlock_sha256_finup(desc, buf, 0, out); |
---|
201 | 191 | } |
---|
202 | 192 | |
---|
203 | | -static int padlock_cra_init(struct crypto_tfm *tfm) |
---|
| 193 | +static int padlock_init_tfm(struct crypto_shash *hash) |
---|
204 | 194 | { |
---|
205 | | - struct crypto_shash *hash = __crypto_shash_cast(tfm); |
---|
206 | | - const char *fallback_driver_name = crypto_tfm_alg_name(tfm); |
---|
207 | | - struct padlock_sha_ctx *ctx = crypto_tfm_ctx(tfm); |
---|
| 195 | + const char *fallback_driver_name = crypto_shash_alg_name(hash); |
---|
| 196 | + struct padlock_sha_ctx *ctx = crypto_shash_ctx(hash); |
---|
208 | 197 | struct crypto_shash *fallback_tfm; |
---|
209 | | - int err = -ENOMEM; |
---|
210 | 198 | |
---|
211 | 199 | /* Allocate a fallback and abort if it failed. */ |
---|
212 | 200 | fallback_tfm = crypto_alloc_shash(fallback_driver_name, 0, |
---|
.. | .. |
---|
214 | 202 | if (IS_ERR(fallback_tfm)) { |
---|
215 | 203 | printk(KERN_WARNING PFX "Fallback driver '%s' could not be loaded!\n", |
---|
216 | 204 | fallback_driver_name); |
---|
217 | | - err = PTR_ERR(fallback_tfm); |
---|
218 | | - goto out; |
---|
| 205 | + return PTR_ERR(fallback_tfm); |
---|
219 | 206 | } |
---|
220 | 207 | |
---|
221 | 208 | ctx->fallback = fallback_tfm; |
---|
222 | 209 | hash->descsize += crypto_shash_descsize(fallback_tfm); |
---|
223 | 210 | return 0; |
---|
224 | | - |
---|
225 | | -out: |
---|
226 | | - return err; |
---|
227 | 211 | } |
---|
228 | 212 | |
---|
229 | | -static void padlock_cra_exit(struct crypto_tfm *tfm) |
---|
| 213 | +static void padlock_exit_tfm(struct crypto_shash *hash) |
---|
230 | 214 | { |
---|
231 | | - struct padlock_sha_ctx *ctx = crypto_tfm_ctx(tfm); |
---|
| 215 | + struct padlock_sha_ctx *ctx = crypto_shash_ctx(hash); |
---|
232 | 216 | |
---|
233 | 217 | crypto_free_shash(ctx->fallback); |
---|
234 | 218 | } |
---|
.. | .. |
---|
241 | 225 | .final = padlock_sha1_final, |
---|
242 | 226 | .export = padlock_sha_export, |
---|
243 | 227 | .import = padlock_sha_import, |
---|
| 228 | + .init_tfm = padlock_init_tfm, |
---|
| 229 | + .exit_tfm = padlock_exit_tfm, |
---|
244 | 230 | .descsize = sizeof(struct padlock_sha_desc), |
---|
245 | 231 | .statesize = sizeof(struct sha1_state), |
---|
246 | 232 | .base = { |
---|
.. | .. |
---|
251 | 237 | .cra_blocksize = SHA1_BLOCK_SIZE, |
---|
252 | 238 | .cra_ctxsize = sizeof(struct padlock_sha_ctx), |
---|
253 | 239 | .cra_module = THIS_MODULE, |
---|
254 | | - .cra_init = padlock_cra_init, |
---|
255 | | - .cra_exit = padlock_cra_exit, |
---|
256 | 240 | } |
---|
257 | 241 | }; |
---|
258 | 242 | |
---|
.. | .. |
---|
264 | 248 | .final = padlock_sha256_final, |
---|
265 | 249 | .export = padlock_sha_export, |
---|
266 | 250 | .import = padlock_sha_import, |
---|
| 251 | + .init_tfm = padlock_init_tfm, |
---|
| 252 | + .exit_tfm = padlock_exit_tfm, |
---|
267 | 253 | .descsize = sizeof(struct padlock_sha_desc), |
---|
268 | 254 | .statesize = sizeof(struct sha256_state), |
---|
269 | 255 | .base = { |
---|
.. | .. |
---|
274 | 260 | .cra_blocksize = SHA256_BLOCK_SIZE, |
---|
275 | 261 | .cra_ctxsize = sizeof(struct padlock_sha_ctx), |
---|
276 | 262 | .cra_module = THIS_MODULE, |
---|
277 | | - .cra_init = padlock_cra_init, |
---|
278 | | - .cra_exit = padlock_cra_exit, |
---|
279 | 263 | } |
---|
280 | 264 | }; |
---|
281 | 265 | |
---|
.. | .. |
---|
506 | 490 | }; |
---|
507 | 491 | |
---|
508 | 492 | static const struct x86_cpu_id padlock_sha_ids[] = { |
---|
509 | | - X86_FEATURE_MATCH(X86_FEATURE_PHE), |
---|
| 493 | + X86_MATCH_FEATURE(X86_FEATURE_PHE, NULL), |
---|
510 | 494 | {} |
---|
511 | 495 | }; |
---|
512 | 496 | MODULE_DEVICE_TABLE(x86cpu, padlock_sha_ids); |
---|