2 * Symmetric key ciphers.
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
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)
13 #ifndef _CRYPTO_INTERNAL_SKCIPHER_H
14 #define _CRYPTO_INTERNAL_SKCIPHER_H
16 #include <crypto/algapi.h>
17 #include <crypto/skcipher.h>
18 #include <linux/types.h>
22 struct skcipher_instance
{
23 void (*free
)(struct skcipher_instance
*inst
);
26 char head
[offsetof(struct skcipher_alg
, base
)];
27 struct crypto_instance base
;
29 struct skcipher_alg alg
;
33 struct crypto_skcipher_spawn
{
34 struct crypto_spawn base
;
37 extern const struct crypto_type crypto_givcipher_type
;
39 static inline struct crypto_instance
*skcipher_crypto_instance(
40 struct skcipher_instance
*inst
)
45 static inline struct skcipher_instance
*skcipher_alg_instance(
46 struct crypto_skcipher
*skcipher
)
48 return container_of(crypto_skcipher_alg(skcipher
),
49 struct skcipher_instance
, alg
);
52 static inline void *skcipher_instance_ctx(struct skcipher_instance
*inst
)
54 return crypto_instance_ctx(skcipher_crypto_instance(inst
));
57 static inline void skcipher_request_complete(struct skcipher_request
*req
, int err
)
59 req
->base
.complete(&req
->base
, err
);
62 static inline void crypto_set_skcipher_spawn(
63 struct crypto_skcipher_spawn
*spawn
, struct crypto_instance
*inst
)
65 crypto_set_spawn(&spawn
->base
, inst
);
68 int crypto_grab_skcipher(struct crypto_skcipher_spawn
*spawn
, const char *name
,
71 static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn
*spawn
)
73 crypto_drop_spawn(&spawn
->base
);
76 static inline struct skcipher_alg
*crypto_skcipher_spawn_alg(
77 struct crypto_skcipher_spawn
*spawn
)
79 return container_of(spawn
->base
.alg
, struct skcipher_alg
, base
);
82 static inline struct skcipher_alg
*crypto_spawn_skcipher_alg(
83 struct crypto_skcipher_spawn
*spawn
)
85 return crypto_skcipher_spawn_alg(spawn
);
88 static inline struct crypto_skcipher
*crypto_spawn_skcipher(
89 struct crypto_skcipher_spawn
*spawn
)
91 return crypto_spawn_tfm2(&spawn
->base
);
94 static inline void crypto_skcipher_set_reqsize(
95 struct crypto_skcipher
*skcipher
, unsigned int reqsize
)
97 skcipher
->reqsize
= reqsize
;
100 int crypto_register_skcipher(struct skcipher_alg
*alg
);
101 void crypto_unregister_skcipher(struct skcipher_alg
*alg
);
102 int crypto_register_skciphers(struct skcipher_alg
*algs
, int count
);
103 void crypto_unregister_skciphers(struct skcipher_alg
*algs
, int count
);
104 int skcipher_register_instance(struct crypto_template
*tmpl
,
105 struct skcipher_instance
*inst
);
107 static inline void ablkcipher_request_complete(struct ablkcipher_request
*req
,
110 req
->base
.complete(&req
->base
, err
);
113 static inline u32
ablkcipher_request_flags(struct ablkcipher_request
*req
)
115 return req
->base
.flags
;
118 static inline void *crypto_skcipher_ctx(struct crypto_skcipher
*tfm
)
120 return crypto_tfm_ctx(&tfm
->base
);
123 static inline void *skcipher_request_ctx(struct skcipher_request
*req
)
128 static inline u32
skcipher_request_flags(struct skcipher_request
*req
)
130 return req
->base
.flags
;
133 static inline unsigned int crypto_skcipher_alg_min_keysize(
134 struct skcipher_alg
*alg
)
136 if ((alg
->base
.cra_flags
& CRYPTO_ALG_TYPE_MASK
) ==
137 CRYPTO_ALG_TYPE_BLKCIPHER
)
138 return alg
->base
.cra_blkcipher
.min_keysize
;
140 if (alg
->base
.cra_ablkcipher
.encrypt
)
141 return alg
->base
.cra_ablkcipher
.min_keysize
;
143 return alg
->min_keysize
;
146 static inline unsigned int crypto_skcipher_alg_max_keysize(
147 struct skcipher_alg
*alg
)
149 if ((alg
->base
.cra_flags
& CRYPTO_ALG_TYPE_MASK
) ==
150 CRYPTO_ALG_TYPE_BLKCIPHER
)
151 return alg
->base
.cra_blkcipher
.max_keysize
;
153 if (alg
->base
.cra_ablkcipher
.encrypt
)
154 return alg
->base
.cra_ablkcipher
.max_keysize
;
156 return alg
->max_keysize
;
159 #endif /* _CRYPTO_INTERNAL_SKCIPHER_H */