Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Authenc: Simple AEAD wrapper for IPsec |
| 4 | * |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 5 | * Copyright (c) 2007-2015 Herbert Xu <herbert@gondor.apana.org.au> |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
Herbert Xu | 68acbf8 | 2015-05-11 17:47:41 +0800 | [diff] [blame] | 8 | #include <crypto/internal/aead.h> |
Herbert Xu | 5f7082e | 2008-08-31 22:21:09 +1000 | [diff] [blame] | 9 | #include <crypto/internal/hash.h> |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 10 | #include <crypto/internal/skcipher.h> |
Herbert Xu | e236d4a | 2007-11-22 23:11:53 +0800 | [diff] [blame] | 11 | #include <crypto/authenc.h> |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 12 | #include <crypto/null.h> |
Herbert Xu | 42c271c | 2007-12-07 18:52:49 +0800 | [diff] [blame] | 13 | #include <crypto/scatterwalk.h> |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 14 | #include <linux/err.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> |
Herbert Xu | e236d4a | 2007-11-22 23:11:53 +0800 | [diff] [blame] | 18 | #include <linux/rtnetlink.h> |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 19 | #include <linux/slab.h> |
| 20 | #include <linux/spinlock.h> |
| 21 | |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 22 | struct authenc_instance_ctx { |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 23 | struct crypto_ahash_spawn auth; |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 24 | struct crypto_skcipher_spawn enc; |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 25 | unsigned int reqoff; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | struct crypto_authenc_ctx { |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 29 | struct crypto_ahash *auth; |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 30 | struct crypto_skcipher *enc; |
Kees Cook | 8d60539 | 2018-09-18 19:10:51 -0700 | [diff] [blame] | 31 | struct crypto_sync_skcipher *null; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 32 | }; |
| 33 | |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 34 | struct authenc_request_ctx { |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 35 | struct scatterlist src[2]; |
| 36 | struct scatterlist dst[2]; |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 37 | char tail[]; |
| 38 | }; |
| 39 | |
Herbert Xu | 180ce7e | 2010-04-26 09:14:05 +0800 | [diff] [blame] | 40 | static void authenc_request_complete(struct aead_request *req, int err) |
| 41 | { |
| 42 | if (err != -EINPROGRESS) |
| 43 | aead_request_complete(req, err); |
| 44 | } |
| 45 | |
Mathias Krause | bc6e2bd | 2013-10-15 13:49:30 +0200 | [diff] [blame] | 46 | int crypto_authenc_extractkeys(struct crypto_authenc_keys *keys, const u8 *key, |
| 47 | unsigned int keylen) |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 48 | { |
Mathias Krause | bc6e2bd | 2013-10-15 13:49:30 +0200 | [diff] [blame] | 49 | struct rtattr *rta = (struct rtattr *)key; |
Herbert Xu | e236d4a | 2007-11-22 23:11:53 +0800 | [diff] [blame] | 50 | struct crypto_authenc_key_param *param; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 51 | |
Herbert Xu | 12dc5e6 | 2007-12-10 10:55:21 +0800 | [diff] [blame] | 52 | if (!RTA_OK(rta, keylen)) |
Mathias Krause | bc6e2bd | 2013-10-15 13:49:30 +0200 | [diff] [blame] | 53 | return -EINVAL; |
Herbert Xu | e236d4a | 2007-11-22 23:11:53 +0800 | [diff] [blame] | 54 | if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM) |
Mathias Krause | bc6e2bd | 2013-10-15 13:49:30 +0200 | [diff] [blame] | 55 | return -EINVAL; |
Eric Biggers | 8f9c469 | 2018-12-16 23:23:22 -0800 | [diff] [blame] | 56 | |
| 57 | /* |
| 58 | * RTA_OK() didn't align the rtattr's payload when validating that it |
| 59 | * fits in the buffer. Yet, the keys should start on the next 4-byte |
| 60 | * aligned boundary. To avoid confusion, require that the rtattr |
| 61 | * payload be exactly the param struct, which has a 4-byte aligned size. |
| 62 | */ |
| 63 | if (RTA_PAYLOAD(rta) != sizeof(*param)) |
Mathias Krause | bc6e2bd | 2013-10-15 13:49:30 +0200 | [diff] [blame] | 64 | return -EINVAL; |
Eric Biggers | 8f9c469 | 2018-12-16 23:23:22 -0800 | [diff] [blame] | 65 | BUILD_BUG_ON(sizeof(*param) % RTA_ALIGNTO); |
Herbert Xu | e236d4a | 2007-11-22 23:11:53 +0800 | [diff] [blame] | 66 | |
| 67 | param = RTA_DATA(rta); |
Mathias Krause | bc6e2bd | 2013-10-15 13:49:30 +0200 | [diff] [blame] | 68 | keys->enckeylen = be32_to_cpu(param->enckeylen); |
Herbert Xu | e236d4a | 2007-11-22 23:11:53 +0800 | [diff] [blame] | 69 | |
Eric Biggers | 8f9c469 | 2018-12-16 23:23:22 -0800 | [diff] [blame] | 70 | key += rta->rta_len; |
| 71 | keylen -= rta->rta_len; |
Herbert Xu | e236d4a | 2007-11-22 23:11:53 +0800 | [diff] [blame] | 72 | |
Mathias Krause | bc6e2bd | 2013-10-15 13:49:30 +0200 | [diff] [blame] | 73 | if (keylen < keys->enckeylen) |
| 74 | return -EINVAL; |
Herbert Xu | e236d4a | 2007-11-22 23:11:53 +0800 | [diff] [blame] | 75 | |
Mathias Krause | bc6e2bd | 2013-10-15 13:49:30 +0200 | [diff] [blame] | 76 | keys->authkeylen = keylen - keys->enckeylen; |
| 77 | keys->authkey = key; |
| 78 | keys->enckey = key + keys->authkeylen; |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | EXPORT_SYMBOL_GPL(crypto_authenc_extractkeys); |
| 83 | |
| 84 | static int crypto_authenc_setkey(struct crypto_aead *authenc, const u8 *key, |
| 85 | unsigned int keylen) |
| 86 | { |
| 87 | struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); |
| 88 | struct crypto_ahash *auth = ctx->auth; |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 89 | struct crypto_skcipher *enc = ctx->enc; |
Mathias Krause | bc6e2bd | 2013-10-15 13:49:30 +0200 | [diff] [blame] | 90 | struct crypto_authenc_keys keys; |
| 91 | int err = -EINVAL; |
| 92 | |
| 93 | if (crypto_authenc_extractkeys(&keys, key, keylen) != 0) |
| 94 | goto badkey; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 95 | |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 96 | crypto_ahash_clear_flags(auth, CRYPTO_TFM_REQ_MASK); |
| 97 | crypto_ahash_set_flags(auth, crypto_aead_get_flags(authenc) & |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 98 | CRYPTO_TFM_REQ_MASK); |
Mathias Krause | bc6e2bd | 2013-10-15 13:49:30 +0200 | [diff] [blame] | 99 | err = crypto_ahash_setkey(auth, keys.authkey, keys.authkeylen); |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 100 | crypto_aead_set_flags(authenc, crypto_ahash_get_flags(auth) & |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 101 | CRYPTO_TFM_RES_MASK); |
| 102 | |
| 103 | if (err) |
| 104 | goto out; |
| 105 | |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 106 | crypto_skcipher_clear_flags(enc, CRYPTO_TFM_REQ_MASK); |
| 107 | crypto_skcipher_set_flags(enc, crypto_aead_get_flags(authenc) & |
| 108 | CRYPTO_TFM_REQ_MASK); |
| 109 | err = crypto_skcipher_setkey(enc, keys.enckey, keys.enckeylen); |
| 110 | crypto_aead_set_flags(authenc, crypto_skcipher_get_flags(enc) & |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 111 | CRYPTO_TFM_RES_MASK); |
| 112 | |
| 113 | out: |
Tudor-Dan Ambarus | ad2fdcd | 2018-04-03 09:39:00 +0300 | [diff] [blame] | 114 | memzero_explicit(&keys, sizeof(keys)); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 115 | return err; |
Herbert Xu | e236d4a | 2007-11-22 23:11:53 +0800 | [diff] [blame] | 116 | |
| 117 | badkey: |
| 118 | crypto_aead_set_flags(authenc, CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 119 | goto out; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 120 | } |
| 121 | |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 122 | static void authenc_geniv_ahash_done(struct crypto_async_request *areq, int err) |
| 123 | { |
| 124 | struct aead_request *req = areq->data; |
| 125 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 126 | struct aead_instance *inst = aead_alg_instance(authenc); |
| 127 | struct authenc_instance_ctx *ictx = aead_instance_ctx(inst); |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 128 | struct authenc_request_ctx *areq_ctx = aead_request_ctx(req); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 129 | struct ahash_request *ahreq = (void *)(areq_ctx->tail + ictx->reqoff); |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 130 | |
| 131 | if (err) |
| 132 | goto out; |
| 133 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 134 | scatterwalk_map_and_copy(ahreq->result, req->dst, |
| 135 | req->assoclen + req->cryptlen, |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 136 | crypto_aead_authsize(authenc), 1); |
| 137 | |
| 138 | out: |
| 139 | aead_request_complete(req, err); |
| 140 | } |
| 141 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 142 | static int crypto_authenc_genicv(struct aead_request *req, unsigned int flags) |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 143 | { |
| 144 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 145 | struct aead_instance *inst = aead_alg_instance(authenc); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 146 | struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 147 | struct authenc_instance_ctx *ictx = aead_instance_ctx(inst); |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 148 | struct crypto_ahash *auth = ctx->auth; |
| 149 | struct authenc_request_ctx *areq_ctx = aead_request_ctx(req); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 150 | struct ahash_request *ahreq = (void *)(areq_ctx->tail + ictx->reqoff); |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 151 | u8 *hash = areq_ctx->tail; |
| 152 | int err; |
| 153 | |
| 154 | hash = (u8 *)ALIGN((unsigned long)hash + crypto_ahash_alignmask(auth), |
| 155 | crypto_ahash_alignmask(auth) + 1); |
| 156 | |
| 157 | ahash_request_set_tfm(ahreq, auth); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 158 | ahash_request_set_crypt(ahreq, req->dst, hash, |
| 159 | req->assoclen + req->cryptlen); |
| 160 | ahash_request_set_callback(ahreq, flags, |
| 161 | authenc_geniv_ahash_done, req); |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 162 | |
| 163 | err = crypto_ahash_digest(ahreq); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 164 | if (err) |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 165 | return err; |
Herbert Xu | 7c3d703 | 2007-12-10 16:15:41 +0800 | [diff] [blame] | 166 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 167 | scatterwalk_map_and_copy(hash, req->dst, req->assoclen + req->cryptlen, |
Herbert Xu | 7ba683a | 2007-12-02 18:49:21 +1100 | [diff] [blame] | 168 | crypto_aead_authsize(authenc), 1); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 169 | |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | static void crypto_authenc_encrypt_done(struct crypto_async_request *req, |
| 174 | int err) |
| 175 | { |
Herbert Xu | a697690 | 2008-08-23 01:04:06 +1000 | [diff] [blame] | 176 | struct aead_request *areq = req->data; |
| 177 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 178 | if (err) |
| 179 | goto out; |
Herbert Xu | e56dd56 | 2007-12-10 16:20:24 +0800 | [diff] [blame] | 180 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 181 | err = crypto_authenc_genicv(areq, 0); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 182 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 183 | out: |
Herbert Xu | 180ce7e | 2010-04-26 09:14:05 +0800 | [diff] [blame] | 184 | authenc_request_complete(areq, err); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 185 | } |
| 186 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 187 | static int crypto_authenc_copy_assoc(struct aead_request *req) |
| 188 | { |
| 189 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
| 190 | struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); |
Kees Cook | 8d60539 | 2018-09-18 19:10:51 -0700 | [diff] [blame] | 191 | SYNC_SKCIPHER_REQUEST_ON_STACK(skreq, ctx->null); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 192 | |
Kees Cook | 8d60539 | 2018-09-18 19:10:51 -0700 | [diff] [blame] | 193 | skcipher_request_set_sync_tfm(skreq, ctx->null); |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 194 | skcipher_request_set_callback(skreq, aead_request_flags(req), |
| 195 | NULL, NULL); |
| 196 | skcipher_request_set_crypt(skreq, req->src, req->dst, req->assoclen, |
| 197 | NULL); |
| 198 | |
| 199 | return crypto_skcipher_encrypt(skreq); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 200 | } |
| 201 | |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 202 | static int crypto_authenc_encrypt(struct aead_request *req) |
| 203 | { |
| 204 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 205 | struct aead_instance *inst = aead_alg_instance(authenc); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 206 | struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 207 | struct authenc_instance_ctx *ictx = aead_instance_ctx(inst); |
Steffen Klassert | 50beceb | 2010-03-03 22:41:08 +0800 | [diff] [blame] | 208 | struct authenc_request_ctx *areq_ctx = aead_request_ctx(req); |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 209 | struct crypto_skcipher *enc = ctx->enc; |
Herbert Xu | e56dd56 | 2007-12-10 16:20:24 +0800 | [diff] [blame] | 210 | unsigned int cryptlen = req->cryptlen; |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 211 | struct skcipher_request *skreq = (void *)(areq_ctx->tail + |
| 212 | ictx->reqoff); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 213 | struct scatterlist *src, *dst; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 214 | int err; |
| 215 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 216 | src = scatterwalk_ffwd(areq_ctx->src, req->src, req->assoclen); |
| 217 | dst = src; |
| 218 | |
| 219 | if (req->src != req->dst) { |
| 220 | err = crypto_authenc_copy_assoc(req); |
| 221 | if (err) |
| 222 | return err; |
| 223 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 224 | dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, req->assoclen); |
| 225 | } |
| 226 | |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 227 | skcipher_request_set_tfm(skreq, enc); |
| 228 | skcipher_request_set_callback(skreq, aead_request_flags(req), |
| 229 | crypto_authenc_encrypt_done, req); |
| 230 | skcipher_request_set_crypt(skreq, src, dst, cryptlen, req->iv); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 231 | |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 232 | err = crypto_skcipher_encrypt(skreq); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 233 | if (err) |
| 234 | return err; |
| 235 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 236 | return crypto_authenc_genicv(req, aead_request_flags(req)); |
Herbert Xu | e56dd56 | 2007-12-10 16:20:24 +0800 | [diff] [blame] | 237 | } |
| 238 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 239 | static int crypto_authenc_decrypt_tail(struct aead_request *req, |
| 240 | unsigned int flags) |
Herbert Xu | e56dd56 | 2007-12-10 16:20:24 +0800 | [diff] [blame] | 241 | { |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 242 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
| 243 | struct aead_instance *inst = aead_alg_instance(authenc); |
Herbert Xu | e56dd56 | 2007-12-10 16:20:24 +0800 | [diff] [blame] | 244 | struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 245 | struct authenc_instance_ctx *ictx = aead_instance_ctx(inst); |
| 246 | struct authenc_request_ctx *areq_ctx = aead_request_ctx(req); |
| 247 | struct ahash_request *ahreq = (void *)(areq_ctx->tail + ictx->reqoff); |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 248 | struct skcipher_request *skreq = (void *)(areq_ctx->tail + |
| 249 | ictx->reqoff); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 250 | unsigned int authsize = crypto_aead_authsize(authenc); |
| 251 | u8 *ihash = ahreq->result + authsize; |
| 252 | struct scatterlist *src, *dst; |
Herbert Xu | e56dd56 | 2007-12-10 16:20:24 +0800 | [diff] [blame] | 253 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 254 | scatterwalk_map_and_copy(ihash, req->src, ahreq->nbytes, authsize, 0); |
Herbert Xu | e56dd56 | 2007-12-10 16:20:24 +0800 | [diff] [blame] | 255 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 256 | if (crypto_memneq(ihash, ahreq->result, authsize)) |
| 257 | return -EBADMSG; |
| 258 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 259 | src = scatterwalk_ffwd(areq_ctx->src, req->src, req->assoclen); |
| 260 | dst = src; |
| 261 | |
Harsh Jain | c34252f | 2016-06-29 00:24:43 +0530 | [diff] [blame] | 262 | if (req->src != req->dst) |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 263 | dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, req->assoclen); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 264 | |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 265 | skcipher_request_set_tfm(skreq, ctx->enc); |
| 266 | skcipher_request_set_callback(skreq, aead_request_flags(req), |
| 267 | req->base.complete, req->base.data); |
| 268 | skcipher_request_set_crypt(skreq, src, dst, |
| 269 | req->cryptlen - authsize, req->iv); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 270 | |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 271 | return crypto_skcipher_decrypt(skreq); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static void authenc_verify_ahash_done(struct crypto_async_request *areq, |
| 275 | int err) |
| 276 | { |
| 277 | struct aead_request *req = areq->data; |
| 278 | |
Herbert Xu | e56dd56 | 2007-12-10 16:20:24 +0800 | [diff] [blame] | 279 | if (err) |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 280 | goto out; |
Herbert Xu | e56dd56 | 2007-12-10 16:20:24 +0800 | [diff] [blame] | 281 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 282 | err = crypto_authenc_decrypt_tail(req, 0); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 283 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 284 | out: |
| 285 | authenc_request_complete(req, err); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | static int crypto_authenc_decrypt(struct aead_request *req) |
| 289 | { |
| 290 | struct crypto_aead *authenc = crypto_aead_reqtfm(req); |
Herbert Xu | 481f34a | 2007-12-04 20:04:21 +1100 | [diff] [blame] | 291 | unsigned int authsize = crypto_aead_authsize(authenc); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 292 | struct aead_instance *inst = aead_alg_instance(authenc); |
| 293 | struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); |
| 294 | struct authenc_instance_ctx *ictx = aead_instance_ctx(inst); |
| 295 | struct crypto_ahash *auth = ctx->auth; |
| 296 | struct authenc_request_ctx *areq_ctx = aead_request_ctx(req); |
| 297 | struct ahash_request *ahreq = (void *)(areq_ctx->tail + ictx->reqoff); |
| 298 | u8 *hash = areq_ctx->tail; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 299 | int err; |
| 300 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 301 | hash = (u8 *)ALIGN((unsigned long)hash + crypto_ahash_alignmask(auth), |
| 302 | crypto_ahash_alignmask(auth) + 1); |
Herbert Xu | 481f34a | 2007-12-04 20:04:21 +1100 | [diff] [blame] | 303 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 304 | ahash_request_set_tfm(ahreq, auth); |
| 305 | ahash_request_set_crypt(ahreq, req->src, hash, |
| 306 | req->assoclen + req->cryptlen - authsize); |
| 307 | ahash_request_set_callback(ahreq, aead_request_flags(req), |
| 308 | authenc_verify_ahash_done, req); |
| 309 | |
| 310 | err = crypto_ahash_digest(ahreq); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 311 | if (err) |
| 312 | return err; |
| 313 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 314 | return crypto_authenc_decrypt_tail(req, aead_request_flags(req)); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 315 | } |
| 316 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 317 | static int crypto_authenc_init_tfm(struct crypto_aead *tfm) |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 318 | { |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 319 | struct aead_instance *inst = aead_alg_instance(tfm); |
| 320 | struct authenc_instance_ctx *ictx = aead_instance_ctx(inst); |
| 321 | struct crypto_authenc_ctx *ctx = crypto_aead_ctx(tfm); |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 322 | struct crypto_ahash *auth; |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 323 | struct crypto_skcipher *enc; |
Kees Cook | 8d60539 | 2018-09-18 19:10:51 -0700 | [diff] [blame] | 324 | struct crypto_sync_skcipher *null; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 325 | int err; |
| 326 | |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 327 | auth = crypto_spawn_ahash(&ictx->auth); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 328 | if (IS_ERR(auth)) |
| 329 | return PTR_ERR(auth); |
| 330 | |
Eric Biggers | 60425a8 | 2016-10-28 09:52:19 -0700 | [diff] [blame] | 331 | enc = crypto_spawn_skcipher(&ictx->enc); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 332 | err = PTR_ERR(enc); |
| 333 | if (IS_ERR(enc)) |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 334 | goto err_free_ahash; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 335 | |
Eric Biggers | 3a2d4fb | 2017-12-07 10:56:34 -0800 | [diff] [blame] | 336 | null = crypto_get_default_null_skcipher(); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 337 | err = PTR_ERR(null); |
| 338 | if (IS_ERR(null)) |
| 339 | goto err_free_skcipher; |
| 340 | |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 341 | ctx->auth = auth; |
| 342 | ctx->enc = enc; |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 343 | ctx->null = null; |
Richard Hartmann | f3542e6 | 2010-02-16 20:27:20 +0800 | [diff] [blame] | 344 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 345 | crypto_aead_set_reqsize( |
| 346 | tfm, |
Herbert Xu | 25df919 | 2015-05-11 17:47:53 +0800 | [diff] [blame] | 347 | sizeof(struct authenc_request_ctx) + |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 348 | ictx->reqoff + |
Herbert Xu | 25df919 | 2015-05-11 17:47:53 +0800 | [diff] [blame] | 349 | max_t(unsigned int, |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 350 | crypto_ahash_reqsize(auth) + |
| 351 | sizeof(struct ahash_request), |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 352 | sizeof(struct skcipher_request) + |
| 353 | crypto_skcipher_reqsize(enc))); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 354 | |
| 355 | return 0; |
| 356 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 357 | err_free_skcipher: |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 358 | crypto_free_skcipher(enc); |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 359 | err_free_ahash: |
| 360 | crypto_free_ahash(auth); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 361 | return err; |
| 362 | } |
| 363 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 364 | static void crypto_authenc_exit_tfm(struct crypto_aead *tfm) |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 365 | { |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 366 | struct crypto_authenc_ctx *ctx = crypto_aead_ctx(tfm); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 367 | |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 368 | crypto_free_ahash(ctx->auth); |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 369 | crypto_free_skcipher(ctx->enc); |
Eric Biggers | 3a2d4fb | 2017-12-07 10:56:34 -0800 | [diff] [blame] | 370 | crypto_put_default_null_skcipher(); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 371 | } |
| 372 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 373 | static void crypto_authenc_free(struct aead_instance *inst) |
| 374 | { |
| 375 | struct authenc_instance_ctx *ctx = aead_instance_ctx(inst); |
| 376 | |
| 377 | crypto_drop_skcipher(&ctx->enc); |
| 378 | crypto_drop_ahash(&ctx->auth); |
| 379 | kfree(inst); |
| 380 | } |
| 381 | |
| 382 | static int crypto_authenc_create(struct crypto_template *tmpl, |
| 383 | struct rtattr **tb) |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 384 | { |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 385 | struct crypto_attr_type *algt; |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 386 | struct aead_instance *inst; |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 387 | struct hash_alg_common *auth; |
| 388 | struct crypto_alg *auth_base; |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 389 | struct skcipher_alg *enc; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 390 | struct authenc_instance_ctx *ctx; |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 391 | const char *enc_name; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 392 | int err; |
| 393 | |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 394 | algt = crypto_get_attr_type(tb); |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 395 | if (IS_ERR(algt)) |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 396 | return PTR_ERR(algt); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 397 | |
Herbert Xu | 5e4b8c1 | 2015-08-13 17:29:06 +0800 | [diff] [blame] | 398 | if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 399 | return -EINVAL; |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 400 | |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 401 | auth = ahash_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH, |
Herbert Xu | 927ef32 | 2016-06-29 18:03:46 +0800 | [diff] [blame] | 402 | CRYPTO_ALG_TYPE_AHASH_MASK | |
| 403 | crypto_requires_sync(algt->type, algt->mask)); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 404 | if (IS_ERR(auth)) |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 405 | return PTR_ERR(auth); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 406 | |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 407 | auth_base = &auth->base; |
| 408 | |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 409 | enc_name = crypto_attr_alg_name(tb[2]); |
| 410 | err = PTR_ERR(enc_name); |
| 411 | if (IS_ERR(enc_name)) |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 412 | goto out_put_auth; |
| 413 | |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 414 | inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); |
| 415 | err = -ENOMEM; |
| 416 | if (!inst) |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 417 | goto out_put_auth; |
Herbert Xu | e236d4a | 2007-11-22 23:11:53 +0800 | [diff] [blame] | 418 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 419 | ctx = aead_instance_ctx(inst); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 420 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 421 | err = crypto_init_ahash_spawn(&ctx->auth, auth, |
| 422 | aead_crypto_instance(inst)); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 423 | if (err) |
| 424 | goto err_free_inst; |
| 425 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 426 | crypto_set_skcipher_spawn(&ctx->enc, aead_crypto_instance(inst)); |
Eric Biggers | a35528e | 2016-10-28 09:51:13 -0700 | [diff] [blame] | 427 | err = crypto_grab_skcipher(&ctx->enc, enc_name, 0, |
| 428 | crypto_requires_sync(algt->type, |
| 429 | algt->mask)); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 430 | if (err) |
| 431 | goto err_drop_auth; |
| 432 | |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 433 | enc = crypto_spawn_skcipher_alg(&ctx->enc); |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 434 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 435 | ctx->reqoff = ALIGN(2 * auth->digestsize + auth_base->cra_alignmask, |
| 436 | auth_base->cra_alignmask + 1); |
| 437 | |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 438 | err = -ENAMETOOLONG; |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 439 | if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 440 | "authenc(%s,%s)", auth_base->cra_name, |
| 441 | enc->base.cra_name) >= |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 442 | CRYPTO_MAX_ALG_NAME) |
| 443 | goto err_drop_enc; |
| 444 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 445 | if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 446 | "authenc(%s,%s)", auth_base->cra_driver_name, |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 447 | enc->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME) |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 448 | goto err_drop_enc; |
| 449 | |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 450 | inst->alg.base.cra_flags = (auth_base->cra_flags | |
| 451 | enc->base.cra_flags) & CRYPTO_ALG_ASYNC; |
| 452 | inst->alg.base.cra_priority = enc->base.cra_priority * 10 + |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 453 | auth_base->cra_priority; |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 454 | inst->alg.base.cra_blocksize = enc->base.cra_blocksize; |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 455 | inst->alg.base.cra_alignmask = auth_base->cra_alignmask | |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 456 | enc->base.cra_alignmask; |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 457 | inst->alg.base.cra_ctxsize = sizeof(struct crypto_authenc_ctx); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 458 | |
Herbert Xu | 7217d49 | 2016-07-12 13:17:34 +0800 | [diff] [blame] | 459 | inst->alg.ivsize = crypto_skcipher_alg_ivsize(enc); |
| 460 | inst->alg.chunksize = crypto_skcipher_alg_chunksize(enc); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 461 | inst->alg.maxauthsize = auth->digestsize; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 462 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 463 | inst->alg.init = crypto_authenc_init_tfm; |
| 464 | inst->alg.exit = crypto_authenc_exit_tfm; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 465 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 466 | inst->alg.setkey = crypto_authenc_setkey; |
| 467 | inst->alg.encrypt = crypto_authenc_encrypt; |
| 468 | inst->alg.decrypt = crypto_authenc_decrypt; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 469 | |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 470 | inst->free = crypto_authenc_free; |
| 471 | |
| 472 | err = aead_register_instance(tmpl, inst); |
| 473 | if (err) |
| 474 | goto err_drop_enc; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 475 | |
| 476 | out: |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 477 | crypto_mod_put(auth_base); |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 478 | return err; |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 479 | |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 480 | err_drop_enc: |
| 481 | crypto_drop_skcipher(&ctx->enc); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 482 | err_drop_auth: |
Steffen Klassert | cbdcf80 | 2009-08-05 19:35:34 +1000 | [diff] [blame] | 483 | crypto_drop_ahash(&ctx->auth); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 484 | err_free_inst: |
| 485 | kfree(inst); |
Herbert Xu | 9ffde35a | 2007-12-17 20:12:49 +0800 | [diff] [blame] | 486 | out_put_auth: |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 487 | goto out; |
| 488 | } |
| 489 | |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 490 | static struct crypto_template crypto_authenc_tmpl = { |
| 491 | .name = "authenc", |
Herbert Xu | 92d95ba | 2015-07-30 17:53:16 +0800 | [diff] [blame] | 492 | .create = crypto_authenc_create, |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 493 | .module = THIS_MODULE, |
| 494 | }; |
| 495 | |
| 496 | static int __init crypto_authenc_module_init(void) |
| 497 | { |
| 498 | return crypto_register_template(&crypto_authenc_tmpl); |
| 499 | } |
| 500 | |
| 501 | static void __exit crypto_authenc_module_exit(void) |
| 502 | { |
| 503 | crypto_unregister_template(&crypto_authenc_tmpl); |
| 504 | } |
| 505 | |
Eric Biggers | c4741b2 | 2019-04-11 21:57:42 -0700 | [diff] [blame] | 506 | subsys_initcall(crypto_authenc_module_init); |
Herbert Xu | 3c09f17 | 2007-08-30 16:24:15 +0800 | [diff] [blame] | 507 | module_exit(crypto_authenc_module_exit); |
| 508 | |
| 509 | MODULE_LICENSE("GPL"); |
| 510 | MODULE_DESCRIPTION("Simple AEAD wrapper for IPsec"); |
Kees Cook | 4943ba1 | 2014-11-24 16:32:38 -0800 | [diff] [blame] | 511 | MODULE_ALIAS_CRYPTO("authenc"); |