]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
s390/crypto: Extend key length check for AES-XTS in fips mode.
authorHarald Freudenberger <freude@linux.vnet.ibm.com>
Thu, 15 Dec 2016 13:58:08 +0000 (14:58 +0100)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Tue, 31 Jan 2017 09:46:06 +0000 (10:46 +0100)
In fips mode only xts keys with 128 bit or 125 bit are allowed.
This fix extends the xts_aes_set_key function to check for these
valid key lengths in fips mode.

Signed-off-by: Harald Freudenberger <freude@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
arch/s390/crypto/aes_s390.c

index 303d28eb03a2f697b5ceb18c25cf8a72df4caf4d..591cbdf615af046d4e0662241b03c3b113280333 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/cpufeature.h>
 #include <linux/init.h>
 #include <linux/spinlock.h>
+#include <linux/fips.h>
 #include <crypto/xts.h>
 #include <asm/cpacf.h>
 
@@ -501,6 +502,12 @@ static int xts_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
        if (err)
                return err;
 
+       /* In fips mode only 128 bit or 256 bit keys are valid */
+       if (fips_enabled && key_len != 32 && key_len != 64) {
+               tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
+               return -EINVAL;
+       }
+
        /* Pick the correct function code based on the key length */
        fc = (key_len == 32) ? CPACF_KM_XTS_128 :
             (key_len == 64) ? CPACF_KM_XTS_256 : 0;