From: Michael Wallner Date: Tue, 17 Jan 2012 16:35:32 +0000 (+0000) Subject: remove Salsa10/Salsa20, which are actually stream ciphers not hash functions X-Git-Tag: php-5.5.0alpha1~613 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2d2aefe414ffbd7c54a2f1e2796886cd5e66c9c6;p=php remove Salsa10/Salsa20, which are actually stream ciphers not hash functions --- diff --git a/NEWS b/NEWS index 61395815b4..0d66249b53 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,7 @@ PHP NEWS - hash . Fixed bug #60221 (Tiger hash output byte order) (Mike) + . Removed Salsa10/Salsa20, which are actually stream ciphers (Mike) - pgsql . Added pg_escape_literal() and pg_escape_identifier() (Yasuo) diff --git a/ext/hash/config.m4 b/ext/hash/config.m4 index ca4f0bcebd..79ac25e19f 100644 --- a/ext/hash/config.m4 +++ b/ext/hash/config.m4 @@ -27,10 +27,10 @@ if test "$PHP_HASH" != "no"; then EXT_HASH_SOURCES="hash.c hash_md.c hash_sha.c hash_ripemd.c hash_haval.c \ hash_tiger.c hash_gost.c hash_snefru.c hash_whirlpool.c hash_adler32.c \ - hash_crc32.c hash_salsa.c hash_fnv.c hash_joaat.c" + hash_crc32.c hash_fnv.c hash_joaat.c" EXT_HASH_HEADERS="php_hash.h php_hash_md.h php_hash_sha.h php_hash_ripemd.h \ php_hash_haval.h php_hash_tiger.h php_hash_gost.h php_hash_snefru.h \ - php_hash_whirlpool.h php_hash_adler32.h php_hash_crc32.h php_hash_salsa.h \ + php_hash_whirlpool.h php_hash_adler32.h php_hash_crc32.h \ php_hash_fnv.h php_hash_joaat.h php_hash_types.h" PHP_NEW_EXTENSION(hash, $EXT_HASH_SOURCES, $ext_shared) diff --git a/ext/hash/config.w32 b/ext/hash/config.w32 index 6a2fcff18f..abe8675f30 100644 --- a/ext/hash/config.w32 +++ b/ext/hash/config.w32 @@ -15,11 +15,11 @@ if (PHP_HASH != "no") { AC_DEFINE('HAVE_HASH_EXT', 1); EXTENSION("hash", "hash.c hash_md.c hash_sha.c hash_ripemd.c hash_haval.c " + "hash_tiger.c hash_gost.c hash_snefru.c hash_whirlpool.c " - + "hash_adler32.c hash_crc32.c hash_salsa.c hash_joaat.c hash_fnv.c"); + + "hash_adler32.c hash_crc32.c hash_joaat.c hash_fnv.c"); PHP_INSTALL_HEADERS("ext/hash/", "php_hash.h php_hash_md.h php_hash_sha.h php_hash_ripemd.h " + "php_hash_haval.h php_hash_tiger.h php_hash_gost.h php_hash_snefru.h " + - "php_hash_whirlpool.h php_hash_adler32.h php_hash_crc32.h php_hash_salsa.h " + + "php_hash_whirlpool.h php_hash_adler32.h php_hash_crc32.h " + "php_hash_types.h"); } diff --git a/ext/hash/hash.c b/ext/hash/hash.c index 6500280328..895d64da33 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -851,8 +851,6 @@ PHP_MINIT_FUNCTION(hash) php_hash_register_algo("adler32", &php_hash_adler32_ops); php_hash_register_algo("crc32", &php_hash_crc32_ops); php_hash_register_algo("crc32b", &php_hash_crc32b_ops); - php_hash_register_algo("salsa10", &php_hash_salsa10_ops); - php_hash_register_algo("salsa20", &php_hash_salsa20_ops); php_hash_register_algo("fnv132", &php_hash_fnv132_ops); php_hash_register_algo("fnv164", &php_hash_fnv164_ops); php_hash_register_algo("joaat", &php_hash_joaat_ops); diff --git a/ext/hash/hash_salsa.c b/ext/hash/hash_salsa.c deleted file mode 100644 index 1532dfdcba..0000000000 --- a/ext/hash/hash_salsa.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2012 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. | - +----------------------------------------------------------------------+ - | Authors: Michael Wallner | - | Sara Golemon | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php_hash.h" -#include "php_hash_salsa.h" - -#define R(a,b) (((a) << (b)) | ((a) >> (32 - (b)))) - -/* {{{ Salsa10 - - The 64-byte input x to Salsa10 is viewed in little-endian form as 16 integers - x0, x1, x2, ..., x15 in {0,1,...,2^32-1}. These 16 integers are fed through - 320 invertible modifications, where each modification changes one integer. - The modifications involve, overall, - - * 10 additions of constants modulo 2^32; - * 320 more additions modulo 2^32; - * 80 ``or'' operations; - * 240 ``xor'' operations; and - * 320 constant-distance rotations. - - The resulting 16 integers are added to the original x0, x1, x2, ..., x15 - respectively modulo 2^32, producing, in little-endian form, the 64-byte output - Salsa10(x). - - D.J.Bernstein -*/ -static void Salsa10(php_hash_uint32 x[16], php_hash_uint32 in[16]) -{ - int i; - - for (i = 10; i > 0; --i) { - x[ 4] ^= R(x[ 0]+x[12], 6); x[ 8] ^= R(x[ 4]+x[ 0],17); - x[12] += R(x[ 8]|x[ 4],16); x[ 0] += R(x[12]^x[ 8], 5); - x[ 9] += R(x[ 5]|x[ 1], 8); x[13] += R(x[ 9]|x[ 5], 7); - x[ 1] ^= R(x[13]+x[ 9],17); x[ 5] += R(x[ 1]^x[13],12); - x[14] ^= R(x[10]+x[ 6], 7); x[ 2] += R(x[14]^x[10],15); - x[ 6] ^= R(x[ 2]+x[14],13); x[10] ^= R(x[ 6]+x[ 2],15); - x[ 3] += R(x[15]|x[11],20); x[ 7] ^= R(x[ 3]+x[15],16); - x[11] += R(x[ 7]^x[ 3], 7); x[15] += R(x[11]^x[ 7], 8); - x[ 1] += R(x[ 0]|x[ 3], 8)^i;x[ 2] ^= R(x[ 1]+x[ 0],14); - x[ 3] ^= R(x[ 2]+x[ 1], 6); x[ 0] += R(x[ 3]^x[ 2],18); - x[ 6] += R(x[ 5]^x[ 4], 8); x[ 7] += R(x[ 6]^x[ 5],12); - x[ 4] += R(x[ 7]|x[ 6],13); x[ 5] ^= R(x[ 4]+x[ 7],15); - x[11] ^= R(x[10]+x[ 9],18); x[ 8] += R(x[11]^x[10],11); - x[ 9] ^= R(x[ 8]+x[11], 8); x[10] += R(x[ 9]|x[ 8], 6); - x[12] += R(x[15]^x[14],17); x[13] ^= R(x[12]+x[15],15); - x[14] += R(x[13]|x[12], 9); x[15] += R(x[14]^x[13], 7); - } - for (i = 0; i < 16; ++i) { - x[i] += in[i]; - } -} -/* }}} */ - -/* {{{ Salsa20 - - The 64-byte input x to Salsa20 is viewed in little-endian form as 16 words - x0, x1, x2, ..., x15 in {0,1,...,2^32-1}. These 16 words are fed through 320 - invertible modifications, where each modification changes one word. The - resulting 16 words are added to the original x0, x1, x2, ..., x15 respectively - modulo 2^32, producing, in little-endian form, the 64-byte output Salsa20(x). - - Each modification involves xor'ing into one word a rotated version of the sum - of two other words modulo 2^32. Thus the 320 modifications involve, overall, - 320 additions, 320 xor's, and 320 rotations. The rotations are all by constant - distances. - - The entire series of modifications is a series of 10 identical double-rounds. - Each double-round is a series of 2 rounds. Each round is a set of 4 parallel - quarter-rounds. Each quarter-round modifies 4 words. - - D.J.Bernstein -*/ -static void Salsa20(php_hash_uint32 x[16], php_hash_uint32 in[16]) -{ - int i; - - for (i = 20; i > 0; i -= 2) { - x[ 4] ^= R(x[ 0]+x[12], 7); x[ 8] ^= R(x[ 4]+x[ 0], 9); - x[12] ^= R(x[ 8]+x[ 4],13); x[ 0] ^= R(x[12]+x[ 8],18); - x[ 9] ^= R(x[ 5]+x[ 1], 7); x[13] ^= R(x[ 9]+x[ 5], 9); - x[ 1] ^= R(x[13]+x[ 9],13); x[ 5] ^= R(x[ 1]+x[13],18); - x[14] ^= R(x[10]+x[ 6], 7); x[ 2] ^= R(x[14]+x[10], 9); - x[ 6] ^= R(x[ 2]+x[14],13); x[10] ^= R(x[ 6]+x[ 2],18); - x[ 3] ^= R(x[15]+x[11], 7); x[ 7] ^= R(x[ 3]+x[15], 9); - x[11] ^= R(x[ 7]+x[ 3],13); x[15] ^= R(x[11]+x[ 7],18); - x[ 1] ^= R(x[ 0]+x[ 3], 7); x[ 2] ^= R(x[ 1]+x[ 0], 9); - x[ 3] ^= R(x[ 2]+x[ 1],13); x[ 0] ^= R(x[ 3]+x[ 2],18); - x[ 6] ^= R(x[ 5]+x[ 4], 7); x[ 7] ^= R(x[ 6]+x[ 5], 9); - x[ 4] ^= R(x[ 7]+x[ 6],13); x[ 5] ^= R(x[ 4]+x[ 7],18); - x[11] ^= R(x[10]+x[ 9], 7); x[ 8] ^= R(x[11]+x[10], 9); - x[ 9] ^= R(x[ 8]+x[11],13); x[10] ^= R(x[ 9]+x[ 8],18); - x[12] ^= R(x[15]+x[14], 7); x[13] ^= R(x[12]+x[15], 9); - x[14] ^= R(x[13]+x[12],13); x[15] ^= R(x[14]+x[13],18); - } - for (i = 0; i < 16; ++i) { - x[i] += in[i]; - } -} -/* }}} */ - -static inline void SalsaTransform(PHP_SALSA_CTX *context, const unsigned char input[64]) -{ - php_hash_uint32 i, j, a[16]; - -#if 0 - fprintf(stderr, "> INPUT: %.*s\n", 64, input); -#endif - - for (i = 0, j = 0; j < 64; i++, j += 4) { - a[i] = ((php_hash_uint32) input[j + 3]) | (((php_hash_uint32) input[j + 2]) << 8) | - (((php_hash_uint32) input[j + 1]) << 16) | (((php_hash_uint32) input[j]) << 24); - } - - if (!context->init) { - memcpy(context->state, a, sizeof(a)); - context->init = 1; - } - - context->Transform(context->state, a); - memset(a, 0, sizeof(a)); -} - -PHP_HASH_API void PHP_SALSA10Init(PHP_SALSA_CTX *context) -{ - memset(context, 0, sizeof(*context)); - context->Transform = Salsa10; -} - -PHP_HASH_API void PHP_SALSA20Init(PHP_SALSA_CTX *context) -{ - memset(context, 0, sizeof(*context)); - context->Transform = Salsa20; -} - -PHP_HASH_API void PHP_SALSAUpdate(PHP_SALSA_CTX *context, const unsigned char *input, size_t len) -{ - if (context->length + len < 64) { - memcpy(&context->buffer[context->length], input, len); - context->length += len; - } else { - size_t i = 0, r = (context->length + len) % 64; - - if (context->length) { - i = 64 - context->length; - memcpy(&context->buffer[context->length], input, i); - SalsaTransform(context, context->buffer); - memset(context->buffer, 0, 64); - } - - for (; i + 64 <= len; i += 64) { - SalsaTransform(context, input + i); - } - - memcpy(context->buffer, input + i, r); - context->length = r; - } -} - -PHP_HASH_API void PHP_SALSAFinal(unsigned char digest[64], PHP_SALSA_CTX *context) -{ - php_hash_uint32 i, j; - - if (context->length) { - SalsaTransform(context, context->buffer); - } - - for (i = 0, j = 0; j < 64; i++, j += 4) { - digest[j] = (unsigned char) ((context->state[i] >> 24) & 0xff); - digest[j + 1] = (unsigned char) ((context->state[i] >> 16) & 0xff); - digest[j + 2] = (unsigned char) ((context->state[i] >> 8) & 0xff); - digest[j + 3] = (unsigned char) (context->state[i] & 0xff); - } - - memset(context, 0, sizeof(*context)); -} - -const php_hash_ops php_hash_salsa10_ops = { - (php_hash_init_func_t) PHP_SALSA10Init, - (php_hash_update_func_t) PHP_SALSAUpdate, - (php_hash_final_func_t) PHP_SALSAFinal, - (php_hash_copy_func_t) php_hash_copy, - 64, - 64, - sizeof(PHP_SALSA_CTX) -}; - -const php_hash_ops php_hash_salsa20_ops = { - (php_hash_init_func_t) PHP_SALSA20Init, - (php_hash_update_func_t) PHP_SALSAUpdate, - (php_hash_final_func_t) PHP_SALSAFinal, - (php_hash_copy_func_t) php_hash_copy, - 64, - 64, - sizeof(PHP_SALSA_CTX) -}; - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/hash/php_hash.h b/ext/hash/php_hash.h index f1c5c72353..87050cb8e5 100644 --- a/ext/hash/php_hash.h +++ b/ext/hash/php_hash.h @@ -78,8 +78,6 @@ extern const php_hash_ops php_hash_gost_ops; extern const php_hash_ops php_hash_adler32_ops; extern const php_hash_ops php_hash_crc32_ops; extern const php_hash_ops php_hash_crc32b_ops; -extern const php_hash_ops php_hash_salsa10_ops; -extern const php_hash_ops php_hash_salsa20_ops; extern const php_hash_ops php_hash_fnv132_ops; extern const php_hash_ops php_hash_fnv164_ops; extern const php_hash_ops php_hash_joaat_ops; diff --git a/ext/hash/php_hash_salsa.h b/ext/hash/php_hash_salsa.h deleted file mode 100644 index 10921597c2..0000000000 --- a/ext/hash/php_hash_salsa.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2012 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: Michael Wallner | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_HASH_SALSA_H -#define PHP_HASH_SALSA_H - -#include "ext/standard/basic_functions.h" - -/* SALSA context */ -typedef struct { - php_hash_uint32 state[16]; - unsigned char init:1; - unsigned char length:7; - unsigned char buffer[64]; - void (*Transform)(php_hash_uint32 state[16], php_hash_uint32 data[16]); -} PHP_SALSA_CTX; - -#define PHP_SALSAInit PHP_SALSA20Init -PHP_HASH_API void PHP_SALSA10Init(PHP_SALSA_CTX *); -PHP_HASH_API void PHP_SALSA20Init(PHP_SALSA_CTX *); - -PHP_HASH_API void PHP_SALSAUpdate(PHP_SALSA_CTX *, const unsigned char *, size_t); -PHP_HASH_API void PHP_SALSAFinal(unsigned char[64], PHP_SALSA_CTX *); - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/hash/tests/hash_algos.phpt b/ext/hash/tests/hash_algos.phpt index f497dfe6e7..55796ecbce 100644 --- a/ext/hash/tests/hash_algos.phpt +++ b/ext/hash/tests/hash_algos.phpt @@ -18,96 +18,92 @@ var_dump(hash_algos()); ===Done=== --EXPECTF-- *** Testing hash_algos() : basic functionality *** -array(45) { - [0]=> +array(43) { + [%d]=> string(3) "md2" - [1]=> + [%d]=> string(3) "md4" - [2]=> + [%d]=> string(3) "md5" - [3]=> + [%d]=> string(4) "sha1" - [4]=> + [%d]=> string(6) "sha224" - [5]=> + [%d]=> string(6) "sha256" - [6]=> + [%d]=> string(6) "sha384" - [7]=> + [%d]=> string(6) "sha512" - [8]=> + [%d]=> string(9) "ripemd128" - [9]=> + [%d]=> string(9) "ripemd160" - [10]=> + [%d]=> string(9) "ripemd256" - [11]=> + [%d]=> string(9) "ripemd320" - [12]=> + [%d]=> string(9) "whirlpool" - [13]=> + [%d]=> string(10) "tiger128,3" - [14]=> + [%d]=> string(10) "tiger160,3" - [15]=> + [%d]=> string(10) "tiger192,3" - [16]=> + [%d]=> string(10) "tiger128,4" - [17]=> + [%d]=> string(10) "tiger160,4" - [18]=> + [%d]=> string(10) "tiger192,4" - [19]=> + [%d]=> string(6) "snefru" - [20]=> + [%d]=> string(9) "snefru256" - [21]=> + [%d]=> string(4) "gost" - [22]=> + [%d]=> string(7) "adler32" - [23]=> + [%d]=> string(5) "crc32" - [24]=> + [%d]=> string(6) "crc32b" - [25]=> - string(7) "salsa10" - [26]=> - string(7) "salsa20" - [27]=> + [%d]=> string(6) "fnv132" - [28]=> + [%d]=> string(6) "fnv164" - [29]=> + [%d]=> string(5) "joaat" - [30]=> + [%d]=> string(10) "haval128,3" - [31]=> + [%d]=> string(10) "haval160,3" - [32]=> + [%d]=> string(10) "haval192,3" - [33]=> + [%d]=> string(10) "haval224,3" - [34]=> + [%d]=> string(10) "haval256,3" - [35]=> + [%d]=> string(10) "haval128,4" - [36]=> + [%d]=> string(10) "haval160,4" - [37]=> + [%d]=> string(10) "haval192,4" - [38]=> + [%d]=> string(10) "haval224,4" - [39]=> + [%d]=> string(10) "haval256,4" - [40]=> + [%d]=> string(10) "haval128,5" - [41]=> + [%d]=> string(10) "haval160,5" - [42]=> + [%d]=> string(10) "haval192,5" - [43]=> + [%d]=> string(10) "haval224,5" - [44]=> + [%d]=> string(10) "haval256,5" } ===Done=== \ No newline at end of file diff --git a/ext/hash/tests/hash_copy_001.phpt b/ext/hash/tests/hash_copy_001.phpt index 6609a6f3bd..421f2157bb 100644 --- a/ext/hash/tests/hash_copy_001.phpt +++ b/ext/hash/tests/hash_copy_001.phpt @@ -106,12 +106,6 @@ string(8) "e5cfc160" string(6) "crc32b" string(8) "69147a4e" string(8) "69147a4e" -string(7) "salsa10" -string(128) "aa39bc97c2bbcb0d79bbebfddca0bf8d769c7919c9e537e456efb5fc67f33f161758dd9da3ddcec7bbbd9c04553a03f74d2dbd26175dd75c353e9300674caa4e" -string(128) "aa39bc97c2bbcb0d79bbebfddca0bf8d769c7919c9e537e456efb5fc67f33f161758dd9da3ddcec7bbbd9c04553a03f74d2dbd26175dd75c353e9300674caa4e" -string(7) "salsa20" -string(128) "2ecbea42273e1e18affc7ef028674c8e55f9382f36de21e5fc38af76e4a7231d0a92feca9bdf586ac18d8a5bdd82be8a1cb1e9186871d6ff785c76a9090ac774" -string(128) "2ecbea42273e1e18affc7ef028674c8e55f9382f36de21e5fc38af76e4a7231d0a92feca9bdf586ac18d8a5bdd82be8a1cb1e9186871d6ff785c76a9090ac774" string(6) "fnv132" string(8) "98139504" string(8) "98139504" @@ -241,12 +235,6 @@ string(8) "59f8d3d2" string(6) "crc32b" string(8) "69147a4e" string(8) "3ee63999" -string(7) "salsa10" -string(128) "aa39bc97c2bbcb0d79bbebfddca0bf8d769c7919c9e537e456efb5fc67f33f161758dd9da3ddcec7bbbd9c04553a03f74d2dbd26175dd75c353e9300674caa4e" -string(128) "709b9196710f035e3602649fdae94f939775fa6a5a0bf01f9884d8af54579cafa01a81ee23d511b85d7fb11c4d827e4309953e3c844b8d66a80c57b6eaf2d8c1" -string(7) "salsa20" -string(128) "2ecbea42273e1e18affc7ef028674c8e55f9382f36de21e5fc38af76e4a7231d0a92feca9bdf586ac18d8a5bdd82be8a1cb1e9186871d6ff785c76a9090ac774" -string(128) "272fd2209f237b9be674eb4917eda0bd978908d56190e62aec283585d6325d8fcbba2b616dd7ba90f93cc5ecdede7185d17a06467b2a17b5c836ee115974ca20" string(6) "fnv132" string(8) "98139504" string(8) "59ad036f"