aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crypto/ablkcipher.c25
-rw-r--r--include/crypto/algapi.h22
-rw-r--r--include/crypto/internal/skcipher.h51
-rw-r--r--include/linux/crypto.h26
4 files changed, 108 insertions, 16 deletions
diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
index 2731acb86e7d..0083140304d2 100644
--- a/crypto/ablkcipher.c
+++ b/crypto/ablkcipher.c
@@ -13,14 +13,16 @@
13 * 13 *
14 */ 14 */
15 15
16#include <crypto/algapi.h> 16#include <crypto/internal/skcipher.h>
17#include <linux/errno.h> 17#include <linux/err.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/seq_file.h> 22#include <linux/seq_file.h>
23 23
24#include "internal.h"
25
24static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key, 26static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
25 unsigned int keylen) 27 unsigned int keylen)
26{ 28{
@@ -105,5 +107,24 @@ const struct crypto_type crypto_ablkcipher_type = {
105}; 107};
106EXPORT_SYMBOL_GPL(crypto_ablkcipher_type); 108EXPORT_SYMBOL_GPL(crypto_ablkcipher_type);
107 109
110int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
111 u32 type, u32 mask)
112{
113 struct crypto_alg *alg;
114 int err;
115
116 type = crypto_skcipher_type(type);
117 mask = crypto_skcipher_mask(mask);
118
119 alg = crypto_alg_mod_lookup(name, type, mask);
120 if (IS_ERR(alg))
121 return PTR_ERR(alg);
122
123 err = crypto_init_spawn(&spawn->base, alg, spawn->base.inst, mask);
124 crypto_mod_put(alg);
125 return err;
126}
127EXPORT_SYMBOL_GPL(crypto_grab_skcipher);
128
108MODULE_LICENSE("GPL"); 129MODULE_LICENSE("GPL");
109MODULE_DESCRIPTION("Asynchronous block chaining cipher type"); 130MODULE_DESCRIPTION("Asynchronous block chaining cipher type");
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
index 726a765e5ec6..fda1759ffe2d 100644
--- a/include/crypto/algapi.h
+++ b/include/crypto/algapi.h
@@ -111,6 +111,12 @@ void crypto_drop_spawn(struct crypto_spawn *spawn);
111struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type, 111struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type,
112 u32 mask); 112 u32 mask);
113 113
114static inline void crypto_set_spawn(struct crypto_spawn *spawn,
115 struct crypto_instance *inst)
116{
117 spawn->inst = inst;
118}
119
114struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb); 120struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb);
115int crypto_check_attr_type(struct rtattr **tb, u32 type); 121int crypto_check_attr_type(struct rtattr **tb, u32 type);
116const char *crypto_attr_alg_name(struct rtattr *rta); 122const char *crypto_attr_alg_name(struct rtattr *rta);
@@ -195,10 +201,9 @@ static inline struct crypto_instance *crypto_aead_alg_instance(
195static inline struct crypto_ablkcipher *crypto_spawn_ablkcipher( 201static inline struct crypto_ablkcipher *crypto_spawn_ablkcipher(
196 struct crypto_spawn *spawn) 202 struct crypto_spawn *spawn)
197{ 203{
198 u32 type = CRYPTO_ALG_TYPE_BLKCIPHER; 204 return __crypto_ablkcipher_cast(
199 u32 mask = CRYPTO_ALG_TYPE_BLKCIPHER_MASK; 205 crypto_spawn_tfm(spawn, crypto_skcipher_type(0),
200 206 crypto_skcipher_mask(0)));
201 return __crypto_ablkcipher_cast(crypto_spawn_tfm(spawn, type, mask));
202} 207}
203 208
204static inline struct crypto_blkcipher *crypto_spawn_blkcipher( 209static inline struct crypto_blkcipher *crypto_spawn_blkcipher(
@@ -308,5 +313,14 @@ static inline struct crypto_alg *crypto_get_attr_alg(struct rtattr **tb,
308 return crypto_attr_alg(tb[1], type, mask); 313 return crypto_attr_alg(tb[1], type, mask);
309} 314}
310 315
316/*
317 * Returns CRYPTO_ALG_ASYNC if type/mask requires the use of sync algorithms.
318 * Otherwise returns zero.
319 */
320static inline int crypto_requires_sync(u32 type, u32 mask)
321{
322 return (type ^ CRYPTO_ALG_ASYNC) & mask & CRYPTO_ALG_ASYNC;
323}
324
311#endif /* _CRYPTO_ALGAPI_H */ 325#endif /* _CRYPTO_ALGAPI_H */
312 326
diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h
new file mode 100644
index 000000000000..87879e64ff4c
--- /dev/null
+++ b/include/crypto/internal/skcipher.h
@@ -0,0 +1,51 @@
1/*
2 * Symmetric key ciphers.
3 *
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#ifndef _CRYPTO_INTERNAL_SKCIPHER_H
14#define _CRYPTO_INTERNAL_SKCIPHER_H
15
16#include <crypto/algapi.h>
17
18struct crypto_skcipher_spawn {
19 struct crypto_spawn base;
20};
21
22static inline void crypto_set_skcipher_spawn(
23 struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst)
24{
25 crypto_set_spawn(&spawn->base, inst);
26}
27
28int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
29 u32 type, u32 mask);
30
31static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn)
32{
33 crypto_drop_spawn(&spawn->base);
34}
35
36static inline struct crypto_alg *crypto_skcipher_spawn_alg(
37 struct crypto_skcipher_spawn *spawn)
38{
39 return spawn->base.alg;
40}
41
42static inline struct crypto_ablkcipher *crypto_spawn_skcipher(
43 struct crypto_skcipher_spawn *spawn)
44{
45 return __crypto_ablkcipher_cast(
46 crypto_spawn_tfm(&spawn->base, crypto_skcipher_type(0),
47 crypto_skcipher_mask(0)));
48}
49
50#endif /* _CRYPTO_INTERNAL_SKCIPHER_H */
51
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index ef7642ed3e42..d6962b409489 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -528,16 +528,26 @@ static inline struct crypto_ablkcipher *__crypto_ablkcipher_cast(
528 return (struct crypto_ablkcipher *)tfm; 528 return (struct crypto_ablkcipher *)tfm;
529} 529}
530 530
531static inline struct crypto_ablkcipher *crypto_alloc_ablkcipher( 531static inline u32 crypto_skcipher_type(u32 type)
532 const char *alg_name, u32 type, u32 mask)
533{ 532{
534 type &= ~CRYPTO_ALG_TYPE_MASK; 533 type &= ~CRYPTO_ALG_TYPE_MASK;
535 mask &= ~CRYPTO_ALG_TYPE_MASK;
536 type |= CRYPTO_ALG_TYPE_BLKCIPHER; 534 type |= CRYPTO_ALG_TYPE_BLKCIPHER;
535 return type;
536}
537
538static inline u32 crypto_skcipher_mask(u32 mask)
539{
540 mask &= ~CRYPTO_ALG_TYPE_MASK;
537 mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK; 541 mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
542 return mask;
543}
538 544
545static inline struct crypto_ablkcipher *crypto_alloc_ablkcipher(
546 const char *alg_name, u32 type, u32 mask)
547{
539 return __crypto_ablkcipher_cast( 548 return __crypto_ablkcipher_cast(
540 crypto_alloc_base(alg_name, type, mask)); 549 crypto_alloc_base(alg_name, crypto_skcipher_type(type),
550 crypto_skcipher_mask(mask)));
541} 551}
542 552
543static inline struct crypto_tfm *crypto_ablkcipher_tfm( 553static inline struct crypto_tfm *crypto_ablkcipher_tfm(
@@ -554,12 +564,8 @@ static inline void crypto_free_ablkcipher(struct crypto_ablkcipher *tfm)
554static inline int crypto_has_ablkcipher(const char *alg_name, u32 type, 564static inline int crypto_has_ablkcipher(const char *alg_name, u32 type,
555 u32 mask) 565 u32 mask)
556{ 566{
557 type &= ~CRYPTO_ALG_TYPE_MASK; 567 return crypto_has_alg(alg_name, crypto_skcipher_type(type),
558 mask &= ~CRYPTO_ALG_TYPE_MASK; 568 crypto_skcipher_mask(mask));
559 type |= CRYPTO_ALG_TYPE_BLKCIPHER;
560 mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
561
562 return crypto_has_alg(alg_name, type, mask);
563} 569}
564 570
565static inline struct ablkcipher_tfm *crypto_ablkcipher_crt( 571static inline struct ablkcipher_tfm *crypto_ablkcipher_crt(