BHash.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @file BHash.c
  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. #include <security/BHash.h>
  23. int BHash_type_valid (int type)
  24. {
  25. switch (type) {
  26. case BHASH_TYPE_MD5:
  27. case BHASH_TYPE_SHA1:
  28. return 1;
  29. default:
  30. return 0;
  31. }
  32. }
  33. int BHash_size (int type)
  34. {
  35. switch (type) {
  36. case BHASH_TYPE_MD5:
  37. return BHASH_TYPE_MD5_SIZE;
  38. case BHASH_TYPE_SHA1:
  39. return BHASH_TYPE_SHA1_SIZE;
  40. default:
  41. ASSERT(0)
  42. return 0;
  43. }
  44. }
  45. void BHash_calculate (int type, uint8_t *data, int data_len, uint8_t *out)
  46. {
  47. switch (type) {
  48. case BHASH_TYPE_MD5:
  49. MD5(data, data_len, out);
  50. break;
  51. case BHASH_TYPE_SHA1:
  52. SHA1(data, data_len, out);
  53. break;
  54. default:
  55. ASSERT(0)
  56. ;
  57. }
  58. }