Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 2 | /* |
| 3 | * GCM: Galois/Counter Mode. |
| 4 | * |
| 5 | * Copyright (c) 2007 Nokia Siemens Networks - Mikko Herranen <mh1@iki.fi> |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 8 | #include <crypto/gf128mul.h> |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 9 | #include <crypto/internal/aead.h> |
Herbert Xu | 1472e5e | 2007-12-07 19:26:11 +0800 | [diff] [blame] | 10 | #include <crypto/internal/skcipher.h> |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 11 | #include <crypto/internal/hash.h> |
Herbert Xu | 17db854 | 2015-05-21 15:11:11 +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> |
Corentin LABBE | e0ab7e9 | 2017-08-22 10:08:17 +0200 | [diff] [blame] | 14 | #include <crypto/gcm.h> |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 15 | #include <crypto/hash.h> |
| 16 | #include "internal.h" |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 17 | #include <linux/err.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/slab.h> |
| 22 | |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 23 | struct gcm_instance_ctx { |
Herbert Xu | 1472e5e | 2007-12-07 19:26:11 +0800 | [diff] [blame] | 24 | struct crypto_skcipher_spawn ctr; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 25 | struct crypto_ahash_spawn ghash; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | struct crypto_gcm_ctx { |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 29 | struct crypto_skcipher *ctr; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 30 | struct crypto_ahash *ghash; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 31 | }; |
| 32 | |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 33 | struct crypto_rfc4106_ctx { |
| 34 | struct crypto_aead *child; |
| 35 | u8 nonce[4]; |
| 36 | }; |
| 37 | |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 38 | struct crypto_rfc4106_req_ctx { |
| 39 | struct scatterlist src[3]; |
| 40 | struct scatterlist dst[3]; |
| 41 | struct aead_request subreq; |
| 42 | }; |
| 43 | |
Jussi Kivilinna | 9489667d | 2013-04-07 16:43:41 +0300 | [diff] [blame] | 44 | struct crypto_rfc4543_instance_ctx { |
| 45 | struct crypto_aead_spawn aead; |
Jussi Kivilinna | 9489667d | 2013-04-07 16:43:41 +0300 | [diff] [blame] | 46 | }; |
| 47 | |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 48 | struct crypto_rfc4543_ctx { |
| 49 | struct crypto_aead *child; |
Kees Cook | 8d60539 | 2018-09-18 19:10:51 -0700 | [diff] [blame] | 50 | struct crypto_sync_skcipher *null; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 51 | u8 nonce[4]; |
| 52 | }; |
| 53 | |
| 54 | struct crypto_rfc4543_req_ctx { |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 55 | struct aead_request subreq; |
| 56 | }; |
| 57 | |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 58 | struct crypto_gcm_ghash_ctx { |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 59 | unsigned int cryptlen; |
| 60 | struct scatterlist *src; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 61 | int (*complete)(struct aead_request *req, u32 flags); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | struct crypto_gcm_req_priv_ctx { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 65 | u8 iv[16]; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 66 | u8 auth_tag[16]; |
Herbert Xu | 6160b28 | 2007-12-04 19:17:50 +1100 | [diff] [blame] | 67 | u8 iauth_tag[16]; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 68 | struct scatterlist src[3]; |
| 69 | struct scatterlist dst[3]; |
| 70 | struct scatterlist sg; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 71 | struct crypto_gcm_ghash_ctx ghash_ctx; |
| 72 | union { |
| 73 | struct ahash_request ahreq; |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 74 | struct skcipher_request skreq; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 75 | } u; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 76 | }; |
| 77 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 78 | static struct { |
| 79 | u8 buf[16]; |
| 80 | struct scatterlist sg; |
| 81 | } *gcm_zeroes; |
| 82 | |
| 83 | static int crypto_rfc4543_copy_src_to_dst(struct aead_request *req, bool enc); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 84 | |
Herbert Xu | 2589469 | 2007-12-12 19:16:38 +0800 | [diff] [blame] | 85 | static inline struct crypto_gcm_req_priv_ctx *crypto_gcm_reqctx( |
| 86 | struct aead_request *req) |
| 87 | { |
| 88 | unsigned long align = crypto_aead_alignmask(crypto_aead_reqtfm(req)); |
| 89 | |
| 90 | return (void *)PTR_ALIGN((u8 *)aead_request_ctx(req), align + 1); |
| 91 | } |
| 92 | |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 93 | static int crypto_gcm_setkey(struct crypto_aead *aead, const u8 *key, |
| 94 | unsigned int keylen) |
| 95 | { |
| 96 | struct crypto_gcm_ctx *ctx = crypto_aead_ctx(aead); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 97 | struct crypto_ahash *ghash = ctx->ghash; |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 98 | struct crypto_skcipher *ctr = ctx->ctr; |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 99 | struct { |
| 100 | be128 hash; |
Ondrej Mosnáček | 50d2e6d | 2016-09-23 10:47:32 +0200 | [diff] [blame] | 101 | u8 iv[16]; |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 102 | |
Gilad Ben-Yossef | 76c6739 | 2017-10-18 08:00:42 +0100 | [diff] [blame] | 103 | struct crypto_wait wait; |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 104 | |
| 105 | struct scatterlist sg[1]; |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 106 | struct skcipher_request req; |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 107 | } *data; |
| 108 | int err; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 109 | |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 110 | crypto_skcipher_clear_flags(ctr, CRYPTO_TFM_REQ_MASK); |
| 111 | crypto_skcipher_set_flags(ctr, crypto_aead_get_flags(aead) & |
| 112 | CRYPTO_TFM_REQ_MASK); |
| 113 | err = crypto_skcipher_setkey(ctr, key, keylen); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 114 | if (err) |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 115 | return err; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 116 | |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 117 | data = kzalloc(sizeof(*data) + crypto_skcipher_reqsize(ctr), |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 118 | GFP_KERNEL); |
| 119 | if (!data) |
| 120 | return -ENOMEM; |
| 121 | |
Gilad Ben-Yossef | 76c6739 | 2017-10-18 08:00:42 +0100 | [diff] [blame] | 122 | crypto_init_wait(&data->wait); |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 123 | sg_init_one(data->sg, &data->hash, sizeof(data->hash)); |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 124 | skcipher_request_set_tfm(&data->req, ctr); |
| 125 | skcipher_request_set_callback(&data->req, CRYPTO_TFM_REQ_MAY_SLEEP | |
| 126 | CRYPTO_TFM_REQ_MAY_BACKLOG, |
Gilad Ben-Yossef | 76c6739 | 2017-10-18 08:00:42 +0100 | [diff] [blame] | 127 | crypto_req_done, |
| 128 | &data->wait); |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 129 | skcipher_request_set_crypt(&data->req, data->sg, data->sg, |
| 130 | sizeof(data->hash), data->iv); |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 131 | |
Gilad Ben-Yossef | 76c6739 | 2017-10-18 08:00:42 +0100 | [diff] [blame] | 132 | err = crypto_wait_req(crypto_skcipher_encrypt(&data->req), |
| 133 | &data->wait); |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 134 | |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 135 | if (err) |
| 136 | goto out; |
| 137 | |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 138 | crypto_ahash_clear_flags(ghash, CRYPTO_TFM_REQ_MASK); |
| 139 | crypto_ahash_set_flags(ghash, crypto_aead_get_flags(aead) & |
| 140 | CRYPTO_TFM_REQ_MASK); |
| 141 | err = crypto_ahash_setkey(ghash, (u8 *)&data->hash, sizeof(be128)); |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 142 | out: |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 143 | kzfree(data); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 144 | return err; |
| 145 | } |
| 146 | |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 147 | static int crypto_gcm_setauthsize(struct crypto_aead *tfm, |
| 148 | unsigned int authsize) |
| 149 | { |
Iuliana Prodan | 65526f6 | 2019-07-31 16:05:54 +0300 | [diff] [blame] | 150 | return crypto_gcm_check_authsize(authsize); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 151 | } |
| 152 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 153 | static void crypto_gcm_init_common(struct aead_request *req) |
| 154 | { |
| 155 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
| 156 | __be32 counter = cpu_to_be32(1); |
| 157 | struct scatterlist *sg; |
| 158 | |
| 159 | memset(pctx->auth_tag, 0, sizeof(pctx->auth_tag)); |
Corentin LABBE | e0ab7e9 | 2017-08-22 10:08:17 +0200 | [diff] [blame] | 160 | memcpy(pctx->iv, req->iv, GCM_AES_IV_SIZE); |
| 161 | memcpy(pctx->iv + GCM_AES_IV_SIZE, &counter, 4); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 162 | |
| 163 | sg_init_table(pctx->src, 3); |
| 164 | sg_set_buf(pctx->src, pctx->auth_tag, sizeof(pctx->auth_tag)); |
| 165 | sg = scatterwalk_ffwd(pctx->src + 1, req->src, req->assoclen); |
| 166 | if (sg != pctx->src + 1) |
Dan Williams | c56f6d1 | 2015-08-07 18:15:13 +0200 | [diff] [blame] | 167 | sg_chain(pctx->src, 2, sg); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 168 | |
| 169 | if (req->src != req->dst) { |
| 170 | sg_init_table(pctx->dst, 3); |
| 171 | sg_set_buf(pctx->dst, pctx->auth_tag, sizeof(pctx->auth_tag)); |
| 172 | sg = scatterwalk_ffwd(pctx->dst + 1, req->dst, req->assoclen); |
| 173 | if (sg != pctx->dst + 1) |
Dan Williams | c56f6d1 | 2015-08-07 18:15:13 +0200 | [diff] [blame] | 174 | sg_chain(pctx->dst, 2, sg); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
| 178 | static void crypto_gcm_init_crypt(struct aead_request *req, |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 179 | unsigned int cryptlen) |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 180 | { |
| 181 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 182 | struct crypto_gcm_ctx *ctx = crypto_aead_ctx(aead); |
Herbert Xu | 2589469 | 2007-12-12 19:16:38 +0800 | [diff] [blame] | 183 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 184 | struct skcipher_request *skreq = &pctx->u.skreq; |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 185 | struct scatterlist *dst; |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 186 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 187 | dst = req->src == req->dst ? pctx->src : pctx->dst; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 188 | |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 189 | skcipher_request_set_tfm(skreq, ctx->ctr); |
| 190 | skcipher_request_set_crypt(skreq, pctx->src, dst, |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 191 | cryptlen + sizeof(pctx->auth_tag), |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 192 | pctx->iv); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 193 | } |
| 194 | |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 195 | static inline unsigned int gcm_remain(unsigned int len) |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 196 | { |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 197 | len &= 0xfU; |
| 198 | return len ? 16 - len : 0; |
| 199 | } |
| 200 | |
| 201 | static void gcm_hash_len_done(struct crypto_async_request *areq, int err); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 202 | |
| 203 | static int gcm_hash_update(struct aead_request *req, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 204 | crypto_completion_t compl, |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 205 | struct scatterlist *src, |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 206 | unsigned int len, u32 flags) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 207 | { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 208 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 209 | struct ahash_request *ahreq = &pctx->u.ahreq; |
| 210 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 211 | ahash_request_set_callback(ahreq, flags, compl, req); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 212 | ahash_request_set_crypt(ahreq, src, NULL, len); |
| 213 | |
| 214 | return crypto_ahash_update(ahreq); |
| 215 | } |
| 216 | |
| 217 | static int gcm_hash_remain(struct aead_request *req, |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 218 | unsigned int remain, |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 219 | crypto_completion_t compl, u32 flags) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 220 | { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 221 | return gcm_hash_update(req, compl, &gcm_zeroes->sg, remain, flags); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 222 | } |
| 223 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 224 | static int gcm_hash_len(struct aead_request *req, u32 flags) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 225 | { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 226 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 227 | struct ahash_request *ahreq = &pctx->u.ahreq; |
| 228 | struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx; |
Eric Biggers | 1866655 | 2019-01-10 12:17:52 -0800 | [diff] [blame] | 229 | be128 lengths; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 230 | |
| 231 | lengths.a = cpu_to_be64(req->assoclen * 8); |
| 232 | lengths.b = cpu_to_be64(gctx->cryptlen * 8); |
| 233 | memcpy(pctx->iauth_tag, &lengths, 16); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 234 | sg_init_one(&pctx->sg, pctx->iauth_tag, 16); |
| 235 | ahash_request_set_callback(ahreq, flags, gcm_hash_len_done, req); |
| 236 | ahash_request_set_crypt(ahreq, &pctx->sg, |
| 237 | pctx->iauth_tag, sizeof(lengths)); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 238 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 239 | return crypto_ahash_finup(ahreq); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 240 | } |
| 241 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 242 | static int gcm_hash_len_continue(struct aead_request *req, u32 flags) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 243 | { |
Herbert Xu | 2589469 | 2007-12-12 19:16:38 +0800 | [diff] [blame] | 244 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 245 | struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 246 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 247 | return gctx->complete(req, flags); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 248 | } |
| 249 | |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 250 | static void gcm_hash_len_done(struct crypto_async_request *areq, int err) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 251 | { |
| 252 | struct aead_request *req = areq->data; |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 253 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 254 | if (err) |
| 255 | goto out; |
| 256 | |
| 257 | err = gcm_hash_len_continue(req, 0); |
| 258 | if (err == -EINPROGRESS) |
| 259 | return; |
| 260 | |
| 261 | out: |
| 262 | aead_request_complete(req, err); |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 263 | } |
| 264 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 265 | static int gcm_hash_crypt_remain_continue(struct aead_request *req, u32 flags) |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 266 | { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 267 | return gcm_hash_len(req, flags) ?: |
| 268 | gcm_hash_len_continue(req, flags); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 269 | } |
| 270 | |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 271 | static void gcm_hash_crypt_remain_done(struct crypto_async_request *areq, |
| 272 | int err) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 273 | { |
| 274 | struct aead_request *req = areq->data; |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 275 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 276 | if (err) |
| 277 | goto out; |
| 278 | |
| 279 | err = gcm_hash_crypt_remain_continue(req, 0); |
| 280 | if (err == -EINPROGRESS) |
| 281 | return; |
| 282 | |
| 283 | out: |
| 284 | aead_request_complete(req, err); |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 285 | } |
| 286 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 287 | static int gcm_hash_crypt_continue(struct aead_request *req, u32 flags) |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 288 | { |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 289 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
| 290 | struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx; |
| 291 | unsigned int remain; |
| 292 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 293 | remain = gcm_remain(gctx->cryptlen); |
| 294 | if (remain) |
| 295 | return gcm_hash_remain(req, remain, |
| 296 | gcm_hash_crypt_remain_done, flags) ?: |
| 297 | gcm_hash_crypt_remain_continue(req, flags); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 298 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 299 | return gcm_hash_crypt_remain_continue(req, flags); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 300 | } |
| 301 | |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 302 | static void gcm_hash_crypt_done(struct crypto_async_request *areq, int err) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 303 | { |
| 304 | struct aead_request *req = areq->data; |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 305 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 306 | if (err) |
| 307 | goto out; |
| 308 | |
| 309 | err = gcm_hash_crypt_continue(req, 0); |
| 310 | if (err == -EINPROGRESS) |
| 311 | return; |
| 312 | |
| 313 | out: |
| 314 | aead_request_complete(req, err); |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 315 | } |
| 316 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 317 | static int gcm_hash_assoc_remain_continue(struct aead_request *req, u32 flags) |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 318 | { |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 319 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
| 320 | struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 321 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 322 | if (gctx->cryptlen) |
| 323 | return gcm_hash_update(req, gcm_hash_crypt_done, |
| 324 | gctx->src, gctx->cryptlen, flags) ?: |
| 325 | gcm_hash_crypt_continue(req, flags); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 326 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 327 | return gcm_hash_crypt_remain_continue(req, flags); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 328 | } |
| 329 | |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 330 | static void gcm_hash_assoc_remain_done(struct crypto_async_request *areq, |
| 331 | int err) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 332 | { |
| 333 | struct aead_request *req = areq->data; |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 334 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 335 | if (err) |
| 336 | goto out; |
| 337 | |
| 338 | err = gcm_hash_assoc_remain_continue(req, 0); |
| 339 | if (err == -EINPROGRESS) |
| 340 | return; |
| 341 | |
| 342 | out: |
| 343 | aead_request_complete(req, err); |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 344 | } |
| 345 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 346 | static int gcm_hash_assoc_continue(struct aead_request *req, u32 flags) |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 347 | { |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 348 | unsigned int remain; |
| 349 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 350 | remain = gcm_remain(req->assoclen); |
| 351 | if (remain) |
| 352 | return gcm_hash_remain(req, remain, |
| 353 | gcm_hash_assoc_remain_done, flags) ?: |
| 354 | gcm_hash_assoc_remain_continue(req, flags); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 355 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 356 | return gcm_hash_assoc_remain_continue(req, flags); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 357 | } |
| 358 | |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 359 | static void gcm_hash_assoc_done(struct crypto_async_request *areq, int err) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 360 | { |
| 361 | struct aead_request *req = areq->data; |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 362 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 363 | if (err) |
| 364 | goto out; |
| 365 | |
| 366 | err = gcm_hash_assoc_continue(req, 0); |
| 367 | if (err == -EINPROGRESS) |
| 368 | return; |
| 369 | |
| 370 | out: |
| 371 | aead_request_complete(req, err); |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 372 | } |
| 373 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 374 | static int gcm_hash_init_continue(struct aead_request *req, u32 flags) |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 375 | { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 376 | if (req->assoclen) |
| 377 | return gcm_hash_update(req, gcm_hash_assoc_done, |
| 378 | req->src, req->assoclen, flags) ?: |
| 379 | gcm_hash_assoc_continue(req, flags); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 380 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 381 | return gcm_hash_assoc_remain_continue(req, flags); |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | static void gcm_hash_init_done(struct crypto_async_request *areq, int err) |
| 385 | { |
| 386 | struct aead_request *req = areq->data; |
| 387 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 388 | if (err) |
| 389 | goto out; |
| 390 | |
| 391 | err = gcm_hash_init_continue(req, 0); |
| 392 | if (err == -EINPROGRESS) |
| 393 | return; |
| 394 | |
| 395 | out: |
| 396 | aead_request_complete(req, err); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 397 | } |
| 398 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 399 | static int gcm_hash(struct aead_request *req, u32 flags) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 400 | { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 401 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 402 | struct ahash_request *ahreq = &pctx->u.ahreq; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 403 | struct crypto_gcm_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 404 | |
| 405 | ahash_request_set_tfm(ahreq, ctx->ghash); |
| 406 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 407 | ahash_request_set_callback(ahreq, flags, gcm_hash_init_done, req); |
| 408 | return crypto_ahash_init(ahreq) ?: |
| 409 | gcm_hash_init_continue(req, flags); |
Herbert Xu | 6160b28 | 2007-12-04 19:17:50 +1100 | [diff] [blame] | 410 | } |
| 411 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 412 | static int gcm_enc_copy_hash(struct aead_request *req, u32 flags) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 413 | { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 414 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 415 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 416 | u8 *auth_tag = pctx->auth_tag; |
| 417 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 418 | crypto_xor(auth_tag, pctx->iauth_tag, 16); |
| 419 | scatterwalk_map_and_copy(auth_tag, req->dst, |
| 420 | req->assoclen + req->cryptlen, |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 421 | crypto_aead_authsize(aead), 1); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 422 | return 0; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 423 | } |
| 424 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 425 | static int gcm_encrypt_continue(struct aead_request *req, u32 flags) |
Herbert Xu | 6160b28 | 2007-12-04 19:17:50 +1100 | [diff] [blame] | 426 | { |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 427 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 428 | struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx; |
Herbert Xu | 6160b28 | 2007-12-04 19:17:50 +1100 | [diff] [blame] | 429 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 430 | gctx->src = sg_next(req->src == req->dst ? pctx->src : pctx->dst); |
| 431 | gctx->cryptlen = req->cryptlen; |
| 432 | gctx->complete = gcm_enc_copy_hash; |
Herbert Xu | 6160b28 | 2007-12-04 19:17:50 +1100 | [diff] [blame] | 433 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 434 | return gcm_hash(req, flags); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 435 | } |
| 436 | |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 437 | static void gcm_encrypt_done(struct crypto_async_request *areq, int err) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 438 | { |
| 439 | struct aead_request *req = areq->data; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 440 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 441 | if (err) |
| 442 | goto out; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 443 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 444 | err = gcm_encrypt_continue(req, 0); |
| 445 | if (err == -EINPROGRESS) |
| 446 | return; |
| 447 | |
| 448 | out: |
Huang Ying | 62c5593 | 2009-11-16 21:52:22 +0800 | [diff] [blame] | 449 | aead_request_complete(req, err); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 450 | } |
| 451 | |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 452 | static int crypto_gcm_encrypt(struct aead_request *req) |
| 453 | { |
Herbert Xu | 2589469 | 2007-12-12 19:16:38 +0800 | [diff] [blame] | 454 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 455 | struct skcipher_request *skreq = &pctx->u.skreq; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 456 | u32 flags = aead_request_flags(req); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 457 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 458 | crypto_gcm_init_common(req); |
| 459 | crypto_gcm_init_crypt(req, req->cryptlen); |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 460 | skcipher_request_set_callback(skreq, flags, gcm_encrypt_done, req); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 461 | |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 462 | return crypto_skcipher_encrypt(skreq) ?: |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 463 | gcm_encrypt_continue(req, flags); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 464 | } |
| 465 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 466 | static int crypto_gcm_verify(struct aead_request *req) |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 467 | { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 468 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 469 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 470 | u8 *auth_tag = pctx->auth_tag; |
| 471 | u8 *iauth_tag = pctx->iauth_tag; |
| 472 | unsigned int authsize = crypto_aead_authsize(aead); |
| 473 | unsigned int cryptlen = req->cryptlen - authsize; |
| 474 | |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 475 | crypto_xor(auth_tag, iauth_tag, 16); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 476 | scatterwalk_map_and_copy(iauth_tag, req->src, |
| 477 | req->assoclen + cryptlen, authsize, 0); |
James Yonan | 6bf37e5 | 2013-09-26 02:20:39 -0600 | [diff] [blame] | 478 | return crypto_memneq(iauth_tag, auth_tag, authsize) ? -EBADMSG : 0; |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 479 | } |
| 480 | |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 481 | static void gcm_decrypt_done(struct crypto_async_request *areq, int err) |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 482 | { |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 483 | struct aead_request *req = areq->data; |
| 484 | |
| 485 | if (!err) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 486 | err = crypto_gcm_verify(req); |
Herbert Xu | 84c9115 | 2007-12-17 21:42:08 +0800 | [diff] [blame] | 487 | |
| 488 | aead_request_complete(req, err); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 489 | } |
| 490 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 491 | static int gcm_dec_hash_continue(struct aead_request *req, u32 flags) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 492 | { |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 493 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 494 | struct skcipher_request *skreq = &pctx->u.skreq; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 495 | struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx; |
| 496 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 497 | crypto_gcm_init_crypt(req, gctx->cryptlen); |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 498 | skcipher_request_set_callback(skreq, flags, gcm_decrypt_done, req); |
| 499 | return crypto_skcipher_decrypt(skreq) ?: crypto_gcm_verify(req); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 500 | } |
| 501 | |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 502 | static int crypto_gcm_decrypt(struct aead_request *req) |
| 503 | { |
Herbert Xu | 6160b28 | 2007-12-04 19:17:50 +1100 | [diff] [blame] | 504 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
Herbert Xu | 2589469 | 2007-12-12 19:16:38 +0800 | [diff] [blame] | 505 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 506 | struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx; |
Herbert Xu | 6160b28 | 2007-12-04 19:17:50 +1100 | [diff] [blame] | 507 | unsigned int authsize = crypto_aead_authsize(aead); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 508 | unsigned int cryptlen = req->cryptlen; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 509 | u32 flags = aead_request_flags(req); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 510 | |
Herbert Xu | 6160b28 | 2007-12-04 19:17:50 +1100 | [diff] [blame] | 511 | cryptlen -= authsize; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 512 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 513 | crypto_gcm_init_common(req); |
| 514 | |
| 515 | gctx->src = sg_next(pctx->src); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 516 | gctx->cryptlen = cryptlen; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 517 | gctx->complete = gcm_dec_hash_continue; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 518 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 519 | return gcm_hash(req, flags); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 520 | } |
| 521 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 522 | static int crypto_gcm_init_tfm(struct crypto_aead *tfm) |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 523 | { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 524 | struct aead_instance *inst = aead_alg_instance(tfm); |
| 525 | struct gcm_instance_ctx *ictx = aead_instance_ctx(inst); |
| 526 | struct crypto_gcm_ctx *ctx = crypto_aead_ctx(tfm); |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 527 | struct crypto_skcipher *ctr; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 528 | struct crypto_ahash *ghash; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 529 | unsigned long align; |
| 530 | int err; |
| 531 | |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 532 | ghash = crypto_spawn_ahash(&ictx->ghash); |
| 533 | if (IS_ERR(ghash)) |
| 534 | return PTR_ERR(ghash); |
| 535 | |
Eric Biggers | 60425a8 | 2016-10-28 09:52:19 -0700 | [diff] [blame] | 536 | ctr = crypto_spawn_skcipher(&ictx->ctr); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 537 | err = PTR_ERR(ctr); |
| 538 | if (IS_ERR(ctr)) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 539 | goto err_free_hash; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 540 | |
| 541 | ctx->ctr = ctr; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 542 | ctx->ghash = ghash; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 543 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 544 | align = crypto_aead_alignmask(tfm); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 545 | align &= ~(crypto_tfm_ctx_alignment() - 1); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 546 | crypto_aead_set_reqsize(tfm, |
Herbert Xu | 5d72336 | 2015-05-11 17:47:59 +0800 | [diff] [blame] | 547 | align + offsetof(struct crypto_gcm_req_priv_ctx, u) + |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 548 | max(sizeof(struct skcipher_request) + |
| 549 | crypto_skcipher_reqsize(ctr), |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 550 | sizeof(struct ahash_request) + |
Herbert Xu | 5d72336 | 2015-05-11 17:47:59 +0800 | [diff] [blame] | 551 | crypto_ahash_reqsize(ghash))); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 552 | |
| 553 | return 0; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 554 | |
| 555 | err_free_hash: |
| 556 | crypto_free_ahash(ghash); |
| 557 | return err; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 558 | } |
| 559 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 560 | static void crypto_gcm_exit_tfm(struct crypto_aead *tfm) |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 561 | { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 562 | struct crypto_gcm_ctx *ctx = crypto_aead_ctx(tfm); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 563 | |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 564 | crypto_free_ahash(ctx->ghash); |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 565 | crypto_free_skcipher(ctx->ctr); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 566 | } |
| 567 | |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 568 | static void crypto_gcm_free(struct aead_instance *inst) |
| 569 | { |
| 570 | struct gcm_instance_ctx *ctx = aead_instance_ctx(inst); |
| 571 | |
| 572 | crypto_drop_skcipher(&ctx->ctr); |
| 573 | crypto_drop_ahash(&ctx->ghash); |
| 574 | kfree(inst); |
| 575 | } |
| 576 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 577 | static int crypto_gcm_create_common(struct crypto_template *tmpl, |
| 578 | struct rtattr **tb, |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 579 | const char *ctr_name, |
| 580 | const char *ghash_name) |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 581 | { |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 582 | struct crypto_attr_type *algt; |
Eric Biggers | b9f76dd | 2020-01-02 19:58:45 -0800 | [diff] [blame] | 583 | u32 mask; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 584 | struct aead_instance *inst; |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 585 | struct skcipher_alg *ctr; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 586 | struct crypto_alg *ghash_alg; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 587 | struct hash_alg_common *ghash; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 588 | struct gcm_instance_ctx *ctx; |
| 589 | int err; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 590 | |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 591 | algt = crypto_get_attr_type(tb); |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 592 | if (IS_ERR(algt)) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 593 | return PTR_ERR(algt); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 594 | |
Herbert Xu | 5e4b8c1 | 2015-08-13 17:29:06 +0800 | [diff] [blame] | 595 | if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 596 | return -EINVAL; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 597 | |
Eric Biggers | b9f76dd | 2020-01-02 19:58:45 -0800 | [diff] [blame] | 598 | mask = crypto_requires_sync(algt->type, algt->mask); |
| 599 | |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 600 | ghash_alg = crypto_find_alg(ghash_name, &crypto_ahash_type, |
| 601 | CRYPTO_ALG_TYPE_HASH, |
Eric Biggers | b9f76dd | 2020-01-02 19:58:45 -0800 | [diff] [blame] | 602 | CRYPTO_ALG_TYPE_AHASH_MASK | mask); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 603 | if (IS_ERR(ghash_alg)) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 604 | return PTR_ERR(ghash_alg); |
| 605 | |
| 606 | ghash = __crypto_hash_alg_common(ghash_alg); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 607 | |
| 608 | err = -ENOMEM; |
Herbert Xu | 1472e5e | 2007-12-07 19:26:11 +0800 | [diff] [blame] | 609 | inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); |
| 610 | if (!inst) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 611 | goto out_put_ghash; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 612 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 613 | ctx = aead_instance_ctx(inst); |
| 614 | err = crypto_init_ahash_spawn(&ctx->ghash, ghash, |
| 615 | aead_crypto_instance(inst)); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 616 | if (err) |
| 617 | goto err_free_inst; |
| 618 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 619 | err = -EINVAL; |
Eric Biggers | f699594 | 2019-04-18 14:43:02 -0700 | [diff] [blame] | 620 | if (strcmp(ghash->base.cra_name, "ghash") != 0 || |
| 621 | ghash->digestsize != 16) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 622 | goto err_drop_ghash; |
| 623 | |
Eric Biggers | b9f76dd | 2020-01-02 19:58:45 -0800 | [diff] [blame] | 624 | err = crypto_grab_skcipher(&ctx->ctr, aead_crypto_instance(inst), |
| 625 | ctr_name, 0, mask); |
Herbert Xu | 1472e5e | 2007-12-07 19:26:11 +0800 | [diff] [blame] | 626 | if (err) |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 627 | goto err_drop_ghash; |
Herbert Xu | 1472e5e | 2007-12-07 19:26:11 +0800 | [diff] [blame] | 628 | |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 629 | ctr = crypto_spawn_skcipher_alg(&ctx->ctr); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 630 | |
Eric Biggers | f699594 | 2019-04-18 14:43:02 -0700 | [diff] [blame] | 631 | /* The skcipher algorithm must be CTR mode, using 16-byte blocks. */ |
Wei Yongjun | 9b40f79 | 2016-10-17 15:10:06 +0000 | [diff] [blame] | 632 | err = -EINVAL; |
Eric Biggers | f699594 | 2019-04-18 14:43:02 -0700 | [diff] [blame] | 633 | if (strncmp(ctr->base.cra_name, "ctr(", 4) != 0 || |
| 634 | crypto_skcipher_alg_ivsize(ctr) != 16 || |
| 635 | ctr->base.cra_blocksize != 1) |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 636 | goto out_put_ctr; |
| 637 | |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 638 | err = -ENAMETOOLONG; |
Eric Biggers | f699594 | 2019-04-18 14:43:02 -0700 | [diff] [blame] | 639 | if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, |
| 640 | "gcm(%s", ctr->base.cra_name + 4) >= CRYPTO_MAX_ALG_NAME) |
| 641 | goto out_put_ctr; |
| 642 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 643 | if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 644 | "gcm_base(%s,%s)", ctr->base.cra_driver_name, |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 645 | ghash_alg->cra_driver_name) >= |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 646 | CRYPTO_MAX_ALG_NAME) |
Herbert Xu | 1472e5e | 2007-12-07 19:26:11 +0800 | [diff] [blame] | 647 | goto out_put_ctr; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 648 | |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 649 | inst->alg.base.cra_flags = (ghash->base.cra_flags | |
| 650 | ctr->base.cra_flags) & CRYPTO_ALG_ASYNC; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 651 | inst->alg.base.cra_priority = (ghash->base.cra_priority + |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 652 | ctr->base.cra_priority) / 2; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 653 | inst->alg.base.cra_blocksize = 1; |
| 654 | inst->alg.base.cra_alignmask = ghash->base.cra_alignmask | |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 655 | ctr->base.cra_alignmask; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 656 | inst->alg.base.cra_ctxsize = sizeof(struct crypto_gcm_ctx); |
Corentin LABBE | e0ab7e9 | 2017-08-22 10:08:17 +0200 | [diff] [blame] | 657 | inst->alg.ivsize = GCM_AES_IV_SIZE; |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 658 | inst->alg.chunksize = crypto_skcipher_alg_chunksize(ctr); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 659 | inst->alg.maxauthsize = 16; |
| 660 | inst->alg.init = crypto_gcm_init_tfm; |
| 661 | inst->alg.exit = crypto_gcm_exit_tfm; |
| 662 | inst->alg.setkey = crypto_gcm_setkey; |
| 663 | inst->alg.setauthsize = crypto_gcm_setauthsize; |
| 664 | inst->alg.encrypt = crypto_gcm_encrypt; |
| 665 | inst->alg.decrypt = crypto_gcm_decrypt; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 666 | |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 667 | inst->free = crypto_gcm_free; |
| 668 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 669 | err = aead_register_instance(tmpl, inst); |
| 670 | if (err) |
| 671 | goto out_put_ctr; |
| 672 | |
| 673 | out_put_ghash: |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 674 | crypto_mod_put(ghash_alg); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 675 | return err; |
Herbert Xu | 1472e5e | 2007-12-07 19:26:11 +0800 | [diff] [blame] | 676 | |
| 677 | out_put_ctr: |
| 678 | crypto_drop_skcipher(&ctx->ctr); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 679 | err_drop_ghash: |
| 680 | crypto_drop_ahash(&ctx->ghash); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 681 | err_free_inst: |
| 682 | kfree(inst); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 683 | goto out_put_ghash; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 684 | } |
| 685 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 686 | static int crypto_gcm_create(struct crypto_template *tmpl, struct rtattr **tb) |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 687 | { |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 688 | const char *cipher_name; |
| 689 | char ctr_name[CRYPTO_MAX_ALG_NAME]; |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 690 | |
| 691 | cipher_name = crypto_attr_alg_name(tb[1]); |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 692 | if (IS_ERR(cipher_name)) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 693 | return PTR_ERR(cipher_name); |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 694 | |
| 695 | if (snprintf(ctr_name, CRYPTO_MAX_ALG_NAME, "ctr(%s)", cipher_name) >= |
| 696 | CRYPTO_MAX_ALG_NAME) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 697 | return -ENAMETOOLONG; |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 698 | |
Eric Biggers | f699594 | 2019-04-18 14:43:02 -0700 | [diff] [blame] | 699 | return crypto_gcm_create_common(tmpl, tb, ctr_name, "ghash"); |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 700 | } |
| 701 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 702 | static int crypto_gcm_base_create(struct crypto_template *tmpl, |
| 703 | struct rtattr **tb) |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 704 | { |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 705 | const char *ctr_name; |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 706 | const char *ghash_name; |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 707 | |
| 708 | ctr_name = crypto_attr_alg_name(tb[1]); |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 709 | if (IS_ERR(ctr_name)) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 710 | return PTR_ERR(ctr_name); |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 711 | |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 712 | ghash_name = crypto_attr_alg_name(tb[2]); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 713 | if (IS_ERR(ghash_name)) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 714 | return PTR_ERR(ghash_name); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 715 | |
Eric Biggers | f699594 | 2019-04-18 14:43:02 -0700 | [diff] [blame] | 716 | return crypto_gcm_create_common(tmpl, tb, ctr_name, ghash_name); |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 717 | } |
| 718 | |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 719 | static int crypto_rfc4106_setkey(struct crypto_aead *parent, const u8 *key, |
| 720 | unsigned int keylen) |
| 721 | { |
| 722 | struct crypto_rfc4106_ctx *ctx = crypto_aead_ctx(parent); |
| 723 | struct crypto_aead *child = ctx->child; |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 724 | |
| 725 | if (keylen < 4) |
| 726 | return -EINVAL; |
| 727 | |
| 728 | keylen -= 4; |
| 729 | memcpy(ctx->nonce, key + keylen, 4); |
| 730 | |
| 731 | crypto_aead_clear_flags(child, CRYPTO_TFM_REQ_MASK); |
| 732 | crypto_aead_set_flags(child, crypto_aead_get_flags(parent) & |
| 733 | CRYPTO_TFM_REQ_MASK); |
Eric Biggers | af5034e | 2019-12-30 21:19:38 -0600 | [diff] [blame] | 734 | return crypto_aead_setkey(child, key, keylen); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | static int crypto_rfc4106_setauthsize(struct crypto_aead *parent, |
| 738 | unsigned int authsize) |
| 739 | { |
| 740 | struct crypto_rfc4106_ctx *ctx = crypto_aead_ctx(parent); |
Iuliana Prodan | 65526f6 | 2019-07-31 16:05:54 +0300 | [diff] [blame] | 741 | int err; |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 742 | |
Iuliana Prodan | 65526f6 | 2019-07-31 16:05:54 +0300 | [diff] [blame] | 743 | err = crypto_rfc4106_check_authsize(authsize); |
| 744 | if (err) |
| 745 | return err; |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 746 | |
| 747 | return crypto_aead_setauthsize(ctx->child, authsize); |
| 748 | } |
| 749 | |
| 750 | static struct aead_request *crypto_rfc4106_crypt(struct aead_request *req) |
| 751 | { |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 752 | struct crypto_rfc4106_req_ctx *rctx = aead_request_ctx(req); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 753 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 754 | struct crypto_rfc4106_ctx *ctx = crypto_aead_ctx(aead); |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 755 | struct aead_request *subreq = &rctx->subreq; |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 756 | struct crypto_aead *child = ctx->child; |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 757 | struct scatterlist *sg; |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 758 | u8 *iv = PTR_ALIGN((u8 *)(subreq + 1) + crypto_aead_reqsize(child), |
| 759 | crypto_aead_alignmask(child) + 1); |
| 760 | |
Corentin LABBE | e0ab7e9 | 2017-08-22 10:08:17 +0200 | [diff] [blame] | 761 | scatterwalk_map_and_copy(iv + GCM_AES_IV_SIZE, req->src, 0, req->assoclen - 8, 0); |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 762 | |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 763 | memcpy(iv, ctx->nonce, 4); |
| 764 | memcpy(iv + 4, req->iv, 8); |
| 765 | |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 766 | sg_init_table(rctx->src, 3); |
Corentin LABBE | e0ab7e9 | 2017-08-22 10:08:17 +0200 | [diff] [blame] | 767 | sg_set_buf(rctx->src, iv + GCM_AES_IV_SIZE, req->assoclen - 8); |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 768 | sg = scatterwalk_ffwd(rctx->src + 1, req->src, req->assoclen); |
| 769 | if (sg != rctx->src + 1) |
| 770 | sg_chain(rctx->src, 2, sg); |
| 771 | |
| 772 | if (req->src != req->dst) { |
| 773 | sg_init_table(rctx->dst, 3); |
Corentin LABBE | e0ab7e9 | 2017-08-22 10:08:17 +0200 | [diff] [blame] | 774 | sg_set_buf(rctx->dst, iv + GCM_AES_IV_SIZE, req->assoclen - 8); |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 775 | sg = scatterwalk_ffwd(rctx->dst + 1, req->dst, req->assoclen); |
| 776 | if (sg != rctx->dst + 1) |
| 777 | sg_chain(rctx->dst, 2, sg); |
| 778 | } |
| 779 | |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 780 | aead_request_set_tfm(subreq, child); |
| 781 | aead_request_set_callback(subreq, req->base.flags, req->base.complete, |
| 782 | req->base.data); |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 783 | aead_request_set_crypt(subreq, rctx->src, |
| 784 | req->src == req->dst ? rctx->src : rctx->dst, |
| 785 | req->cryptlen, iv); |
| 786 | aead_request_set_ad(subreq, req->assoclen - 8); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 787 | |
| 788 | return subreq; |
| 789 | } |
| 790 | |
| 791 | static int crypto_rfc4106_encrypt(struct aead_request *req) |
| 792 | { |
Iuliana Prodan | 65526f6 | 2019-07-31 16:05:54 +0300 | [diff] [blame] | 793 | int err; |
| 794 | |
| 795 | err = crypto_ipsec_check_assoclen(req->assoclen); |
| 796 | if (err) |
| 797 | return err; |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 798 | |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 799 | req = crypto_rfc4106_crypt(req); |
| 800 | |
| 801 | return crypto_aead_encrypt(req); |
| 802 | } |
| 803 | |
| 804 | static int crypto_rfc4106_decrypt(struct aead_request *req) |
| 805 | { |
Iuliana Prodan | 65526f6 | 2019-07-31 16:05:54 +0300 | [diff] [blame] | 806 | int err; |
| 807 | |
| 808 | err = crypto_ipsec_check_assoclen(req->assoclen); |
| 809 | if (err) |
| 810 | return err; |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 811 | |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 812 | req = crypto_rfc4106_crypt(req); |
| 813 | |
| 814 | return crypto_aead_decrypt(req); |
| 815 | } |
| 816 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 817 | static int crypto_rfc4106_init_tfm(struct crypto_aead *tfm) |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 818 | { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 819 | struct aead_instance *inst = aead_alg_instance(tfm); |
| 820 | struct crypto_aead_spawn *spawn = aead_instance_ctx(inst); |
| 821 | struct crypto_rfc4106_ctx *ctx = crypto_aead_ctx(tfm); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 822 | struct crypto_aead *aead; |
| 823 | unsigned long align; |
| 824 | |
| 825 | aead = crypto_spawn_aead(spawn); |
| 826 | if (IS_ERR(aead)) |
| 827 | return PTR_ERR(aead); |
| 828 | |
| 829 | ctx->child = aead; |
| 830 | |
| 831 | align = crypto_aead_alignmask(aead); |
| 832 | align &= ~(crypto_tfm_ctx_alignment() - 1); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 833 | crypto_aead_set_reqsize( |
| 834 | tfm, |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 835 | sizeof(struct crypto_rfc4106_req_ctx) + |
Herbert Xu | 5d72336 | 2015-05-11 17:47:59 +0800 | [diff] [blame] | 836 | ALIGN(crypto_aead_reqsize(aead), crypto_tfm_ctx_alignment()) + |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 837 | align + 24); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 838 | |
| 839 | return 0; |
| 840 | } |
| 841 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 842 | static void crypto_rfc4106_exit_tfm(struct crypto_aead *tfm) |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 843 | { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 844 | struct crypto_rfc4106_ctx *ctx = crypto_aead_ctx(tfm); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 845 | |
| 846 | crypto_free_aead(ctx->child); |
| 847 | } |
| 848 | |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 849 | static void crypto_rfc4106_free(struct aead_instance *inst) |
| 850 | { |
| 851 | crypto_drop_aead(aead_instance_ctx(inst)); |
| 852 | kfree(inst); |
| 853 | } |
| 854 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 855 | static int crypto_rfc4106_create(struct crypto_template *tmpl, |
| 856 | struct rtattr **tb) |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 857 | { |
| 858 | struct crypto_attr_type *algt; |
Eric Biggers | cd900f0 | 2020-01-02 19:58:46 -0800 | [diff] [blame^] | 859 | u32 mask; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 860 | struct aead_instance *inst; |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 861 | struct crypto_aead_spawn *spawn; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 862 | struct aead_alg *alg; |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 863 | const char *ccm_name; |
| 864 | int err; |
| 865 | |
| 866 | algt = crypto_get_attr_type(tb); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 867 | if (IS_ERR(algt)) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 868 | return PTR_ERR(algt); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 869 | |
Herbert Xu | 5e4b8c1 | 2015-08-13 17:29:06 +0800 | [diff] [blame] | 870 | if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 871 | return -EINVAL; |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 872 | |
Eric Biggers | cd900f0 | 2020-01-02 19:58:46 -0800 | [diff] [blame^] | 873 | mask = crypto_requires_sync(algt->type, algt->mask); |
| 874 | |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 875 | ccm_name = crypto_attr_alg_name(tb[1]); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 876 | if (IS_ERR(ccm_name)) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 877 | return PTR_ERR(ccm_name); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 878 | |
| 879 | inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); |
| 880 | if (!inst) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 881 | return -ENOMEM; |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 882 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 883 | spawn = aead_instance_ctx(inst); |
Eric Biggers | cd900f0 | 2020-01-02 19:58:46 -0800 | [diff] [blame^] | 884 | err = crypto_grab_aead(spawn, aead_crypto_instance(inst), |
| 885 | ccm_name, 0, mask); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 886 | if (err) |
| 887 | goto out_free_inst; |
| 888 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 889 | alg = crypto_spawn_aead_alg(spawn); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 890 | |
| 891 | err = -EINVAL; |
| 892 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 893 | /* Underlying IV size must be 12. */ |
Corentin LABBE | e0ab7e9 | 2017-08-22 10:08:17 +0200 | [diff] [blame] | 894 | if (crypto_aead_alg_ivsize(alg) != GCM_AES_IV_SIZE) |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 895 | goto out_drop_alg; |
| 896 | |
| 897 | /* Not a stream cipher? */ |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 898 | if (alg->base.cra_blocksize != 1) |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 899 | goto out_drop_alg; |
| 900 | |
| 901 | err = -ENAMETOOLONG; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 902 | if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, |
| 903 | "rfc4106(%s)", alg->base.cra_name) >= |
| 904 | CRYPTO_MAX_ALG_NAME || |
| 905 | snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, |
| 906 | "rfc4106(%s)", alg->base.cra_driver_name) >= |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 907 | CRYPTO_MAX_ALG_NAME) |
| 908 | goto out_drop_alg; |
| 909 | |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 910 | inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 911 | inst->alg.base.cra_priority = alg->base.cra_priority; |
| 912 | inst->alg.base.cra_blocksize = 1; |
| 913 | inst->alg.base.cra_alignmask = alg->base.cra_alignmask; |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 914 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 915 | inst->alg.base.cra_ctxsize = sizeof(struct crypto_rfc4106_ctx); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 916 | |
Corentin LABBE | e0ab7e9 | 2017-08-22 10:08:17 +0200 | [diff] [blame] | 917 | inst->alg.ivsize = GCM_RFC4106_IV_SIZE; |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 918 | inst->alg.chunksize = crypto_aead_alg_chunksize(alg); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 919 | inst->alg.maxauthsize = crypto_aead_alg_maxauthsize(alg); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 920 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 921 | inst->alg.init = crypto_rfc4106_init_tfm; |
| 922 | inst->alg.exit = crypto_rfc4106_exit_tfm; |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 923 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 924 | inst->alg.setkey = crypto_rfc4106_setkey; |
| 925 | inst->alg.setauthsize = crypto_rfc4106_setauthsize; |
| 926 | inst->alg.encrypt = crypto_rfc4106_encrypt; |
| 927 | inst->alg.decrypt = crypto_rfc4106_decrypt; |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 928 | |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 929 | inst->free = crypto_rfc4106_free; |
| 930 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 931 | err = aead_register_instance(tmpl, inst); |
| 932 | if (err) |
| 933 | goto out_drop_alg; |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 934 | |
| 935 | out: |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 936 | return err; |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 937 | |
| 938 | out_drop_alg: |
| 939 | crypto_drop_aead(spawn); |
| 940 | out_free_inst: |
| 941 | kfree(inst); |
Herbert Xu | dadbc53 | 2007-12-17 15:33:17 +0800 | [diff] [blame] | 942 | goto out; |
| 943 | } |
| 944 | |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 945 | static int crypto_rfc4543_setkey(struct crypto_aead *parent, const u8 *key, |
| 946 | unsigned int keylen) |
| 947 | { |
| 948 | struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(parent); |
| 949 | struct crypto_aead *child = ctx->child; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 950 | |
| 951 | if (keylen < 4) |
| 952 | return -EINVAL; |
| 953 | |
| 954 | keylen -= 4; |
| 955 | memcpy(ctx->nonce, key + keylen, 4); |
| 956 | |
| 957 | crypto_aead_clear_flags(child, CRYPTO_TFM_REQ_MASK); |
| 958 | crypto_aead_set_flags(child, crypto_aead_get_flags(parent) & |
| 959 | CRYPTO_TFM_REQ_MASK); |
Eric Biggers | af5034e | 2019-12-30 21:19:38 -0600 | [diff] [blame] | 960 | return crypto_aead_setkey(child, key, keylen); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | static int crypto_rfc4543_setauthsize(struct crypto_aead *parent, |
| 964 | unsigned int authsize) |
| 965 | { |
| 966 | struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(parent); |
| 967 | |
| 968 | if (authsize != 16) |
| 969 | return -EINVAL; |
| 970 | |
| 971 | return crypto_aead_setauthsize(ctx->child, authsize); |
| 972 | } |
| 973 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 974 | static int crypto_rfc4543_crypt(struct aead_request *req, bool enc) |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 975 | { |
| 976 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 977 | struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(aead); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 978 | struct crypto_rfc4543_req_ctx *rctx = aead_request_ctx(req); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 979 | struct aead_request *subreq = &rctx->subreq; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 980 | unsigned int authsize = crypto_aead_authsize(aead); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 981 | u8 *iv = PTR_ALIGN((u8 *)(rctx + 1) + crypto_aead_reqsize(ctx->child), |
| 982 | crypto_aead_alignmask(ctx->child) + 1); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 983 | int err; |
| 984 | |
| 985 | if (req->src != req->dst) { |
| 986 | err = crypto_rfc4543_copy_src_to_dst(req, enc); |
| 987 | if (err) |
| 988 | return err; |
| 989 | } |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 990 | |
| 991 | memcpy(iv, ctx->nonce, 4); |
| 992 | memcpy(iv + 4, req->iv, 8); |
| 993 | |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 994 | aead_request_set_tfm(subreq, ctx->child); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 995 | aead_request_set_callback(subreq, req->base.flags, |
| 996 | req->base.complete, req->base.data); |
| 997 | aead_request_set_crypt(subreq, req->src, req->dst, |
| 998 | enc ? 0 : authsize, iv); |
| 999 | aead_request_set_ad(subreq, req->assoclen + req->cryptlen - |
| 1000 | subreq->cryptlen); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1001 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1002 | return enc ? crypto_aead_encrypt(subreq) : crypto_aead_decrypt(subreq); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1003 | } |
| 1004 | |
Jussi Kivilinna | 9489667d | 2013-04-07 16:43:41 +0300 | [diff] [blame] | 1005 | static int crypto_rfc4543_copy_src_to_dst(struct aead_request *req, bool enc) |
| 1006 | { |
| 1007 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 1008 | struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(aead); |
| 1009 | unsigned int authsize = crypto_aead_authsize(aead); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1010 | unsigned int nbytes = req->assoclen + req->cryptlen - |
| 1011 | (enc ? 0 : authsize); |
Kees Cook | 8d60539 | 2018-09-18 19:10:51 -0700 | [diff] [blame] | 1012 | SYNC_SKCIPHER_REQUEST_ON_STACK(nreq, ctx->null); |
Jussi Kivilinna | 9489667d | 2013-04-07 16:43:41 +0300 | [diff] [blame] | 1013 | |
Kees Cook | 8d60539 | 2018-09-18 19:10:51 -0700 | [diff] [blame] | 1014 | skcipher_request_set_sync_tfm(nreq, ctx->null); |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 1015 | skcipher_request_set_callback(nreq, req->base.flags, NULL, NULL); |
| 1016 | skcipher_request_set_crypt(nreq, req->src, req->dst, nbytes, NULL); |
| 1017 | |
| 1018 | return crypto_skcipher_encrypt(nreq); |
Jussi Kivilinna | 9489667d | 2013-04-07 16:43:41 +0300 | [diff] [blame] | 1019 | } |
| 1020 | |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1021 | static int crypto_rfc4543_encrypt(struct aead_request *req) |
| 1022 | { |
Iuliana Prodan | 74bf81d | 2019-08-02 11:47:33 +0300 | [diff] [blame] | 1023 | return crypto_ipsec_check_assoclen(req->assoclen) ?: |
| 1024 | crypto_rfc4543_crypt(req, true); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | static int crypto_rfc4543_decrypt(struct aead_request *req) |
| 1028 | { |
Iuliana Prodan | 74bf81d | 2019-08-02 11:47:33 +0300 | [diff] [blame] | 1029 | return crypto_ipsec_check_assoclen(req->assoclen) ?: |
| 1030 | crypto_rfc4543_crypt(req, false); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1031 | } |
| 1032 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1033 | static int crypto_rfc4543_init_tfm(struct crypto_aead *tfm) |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1034 | { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1035 | struct aead_instance *inst = aead_alg_instance(tfm); |
| 1036 | struct crypto_rfc4543_instance_ctx *ictx = aead_instance_ctx(inst); |
Jussi Kivilinna | 9489667d | 2013-04-07 16:43:41 +0300 | [diff] [blame] | 1037 | struct crypto_aead_spawn *spawn = &ictx->aead; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1038 | struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(tfm); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1039 | struct crypto_aead *aead; |
Kees Cook | 8d60539 | 2018-09-18 19:10:51 -0700 | [diff] [blame] | 1040 | struct crypto_sync_skcipher *null; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1041 | unsigned long align; |
Jussi Kivilinna | 9489667d | 2013-04-07 16:43:41 +0300 | [diff] [blame] | 1042 | int err = 0; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1043 | |
| 1044 | aead = crypto_spawn_aead(spawn); |
| 1045 | if (IS_ERR(aead)) |
| 1046 | return PTR_ERR(aead); |
| 1047 | |
Eric Biggers | 3a2d4fb | 2017-12-07 10:56:34 -0800 | [diff] [blame] | 1048 | null = crypto_get_default_null_skcipher(); |
Jussi Kivilinna | 9489667d | 2013-04-07 16:43:41 +0300 | [diff] [blame] | 1049 | err = PTR_ERR(null); |
| 1050 | if (IS_ERR(null)) |
| 1051 | goto err_free_aead; |
| 1052 | |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1053 | ctx->child = aead; |
Jussi Kivilinna | 9489667d | 2013-04-07 16:43:41 +0300 | [diff] [blame] | 1054 | ctx->null = null; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1055 | |
| 1056 | align = crypto_aead_alignmask(aead); |
| 1057 | align &= ~(crypto_tfm_ctx_alignment() - 1); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1058 | crypto_aead_set_reqsize( |
| 1059 | tfm, |
Herbert Xu | 5d72336 | 2015-05-11 17:47:59 +0800 | [diff] [blame] | 1060 | sizeof(struct crypto_rfc4543_req_ctx) + |
| 1061 | ALIGN(crypto_aead_reqsize(aead), crypto_tfm_ctx_alignment()) + |
Corentin LABBE | e0ab7e9 | 2017-08-22 10:08:17 +0200 | [diff] [blame] | 1062 | align + GCM_AES_IV_SIZE); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1063 | |
| 1064 | return 0; |
Jussi Kivilinna | 9489667d | 2013-04-07 16:43:41 +0300 | [diff] [blame] | 1065 | |
| 1066 | err_free_aead: |
| 1067 | crypto_free_aead(aead); |
| 1068 | return err; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1069 | } |
| 1070 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1071 | static void crypto_rfc4543_exit_tfm(struct crypto_aead *tfm) |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1072 | { |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1073 | struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(tfm); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1074 | |
| 1075 | crypto_free_aead(ctx->child); |
Eric Biggers | 3a2d4fb | 2017-12-07 10:56:34 -0800 | [diff] [blame] | 1076 | crypto_put_default_null_skcipher(); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1077 | } |
| 1078 | |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 1079 | static void crypto_rfc4543_free(struct aead_instance *inst) |
| 1080 | { |
| 1081 | struct crypto_rfc4543_instance_ctx *ctx = aead_instance_ctx(inst); |
| 1082 | |
| 1083 | crypto_drop_aead(&ctx->aead); |
| 1084 | |
| 1085 | kfree(inst); |
| 1086 | } |
| 1087 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1088 | static int crypto_rfc4543_create(struct crypto_template *tmpl, |
| 1089 | struct rtattr **tb) |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1090 | { |
| 1091 | struct crypto_attr_type *algt; |
Eric Biggers | cd900f0 | 2020-01-02 19:58:46 -0800 | [diff] [blame^] | 1092 | u32 mask; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1093 | struct aead_instance *inst; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1094 | struct crypto_aead_spawn *spawn; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1095 | struct aead_alg *alg; |
Jussi Kivilinna | 9489667d | 2013-04-07 16:43:41 +0300 | [diff] [blame] | 1096 | struct crypto_rfc4543_instance_ctx *ctx; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1097 | const char *ccm_name; |
| 1098 | int err; |
| 1099 | |
| 1100 | algt = crypto_get_attr_type(tb); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1101 | if (IS_ERR(algt)) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1102 | return PTR_ERR(algt); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1103 | |
Herbert Xu | 5e4b8c1 | 2015-08-13 17:29:06 +0800 | [diff] [blame] | 1104 | if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1105 | return -EINVAL; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1106 | |
Eric Biggers | cd900f0 | 2020-01-02 19:58:46 -0800 | [diff] [blame^] | 1107 | mask = crypto_requires_sync(algt->type, algt->mask); |
| 1108 | |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1109 | ccm_name = crypto_attr_alg_name(tb[1]); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1110 | if (IS_ERR(ccm_name)) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1111 | return PTR_ERR(ccm_name); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1112 | |
Jussi Kivilinna | 9489667d | 2013-04-07 16:43:41 +0300 | [diff] [blame] | 1113 | inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1114 | if (!inst) |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1115 | return -ENOMEM; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1116 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1117 | ctx = aead_instance_ctx(inst); |
Jussi Kivilinna | 9489667d | 2013-04-07 16:43:41 +0300 | [diff] [blame] | 1118 | spawn = &ctx->aead; |
Eric Biggers | cd900f0 | 2020-01-02 19:58:46 -0800 | [diff] [blame^] | 1119 | err = crypto_grab_aead(spawn, aead_crypto_instance(inst), |
| 1120 | ccm_name, 0, mask); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1121 | if (err) |
| 1122 | goto out_free_inst; |
| 1123 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1124 | alg = crypto_spawn_aead_alg(spawn); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1125 | |
| 1126 | err = -EINVAL; |
| 1127 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1128 | /* Underlying IV size must be 12. */ |
Corentin LABBE | e0ab7e9 | 2017-08-22 10:08:17 +0200 | [diff] [blame] | 1129 | if (crypto_aead_alg_ivsize(alg) != GCM_AES_IV_SIZE) |
Herbert Xu | 17db854 | 2015-05-21 15:11:11 +0800 | [diff] [blame] | 1130 | goto out_drop_alg; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1131 | |
| 1132 | /* Not a stream cipher? */ |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1133 | if (alg->base.cra_blocksize != 1) |
Herbert Xu | 17db854 | 2015-05-21 15:11:11 +0800 | [diff] [blame] | 1134 | goto out_drop_alg; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1135 | |
| 1136 | err = -ENAMETOOLONG; |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1137 | if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, |
| 1138 | "rfc4543(%s)", alg->base.cra_name) >= |
| 1139 | CRYPTO_MAX_ALG_NAME || |
| 1140 | snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, |
| 1141 | "rfc4543(%s)", alg->base.cra_driver_name) >= |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1142 | CRYPTO_MAX_ALG_NAME) |
Herbert Xu | 17db854 | 2015-05-21 15:11:11 +0800 | [diff] [blame] | 1143 | goto out_drop_alg; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1144 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1145 | inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC; |
| 1146 | inst->alg.base.cra_priority = alg->base.cra_priority; |
| 1147 | inst->alg.base.cra_blocksize = 1; |
| 1148 | inst->alg.base.cra_alignmask = alg->base.cra_alignmask; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1149 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1150 | inst->alg.base.cra_ctxsize = sizeof(struct crypto_rfc4543_ctx); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1151 | |
Corentin LABBE | e0ab7e9 | 2017-08-22 10:08:17 +0200 | [diff] [blame] | 1152 | inst->alg.ivsize = GCM_RFC4543_IV_SIZE; |
Herbert Xu | 16f37ecd | 2016-07-12 13:17:39 +0800 | [diff] [blame] | 1153 | inst->alg.chunksize = crypto_aead_alg_chunksize(alg); |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1154 | inst->alg.maxauthsize = crypto_aead_alg_maxauthsize(alg); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1155 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1156 | inst->alg.init = crypto_rfc4543_init_tfm; |
| 1157 | inst->alg.exit = crypto_rfc4543_exit_tfm; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1158 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1159 | inst->alg.setkey = crypto_rfc4543_setkey; |
| 1160 | inst->alg.setauthsize = crypto_rfc4543_setauthsize; |
| 1161 | inst->alg.encrypt = crypto_rfc4543_encrypt; |
| 1162 | inst->alg.decrypt = crypto_rfc4543_decrypt; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1163 | |
Herbert Xu | 7b05a37 | 2015-07-09 07:17:30 +0800 | [diff] [blame] | 1164 | inst->free = crypto_rfc4543_free, |
| 1165 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1166 | err = aead_register_instance(tmpl, inst); |
| 1167 | if (err) |
| 1168 | goto out_drop_alg; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1169 | |
| 1170 | out: |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1171 | return err; |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1172 | |
| 1173 | out_drop_alg: |
| 1174 | crypto_drop_aead(spawn); |
| 1175 | out_free_inst: |
| 1176 | kfree(inst); |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1177 | goto out; |
| 1178 | } |
| 1179 | |
Xiongfeng Wang | 56a00d9 | 2019-01-18 13:58:13 +0800 | [diff] [blame] | 1180 | static struct crypto_template crypto_gcm_tmpls[] = { |
| 1181 | { |
| 1182 | .name = "gcm_base", |
| 1183 | .create = crypto_gcm_base_create, |
| 1184 | .module = THIS_MODULE, |
| 1185 | }, { |
| 1186 | .name = "gcm", |
| 1187 | .create = crypto_gcm_create, |
| 1188 | .module = THIS_MODULE, |
| 1189 | }, { |
| 1190 | .name = "rfc4106", |
| 1191 | .create = crypto_rfc4106_create, |
| 1192 | .module = THIS_MODULE, |
| 1193 | }, { |
| 1194 | .name = "rfc4543", |
| 1195 | .create = crypto_rfc4543_create, |
| 1196 | .module = THIS_MODULE, |
| 1197 | }, |
Tobias Brunner | 73c89c1 | 2010-01-17 21:52:11 +1100 | [diff] [blame] | 1198 | }; |
| 1199 | |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 1200 | static int __init crypto_gcm_module_init(void) |
| 1201 | { |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 1202 | int err; |
| 1203 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1204 | gcm_zeroes = kzalloc(sizeof(*gcm_zeroes), GFP_KERNEL); |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 1205 | if (!gcm_zeroes) |
| 1206 | return -ENOMEM; |
| 1207 | |
Herbert Xu | adcbc68 | 2015-06-16 13:54:18 +0800 | [diff] [blame] | 1208 | sg_init_one(&gcm_zeroes->sg, gcm_zeroes->buf, sizeof(gcm_zeroes->buf)); |
| 1209 | |
Xiongfeng Wang | 56a00d9 | 2019-01-18 13:58:13 +0800 | [diff] [blame] | 1210 | err = crypto_register_templates(crypto_gcm_tmpls, |
| 1211 | ARRAY_SIZE(crypto_gcm_tmpls)); |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 1212 | if (err) |
Xiongfeng Wang | 56a00d9 | 2019-01-18 13:58:13 +0800 | [diff] [blame] | 1213 | kfree(gcm_zeroes); |
Herbert Xu | d00aa19 | 2007-12-07 20:31:10 +0800 | [diff] [blame] | 1214 | |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 1215 | return err; |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | static void __exit crypto_gcm_module_exit(void) |
| 1219 | { |
Huang Ying | 9382d97 | 2009-08-06 15:34:26 +1000 | [diff] [blame] | 1220 | kfree(gcm_zeroes); |
Xiongfeng Wang | 56a00d9 | 2019-01-18 13:58:13 +0800 | [diff] [blame] | 1221 | crypto_unregister_templates(crypto_gcm_tmpls, |
| 1222 | ARRAY_SIZE(crypto_gcm_tmpls)); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 1223 | } |
| 1224 | |
Eric Biggers | c4741b2 | 2019-04-11 21:57:42 -0700 | [diff] [blame] | 1225 | subsys_initcall(crypto_gcm_module_init); |
Mikko Herranen | 28db8e3 | 2007-11-26 22:24:11 +0800 | [diff] [blame] | 1226 | module_exit(crypto_gcm_module_exit); |
| 1227 | |
| 1228 | MODULE_LICENSE("GPL"); |
| 1229 | MODULE_DESCRIPTION("Galois/Counter Mode"); |
| 1230 | MODULE_AUTHOR("Mikko Herranen <mh1@iki.fi>"); |
Kees Cook | 5d26a10 | 2014-11-20 17:05:53 -0800 | [diff] [blame] | 1231 | MODULE_ALIAS_CRYPTO("gcm_base"); |
| 1232 | MODULE_ALIAS_CRYPTO("rfc4106"); |
| 1233 | MODULE_ALIAS_CRYPTO("rfc4543"); |
Kees Cook | 4943ba1 | 2014-11-24 16:32:38 -0800 | [diff] [blame] | 1234 | MODULE_ALIAS_CRYPTO("gcm"); |