sha512-select.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Top-level vtables to select a SHA-512 implementation.
  3. */
  4. #include <assert.h>
  5. #include <stdlib.h>
  6. #include "putty.h"
  7. #include "ssh.h"
  8. #include "sha512.h"
  9. static const ssh_hashalg *const real_sha512_algs[] = {
  10. #if HAVE_NEON_SHA512
  11. &ssh_sha512_neon,
  12. #endif
  13. &ssh_sha512_sw,
  14. NULL,
  15. };
  16. static const ssh_hashalg *const real_sha384_algs[] = {
  17. #if HAVE_NEON_SHA512
  18. &ssh_sha384_neon,
  19. #endif
  20. &ssh_sha384_sw,
  21. NULL,
  22. };
  23. static ssh_hash *sha512_select(const ssh_hashalg *alg)
  24. {
  25. const ssh_hashalg *const *real_algs =
  26. (const ssh_hashalg *const *)alg->extra;
  27. { // WINSCP
  28. size_t i;
  29. for (i = 0; real_algs[i]; i++) {
  30. const ssh_hashalg *alg = real_algs[i];
  31. const struct sha512_extra *alg_extra =
  32. (const struct sha512_extra *)alg->extra;
  33. if (check_availability(alg_extra))
  34. return ssh_hash_new(alg);
  35. }
  36. /* We should never reach the NULL at the end of the list, because
  37. * the last non-NULL entry should be software-only SHA-512, which
  38. * is always available. */
  39. unreachable("sha512_select ran off the end of its list");
  40. } // WINSCP
  41. }
  42. const ssh_hashalg ssh_sha512 = {
  43. /*.new =*/ sha512_select,
  44. NULL, NULL, NULL, NULL, // WINSCP
  45. /*.hlen =*/ 64,
  46. /*.blocklen =*/ 128,
  47. HASHALG_NAMES_ANNOTATED("SHA-512", "dummy selector vtable"),
  48. /*.extra =*/ real_sha512_algs,
  49. };
  50. const ssh_hashalg ssh_sha384 = {
  51. /*.new =*/ sha512_select,
  52. NULL, NULL, NULL, NULL, // WINSCP
  53. /*.hlen =*/ 48,
  54. /*.blocklen =*/ 128,
  55. HASHALG_NAMES_ANNOTATED("SHA-384", "dummy selector vtable"),
  56. /*.extra =*/ real_sha384_algs,
  57. };