hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/crypto/padlock-sha.c
....@@ -1,15 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Cryptographic API.
34 *
45 * Support for VIA PadLock hardware crypto engine.
56 *
67 * 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
- *
138 */
149
1510 #include <crypto/internal/hash.h>
....@@ -39,7 +34,6 @@
3934 struct padlock_sha_ctx *ctx = crypto_shash_ctx(desc->tfm);
4035
4136 dctx->fallback.tfm = ctx->fallback;
42
- dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
4337 return crypto_shash_init(&dctx->fallback);
4438 }
4539
....@@ -48,7 +42,6 @@
4842 {
4943 struct padlock_sha_desc *dctx = shash_desc_ctx(desc);
5044
51
- dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
5245 return crypto_shash_update(&dctx->fallback, data, length);
5346 }
5447
....@@ -65,7 +58,6 @@
6558 struct padlock_sha_ctx *ctx = crypto_shash_ctx(desc->tfm);
6659
6760 dctx->fallback.tfm = ctx->fallback;
68
- dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
6961 return crypto_shash_import(&dctx->fallback, in);
7062 }
7163
....@@ -91,7 +83,6 @@
9183 unsigned int leftover;
9284 int err;
9385
94
- dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
9586 err = crypto_shash_export(&dctx->fallback, &state);
9687 if (err)
9788 goto out;
....@@ -153,7 +144,6 @@
153144 unsigned int leftover;
154145 int err;
155146
156
- dctx->fallback.flags = desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP;
157147 err = crypto_shash_export(&dctx->fallback, &state);
158148 if (err)
159149 goto out;
....@@ -200,13 +190,11 @@
200190 return padlock_sha256_finup(desc, buf, 0, out);
201191 }
202192
203
-static int padlock_cra_init(struct crypto_tfm *tfm)
193
+static int padlock_init_tfm(struct crypto_shash *hash)
204194 {
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);
208197 struct crypto_shash *fallback_tfm;
209
- int err = -ENOMEM;
210198
211199 /* Allocate a fallback and abort if it failed. */
212200 fallback_tfm = crypto_alloc_shash(fallback_driver_name, 0,
....@@ -214,21 +202,17 @@
214202 if (IS_ERR(fallback_tfm)) {
215203 printk(KERN_WARNING PFX "Fallback driver '%s' could not be loaded!\n",
216204 fallback_driver_name);
217
- err = PTR_ERR(fallback_tfm);
218
- goto out;
205
+ return PTR_ERR(fallback_tfm);
219206 }
220207
221208 ctx->fallback = fallback_tfm;
222209 hash->descsize += crypto_shash_descsize(fallback_tfm);
223210 return 0;
224
-
225
-out:
226
- return err;
227211 }
228212
229
-static void padlock_cra_exit(struct crypto_tfm *tfm)
213
+static void padlock_exit_tfm(struct crypto_shash *hash)
230214 {
231
- struct padlock_sha_ctx *ctx = crypto_tfm_ctx(tfm);
215
+ struct padlock_sha_ctx *ctx = crypto_shash_ctx(hash);
232216
233217 crypto_free_shash(ctx->fallback);
234218 }
....@@ -241,6 +225,8 @@
241225 .final = padlock_sha1_final,
242226 .export = padlock_sha_export,
243227 .import = padlock_sha_import,
228
+ .init_tfm = padlock_init_tfm,
229
+ .exit_tfm = padlock_exit_tfm,
244230 .descsize = sizeof(struct padlock_sha_desc),
245231 .statesize = sizeof(struct sha1_state),
246232 .base = {
....@@ -251,8 +237,6 @@
251237 .cra_blocksize = SHA1_BLOCK_SIZE,
252238 .cra_ctxsize = sizeof(struct padlock_sha_ctx),
253239 .cra_module = THIS_MODULE,
254
- .cra_init = padlock_cra_init,
255
- .cra_exit = padlock_cra_exit,
256240 }
257241 };
258242
....@@ -264,6 +248,8 @@
264248 .final = padlock_sha256_final,
265249 .export = padlock_sha_export,
266250 .import = padlock_sha_import,
251
+ .init_tfm = padlock_init_tfm,
252
+ .exit_tfm = padlock_exit_tfm,
267253 .descsize = sizeof(struct padlock_sha_desc),
268254 .statesize = sizeof(struct sha256_state),
269255 .base = {
....@@ -274,8 +260,6 @@
274260 .cra_blocksize = SHA256_BLOCK_SIZE,
275261 .cra_ctxsize = sizeof(struct padlock_sha_ctx),
276262 .cra_module = THIS_MODULE,
277
- .cra_init = padlock_cra_init,
278
- .cra_exit = padlock_cra_exit,
279263 }
280264 };
281265
....@@ -506,7 +490,7 @@
506490 };
507491
508492 static const struct x86_cpu_id padlock_sha_ids[] = {
509
- X86_FEATURE_MATCH(X86_FEATURE_PHE),
493
+ X86_MATCH_FEATURE(X86_FEATURE_PHE, NULL),
510494 {}
511495 };
512496 MODULE_DEVICE_TABLE(x86cpu, padlock_sha_ids);