md5.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Declaration of functions and data types used for MD5 sum computing
  2. library functions.
  3. Copyright (C) 1995-1997,1999,2000,2001,2004,2005,2006,2008
  4. Free Software Foundation, Inc.
  5. This file is part of the GNU C Library.
  6. This program is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the
  8. Free Software Foundation; either version 2, or (at your option) any
  9. later version.
  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. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software Foundation,
  16. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  17. #ifndef _MD5_H
  18. #define _MD5_H 1
  19. #include <stdio.h>
  20. #include <stdint.h>
  21. #define MD5_DIGEST_SIZE 16
  22. #define MD5_BLOCK_SIZE 64
  23. #ifndef __GNUC_PREREQ
  24. #if defined __GNUC__ && defined __GNUC_MINOR__
  25. #define __GNUC_PREREQ(maj, min) \
  26. ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
  27. #else
  28. #define __GNUC_PREREQ(maj, min) 0
  29. #endif
  30. #endif
  31. #ifndef __THROW
  32. #if defined __cplusplus && __GNUC_PREREQ (2,8)
  33. #define __THROW throw ()
  34. #else
  35. #define __THROW
  36. #endif
  37. #endif
  38. #ifndef _LIBC
  39. #define __md5_buffer md5_buffer
  40. #define __md5_finish_ctx md5_finish_ctx
  41. #define __md5_init_ctx md5_init_ctx
  42. #define __md5_process_block md5_process_block
  43. #define __md5_process_bytes md5_process_bytes
  44. #define __md5_read_ctx md5_read_ctx
  45. #define __md5_stream md5_stream
  46. #endif
  47. /* Structure to save state of computation between the single steps. */
  48. struct md5_ctx {
  49. uint32_t A;
  50. uint32_t B;
  51. uint32_t C;
  52. uint32_t D;
  53. uint32_t total[2];
  54. uint32_t buflen;
  55. uint32_t buffer[32];
  56. };
  57. /*
  58. * The following three functions are build up the low level used in
  59. * the functions `md5_stream' and `md5_buffer'.
  60. */
  61. /* Initialize structure containing state of computation.
  62. (RFC 1321, 3.3: Step 3) */
  63. extern void __md5_init_ctx(struct md5_ctx *ctx) __THROW;
  64. /* Starting with the result of former calls of this function (or the
  65. initialization function update the context for the next LEN bytes
  66. starting at BUFFER.
  67. It is necessary that LEN is a multiple of 64!!! */
  68. extern void __md5_process_block(const void *buffer, size_t len,
  69. struct md5_ctx *ctx) __THROW;
  70. /* Starting with the result of former calls of this function (or the
  71. initialization function update the context for the next LEN bytes
  72. starting at BUFFER.
  73. It is NOT required that LEN is a multiple of 64. */
  74. extern void __md5_process_bytes(const void *buffer, size_t len,
  75. struct md5_ctx *ctx) __THROW;
  76. /* Process the remaining bytes in the buffer and put result from CTX
  77. in first 16 bytes following RESBUF. The result is always in little
  78. endian byte order, so that a byte-wise output yields to the wanted
  79. ASCII representation of the message digest. */
  80. extern void *__md5_finish_ctx(struct md5_ctx *ctx, void *resbuf) __THROW;
  81. /* Put result from CTX in first 16 bytes following RESBUF. The result is
  82. always in little endian byte order, so that a byte-wise output yields
  83. to the wanted ASCII representation of the message digest. */
  84. extern void *__md5_read_ctx(const struct md5_ctx *ctx, void *resbuf) __THROW;
  85. /* Compute MD5 message digest for bytes read from STREAM. The
  86. resulting message digest number will be written into the 16 bytes
  87. beginning at RESBLOCK. */
  88. extern int __md5_stream(FILE * stream, void *resblock) __THROW;
  89. /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
  90. result is always in little endian byte order, so that a byte-wise
  91. output yields to the wanted ASCII representation of the message
  92. digest. */
  93. extern void *__md5_buffer(const char *buffer, size_t len,
  94. void *resblock) __THROW;
  95. #endif /* md5.h */