00001 /* 00002 * This is work is derived from material Copyright RSA Data Security, Inc. 00003 * 00004 * The RSA copyright statement and Licence for that original material is 00005 * included below. This is followed by the Apache copyright statement and 00006 * licence for the modifications made to that material. 00007 */ 00008 00009 /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All 00010 rights reserved. 00011 00012 License to copy and use this software is granted provided that it 00013 is identified as the "RSA Data Security, Inc. MD5 Message-Digest 00014 Algorithm" in all material mentioning or referencing this software 00015 or this function. 00016 00017 License is also granted to make and use derivative works provided 00018 that such works are identified as "derived from the RSA Data 00019 Security, Inc. MD5 Message-Digest Algorithm" in all material 00020 mentioning or referencing the derived work. 00021 00022 RSA Data Security, Inc. makes no representations concerning either 00023 the merchantability of this software or the suitability of this 00024 software for any particular purpose. It is provided "as is" 00025 without express or implied warranty of any kind. 00026 00027 These notices must be retained in any copies of any part of this 00028 documentation and/or software. 00029 */ 00030 00031 /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as 00032 * applicable. 00033 * 00034 * Licensed under the Apache License, Version 2.0 (the "License"); 00035 * you may not use this file except in compliance with the License. 00036 * You may obtain a copy of the License at 00037 * 00038 * http://www.apache.org/licenses/LICENSE-2.0 00039 * 00040 * Unless required by applicable law or agreed to in writing, software 00041 * distributed under the License is distributed on an "AS IS" BASIS, 00042 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00043 * See the License for the specific language governing permissions and 00044 * limitations under the License. 00045 */ 00046 00047 #ifndef APR_MD5_H 00048 #define APR_MD5_H 00049 00050 #include "apu.h" 00051 #include "apr_xlate.h" 00052 00053 #ifdef __cplusplus 00054 extern "C" { 00055 #endif 00056 /** 00057 * @file apr_md5.h 00058 * @brief APR MD5 Routines 00059 */ 00060 00061 /** 00062 * @defgroup APR_MD5 MD5 Routines 00063 * @ingroup APR 00064 * @{ 00065 */ 00066 00067 /** The MD5 digest size */ 00068 #define APR_MD5_DIGESTSIZE 16 00069 00070 /** @see apr_md5_ctx_t */ 00071 typedef struct apr_md5_ctx_t apr_md5_ctx_t; 00072 00073 /** MD5 context. */ 00074 struct apr_md5_ctx_t { 00075 /** state (ABCD) */ 00076 apr_uint32_t state[4]; 00077 /** number of bits, modulo 2^64 (lsb first) */ 00078 apr_uint32_t count[2]; 00079 /** input buffer */ 00080 unsigned char buffer[64]; 00081 /** translation handle 00082 * ignored if xlate is unsupported 00083 */ 00084 apr_xlate_t *xlate; 00085 }; 00086 00087 /** 00088 * MD5 Initialize. Begins an MD5 operation, writing a new context. 00089 * @param context The MD5 context to initialize. 00090 */ 00091 APU_DECLARE(apr_status_t) apr_md5_init(apr_md5_ctx_t *context); 00092 00093 /** 00094 * MD5 translation setup. Provides the APR translation handle to be used 00095 * for translating the content before calculating the digest. 00096 * @param context The MD5 content to set the translation for. 00097 * @param xlate The translation handle to use for this MD5 context 00098 */ 00099 APU_DECLARE(apr_status_t) apr_md5_set_xlate(apr_md5_ctx_t *context, 00100 apr_xlate_t *xlate); 00101 00102 /** 00103 * MD5 block update operation. Continue an MD5 message-digest operation, 00104 * processing another message block, and updating the context. 00105 * @param context The MD5 content to update. 00106 * @param input next message block to update 00107 * @param inputLen The length of the next message block 00108 */ 00109 APU_DECLARE(apr_status_t) apr_md5_update(apr_md5_ctx_t *context, 00110 const void *input, 00111 apr_size_t inputLen); 00112 00113 /** 00114 * MD5 finalization. Ends an MD5 message-digest operation, writing the 00115 * message digest and zeroing the context 00116 * @param digest The final MD5 digest 00117 * @param context The MD5 content we are finalizing. 00118 */ 00119 APU_DECLARE(apr_status_t) apr_md5_final(unsigned char digest[APR_MD5_DIGESTSIZE], 00120 apr_md5_ctx_t *context); 00121 00122 /** 00123 * MD5 in one step 00124 * @param digest The final MD5 digest 00125 * @param input The message block to use 00126 * @param inputLen The length of the message block 00127 */ 00128 APU_DECLARE(apr_status_t) apr_md5(unsigned char digest[APR_MD5_DIGESTSIZE], 00129 const void *input, 00130 apr_size_t inputLen); 00131 00132 /** 00133 * Encode a password using an MD5 algorithm 00134 * @param password The password to encode 00135 * @param salt The salt to use for the encoding 00136 * @param result The string to store the encoded password in 00137 * @param nbytes The size of the result buffer 00138 */ 00139 APU_DECLARE(apr_status_t) apr_md5_encode(const char *password, const char *salt, 00140 char *result, apr_size_t nbytes); 00141 00142 00143 /** 00144 * Validate hashes created by APR-supported algorithms: md5 and sha1. 00145 * hashes created by crypt are supported only on platforms that provide 00146 * crypt(3), so don't rely on that function unless you know that your 00147 * application will be run only on platforms that support it. On platforms 00148 * that don't support crypt(3), this falls back to a clear text string 00149 * comparison. 00150 * @param passwd The password to validate 00151 * @param hash The password to validate against 00152 */ 00153 APU_DECLARE(apr_status_t) apr_password_validate(const char *passwd, 00154 const char *hash); 00155 00156 00157 /** @} */ 00158 #ifdef __cplusplus 00159 } 00160 #endif 00161 00162 #endif /* !APR_MD5_H */