xts.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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_check_key(struct crypto_tfm *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. /* ensure that the AES and tweak key are not identical */
  18. if (fips_enabled && !crypto_memneq(key, key + (keylen / 2), keylen / 2))
  19. return -EINVAL;
  20. return 0;
  21. }
  22. static inline int xts_verify_key(struct crypto_skcipher *tfm,
  23. const u8 *key, unsigned int keylen)
  24. {
  25. /*
  26. * key consists of keys of equal size concatenated, therefore
  27. * the length must be even.
  28. */
  29. if (keylen % 2)
  30. return -EINVAL;
  31. /* ensure that the AES and tweak key are not identical */
  32. if ((fips_enabled || (crypto_skcipher_get_flags(tfm) &
  33. CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) &&
  34. !crypto_memneq(key, key + (keylen / 2), keylen / 2))
  35. return -EINVAL;
  36. return 0;
  37. }
  38. #endif /* _CRYPTO_XTS_H */