Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _CRYPTO_XTS_H
0003 #define _CRYPTO_XTS_H
0004 
0005 #include <crypto/b128ops.h>
0006 #include <crypto/internal/skcipher.h>
0007 #include <linux/fips.h>
0008 
0009 #define XTS_BLOCK_SIZE 16
0010 
0011 static inline int xts_check_key(struct crypto_tfm *tfm,
0012                 const u8 *key, unsigned int keylen)
0013 {
0014     /*
0015      * key consists of keys of equal size concatenated, therefore
0016      * the length must be even.
0017      */
0018     if (keylen % 2)
0019         return -EINVAL;
0020 
0021     /* ensure that the AES and tweak key are not identical */
0022     if (fips_enabled && !crypto_memneq(key, key + (keylen / 2), keylen / 2))
0023         return -EINVAL;
0024 
0025     return 0;
0026 }
0027 
0028 static inline int xts_verify_key(struct crypto_skcipher *tfm,
0029                  const u8 *key, unsigned int keylen)
0030 {
0031     /*
0032      * key consists of keys of equal size concatenated, therefore
0033      * the length must be even.
0034      */
0035     if (keylen % 2)
0036         return -EINVAL;
0037 
0038     /* ensure that the AES and tweak key are not identical */
0039     if ((fips_enabled || (crypto_skcipher_get_flags(tfm) &
0040                   CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) &&
0041         !crypto_memneq(key, key + (keylen / 2), keylen / 2))
0042         return -EINVAL;
0043 
0044     return 0;
0045 }
0046 
0047 #endif  /* _CRYPTO_XTS_H */