2 * AEAD: Authenticated Encryption with Associated Data
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_AEAD_H
14 #define _CRYPTO_INTERNAL_AEAD_H
16 #include <crypto/aead.h>
17 #include <crypto/algapi.h>
18 #include <linux/stddef.h>
19 #include <linux/types.h>
23 struct aead_instance
{
24 void (*free
)(struct aead_instance
*inst
);
27 char head
[offsetof(struct aead_alg
, base
)];
28 struct crypto_instance base
;
34 struct crypto_aead_spawn
{
35 struct crypto_spawn base
;
39 struct crypto_queue base
;
42 extern const struct crypto_type crypto_aead_type
;
43 extern const struct crypto_type crypto_nivaead_type
;
45 static inline void *crypto_aead_ctx(struct crypto_aead
*tfm
)
47 return crypto_tfm_ctx(&tfm
->base
);
50 static inline struct crypto_instance
*crypto_aead_alg_instance(
51 struct crypto_aead
*aead
)
53 return crypto_tfm_alg_instance(&aead
->base
);
56 static inline struct crypto_instance
*aead_crypto_instance(
57 struct aead_instance
*inst
)
59 return container_of(&inst
->alg
.base
, struct crypto_instance
, alg
);
62 static inline struct aead_instance
*aead_instance(struct crypto_instance
*inst
)
64 return container_of(&inst
->alg
, struct aead_instance
, alg
.base
);
67 static inline struct aead_instance
*aead_alg_instance(struct crypto_aead
*aead
)
69 return aead_instance(crypto_aead_alg_instance(aead
));
72 static inline void *aead_instance_ctx(struct aead_instance
*inst
)
74 return crypto_instance_ctx(aead_crypto_instance(inst
));
77 static inline void *aead_request_ctx(struct aead_request
*req
)
82 static inline void aead_request_complete(struct aead_request
*req
, int err
)
84 req
->base
.complete(&req
->base
, err
);
87 static inline u32
aead_request_flags(struct aead_request
*req
)
89 return req
->base
.flags
;
92 static inline void crypto_set_aead_spawn(
93 struct crypto_aead_spawn
*spawn
, struct crypto_instance
*inst
)
95 crypto_set_spawn(&spawn
->base
, inst
);
98 struct crypto_alg
*crypto_lookup_aead(const char *name
, u32 type
, u32 mask
);
100 int crypto_grab_aead(struct crypto_aead_spawn
*spawn
, const char *name
,
103 static inline void crypto_drop_aead(struct crypto_aead_spawn
*spawn
)
105 crypto_drop_spawn(&spawn
->base
);
108 static inline struct crypto_alg
*crypto_aead_spawn_alg(
109 struct crypto_aead_spawn
*spawn
)
111 return spawn
->base
.alg
;
114 static inline struct aead_alg
*crypto_spawn_aead_alg(
115 struct crypto_aead_spawn
*spawn
)
117 return container_of(spawn
->base
.alg
, struct aead_alg
, base
);
120 static inline struct crypto_aead
*crypto_spawn_aead(
121 struct crypto_aead_spawn
*spawn
)
123 return crypto_spawn_tfm2(&spawn
->base
);
126 static inline struct crypto_aead
*aead_geniv_base(struct crypto_aead
*geniv
)
131 static inline void *aead_givcrypt_reqctx(struct aead_givcrypt_request
*req
)
133 return aead_request_ctx(&req
->areq
);
136 static inline void aead_givcrypt_complete(struct aead_givcrypt_request
*req
,
139 aead_request_complete(&req
->areq
, err
);
142 static inline void crypto_aead_set_reqsize(struct crypto_aead
*aead
,
143 unsigned int reqsize
)
145 crypto_aead_crt(aead
)->reqsize
= reqsize
;
148 static inline unsigned int crypto_aead_alg_maxauthsize(struct aead_alg
*alg
)
150 return alg
->base
.cra_aead
.encrypt
? alg
->base
.cra_aead
.maxauthsize
:
154 static inline unsigned int crypto_aead_maxauthsize(struct crypto_aead
*aead
)
156 return crypto_aead_alg_maxauthsize(crypto_aead_alg(aead
));
159 static inline void aead_init_queue(struct aead_queue
*queue
,
160 unsigned int max_qlen
)
162 crypto_init_queue(&queue
->base
, max_qlen
);
165 static inline int aead_enqueue_request(struct aead_queue
*queue
,
166 struct aead_request
*request
)
168 return crypto_enqueue_request(&queue
->base
, &request
->base
);
171 static inline struct aead_request
*aead_dequeue_request(
172 struct aead_queue
*queue
)
174 struct crypto_async_request
*req
;
176 req
= crypto_dequeue_request(&queue
->base
);
178 return req
? container_of(req
, struct aead_request
, base
) : NULL
;
181 static inline struct aead_request
*aead_get_backlog(struct aead_queue
*queue
)
183 struct crypto_async_request
*req
;
185 req
= crypto_get_backlog(&queue
->base
);
187 return req
? container_of(req
, struct aead_request
, base
) : NULL
;
190 int crypto_register_aead(struct aead_alg
*alg
);
191 void crypto_unregister_aead(struct aead_alg
*alg
);
192 int crypto_register_aeads(struct aead_alg
*algs
, int count
);
193 void crypto_unregister_aeads(struct aead_alg
*algs
, int count
);
194 int aead_register_instance(struct crypto_template
*tmpl
,
195 struct aead_instance
*inst
);
197 #endif /* _CRYPTO_INTERNAL_AEAD_H */