aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/hash.c')
-rw-r--r--crypto/hash.c102
1 files changed, 93 insertions, 9 deletions
diff --git a/crypto/hash.c b/crypto/hash.c
index 7dcff671c19b..cb86b19fd105 100644
--- a/crypto/hash.c
+++ b/crypto/hash.c
@@ -9,6 +9,7 @@
9 * any later version. 9 * any later version.
10 */ 10 */
11 11
12#include <crypto/internal/hash.h>
12#include <linux/errno.h> 13#include <linux/errno.h>
13#include <linux/kernel.h> 14#include <linux/kernel.h>
14#include <linux/module.h> 15#include <linux/module.h>
@@ -59,24 +60,107 @@ static int hash_setkey(struct crypto_hash *crt, const u8 *key,
59 return alg->setkey(crt, key, keylen); 60 return alg->setkey(crt, key, keylen);
60} 61}
61 62
62static int crypto_init_hash_ops(struct crypto_tfm *tfm, u32 type, u32 mask) 63static int hash_async_setkey(struct crypto_ahash *tfm_async, const u8 *key,
64 unsigned int keylen)
65{
66 struct crypto_tfm *tfm = crypto_ahash_tfm(tfm_async);
67 struct crypto_hash *tfm_hash = __crypto_hash_cast(tfm);
68 struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
69
70 return alg->setkey(tfm_hash, key, keylen);
71}
72
73static int hash_async_init(struct ahash_request *req)
74{
75 struct crypto_tfm *tfm = req->base.tfm;
76 struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
77 struct hash_desc desc = {
78 .tfm = __crypto_hash_cast(tfm),
79 .flags = req->base.flags,
80 };
81
82 return alg->init(&desc);
83}
84
85static int hash_async_update(struct ahash_request *req)
86{
87 struct crypto_tfm *tfm = req->base.tfm;
88 struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
89 struct hash_desc desc = {
90 .tfm = __crypto_hash_cast(tfm),
91 .flags = req->base.flags,
92 };
93
94 return alg->update(&desc, req->src, req->nbytes);
95}
96
97static int hash_async_final(struct ahash_request *req)
98{
99 struct crypto_tfm *tfm = req->base.tfm;
100 struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
101 struct hash_desc desc = {
102 .tfm = __crypto_hash_cast(tfm),
103 .flags = req->base.flags,
104 };
105
106 return alg->final(&desc, req->result);
107}
108
109static int hash_async_digest(struct ahash_request *req)
110{
111 struct crypto_tfm *tfm = req->base.tfm;
112 struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
113 struct hash_desc desc = {
114 .tfm = __crypto_hash_cast(tfm),
115 .flags = req->base.flags,
116 };
117
118 return alg->digest(&desc, req->src, req->nbytes, req->result);
119}
120
121static int crypto_init_hash_ops_async(struct crypto_tfm *tfm)
122{
123 struct ahash_tfm *crt = &tfm->crt_ahash;
124 struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
125
126 crt->init = hash_async_init;
127 crt->update = hash_async_update;
128 crt->final = hash_async_final;
129 crt->digest = hash_async_digest;
130 crt->setkey = hash_async_setkey;
131 crt->digestsize = alg->digestsize;
132
133 return 0;
134}
135
136static int crypto_init_hash_ops_sync(struct crypto_tfm *tfm)
63{ 137{
64 struct hash_tfm *crt = &tfm->crt_hash; 138 struct hash_tfm *crt = &tfm->crt_hash;
65 struct hash_alg *alg = &tfm->__crt_alg->cra_hash; 139 struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
66 140
67 if (alg->digestsize > crypto_tfm_alg_blocksize(tfm)) 141 crt->init = alg->init;
68 return -EINVAL; 142 crt->update = alg->update;
69 143 crt->final = alg->final;
70 crt->init = alg->init; 144 crt->digest = alg->digest;
71 crt->update = alg->update; 145 crt->setkey = hash_setkey;
72 crt->final = alg->final;
73 crt->digest = alg->digest;
74 crt->setkey = hash_setkey;
75 crt->digestsize = alg->digestsize; 146 crt->digestsize = alg->digestsize;
76 147
77 return 0; 148 return 0;
78} 149}
79 150
151static int crypto_init_hash_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
152{
153 struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
154
155 if (alg->digestsize > PAGE_SIZE / 8)
156 return -EINVAL;
157
158 if ((mask & CRYPTO_ALG_TYPE_HASH_MASK) != CRYPTO_ALG_TYPE_HASH_MASK)
159 return crypto_init_hash_ops_async(tfm);
160 else
161 return crypto_init_hash_ops_sync(tfm);
162}
163
80static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg) 164static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg)
81 __attribute__ ((unused)); 165 __attribute__ ((unused));
82static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg) 166static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg)