BHash.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * @file BHash.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * Cryptographic hash funtions abstraction.
  25. */
  26. #ifndef BADVPN_SECURITY_BHASH_H
  27. #define BADVPN_SECURITY_BHASH_H
  28. #include <stdint.h>
  29. #include <openssl/md5.h>
  30. #include <openssl/sha.h>
  31. #include <misc/debug.h>
  32. #define BHASH_TYPE_MD5 1
  33. #define BHASH_TYPE_MD5_SIZE 16
  34. #define BHASH_TYPE_SHA1 2
  35. #define BHASH_TYPE_SHA1_SIZE 20
  36. #define BHASH_MAX_SIZE 20
  37. /**
  38. * Checks if the given hash type number is valid.
  39. *
  40. * @param type hash type number
  41. * @return 1 if valid, 0 if not
  42. */
  43. int BHash_type_valid (int type);
  44. /**
  45. * Returns the size of a hash.
  46. *
  47. * @param cipher hash type number. Must be valid.
  48. * @return hash size in bytes
  49. */
  50. int BHash_size (int type);
  51. /**
  52. * Calculates a hash.
  53. * {@link BSecurity_GlobalInitThreadSafe} must have been done if this is
  54. * being called from a non-main thread.
  55. *
  56. * @param type hash type number. Must be valid.
  57. * @param data data to calculate the hash of
  58. * @param data_len length of data
  59. * @param out the hash will be written here. Must not overlap with data.
  60. */
  61. void BHash_calculate (int type, uint8_t *data, int data_len, uint8_t *out);
  62. #endif