lrw.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _CRYPTO_LRW_H
  3. #define _CRYPTO_LRW_H
  4. #include <crypto/b128ops.h>
  5. struct scatterlist;
  6. struct gf128mul_64k;
  7. struct blkcipher_desc;
  8. #define LRW_BLOCK_SIZE 16
  9. struct lrw_table_ctx {
  10. /* optimizes multiplying a random (non incrementing, as at the
  11. * start of a new sector) value with key2, we could also have
  12. * used 4k optimization tables or no optimization at all. In the
  13. * latter case we would have to store key2 here */
  14. struct gf128mul_64k *table;
  15. /* stores:
  16. * key2*{ 0,0,...0,0,0,0,1 }, key2*{ 0,0,...0,0,0,1,1 },
  17. * key2*{ 0,0,...0,0,1,1,1 }, key2*{ 0,0,...0,1,1,1,1 }
  18. * key2*{ 0,0,...1,1,1,1,1 }, etc
  19. * needed for optimized multiplication of incrementing values
  20. * with key2 */
  21. be128 mulinc[128];
  22. };
  23. int lrw_init_table(struct lrw_table_ctx *ctx, const u8 *tweak);
  24. void lrw_free_table(struct lrw_table_ctx *ctx);
  25. struct lrw_crypt_req {
  26. be128 *tbuf;
  27. unsigned int tbuflen;
  28. struct lrw_table_ctx *table_ctx;
  29. void *crypt_ctx;
  30. void (*crypt_fn)(void *ctx, u8 *blks, unsigned int nbytes);
  31. };
  32. int lrw_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  33. struct scatterlist *src, unsigned int nbytes,
  34. struct lrw_crypt_req *req);
  35. #endif /* _CRYPTO_LRW_H */