hc
2024-01-31 f9004dbfff8a3fbbd7e2a88c8a4327c7f2f8e5b2
kernel/include/crypto/internal/hash.h
....@@ -1,13 +1,8 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * Hash algorithms.
34 *
45 * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms of the GNU General Public License as published by the Free
8
- * Software Foundation; either version 2 of the License, or (at your option)
9
- * any later version.
10
- *
116 */
127
138 #ifndef _CRYPTO_INTERNAL_HASH_H
....@@ -35,11 +30,25 @@
3530 };
3631
3732 struct ahash_instance {
38
- struct ahash_alg alg;
33
+ void (*free)(struct ahash_instance *inst);
34
+ union {
35
+ struct {
36
+ char head[offsetof(struct ahash_alg, halg.base)];
37
+ struct crypto_instance base;
38
+ } s;
39
+ struct ahash_alg alg;
40
+ };
3941 };
4042
4143 struct shash_instance {
42
- struct shash_alg alg;
44
+ void (*free)(struct shash_instance *inst);
45
+ union {
46
+ struct {
47
+ char head[offsetof(struct shash_alg, base)];
48
+ struct crypto_instance base;
49
+ } s;
50
+ struct shash_alg alg;
51
+ };
4352 };
4453
4554 struct crypto_ahash_spawn {
....@@ -50,71 +59,69 @@
5059 struct crypto_spawn base;
5160 };
5261
53
-extern const struct crypto_type crypto_ahash_type;
54
-
5562 int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err);
5663 int crypto_hash_walk_first(struct ahash_request *req,
5764 struct crypto_hash_walk *walk);
58
-int crypto_ahash_walk_first(struct ahash_request *req,
59
- struct crypto_hash_walk *walk);
60
-
61
-static inline int crypto_ahash_walk_done(struct crypto_hash_walk *walk,
62
- int err)
63
-{
64
- return crypto_hash_walk_done(walk, err);
65
-}
6665
6766 static inline int crypto_hash_walk_last(struct crypto_hash_walk *walk)
6867 {
6968 return !(walk->entrylen | walk->total);
7069 }
7170
72
-static inline int crypto_ahash_walk_last(struct crypto_hash_walk *walk)
73
-{
74
- return crypto_hash_walk_last(walk);
75
-}
76
-
7771 int crypto_register_ahash(struct ahash_alg *alg);
78
-int crypto_unregister_ahash(struct ahash_alg *alg);
72
+void crypto_unregister_ahash(struct ahash_alg *alg);
7973 int crypto_register_ahashes(struct ahash_alg *algs, int count);
8074 void crypto_unregister_ahashes(struct ahash_alg *algs, int count);
8175 int ahash_register_instance(struct crypto_template *tmpl,
8276 struct ahash_instance *inst);
83
-void ahash_free_instance(struct crypto_instance *inst);
8477
8578 bool crypto_shash_alg_has_setkey(struct shash_alg *alg);
8679
80
+static inline bool crypto_shash_alg_needs_key(struct shash_alg *alg)
81
+{
82
+ return crypto_shash_alg_has_setkey(alg) &&
83
+ !(alg->base.cra_flags & CRYPTO_ALG_OPTIONAL_KEY);
84
+}
85
+
8786 bool crypto_hash_alg_has_setkey(struct hash_alg_common *halg);
8887
89
-int crypto_init_ahash_spawn(struct crypto_ahash_spawn *spawn,
90
- struct hash_alg_common *alg,
91
- struct crypto_instance *inst);
88
+int crypto_grab_ahash(struct crypto_ahash_spawn *spawn,
89
+ struct crypto_instance *inst,
90
+ const char *name, u32 type, u32 mask);
9291
9392 static inline void crypto_drop_ahash(struct crypto_ahash_spawn *spawn)
9493 {
9594 crypto_drop_spawn(&spawn->base);
9695 }
9796
98
-struct hash_alg_common *ahash_attr_alg(struct rtattr *rta, u32 type, u32 mask);
97
+static inline struct hash_alg_common *crypto_spawn_ahash_alg(
98
+ struct crypto_ahash_spawn *spawn)
99
+{
100
+ return __crypto_hash_alg_common(spawn->base.alg);
101
+}
99102
100103 int crypto_register_shash(struct shash_alg *alg);
101
-int crypto_unregister_shash(struct shash_alg *alg);
104
+void crypto_unregister_shash(struct shash_alg *alg);
102105 int crypto_register_shashes(struct shash_alg *algs, int count);
103
-int crypto_unregister_shashes(struct shash_alg *algs, int count);
106
+void crypto_unregister_shashes(struct shash_alg *algs, int count);
104107 int shash_register_instance(struct crypto_template *tmpl,
105108 struct shash_instance *inst);
106
-void shash_free_instance(struct crypto_instance *inst);
109
+void shash_free_singlespawn_instance(struct shash_instance *inst);
107110
108
-int crypto_init_shash_spawn(struct crypto_shash_spawn *spawn,
109
- struct shash_alg *alg,
110
- struct crypto_instance *inst);
111
+int crypto_grab_shash(struct crypto_shash_spawn *spawn,
112
+ struct crypto_instance *inst,
113
+ const char *name, u32 type, u32 mask);
111114
112115 static inline void crypto_drop_shash(struct crypto_shash_spawn *spawn)
113116 {
114117 crypto_drop_spawn(&spawn->base);
115118 }
116119
117
-struct shash_alg *shash_attr_alg(struct rtattr *rta, u32 type, u32 mask);
120
+static inline struct shash_alg *crypto_spawn_shash_alg(
121
+ struct crypto_shash_spawn *spawn)
122
+{
123
+ return __crypto_shash_alg(spawn->base.alg);
124
+}
118125
119126 int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc);
120127 int shash_ahash_finup(struct ahash_request *req, struct shash_desc *desc);
....@@ -142,29 +149,24 @@
142149 static inline struct crypto_instance *ahash_crypto_instance(
143150 struct ahash_instance *inst)
144151 {
145
- return container_of(&inst->alg.halg.base, struct crypto_instance, alg);
152
+ return &inst->s.base;
146153 }
147154
148155 static inline struct ahash_instance *ahash_instance(
149156 struct crypto_instance *inst)
150157 {
151
- return container_of(&inst->alg, struct ahash_instance, alg.halg.base);
158
+ return container_of(inst, struct ahash_instance, s.base);
159
+}
160
+
161
+static inline struct ahash_instance *ahash_alg_instance(
162
+ struct crypto_ahash *ahash)
163
+{
164
+ return ahash_instance(crypto_tfm_alg_instance(&ahash->base));
152165 }
153166
154167 static inline void *ahash_instance_ctx(struct ahash_instance *inst)
155168 {
156169 return crypto_instance_ctx(ahash_crypto_instance(inst));
157
-}
158
-
159
-static inline unsigned int ahash_instance_headroom(void)
160
-{
161
- return sizeof(struct ahash_alg) - sizeof(struct crypto_alg);
162
-}
163
-
164
-static inline struct ahash_instance *ahash_alloc_instance(
165
- const char *name, struct crypto_alg *alg)
166
-{
167
- return crypto_alloc_instance2(name, alg, ahash_instance_headroom());
168170 }
169171
170172 static inline void ahash_request_complete(struct ahash_request *req, int err)
....@@ -195,12 +197,6 @@
195197 return ahash_request_cast(crypto_dequeue_request(queue));
196198 }
197199
198
-static inline int ahash_tfm_in_queue(struct crypto_queue *queue,
199
- struct crypto_ahash *tfm)
200
-{
201
- return crypto_tfm_in_queue(queue, crypto_ahash_tfm(tfm));
202
-}
203
-
204200 static inline void *crypto_shash_ctx(struct crypto_shash *tfm)
205201 {
206202 return crypto_tfm_ctx(&tfm->base);
....@@ -209,26 +205,24 @@
209205 static inline struct crypto_instance *shash_crypto_instance(
210206 struct shash_instance *inst)
211207 {
212
- return container_of(&inst->alg.base, struct crypto_instance, alg);
208
+ return &inst->s.base;
213209 }
214210
215211 static inline struct shash_instance *shash_instance(
216212 struct crypto_instance *inst)
217213 {
218
- return container_of(__crypto_shash_alg(&inst->alg),
219
- struct shash_instance, alg);
214
+ return container_of(inst, struct shash_instance, s.base);
215
+}
216
+
217
+static inline struct shash_instance *shash_alg_instance(
218
+ struct crypto_shash *shash)
219
+{
220
+ return shash_instance(crypto_tfm_alg_instance(&shash->base));
220221 }
221222
222223 static inline void *shash_instance_ctx(struct shash_instance *inst)
223224 {
224225 return crypto_instance_ctx(shash_crypto_instance(inst));
225
-}
226
-
227
-static inline struct shash_instance *shash_alloc_instance(
228
- const char *name, struct crypto_alg *alg)
229
-{
230
- return crypto_alloc_instance2(name, alg,
231
- sizeof(struct shash_alg) - sizeof(*alg));
232226 }
233227
234228 static inline struct crypto_shash *crypto_spawn_shash(