sha1-select.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Top-level vtables to select a SHA-1 implementation.
  3. */
  4. #include <assert.h>
  5. #include <stdlib.h>
  6. #include "putty.h"
  7. #include "ssh.h"
  8. #include "sha1.h"
  9. static ssh_hash *sha1_select(const ssh_hashalg *alg)
  10. {
  11. static const ssh_hashalg *const real_algs[] = {
  12. #if HAVE_SHA_NI
  13. &ssh_sha1_ni,
  14. #endif
  15. #if HAVE_NEON_CRYPTO
  16. &ssh_sha1_neon,
  17. #endif
  18. &ssh_sha1_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 sha1_extra *alg_extra =
  24. (const struct sha1_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-1, which
  30. * is always available. */
  31. unreachable("sha1_select ran off the end of its list");
  32. }
  33. const ssh_hashalg ssh_sha1 = {
  34. .new = sha1_select,
  35. .hlen = 20,
  36. .blocklen = 64,
  37. HASHALG_NAMES_ANNOTATED("SHA-1", "dummy selector vtable"),
  38. };