260-eng_devcrypto-make-sure-digest-can-do-copy.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. From 488521d77fdc1de5ae256ce0d9203e35ebc92993 Mon Sep 17 00:00:00 2001
  2. From: Eneas U de Queiroz <[email protected]>
  3. Date: Sat, 8 Dec 2018 18:01:04 -0200
  4. Subject: [PATCH 7/7] eng_devcrypto: make sure digest can do copy
  5. Digest must be able to do partial-state copy to be used.
  6. Signed-off-by: Eneas U de Queiroz <[email protected]>
  7. Reviewed-by: Matthias St. Pierre <[email protected]>
  8. Reviewed-by: Richard Levitte <[email protected]>
  9. (Merged from https://github.com/openssl/openssl/pull/7585)
  10. (cherry picked from commit 16e252a01b754a13e83d5e5e87afbe389997926b)
  11. --- a/crypto/engine/eng_devcrypto.c
  12. +++ b/crypto/engine/eng_devcrypto.c
  13. @@ -601,6 +601,30 @@ static int digest_cleanup(EVP_MD_CTX *ct
  14. return 1;
  15. }
  16. +static int devcrypto_test_digest(size_t digest_data_index)
  17. +{
  18. + struct session_op sess1, sess2;
  19. + struct cphash_op cphash;
  20. + int ret=0;
  21. +
  22. + memset(&sess1, 0, sizeof(sess1));
  23. + memset(&sess2, 0, sizeof(sess2));
  24. + sess1.mac = digest_data[digest_data_index].devcryptoid;
  25. + if (ioctl(cfd, CIOCGSESSION, &sess1) < 0)
  26. + return 0;
  27. + /* Make sure the driver is capable of hash state copy */
  28. + sess2.mac = sess1.mac;
  29. + if (ioctl(cfd, CIOCGSESSION, &sess2) >= 0) {
  30. + cphash.src_ses = sess1.ses;
  31. + cphash.dst_ses = sess2.ses;
  32. + if (ioctl(cfd, CIOCCPHASH, &cphash) >= 0)
  33. + ret = 1;
  34. + ioctl(cfd, CIOCFSESSION, &sess2.ses);
  35. + }
  36. + ioctl(cfd, CIOCFSESSION, &sess1.ses);
  37. + return ret;
  38. +}
  39. +
  40. /*
  41. * Keep a table of known nids and associated methods.
  42. * Note that known_digest_nids[] isn't necessarily indexed the same way as
  43. @@ -613,20 +637,14 @@ static EVP_MD *known_digest_methods[OSSL
  44. static void prepare_digest_methods(void)
  45. {
  46. size_t i;
  47. - struct session_op sess;
  48. -
  49. - memset(&sess, 0, sizeof(sess));
  50. for (i = 0, known_digest_nids_amount = 0; i < OSSL_NELEM(digest_data);
  51. i++) {
  52. /*
  53. - * Check that the algo is really availably by trying to open and close
  54. - * a session.
  55. + * Check that the algo is usable
  56. */
  57. - sess.mac = digest_data[i].devcryptoid;
  58. - if (ioctl(cfd, CIOCGSESSION, &sess) < 0
  59. - || ioctl(cfd, CIOCFSESSION, &sess.ses) < 0)
  60. + if (!devcrypto_test_digest(i))
  61. continue;
  62. if ((known_digest_methods[i] = EVP_MD_meth_new(digest_data[i].nid,