]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/crypto/internal/skcipher.h
crypto: crc32c-vpmsum - Rename CRYPT_CRC32C_VPMSUM option
[mirror_ubuntu-jammy-kernel.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);
3a01d0ee 70
378f4f51
HX
71static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn)
72{
73 crypto_drop_spawn(&spawn->base);
74}
75
3a01d0ee 76static inline struct skcipher_alg *crypto_skcipher_spawn_alg(
378f4f51
HX
77 struct crypto_skcipher_spawn *spawn)
78{
3a01d0ee 79 return container_of(spawn->base.alg, struct skcipher_alg, base);
378f4f51
HX
80}
81
4e6c3df4
HX
82static inline struct skcipher_alg *crypto_spawn_skcipher_alg(
83 struct crypto_skcipher_spawn *spawn)
84{
3a01d0ee 85 return crypto_skcipher_spawn_alg(spawn);
4e6c3df4
HX
86}
87
3a01d0ee 88static inline struct crypto_skcipher *crypto_spawn_skcipher(
378f4f51
HX
89 struct crypto_skcipher_spawn *spawn)
90{
3a01d0ee 91 return crypto_spawn_tfm2(&spawn->base);
378f4f51
HX
92}
93
4e6c3df4
HX
94static inline void crypto_skcipher_set_reqsize(
95 struct crypto_skcipher *skcipher, unsigned int reqsize)
96{
97 skcipher->reqsize = reqsize;
98}
99
100int crypto_register_skcipher(struct skcipher_alg *alg);
101void crypto_unregister_skcipher(struct skcipher_alg *alg);
102int crypto_register_skciphers(struct skcipher_alg *algs, int count);
103void crypto_unregister_skciphers(struct skcipher_alg *algs, int count);
104int skcipher_register_instance(struct crypto_template *tmpl,
105 struct skcipher_instance *inst);
106
15c67286
HX
107static inline void ablkcipher_request_complete(struct ablkcipher_request *req,
108 int err)
109{
110 req->base.complete(&req->base, err);
111}
112
3631c650
HX
113static inline u32 ablkcipher_request_flags(struct ablkcipher_request *req)
114{
115 return req->base.flags;
116}
117
7a7ffe65
HX
118static inline void *crypto_skcipher_ctx(struct crypto_skcipher *tfm)
119{
120 return crypto_tfm_ctx(&tfm->base);
121}
122
123static inline void *skcipher_request_ctx(struct skcipher_request *req)
124{
125 return req->__ctx;
126}
127
128static inline u32 skcipher_request_flags(struct skcipher_request *req)
129{
130 return req->base.flags;
131}
132
4e6c3df4
HX
133static inline unsigned int crypto_skcipher_alg_min_keysize(
134 struct skcipher_alg *alg)
135{
136 if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) ==
137 CRYPTO_ALG_TYPE_BLKCIPHER)
138 return alg->base.cra_blkcipher.min_keysize;
139
140 if (alg->base.cra_ablkcipher.encrypt)
141 return alg->base.cra_ablkcipher.min_keysize;
142
143 return alg->min_keysize;
144}
145
146static inline unsigned int crypto_skcipher_alg_max_keysize(
147 struct skcipher_alg *alg)
148{
149 if ((alg->base.cra_flags & CRYPTO_ALG_TYPE_MASK) ==
150 CRYPTO_ALG_TYPE_BLKCIPHER)
151 return alg->base.cra_blkcipher.max_keysize;
152
153 if (alg->base.cra_ablkcipher.encrypt)
154 return alg->base.cra_ablkcipher.max_keysize;
155
156 return alg->max_keysize;
157}
158
378f4f51
HX
159#endif /* _CRYPTO_INTERNAL_SKCIPHER_H */
160