aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/cryptomgr.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-01-01 02:37:02 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2007-05-02 00:38:31 -0400
commitebc610e5bc76df073221e64e86c3f7533a09ea40 (patch)
treed53f4fa3da412f6df4b5891e23ca7c7607a3a5ce /crypto/cryptomgr.c
parent6158efc09016d3186263f6fd3a50667446ec4008 (diff)
[CRYPTO] templates: Pass type/mask when creating instances
This patch passes the type/mask along when constructing instances of templates. This is in preparation for templates that may support multiple types of instances depending on what is requested. For example, the planned software async crypto driver will use this construct. For the moment this allows us to check whether the instance constructed is of the correct type and avoid returning success if the type does not match. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/cryptomgr.c')
-rw-r--r--crypto/cryptomgr.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/crypto/cryptomgr.c b/crypto/cryptomgr.c
index 2ebffb84f1d9..7a3df9b41218 100644
--- a/crypto/cryptomgr.c
+++ b/crypto/cryptomgr.c
@@ -26,14 +26,19 @@
26struct cryptomgr_param { 26struct cryptomgr_param {
27 struct work_struct work; 27 struct work_struct work;
28 28
29 struct rtattr *tb[CRYPTOA_MAX];
30
31 struct {
32 struct rtattr attr;
33 struct crypto_attr_type data;
34 } type;
35
29 struct { 36 struct {
30 struct rtattr attr; 37 struct rtattr attr;
31 struct crypto_attr_alg data; 38 struct crypto_attr_alg data;
32 } alg; 39 } alg;
33 40
34 struct { 41 struct {
35 u32 type;
36 u32 mask;
37 char name[CRYPTO_MAX_ALG_NAME]; 42 char name[CRYPTO_MAX_ALG_NAME];
38 } larval; 43 } larval;
39 44
@@ -53,7 +58,7 @@ static void cryptomgr_probe(struct work_struct *work)
53 goto err; 58 goto err;
54 59
55 do { 60 do {
56 inst = tmpl->alloc(&param->alg, sizeof(param->alg)); 61 inst = tmpl->alloc(param->tb);
57 if (IS_ERR(inst)) 62 if (IS_ERR(inst))
58 err = PTR_ERR(inst); 63 err = PTR_ERR(inst);
59 else if ((err = crypto_register_instance(tmpl, inst))) 64 else if ((err = crypto_register_instance(tmpl, inst)))
@@ -70,8 +75,8 @@ out:
70 return; 75 return;
71 76
72err: 77err:
73 crypto_larval_error(param->larval.name, param->larval.type, 78 crypto_larval_error(param->larval.name, param->type.data.type,
74 param->larval.mask); 79 param->type.data.mask);
75 goto out; 80 goto out;
76} 81}
77 82
@@ -82,7 +87,7 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
82 const char *p; 87 const char *p;
83 unsigned int len; 88 unsigned int len;
84 89
85 param = kmalloc(sizeof(*param), GFP_KERNEL); 90 param = kzalloc(sizeof(*param), GFP_KERNEL);
86 if (!param) 91 if (!param)
87 goto err; 92 goto err;
88 93
@@ -94,7 +99,6 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
94 goto err_free_param; 99 goto err_free_param;
95 100
96 memcpy(param->template, name, len); 101 memcpy(param->template, name, len);
97 param->template[len] = 0;
98 102
99 name = p + 1; 103 name = p + 1;
100 for (p = name; isalnum(*p) || *p == '-' || *p == '_'; p++) 104 for (p = name; isalnum(*p) || *p == '-' || *p == '_'; p++)
@@ -104,14 +108,18 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
104 if (!len || *p != ')' || p[1]) 108 if (!len || *p != ')' || p[1])
105 goto err_free_param; 109 goto err_free_param;
106 110
111 param->type.attr.rta_len = sizeof(param->type);
112 param->type.attr.rta_type = CRYPTOA_TYPE;
113 param->type.data.type = larval->alg.cra_flags;
114 param->type.data.mask = larval->mask;
115 param->tb[CRYPTOA_TYPE - 1] = &param->type.attr;
116
107 param->alg.attr.rta_len = sizeof(param->alg); 117 param->alg.attr.rta_len = sizeof(param->alg);
108 param->alg.attr.rta_type = CRYPTOA_ALG; 118 param->alg.attr.rta_type = CRYPTOA_ALG;
109 memcpy(param->alg.data.name, name, len); 119 memcpy(param->alg.data.name, name, len);
110 param->alg.data.name[len] = 0; 120 param->tb[CRYPTOA_ALG - 1] = &param->alg.attr;
111 121
112 memcpy(param->larval.name, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME); 122 memcpy(param->larval.name, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME);
113 param->larval.type = larval->alg.cra_flags;
114 param->larval.mask = larval->mask;
115 123
116 INIT_WORK(&param->work, cryptomgr_probe); 124 INIT_WORK(&param->work, cryptomgr_probe);
117 schedule_work(&param->work); 125 schedule_work(&param->work);