md5.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* $USAGI: md5.h,v 1.2 2000/11/02 11:59:25 yoshfuji Exp $ */
  2. /* $KAME: md5.h,v 1.4 2000/03/27 04:36:22 sumikawa Exp $ */
  3. /* $Id: md5.h,v 1.3 2006/01/17 17:40:45 paul Exp $ */
  4. /*
  5. * Copyright (C) 2004 6WIND
  6. * <Vincent.Jardin@6WIND.com>
  7. * All rights reserved.
  8. *
  9. * This MD5 code is Big endian and Little Endian compatible.
  10. */
  11. /*
  12. * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions
  17. * are met:
  18. * 1. Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. * 2. Redistributions in binary form must reproduce the above copyright
  21. * notice, this list of conditions and the following disclaimer in the
  22. * documentation and/or other materials provided with the distribution.
  23. * 3. Neither the name of the project nor the names of its contributors
  24. * may be used to endorse or promote products derived from this software
  25. * without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  28. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  31. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  33. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  36. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  37. * SUCH DAMAGE.
  38. */
  39. #ifndef _LIBZEBRA_MD5_H_
  40. #define _LIBZEBRA_MD5_H_
  41. #define MD5_BUFLEN 64
  42. typedef struct {
  43. union {
  44. uint32_t md5_state32[4];
  45. uint8_t md5_state8[16];
  46. } md5_st;
  47. #define md5_sta md5_st.md5_state32[0]
  48. #define md5_stb md5_st.md5_state32[1]
  49. #define md5_stc md5_st.md5_state32[2]
  50. #define md5_std md5_st.md5_state32[3]
  51. #define md5_st8 md5_st.md5_state8
  52. union {
  53. uint64_t md5_count64;
  54. uint8_t md5_count8[8];
  55. } md5_count;
  56. #define md5_n md5_count.md5_count64
  57. #define md5_n8 md5_count.md5_count8
  58. uint md5_i;
  59. uint8_t md5_buf[MD5_BUFLEN];
  60. } md5_ctxt;
  61. extern void md5_init (md5_ctxt *);
  62. extern void md5_loop (md5_ctxt *, const void *, u_int);
  63. extern void md5_pad (md5_ctxt *);
  64. extern void md5_result (uint8_t *, md5_ctxt *);
  65. /* compatibility */
  66. #define MD5_CTX md5_ctxt
  67. #define MD5Init(x) md5_init((x))
  68. #define MD5Update(x, y, z) md5_loop((x), (y), (z))
  69. #define MD5Final(x, y) \
  70. do { \
  71. md5_pad((y)); \
  72. md5_result((x), (y)); \
  73. } while (0)
  74. /* From RFC 2104 */
  75. void hmac_md5(unsigned char* text, int text_len, unsigned char* key,
  76. int key_len, uint8_t *digest);
  77. #endif /* ! _LIBZEBRA_MD5_H_*/