aboutsummaryrefslogtreecommitdiffstats
path: root/include/crypto/hash.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/crypto/hash.h')
-rw-r--r--include/crypto/hash.h109
1 files changed, 78 insertions, 31 deletions
diff --git a/include/crypto/hash.h b/include/crypto/hash.h
index fcc02d978231..262861d8f0cb 100644
--- a/include/crypto/hash.h
+++ b/include/crypto/hash.h
@@ -15,6 +15,39 @@
15 15
16#include <linux/crypto.h> 16#include <linux/crypto.h>
17 17
18struct crypto_ahash;
19
20struct hash_alg_common {
21 unsigned int digestsize;
22 unsigned int statesize;
23
24 struct crypto_alg base;
25};
26
27struct ahash_request {
28 struct crypto_async_request base;
29
30 unsigned int nbytes;
31 struct scatterlist *src;
32 u8 *result;
33
34 void *__ctx[] CRYPTO_MINALIGN_ATTR;
35};
36
37struct ahash_alg {
38 int (*init)(struct ahash_request *req);
39 int (*update)(struct ahash_request *req);
40 int (*final)(struct ahash_request *req);
41 int (*finup)(struct ahash_request *req);
42 int (*digest)(struct ahash_request *req);
43 int (*export)(struct ahash_request *req, void *out);
44 int (*import)(struct ahash_request *req, const void *in);
45 int (*setkey)(struct crypto_ahash *tfm, const u8 *key,
46 unsigned int keylen);
47
48 struct hash_alg_common halg;
49};
50
18struct shash_desc { 51struct shash_desc {
19 struct crypto_shash *tfm; 52 struct crypto_shash *tfm;
20 u32 flags; 53 u32 flags;
@@ -37,6 +70,8 @@ struct shash_alg {
37 unsigned int keylen); 70 unsigned int keylen);
38 71
39 unsigned int descsize; 72 unsigned int descsize;
73
74 /* These fields must match hash_alg_common. */
40 unsigned int digestsize; 75 unsigned int digestsize;
41 unsigned int statesize; 76 unsigned int statesize;
42 77
@@ -44,6 +79,18 @@ struct shash_alg {
44}; 79};
45 80
46struct crypto_ahash { 81struct crypto_ahash {
82 int (*init)(struct ahash_request *req);
83 int (*update)(struct ahash_request *req);
84 int (*final)(struct ahash_request *req);
85 int (*finup)(struct ahash_request *req);
86 int (*digest)(struct ahash_request *req);
87 int (*export)(struct ahash_request *req, void *out);
88 int (*import)(struct ahash_request *req, const void *in);
89 int (*setkey)(struct crypto_ahash *tfm, const u8 *key,
90 unsigned int keylen);
91
92 unsigned int digestsize;
93 unsigned int reqsize;
47 struct crypto_tfm base; 94 struct crypto_tfm base;
48}; 95};
49 96
@@ -54,19 +101,11 @@ struct crypto_shash {
54 101
55static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm) 102static inline struct crypto_ahash *__crypto_ahash_cast(struct crypto_tfm *tfm)
56{ 103{
57 return (struct crypto_ahash *)tfm; 104 return container_of(tfm, struct crypto_ahash, base);
58} 105}
59 106
60static inline struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, 107struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, u32 type,
61 u32 type, u32 mask) 108 u32 mask);
62{
63 type &= ~CRYPTO_ALG_TYPE_MASK;
64 mask &= ~CRYPTO_ALG_TYPE_MASK;
65 type |= CRYPTO_ALG_TYPE_AHASH;
66 mask |= CRYPTO_ALG_TYPE_AHASH_MASK;
67
68 return __crypto_ahash_cast(crypto_alloc_base(alg_name, type, mask));
69}
70 109
71static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm) 110static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm)
72{ 111{
@@ -75,7 +114,7 @@ static inline struct crypto_tfm *crypto_ahash_tfm(struct crypto_ahash *tfm)
75 114
76static inline void crypto_free_ahash(struct crypto_ahash *tfm) 115static inline void crypto_free_ahash(struct crypto_ahash *tfm)
77{ 116{
78 crypto_free_tfm(crypto_ahash_tfm(tfm)); 117 crypto_destroy_tfm(tfm, crypto_ahash_tfm(tfm));
79} 118}
80 119
81static inline unsigned int crypto_ahash_alignmask( 120static inline unsigned int crypto_ahash_alignmask(
@@ -84,14 +123,26 @@ static inline unsigned int crypto_ahash_alignmask(
84 return crypto_tfm_alg_alignmask(crypto_ahash_tfm(tfm)); 123 return crypto_tfm_alg_alignmask(crypto_ahash_tfm(tfm));
85} 124}
86 125
87static inline struct ahash_tfm *crypto_ahash_crt(struct crypto_ahash *tfm) 126static inline struct hash_alg_common *__crypto_hash_alg_common(
127 struct crypto_alg *alg)
88{ 128{
89 return &crypto_ahash_tfm(tfm)->crt_ahash; 129 return container_of(alg, struct hash_alg_common, base);
130}
131
132static inline struct hash_alg_common *crypto_hash_alg_common(
133 struct crypto_ahash *tfm)
134{
135 return __crypto_hash_alg_common(crypto_ahash_tfm(tfm)->__crt_alg);
90} 136}
91 137
92static inline unsigned int crypto_ahash_digestsize(struct crypto_ahash *tfm) 138static inline unsigned int crypto_ahash_digestsize(struct crypto_ahash *tfm)
93{ 139{
94 return crypto_ahash_crt(tfm)->digestsize; 140 return tfm->digestsize;
141}
142
143static inline unsigned int crypto_ahash_statesize(struct crypto_ahash *tfm)
144{
145 return crypto_hash_alg_common(tfm)->statesize;
95} 146}
96 147
97static inline u32 crypto_ahash_get_flags(struct crypto_ahash *tfm) 148static inline u32 crypto_ahash_get_flags(struct crypto_ahash *tfm)
@@ -117,7 +168,7 @@ static inline struct crypto_ahash *crypto_ahash_reqtfm(
117 168
118static inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm) 169static inline unsigned int crypto_ahash_reqsize(struct crypto_ahash *tfm)
119{ 170{
120 return crypto_ahash_crt(tfm)->reqsize; 171 return tfm->reqsize;
121} 172}
122 173
123static inline void *ahash_request_ctx(struct ahash_request *req) 174static inline void *ahash_request_ctx(struct ahash_request *req)
@@ -128,41 +179,37 @@ static inline void *ahash_request_ctx(struct ahash_request *req)
128static inline int crypto_ahash_setkey(struct crypto_ahash *tfm, 179static inline int crypto_ahash_setkey(struct crypto_ahash *tfm,
129 const u8 *key, unsigned int keylen) 180 const u8 *key, unsigned int keylen)
130{ 181{
131 struct ahash_tfm *crt = crypto_ahash_crt(tfm); 182 return tfm->setkey(tfm, key, keylen);
132
133 return crt->setkey(tfm, key, keylen);
134} 183}
135 184
136static inline int crypto_ahash_digest(struct ahash_request *req) 185static inline int crypto_ahash_digest(struct ahash_request *req)
137{ 186{
138 struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); 187 return crypto_ahash_reqtfm(req)->digest(req);
139 return crt->digest(req);
140} 188}
141 189
142static inline void crypto_ahash_export(struct ahash_request *req, u8 *out) 190static inline int crypto_ahash_export(struct ahash_request *req, void *out)
143{ 191{
144 memcpy(out, ahash_request_ctx(req), 192 return crypto_ahash_reqtfm(req)->export(req, out);
145 crypto_ahash_reqsize(crypto_ahash_reqtfm(req)));
146} 193}
147 194
148int crypto_ahash_import(struct ahash_request *req, const u8 *in); 195static inline int crypto_ahash_import(struct ahash_request *req, const void *in)
196{
197 return crypto_ahash_reqtfm(req)->import(req, in);
198}
149 199
150static inline int crypto_ahash_init(struct ahash_request *req) 200static inline int crypto_ahash_init(struct ahash_request *req)
151{ 201{
152 struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); 202 return crypto_ahash_reqtfm(req)->init(req);
153 return crt->init(req);
154} 203}
155 204
156static inline int crypto_ahash_update(struct ahash_request *req) 205static inline int crypto_ahash_update(struct ahash_request *req)
157{ 206{
158 struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); 207 return crypto_ahash_reqtfm(req)->update(req);
159 return crt->update(req);
160} 208}
161 209
162static inline int crypto_ahash_final(struct ahash_request *req) 210static inline int crypto_ahash_final(struct ahash_request *req)
163{ 211{
164 struct ahash_tfm *crt = crypto_ahash_crt(crypto_ahash_reqtfm(req)); 212 return crypto_ahash_reqtfm(req)->final(req);
165 return crt->final(req);
166} 213}
167 214
168static inline void ahash_request_set_tfm(struct ahash_request *req, 215static inline void ahash_request_set_tfm(struct ahash_request *req,