hmac_sha1.h 3.2 KB

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