xts.h 978 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _CRYPTO_XTS_H
  3. #define _CRYPTO_XTS_H
  4. #include <crypto/b128ops.h>
  5. #include <crypto/internal/skcipher.h>
  6. #include <linux/fips.h>
  7. #define XTS_BLOCK_SIZE 16
  8. static inline int xts_verify_key(struct crypto_skcipher *tfm,
  9. const u8 *key, unsigned int keylen)
  10. {
  11. /*
  12. * key consists of keys of equal size concatenated, therefore
  13. * the length must be even.
  14. */
  15. if (keylen % 2)
  16. return -EINVAL;
  17. /*
  18. * In FIPS mode only a combined key length of either 256 or
  19. * 512 bits is allowed, c.f. FIPS 140-3 IG C.I.
  20. */
  21. if (fips_enabled && keylen != 32 && keylen != 64)
  22. return -EINVAL;
  23. /*
  24. * Ensure that the AES and tweak key are not identical when
  25. * in FIPS mode or the FORBID_WEAK_KEYS flag is set.
  26. */
  27. if ((fips_enabled || (crypto_skcipher_get_flags(tfm) &
  28. CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) &&
  29. !crypto_memneq(key, key + (keylen / 2), keylen / 2))
  30. return -EINVAL;
  31. return 0;
  32. }
  33. #endif /* _CRYPTO_XTS_H */