diff options
author | Salvatore Mesoraca <s.mesoraca16@gmail.com> | 2018-04-09 09:54:46 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2018-04-20 12:58:32 -0400 |
commit | 13c935bb09948aef0202574ee12bb089459eb43b (patch) | |
tree | 6fa0ea9c5433ea754889a5924d566815b6ad7f35 | |
parent | c4e848586cf11dd80633e4981108f36d4b414df1 (diff) |
crypto: api - laying defines and checks for statically allocated buffers
In preparation for the removal of VLAs[1] from crypto code.
We create 2 new compile-time constants: all ciphers implemented
in Linux have a block size less than or equal to 16 bytes and
the most demanding hw require 16 bytes alignment for the block
buffer.
We also enforce these limits in crypto_check_alg when a new
cipher is registered.
[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/algapi.c | 10 | ||||
-rw-r--r-- | include/crypto/algapi.h | 8 |
2 files changed, 18 insertions, 0 deletions
diff --git a/crypto/algapi.c b/crypto/algapi.c index 2a0271b5f62a..c0755cf4f53f 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c | |||
@@ -10,6 +10,7 @@ | |||
10 | * | 10 | * |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <crypto/algapi.h> | ||
13 | #include <linux/err.h> | 14 | #include <linux/err.h> |
14 | #include <linux/errno.h> | 15 | #include <linux/errno.h> |
15 | #include <linux/fips.h> | 16 | #include <linux/fips.h> |
@@ -59,6 +60,15 @@ static int crypto_check_alg(struct crypto_alg *alg) | |||
59 | if (alg->cra_blocksize > PAGE_SIZE / 8) | 60 | if (alg->cra_blocksize > PAGE_SIZE / 8) |
60 | return -EINVAL; | 61 | return -EINVAL; |
61 | 62 | ||
63 | if (!alg->cra_type && (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == | ||
64 | CRYPTO_ALG_TYPE_CIPHER) { | ||
65 | if (alg->cra_alignmask > MAX_CIPHER_ALIGNMASK) | ||
66 | return -EINVAL; | ||
67 | |||
68 | if (alg->cra_blocksize > MAX_CIPHER_BLOCKSIZE) | ||
69 | return -EINVAL; | ||
70 | } | ||
71 | |||
62 | if (alg->cra_priority < 0) | 72 | if (alg->cra_priority < 0) |
63 | return -EINVAL; | 73 | return -EINVAL; |
64 | 74 | ||
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 1aba888241dd..bd5e8ccf1687 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h | |||
@@ -17,6 +17,14 @@ | |||
17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
18 | #include <linux/skbuff.h> | 18 | #include <linux/skbuff.h> |
19 | 19 | ||
20 | /* | ||
21 | * Maximum values for blocksize and alignmask, used to allocate | ||
22 | * static buffers that are big enough for any combination of | ||
23 | * ciphers and architectures. | ||
24 | */ | ||
25 | #define MAX_CIPHER_BLOCKSIZE 16 | ||
26 | #define MAX_CIPHER_ALIGNMASK 15 | ||
27 | |||
20 | struct crypto_aead; | 28 | struct crypto_aead; |
21 | struct crypto_instance; | 29 | struct crypto_instance; |
22 | struct module; | 30 | struct module; |