md5.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2016, Daniel Stenberg, <[email protected]>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "curl_setup.h"
  23. #ifndef CURL_DISABLE_CRYPTO_AUTH
  24. #include <curl/curl.h>
  25. #include "curl_md5.h"
  26. #include "curl_hmac.h"
  27. #include "warnless.h"
  28. #if defined(USE_GNUTLS_NETTLE)
  29. #include <nettle/md5.h>
  30. #include "curl_memory.h"
  31. /* The last #include file should be: */
  32. #include "memdebug.h"
  33. typedef struct md5_ctx MD5_CTX;
  34. static void MD5_Init(MD5_CTX * ctx)
  35. {
  36. md5_init(ctx);
  37. }
  38. static void MD5_Update(MD5_CTX * ctx,
  39. const unsigned char *input,
  40. unsigned int inputLen)
  41. {
  42. md5_update(ctx, inputLen, input);
  43. }
  44. static void MD5_Final(unsigned char digest[16], MD5_CTX * ctx)
  45. {
  46. md5_digest(ctx, 16, digest);
  47. }
  48. #elif defined(USE_GNUTLS)
  49. #include <gcrypt.h>
  50. #include "curl_memory.h"
  51. /* The last #include file should be: */
  52. #include "memdebug.h"
  53. typedef gcry_md_hd_t MD5_CTX;
  54. static void MD5_Init(MD5_CTX * ctx)
  55. {
  56. gcry_md_open(ctx, GCRY_MD_MD5, 0);
  57. }
  58. static void MD5_Update(MD5_CTX * ctx,
  59. const unsigned char *input,
  60. unsigned int inputLen)
  61. {
  62. gcry_md_write(*ctx, input, inputLen);
  63. }
  64. static void MD5_Final(unsigned char digest[16], MD5_CTX * ctx)
  65. {
  66. memcpy(digest, gcry_md_read(*ctx, 0), 16);
  67. gcry_md_close(*ctx);
  68. }
  69. #elif defined(USE_OPENSSL)
  70. /* When OpenSSL is available we use the MD5-function from OpenSSL */
  71. #include <openssl/md5.h>
  72. #include "curl_memory.h"
  73. /* The last #include file should be: */
  74. #include "memdebug.h"
  75. #elif (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && \
  76. (__MAC_OS_X_VERSION_MAX_ALLOWED >= 1040)) || \
  77. (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \
  78. (__IPHONE_OS_VERSION_MAX_ALLOWED >= 20000))
  79. /* For Apple operating systems: CommonCrypto has the functions we need.
  80. These functions are available on Tiger and later, as well as iOS 2.0
  81. and later. If you're building for an older cat, well, sorry.
  82. Declaring the functions as static like this seems to be a bit more
  83. reliable than defining COMMON_DIGEST_FOR_OPENSSL on older cats. */
  84. # include <CommonCrypto/CommonDigest.h>
  85. # define MD5_CTX CC_MD5_CTX
  86. #include "curl_memory.h"
  87. /* The last #include file should be: */
  88. #include "memdebug.h"
  89. static void MD5_Init(MD5_CTX *ctx)
  90. {
  91. CC_MD5_Init(ctx);
  92. }
  93. static void MD5_Update(MD5_CTX *ctx,
  94. const unsigned char *input,
  95. unsigned int inputLen)
  96. {
  97. CC_MD5_Update(ctx, input, inputLen);
  98. }
  99. static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
  100. {
  101. CC_MD5_Final(digest, ctx);
  102. }
  103. #elif defined(_WIN32) && !defined(CURL_WINDOWS_APP)
  104. #include <wincrypt.h>
  105. #include "curl_memory.h"
  106. /* The last #include file should be: */
  107. #include "memdebug.h"
  108. typedef struct {
  109. HCRYPTPROV hCryptProv;
  110. HCRYPTHASH hHash;
  111. } MD5_CTX;
  112. static void MD5_Init(MD5_CTX *ctx)
  113. {
  114. if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL,
  115. PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
  116. CryptCreateHash(ctx->hCryptProv, CALG_MD5, 0, 0, &ctx->hHash);
  117. }
  118. }
  119. static void MD5_Update(MD5_CTX *ctx,
  120. const unsigned char *input,
  121. unsigned int inputLen)
  122. {
  123. CryptHashData(ctx->hHash, (unsigned char *)input, inputLen, 0);
  124. }
  125. static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
  126. {
  127. unsigned long length = 0;
  128. CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0);
  129. if(length == 16)
  130. CryptGetHashParam(ctx->hHash, HP_HASHVAL, digest, &length, 0);
  131. if(ctx->hHash)
  132. CryptDestroyHash(ctx->hHash);
  133. if(ctx->hCryptProv)
  134. CryptReleaseContext(ctx->hCryptProv, 0);
  135. }
  136. #elif defined(USE_AXTLS)
  137. #include <axTLS/config.h>
  138. #include <axTLS/os_int.h>
  139. #include <axTLS/crypto.h>
  140. #include "curl_memory.h"
  141. /* The last #include file should be: */
  142. #include "memdebug.h"
  143. #else
  144. /* When no other crypto library is available we use this code segment */
  145. /*
  146. * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
  147. * MD5 Message-Digest Algorithm (RFC 1321).
  148. *
  149. * Homepage:
  150. http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
  151. *
  152. * Author:
  153. * Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
  154. *
  155. * This software was written by Alexander Peslyak in 2001. No copyright is
  156. * claimed, and the software is hereby placed in the public domain.
  157. * In case this attempt to disclaim copyright and place the software in the
  158. * public domain is deemed null and void, then the software is
  159. * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
  160. * general public under the following terms:
  161. *
  162. * Redistribution and use in source and binary forms, with or without
  163. * modification, are permitted.
  164. *
  165. * There's ABSOLUTELY NO WARRANTY, express or implied.
  166. *
  167. * (This is a heavily cut-down "BSD license".)
  168. *
  169. * This differs from Colin Plumb's older public domain implementation in that
  170. * no exactly 32-bit integer data type is required (any 32-bit or wider
  171. * unsigned integer data type will do), there's no compile-time endianness
  172. * configuration, and the function prototypes match OpenSSL's. No code from
  173. * Colin Plumb's implementation has been reused; this comment merely compares
  174. * the properties of the two independent implementations.
  175. *
  176. * The primary goals of this implementation are portability and ease of use.
  177. * It is meant to be fast, but not as fast as possible. Some known
  178. * optimizations are not included to reduce source code size and avoid
  179. * compile-time configuration.
  180. */
  181. #include <string.h>
  182. /* The last #include files should be: */
  183. #include "curl_memory.h"
  184. #include "memdebug.h"
  185. /* Any 32-bit or wider unsigned integer data type will do */
  186. typedef unsigned int MD5_u32plus;
  187. typedef struct {
  188. MD5_u32plus lo, hi;
  189. MD5_u32plus a, b, c, d;
  190. unsigned char buffer[64];
  191. MD5_u32plus block[16];
  192. } MD5_CTX;
  193. static void MD5_Init(MD5_CTX *ctx);
  194. static void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size);
  195. static void MD5_Final(unsigned char *result, MD5_CTX *ctx);
  196. /*
  197. * The basic MD5 functions.
  198. *
  199. * F and G are optimized compared to their RFC 1321 definitions for
  200. * architectures that lack an AND-NOT instruction, just like in Colin Plumb's
  201. * implementation.
  202. */
  203. #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
  204. #define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
  205. #define H(x, y, z) (((x) ^ (y)) ^ (z))
  206. #define H2(x, y, z) ((x) ^ ((y) ^ (z)))
  207. #define I(x, y, z) ((y) ^ ((x) | ~(z)))
  208. /*
  209. * The MD5 transformation for all four rounds.
  210. */
  211. #define STEP(f, a, b, c, d, x, t, s) \
  212. (a) += f((b), (c), (d)) + (x) + (t); \
  213. (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
  214. (a) += (b);
  215. /*
  216. * SET reads 4 input bytes in little-endian byte order and stores them
  217. * in a properly aligned word in host byte order.
  218. *
  219. * The check for little-endian architectures that tolerate unaligned
  220. * memory accesses is just an optimization. Nothing will break if it
  221. * doesn't work.
  222. */
  223. #if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
  224. #define SET(n) \
  225. (*(MD5_u32plus *)&ptr[(n) * 4])
  226. #define GET(n) \
  227. SET(n)
  228. #else
  229. #define SET(n) \
  230. (ctx->block[(n)] = \
  231. (MD5_u32plus)ptr[(n) * 4] | \
  232. ((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
  233. ((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
  234. ((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
  235. #define GET(n) \
  236. (ctx->block[(n)])
  237. #endif
  238. /*
  239. * This processes one or more 64-byte data blocks, but does NOT update
  240. * the bit counters. There are no alignment requirements.
  241. */
  242. static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
  243. {
  244. const unsigned char *ptr;
  245. MD5_u32plus a, b, c, d;
  246. MD5_u32plus saved_a, saved_b, saved_c, saved_d;
  247. ptr = (const unsigned char *)data;
  248. a = ctx->a;
  249. b = ctx->b;
  250. c = ctx->c;
  251. d = ctx->d;
  252. do {
  253. saved_a = a;
  254. saved_b = b;
  255. saved_c = c;
  256. saved_d = d;
  257. /* Round 1 */
  258. STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
  259. STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
  260. STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
  261. STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
  262. STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
  263. STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
  264. STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
  265. STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
  266. STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
  267. STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
  268. STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
  269. STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
  270. STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
  271. STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
  272. STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
  273. STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
  274. /* Round 2 */
  275. STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
  276. STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
  277. STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
  278. STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
  279. STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
  280. STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
  281. STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
  282. STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
  283. STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
  284. STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
  285. STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
  286. STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
  287. STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
  288. STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
  289. STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
  290. STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
  291. /* Round 3 */
  292. STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
  293. STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11)
  294. STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
  295. STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23)
  296. STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
  297. STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11)
  298. STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
  299. STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23)
  300. STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
  301. STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11)
  302. STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
  303. STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23)
  304. STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
  305. STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11)
  306. STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
  307. STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23)
  308. /* Round 4 */
  309. STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
  310. STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
  311. STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
  312. STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
  313. STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
  314. STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
  315. STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
  316. STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
  317. STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
  318. STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
  319. STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
  320. STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
  321. STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
  322. STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
  323. STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
  324. STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
  325. a += saved_a;
  326. b += saved_b;
  327. c += saved_c;
  328. d += saved_d;
  329. ptr += 64;
  330. } while(size -= 64);
  331. ctx->a = a;
  332. ctx->b = b;
  333. ctx->c = c;
  334. ctx->d = d;
  335. return ptr;
  336. }
  337. static void MD5_Init(MD5_CTX *ctx)
  338. {
  339. ctx->a = 0x67452301;
  340. ctx->b = 0xefcdab89;
  341. ctx->c = 0x98badcfe;
  342. ctx->d = 0x10325476;
  343. ctx->lo = 0;
  344. ctx->hi = 0;
  345. }
  346. static void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
  347. {
  348. MD5_u32plus saved_lo;
  349. unsigned long used, available;
  350. saved_lo = ctx->lo;
  351. ctx->lo = (saved_lo + size) & 0x1fffffff;
  352. if(ctx->lo < saved_lo)
  353. ctx->hi++;
  354. ctx->hi += (MD5_u32plus)size >> 29;
  355. used = saved_lo & 0x3f;
  356. if(used) {
  357. available = 64 - used;
  358. if(size < available) {
  359. memcpy(&ctx->buffer[used], data, size);
  360. return;
  361. }
  362. memcpy(&ctx->buffer[used], data, available);
  363. data = (const unsigned char *)data + available;
  364. size -= available;
  365. body(ctx, ctx->buffer, 64);
  366. }
  367. if(size >= 64) {
  368. data = body(ctx, data, size & ~(unsigned long)0x3f);
  369. size &= 0x3f;
  370. }
  371. memcpy(ctx->buffer, data, size);
  372. }
  373. static void MD5_Final(unsigned char *result, MD5_CTX *ctx)
  374. {
  375. unsigned long used, available;
  376. used = ctx->lo & 0x3f;
  377. ctx->buffer[used++] = 0x80;
  378. available = 64 - used;
  379. if(available < 8) {
  380. memset(&ctx->buffer[used], 0, available);
  381. body(ctx, ctx->buffer, 64);
  382. used = 0;
  383. available = 64;
  384. }
  385. memset(&ctx->buffer[used], 0, available - 8);
  386. ctx->lo <<= 3;
  387. ctx->buffer[56] = curlx_ultouc((ctx->lo)&0xff);
  388. ctx->buffer[57] = curlx_ultouc((ctx->lo >> 8)&0xff);
  389. ctx->buffer[58] = curlx_ultouc((ctx->lo >> 16)&0xff);
  390. ctx->buffer[59] = curlx_ultouc(ctx->lo >> 24);
  391. ctx->buffer[60] = curlx_ultouc((ctx->hi)&0xff);
  392. ctx->buffer[61] = curlx_ultouc((ctx->hi >> 8)&0xff);
  393. ctx->buffer[62] = curlx_ultouc((ctx->hi >> 16)&0xff);
  394. ctx->buffer[63] = curlx_ultouc(ctx->hi >> 24);
  395. body(ctx, ctx->buffer, 64);
  396. result[0] = curlx_ultouc((ctx->a)&0xff);
  397. result[1] = curlx_ultouc((ctx->a >> 8)&0xff);
  398. result[2] = curlx_ultouc((ctx->a >> 16)&0xff);
  399. result[3] = curlx_ultouc(ctx->a >> 24);
  400. result[4] = curlx_ultouc((ctx->b)&0xff);
  401. result[5] = curlx_ultouc((ctx->b >> 8)&0xff);
  402. result[6] = curlx_ultouc((ctx->b >> 16)&0xff);
  403. result[7] = curlx_ultouc(ctx->b >> 24);
  404. result[8] = curlx_ultouc((ctx->c)&0xff);
  405. result[9] = curlx_ultouc((ctx->c >> 8)&0xff);
  406. result[10] = curlx_ultouc((ctx->c >> 16)&0xff);
  407. result[11] = curlx_ultouc(ctx->c >> 24);
  408. result[12] = curlx_ultouc((ctx->d)&0xff);
  409. result[13] = curlx_ultouc((ctx->d >> 8)&0xff);
  410. result[14] = curlx_ultouc((ctx->d >> 16)&0xff);
  411. result[15] = curlx_ultouc(ctx->d >> 24);
  412. memset(ctx, 0, sizeof(*ctx));
  413. }
  414. #endif /* CRYPTO LIBS */
  415. const HMAC_params Curl_HMAC_MD5[] = {
  416. {
  417. (HMAC_hinit_func) MD5_Init, /* Hash initialization function. */
  418. (HMAC_hupdate_func) MD5_Update, /* Hash update function. */
  419. (HMAC_hfinal_func) MD5_Final, /* Hash computation end function. */
  420. sizeof(MD5_CTX), /* Size of hash context structure. */
  421. 64, /* Maximum key length. */
  422. 16 /* Result size. */
  423. }
  424. };
  425. const MD5_params Curl_DIGEST_MD5[] = {
  426. {
  427. (Curl_MD5_init_func) MD5_Init, /* Digest initialization function */
  428. (Curl_MD5_update_func) MD5_Update, /* Digest update function */
  429. (Curl_MD5_final_func) MD5_Final, /* Digest computation end function */
  430. sizeof(MD5_CTX), /* Size of digest context struct */
  431. 16 /* Result size */
  432. }
  433. };
  434. /*
  435. * @unittest: 1601
  436. */
  437. void Curl_md5it(unsigned char *outbuffer, /* 16 bytes */
  438. const unsigned char *input)
  439. {
  440. MD5_CTX ctx;
  441. MD5_Init(&ctx);
  442. MD5_Update(&ctx, input, curlx_uztoui(strlen((char *)input)));
  443. MD5_Final(outbuffer, &ctx);
  444. }
  445. MD5_context *Curl_MD5_init(const MD5_params *md5params)
  446. {
  447. MD5_context *ctxt;
  448. /* Create MD5 context */
  449. ctxt = malloc(sizeof *ctxt);
  450. if(!ctxt)
  451. return ctxt;
  452. ctxt->md5_hashctx = malloc(md5params->md5_ctxtsize);
  453. if(!ctxt->md5_hashctx) {
  454. free(ctxt);
  455. return NULL;
  456. }
  457. ctxt->md5_hash = md5params;
  458. (*md5params->md5_init_func)(ctxt->md5_hashctx);
  459. return ctxt;
  460. }
  461. int Curl_MD5_update(MD5_context *context,
  462. const unsigned char *data,
  463. unsigned int len)
  464. {
  465. (*context->md5_hash->md5_update_func)(context->md5_hashctx, data, len);
  466. return 0;
  467. }
  468. int Curl_MD5_final(MD5_context *context, unsigned char *result)
  469. {
  470. (*context->md5_hash->md5_final_func)(result, context->md5_hashctx);
  471. free(context->md5_hashctx);
  472. free(context);
  473. return 0;
  474. }
  475. #endif /* CURL_DISABLE_CRYPTO_AUTH */