Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 1 | /* |
| 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> |
Herbert Xu | f5d8660 | 2015-06-18 14:00:49 +0800 | [diff] [blame] | 18 | #include <linux/stddef.h> |
Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 19 | #include <linux/types.h> |
| 20 | |
| 21 | struct rtattr; |
| 22 | |
Herbert Xu | 63293c6 | 2015-05-21 15:11:08 +0800 | [diff] [blame] | 23 | struct aead_instance { |
Herbert Xu | f5d8660 | 2015-06-18 14:00:49 +0800 | [diff] [blame] | 24 | union { |
| 25 | struct { |
| 26 | char head[offsetof(struct aead_alg, base)]; |
| 27 | struct crypto_instance base; |
| 28 | } s; |
| 29 | struct aead_alg alg; |
| 30 | }; |
Herbert Xu | 63293c6 | 2015-05-21 15:11:08 +0800 | [diff] [blame] | 31 | }; |
| 32 | |
Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 33 | struct crypto_aead_spawn { |
| 34 | struct crypto_spawn base; |
| 35 | }; |
| 36 | |
Herbert Xu | 5d1d65f | 2015-05-11 17:48:12 +0800 | [diff] [blame] | 37 | extern const struct crypto_type crypto_aead_type; |
Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 38 | extern const struct crypto_type crypto_nivaead_type; |
| 39 | |
Herbert Xu | 5d1d65f | 2015-05-11 17:48:12 +0800 | [diff] [blame] | 40 | static inline void *crypto_aead_ctx(struct crypto_aead *tfm) |
| 41 | { |
| 42 | return crypto_tfm_ctx(&tfm->base); |
| 43 | } |
| 44 | |
| 45 | static inline struct crypto_instance *crypto_aead_alg_instance( |
| 46 | struct crypto_aead *aead) |
| 47 | { |
| 48 | return crypto_tfm_alg_instance(&aead->base); |
| 49 | } |
| 50 | |
Herbert Xu | 63293c6 | 2015-05-21 15:11:08 +0800 | [diff] [blame] | 51 | static inline struct crypto_instance *aead_crypto_instance( |
| 52 | struct aead_instance *inst) |
| 53 | { |
| 54 | return container_of(&inst->alg.base, struct crypto_instance, alg); |
| 55 | } |
| 56 | |
| 57 | static inline struct aead_instance *aead_instance(struct crypto_instance *inst) |
| 58 | { |
| 59 | return container_of(&inst->alg, struct aead_instance, alg.base); |
| 60 | } |
| 61 | |
Herbert Xu | 5c98d62 | 2015-05-28 22:07:55 +0800 | [diff] [blame] | 62 | static inline struct aead_instance *aead_alg_instance(struct crypto_aead *aead) |
| 63 | { |
| 64 | return aead_instance(crypto_aead_alg_instance(aead)); |
| 65 | } |
| 66 | |
Herbert Xu | 63293c6 | 2015-05-21 15:11:08 +0800 | [diff] [blame] | 67 | static inline void *aead_instance_ctx(struct aead_instance *inst) |
| 68 | { |
| 69 | return crypto_instance_ctx(aead_crypto_instance(inst)); |
| 70 | } |
| 71 | |
Herbert Xu | 5d1d65f | 2015-05-11 17:48:12 +0800 | [diff] [blame] | 72 | static inline void *aead_request_ctx(struct aead_request *req) |
| 73 | { |
| 74 | return req->__ctx; |
| 75 | } |
| 76 | |
| 77 | static inline void aead_request_complete(struct aead_request *req, int err) |
| 78 | { |
| 79 | req->base.complete(&req->base, err); |
| 80 | } |
| 81 | |
| 82 | static inline u32 aead_request_flags(struct aead_request *req) |
| 83 | { |
| 84 | return req->base.flags; |
| 85 | } |
| 86 | |
Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 87 | static inline void crypto_set_aead_spawn( |
| 88 | struct crypto_aead_spawn *spawn, struct crypto_instance *inst) |
| 89 | { |
| 90 | crypto_set_spawn(&spawn->base, inst); |
| 91 | } |
| 92 | |
Steffen Klassert | 1e12299 | 2012-03-29 09:03:47 +0200 | [diff] [blame] | 93 | struct crypto_alg *crypto_lookup_aead(const char *name, u32 type, u32 mask); |
| 94 | |
Herbert Xu | d29ce98 | 2007-12-12 19:24:27 +0800 | [diff] [blame] | 95 | int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name, |
| 96 | u32 type, u32 mask); |
| 97 | |
Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 98 | static inline void crypto_drop_aead(struct crypto_aead_spawn *spawn) |
| 99 | { |
| 100 | crypto_drop_spawn(&spawn->base); |
| 101 | } |
| 102 | |
| 103 | static inline struct crypto_alg *crypto_aead_spawn_alg( |
| 104 | struct crypto_aead_spawn *spawn) |
| 105 | { |
| 106 | return spawn->base.alg; |
| 107 | } |
| 108 | |
Herbert Xu | 63293c6 | 2015-05-21 15:11:08 +0800 | [diff] [blame] | 109 | static inline struct aead_alg *crypto_spawn_aead_alg( |
| 110 | struct crypto_aead_spawn *spawn) |
| 111 | { |
| 112 | return container_of(spawn->base.alg, struct aead_alg, base); |
| 113 | } |
| 114 | |
Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 115 | static inline struct crypto_aead *crypto_spawn_aead( |
| 116 | struct crypto_aead_spawn *spawn) |
| 117 | { |
Herbert Xu | 5d1d65f | 2015-05-11 17:48:12 +0800 | [diff] [blame] | 118 | return crypto_spawn_tfm2(&spawn->base); |
Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 119 | } |
| 120 | |
Herbert Xu | 856e3f40 | 2015-05-21 15:11:13 +0800 | [diff] [blame] | 121 | struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl, |
| 122 | struct rtattr **tb, u32 type, u32 mask); |
| 123 | void aead_geniv_free(struct aead_instance *inst); |
Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 124 | int aead_geniv_init(struct crypto_tfm *tfm); |
| 125 | void aead_geniv_exit(struct crypto_tfm *tfm); |
| 126 | |
| 127 | static inline struct crypto_aead *aead_geniv_base(struct crypto_aead *geniv) |
| 128 | { |
Herbert Xu | 5d1d65f | 2015-05-11 17:48:12 +0800 | [diff] [blame] | 129 | return geniv->child; |
Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static inline void *aead_givcrypt_reqctx(struct aead_givcrypt_request *req) |
| 133 | { |
| 134 | return aead_request_ctx(&req->areq); |
| 135 | } |
| 136 | |
| 137 | static inline void aead_givcrypt_complete(struct aead_givcrypt_request *req, |
| 138 | int err) |
| 139 | { |
| 140 | aead_request_complete(&req->areq, err); |
| 141 | } |
| 142 | |
Herbert Xu | 21b70134 | 2015-05-11 17:47:52 +0800 | [diff] [blame] | 143 | static inline void crypto_aead_set_reqsize(struct crypto_aead *aead, |
| 144 | unsigned int reqsize) |
| 145 | { |
| 146 | crypto_aead_crt(aead)->reqsize = reqsize; |
| 147 | } |
| 148 | |
Herbert Xu | 30e4c01 | 2015-05-22 16:30:48 +0800 | [diff] [blame] | 149 | static inline unsigned int crypto_aead_alg_maxauthsize(struct aead_alg *alg) |
| 150 | { |
| 151 | return alg->base.cra_aead.encrypt ? alg->base.cra_aead.maxauthsize : |
| 152 | alg->maxauthsize; |
| 153 | } |
| 154 | |
Herbert Xu | f569525 | 2015-05-21 15:11:05 +0800 | [diff] [blame] | 155 | static inline unsigned int crypto_aead_maxauthsize(struct crypto_aead *aead) |
| 156 | { |
Herbert Xu | 30e4c01 | 2015-05-22 16:30:48 +0800 | [diff] [blame] | 157 | return crypto_aead_alg_maxauthsize(crypto_aead_alg(aead)); |
Herbert Xu | f569525 | 2015-05-21 15:11:05 +0800 | [diff] [blame] | 158 | } |
| 159 | |
Herbert Xu | 63293c6 | 2015-05-21 15:11:08 +0800 | [diff] [blame] | 160 | int crypto_register_aead(struct aead_alg *alg); |
Herbert Xu | 4361536 | 2015-05-28 22:07:57 +0800 | [diff] [blame] | 161 | void crypto_unregister_aead(struct aead_alg *alg); |
Herbert Xu | caab946 | 2015-05-28 22:07:59 +0800 | [diff] [blame] | 162 | int crypto_register_aeads(struct aead_alg *algs, int count); |
| 163 | void crypto_unregister_aeads(struct aead_alg *algs, int count); |
Herbert Xu | 63293c6 | 2015-05-21 15:11:08 +0800 | [diff] [blame] | 164 | int aead_register_instance(struct crypto_template *tmpl, |
| 165 | struct aead_instance *inst); |
| 166 | |
Herbert Xu | 5b6d2d7 | 2007-12-12 19:23:36 +0800 | [diff] [blame] | 167 | #endif /* _CRYPTO_INTERNAL_AEAD_H */ |
| 168 | |