apr_md5.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. {
  2. * This is work is derived from material Copyright RSA Data Security, Inc.
  3. *
  4. * The RSA copyright statement and Licence for that original material is
  5. * included below. This is followed by the Apache copyright statement and
  6. * licence for the modifications made to that material.
  7. }
  8. { Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
  9. rights reserved.
  10. License to copy and use this software is granted provided that it
  11. is identified as the "RSA Data Security, Inc. MD5 Message-Digest
  12. Algorithm" in all material mentioning or referencing this software
  13. or this function.
  14. License is also granted to make and use derivative works provided
  15. that such works are identified as "derived from the RSA Data
  16. Security, Inc. MD5 Message-Digest Algorithm" in all material
  17. mentioning or referencing the derived work.
  18. RSA Data Security, Inc. makes no representations concerning either
  19. the merchantability of this software or the suitability of this
  20. software for any particular purpose. It is provided "as is"
  21. without express or implied warranty of any kind.
  22. These notices must be retained in any copies of any part of this
  23. documentation and/or software.
  24. }
  25. { Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  26. * applicable.
  27. *
  28. * Licensed under the Apache License, Version 2.0 (the "License");
  29. * you may not use this file except in compliance with the License.
  30. * You may obtain a copy of the License at
  31. *
  32. * http://www.apache.org/licenses/LICENSE-2.0
  33. *
  34. * Unless required by applicable law or agreed to in writing, software
  35. * distributed under the License is distributed on an "AS IS" BASIS,
  36. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  37. * See the License for the specific language governing permissions and
  38. * limitations under the License.
  39. }
  40. {#include "apu.h"}
  41. {$include apr_xlate.inc}
  42. {
  43. * @file apr_md5.h
  44. * @brief APR MD5 Routines
  45. }
  46. {
  47. * @defgroup APR_MD5 MD5 Routines
  48. * @ingroup APR
  49. }
  50. const
  51. { The MD5 digest size }
  52. APR_MD5_DIGESTSIZE = 16;
  53. { @see apr_md5_ctx_t }
  54. type
  55. TDigestArray = array [0..APR_MD5_DIGESTSIZE] of Char;
  56. Papr_md5_ctx_t = ^apr_md5_ctx_t;
  57. { MD5 context. }
  58. apr_md5_ctx_t = record
  59. { state (ABCD) }
  60. state: array [1..4] of apr_uint32_t;
  61. { number of bits, modulo 2^64 (lsb first) }
  62. count: array [1..2] of apr_uint32_t;
  63. { input buffer }
  64. buffer: array [1..64] of Char;
  65. { translation handle
  66. * ignored if xlate is unsupported
  67. }
  68. xlate: Papr_xlate_t;
  69. end;
  70. {
  71. * MD5 Initialize. Begins an MD5 operation, writing a new context.
  72. * @param context The MD5 context to initialize.
  73. }
  74. function apr_md5_init(context: Papr_md5_ctx_t): apr_status_t;
  75. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  76. external LibAPRUtil name LibNamePrefix + 'apr_md5_init' + LibSuff4;
  77. {
  78. * MD5 translation setup. Provides the APR translation handle to be used
  79. * for translating the content before calculating the digest.
  80. * @param context The MD5 content to set the translation for.
  81. * @param xlate The translation handle to use for this MD5 context
  82. }
  83. function apr_md5_set_xlate(context: Papr_md5_ctx_t;
  84. xlate: Papr_xlate_t): apr_status_t;
  85. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  86. external LibAPRUtil name LibNamePrefix + 'apr_md5_set_xlate' + LibSuff8;
  87. {
  88. * MD5 block update operation. Continue an MD5 message-digest operation,
  89. * processing another message block, and updating the context.
  90. * @param context The MD5 content to update.
  91. * @param input next message block to update
  92. * @param inputLen The length of the next message block
  93. }
  94. function apr_md5_update(context: Papr_md5_ctx_t;
  95. input: Pointer; inputLen: apr_size_t): apr_status_t;
  96. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  97. external LibAPRUtil name LibNamePrefix + 'apr_md5_update' + LibSuff12;
  98. {
  99. * MD5 finalization. Ends an MD5 message-digest operation, writing the
  100. * message digest and zeroing the context
  101. * @param digest The final MD5 digest
  102. * @param context The MD5 content we are finalizing.
  103. }
  104. function apr_md5_final(digest: TDigestArray;
  105. context: Papr_md5_ctx_t): apr_status_t;
  106. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  107. external LibAPRUtil name LibNamePrefix + 'apr_md5_final' + LibSuff8;
  108. {
  109. * MD5 in one step
  110. * @param digest The final MD5 digest
  111. * @param input The message block to use
  112. * @param inputLen The length of the message block
  113. }
  114. function apr_md5(digest: TDigestArray;
  115. input: Pointer; inputLen: apr_size_t): apr_status_t;
  116. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  117. external LibAPRUtil name LibNamePrefix + 'apr_md5' + LibSuff12;
  118. {
  119. * Encode a password using an MD5 algorithm
  120. * @param password The password to encode
  121. * @param salt The salt to use for the encoding
  122. * @param result The string to store the encoded password in
  123. * @param nbytes The length of the string
  124. }
  125. function apr_md5_encode(const password, salt: PChar;
  126. result: PChar; nbytes: apr_size_t): apr_status_t;
  127. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  128. external LibAPRUtil name LibNamePrefix + 'apr_md5_encode' + LibSuff16;
  129. {
  130. * Validate hashes created by APR-supported algorithms: md5 and sha1.
  131. * hashes created by crypt are supported only on platforms that provide
  132. * crypt(3), so don't rely on that function unless you know that your
  133. * application will be run only on platforms that support it. On platforms
  134. * that don't support crypt(3), this falls back to a clear text string
  135. * comparison.
  136. * @param passwd The password to validate
  137. * @param hash The password to validate against
  138. }
  139. function apr_password_validate(const passwd, hash: PChar): apr_status_t;
  140. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  141. external LibAPRUtil name LibNamePrefix + 'apr_password_validate' + LibSuff8;