XFER_UDMA_7, XFER_UDMA_6, XFER_UDMA_5, XFER_UDMA_4, XFER_UDMA_3, XFER_UDMA_2, XFER_UDMA_1, XFER_UDMA_0, XFER_MW_DMA_4, XFER_MW_DMA_3, XFER_MW_DMA_2, XFER_MW_DMA_1, XFER_MW_DMA_0, XFER_SW_DMA_2, XFER_SW_DMA_1, XFER_SW_DMA_0, XFER_PIO_6, XFER_PIO_5, XFER_PIO_4, XFER_PIO_3, XFER_PIO_2, XFER_PIO_1, XFER_PIO_0
     ˆÅÆ„¿ÄÁÈ *›    /*
   +----------------------------------------------------------------------+
   | PHP Version 5                                                        |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2016 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 3.01 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available through the world-wide-web at the following url:           |
   | http://www.php.net/license/3_01.txt                                  |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | license@php.net so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: Alexander Peslyak (Solar Designer) <solar at openwall.com>   |
   |         Lachlan Roche                                                |
   |         Alessandro Astarita <aleast@capri.it>                        |
   +----------------------------------------------------------------------+
*/

/* $Id$ */

#include "php.h"
#include "md5.h"

PHPAPI void make_digest(char *md5str, const unsigned char *digest) /* {{{ */
{
	make_digest_ex(md5str, digest, 16);
}
/* }}} */

PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, int len) /* {{{ */
{
	static const char hexits[17] = "0123456789abcdef";
	int i;

	for (i = 0; i < len; i++) {
		md5str[i * 2]       = hexits[digest[i] >> 4];
		md5str[(i * 2) + 1] = hexits[digest[i] &  0x0F];
	}
	md5str[len * 2] = '\0';
}
/* }}} */

/* {{{ proto string md5(string str, [ bool raw_output])
   Calculate the md5 hash of a string */
PHP_NAMED_FUNCTION(php_if_md5)
{
	char *arg;
	int arg_len;
	zend_bool raw_output = 0;
	char md5str[33];
	PHP_MD5_CTX context;
	unsigned char digest[16];
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) {
		return;
	}
	
	md5str[0] = '\0';
	PHP_MD5Init(&context);
	PHP_MD5Update(&context, arg, arg_len);
	PHP_MD5Final(digest, &context);
	if (raw_output) {
		RETURN_STRINGL(digest, 16, 1);
	} else {
		make_digest_ex(md5str, digest, 16);
		RETVAL_STRING(md5str, 1);
	}

}
/* }}} */

/* {{{ proto string md5_file(string filename [, bool raw_output])
   Calculate the md5 hash of given filename */
PHP_NAMED_FUNCTION(php_if_md5_file)
{
	char          *arg;
	int           arg_len;
	zend_bool raw_output = 0;
	char          md5str[33];
	unsigned char buf[1024];
	unsigned char digest[16];
	PHP_MD5_CTX   context;
	int           n;
	php_stream    *stream;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|b", &arg, &arg_len, &raw_output) == FAILURE) {
		return;
	}
	
	stream = php_stream_open_wrapper(arg, "rb", REPORT_ERRORS, NULL);
	if (!stream) {
		RETURN_FALSE;
	}

	PHP_MD5Init(&context);

	while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
		PHP_MD5Update(&context, buf, n);
	}

	PHP_MD5Final(digest, &context);

	php_stream_close(stream);

	if (n<0) {
		RETURN_FALSE;
	}

	if (raw_output) {
		RETURN_STRINGL(digest, 16, 1);
	} else {
		make_digest_ex(md5str, digest, 16);
		RETVAL_STRING(md5str, 1);
	}
}
/* }}} */

/*
 * This is an OpenSSL-compatible implementation of the RSA Data Security,
 * Inc. MD5 Message-Digest Algorithm (RFC 1321).
 *
 * Written by Solar Designer <solar at openwall.com> in 2001, and placed
 * in the public domain.  There's absolutely no warranty.
 *
 * This differs from Colin Plumb's older public domain implementation in
 * that no 32-bit integer data type i