aboutsummaryrefslogtreecommitdiffstats
path: root/include/crypto/internal
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2016-07-12 01:17:31 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2016-07-18 05:35:36 -0400
commit4e6c3df4d729f85997cbf276bfa8ffd8579b8e77 (patch)
tree3293b9ab0a019308724c8b44430cadc0a3b4488d /include/crypto/internal
parenteb9bc8e7afaa9f062105dad55ec1c0663d961bb3 (diff)
crypto: skcipher - Add low-level skcipher interface
This patch allows skcipher algorithms and instances to be created and registered with the crypto API. They are accessible through the top-level skcipher interface, along with ablkcipher/blkcipher algorithms and instances. This patch also introduces a new parameter called chunk size which is meant for ciphers such as CTR and CTS which ostensibly can handle arbitrary lengths, but still behave like block ciphers in that you can only process a partial block at the very end. For these ciphers the block size will continue to be set to 1 as it is now while the chunk size will be set to the underlying block size. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include/crypto/internal')
-rw-r--r--include/crypto/internal/skcipher.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h
index 2cf7a61ece59..ce6619c339fe 100644
--- a/include/crypto/internal/skcipher.h
+++ b/include/crypto/internal/skcipher.h
@@ -19,12 +19,46 @@
19 19
20struct rtattr; 20struct rtattr;
21 21
22struct skcipher_instance {
23 void (*free)(struct skcipher_instance *inst);
24 union {
25 struct {
26 char head[offsetof(struct skcipher_alg, base)];
27 struct crypto_instance base;
28 } s;
29 struct skcipher_alg alg;
30 };
31};
32
22struct crypto_skcipher_spawn { 33struct crypto_skcipher_spawn {
23 struct crypto_spawn base; 34 struct crypto_spawn base;
24}; 35};
25 36
26extern const struct crypto_type crypto_givcipher_type; 37extern const struct crypto_type crypto_givcipher_type;
27 38
39static inline struct crypto_instance *skcipher_crypto_instance(
40 struct skcipher_instance *inst)
41{
42 return &inst->s.base;
43}
44
45static inline struct skcipher_instance *skcipher_alg_instance(
46 struct crypto_skcipher *skcipher)
47{
48 return container_of(crypto_skcipher_alg(skcipher),
49 struct skcipher_instance, alg);
50}
51
52static inline void *skcipher_instance_ctx(struct skcipher_instance *inst)
53{
54 return crypto_instance_ctx(skcipher_crypto_instance(inst));
55}
56
57static inline void skcipher_request_complete(struct skcipher_request *req, int err)
58{
59 req->base.complete(&req->base, err);
60}
61
28static inline void crypto_set_skcipher_spawn( 62static inline void crypto_set_skcipher_spawn(
29 struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst) 63 struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst)
30{ 64{
@@ -33,6 +67,8 @@ static inline void crypto_set_skcipher_spawn(
33 67
34int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name, 68int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
35 u32 type, u32 mask); 69 u32 type, u32 mask);
70int crypto_grab_skcipher2(struct crypto_skcipher_spawn *spawn,
71 const char *name, u32 type, u32 mask);
36 72
37struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type, u32 mask); 73struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type, u32 mask);
38 74
@@ -47,6 +83,12 @@ static inline struct crypto_alg *crypto_skcipher_spawn_alg(
47 return spawn->base.alg; 83 return spawn->base.alg;
48} 84}
49 85
86static inline struct skcipher_alg *crypto_spawn_skcipher_alg(
87 struct crypto_skcipher_spawn *spawn)
88{
89 return container_of(spawn->base.alg, struct skcipher_alg, base);
90}
91
50static inline struct crypto_ablkcipher *crypto_spawn_skcipher( 92static inline struct crypto_ablkcipher *crypto_spawn_skcipher(
51 struct crypto_skcipher_spawn *spawn) 93 struct crypto_skcipher_spawn *spawn)
52{ 94{
@@ -55,6 +97,25 @@ static inline struct crypto_ablkcipher *crypto_spawn_skcipher(
55 crypto_skcipher_mask(0))); 97 crypto_skcipher_mask(0)));
56} 98}
57 99
100static inline struct crypto_skcipher *crypto_spawn_skcipher2(
101 struct crypto_skcipher_spawn *spawn)
102{
103 return crypto_spawn_tfm2(&spawn->base);
104}
105
106static inline void crypto_skcipher_set_reqsize(
107 struct crypto_skcipher *skcipher, unsigned int reqsize)
108{
109 skcipher->reqsize = reqsize;
110}
111
112int crypto_register_skcipher(struct skcipher_alg *alg);
113void crypto_unregister_skcipher(struct skcipher_alg *alg);
114int crypto_register_skciphers(struct skcipher_alg *algs, int count);
115void crypto_unregister_skciphers(struct skcipher_alg *algs, int count);
116int skcipher_register_instance(struct crypto_template *tmpl,
117 struct skcipher_instance *inst);
118
58int skcipher_null_givencrypt(struct skcipher_givcrypt_request *req); 119int skcipher_null_givencrypt(struct skcipher_givcrypt_request *req);
59int skcipher_null_givdecrypt(struct skcipher_givcrypt_request *req); 120int skcipher_null_givdecrypt(struct skcipher_givcrypt_request *req);
60const char *crypto_default_geniv(const struct crypto_alg *alg); 121const char *crypto_default_geniv(const struct crypto_alg *alg);
@@ -122,5 +183,31 @@ static inline u32 skcipher_request_flags(struct skcipher_request *req)
122 return req->base.flags; 183 return req->base.flags;
123} 184}
124 185
186static inline unsigned int crypto_skcipher_alg_min_keysize(
187 struct skcipher_alg *alg)
188{
189 if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) ==
190 CRYPTO_ALG_TYPE_BLKCIPHER)
191 return alg->base.cra_blkcipher.min_keysize;
192
193 if (alg->base.cra_ablkcipher.encrypt)
194 return alg->base.cra_ablkcipher.min_keysize;
195
196 return alg->min_keysize;
197}
198
199static inline unsigned int crypto_skcipher_alg_max_keysize(
200 struct skcipher_alg *alg)
201{
202 if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) ==
203 CRYPTO_ALG_TYPE_BLKCIPHER)
204 return alg->base.cra_blkcipher.max_keysize;
205
206 if (alg->base.cra_ablkcipher.encrypt)
207 return alg->base.cra_ablkcipher.max_keysize;
208
209 return alg->max_keysize;
210}
211
125#endif /* _CRYPTO_INTERNAL_SKCIPHER_H */ 212#endif /* _CRYPTO_INTERNAL_SKCIPHER_H */
126 213