xts.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef _CRYPTO_XTS_H
  2. #define _CRYPTO_XTS_H
  3. #include <crypto/b128ops.h>
  4. #include <linux/crypto.h>
  5. #include <crypto/algapi.h>
  6. #include <linux/fips.h>
  7. struct scatterlist;
  8. struct blkcipher_desc;
  9. #define XTS_BLOCK_SIZE 16
  10. struct xts_crypt_req {
  11. be128 *tbuf;
  12. unsigned int tbuflen;
  13. void *tweak_ctx;
  14. void (*tweak_fn)(void *ctx, u8* dst, const u8* src);
  15. void *crypt_ctx;
  16. void (*crypt_fn)(void *ctx, u8 *blks, unsigned int nbytes);
  17. };
  18. #define XTS_TWEAK_CAST(x) ((void (*)(void *, u8*, const u8*))(x))
  19. int xts_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  20. struct scatterlist *src, unsigned int nbytes,
  21. struct xts_crypt_req *req);
  22. static inline int xts_check_key(struct crypto_tfm *tfm,
  23. const u8 *key, unsigned int keylen)
  24. {
  25. u32 *flags = &tfm->crt_flags;
  26. /*
  27. * key consists of keys of equal size concatenated, therefore
  28. * the length must be even.
  29. */
  30. if (keylen % 2) {
  31. *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
  32. return -EINVAL;
  33. }
  34. /* ensure that the AES and tweak key are not identical */
  35. if (fips_enabled &&
  36. !crypto_memneq(key, key + (keylen / 2), keylen / 2)) {
  37. *flags |= CRYPTO_TFM_RES_WEAK_KEY;
  38. return -EINVAL;
  39. }
  40. return 0;
  41. }
  42. #endif /* _CRYPTO_XTS_H */