From: Sara Golemon Date: Tue, 19 Sep 2006 23:42:49 +0000 (+0000) Subject: Strip unused implementations of md5(), md5_file(), sha1(), and sha1_file() X-Git-Tag: RELEASE_1_0_0RC1~1614 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c8f96d157d37e66cb30f32d513833bfd742d0d5f;p=php Strip unused implementations of md5(), md5_file(), sha1(), and sha1_file() from this extension. It was decided a few months ago that those implementations would simply stay in ext/standard and never leave. --- diff --git a/ext/hash/hash.c b/ext/hash/hash.c index 9c4b23379d..6fed80051c 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -615,34 +615,6 @@ PHP_MINFO_FUNCTION(hash) /* }}} */ /* {{{ arginfo */ -#ifdef PHP_HASH_MD5_NOT_IN_CORE -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_md5, 0, 0, 1) - ZEND_ARG_INFO(0, str) - ZEND_ARG_INFO(0, raw_output) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_md5_file, 0, 0, 1) - ZEND_ARG_INFO(0, filename) - ZEND_ARG_INFO(0, raw_output) -ZEND_END_ARG_INFO() -#endif - -#ifdef PHP_HASH_SHA1_NOT_IN_CORE -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_sha1, 0, 0, 1) - ZEND_ARG_INFO(0, str) - ZEND_ARG_INFO(0, raw_output) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_hash_sha1_file, 0, 0, 1) - ZEND_ARG_INFO(0, filename) - ZEND_ARG_INFO(0, raw_output) -ZEND_END_ARG_INFO() -#endif - static ZEND_BEGIN_ARG_INFO_EX(arginfo_hash, 0, 0, 2) ZEND_ARG_INFO(0, algo) @@ -729,17 +701,6 @@ zend_function_entry hash_functions[] = { PHP_FE(hash_algos, arginfo_hash_algos) - /* BC Land */ -#ifdef PHP_HASH_MD5_NOT_IN_CORE - PHP_NAMED_FE(md5, php_if_md5, arginfo_hash_md5) - PHP_NAMED_FE(md5_file, php_if_md5_file, arginfo_hash_md5_file) -#endif /* PHP_HASH_MD5_NOT_IN_CORE */ - -#ifdef PHP_HASH_SHA1_NOT_IN_CORE - PHP_NAMED_FE(sha1, php_if_sha1, arginfo_hash_sha1) - PHP_NAMED_FE(sha1_file, php_if_sha1_file, arginfo_hash_sha1_file) -#endif /* PHP_HASH_SHA1_NOT_IN_CORE */ - {NULL, NULL, NULL} }; /* }}} */ diff --git a/ext/hash/hash_md.c b/ext/hash/hash_md.c index 8c43845cde..66b1e2ef89 100644 --- a/ext/hash/hash_md.c +++ b/ext/hash/hash_md.c @@ -88,358 +88,6 @@ static void Decode(php_hash_uint32 *output, const unsigned char *input, unsigned } /* }}} */ -#ifdef PHP_HASH_MD5_NOT_IN_CORE - -/* MD5 */ - -PHP_HASH_API void make_digest(char *md5str, unsigned char *digest) -{ - php_hash_bin2hex(md5str, digest, 16); - md5str[32] = '\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(md5str, digest); - 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, "s|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(md5str, digest); - RETVAL_STRING(md5str, 1); - } -} -/* }}} */ - -/* - * The remaining code is the reference MD5 code (md5c.c) from rfc1321 - */ -/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm - */ - -/* 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. - */ - -/* Constants for MD5Transform routine. - */ - -#define S11 7 -#define S12 12 -#define S13 17 -#define S14 22 -#define S21 5 -#define S22 9 -#define S23 14 -#define S24 20 -#define S31 4 -#define S32 11 -#define S33 16 -#define S34 23 -#define S41 6 -#define S42 10 -#define S43 15 -#define S44 21 - -static void MD5Transform(php_hash_uint32[4], const unsigned char[64]); - -/* F, G, H and I are basic MD5 functions. - */ -#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) -#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) -#define H(x, y, z) ((x) ^ (y) ^ (z)) -#define I(x, y, z) ((y) ^ ((x) | (~z))) - -/* ROTATE_LEFT rotates x left n bits. - */ -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - -/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. - Rotation is separate from addition to prevent recomputation. - */ -#define FF(a, b, c, d, x, s, ac) { \ - (a) += F ((b), (c), (d)) + (x) + (php_hash_uint32)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } -#define GG(a, b, c, d, x, s, ac) { \ - (a) += G ((b), (c), (d)) + (x) + (php_hash_uint32)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } -#define HH(a, b, c, d, x, s, ac) { \ - (a) += H ((b), (c), (d)) + (x) + (php_hash_uint32)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } -#define II(a, b, c, d, x, s, ac) { \ - (a) += I ((b), (c), (d)) + (x) + (php_hash_uint32)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } - -/* {{{ PHP_MD5Init - * MD5 initialization. Begins an MD5 operation, writing a new context. - */ -PHP_HASH_API void PHP_MD5Init(PHP_MD5_CTX * context) -{ - context->count[0] = context->count[1] = 0; - /* Load magic initialization constants. - */ - context->state[0] = 0x67452301; - context->state[1] = 0xefcdab89; - context->state[2] = 0x98badcfe; - context->state[3] = 0x10325476; -} -/* }}} */ - -/* {{{ PHP_MD5Update - MD5 block update operation. Continues an MD5 message-digest - operation, processing another message block, and updating the - context. - */ -PHP_HASH_API void PHP_MD5Update(PHP_MD5_CTX * context, const unsigned char *input, - unsigned int inputLen) -{ - unsigned int i, index, partLen; - - /* Compute number of bytes mod 64 */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3F); - - /* Update number of bits */ - if ((context->count[0] += ((php_hash_uint32) inputLen << 3)) - < ((php_hash_uint32) inputLen << 3)) - context->count[1]++; - context->count[1] += ((php_hash_uint32) inputLen >> 29); - - partLen = 64 - index; - - /* Transform as many times as possible. - */ - if (inputLen >= partLen) { - memcpy - ((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen); - MD5Transform(context->state, context->buffer); - - for (i = partLen; i + 63 < inputLen; i += 64) - MD5Transform(context->state, &input[i]); - - index = 0; - } else - i = 0; - - /* Buffer remaining input */ - memcpy - ((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], - inputLen - i); -} -/* }}} */ - -/* {{{ PHP_MD5Final - MD5 finalization. Ends an MD5 message-digest operation, writing the - the message digest and zeroizing the context. - */ -PHP_HASH_API void PHP_MD5Final(unsigned char digest[16], PHP_MD5_CTX * context) -{ - unsigned char bits[8]; - unsigned int index, padLen; - - /* Save number of bits */ - Encode(bits, context->count, 8); - - /* Pad out to 56 mod 64. - */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3f); - padLen = (index < 56) ? (56 - index) : (120 - index); - PHP_MD5Update(context, PADDING, padLen); - - /* Append length (before padding) */ - PHP_MD5Update(context, bits, 8); - - /* Store state in digest */ - Encode(digest, context->state, 16); - - /* Zeroize sensitive information. - */ - memset((unsigned char*) context, 0, sizeof(*context)); -} -/* }}} */ - -/* {{{ MD5Transform - * MD5 basic transformation. Transforms state based on block. - */ -static void MD5Transform(state, block) -php_hash_uint32 state[4]; -const unsigned char block[64]; -{ - php_hash_uint32 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; - - Decode(x, block, 64); - - /* Round 1 */ - FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */ - FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */ - FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */ - FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */ - FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */ - FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */ - FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */ - FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */ - FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */ - FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */ - FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ - FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ - FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ - FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ - FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ - FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ - - /* Round 2 */ - GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */ - GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */ - GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ - GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */ - GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */ - GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */ - GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ - GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */ - GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */ - GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ - GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */ - GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */ - GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ - GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */ - GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */ - GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ - - /* Round 3 */ - HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */ - HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */ - HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ - HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ - HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */ - HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */ - HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */ - HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ - HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ - HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */ - HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */ - HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */ - HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */ - HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ - HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ - HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */ - - /* Round 4 */ - II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */ - II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */ - II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ - II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */ - II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ - II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */ - II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ - II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */ - II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */ - II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ - II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */ - II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ - II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */ - II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ - II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */ - II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */ - - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - - /* Zeroize sensitive information. */ - memset((unsigned char*) x, 0, sizeof(x)); -} -/* }}} */ - -#endif /* PHP_HASH_MD5_NOT_IN_CORE */ - /* MD4 */ #define MD4_F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) diff --git a/ext/hash/hash_sha.c b/ext/hash/hash_sha.c index 3b1156d5bd..b8a6cc6291 100644 --- a/ext/hash/hash_sha.c +++ b/ext/hash/hash_sha.c @@ -75,336 +75,6 @@ php_hash_ops php_hash_sha1_ops = { sizeof(PHP_SHA1_CTX) }; -#ifdef PHP_HASH_SHA1_NOT_IN_CORE - -PHP_HASH_API void make_sha1_digest(char *sha1str, unsigned char *digest) -{ - php_hash_bin2hex(sha1str, digest, 20); - sha1str[40] = '\0'; -} - -/* {{{ proto string sha1(string str [, bool raw_output]) - Calculate the sha1 hash of a string */ -PHP_FUNCTION(sha1) -{ - char *arg; - int arg_len; - zend_bool raw_output = 0; - char sha1str[41]; - PHP_SHA1_CTX context; - unsigned char digest[20]; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) { - return; - } - - sha1str[0] = '\0'; - PHP_SHA1Init(&context); - PHP_SHA1Update(&context, arg, arg_len); - PHP_SHA1Final(digest, &context); - if (raw_output) { - RETURN_STRINGL(digest, 20, 1); - } else { - make_sha1_digest(sha1str, digest); - RETVAL_STRING(sha1str, 1); - } - -} - -/* }}} */ - -/* {{{ proto string sha1_file(string filename [, bool raw_output]) - Calculate the sha1 hash of given filename */ -PHP_FUNCTION(sha1_file) -{ - char *arg; - int arg_len; - zend_bool raw_output = 0; - char sha1str[41]; - unsigned char buf[1024]; - unsigned char digest[20]; - PHP_SHA1_CTX context; - int n; - php_stream *stream; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) { - return; - } - - stream = php_stream_open_wrapper(arg, "rb", REPORT_ERRORS, NULL); - if (!stream) { - RETURN_FALSE; - } - - PHP_SHA1Init(&context); - - while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) { - PHP_SHA1Update(&context, buf, n); - } - - PHP_SHA1Final(digest, &context); - - php_stream_close(stream); - - if (n<0) { - RETURN_FALSE; - } - - if (raw_output) { - RETURN_STRINGL(digest, 20, 1); - } else { - make_sha1_digest(sha1str, digest); - RETVAL_STRING(sha1str, 1); - } -} -/* }}} */ - -/* F, G, H and I are basic SHA1 functions. - */ -#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) -#define G(x, y, z) ((x) ^ (y) ^ (z)) -#define H(x, y, z) (((x) & (y)) | ((z) & ((x) | (y)))) -#define I(x, y, z) ((x) ^ (y) ^ (z)) - -/* ROTATE_LEFT rotates x left n bits. - */ -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - -/* W[i] - */ -#define W(i) ( tmp=x[(i-3)&15]^x[(i-8)&15]^x[(i-14)&15]^x[i&15], \ - (x[i&15]=ROTATE_LEFT(tmp, 1)) ) - -/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. - */ -#define FF(a, b, c, d, e, w) { \ - (e) += F ((b), (c), (d)) + (w) + (php_hash_uint32)(0x5A827999); \ - (e) += ROTATE_LEFT ((a), 5); \ - (b) = ROTATE_LEFT((b), 30); \ - } -#define GG(a, b, c, d, e, w) { \ - (e) += G ((b), (c), (d)) + (w) + (php_hash_uint32)(0x6ED9EBA1); \ - (e) += ROTATE_LEFT ((a), 5); \ - (b) = ROTATE_LEFT((b), 30); \ - } -#define HH(a, b, c, d, e, w) { \ - (e) += H ((b), (c), (d)) + (w) + (php_hash_uint32)(0x8F1BBCDC); \ - (e) += ROTATE_LEFT ((a), 5); \ - (b) = ROTATE_LEFT((b), 30); \ - } -#define II(a, b, c, d, e, w) { \ - (e) += I ((b), (c), (d)) + (w) + (php_hash_uint32)(0xCA62C1D6); \ - (e) += ROTATE_LEFT ((a), 5); \ - (b) = ROTATE_LEFT((b), 30); \ - } - - -/* {{{ PHP_SHA1Init - * SHA1 initialization. Begins an SHA1 operation, writing a new context. - */ -PHP_HASH_API void PHP_SHA1Init(PHP_SHA1_CTX * context) -{ - context->count[0] = context->count[1] = 0; - /* Load magic initialization constants. - */ - context->state[0] = 0x67452301; - context->state[1] = 0xefcdab89; - context->state[2] = 0x98badcfe; - context->state[3] = 0x10325476; - context->state[4] = 0xc3d2e1f0; -} -/* }}} */ - -/* {{{ SHA1Transform - * SHA1 basic transformation. Transforms state based on block. - */ -static void SHA1Transform(php_hash_uint32 state[5], const unsigned char block[64]) -{ - php_hash_uint32 a = state[0], b = state[1], c = state[2]; - php_hash_uint32 d = state[3], e = state[4], x[16], tmp; - - SHADecode32(x, block, 64); - - /* Round 1 */ - FF(a, b, c, d, e, x[0]); /* 1 */ - FF(e, a, b, c, d, x[1]); /* 2 */ - FF(d, e, a, b, c, x[2]); /* 3 */ - FF(c, d, e, a, b, x[3]); /* 4 */ - FF(b, c, d, e, a, x[4]); /* 5 */ - FF(a, b, c, d, e, x[5]); /* 6 */ - FF(e, a, b, c, d, x[6]); /* 7 */ - FF(d, e, a, b, c, x[7]); /* 8 */ - FF(c, d, e, a, b, x[8]); /* 9 */ - FF(b, c, d, e, a, x[9]); /* 10 */ - FF(a, b, c, d, e, x[10]); /* 11 */ - FF(e, a, b, c, d, x[11]); /* 12 */ - FF(d, e, a, b, c, x[12]); /* 13 */ - FF(c, d, e, a, b, x[13]); /* 14 */ - FF(b, c, d, e, a, x[14]); /* 15 */ - FF(a, b, c, d, e, x[15]); /* 16 */ - FF(e, a, b, c, d, W(16)); /* 17 */ - FF(d, e, a, b, c, W(17)); /* 18 */ - FF(c, d, e, a, b, W(18)); /* 19 */ - FF(b, c, d, e, a, W(19)); /* 20 */ - - /* Round 2 */ - GG(a, b, c, d, e, W(20)); /* 21 */ - GG(e, a, b, c, d, W(21)); /* 22 */ - GG(d, e, a, b, c, W(22)); /* 23 */ - GG(c, d, e, a, b, W(23)); /* 24 */ - GG(b, c, d, e, a, W(24)); /* 25 */ - GG(a, b, c, d, e, W(25)); /* 26 */ - GG(e, a, b, c, d, W(26)); /* 27 */ - GG(d, e, a, b, c, W(27)); /* 28 */ - GG(c, d, e, a, b, W(28)); /* 29 */ - GG(b, c, d, e, a, W(29)); /* 30 */ - GG(a, b, c, d, e, W(30)); /* 31 */ - GG(e, a, b, c, d, W(31)); /* 32 */ - GG(d, e, a, b, c, W(32)); /* 33 */ - GG(c, d, e, a, b, W(33)); /* 34 */ - GG(b, c, d, e, a, W(34)); /* 35 */ - GG(a, b, c, d, e, W(35)); /* 36 */ - GG(e, a, b, c, d, W(36)); /* 37 */ - GG(d, e, a, b, c, W(37)); /* 38 */ - GG(c, d, e, a, b, W(38)); /* 39 */ - GG(b, c, d, e, a, W(39)); /* 40 */ - - /* Round 3 */ - HH(a, b, c, d, e, W(40)); /* 41 */ - HH(e, a, b, c, d, W(41)); /* 42 */ - HH(d, e, a, b, c, W(42)); /* 43 */ - HH(c, d, e, a, b, W(43)); /* 44 */ - HH(b, c, d, e, a, W(44)); /* 45 */ - HH(a, b, c, d, e, W(45)); /* 46 */ - HH(e, a, b, c, d, W(46)); /* 47 */ - HH(d, e, a, b, c, W(47)); /* 48 */ - HH(c, d, e, a, b, W(48)); /* 49 */ - HH(b, c, d, e, a, W(49)); /* 50 */ - HH(a, b, c, d, e, W(50)); /* 51 */ - HH(e, a, b, c, d, W(51)); /* 52 */ - HH(d, e, a, b, c, W(52)); /* 53 */ - HH(c, d, e, a, b, W(53)); /* 54 */ - HH(b, c, d, e, a, W(54)); /* 55 */ - HH(a, b, c, d, e, W(55)); /* 56 */ - HH(e, a, b, c, d, W(56)); /* 57 */ - HH(d, e, a, b, c, W(57)); /* 58 */ - HH(c, d, e, a, b, W(58)); /* 59 */ - HH(b, c, d, e, a, W(59)); /* 60 */ - - /* Round 4 */ - II(a, b, c, d, e, W(60)); /* 61 */ - II(e, a, b, c, d, W(61)); /* 62 */ - II(d, e, a, b, c, W(62)); /* 63 */ - II(c, d, e, a, b, W(63)); /* 64 */ - II(b, c, d, e, a, W(64)); /* 65 */ - II(a, b, c, d, e, W(65)); /* 66 */ - II(e, a, b, c, d, W(66)); /* 67 */ - II(d, e, a, b, c, W(67)); /* 68 */ - II(c, d, e, a, b, W(68)); /* 69 */ - II(b, c, d, e, a, W(69)); /* 70 */ - II(a, b, c, d, e, W(70)); /* 71 */ - II(e, a, b, c, d, W(71)); /* 72 */ - II(d, e, a, b, c, W(72)); /* 73 */ - II(c, d, e, a, b, W(73)); /* 74 */ - II(b, c, d, e, a, W(74)); /* 75 */ - II(a, b, c, d, e, W(75)); /* 76 */ - II(e, a, b, c, d, W(76)); /* 77 */ - II(d, e, a, b, c, W(77)); /* 78 */ - II(c, d, e, a, b, W(78)); /* 79 */ - II(b, c, d, e, a, W(79)); /* 80 */ - - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - state[4] += e; - - /* Zeroize sensitive information. */ - memset((unsigned char*) x, 0, sizeof(x)); -} -/* }}} */ - -/* {{{ PHP_SHA1Update - SHA1 block update operation. Continues an SHA1 message-digest - operation, processing another message block, and updating the - context. - */ -PHP_HASH_API void PHP_SHA1Update(PHP_SHA1_CTX * context, const unsigned char *input, - unsigned int inputLen) -{ - unsigned int i, index, partLen; - - /* Compute number of bytes mod 64 */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3F); - - /* Update number of bits */ - if ((context->count[0] += ((php_hash_uint32) inputLen << 3)) - < ((php_hash_uint32) inputLen << 3)) - context->count[1]++; - context->count[1] += ((php_hash_uint32) inputLen >> 29); - - partLen = 64 - index; - - /* Transform as many times as possible. - */ - if (inputLen >= partLen) { - memcpy - ((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen); - SHA1Transform(context->state, context->buffer); - - for (i = partLen; i + 63 < inputLen; i += 64) - SHA1Transform(context->state, &input[i]); - - index = 0; - } else - i = 0; - - /* Buffer remaining input */ - memcpy - ((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], - inputLen - i); -} -/* }}} */ - -/* {{{ PHP_SHA1Final - SHA1 finalization. Ends an SHA1 message-digest operation, writing the - the message digest and zeroizing the context. - */ -PHP_HASH_API void PHP_SHA1Final(unsigned char digest[20], PHP_SHA1_CTX * context) -{ - unsigned char bits[8]; - unsigned int index, padLen; - - /* Save number of bits */ - bits[7] = context->count[0] & 0xFF; - bits[6] = (context->count[0] >> 8) & 0xFF; - bits[5] = (context->count[0] >> 16) & 0xFF; - bits[4] = (context->count[0] >> 24) & 0xFF; - bits[3] = context->count[1] & 0xFF; - bits[2] = (context->count[1] >> 8) & 0xFF; - bits[1] = (context->count[1] >> 16) & 0xFF; - bits[0] = (context->count[1] >> 24) & 0xFF; - - /* Pad out to 56 mod 64. - */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3f); - padLen = (index < 56) ? (56 - index) : (120 - index); - PHP_SHA1Update(context, PADDING, padLen); - - /* Append length (before padding) */ - PHP_SHA1Update(context, bits, 8); - - /* Store state in digest */ - SHAEncode32(digest, context->state, 20); - - /* Zeroize sensitive information. - */ - memset((unsigned char*) context, 0, sizeof(*context)); -} -/* }}} */ - -#endif /* PHP_HASH_SHA1_NOT_IN_CORE */ - /* sha256 */ php_hash_ops php_hash_sha256_ops = { diff --git a/ext/hash/php_hash_md.h b/ext/hash/php_hash_md.h index 66a0c88ef5..46bc5074fd 100644 --- a/ext/hash/php_hash_md.h +++ b/ext/hash/php_hash_md.h @@ -22,58 +22,8 @@ #ifndef PHP_HASH_MD_H #define PHP_HASH_MD_H -/* When SHA is removed from Core, - the ext/standard/sha1.c file can be removed - and the ext/standard/sha1.h file can be reduced to: - #define PHP_HASH_SHA1_NOT_IN_CORE - #include "ext/hash/php_hash_sha.h" - Don't forget to remove md5() and md5_file() entries from basic_functions.c - */ - #include "ext/standard/md5.h" -#ifdef PHP_HASH_MD5_NOT_IN_CORE -/* MD5.H - header file for MD5C.C - */ - -/* 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. - */ - -/* MD5 context. */ -typedef struct { - php_hash_uint32 state[4]; /* state (ABCD) */ - php_hash_uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */ - unsigned char buffer[64]; /* input buffer */ -} PHP_MD5_CTX; - -PHP_HASH_API void make_digest(char *md5str, unsigned char *digest); -PHP_HASH_API void PHP_MD5Init(PHP_MD5_CTX *); -PHP_HASH_API void PHP_MD5Update(PHP_MD5_CTX *, const unsigned char *, unsigned int); -PHP_HASH_API void PHP_MD5Final(unsigned char[16], PHP_MD5_CTX *); - -PHP_NAMED_FUNCTION(php_if_md5); -PHP_NAMED_FUNCTION(php_if_md5_file); -#endif /* PHP_HASH_MD5_NOT_IN_CORE */ - /* MD4 context */ typedef struct { php_hash_uint32 state[4]; diff --git a/ext/hash/php_hash_sha.h b/ext/hash/php_hash_sha.h index c01b3de196..1e183495a1 100644 --- a/ext/hash/php_hash_sha.h +++ b/ext/hash/php_hash_sha.h @@ -22,34 +22,9 @@ #ifndef PHP_HASH_SHA_H #define PHP_HASH_SHA_H -/* When SHA is removed from Core, - the ext/standard/sha1.c file can be removed - and the ext/standard/sha1.h file can be reduced to: - #define PHP_HASH_SHA1_NOT_IN_CORE - #include "ext/hash/php_hash_sha.h" - Don't forget to remove sha1() and sha1_file() from basic_functions.c - */ #include "ext/standard/sha1.h" #include "ext/standard/basic_functions.h" -#ifdef PHP_HASH_SHA1_NOT_IN_CORE - -/* SHA1 context. */ -typedef struct { - php_hash_uint32 state[5]; /* state (ABCD) */ - php_hash_uint32 count[2]; /* number of bits, modulo 2^64 */ - unsigned char buffer[64]; /* input buffer */ -} PHP_SHA1_CTX; - -PHP_HASH_API void PHP_SHA1Init(PHP_SHA1_CTX *); -PHP_HASH_API void PHP_SHA1Update(PHP_SHA1_CTX *, const unsigned char *, unsigned int); -PHP_HASH_API void PHP_SHA1Final(unsigned char[20], PHP_SHA1_CTX *); - -PHP_FUNCTION(sha1); -PHP_FUNCTION(sha1_file); - -#endif /* PHP_HASH_SHA1_NOT_IN_CORE */ - /* SHA256 context. */ typedef struct { php_hash_uint32 state[8]; /* state */