150-crypto-ccp-add-hash-state-import-and-export-support.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. From: Tom Lendacky <[email protected]>
  2. Subject: [PATCH v1] crypto: ccp - Add hash state import and export support
  3. Date: Tue, 12 Jan 2016 11:17:38 -0600
  4. Message-ID: <[email protected]>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset="utf-8"
  7. Content-Transfer-Encoding: 7bit
  8. Cc: Herbert Xu <[email protected]>, <[email protected]>,
  9. "David Miller" <[email protected]>
  10. To: <[email protected]>
  11. Commit 8996eafdcbad ("crypto: ahash - ensure statesize is non-zero")
  12. added a check to prevent ahash algorithms from successfully registering
  13. if the import and export functions were not implemented. This prevents
  14. an oops in the hash_accept function of algif_hash. This commit causes
  15. the ccp-crypto module SHA support and AES CMAC support from successfully
  16. registering and causing the ccp-crypto module load to fail because the
  17. ahash import and export functions are not implemented.
  18. Update the CCP Crypto API support to provide import and export support
  19. for ahash algorithms.
  20. Cc: <[email protected]> # 3.14.x-
  21. Signed-off-by: Tom Lendacky <[email protected]>
  22. ---
  23. drivers/crypto/ccp/ccp-crypto-aes-cmac.c | 23 +++++++++++++++++++++++
  24. drivers/crypto/ccp/ccp-crypto-sha.c | 23 +++++++++++++++++++++++
  25. 2 files changed, 46 insertions(+)
  26. --- a/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
  27. +++ b/drivers/crypto/ccp/ccp-crypto-aes-cmac.c
  28. @@ -220,6 +220,26 @@ static int ccp_aes_cmac_digest(struct ah
  29. return ccp_aes_cmac_finup(req);
  30. }
  31. +static int ccp_aes_cmac_export(struct ahash_request *req, void *out)
  32. +{
  33. + struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx(req);
  34. + struct ccp_aes_cmac_req_ctx *state = out;
  35. +
  36. + *state = *rctx;
  37. +
  38. + return 0;
  39. +}
  40. +
  41. +static int ccp_aes_cmac_import(struct ahash_request *req, const void *in)
  42. +{
  43. + struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx(req);
  44. + const struct ccp_aes_cmac_req_ctx *state = in;
  45. +
  46. + *rctx = *state;
  47. +
  48. + return 0;
  49. +}
  50. +
  51. static int ccp_aes_cmac_setkey(struct crypto_ahash *tfm, const u8 *key,
  52. unsigned int key_len)
  53. {
  54. @@ -352,10 +372,13 @@ int ccp_register_aes_cmac_algs(struct li
  55. alg->final = ccp_aes_cmac_final;
  56. alg->finup = ccp_aes_cmac_finup;
  57. alg->digest = ccp_aes_cmac_digest;
  58. + alg->export = ccp_aes_cmac_export;
  59. + alg->import = ccp_aes_cmac_import;
  60. alg->setkey = ccp_aes_cmac_setkey;
  61. halg = &alg->halg;
  62. halg->digestsize = AES_BLOCK_SIZE;
  63. + halg->statesize = sizeof(struct ccp_aes_cmac_req_ctx);
  64. base = &halg->base;
  65. snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "cmac(aes)");
  66. --- a/drivers/crypto/ccp/ccp-crypto-sha.c
  67. +++ b/drivers/crypto/ccp/ccp-crypto-sha.c
  68. @@ -207,6 +207,26 @@ static int ccp_sha_digest(struct ahash_r
  69. return ccp_sha_finup(req);
  70. }
  71. +static int ccp_sha_export(struct ahash_request *req, void *out)
  72. +{
  73. + struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req);
  74. + struct ccp_sha_req_ctx *state = out;
  75. +
  76. + *state = *rctx;
  77. +
  78. + return 0;
  79. +}
  80. +
  81. +static int ccp_sha_import(struct ahash_request *req, const void *in)
  82. +{
  83. + struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req);
  84. + const struct ccp_sha_req_ctx *state = in;
  85. +
  86. + *rctx = *state;
  87. +
  88. + return 0;
  89. +}
  90. +
  91. static int ccp_sha_setkey(struct crypto_ahash *tfm, const u8 *key,
  92. unsigned int key_len)
  93. {
  94. @@ -403,9 +423,12 @@ static int ccp_register_sha_alg(struct l
  95. alg->final = ccp_sha_final;
  96. alg->finup = ccp_sha_finup;
  97. alg->digest = ccp_sha_digest;
  98. + alg->export = ccp_sha_export;
  99. + alg->import = ccp_sha_import;
  100. halg = &alg->halg;
  101. halg->digestsize = def->digest_size;
  102. + halg->statesize = sizeof(struct ccp_sha_req_ctx);
  103. base = &halg->base;
  104. snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "%s", def->name);