Following an offline discussion with some internals folks, I've put together a general hashing extensions which could potentially find a place in core as an enabled by default extension:

ext/hash:

string hash(string $algo, string $value[,$raw=false])
string hash_file(string $algo, string $filename[,$raw=false])

Where $algo is (currently) any of 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160' each of which are implemented internally using raw math and no library dependencies. I've also got an upgrade path laid out for extracting md5() and sha1() from core in future versions (6.0?) without compromising backward compatability.

The extension also supports incremental hashing:

resource hash_init($algo);
bool hash_update($context, $data);
string hash_final($context[,$raw=false])

External extensions can already "register" additional hashing algos using the module dependency hooks now available.

For the future I've got plans for allowing registration of userspace hashing functions, HMAC support, and a streams filter implementation as well as additional engines: crc, haval, md4, etc...

Examples:

$digest = hash('sha256', 'abc');

$ctx = hash_init('sha256');
hash_update($ctx, 'a');
hash_update($ctx, 'bc');
$digest = hash_final($ctx);

I'm just putting on some finishing touches and will post a tarball later today.

-Sara

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to