crypt_find_hash_any.c 918 B

12345678910111213141516171819202122232425262728293031323334
  1. /* LibTomCrypt, modular cryptographic library -- Tom St Denis
  2. *
  3. * LibTomCrypt is a library that provides various cryptographic
  4. * algorithms in a highly modular and flexible manner.
  5. *
  6. * The library is free for all purposes without any express
  7. * guarantee it works.
  8. *
  9. * Tom St Denis, [email protected], http://libtomcrypt.org
  10. */
  11. #include "mycrypt.h"
  12. /* return first hash with at least [amount over] digestlen bytes of output */
  13. int find_hash_any(const char *name, int digestlen)
  14. {
  15. int x, y, z;
  16. _ARGCHK(name != NULL);
  17. x = find_hash(name);
  18. if (x != -1) return x;
  19. y = MAXBLOCKSIZE+1;
  20. z = -1;
  21. for (x = 0; x < TAB_SIZE; x++) {
  22. if (hash_descriptor[x].name == NULL) {
  23. continue;
  24. }
  25. if ((int)hash_descriptor[x].hashsize >= digestlen && (int)hash_descriptor[x].hashsize < y) {
  26. z = x;
  27. y = hash_descriptor[x].hashsize;
  28. }
  29. }
  30. return z;
  31. }