blob: 4137330f01ab56ca0223a20258e532906468d217 [file] [log] [blame]
Herbert Xu5b6d2d72007-12-12 19:23:36 +08001/*
2 * AEAD: Authenticated Encryption with Associated Data
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_AEAD_H
14#define _CRYPTO_INTERNAL_AEAD_H
15
16#include <crypto/aead.h>
17#include <crypto/algapi.h>
18#include <linux/types.h>
19
20struct rtattr;
21
Herbert Xu63293c62015-05-21 15:11:08 +080022struct aead_instance {
23 struct aead_alg alg;
24};
25
Herbert Xu5b6d2d72007-12-12 19:23:36 +080026struct crypto_aead_spawn {
27 struct crypto_spawn base;
28};
29
Herbert Xu5d1d65f2015-05-11 17:48:12 +080030extern const struct crypto_type crypto_aead_type;
Herbert Xu5b6d2d72007-12-12 19:23:36 +080031extern const struct crypto_type crypto_nivaead_type;
32
Herbert Xu5d1d65f2015-05-11 17:48:12 +080033static inline void *crypto_aead_ctx(struct crypto_aead *tfm)
34{
35 return crypto_tfm_ctx(&tfm->base);
36}
37
38static inline struct crypto_instance *crypto_aead_alg_instance(
39 struct crypto_aead *aead)
40{
41 return crypto_tfm_alg_instance(&aead->base);
42}
43
Herbert Xu63293c62015-05-21 15:11:08 +080044static inline struct crypto_instance *aead_crypto_instance(
45 struct aead_instance *inst)
46{
47 return container_of(&inst->alg.base, struct crypto_instance, alg);
48}
49
50static inline struct aead_instance *aead_instance(struct crypto_instance *inst)
51{
52 return container_of(&inst->alg, struct aead_instance, alg.base);
53}
54
55static inline void *aead_instance_ctx(struct aead_instance *inst)
56{
57 return crypto_instance_ctx(aead_crypto_instance(inst));
58}
59
Herbert Xu5d1d65f2015-05-11 17:48:12 +080060static inline void *aead_request_ctx(struct aead_request *req)
61{
62 return req->__ctx;
63}
64
65static inline void aead_request_complete(struct aead_request *req, int err)
66{
67 req->base.complete(&req->base, err);
68}
69
70static inline u32 aead_request_flags(struct aead_request *req)
71{
72 return req->base.flags;
73}
74
Herbert Xu5b6d2d72007-12-12 19:23:36 +080075static inline void crypto_set_aead_spawn(
76 struct crypto_aead_spawn *spawn, struct crypto_instance *inst)
77{
78 crypto_set_spawn(&spawn->base, inst);
79}
80
Steffen Klassert1e122992012-03-29 09:03:47 +020081struct crypto_alg *crypto_lookup_aead(const char *name, u32 type, u32 mask);
82
Herbert Xud29ce982007-12-12 19:24:27 +080083int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
84 u32 type, u32 mask);
85
Herbert Xu5b6d2d72007-12-12 19:23:36 +080086static inline void crypto_drop_aead(struct crypto_aead_spawn *spawn)
87{
88 crypto_drop_spawn(&spawn->base);
89}
90
91static inline struct crypto_alg *crypto_aead_spawn_alg(
92 struct crypto_aead_spawn *spawn)
93{
94 return spawn->base.alg;
95}
96
Herbert Xu63293c62015-05-21 15:11:08 +080097static inline struct aead_alg *crypto_spawn_aead_alg(
98 struct crypto_aead_spawn *spawn)
99{
100 return container_of(spawn->base.alg, struct aead_alg, base);
101}
102
Herbert Xu5b6d2d72007-12-12 19:23:36 +0800103static inline struct crypto_aead *crypto_spawn_aead(
104 struct crypto_aead_spawn *spawn)
105{
Herbert Xu5d1d65f2015-05-11 17:48:12 +0800106 return crypto_spawn_tfm2(&spawn->base);
Herbert Xu5b6d2d72007-12-12 19:23:36 +0800107}
108
Herbert Xu856e3f402015-05-21 15:11:13 +0800109struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl,
110 struct rtattr **tb, u32 type, u32 mask);
111void aead_geniv_free(struct aead_instance *inst);
Herbert Xu5b6d2d72007-12-12 19:23:36 +0800112int aead_geniv_init(struct crypto_tfm *tfm);
113void aead_geniv_exit(struct crypto_tfm *tfm);
114
115static inline struct crypto_aead *aead_geniv_base(struct crypto_aead *geniv)
116{
Herbert Xu5d1d65f2015-05-11 17:48:12 +0800117 return geniv->child;
Herbert Xu5b6d2d72007-12-12 19:23:36 +0800118}
119
120static inline void *aead_givcrypt_reqctx(struct aead_givcrypt_request *req)
121{
122 return aead_request_ctx(&req->areq);
123}
124
125static inline void aead_givcrypt_complete(struct aead_givcrypt_request *req,
126 int err)
127{
128 aead_request_complete(&req->areq, err);
129}
130
Herbert Xu21b701342015-05-11 17:47:52 +0800131static inline void crypto_aead_set_reqsize(struct crypto_aead *aead,
132 unsigned int reqsize)
133{
134 crypto_aead_crt(aead)->reqsize = reqsize;
135}
136
Herbert Xu30e4c012015-05-22 16:30:48 +0800137static inline unsigned int crypto_aead_alg_maxauthsize(struct aead_alg *alg)
138{
139 return alg->base.cra_aead.encrypt ? alg->base.cra_aead.maxauthsize :
140 alg->maxauthsize;
141}
142
Herbert Xuf5695252015-05-21 15:11:05 +0800143static inline unsigned int crypto_aead_maxauthsize(struct crypto_aead *aead)
144{
Herbert Xu30e4c012015-05-22 16:30:48 +0800145 return crypto_aead_alg_maxauthsize(crypto_aead_alg(aead));
Herbert Xuf5695252015-05-21 15:11:05 +0800146}
147
Herbert Xu63293c62015-05-21 15:11:08 +0800148int crypto_register_aead(struct aead_alg *alg);
149int crypto_unregister_aead(struct aead_alg *alg);
150int aead_register_instance(struct crypto_template *tmpl,
151 struct aead_instance *inst);
152
Herbert Xu5b6d2d72007-12-12 19:23:36 +0800153#endif /* _CRYPTO_INTERNAL_AEAD_H */
154