apr_md5.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. /* Licensed to the Apache Software Foundation (ASF) under one or more
  26. * contributor license agreements. See the NOTICE file distributed with
  27. * this work for additional information regarding copyright ownership.
  28. * The ASF licenses this file to You under the Apache License, Version 2.0
  29. * (the "License"); you may not use this file except in compliance with
  30. * the License. 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. #ifndef APR_MD5_H
  41. #define APR_MD5_H
  42. #include "apu.h"
  43. #include "apr_xlate.h"
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /**
  48. * @file apr_md5.h
  49. * @brief APR MD5 Routines
  50. */
  51. /**
  52. * @defgroup APR_MD5 MD5 Routines
  53. * @ingroup APR
  54. * @{
  55. */
  56. /** The MD5 digest size */
  57. #define APR_MD5_DIGESTSIZE 16
  58. /** @see apr_md5_ctx_t */
  59. typedef struct apr_md5_ctx_t apr_md5_ctx_t;
  60. /** MD5 context. */
  61. struct apr_md5_ctx_t {
  62. /** state (ABCD) */
  63. apr_uint32_t state[4];
  64. /** number of bits, modulo 2^64 (lsb first) */
  65. apr_uint32_t count[2];
  66. /** input buffer */
  67. unsigned char buffer[64];
  68. /** translation handle
  69. * ignored if xlate is unsupported
  70. */
  71. apr_xlate_t *xlate;
  72. };
  73. /**
  74. * MD5 Initialize. Begins an MD5 operation, writing a new context.
  75. * @param context The MD5 context to initialize.
  76. */
  77. APU_DECLARE(apr_status_t) apr_md5_init(apr_md5_ctx_t *context);
  78. /**
  79. * MD5 translation setup. Provides the APR translation handle to be used
  80. * for translating the content before calculating the digest.
  81. * @param context The MD5 content to set the translation for.
  82. * @param xlate The translation handle to use for this MD5 context
  83. */
  84. APU_DECLARE(apr_status_t) apr_md5_set_xlate(apr_md5_ctx_t *context,
  85. apr_xlate_t *xlate);
  86. /**
  87. * MD5 block update operation. Continue an MD5 message-digest operation,
  88. * processing another message block, and updating the context.
  89. * @param context The MD5 content to update.
  90. * @param input next message block to update
  91. * @param inputLen The length of the next message block
  92. */
  93. APU_DECLARE(apr_status_t) apr_md5_update(apr_md5_ctx_t *context,
  94. const void *input,
  95. apr_size_t inputLen);
  96. /**
  97. * MD5 finalization. Ends an MD5 message-digest operation, writing the
  98. * message digest and zeroing the context
  99. * @param digest The final MD5 digest
  100. * @param context The MD5 content we are finalizing.
  101. */
  102. APU_DECLARE(apr_status_t) apr_md5_final(unsigned char digest[APR_MD5_DIGESTSIZE],
  103. apr_md5_ctx_t *context);
  104. /**
  105. * MD5 in one step
  106. * @param digest The final MD5 digest
  107. * @param input The message block to use
  108. * @param inputLen The length of the message block
  109. */
  110. APU_DECLARE(apr_status_t) apr_md5(unsigned char digest[APR_MD5_DIGESTSIZE],
  111. const void *input,
  112. apr_size_t inputLen);
  113. /**
  114. * Encode a password using an MD5 algorithm
  115. * @param password The password to encode
  116. * @param salt The salt string to use for the encoding
  117. * @param result The string to store the encoded password in
  118. * @param nbytes The size of the result buffer
  119. */
  120. APU_DECLARE(apr_status_t) apr_md5_encode(const char *password, const char *salt,
  121. char *result, apr_size_t nbytes);
  122. /**
  123. * Encode a password using the bcrypt algorithm
  124. * @param password The password to encode
  125. * @param count The cost of the encoding, possible values are 4 to 31
  126. * @param salt Pointer to binary data to be used as salt for the encoding
  127. * @param salt_len The size of the salt data (must be >= 16)
  128. * @param out The string to store the encoded password in
  129. * @param out_len The size of the result buffer (must be >= 61)
  130. */
  131. APU_DECLARE(apr_status_t) apr_bcrypt_encode(const char *pw,
  132. unsigned int count,
  133. const unsigned char *salt,
  134. apr_size_t salt_len,
  135. char *out, apr_size_t out_len);
  136. /**
  137. * Validate hashes created by APR-supported algorithms: md5, bcrypt, and sha1.
  138. * hashes created by crypt are supported only on platforms that provide
  139. * crypt(3), so don't rely on that function unless you know that your
  140. * application will be run only on platforms that support it. On platforms
  141. * that don't support crypt(3), this falls back to a clear text string
  142. * comparison.
  143. * @param passwd The password to validate
  144. * @param hash The password to validate against
  145. */
  146. APU_DECLARE(apr_status_t) apr_password_validate(const char *passwd,
  147. const char *hash);
  148. /** @} */
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif /* !APR_MD5_H */