diff options
author | Salvatore Mesoraca <s.mesoraca16@gmail.com> | 2018-04-09 09:54:47 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2018-04-20 12:58:34 -0400 |
commit | 6650c4de681ee90ea6da1fc34fb913f60e9bb008 (patch) | |
tree | 6b0aad6025f677271fa95e979ddb04d5083463e1 | |
parent | 13c935bb09948aef0202574ee12bb089459eb43b (diff) |
crypto: remove several VLAs
We avoid various VLAs[1] by using constant expressions for block size
and alignment mask.
[1] http://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com
Signed-off-by: Salvatore Mesoraca <s.mesoraca16@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/cfb.c | 7 | ||||
-rw-r--r-- | crypto/cipher.c | 3 | ||||
-rw-r--r-- | crypto/ctr.c | 4 | ||||
-rw-r--r-- | crypto/cts.c | 5 | ||||
-rw-r--r-- | crypto/pcbc.c | 5 |
5 files changed, 13 insertions, 11 deletions
diff --git a/crypto/cfb.c b/crypto/cfb.c index 94ee39bed758..a0d68c09e1b9 100644 --- a/crypto/cfb.c +++ b/crypto/cfb.c | |||
@@ -53,9 +53,8 @@ static void crypto_cfb_encrypt_one(struct crypto_skcipher *tfm, | |||
53 | static void crypto_cfb_final(struct skcipher_walk *walk, | 53 | static void crypto_cfb_final(struct skcipher_walk *walk, |
54 | struct crypto_skcipher *tfm) | 54 | struct crypto_skcipher *tfm) |
55 | { | 55 | { |
56 | const unsigned int bsize = crypto_cfb_bsize(tfm); | ||
57 | const unsigned long alignmask = crypto_skcipher_alignmask(tfm); | 56 | const unsigned long alignmask = crypto_skcipher_alignmask(tfm); |
58 | u8 tmp[bsize + alignmask]; | 57 | u8 tmp[MAX_CIPHER_BLOCKSIZE + MAX_CIPHER_ALIGNMASK]; |
59 | u8 *stream = PTR_ALIGN(tmp + 0, alignmask + 1); | 58 | u8 *stream = PTR_ALIGN(tmp + 0, alignmask + 1); |
60 | u8 *src = walk->src.virt.addr; | 59 | u8 *src = walk->src.virt.addr; |
61 | u8 *dst = walk->dst.virt.addr; | 60 | u8 *dst = walk->dst.virt.addr; |
@@ -94,7 +93,7 @@ static int crypto_cfb_encrypt_inplace(struct skcipher_walk *walk, | |||
94 | unsigned int nbytes = walk->nbytes; | 93 | unsigned int nbytes = walk->nbytes; |
95 | u8 *src = walk->src.virt.addr; | 94 | u8 *src = walk->src.virt.addr; |
96 | u8 *iv = walk->iv; | 95 | u8 *iv = walk->iv; |
97 | u8 tmp[bsize]; | 96 | u8 tmp[MAX_CIPHER_BLOCKSIZE]; |
98 | 97 | ||
99 | do { | 98 | do { |
100 | crypto_cfb_encrypt_one(tfm, iv, tmp); | 99 | crypto_cfb_encrypt_one(tfm, iv, tmp); |
@@ -164,7 +163,7 @@ static int crypto_cfb_decrypt_inplace(struct skcipher_walk *walk, | |||
164 | unsigned int nbytes = walk->nbytes; | 163 | unsigned int nbytes = walk->nbytes; |
165 | u8 *src = walk->src.virt.addr; | 164 | u8 *src = walk->src.virt.addr; |
166 | u8 *iv = walk->iv; | 165 | u8 *iv = walk->iv; |
167 | u8 tmp[bsize]; | 166 | u8 tmp[MAX_CIPHER_BLOCKSIZE]; |
168 | 167 | ||
169 | do { | 168 | do { |
170 | crypto_cfb_encrypt_one(tfm, iv, tmp); | 169 | crypto_cfb_encrypt_one(tfm, iv, tmp); |
diff --git a/crypto/cipher.c b/crypto/cipher.c index 94fa3551476b..57836c30a49a 100644 --- a/crypto/cipher.c +++ b/crypto/cipher.c | |||
@@ -13,6 +13,7 @@ | |||
13 | * | 13 | * |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <crypto/algapi.h> | ||
16 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
17 | #include <linux/crypto.h> | 18 | #include <linux/crypto.h> |
18 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
@@ -67,7 +68,7 @@ static void cipher_crypt_unaligned(void (*fn)(struct crypto_tfm *, u8 *, | |||
67 | { | 68 | { |
68 | unsigned long alignmask = crypto_tfm_alg_alignmask(tfm); | 69 | unsigned long alignmask = crypto_tfm_alg_alignmask(tfm); |
69 | unsigned int size = crypto_tfm_alg_blocksize(tfm); | 70 | unsigned int size = crypto_tfm_alg_blocksize(tfm); |
70 | u8 buffer[size + alignmask]; | 71 | u8 buffer[MAX_CIPHER_BLOCKSIZE + MAX_CIPHER_ALIGNMASK]; |
71 | u8 *tmp = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1); | 72 | u8 *tmp = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1); |
72 | 73 | ||
73 | memcpy(tmp, src, size); | 74 | memcpy(tmp, src, size); |
diff --git a/crypto/ctr.c b/crypto/ctr.c index 854d924f9d8e..435b75bd619e 100644 --- a/crypto/ctr.c +++ b/crypto/ctr.c | |||
@@ -58,7 +58,7 @@ static void crypto_ctr_crypt_final(struct blkcipher_walk *walk, | |||
58 | unsigned int bsize = crypto_cipher_blocksize(tfm); | 58 | unsigned int bsize = crypto_cipher_blocksize(tfm); |
59 | unsigned long alignmask = crypto_cipher_alignmask(tfm); | 59 | unsigned long alignmask = crypto_cipher_alignmask(tfm); |
60 | u8 *ctrblk = walk->iv; | 60 | u8 *ctrblk = walk->iv; |
61 | u8 tmp[bsize + alignmask]; | 61 | u8 tmp[MAX_CIPHER_BLOCKSIZE + MAX_CIPHER_ALIGNMASK]; |
62 | u8 *keystream = PTR_ALIGN(tmp + 0, alignmask + 1); | 62 | u8 *keystream = PTR_ALIGN(tmp + 0, alignmask + 1); |
63 | u8 *src = walk->src.virt.addr; | 63 | u8 *src = walk->src.virt.addr; |
64 | u8 *dst = walk->dst.virt.addr; | 64 | u8 *dst = walk->dst.virt.addr; |
@@ -106,7 +106,7 @@ static int crypto_ctr_crypt_inplace(struct blkcipher_walk *walk, | |||
106 | unsigned int nbytes = walk->nbytes; | 106 | unsigned int nbytes = walk->nbytes; |
107 | u8 *ctrblk = walk->iv; | 107 | u8 *ctrblk = walk->iv; |
108 | u8 *src = walk->src.virt.addr; | 108 | u8 *src = walk->src.virt.addr; |
109 | u8 tmp[bsize + alignmask]; | 109 | u8 tmp[MAX_CIPHER_BLOCKSIZE + MAX_CIPHER_ALIGNMASK]; |
110 | u8 *keystream = PTR_ALIGN(tmp + 0, alignmask + 1); | 110 | u8 *keystream = PTR_ALIGN(tmp + 0, alignmask + 1); |
111 | 111 | ||
112 | do { | 112 | do { |
diff --git a/crypto/cts.c b/crypto/cts.c index 4773c188e6d9..4e28d83ae37d 100644 --- a/crypto/cts.c +++ b/crypto/cts.c | |||
@@ -40,6 +40,7 @@ | |||
40 | * rfc3962 includes errata information in its Appendix A. | 40 | * rfc3962 includes errata information in its Appendix A. |
41 | */ | 41 | */ |
42 | 42 | ||
43 | #include <crypto/algapi.h> | ||
43 | #include <crypto/internal/skcipher.h> | 44 | #include <crypto/internal/skcipher.h> |
44 | #include <linux/err.h> | 45 | #include <linux/err.h> |
45 | #include <linux/init.h> | 46 | #include <linux/init.h> |
@@ -104,7 +105,7 @@ static int cts_cbc_encrypt(struct skcipher_request *req) | |||
104 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | 105 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
105 | struct skcipher_request *subreq = &rctx->subreq; | 106 | struct skcipher_request *subreq = &rctx->subreq; |
106 | int bsize = crypto_skcipher_blocksize(tfm); | 107 | int bsize = crypto_skcipher_blocksize(tfm); |
107 | u8 d[bsize * 2] __aligned(__alignof__(u32)); | 108 | u8 d[MAX_CIPHER_BLOCKSIZE * 2] __aligned(__alignof__(u32)); |
108 | struct scatterlist *sg; | 109 | struct scatterlist *sg; |
109 | unsigned int offset; | 110 | unsigned int offset; |
110 | int lastn; | 111 | int lastn; |
@@ -183,7 +184,7 @@ static int cts_cbc_decrypt(struct skcipher_request *req) | |||
183 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); | 184 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
184 | struct skcipher_request *subreq = &rctx->subreq; | 185 | struct skcipher_request *subreq = &rctx->subreq; |
185 | int bsize = crypto_skcipher_blocksize(tfm); | 186 | int bsize = crypto_skcipher_blocksize(tfm); |
186 | u8 d[bsize * 2] __aligned(__alignof__(u32)); | 187 | u8 d[MAX_CIPHER_BLOCKSIZE * 2] __aligned(__alignof__(u32)); |
187 | struct scatterlist *sg; | 188 | struct scatterlist *sg; |
188 | unsigned int offset; | 189 | unsigned int offset; |
189 | u8 *space; | 190 | u8 *space; |
diff --git a/crypto/pcbc.c b/crypto/pcbc.c index d9e45a958720..ef802f6e9642 100644 --- a/crypto/pcbc.c +++ b/crypto/pcbc.c | |||
@@ -14,6 +14,7 @@ | |||
14 | * | 14 | * |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <crypto/algapi.h> | ||
17 | #include <crypto/internal/skcipher.h> | 18 | #include <crypto/internal/skcipher.h> |
18 | #include <linux/err.h> | 19 | #include <linux/err.h> |
19 | #include <linux/init.h> | 20 | #include <linux/init.h> |
@@ -72,7 +73,7 @@ static int crypto_pcbc_encrypt_inplace(struct skcipher_request *req, | |||
72 | unsigned int nbytes = walk->nbytes; | 73 | unsigned int nbytes = walk->nbytes; |
73 | u8 *src = walk->src.virt.addr; | 74 | u8 *src = walk->src.virt.addr; |
74 | u8 *iv = walk->iv; | 75 | u8 *iv = walk->iv; |
75 | u8 tmpbuf[bsize]; | 76 | u8 tmpbuf[MAX_CIPHER_BLOCKSIZE]; |
76 | 77 | ||
77 | do { | 78 | do { |
78 | memcpy(tmpbuf, src, bsize); | 79 | memcpy(tmpbuf, src, bsize); |
@@ -144,7 +145,7 @@ static int crypto_pcbc_decrypt_inplace(struct skcipher_request *req, | |||
144 | unsigned int nbytes = walk->nbytes; | 145 | unsigned int nbytes = walk->nbytes; |
145 | u8 *src = walk->src.virt.addr; | 146 | u8 *src = walk->src.virt.addr; |
146 | u8 *iv = walk->iv; | 147 | u8 *iv = walk->iv; |
147 | u8 tmpbuf[bsize] __aligned(__alignof__(u32)); | 148 | u8 tmpbuf[MAX_CIPHER_BLOCKSIZE] __aligned(__alignof__(u32)); |
148 | 149 | ||
149 | do { | 150 | do { |
150 | memcpy(tmpbuf, src, bsize); | 151 | memcpy(tmpbuf, src, bsize); |