| 
									
										
										
										
											2016-05-18 02:52:22 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2020-04-23 20:55:52 +08:00
										 |  |  |  * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											1998-12-21 18:56:39 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-12-06 20:44:44 +08:00
										 |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							| 
									
										
										
										
											2016-05-18 02:52:22 +08:00
										 |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							| 
									
										
										
										
											1998-12-21 18:56:39 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-15 09:13:03 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * MD5 low level APIs are deprecated for public use, but still ok for | 
					
						
							|  |  |  |  * internal use. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #include "internal/deprecated.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-12-21 18:56:39 +08:00
										 |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											1999-05-13 21:16:42 +08:00
										 |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <openssl/md5.h>
 | 
					
						
							| 
									
										
										
										
											2002-12-03 22:20:44 +08:00
										 |  |  | #include <openssl/crypto.h>
 | 
					
						
							| 
									
										
										
										
											1998-12-21 18:56:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-06-05 05:35:58 +08:00
										 |  |  | #ifdef CHARSET_EBCDIC
 | 
					
						
							|  |  |  | # include <openssl/ebcdic.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-05-15 19:29:55 +08:00
										 |  |  | unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md) | 
					
						
							| 
									
										
										
										
											1998-12-21 18:56:39 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     MD5_CTX c; | 
					
						
							|  |  |  |     static unsigned char m[MD5_DIGEST_LENGTH]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (md == NULL) | 
					
						
							|  |  |  |         md = m; | 
					
						
							| 
									
										
										
										
											2005-04-15 06:58:44 +08:00
										 |  |  |     if (!MD5_Init(&c)) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											1999-06-05 05:35:58 +08:00
										 |  |  | #ifndef CHARSET_EBCDIC
 | 
					
						
							| 
									
										
										
										
											1998-12-21 18:56:39 +08:00
										 |  |  |     MD5_Update(&c, d, n); | 
					
						
							| 
									
										
										
										
											1999-06-05 05:35:58 +08:00
										 |  |  | #else
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         char temp[1024]; | 
					
						
							|  |  |  |         unsigned long chunk; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         while (n > 0) { | 
					
						
							|  |  |  |             chunk = (n > sizeof(temp)) ? sizeof(temp) : n; | 
					
						
							|  |  |  |             ebcdic2ascii(temp, d, chunk); | 
					
						
							|  |  |  |             MD5_Update(&c, temp, chunk); | 
					
						
							|  |  |  |             n -= chunk; | 
					
						
							|  |  |  |             d += chunk; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											1998-12-21 18:56:39 +08:00
										 |  |  |     MD5_Final(md, &c); | 
					
						
							| 
									
										
										
										
											2002-11-29 19:30:45 +08:00
										 |  |  |     OPENSSL_cleanse(&c, sizeof(c)); /* security consideration */ | 
					
						
							| 
									
										
										
										
											2017-10-17 22:04:09 +08:00
										 |  |  |     return md; | 
					
						
							| 
									
										
										
										
											1998-12-21 18:56:39 +08:00
										 |  |  | } |