aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crypto/tcrypt.c76
1 files changed, 57 insertions, 19 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index e0ea4d53f25e..e99cb4bc5463 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -104,22 +104,30 @@ static void test_hash(char *algo, struct hash_testvec *template,
104 unsigned int i, j, k, temp; 104 unsigned int i, j, k, temp;
105 struct scatterlist sg[8]; 105 struct scatterlist sg[8];
106 char result[64]; 106 char result[64];
107 struct crypto_hash *tfm; 107 struct crypto_ahash *tfm;
108 struct hash_desc desc; 108 struct ahash_request *req;
109 struct tcrypt_result tresult;
109 int ret; 110 int ret;
110 void *hash_buff; 111 void *hash_buff;
111 112
112 printk("\ntesting %s\n", algo); 113 printk("\ntesting %s\n", algo);
113 114
114 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); 115 init_completion(&tresult.completion);
116
117 tfm = crypto_alloc_ahash(algo, 0, 0);
115 if (IS_ERR(tfm)) { 118 if (IS_ERR(tfm)) {
116 printk("failed to load transform for %s: %ld\n", algo, 119 printk("failed to load transform for %s: %ld\n", algo,
117 PTR_ERR(tfm)); 120 PTR_ERR(tfm));
118 return; 121 return;
119 } 122 }
120 123
121 desc.tfm = tfm; 124 req = ahash_request_alloc(tfm, GFP_KERNEL);
122 desc.flags = 0; 125 if (!req) {
126 printk(KERN_ERR "failed to allocate request for %s\n", algo);
127 goto out_noreq;
128 }
129 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
130 tcrypt_complete, &tresult);
123 131
124 for (i = 0; i < tcount; i++) { 132 for (i = 0; i < tcount; i++) {
125 printk("test %u:\n", i + 1); 133 printk("test %u:\n", i + 1);
@@ -133,8 +141,9 @@ static void test_hash(char *algo, struct hash_testvec *template,
133 sg_init_one(&sg[0], hash_buff, template[i].psize); 141 sg_init_one(&sg[0], hash_buff, template[i].psize);
134 142
135 if (template[i].ksize) { 143 if (template[i].ksize) {
136 ret = crypto_hash_setkey(tfm, template[i].key, 144 crypto_ahash_clear_flags(tfm, ~0);
137 template[i].ksize); 145 ret = crypto_ahash_setkey(tfm, template[i].key,
146 template[i].ksize);
138 if (ret) { 147 if (ret) {
139 printk("setkey() failed ret=%d\n", ret); 148 printk("setkey() failed ret=%d\n", ret);
140 kfree(hash_buff); 149 kfree(hash_buff);
@@ -142,17 +151,30 @@ static void test_hash(char *algo, struct hash_testvec *template,
142 } 151 }
143 } 152 }
144 153
145 ret = crypto_hash_digest(&desc, sg, template[i].psize, result); 154 ahash_request_set_crypt(req, sg, result, template[i].psize);
146 if (ret) { 155 ret = crypto_ahash_digest(req);
156 switch (ret) {
157 case 0:
158 break;
159 case -EINPROGRESS:
160 case -EBUSY:
161 ret = wait_for_completion_interruptible(
162 &tresult.completion);
163 if (!ret && !(ret = tresult.err)) {
164 INIT_COMPLETION(tresult.completion);
165 break;
166 }
167 /* fall through */
168 default:
147 printk("digest () failed ret=%d\n", ret); 169 printk("digest () failed ret=%d\n", ret);
148 kfree(hash_buff); 170 kfree(hash_buff);
149 goto out; 171 goto out;
150 } 172 }
151 173
152 hexdump(result, crypto_hash_digestsize(tfm)); 174 hexdump(result, crypto_ahash_digestsize(tfm));
153 printk("%s\n", 175 printk("%s\n",
154 memcmp(result, template[i].digest, 176 memcmp(result, template[i].digest,
155 crypto_hash_digestsize(tfm)) ? 177 crypto_ahash_digestsize(tfm)) ?
156 "fail" : "pass"); 178 "fail" : "pass");
157 kfree(hash_buff); 179 kfree(hash_buff);
158 } 180 }
@@ -181,8 +203,9 @@ static void test_hash(char *algo, struct hash_testvec *template,
181 } 203 }
182 204
183 if (template[i].ksize) { 205 if (template[i].ksize) {
184 ret = crypto_hash_setkey(tfm, template[i].key, 206 crypto_ahash_clear_flags(tfm, ~0);
185 template[i].ksize); 207 ret = crypto_ahash_setkey(tfm, template[i].key,
208 template[i].ksize);
186 209
187 if (ret) { 210 if (ret) {
188 printk("setkey() failed ret=%d\n", ret); 211 printk("setkey() failed ret=%d\n", ret);
@@ -190,23 +213,38 @@ static void test_hash(char *algo, struct hash_testvec *template,
190 } 213 }
191 } 214 }
192 215
193 ret = crypto_hash_digest(&desc, sg, template[i].psize, 216 ahash_request_set_crypt(req, sg, result,
194 result); 217 template[i].psize);
195 if (ret) { 218 ret = crypto_ahash_digest(req);
219 switch (ret) {
220 case 0:
221 break;
222 case -EINPROGRESS:
223 case -EBUSY:
224 ret = wait_for_completion_interruptible(
225 &tresult.completion);
226 if (!ret && !(ret = tresult.err)) {
227 INIT_COMPLETION(tresult.completion);
228 break;
229 }
230 /* fall through */
231 default:
196 printk("digest () failed ret=%d\n", ret); 232 printk("digest () failed ret=%d\n", ret);
197 goto out; 233 goto out;
198 } 234 }
199 235
200 hexdump(result, crypto_hash_digestsize(tfm)); 236 hexdump(result, crypto_ahash_digestsize(tfm));
201 printk("%s\n", 237 printk("%s\n",
202 memcmp(result, template[i].digest, 238 memcmp(result, template[i].digest,
203 crypto_hash_digestsize(tfm)) ? 239 crypto_ahash_digestsize(tfm)) ?
204 "fail" : "pass"); 240 "fail" : "pass");
205 } 241 }
206 } 242 }
207 243
208out: 244out:
209 crypto_free_hash(tfm); 245 ahash_request_free(req);
246out_noreq:
247 crypto_free_ahash(tfm);
210} 248}
211 249
212static void test_aead(char *algo, int enc, struct aead_testvec *template, 250static void test_aead(char *algo, int enc, struct aead_testvec *template,