aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/cryptomgr.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-08-29 07:27:26 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:55:40 -0400
commit39e1ee011f42dbbcb0210c73ea728ae54cf63b06 (patch)
tree0689571972f9678f93cec8bd7f3dac2934c5bc59 /crypto/cryptomgr.c
parent1ae978208e2ee9ba1b01d309164bc5e590cd242d (diff)
[CRYPTO] api: Add support for multiple template parameters
This patch adds support for having multiple parameters to a template, separated by a comma. It also adds support for integer parameters in addition to the current algorithm parameter type. This will be used by the authenc template which will have four parameters: the authentication algorithm, the encryption algorithm, the authentication size and the encryption key length. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/cryptomgr.c')
-rw-r--r--crypto/cryptomgr.c95
1 files changed, 70 insertions, 25 deletions
diff --git a/crypto/cryptomgr.c b/crypto/cryptomgr.c
index e5fb7cca5107..c83884fec5f9 100644
--- a/crypto/cryptomgr.c
+++ b/crypto/cryptomgr.c
@@ -24,22 +24,26 @@
24#include "internal.h" 24#include "internal.h"
25 25
26struct cryptomgr_param { 26struct cryptomgr_param {
27 struct rtattr *tb[CRYPTOA_MAX]; 27 struct rtattr *tb[CRYPTO_MAX_ATTRS + 2];
28 28
29 struct { 29 struct {
30 struct rtattr attr; 30 struct rtattr attr;
31 struct crypto_attr_type data; 31 struct crypto_attr_type data;
32 } type; 32 } type;
33 33
34 struct { 34 union {
35 struct rtattr attr; 35 struct rtattr attr;
36 struct crypto_attr_alg data; 36 struct {
37 } alg; 37 struct rtattr attr;
38 38 struct crypto_attr_alg data;
39 struct { 39 } alg;
40 char name[CRYPTO_MAX_ALG_NAME]; 40 struct {
41 } larval; 41 struct rtattr attr;
42 42 struct crypto_attr_u32 data;
43 } nu32;
44 } attrs[CRYPTO_MAX_ATTRS];
45
46 char larval[CRYPTO_MAX_ALG_NAME];
43 char template[CRYPTO_MAX_ALG_NAME]; 47 char template[CRYPTO_MAX_ALG_NAME];
44}; 48};
45 49
@@ -72,7 +76,7 @@ out:
72 module_put_and_exit(0); 76 module_put_and_exit(0);
73 77
74err: 78err:
75 crypto_larval_error(param->larval.name, param->type.data.type, 79 crypto_larval_error(param->larval, param->type.data.type,
76 param->type.data.mask); 80 param->type.data.mask);
77 goto out; 81 goto out;
78} 82}
@@ -84,6 +88,7 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
84 const char *name = larval->alg.cra_name; 88 const char *name = larval->alg.cra_name;
85 const char *p; 89 const char *p;
86 unsigned int len; 90 unsigned int len;
91 int i;
87 92
88 if (!try_module_get(THIS_MODULE)) 93 if (!try_module_get(THIS_MODULE))
89 goto err; 94 goto err;
@@ -101,33 +106,73 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
101 106
102 memcpy(param->template, name, len); 107 memcpy(param->template, name, len);
103 108
104 name = p + 1; 109 i = 0;
105 len = 0; 110 for (;;) {
106 for (p = name; *p; p++) { 111 int notnum = 0;
107 for (; isalnum(*p) || *p == '-' || *p == '_' || *p == '('; p++)
108 ;
109 112
110 if (*p != ')') 113 name = ++p;
111 goto err_free_param; 114 len = 0;
115
116 for (; isalnum(*p) || *p == '-' || *p == '_'; p++)
117 notnum |= !isdigit(*p);
118
119 if (*p == '(') {
120 int recursion = 0;
121
122 for (;;) {
123 if (!*++p)
124 goto err_free_param;
125 if (*p == '(')
126 recursion++;
127 else if (*p == ')' && !recursion--)
128 break;
129 }
130
131 notnum = 1;
132 }
112 133
113 len = p - name; 134 len = p - name;
135 if (!len)
136 goto err_free_param;
137
138 if (notnum) {
139 param->attrs[i].alg.attr.rta_len =
140 sizeof(param->attrs[i].alg);
141 param->attrs[i].alg.attr.rta_type = CRYPTOA_ALG;
142 memcpy(param->attrs[i].alg.data.name, name, len);
143 } else {
144 param->attrs[i].nu32.attr.rta_len =
145 sizeof(param->attrs[i].nu32);
146 param->attrs[i].nu32.attr.rta_type = CRYPTOA_U32;
147 param->attrs[i].nu32.data.num =
148 simple_strtol(name, NULL, 0);
149 }
150
151 param->tb[i + 1] = &param->attrs[i].attr;
152 i++;
153
154 if (WARN_ON(i >= CRYPTO_MAX_ATTRS))
155 goto err_free_param;
156
157 if (*p == ')')
158 break;
159
160 if (*p != ',')
161 goto err_free_param;
114 } 162 }
115 163
116 if (!len || name[len + 1]) 164 if (!i)
117 goto err_free_param; 165 goto err_free_param;
118 166
167 param->tb[i + 1] = NULL;
168
119 param->type.attr.rta_len = sizeof(param->type); 169 param->type.attr.rta_len = sizeof(param->type);
120 param->type.attr.rta_type = CRYPTOA_TYPE; 170 param->type.attr.rta_type = CRYPTOA_TYPE;
121 param->type.data.type = larval->alg.cra_flags; 171 param->type.data.type = larval->alg.cra_flags;
122 param->type.data.mask = larval->mask; 172 param->type.data.mask = larval->mask;
123 param->tb[CRYPTOA_TYPE - 1] = &param->type.attr; 173 param->tb[0] = &param->type.attr;
124
125 param->alg.attr.rta_len = sizeof(param->alg);
126 param->alg.attr.rta_type = CRYPTOA_ALG;
127 memcpy(param->alg.data.name, name, len);
128 param->tb[CRYPTOA_ALG - 1] = &param->alg.attr;
129 174
130 memcpy(param->larval.name, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME); 175 memcpy(param->larval, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME);
131 176
132 thread = kthread_run(cryptomgr_probe, param, "cryptomgr"); 177 thread = kthread_run(cryptomgr_probe, param, "cryptomgr");
133 if (IS_ERR(thread)) 178 if (IS_ERR(thread))