sha512-select.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. for (size_t i = 0; real_algs[i]; i++) {
  28. const ssh_hashalg *alg = real_algs[i];
  29. const struct sha512_extra *alg_extra =
  30. (const struct sha512_extra *)alg->extra;
  31. if (check_availability(alg_extra))
  32. return ssh_hash_new(alg);
  33. }
  34. /* We should never reach the NULL at the end of the list, because
  35. * the last non-NULL entry should be software-only SHA-512, which
  36. * is always available. */
  37. unreachable("sha512_select ran off the end of its list");
  38. }
  39. const ssh_hashalg ssh_sha512 = {
  40. .new = sha512_select,
  41. .hlen = 64,
  42. .blocklen = 128,
  43. HASHALG_NAMES_ANNOTATED("SHA-512", "dummy selector vtable"),
  44. .extra = real_sha512_algs,
  45. };
  46. const ssh_hashalg ssh_sha384 = {
  47. .new = sha512_select,
  48. .hlen = 48,
  49. .blocklen = 128,
  50. HASHALG_NAMES_ANNOTATED("SHA-384", "dummy selector vtable"),
  51. .extra = real_sha384_algs,
  52. };