/opensource.apple.com/source/apache_mod_php/apache_mod_php-44.2/php/ext/standard/md5.c
C | 465 lines | 353 code | 57 blank | 55 comment | 2 complexity | a827e92dbc49739eaa658b61eac4f6e1 MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0, GPL-2.0, ISC, LGPL-2.1, Apache-2.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause, WTFPL, MIT, AGPL-1.0, AGPL-3.0
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>md5.c</title>
- <style type="text/css">
- .enscript-comment { font-style: italic; color: rgb(178,34,34); }
- .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
- .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
- .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
- .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
- .enscript-string { font-weight: bold; color: rgb(188,143,143); }
- .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
- .enscript-type { font-weight: bold; color: rgb(34,139,34); }
- .enscript-highlight { text-decoration: underline; color: 0; }
- </style>
- </head>
- <body id="top">
- <h1 style="margin:8px;" id="f1">md5.c <span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
- <hr/>
- <div></div>
- <pre>
- <span class="enscript-comment">/*
- +----------------------------------------------------------------------+
- | PHP Version 5 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2008 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: |
- | <a href="http://www.php.net/license/3_01.txt">http://www.php.net/license/3_01.txt</a> |
- | 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 |
- | <a href="mailto:license@php.net">license@php.net</a> so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Lachlan Roche |
- +----------------------------------------------------------------------+
- */</span>
- <span class="enscript-comment">/* $Id: md5.c,v 1.39.2.1.2.5 2007/12/31 07:20:13 sebastian Exp $ */</span>
- <span class="enscript-comment">/*
- * md5.c - Copyright 1997 Lachlan Roche
- * md5_file() added by Alessandro Astarita <<a href="mailto:aleast@capri.it">aleast@capri.it</a>>
- */</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string">"php.h"</span>
- #<span class="enscript-reference">include</span> <span class="enscript-string">"md5.h"</span>
- PHPAPI <span class="enscript-type">void</span> <span class="enscript-function-name">make_digest</span>(<span class="enscript-type">char</span> *md5str, <span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> *digest)
- {
- make_digest_ex(md5str, digest, 16);
- }
- PHPAPI <span class="enscript-type">void</span> <span class="enscript-function-name">make_digest_ex</span>(<span class="enscript-type">char</span> *md5str, <span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> *digest, <span class="enscript-type">int</span> len)
- {
- <span class="enscript-type">static</span> <span class="enscript-type">const</span> <span class="enscript-type">char</span> hexits[17] = <span class="enscript-string">"0123456789abcdef"</span>;
- <span class="enscript-type">int</span> i;
- <span class="enscript-keyword">for</span> (i = 0; i < len; i++) {
- md5str[i * 2] = hexits[digest[i] >> 4];
- md5str[(i * 2) + 1] = hexits[digest[i] & 0x0F];
- }
- md5str[len * 2] = <span class="enscript-string">'\0'</span>;
- }
- <span class="enscript-comment">/* {{{ proto string md5(string str, [ bool raw_output])
- Calculate the md5 hash of a string */</span>
- <span class="enscript-function-name">PHP_NAMED_FUNCTION</span>(php_if_md5)
- {
- <span class="enscript-type">char</span> *arg;
- <span class="enscript-type">int</span> arg_len;
- zend_bool raw_output = 0;
- <span class="enscript-type">char</span> md5str[33];
- PHP_MD5_CTX context;
- <span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> digest[16];
-
- <span class="enscript-keyword">if</span> (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, <span class="enscript-string">"s|b"</span>, &arg, &arg_len, &raw_output) == FAILURE) {
- <span class="enscript-keyword">return</span>;
- }
-
- md5str[0] = <span class="enscript-string">'\0'</span>;
- PHP_MD5Init(&context);
- PHP_MD5Update(&context, arg, arg_len);
- PHP_MD5Final(digest, &context);
- <span class="enscript-keyword">if</span> (raw_output) {
- RETURN_STRINGL(digest, 16, 1);
- } <span class="enscript-keyword">else</span> {
- make_digest_ex(md5str, digest, 16);
- RETVAL_STRING(md5str, 1);
- }
- }
- <span class="enscript-comment">/* }}} */</span>
- <span class="enscript-comment">/* {{{ proto string md5_file(string filename [, bool raw_output])
- Calculate the md5 hash of given filename */</span>
- <span class="enscript-function-name">PHP_NAMED_FUNCTION</span>(php_if_md5_file)
- {
- <span class="enscript-type">char</span> *arg;
- <span class="enscript-type">int</span> arg_len;
- zend_bool raw_output = 0;
- <span class="enscript-type">char</span> md5str[33];
- <span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> buf[1024];
- <span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> digest[16];
- PHP_MD5_CTX context;
- <span class="enscript-type">int</span> n;
- php_stream *stream;
- <span class="enscript-keyword">if</span> (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, <span class="enscript-string">"s|b"</span>, &arg, &arg_len, &raw_output) == FAILURE) {
- <span class="enscript-keyword">return</span>;
- }
-
- stream = php_stream_open_wrapper(arg, <span class="enscript-string">"rb"</span>, REPORT_ERRORS | ENFORCE_SAFE_MODE, NULL);
- <span class="enscript-keyword">if</span> (!stream) {
- RETURN_FALSE;
- }
- PHP_MD5Init(&context);
- <span class="enscript-keyword">while</span> ((n = php_stream_read(stream, buf, <span class="enscript-keyword">sizeof</span>(buf))) > 0) {
- PHP_MD5Update(&context, buf, n);
- }
- PHP_MD5Final(digest, &context);
- php_stream_close(stream);
- <span class="enscript-keyword">if</span> (n<0) {
- RETURN_FALSE;
- }
- <span class="enscript-keyword">if</span> (raw_output) {
- RETURN_STRINGL(digest, 16, 1);
- } <span class="enscript-keyword">else</span> {
- make_digest_ex(md5str, digest, 16);
- RETVAL_STRING(md5str, 1);
- }
- }
- <span class="enscript-comment">/* }}} */</span>
- <span class="enscript-comment">/*
- * The remaining code is the reference MD5 code (md5c.c) from rfc1321
- */</span>
- <span class="enscript-comment">/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
- */</span>
- <span class="enscript-comment">/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
- rights reserved.
- License to copy and use this software is granted provided that it
- is identified as the "RSA Data Security, Inc. MD5 Message-Digest
- Algorithm" in all material mentioning or referencing this software
- or this function.
- License is also granted to make and use derivative works provided
- that such works are identified as "derived from the RSA Data
- Security, Inc. MD5 Message-Digest Algorithm" in all material
- mentioning or referencing the derived work.
- RSA Data Security, Inc. makes no representations concerning either
- the merchantability of this software or the suitability of this
- software for any particular purpose. It is provided "as is"
- without express or implied warranty of any kind.
- These notices must be retained in any copies of any part of this
- documentation and/or software.
- */</span>
- <span class="enscript-comment">/* Constants for MD5Transform routine.
- */</span>
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S11</span> 7
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S12</span> 12
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S13</span> 17
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S14</span> 22
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S21</span> 5
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S22</span> 9
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S23</span> 14
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S24</span> 20
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S31</span> 4
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S32</span> 11
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S33</span> 16
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S34</span> 23
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S41</span> 6
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S42</span> 10
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S43</span> 15
- #<span class="enscript-reference">define</span> <span class="enscript-variable-name">S44</span> 21
- <span class="enscript-type">static</span> <span class="enscript-type">void</span> <span class="enscript-function-name">MD5Transform</span>(php_uint32[4], <span class="enscript-type">const</span> <span class="enscript-type">unsigned</span> <span class="enscript-type">char</span>[64]);
- <span class="enscript-type">static</span> <span class="enscript-type">void</span> <span class="enscript-function-name">Encode</span>(<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> *, php_uint32 *, <span class="enscript-type">unsigned</span> <span class="enscript-type">int</span>);
- <span class="enscript-type">static</span> <span class="enscript-type">void</span> <span class="enscript-function-name">Decode</span>(php_uint32 *, <span class="enscript-type">const</span> <span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> *, <span class="enscript-type">unsigned</span> <span class="enscript-type">int</span>);
- <span class="enscript-type">static</span> <span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> PADDING[64] =
- {
- 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- };
- <span class="enscript-comment">/* F, G, H and I are basic MD5 functions.
- */</span>
- #<span class="enscript-reference">define</span> <span class="enscript-function-name">F</span>(x, y, z) (((x) & (y)) | ((~x) & (z)))
- #<span class="enscript-reference">define</span> <span class="enscript-function-name">G</span>(x, y, z) (((x) & (z)) | ((y) & (~z)))
- #<span class="enscript-reference">define</span> <span class="enscript-function-name">H</span>(x, y, z) ((x) ^ (y) ^ (z))
- #<span class="enscript-reference">define</span> <span class="enscript-function-name">I</span>(x, y, z) ((y) ^ ((x) | (~z)))
- <span class="enscript-comment">/* ROTATE_LEFT rotates x left n bits.
- */</span>
- #<span class="enscript-reference">define</span> <span class="enscript-function-name">ROTATE_LEFT</span>(x, n) (((x) << (n)) | ((x) >> (32-(n))))
- <span class="enscript-comment">/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
- Rotation is separate from addition to prevent recomputation.
- */</span>
- #<span class="enscript-reference">define</span> <span class="enscript-function-name">FF</span>(a, b, c, d, x, s, ac) { \
- (a) += F ((b), (c), (d)) + (x) + (php_uint32)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
- #<span class="enscript-reference">define</span> <span class="enscript-function-name">GG</span>(a, b, c, d, x, s, ac) { \
- (a) += G ((b), (c), (d)) + (x) + (php_uint32)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
- #<span class="enscript-reference">define</span> <span class="enscript-function-name">HH</span>(a, b, c, d, x, s, ac) { \
- (a) += H ((b), (c), (d)) + (x) + (php_uint32)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
- #<span class="enscript-reference">define</span> <span class="enscript-function-name">II</span>(a, b, c, d, x, s, ac) { \
- (a) += I ((b), (c), (d)) + (x) + (php_uint32)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
- <span class="enscript-comment">/* {{{ PHP_MD5Init
- * MD5 initialization. Begins an MD5 operation, writing a new context.
- */</span>
- PHPAPI <span class="enscript-type">void</span> <span class="enscript-function-name">PHP_MD5Init</span>(PHP_MD5_CTX * context)
- {
- context->count[0] = context->count[1] = 0;
- <span class="enscript-comment">/* Load magic initialization constants.
- */</span>
- context->state[0] = 0x67452301;
- context->state[1] = 0xefcdab89;
- context->state[2] = 0x98badcfe;
- context->state[3] = 0x10325476;
- }
- <span class="enscript-comment">/* }}} */</span>
- <span class="enscript-comment">/* {{{ PHP_MD5Update
- MD5 block update operation. Continues an MD5 message-digest
- operation, processing another message block, and updating the
- context.
- */</span>
- PHPAPI <span class="enscript-type">void</span> <span class="enscript-function-name">PHP_MD5Update</span>(PHP_MD5_CTX * context, <span class="enscript-type">const</span> <span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> *input,
- <span class="enscript-type">unsigned</span> <span class="enscript-type">int</span> inputLen)
- {
- <span class="enscript-type">unsigned</span> <span class="enscript-type">int</span> i, index, partLen;
- <span class="enscript-comment">/* Compute number of bytes mod 64 */</span>
- index = (<span class="enscript-type">unsigned</span> <span class="enscript-type">int</span>) ((context->count[0] >> 3) & 0x3F);
- <span class="enscript-comment">/* Update number of bits */</span>
- <span class="enscript-keyword">if</span> ((context->count[0] += ((php_uint32) inputLen << 3))
- < ((php_uint32) inputLen << 3))
- context->count[1]++;
- context->count[1] += ((php_uint32) inputLen >> 29);
- partLen = 64 - index;
- <span class="enscript-comment">/* Transform as many times as possible.
- */</span>
- <span class="enscript-keyword">if</span> (inputLen >= partLen) {
- memcpy
- ((<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span>*) & context->buffer[index], (<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span>*) input, partLen);
- MD5Transform(context->state, context->buffer);
- <span class="enscript-keyword">for</span> (i = partLen; i + 63 < inputLen; i += 64)
- MD5Transform(context->state, &input[i]);
- index = 0;
- } <span class="enscript-keyword">else</span>
- i = 0;
- <span class="enscript-comment">/* Buffer remaining input */</span>
- memcpy
- ((<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span>*) & context->buffer[index], (<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span>*) & input[i],
- inputLen - i);
- }
- <span class="enscript-comment">/* }}} */</span>
- <span class="enscript-comment">/* {{{ PHP_MD5Final
- MD5 finalization. Ends an MD5 message-digest operation, writing the
- the message digest and zeroizing the context.
- */</span>
- PHPAPI <span class="enscript-type">void</span> <span class="enscript-function-name">PHP_MD5Final</span>(<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> digest[16], PHP_MD5_CTX * context)
- {
- <span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> bits[8];
- <span class="enscript-type">unsigned</span> <span class="enscript-type">int</span> index, padLen;
- <span class="enscript-comment">/* Save number of bits */</span>
- Encode(bits, context->count, 8);
- <span class="enscript-comment">/* Pad out to 56 mod 64.
- */</span>
- index = (<span class="enscript-type">unsigned</span> <span class="enscript-type">int</span>) ((context->count[0] >> 3) & 0x3f);
- padLen = (index < 56) ? (56 - index) : (120 - index);
- PHP_MD5Update(context, PADDING, padLen);
- <span class="enscript-comment">/* Append length (before padding) */</span>
- PHP_MD5Update(context, bits, 8);
- <span class="enscript-comment">/* Store state in digest */</span>
- Encode(digest, context->state, 16);
- <span class="enscript-comment">/* Zeroize sensitive information.
- */</span>
- memset((<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span>*) context, 0, <span class="enscript-keyword">sizeof</span>(*context));
- }
- <span class="enscript-comment">/* }}} */</span>
- <span class="enscript-comment">/* {{{ MD5Transform
- * MD5 basic transformation. Transforms state based on block.
- */</span>
- <span class="enscript-type">static</span> <span class="enscript-type">void</span> <span class="enscript-function-name">MD5Transform</span>(state, block)
- php_uint32 state[4];
- <span class="enscript-type">const</span> <span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> block[64];
- {
- php_uint32 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
- Decode(x, block, 64);
- <span class="enscript-comment">/* Round 1 */</span>
- FF(a, b, c, d, x[0], S11, 0xd76aa478); <span class="enscript-comment">/* 1 */</span>
- FF(d, a, b, c, x[1], S12, 0xe8c7b756); <span class="enscript-comment">/* 2 */</span>
- FF(c, d, a, b, x[2], S13, 0x242070db); <span class="enscript-comment">/* 3 */</span>
- FF(b, c, d, a, x[3], S14, 0xc1bdceee); <span class="enscript-comment">/* 4 */</span>
- FF(a, b, c, d, x[4], S11, 0xf57c0faf); <span class="enscript-comment">/* 5 */</span>
- FF(d, a, b, c, x[5], S12, 0x4787c62a); <span class="enscript-comment">/* 6 */</span>
- FF(c, d, a, b, x[6], S13, 0xa8304613); <span class="enscript-comment">/* 7 */</span>
- FF(b, c, d, a, x[7], S14, 0xfd469501); <span class="enscript-comment">/* 8 */</span>
- FF(a, b, c, d, x[8], S11, 0x698098d8); <span class="enscript-comment">/* 9 */</span>
- FF(d, a, b, c, x[9], S12, 0x8b44f7af); <span class="enscript-comment">/* 10 */</span>
- FF(c, d, a, b, x[10], S13, 0xffff5bb1); <span class="enscript-comment">/* 11 */</span>
- FF(b, c, d, a, x[11], S14, 0x895cd7be); <span class="enscript-comment">/* 12 */</span>
- FF(a, b, c, d, x[12], S11, 0x6b901122); <span class="enscript-comment">/* 13 */</span>
- FF(d, a, b, c, x[13], S12, 0xfd987193); <span class="enscript-comment">/* 14 */</span>
- FF(c, d, a, b, x[14], S13, 0xa679438e); <span class="enscript-comment">/* 15 */</span>
- FF(b, c, d, a, x[15], S14, 0x49b40821); <span class="enscript-comment">/* 16 */</span>
- <span class="enscript-comment">/* Round 2 */</span>
- GG(a, b, c, d, x[1], S21, 0xf61e2562); <span class="enscript-comment">/* 17 */</span>
- GG(d, a, b, c, x[6], S22, 0xc040b340); <span class="enscript-comment">/* 18 */</span>
- GG(c, d, a, b, x[11], S23, 0x265e5a51); <span class="enscript-comment">/* 19 */</span>
- GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); <span class="enscript-comment">/* 20 */</span>
- GG(a, b, c, d, x[5], S21, 0xd62f105d); <span class="enscript-comment">/* 21 */</span>
- GG(d, a, b, c, x[10], S22, 0x2441453); <span class="enscript-comment">/* 22 */</span>
- GG(c, d, a, b, x[15], S23, 0xd8a1e681); <span class="enscript-comment">/* 23 */</span>
- GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); <span class="enscript-comment">/* 24 */</span>
- GG(a, b, c, d, x[9], S21, 0x21e1cde6); <span class="enscript-comment">/* 25 */</span>
- GG(d, a, b, c, x[14], S22, 0xc33707d6); <span class="enscript-comment">/* 26 */</span>
- GG(c, d, a, b, x[3], S23, 0xf4d50d87); <span class="enscript-comment">/* 27 */</span>
- GG(b, c, d, a, x[8], S24, 0x455a14ed); <span class="enscript-comment">/* 28 */</span>
- GG(a, b, c, d, x[13], S21, 0xa9e3e905); <span class="enscript-comment">/* 29 */</span>
- GG(d, a, b, c, x[2], S22, 0xfcefa3f8); <span class="enscript-comment">/* 30 */</span>
- GG(c, d, a, b, x[7], S23, 0x676f02d9); <span class="enscript-comment">/* 31 */</span>
- GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); <span class="enscript-comment">/* 32 */</span>
- <span class="enscript-comment">/* Round 3 */</span>
- HH(a, b, c, d, x[5], S31, 0xfffa3942); <span class="enscript-comment">/* 33 */</span>
- HH(d, a, b, c, x[8], S32, 0x8771f681); <span class="enscript-comment">/* 34 */</span>
- HH(c, d, a, b, x[11], S33, 0x6d9d6122); <span class="enscript-comment">/* 35 */</span>
- HH(b, c, d, a, x[14], S34, 0xfde5380c); <span class="enscript-comment">/* 36 */</span>
- HH(a, b, c, d, x[1], S31, 0xa4beea44); <span class="enscript-comment">/* 37 */</span>
- HH(d, a, b, c, x[4], S32, 0x4bdecfa9); <span class="enscript-comment">/* 38 */</span>
- HH(c, d, a, b, x[7], S33, 0xf6bb4b60); <span class="enscript-comment">/* 39 */</span>
- HH(b, c, d, a, x[10], S34, 0xbebfbc70); <span class="enscript-comment">/* 40 */</span>
- HH(a, b, c, d, x[13], S31, 0x289b7ec6); <span class="enscript-comment">/* 41 */</span>
- HH(d, a, b, c, x[0], S32, 0xeaa127fa); <span class="enscript-comment">/* 42 */</span>
- HH(c, d, a, b, x[3], S33, 0xd4ef3085); <span class="enscript-comment">/* 43 */</span>
- HH(b, c, d, a, x[6], S34, 0x4881d05); <span class="enscript-comment">/* 44 */</span>
- HH(a, b, c, d, x[9], S31, 0xd9d4d039); <span class="enscript-comment">/* 45 */</span>
- HH(d, a, b, c, x[12], S32, 0xe6db99e5); <span class="enscript-comment">/* 46 */</span>
- HH(c, d, a, b, x[15], S33, 0x1fa27cf8); <span class="enscript-comment">/* 47 */</span>
- HH(b, c, d, a, x[2], S34, 0xc4ac5665); <span class="enscript-comment">/* 48 */</span>
- <span class="enscript-comment">/* Round 4 */</span>
- II(a, b, c, d, x[0], S41, 0xf4292244); <span class="enscript-comment">/* 49 */</span>
- II(d, a, b, c, x[7], S42, 0x432aff97); <span class="enscript-comment">/* 50 */</span>
- II(c, d, a, b, x[14], S43, 0xab9423a7); <span class="enscript-comment">/* 51 */</span>
- II(b, c, d, a, x[5], S44, 0xfc93a039); <span class="enscript-comment">/* 52 */</span>
- II(a, b, c, d, x[12], S41, 0x655b59c3); <span class="enscript-comment">/* 53 */</span>
- II(d, a, b, c, x[3], S42, 0x8f0ccc92); <span class="enscript-comment">/* 54 */</span>
- II(c, d, a, b, x[10], S43, 0xffeff47d); <span class="enscript-comment">/* 55 */</span>
- II(b, c, d, a, x[1], S44, 0x85845dd1); <span class="enscript-comment">/* 56 */</span>
- II(a, b, c, d, x[8], S41, 0x6fa87e4f); <span class="enscript-comment">/* 57 */</span>
- II(d, a, b, c, x[15], S42, 0xfe2ce6e0); <span class="enscript-comment">/* 58 */</span>
- II(c, d, a, b, x[6], S43, 0xa3014314); <span class="enscript-comment">/* 59 */</span>
- II(b, c, d, a, x[13], S44, 0x4e0811a1); <span class="enscript-comment">/* 60 */</span>
- II(a, b, c, d, x[4], S41, 0xf7537e82); <span class="enscript-comment">/* 61 */</span>
- II(d, a, b, c, x[11], S42, 0xbd3af235); <span class="enscript-comment">/* 62 */</span>
- II(c, d, a, b, x[2], S43, 0x2ad7d2bb); <span class="enscript-comment">/* 63 */</span>
- II(b, c, d, a, x[9], S44, 0xeb86d391); <span class="enscript-comment">/* 64 */</span>
- state[0] += a;
- state[1] += b;
- state[2] += c;
- state[3] += d;
- <span class="enscript-comment">/* Zeroize sensitive information. */</span>
- memset((<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span>*) x, 0, <span class="enscript-keyword">sizeof</span>(x));
- }
- <span class="enscript-comment">/* }}} */</span>
- <span class="enscript-comment">/* {{{ Encode
- Encodes input (php_uint32) into output (unsigned char). Assumes len is
- a multiple of 4.
- */</span>
- <span class="enscript-type">static</span> <span class="enscript-type">void</span> <span class="enscript-function-name">Encode</span>(output, input, len)
- <span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> *output;
- php_uint32 *input;
- <span class="enscript-type">unsigned</span> <span class="enscript-type">int</span> len;
- {
- <span class="enscript-type">unsigned</span> <span class="enscript-type">int</span> i, j;
- <span class="enscript-keyword">for</span> (i = 0, j = 0; j < len; i++, j += 4) {
- output[j] = (<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span>) (input[i] & 0xff);
- output[j + 1] = (<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span>) ((input[i] >> 8) & 0xff);
- output[j + 2] = (<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span>) ((input[i] >> 16) & 0xff);
- output[j + 3] = (<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span>) ((input[i] >> 24) & 0xff);
- }
- }
- <span class="enscript-comment">/* }}} */</span>
- <span class="enscript-comment">/* {{{ Decode
- Decodes input (unsigned char) into output (php_uint32). Assumes len is
- a multiple of 4.
- */</span>
- <span class="enscript-type">static</span> <span class="enscript-type">void</span> <span class="enscript-function-name">Decode</span>(output, input, len)
- php_uint32 *output;
- <span class="enscript-type">const</span> <span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> *input;
- <span class="enscript-type">unsigned</span> <span class="enscript-type">int</span> len;
- {
- <span class="enscript-type">unsigned</span> <span class="enscript-type">int</span> i, j;
- <span class="enscript-keyword">for</span> (i = 0, j = 0; j < len; i++, j += 4)
- output[i] = ((php_uint32) input[j]) | (((php_uint32) input[j + 1]) << 8) |
- (((php_uint32) input[j + 2]) << 16) | (((php_uint32) input[j + 3]) << 24);
- }
- <span class="enscript-comment">/* }}} */</span>
- <span class="enscript-comment">/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */</span>
- </pre>
- <hr />
- </body></html>