common.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _COMMON_H_
  6. #define _COMMON_H_
  7. #include <linux/crypto.h>
  8. #include <linux/types.h>
  9. #include <crypto/aes.h>
  10. #include <crypto/hash.h>
  11. #include <crypto/internal/skcipher.h>
  12. /* xts du size */
  13. #define QCE_SECTOR_SIZE 512
  14. /* key size in bytes */
  15. #define QCE_SHA_HMAC_KEY_SIZE 64
  16. #define QCE_MAX_CIPHER_KEY_SIZE AES_KEYSIZE_256
  17. /* IV length in bytes */
  18. #define QCE_AES_IV_LENGTH AES_BLOCK_SIZE
  19. /* max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */
  20. #define QCE_MAX_IV_SIZE AES_BLOCK_SIZE
  21. /* maximum nonce bytes */
  22. #define QCE_MAX_NONCE 16
  23. #define QCE_MAX_NONCE_WORDS (QCE_MAX_NONCE / sizeof(u32))
  24. /* burst size alignment requirement */
  25. #define QCE_MAX_ALIGN_SIZE 64
  26. /* cipher algorithms */
  27. #define QCE_ALG_DES BIT(0)
  28. #define QCE_ALG_3DES BIT(1)
  29. #define QCE_ALG_AES BIT(2)
  30. /* hash and hmac algorithms */
  31. #define QCE_HASH_SHA1 BIT(3)
  32. #define QCE_HASH_SHA256 BIT(4)
  33. #define QCE_HASH_SHA1_HMAC BIT(5)
  34. #define QCE_HASH_SHA256_HMAC BIT(6)
  35. #define QCE_HASH_AES_CMAC BIT(7)
  36. /* cipher modes */
  37. #define QCE_MODE_CBC BIT(8)
  38. #define QCE_MODE_ECB BIT(9)
  39. #define QCE_MODE_CTR BIT(10)
  40. #define QCE_MODE_XTS BIT(11)
  41. #define QCE_MODE_CCM BIT(12)
  42. #define QCE_MODE_MASK GENMASK(12, 8)
  43. /* cipher encryption/decryption operations */
  44. #define QCE_ENCRYPT BIT(13)
  45. #define QCE_DECRYPT BIT(14)
  46. #define IS_DES(flags) (flags & QCE_ALG_DES)
  47. #define IS_3DES(flags) (flags & QCE_ALG_3DES)
  48. #define IS_AES(flags) (flags & QCE_ALG_AES)
  49. #define IS_SHA1(flags) (flags & QCE_HASH_SHA1)
  50. #define IS_SHA256(flags) (flags & QCE_HASH_SHA256)
  51. #define IS_SHA1_HMAC(flags) (flags & QCE_HASH_SHA1_HMAC)
  52. #define IS_SHA256_HMAC(flags) (flags & QCE_HASH_SHA256_HMAC)
  53. #define IS_CMAC(flags) (flags & QCE_HASH_AES_CMAC)
  54. #define IS_SHA(flags) (IS_SHA1(flags) || IS_SHA256(flags))
  55. #define IS_SHA_HMAC(flags) \
  56. (IS_SHA1_HMAC(flags) || IS_SHA256_HMAC(flags))
  57. #define IS_CBC(mode) (mode & QCE_MODE_CBC)
  58. #define IS_ECB(mode) (mode & QCE_MODE_ECB)
  59. #define IS_CTR(mode) (mode & QCE_MODE_CTR)
  60. #define IS_XTS(mode) (mode & QCE_MODE_XTS)
  61. #define IS_CCM(mode) (mode & QCE_MODE_CCM)
  62. #define IS_ENCRYPT(dir) (dir & QCE_ENCRYPT)
  63. #define IS_DECRYPT(dir) (dir & QCE_DECRYPT)
  64. struct qce_alg_template {
  65. struct list_head entry;
  66. u32 crypto_alg_type;
  67. unsigned long alg_flags;
  68. const u32 *std_iv;
  69. union {
  70. struct skcipher_alg skcipher;
  71. struct ahash_alg ahash;
  72. } alg;
  73. struct qce_device *qce;
  74. const u8 *hash_zero;
  75. const u32 digest_size;
  76. };
  77. void qce_cpu_to_be32p_array(__be32 *dst, const u8 *src, unsigned int len);
  78. int qce_check_status(struct qce_device *qce, u32 *status);
  79. void qce_get_version(struct qce_device *qce, u32 *major, u32 *minor, u32 *step);
  80. int qce_start(struct crypto_async_request *async_req, u32 type, u32 totallen,
  81. u32 offset);
  82. #endif /* _COMMON_H_ */