sha256-select.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Top-level vtables to select a SHA-256 implementation.
  3. */
  4. #include <assert.h>
  5. #include <stdlib.h>
  6. #include "putty.h"
  7. #include "ssh.h"
  8. #include "sha256.h"
  9. static ssh_hash *sha256_select(const ssh_hashalg *alg)
  10. {
  11. static const ssh_hashalg *const real_algs[] = {
  12. #if HAVE_SHA_NI
  13. &ssh_sha256_ni,
  14. #endif
  15. #if HAVE_NEON_CRYPTO
  16. &ssh_sha256_neon,
  17. #endif
  18. &ssh_sha256_sw,
  19. NULL,
  20. };
  21. for (size_t i = 0; real_algs[i]; i++) {
  22. const ssh_hashalg *alg = real_algs[i];
  23. const struct sha256_extra *alg_extra =
  24. (const struct sha256_extra *)alg->extra;
  25. if (check_availability(alg_extra))
  26. return ssh_hash_new(alg);
  27. }
  28. /* We should never reach the NULL at the end of the list, because
  29. * the last non-NULL entry should be software-only SHA-256, which
  30. * is always available. */
  31. unreachable("sha256_select ran off the end of its list");
  32. }
  33. const ssh_hashalg ssh_sha256 = {
  34. .new = sha256_select,
  35. .hlen = 32,
  36. .blocklen = 64,
  37. HASHALG_NAMES_ANNOTATED("SHA-256", "dummy selector vtable"),
  38. };