shautils.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * sha and other hashing utilities
  3. *
  4. * Copyright (C) 2014 1&1 Germany
  5. *
  6. * This file is part of Kamailio, a free SIP server.
  7. *
  8. * Kamailio is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * Kamailio 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
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "../../md5.h"
  23. #include "../../ut.h"
  24. #include "shautils.h"
  25. /*! \brief Compute MD5 checksum */
  26. void compute_md5(char *dst, char *src, int src_len)
  27. {
  28. MD5_CTX context;
  29. unsigned char digest[16];
  30. MD5Init (&context);
  31. MD5Update (&context, src, src_len);
  32. U_MD5Final (digest, &context);
  33. string2hex(digest, 16, dst);
  34. }
  35. /*! \brief Compute SHA256 checksum */
  36. void compute_sha256(char *dst, u_int8_t *src, int src_len)
  37. {
  38. SHA256_CTX ctx256;
  39. SHA256_Init(&ctx256);
  40. SHA256_Update(&ctx256, src, src_len);
  41. SHA256_End(&ctx256, dst);
  42. }
  43. /*! \brief Compute SHA384 checksum */
  44. void compute_sha384(char *dst, u_int8_t *src, int src_len)
  45. {
  46. SHA384_CTX ctx384;
  47. SHA384_Init(&ctx384);
  48. SHA384_Update(&ctx384, src, src_len);
  49. SHA384_End(&ctx384, dst);
  50. }
  51. /*! \brief Compute SHA512 checksum */
  52. void compute_sha512(char *dst, u_int8_t *src, int src_len)
  53. {
  54. SHA512_CTX ctx512;
  55. SHA512_Init(&ctx512);
  56. SHA512_Update(&ctx512, src, src_len);
  57. SHA512_End(&ctx512, dst);
  58. }