sha1.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJLIB_UTIL_SHA1_H__
  20. #define __PJLIB_UTIL_SHA1_H__
  21. /**
  22. * @file sha1.h
  23. * @brief SHA1 encryption implementation
  24. */
  25. #include <pj/types.h>
  26. PJ_BEGIN_DECL
  27. /**
  28. * @defgroup PJLIB_UTIL_SHA1 SHA1
  29. * @ingroup PJLIB_UTIL_ENCRYPTION
  30. * @{
  31. */
  32. /** SHA1 context */
  33. typedef struct pj_sha1_context
  34. {
  35. pj_uint32_t state[5]; /**< State */
  36. pj_uint32_t count[2]; /**< Count */
  37. pj_uint8_t buffer[64]; /**< Buffer */
  38. } pj_sha1_context;
  39. /** SHA1 digest size is 20 bytes */
  40. #define PJ_SHA1_DIGEST_SIZE 20
  41. /** Initialize the algorithm.
  42. * @param ctx SHA1 context.
  43. */
  44. PJ_DECL(void) pj_sha1_init(pj_sha1_context *ctx);
  45. /** Append a stream to the message.
  46. * @param ctx SHA1 context.
  47. * @param data Data.
  48. * @param nbytes Length of data.
  49. */
  50. PJ_DECL(void) pj_sha1_update(pj_sha1_context *ctx,
  51. const pj_uint8_t *data,
  52. pj_size_t nbytes);
  53. /** Finish the message and return the digest.
  54. * @param ctx SHA1 context.
  55. * @param digest 16 byte digest.
  56. */
  57. PJ_DECL(void) pj_sha1_final(pj_sha1_context *ctx,
  58. pj_uint8_t digest[PJ_SHA1_DIGEST_SIZE]);
  59. /**
  60. * @}
  61. */
  62. PJ_END_DECL
  63. #endif /* __PJLIB_UTIL_SHA1_H__ */