crypto: skcipher - Add low-level skcipher interface
[deliverable/linux.git] / include / crypto / internal / skcipher.h
CommitLineData
378f4f51
HX
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>
61da88e2 17#include <crypto/skcipher.h>
ecfc4329
HX
18#include <linux/types.h>
19
20struct rtattr;
378f4f51 21
4e6c3df4
HX
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
378f4f51
HX
33struct crypto_skcipher_spawn {
34 struct crypto_spawn base;
35};
36
61da88e2
HX
37extern const struct crypto_type crypto_givcipher_type;
38
4e6c3df4
HX
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
378f4f51
HX
62static inline void crypto_set_skcipher_spawn(
63 struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst)
64{
65 crypto_set_spawn(&spawn->base, inst);
66}
67
68int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
69 u32 type, u32 mask);
4e6c3df4
HX
70int crypto_grab_skcipher2(struct crypto_skcipher_spawn *spawn,
71 const char *name, u32 type, u32 mask);
378f4f51 72
1e122994
SK
73struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type, u32 mask);
74
378f4f51
HX
75static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn)
76{
77 crypto_drop_spawn(&spawn->base);
78}
79
80static inline struct crypto_alg *crypto_skcipher_spawn_alg(
81 struct crypto_skcipher_spawn *spawn)
82{
83 return spawn->base.alg;
84}
85
4e6c3df4
HX
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
378f4f51
HX
92static inline struct crypto_ablkcipher *crypto_spawn_skcipher(
93 struct crypto_skcipher_spawn *spawn)
94{
95 return __crypto_ablkcipher_cast(
96 crypto_spawn_tfm(&spawn->base, crypto_skcipher_type(0),
97 crypto_skcipher_mask(0)));
98}
99
4e6c3df4
HX
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
b9c55aa4
HX
119int skcipher_null_givencrypt(struct skcipher_givcrypt_request *req);
120int skcipher_null_givdecrypt(struct skcipher_givcrypt_request *req);
ecfc4329
HX
121const char *crypto_default_geniv(const struct crypto_alg *alg);
122
123struct crypto_instance *skcipher_geniv_alloc(struct crypto_template *tmpl,
124 struct rtattr **tb, u32 type,
125 u32 mask);
126void skcipher_geniv_free(struct crypto_instance *inst);
127int skcipher_geniv_init(struct crypto_tfm *tfm);
128void skcipher_geniv_exit(struct crypto_tfm *tfm);
129
130static inline struct crypto_ablkcipher *skcipher_geniv_cipher(
131 struct crypto_ablkcipher *geniv)
132{
133 return crypto_ablkcipher_crt(geniv)->base;
134}
135
e7cd2514
HX
136static inline int skcipher_enqueue_givcrypt(
137 struct crypto_queue *queue, struct skcipher_givcrypt_request *request)
138{
139 return ablkcipher_enqueue_request(queue, &request->creq);
140}
141
142static inline struct skcipher_givcrypt_request *skcipher_dequeue_givcrypt(
143 struct crypto_queue *queue)
144{
d656c180 145 return skcipher_givcrypt_cast(crypto_dequeue_request(queue));
e7cd2514
HX
146}
147
61da88e2
HX
148static inline void *skcipher_givcrypt_reqctx(
149 struct skcipher_givcrypt_request *req)
150{
151 return ablkcipher_request_ctx(&req->creq);
152}
153
15c67286
HX
154static inline void ablkcipher_request_complete(struct ablkcipher_request *req,
155 int err)
156{
157 req->base.complete(&req->base, err);
158}
159
160static inline void skcipher_givcrypt_complete(
161 struct skcipher_givcrypt_request *req, int err)
162{
163 ablkcipher_request_complete(&req->creq, err);
164}
165
3631c650
HX
166static inline u32 ablkcipher_request_flags(struct ablkcipher_request *req)
167{
168 return req->base.flags;
169}
170
7a7ffe65
HX
171static inline void *crypto_skcipher_ctx(struct crypto_skcipher *tfm)
172{
173 return crypto_tfm_ctx(&tfm->base);
174}
175
176static inline void *skcipher_request_ctx(struct skcipher_request *req)
177{
178 return req->__ctx;
179}
180
181static inline u32 skcipher_request_flags(struct skcipher_request *req)
182{
183 return req->base.flags;
184}
185
4e6c3df4
HX
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
378f4f51
HX
212#endif /* _CRYPTO_INTERNAL_SKCIPHER_H */
213
This page took 0.51169 seconds and 5 git commands to generate.