aesgcm-select.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "ssh.h"
  2. #include "aesgcm.h"
  3. static ssh2_mac *aesgcm_mac_selector_new(const ssh2_macalg *alg,
  4. ssh_cipher *cipher)
  5. {
  6. static const ssh2_macalg *const real_algs[] = {
  7. #if HAVE_CLMUL
  8. &ssh2_aesgcm_mac_clmul,
  9. #endif
  10. #if HAVE_NEON_PMULL
  11. &ssh2_aesgcm_mac_neon,
  12. #endif
  13. &ssh2_aesgcm_mac_sw,
  14. NULL,
  15. };
  16. for (size_t i = 0; real_algs[i]; i++) {
  17. const ssh2_macalg *alg = real_algs[i];
  18. const struct aesgcm_extra *alg_extra =
  19. (const struct aesgcm_extra *)alg->extra;
  20. if (check_aesgcm_availability(alg_extra))
  21. return ssh2_mac_new(alg, cipher);
  22. }
  23. /* We should never reach the NULL at the end of the list, because
  24. * the last non-NULL entry should be software-only GCM, which is
  25. * always available. */
  26. unreachable("aesgcm_select ran off the end of its list");
  27. }
  28. const ssh2_macalg ssh2_aesgcm_mac = {
  29. .new = aesgcm_mac_selector_new,
  30. .name = "",
  31. .etm_name = "", /* Not selectable independently */
  32. .len = 16,
  33. .keylen = 0,
  34. };