aboutsummaryrefslogtreecommitdiffstats
path: root/include/crypto/aes.h
diff options
context:
space:
mode:
authorIuliana Prodan <iuliana.prodan@nxp.com>2019-07-31 16:05:55 +0300
committerHerbert Xu <herbert@gondor.apana.org.au>2019-08-09 15:11:43 +1000
commitbc67d04e75260942fb534fb91673103dcad7ca96 (patch)
tree7a32f21ca3a91c5eddf22fa8a06ac13f1ecad681 /include/crypto/aes.h
parentcrypto: gcm - helper functions for assoclen/authsize check (diff)
downloadlinux-dev-bc67d04e75260942fb534fb91673103dcad7ca96.tar.xz
linux-dev-bc67d04e75260942fb534fb91673103dcad7ca96.zip
crypto: aes - helper function to validate key length for AES algorithms
Add inline helper function to check key length for AES algorithms. The key can be 128, 192 or 256 bits size. This function is used in the generic aes implementation. Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to '')
-rw-r--r--include/crypto/aes.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/crypto/aes.h b/include/crypto/aes.h
index 8e0f4cf948e5..2090729701ab 100644
--- a/include/crypto/aes.h
+++ b/include/crypto/aes.h
@@ -31,6 +31,23 @@ struct crypto_aes_ctx {
extern const u32 crypto_ft_tab[4][256] ____cacheline_aligned;
extern const u32 crypto_it_tab[4][256] ____cacheline_aligned;
+/*
+ * validate key length for AES algorithms
+ */
+static inline int aes_check_keylen(unsigned int keylen)
+{
+ switch (keylen) {
+ case AES_KEYSIZE_128:
+ case AES_KEYSIZE_192:
+ case AES_KEYSIZE_256:
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
int crypto_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
unsigned int key_len);