aesgcm.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Common parts of the state structure for AESGCM MAC implementations.
  3. */
  4. #define AESGCM_COMMON_FIELDS \
  5. ssh_cipher *cipher; \
  6. unsigned char partblk[16]; \
  7. size_t skiplen, aadlen, ciphertextlen; \
  8. size_t skipgot, aadgot, partlen; \
  9. BinarySink_IMPLEMENTATION; \
  10. ssh2_mac mac
  11. /*
  12. * The 'extra' structure is used to include information about how to
  13. * check if a given implementation is available at run time, and
  14. * whether we've already checked.
  15. */
  16. struct aesgcm_extra_mutable;
  17. struct aesgcm_extra {
  18. /* Function to check availability. Might be expensive, so we don't
  19. * want to call it more than once. */
  20. bool (*check_available)(void);
  21. /* Point to a writable substructure. */
  22. struct aesgcm_extra_mutable *mut;
  23. /*
  24. * Extra API function specific to this MAC type that allows
  25. * testcrypt to set more general lengths for skiplen and aadlen.
  26. */
  27. void (*set_prefix_lengths)(ssh2_mac *mac, size_t skip, size_t aad);
  28. };
  29. struct aesgcm_extra_mutable {
  30. bool checked_availability;
  31. bool is_available;
  32. };
  33. static inline bool check_aesgcm_availability(const struct aesgcm_extra *extra)
  34. {
  35. if (!extra->mut->checked_availability) {
  36. extra->mut->is_available = extra->check_available();
  37. extra->mut->checked_availability = true;
  38. }
  39. return extra->mut->is_available;
  40. }