diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2006-08-21 10:06:54 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2006-09-20 21:41:51 -0400 |
commit | e853c3cfa8cc24869ecd2526e589bcb176bc12e9 (patch) | |
tree | 24ad223420bdea868e891676ebb7285e3c477a05 /crypto | |
parent | 8f21cf0d2bae04ece761595036c9da8328b279aa (diff) |
[CRYPTO] api: Added crypto_type support
This patch adds the crypto_type structure which will be used for all new
crypto algorithm types, beginning with block ciphers.
The primary purpose of this abstraction is to allow different crypto_type
objects for crypto algorithms of the same type, in particular, there will
be a different crypto_type objects for asynchronous algorithms.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/api.c | 32 | ||||
-rw-r--r-- | crypto/proc.c | 5 |
2 files changed, 27 insertions, 10 deletions
diff --git a/crypto/api.c b/crypto/api.c index bc4b7901acdf..edaa843d8e83 100644 --- a/crypto/api.c +++ b/crypto/api.c | |||
@@ -226,17 +226,18 @@ static int crypto_init_flags(struct crypto_tfm *tfm, u32 flags) | |||
226 | 226 | ||
227 | case CRYPTO_ALG_TYPE_COMPRESS: | 227 | case CRYPTO_ALG_TYPE_COMPRESS: |
228 | return crypto_init_compress_flags(tfm, flags); | 228 | return crypto_init_compress_flags(tfm, flags); |
229 | |||
230 | default: | ||
231 | break; | ||
232 | } | 229 | } |
233 | 230 | ||
234 | BUG(); | 231 | return 0; |
235 | return -EINVAL; | ||
236 | } | 232 | } |
237 | 233 | ||
238 | static int crypto_init_ops(struct crypto_tfm *tfm) | 234 | static int crypto_init_ops(struct crypto_tfm *tfm) |
239 | { | 235 | { |
236 | const struct crypto_type *type = tfm->__crt_alg->cra_type; | ||
237 | |||
238 | if (type) | ||
239 | return type->init(tfm); | ||
240 | |||
240 | switch (crypto_tfm_alg_type(tfm)) { | 241 | switch (crypto_tfm_alg_type(tfm)) { |
241 | case CRYPTO_ALG_TYPE_CIPHER: | 242 | case CRYPTO_ALG_TYPE_CIPHER: |
242 | return crypto_init_cipher_ops(tfm); | 243 | return crypto_init_cipher_ops(tfm); |
@@ -257,6 +258,14 @@ static int crypto_init_ops(struct crypto_tfm *tfm) | |||
257 | 258 | ||
258 | static void crypto_exit_ops(struct crypto_tfm *tfm) | 259 | static void crypto_exit_ops(struct crypto_tfm *tfm) |
259 | { | 260 | { |
261 | const struct crypto_type *type = tfm->__crt_alg->cra_type; | ||
262 | |||
263 | if (type) { | ||
264 | if (type->exit) | ||
265 | type->exit(tfm); | ||
266 | return; | ||
267 | } | ||
268 | |||
260 | switch (crypto_tfm_alg_type(tfm)) { | 269 | switch (crypto_tfm_alg_type(tfm)) { |
261 | case CRYPTO_ALG_TYPE_CIPHER: | 270 | case CRYPTO_ALG_TYPE_CIPHER: |
262 | crypto_exit_cipher_ops(tfm); | 271 | crypto_exit_cipher_ops(tfm); |
@@ -278,26 +287,31 @@ static void crypto_exit_ops(struct crypto_tfm *tfm) | |||
278 | 287 | ||
279 | static unsigned int crypto_ctxsize(struct crypto_alg *alg, int flags) | 288 | static unsigned int crypto_ctxsize(struct crypto_alg *alg, int flags) |
280 | { | 289 | { |
290 | const struct crypto_type *type = alg->cra_type; | ||
281 | unsigned int len; | 291 | unsigned int len; |
282 | 292 | ||
293 | len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1); | ||
294 | if (type) | ||
295 | return len + type->ctxsize(alg); | ||
296 | |||
283 | switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { | 297 | switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { |
284 | default: | 298 | default: |
285 | BUG(); | 299 | BUG(); |
286 | 300 | ||
287 | case CRYPTO_ALG_TYPE_CIPHER: | 301 | case CRYPTO_ALG_TYPE_CIPHER: |
288 | len = crypto_cipher_ctxsize(alg, flags); | 302 | len += crypto_cipher_ctxsize(alg, flags); |
289 | break; | 303 | break; |
290 | 304 | ||
291 | case CRYPTO_ALG_TYPE_DIGEST: | 305 | case CRYPTO_ALG_TYPE_DIGEST: |
292 | len = crypto_digest_ctxsize(alg, flags); | 306 | len += crypto_digest_ctxsize(alg, flags); |
293 | break; | 307 | break; |
294 | 308 | ||
295 | case CRYPTO_ALG_TYPE_COMPRESS: | 309 | case CRYPTO_ALG_TYPE_COMPRESS: |
296 | len = crypto_compress_ctxsize(alg, flags); | 310 | len += crypto_compress_ctxsize(alg, flags); |
297 | break; | 311 | break; |
298 | } | 312 | } |
299 | 313 | ||
300 | return len + (alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1)); | 314 | return len; |
301 | } | 315 | } |
302 | 316 | ||
303 | void crypto_shoot_alg(struct crypto_alg *alg) | 317 | void crypto_shoot_alg(struct crypto_alg *alg) |
diff --git a/crypto/proc.c b/crypto/proc.c index 9e573b17e887..dabce0676f63 100644 --- a/crypto/proc.c +++ b/crypto/proc.c | |||
@@ -78,7 +78,10 @@ static int c_show(struct seq_file *m, void *p) | |||
78 | seq_printf(m, "type : compression\n"); | 78 | seq_printf(m, "type : compression\n"); |
79 | break; | 79 | break; |
80 | default: | 80 | default: |
81 | seq_printf(m, "type : unknown\n"); | 81 | if (alg->cra_type && alg->cra_type->show) |
82 | alg->cra_type->show(m, alg); | ||
83 | else | ||
84 | seq_printf(m, "type : unknown\n"); | ||
82 | break; | 85 | break; |
83 | } | 86 | } |
84 | 87 | ||