BHash.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. /**
  37. * Checks if the given hash type number is valid.
  38. *
  39. * @param type hash type number
  40. * @return 1 if valid, 0 if not
  41. */
  42. int BHash_type_valid (int type);
  43. /**
  44. * Returns the size of a hash.
  45. *
  46. * @param cipher hash type number. Must be valid.
  47. * @return hash size in bytes
  48. */
  49. int BHash_size (int type);
  50. /**
  51. * Calculates a hash.
  52. *
  53. * @param type hash type number. Must be valid.
  54. * @param data data to calculate the hash of
  55. * @param data_len length of data
  56. * @param out the hash will be written here. Must not overlap with data.
  57. */
  58. void BHash_calculate (int type, uint8_t *data, int data_len, uint8_t *out);
  59. #endif