hmac_md5.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_HMAC_MD5_H__
  20. #define __PJLIB_UTIL_HMAC_MD5_H__
  21. /**
  22. * @file hmac_md5.h
  23. * @brief HMAC MD5 Message Authentication
  24. */
  25. /**
  26. * @defgroup PJLIB_UTIL_ENCRYPTION Encryption Algorithms
  27. */
  28. #include <pj/types.h>
  29. #include <pjlib-util/md5.h>
  30. PJ_BEGIN_DECL
  31. /**
  32. * @defgroup PJLIB_UTIL_HMAC_MD5 HMAC MD5 Message Authentication
  33. * @ingroup PJLIB_UTIL_ENCRYPTION
  34. * @{
  35. *
  36. * This module contains the implementation of HMAC: Keyed-Hashing
  37. * for Message Authentication, as described in RFC 2104
  38. */
  39. /**
  40. * The HMAC-MD5 context used in the incremental HMAC calculation.
  41. */
  42. typedef struct pj_hmac_md5_context
  43. {
  44. pj_md5_context context; /**< MD5 context */
  45. pj_uint8_t k_opad[64]; /**< opad xor-ed with key */
  46. } pj_hmac_md5_context;
  47. /**
  48. * Calculate HMAC MD5 digest for the specified input and key.
  49. *
  50. * @param input Pointer to the input stream.
  51. * @param input_len Length of input stream in bytes.
  52. * @param key Pointer to the authentication key.
  53. * @param key_len Length of the authentication key.
  54. * @param digest Buffer to be filled with HMAC MD5 digest.
  55. */
  56. PJ_DECL(void) pj_hmac_md5(const pj_uint8_t *input, unsigned input_len,
  57. const pj_uint8_t *key, unsigned key_len,
  58. pj_uint8_t digest[16]);
  59. /**
  60. * Initiate HMAC-MD5 context for incremental hashing.
  61. *
  62. * @param hctx HMAC-MD5 context.
  63. * @param key Pointer to the authentication key.
  64. * @param key_len Length of the authentication key.
  65. */
  66. PJ_DECL(void) pj_hmac_md5_init(pj_hmac_md5_context *hctx,
  67. const pj_uint8_t *key, unsigned key_len);
  68. /**
  69. * Append string to the message.
  70. *
  71. * @param hctx HMAC-MD5 context.
  72. * @param input Pointer to the input stream.
  73. * @param input_len Length of input stream in bytes.
  74. */
  75. PJ_DECL(void) pj_hmac_md5_update(pj_hmac_md5_context *hctx,
  76. const pj_uint8_t *input,
  77. unsigned input_len);
  78. /**
  79. * Finish the message and return the digest.
  80. *
  81. * @param hctx HMAC-MD5 context.
  82. * @param digest Buffer to be filled with HMAC MD5 digest.
  83. */
  84. PJ_DECL(void) pj_hmac_md5_final(pj_hmac_md5_context *hctx,
  85. pj_uint8_t digest[16]);
  86. /**
  87. * @}
  88. */
  89. PJ_END_DECL
  90. #endif /* __PJLIB_UTIL_HMAC_MD5_H__ */