md5.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* Declaration of functions and data types used for MD5 sum computing
  2. library functions.
  3. Copyright (C) 1995-1997, 1999-2001, 2004-2006, 2008-2015 Free Software
  4. 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 3, 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, see <http://www.gnu.org/licenses/>. */
  16. #ifndef _MD5_H
  17. #define _MD5_H 1
  18. #include <stdio.h>
  19. #include <stdint.h>
  20. # if HAVE_OPENSSL_MD5
  21. # include <openssl/md5.h>
  22. # endif
  23. #define MD5_DIGEST_SIZE 16
  24. #define MD5_BLOCK_SIZE 64
  25. #ifndef __GNUC_PREREQ
  26. # if defined __GNUC__ && defined __GNUC_MINOR__
  27. # define __GNUC_PREREQ(maj, min) \
  28. ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
  29. # else
  30. # define __GNUC_PREREQ(maj, min) 0
  31. # endif
  32. #endif
  33. #ifndef __THROW
  34. # if defined __cplusplus && __GNUC_PREREQ (2,8)
  35. # define __THROW throw ()
  36. # else
  37. # define __THROW
  38. # endif
  39. #endif
  40. #ifndef _LIBC
  41. # define __md5_buffer md5_buffer
  42. # define __md5_finish_ctx md5_finish_ctx
  43. # define __md5_init_ctx md5_init_ctx
  44. # define __md5_process_block md5_process_block
  45. # define __md5_process_bytes md5_process_bytes
  46. # define __md5_read_ctx md5_read_ctx
  47. # define __md5_stream md5_stream
  48. #endif
  49. # ifdef __cplusplus
  50. extern "C" {
  51. # endif
  52. # if HAVE_OPENSSL_MD5
  53. # define GL_OPENSSL_NAME 5
  54. # include "gl_openssl.h"
  55. # else
  56. /* Structure to save state of computation between the single steps. */
  57. struct md5_ctx
  58. {
  59. uint32_t A;
  60. uint32_t B;
  61. uint32_t C;
  62. uint32_t D;
  63. uint32_t total[2];
  64. uint32_t buflen;
  65. uint32_t buffer[32];
  66. };
  67. /*
  68. * The following three functions are build up the low level used in
  69. * the functions 'md5_stream' and 'md5_buffer'.
  70. */
  71. /* Initialize structure containing state of computation.
  72. (RFC 1321, 3.3: Step 3) */
  73. extern void __md5_init_ctx (struct md5_ctx *ctx) __THROW;
  74. /* Starting with the result of former calls of this function (or the
  75. initialization function update the context for the next LEN bytes
  76. starting at BUFFER.
  77. It is necessary that LEN is a multiple of 64!!! */
  78. extern void __md5_process_block (const void *buffer, size_t len,
  79. struct md5_ctx *ctx) __THROW;
  80. /* Starting with the result of former calls of this function (or the
  81. initialization function update the context for the next LEN bytes
  82. starting at BUFFER.
  83. It is NOT required that LEN is a multiple of 64. */
  84. extern void __md5_process_bytes (const void *buffer, size_t len,
  85. struct md5_ctx *ctx) __THROW;
  86. /* Process the remaining bytes in the buffer and put result from CTX
  87. in first 16 bytes following RESBUF. The result is always in little
  88. endian byte order, so that a byte-wise output yields to the wanted
  89. ASCII representation of the message digest. */
  90. extern void *__md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) __THROW;
  91. /* Put result from CTX in first 16 bytes following RESBUF. The result is
  92. always in little endian byte order, so that a byte-wise output yields
  93. to the wanted ASCII representation of the message digest. */
  94. extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) __THROW;
  95. /* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
  96. result is always in little endian byte order, so that a byte-wise
  97. output yields to the wanted ASCII representation of the message
  98. digest. */
  99. extern void *__md5_buffer (const char *buffer, size_t len,
  100. void *resblock) __THROW;
  101. # endif
  102. /* Compute MD5 message digest for bytes read from STREAM. The
  103. resulting message digest number will be written into the 16 bytes
  104. beginning at RESBLOCK. */
  105. extern int __md5_stream (FILE *stream, void *resblock) __THROW;
  106. # ifdef __cplusplus
  107. }
  108. # endif
  109. #endif /* md5.h */