aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/algboss.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2008-08-03 09:15:23 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2008-08-29 01:49:57 -0400
commit73d3864a4823abda19ebc4387b6ddcbf416e3a77 (patch)
tree2939754dc2532f412c34a974e5f22dde112c525d /crypto/algboss.c
parentda7f033ddc9fdebb3223b0bf88a2a2ab5b797608 (diff)
crypto: api - Use test infrastructure
This patch makes use of the new testing infrastructure by requiring algorithms to pass a run-time test before they're made available to users. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/algboss.c')
-rw-r--r--crypto/algboss.c75
1 files changed, 70 insertions, 5 deletions
diff --git a/crypto/algboss.c b/crypto/algboss.c
index 2662ac014841..ed9f663c82c6 100644
--- a/crypto/algboss.c
+++ b/crypto/algboss.c
@@ -45,6 +45,15 @@ struct cryptomgr_param {
45 45
46 char larval[CRYPTO_MAX_ALG_NAME]; 46 char larval[CRYPTO_MAX_ALG_NAME];
47 char template[CRYPTO_MAX_ALG_NAME]; 47 char template[CRYPTO_MAX_ALG_NAME];
48
49 u32 otype;
50 u32 omask;
51};
52
53struct crypto_test_param {
54 char driver[CRYPTO_MAX_ALG_NAME];
55 char alg[CRYPTO_MAX_ALG_NAME];
56 u32 type;
48}; 57};
49 58
50static int cryptomgr_probe(void *data) 59static int cryptomgr_probe(void *data)
@@ -76,8 +85,7 @@ out:
76 module_put_and_exit(0); 85 module_put_and_exit(0);
77 86
78err: 87err:
79 crypto_larval_error(param->larval, param->type.data.type, 88 crypto_larval_error(param->larval, param->otype, param->omask);
80 param->type.data.mask);
81 goto out; 89 goto out;
82} 90}
83 91
@@ -169,13 +177,68 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
169 177
170 param->type.attr.rta_len = sizeof(param->type); 178 param->type.attr.rta_len = sizeof(param->type);
171 param->type.attr.rta_type = CRYPTOA_TYPE; 179 param->type.attr.rta_type = CRYPTOA_TYPE;
172 param->type.data.type = larval->alg.cra_flags; 180 param->type.data.type = larval->alg.cra_flags & ~CRYPTO_ALG_TESTED;
173 param->type.data.mask = larval->mask; 181 param->type.data.mask = larval->mask & ~CRYPTO_ALG_TESTED;
174 param->tb[0] = &param->type.attr; 182 param->tb[0] = &param->type.attr;
175 183
184 param->otype = larval->alg.cra_flags;
185 param->omask = larval->mask;
186
176 memcpy(param->larval, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME); 187 memcpy(param->larval, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME);
177 188
178 thread = kthread_run(cryptomgr_probe, param, "cryptomgr"); 189 thread = kthread_run(cryptomgr_probe, param, "cryptomgr_probe");
190 if (IS_ERR(thread))
191 goto err_free_param;
192
193 return NOTIFY_STOP;
194
195err_free_param:
196 kfree(param);
197err_put_module:
198 module_put(THIS_MODULE);
199err:
200 return NOTIFY_OK;
201}
202
203static int cryptomgr_test(void *data)
204{
205 struct crypto_test_param *param = data;
206 u32 type = param->type;
207 int err = 0;
208
209 if (!((type ^ CRYPTO_ALG_TYPE_BLKCIPHER) &
210 CRYPTO_ALG_TYPE_BLKCIPHER_MASK) && !(type & CRYPTO_ALG_GENIV))
211 goto skiptest;
212
213 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER)
214 goto skiptest;
215
216 err = alg_test(param->driver, param->alg, 0, CRYPTO_ALG_TESTED);
217
218skiptest:
219 crypto_alg_tested(param->driver, err);
220
221 kfree(param);
222 module_put_and_exit(0);
223}
224
225static int cryptomgr_schedule_test(struct crypto_alg *alg)
226{
227 struct task_struct *thread;
228 struct crypto_test_param *param;
229
230 if (!try_module_get(THIS_MODULE))
231 goto err;
232
233 param = kzalloc(sizeof(*param), GFP_KERNEL);
234 if (!param)
235 goto err_put_module;
236
237 memcpy(param->driver, alg->cra_driver_name, sizeof(param->driver));
238 memcpy(param->alg, alg->cra_name, sizeof(param->alg));
239 param->type = alg->cra_flags;
240
241 thread = kthread_run(cryptomgr_test, param, "cryptomgr_test");
179 if (IS_ERR(thread)) 242 if (IS_ERR(thread))
180 goto err_free_param; 243 goto err_free_param;
181 244
@@ -195,6 +258,8 @@ static int cryptomgr_notify(struct notifier_block *this, unsigned long msg,
195 switch (msg) { 258 switch (msg) {
196 case CRYPTO_MSG_ALG_REQUEST: 259 case CRYPTO_MSG_ALG_REQUEST:
197 return cryptomgr_schedule_probe(data); 260 return cryptomgr_schedule_probe(data);
261 case CRYPTO_MSG_ALG_REGISTER:
262 return cryptomgr_schedule_test(data);
198 } 263 }
199 264
200 return NOTIFY_DONE; 265 return NOTIFY_DONE;