summaryrefslogtreecommitdiffstats
path: root/include/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2015-05-21 03:11:08 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-05-21 23:25:54 -0400
commit63293c61133447249d7e5b49d333f68825d30e43 (patch)
tree5525d14473d05acf8eb38b8f8e0b8f33acec399f /include/crypto
parent56fcf73a29007aa7bec2e3fc5da2962f3f72d610 (diff)
crypto: aead - Add support for new AEAD implementations
This patch adds the basic structure of the new AEAD type. Unlike the current version, there is no longer any concept of geniv. IV generation will still be carried out by wrappers but they will be normal AEAD algorithms that simply take the IPsec sequence number as the IV. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include/crypto')
-rw-r--r--include/crypto/aead.h44
-rw-r--r--include/crypto/internal/aead.h36
2 files changed, 76 insertions, 4 deletions
diff --git a/include/crypto/aead.h b/include/crypto/aead.h
index aebf57dfb903..177e6f46e2bb 100644
--- a/include/crypto/aead.h
+++ b/include/crypto/aead.h
@@ -17,8 +17,6 @@
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19 19
20#define aead_alg old_aead_alg
21
22/** 20/**
23 * DOC: Authenticated Encryption With Associated Data (AEAD) Cipher API 21 * DOC: Authenticated Encryption With Associated Data (AEAD) Cipher API
24 * 22 *
@@ -92,7 +90,48 @@ struct aead_givcrypt_request {
92 struct aead_request areq; 90 struct aead_request areq;
93}; 91};
94 92
93/**
94 * struct aead_alg - AEAD cipher definition
95 * @maxauthsize: Set the maximum authentication tag size supported by the
96 * transformation. A transformation may support smaller tag sizes.
97 * As the authentication tag is a message digest to ensure the
98 * integrity of the encrypted data, a consumer typically wants the
99 * largest authentication tag possible as defined by this
100 * variable.
101 * @setauthsize: Set authentication size for the AEAD transformation. This
102 * function is used to specify the consumer requested size of the
103 * authentication tag to be either generated by the transformation
104 * during encryption or the size of the authentication tag to be
105 * supplied during the decryption operation. This function is also
106 * responsible for checking the authentication tag size for
107 * validity.
108 * @setkey: see struct ablkcipher_alg
109 * @encrypt: see struct ablkcipher_alg
110 * @decrypt: see struct ablkcipher_alg
111 * @geniv: see struct ablkcipher_alg
112 * @ivsize: see struct ablkcipher_alg
113 *
114 * All fields except @ivsize is mandatory and must be filled.
115 */
116struct aead_alg {
117 int (*setkey)(struct crypto_aead *tfm, const u8 *key,
118 unsigned int keylen);
119 int (*setauthsize)(struct crypto_aead *tfm, unsigned int authsize);
120 int (*encrypt)(struct aead_request *req);
121 int (*decrypt)(struct aead_request *req);
122
123 const char *geniv;
124
125 unsigned int ivsize;
126 unsigned int maxauthsize;
127
128 struct crypto_alg base;
129};
130
95struct crypto_aead { 131struct crypto_aead {
132 int (*setkey)(struct crypto_aead *tfm, const u8 *key,
133 unsigned int keylen);
134 int (*setauthsize)(struct crypto_aead *tfm, unsigned int authsize);
96 int (*encrypt)(struct aead_request *req); 135 int (*encrypt)(struct aead_request *req);
97 int (*decrypt)(struct aead_request *req); 136 int (*decrypt)(struct aead_request *req);
98 int (*givencrypt)(struct aead_givcrypt_request *req); 137 int (*givencrypt)(struct aead_givcrypt_request *req);
@@ -102,6 +141,7 @@ struct crypto_aead {
102 141
103 unsigned int ivsize; 142 unsigned int ivsize;
104 unsigned int authsize; 143 unsigned int authsize;
144 unsigned int maxauthsize;
105 unsigned int reqsize; 145 unsigned int reqsize;
106 146
107 struct crypto_tfm base; 147 struct crypto_tfm base;
diff --git a/include/crypto/internal/aead.h b/include/crypto/internal/aead.h
index 4614f795f8bc..6cd31519c4f6 100644
--- a/include/crypto/internal/aead.h
+++ b/include/crypto/internal/aead.h
@@ -19,6 +19,10 @@
19 19
20struct rtattr; 20struct rtattr;
21 21
22struct aead_instance {
23 struct aead_alg alg;
24};
25
22struct crypto_aead_spawn { 26struct crypto_aead_spawn {
23 struct crypto_spawn base; 27 struct crypto_spawn base;
24}; 28};
@@ -33,7 +37,8 @@ static inline struct old_aead_alg *crypto_old_aead_alg(struct crypto_aead *tfm)
33 37
34static inline struct aead_alg *crypto_aead_alg(struct crypto_aead *tfm) 38static inline struct aead_alg *crypto_aead_alg(struct crypto_aead *tfm)
35{ 39{
36 return &crypto_aead_tfm(tfm)->__crt_alg->cra_aead; 40 return container_of(crypto_aead_tfm(tfm)->__crt_alg,
41 struct aead_alg, base);
37} 42}
38 43
39static inline void *crypto_aead_ctx(struct crypto_aead *tfm) 44static inline void *crypto_aead_ctx(struct crypto_aead *tfm)
@@ -47,6 +52,22 @@ static inline struct crypto_instance *crypto_aead_alg_instance(
47 return crypto_tfm_alg_instance(&aead->base); 52 return crypto_tfm_alg_instance(&aead->base);
48} 53}
49 54
55static inline struct crypto_instance *aead_crypto_instance(
56 struct aead_instance *inst)
57{
58 return container_of(&inst->alg.base, struct crypto_instance, alg);
59}
60
61static inline struct aead_instance *aead_instance(struct crypto_instance *inst)
62{
63 return container_of(&inst->alg, struct aead_instance, alg.base);
64}
65
66static inline void *aead_instance_ctx(struct aead_instance *inst)
67{
68 return crypto_instance_ctx(aead_crypto_instance(inst));
69}
70
50static inline void *aead_request_ctx(struct aead_request *req) 71static inline void *aead_request_ctx(struct aead_request *req)
51{ 72{
52 return req->__ctx; 73 return req->__ctx;
@@ -84,6 +105,12 @@ static inline struct crypto_alg *crypto_aead_spawn_alg(
84 return spawn->base.alg; 105 return spawn->base.alg;
85} 106}
86 107
108static inline struct aead_alg *crypto_spawn_aead_alg(
109 struct crypto_aead_spawn *spawn)
110{
111 return container_of(spawn->base.alg, struct aead_alg, base);
112}
113
87static inline struct crypto_aead *crypto_spawn_aead( 114static inline struct crypto_aead *crypto_spawn_aead(
88 struct crypto_aead_spawn *spawn) 115 struct crypto_aead_spawn *spawn)
89{ 116{
@@ -121,8 +148,13 @@ static inline void crypto_aead_set_reqsize(struct crypto_aead *aead,
121 148
122static inline unsigned int crypto_aead_maxauthsize(struct crypto_aead *aead) 149static inline unsigned int crypto_aead_maxauthsize(struct crypto_aead *aead)
123{ 150{
124 return crypto_old_aead_alg(aead)->maxauthsize; 151 return aead->maxauthsize;
125} 152}
126 153
154int crypto_register_aead(struct aead_alg *alg);
155int crypto_unregister_aead(struct aead_alg *alg);
156int aead_register_instance(struct crypto_template *tmpl,
157 struct aead_instance *inst);
158
127#endif /* _CRYPTO_INTERNAL_AEAD_H */ 159#endif /* _CRYPTO_INTERNAL_AEAD_H */
128 160