.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
---|
1 | 2 | /* |
---|
2 | 3 | * Hash algorithms. |
---|
3 | 4 | * |
---|
4 | 5 | * 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 | | - * |
---|
11 | 6 | */ |
---|
12 | 7 | |
---|
13 | 8 | #ifndef _CRYPTO_INTERNAL_HASH_H |
---|
.. | .. |
---|
35 | 30 | }; |
---|
36 | 31 | |
---|
37 | 32 | 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 | + }; |
---|
39 | 41 | }; |
---|
40 | 42 | |
---|
41 | 43 | 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 | + }; |
---|
43 | 52 | }; |
---|
44 | 53 | |
---|
45 | 54 | struct crypto_ahash_spawn { |
---|
.. | .. |
---|
50 | 59 | struct crypto_spawn base; |
---|
51 | 60 | }; |
---|
52 | 61 | |
---|
53 | | -extern const struct crypto_type crypto_ahash_type; |
---|
54 | | - |
---|
55 | 62 | int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err); |
---|
56 | 63 | int crypto_hash_walk_first(struct ahash_request *req, |
---|
57 | 64 | 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 | | -} |
---|
66 | 65 | |
---|
67 | 66 | static inline int crypto_hash_walk_last(struct crypto_hash_walk *walk) |
---|
68 | 67 | { |
---|
69 | 68 | return !(walk->entrylen | walk->total); |
---|
70 | 69 | } |
---|
71 | 70 | |
---|
72 | | -static inline int crypto_ahash_walk_last(struct crypto_hash_walk *walk) |
---|
73 | | -{ |
---|
74 | | - return crypto_hash_walk_last(walk); |
---|
75 | | -} |
---|
76 | | - |
---|
77 | 71 | 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); |
---|
79 | 73 | int crypto_register_ahashes(struct ahash_alg *algs, int count); |
---|
80 | 74 | void crypto_unregister_ahashes(struct ahash_alg *algs, int count); |
---|
81 | 75 | int ahash_register_instance(struct crypto_template *tmpl, |
---|
82 | 76 | struct ahash_instance *inst); |
---|
83 | | -void ahash_free_instance(struct crypto_instance *inst); |
---|
84 | 77 | |
---|
85 | 78 | bool crypto_shash_alg_has_setkey(struct shash_alg *alg); |
---|
86 | 79 | |
---|
| 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 | + |
---|
87 | 86 | bool crypto_hash_alg_has_setkey(struct hash_alg_common *halg); |
---|
88 | 87 | |
---|
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); |
---|
92 | 91 | |
---|
93 | 92 | static inline void crypto_drop_ahash(struct crypto_ahash_spawn *spawn) |
---|
94 | 93 | { |
---|
95 | 94 | crypto_drop_spawn(&spawn->base); |
---|
96 | 95 | } |
---|
97 | 96 | |
---|
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 | +} |
---|
99 | 102 | |
---|
100 | 103 | 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); |
---|
102 | 105 | 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); |
---|
104 | 107 | int shash_register_instance(struct crypto_template *tmpl, |
---|
105 | 108 | struct shash_instance *inst); |
---|
106 | | -void shash_free_instance(struct crypto_instance *inst); |
---|
| 109 | +void shash_free_singlespawn_instance(struct shash_instance *inst); |
---|
107 | 110 | |
---|
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); |
---|
111 | 114 | |
---|
112 | 115 | static inline void crypto_drop_shash(struct crypto_shash_spawn *spawn) |
---|
113 | 116 | { |
---|
114 | 117 | crypto_drop_spawn(&spawn->base); |
---|
115 | 118 | } |
---|
116 | 119 | |
---|
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 | +} |
---|
118 | 125 | |
---|
119 | 126 | int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc); |
---|
120 | 127 | int shash_ahash_finup(struct ahash_request *req, struct shash_desc *desc); |
---|
.. | .. |
---|
142 | 149 | static inline struct crypto_instance *ahash_crypto_instance( |
---|
143 | 150 | struct ahash_instance *inst) |
---|
144 | 151 | { |
---|
145 | | - return container_of(&inst->alg.halg.base, struct crypto_instance, alg); |
---|
| 152 | + return &inst->s.base; |
---|
146 | 153 | } |
---|
147 | 154 | |
---|
148 | 155 | static inline struct ahash_instance *ahash_instance( |
---|
149 | 156 | struct crypto_instance *inst) |
---|
150 | 157 | { |
---|
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)); |
---|
152 | 165 | } |
---|
153 | 166 | |
---|
154 | 167 | static inline void *ahash_instance_ctx(struct ahash_instance *inst) |
---|
155 | 168 | { |
---|
156 | 169 | 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()); |
---|
168 | 170 | } |
---|
169 | 171 | |
---|
170 | 172 | static inline void ahash_request_complete(struct ahash_request *req, int err) |
---|
.. | .. |
---|
195 | 197 | return ahash_request_cast(crypto_dequeue_request(queue)); |
---|
196 | 198 | } |
---|
197 | 199 | |
---|
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 | | - |
---|
204 | 200 | static inline void *crypto_shash_ctx(struct crypto_shash *tfm) |
---|
205 | 201 | { |
---|
206 | 202 | return crypto_tfm_ctx(&tfm->base); |
---|
.. | .. |
---|
209 | 205 | static inline struct crypto_instance *shash_crypto_instance( |
---|
210 | 206 | struct shash_instance *inst) |
---|
211 | 207 | { |
---|
212 | | - return container_of(&inst->alg.base, struct crypto_instance, alg); |
---|
| 208 | + return &inst->s.base; |
---|
213 | 209 | } |
---|
214 | 210 | |
---|
215 | 211 | static inline struct shash_instance *shash_instance( |
---|
216 | 212 | struct crypto_instance *inst) |
---|
217 | 213 | { |
---|
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)); |
---|
220 | 221 | } |
---|
221 | 222 | |
---|
222 | 223 | static inline void *shash_instance_ctx(struct shash_instance *inst) |
---|
223 | 224 | { |
---|
224 | 225 | 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)); |
---|
232 | 226 | } |
---|
233 | 227 | |
---|
234 | 228 | static inline struct crypto_shash *crypto_spawn_shash( |
---|