cvs: pear /Message Message.php common.php /Message/HMAC HAVAL128.php HAVAL160.php HAVAL192.php HAVAL224.php HAVAL256.php MD4.php MD5.php
RIPEMD160.php SHA1.php SHA256.php TIGER.php TIGER128.php TIGER160.php common.php /Message/Hash ADLER32.php CRC32.php CRC32B.php GOST.php HAVAL128.php
HAVAL160.php HAVAL192.php HAVAL224.php HAVAL256.php MD4.php MD5.php RIPEMD160.php SHA1.php SHA256.php TIGER.php TIGER128.php TIGER160.php common.php
/Message/misc hash_proto hmac_proto mkclasses.php rfc2104_testvectors.php rfc2202_test.php testmessage.php
| From: | Jesus M. Castagnetto | Date: | Wed, 02 Oct 2002 03:54:20 +0000 |
| Subject: | cvs: pear /Message Message.php common.php /Message/HMAC HAVAL128.php HAVAL160.php HAVAL192.php HAVAL224.php HAVAL256.php MD4.php MD5.php RIPEMD160.php SHA1.php SHA256.php TIGER.php TIGER128.php TIGER160.php common.php /Message/Hash ADLER32.php CRC32.php CRC32B.php GOST.php HAVAL128.php HAVAL160.php HAVAL192.php HAVAL224.php HAVAL256.php MD4.php MD5.php RIPEMD160.php SHA1.php SHA256.php TIGER.php TIGER128.php TIGER160.php common.php /Message/misc hash_proto hmac_proto mkclasses.php rfc2104_testvectors.php rfc2202_test.php testmessage.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-6810@lists.php.net to get a copy of this message | ||
jmcastagnetto Tue Oct 1 23:54:20 2002 EDT
Added files:
/pear/Message Message.php common.php
/pear/Message/HMAC HAVAL128.php HAVAL160.php HAVAL192.php
HAVAL224.php HAVAL256.php MD4.php MD5.php
RIPEMD160.php SHA1.php SHA256.php TIGER.php
TIGER128.php TIGER160.php common.php
/pear/Message/Hash ADLER32.php CRC32.php CRC32B.php GOST.php
HAVAL128.php HAVAL160.php HAVAL192.php
HAVAL224.php HAVAL256.php MD4.php MD5.php
RIPEMD160.php SHA1.php SHA256.php TIGER.php
TIGER128.php TIGER160.php common.php
/pear/Message/misc hash_proto hmac_proto mkclasses.php
rfc2104_testvectors.php rfc2202_test.php
testmessage.php
Log:
Initial import w/ some minimal documentation.
Index: pear/Message/Message.php +++ pear/Message/Message.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: Message.php,v 1.1 2002/10/02 03:54:18 jmcastagnetto Exp $ // require_once 'PEAR.php'; class Message extends PEAR { function &hash($hash_name, $ser = '', $enc = '') { if (!extension_loaded('mhash')) { return PEAR::raiseError('Could not find the mhash extension'); } else { // mangle hash name to compare to mhash's constants list($hash, $hash_name) = Message::_mangle($hash_name); $valid_hash = array ('MHASH_MD5', 'MHASH_SHA1'); if (!defined($hash)) { return PEAR::raiseError("Unsupported hash: $hash_name"); } else { include_once "Message/Hash/{$hash_name}.php"; $hash_class = "Message_Hash_{$hash_name}"; return new $hash_class($ser, $enc); } } } function &createHash($hash_name, $ser = '', $enc = '') { return Message::hash($hash_name, $ser, $enc); } function &hmac($hash_name, $key, $ser = '', $enc = '') { if (!extension_loaded('mhash')) { return PEAR::raiseError('Could not find the mhash extension'); } else { // mangle hash name to compare to mhash's constants list($hash, $hash_name) = Message::_mangle($hash_name); $cannot_hmac = array('CRC32', 'GOST', 'CRC32B', 'ADLER32'); if (!defined($hash) || in_array($hash_name, $cannot_hmac)) { return PEAR::raiseError("Unsupported hmac: $hash_name"); } else { include_once "Message/HMAC/{$hash_name}.php"; $hmac = "Message_HMAC_{$hash_name}"; return new $hmac($key, $ser, $enc); } } } function &createHMAC($hash_name, $key, $ser = '', $enc = '') { return Message::hmac($hash_name, $key, $ser, $enc); } function calcHash($hash_name, $data, $ser = 'none', $enc = 'hex') { if (!extension_loaded('mhash')) { return PEAR::raiseError('Could not find the mhash extension'); } else { $hash =& Message::hash($hash_name, $ser, $enc); if (PEAR::isError($hash)) return $hash; else return $hash->calc($data); } } function calcHMAC($hash_name, $data, $key, $ser = 'none', $enc = 'hex') { if (!extension_loaded('mhash')) { return PEAR::raiseError('Could not find the mhash extension'); } else { $hmac =& Message::hmac($hash_name, $key, $ser, $enc); if (PEAR::isError($hmac)) return $hmac; else return $hmac->calc($data); } } function validateHMAC($hash_name, $data, $signature, $key, $ser = '', $enc = '') { $hmac = Message::calcHMAC($hash_name, $data, $key, $ser, $enc); if (PEAR::isError($hmac)) return $hmac; else return (boolean) ($hmac == $signature); } function _mangle($hash_name) { if (preg_match('/^MHASH_/', $hash_name)) { $hash = $hash_name; } else { $hash = 'MHASH_'.$hash_name; } list(,$hash_name) = explode('_', $hash); return array($hash, $hash_name); } } ?> Index: pear/Message/common.php +++ pear/Message/common.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: common.php,v 1.1 2002/10/02 03:54:18 jmcastagnetto Exp $ // require_once 'PEAR.php'; /** * Class the implements the basic methods of the message hash and hmac classes */ class Message_Common { var $hash_name; var $serialization; var $encoding; function Message_Common($hash_name, $ser = '', $enc = '') { $this->hash_name = $hash_name; $this->setSerialization($ser); $this->setEncoding($enc); } function setSerialization($mode) { $valid_modes = array ('none', 'serialize', 'wddx'); if ($mode && in_array($mode, $valid_modes)) $this->serialization = $mode; else $this->serialization = 'none'; } function setEncoding($mode) { $valid_modes = array ('bin', 'hex', 'base64'); if ($mode && in_array($mode, $valid_modes)) $this->serialization = $mode; else $this->serialization = 'none'; } function serialize($data) { switch ($this->serialization) { case 'serialize' : return serialize($data); break; case 'wddx' : return wddx_serialize_value($data); break; case 'none' : default : return $data; break; } } function encode($data) { switch ($this->encoding) { case 'bin' : return $data; break; case 'base64' : return base64_encode($data); break; case 'hex' : default : return bin2hex($data); break; } } function getData($input) { if (is_resource($input)) { $data = ''; $restype = get_resource_type($input); switch ($restype) { case 'file' : case 'pipe' : case 'socket' : case 'stream' : while($part = fread($input, 1024)) $data .= $part; break; case 'zlib' : while($part = gzread($input, 4096)) $data .= $part; break; case 'bzip2' : while($part = bzread($input, 4096)) $data .= $part; break; default : return PEAR::raiseError('Resource not supported: '.$restype); break; } return $data; } else { return $input; } } } ?> Index: pear/Message/HMAC/HAVAL128.php +++ pear/Message/HMAC/HAVAL128.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL128.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the HAVAL128 algorithm */ class Message_HMAC_HAVAL128 extends Message_HMAC_Common { function Message_HMAC_HAVAL128($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_HAVAL128', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/HAVAL160.php +++ pear/Message/HMAC/HAVAL160.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL160.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the HAVAL160 algorithm */ class Message_HMAC_HAVAL160 extends Message_HMAC_Common { function Message_HMAC_HAVAL160($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_HAVAL160', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/HAVAL192.php +++ pear/Message/HMAC/HAVAL192.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL192.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the HAVAL192 algorithm */ class Message_HMAC_HAVAL192 extends Message_HMAC_Common { function Message_HMAC_HAVAL192($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_HAVAL192', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/HAVAL224.php +++ pear/Message/HMAC/HAVAL224.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL224.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the HAVAL224 algorithm */ class Message_HMAC_HAVAL224 extends Message_HMAC_Common { function Message_HMAC_HAVAL224($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_HAVAL224', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/HAVAL256.php +++ pear/Message/HMAC/HAVAL256.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL256.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the HAVAL256 algorithm */ class Message_HMAC_HAVAL256 extends Message_HMAC_Common { function Message_HMAC_HAVAL256($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_HAVAL256', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/MD4.php +++ pear/Message/HMAC/MD4.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: MD4.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the MD4 algorithm */ class Message_HMAC_MD4 extends Message_HMAC_Common { function Message_HMAC_MD4($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_MD4', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/MD5.php +++ pear/Message/HMAC/MD5.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: MD5.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the MD5 algorithm */ class Message_HMAC_MD5 extends Message_HMAC_Common { function Message_HMAC_MD5($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_MD5', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/RIPEMD160.php +++ pear/Message/HMAC/RIPEMD160.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: RIPEMD160.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the RIPEMD160 algorithm */ class Message_HMAC_RIPEMD160 extends Message_HMAC_Common { function Message_HMAC_RIPEMD160($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_RIPEMD160', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/SHA1.php +++ pear/Message/HMAC/SHA1.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: SHA1.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the SHA1 algorithm */ class Message_HMAC_SHA1 extends Message_HMAC_Common { function Message_HMAC_SHA1($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_SHA1', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/SHA256.php +++ pear/Message/HMAC/SHA256.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: SHA256.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the SHA256 algorithm */ class Message_HMAC_SHA256 extends Message_HMAC_Common { function Message_HMAC_SHA256($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_SHA256', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/TIGER.php +++ pear/Message/HMAC/TIGER.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: TIGER.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the TIGER algorithm */ class Message_HMAC_TIGER extends Message_HMAC_Common { function Message_HMAC_TIGER($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_TIGER', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/TIGER128.php +++ pear/Message/HMAC/TIGER128.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: TIGER128.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the TIGER128 algorithm */ class Message_HMAC_TIGER128 extends Message_HMAC_Common { function Message_HMAC_TIGER128($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_TIGER128', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/TIGER160.php +++ pear/Message/HMAC/TIGER160.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: TIGER160.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the TIGER160 algorithm */ class Message_HMAC_TIGER160 extends Message_HMAC_Common { function Message_HMAC_TIGER160($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_TIGER160', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/common.php +++ pear/Message/HMAC/common.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: common.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'PEAR.php'; require_once 'Message/common.php'; class Message_HMAC_Common extends Message_Common { var $key; function Message_HMAC_Common($hash_name, $key, $ser = '', $enc = '') { $this->Message_Common($hash_name, $ser, $enc); $this->key = $key; } function setKey($key) { $this->key = $key; } function calc($input, $ser = '', $enc = '') { if (!extension_loaded('mhash')) { return PEAR::raiseError('Extension mhash not found'); } else { $data = $this->getData($input); if (PEAR::isError($data)) return $data; if (!empty($ser)) $this->setSerialization($ser); if (!empty($enc)) $this->setEncoding($enc); $data = $this->serialize($data); $sig = mhash(constant($this->hash_name), $data, $this->key); return $this->encode($sig); } } function validate($input, $signature, $ser = '', $enc = '') { $data = $this->calc($input, $ser, $enc); if (PEAR::isError($data)) return $data; else return (boolean) ($data == $signature); } } ?> Index: pear/Message/Hash/ADLER32.php +++ pear/Message/Hash/ADLER32.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: ADLER32.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the ADLER32 algorithm */ class Message_Hash_ADLER32 extends Message_Hash_Common { function Message_Hash_ADLER32($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_ADLER32', $ser, $enc); } } ?> Index: pear/Message/Hash/CRC32.php +++ pear/Message/Hash/CRC32.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: CRC32.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the CRC32 algorithm */ class Message_Hash_CRC32 extends Message_Hash_Common { function Message_Hash_CRC32($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_CRC32', $ser, $enc); } } ?> Index: pear/Message/Hash/CRC32B.php +++ pear/Message/Hash/CRC32B.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: CRC32B.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the CRC32B algorithm */ class Message_Hash_CRC32B extends Message_Hash_Common { function Message_Hash_CRC32B($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_CRC32B', $ser, $enc); } } ?> Index: pear/Message/Hash/GOST.php +++ pear/Message/Hash/GOST.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: GOST.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the GOST algorithm */ class Message_Hash_GOST extends Message_Hash_Common { function Message_Hash_GOST($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_GOST', $ser, $enc); } } ?> Index: pear/Message/Hash/HAVAL128.php +++ pear/Message/Hash/HAVAL128.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL128.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the HAVAL128 algorithm */ class Message_Hash_HAVAL128 extends Message_Hash_Common { function Message_Hash_HAVAL128($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_HAVAL128', $ser, $enc); } } ?> Index: pear/Message/Hash/HAVAL160.php +++ pear/Message/Hash/HAVAL160.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL160.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the HAVAL160 algorithm */ class Message_Hash_HAVAL160 extends Message_Hash_Common { function Message_Hash_HAVAL160($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_HAVAL160', $ser, $enc); } } ?> Index: pear/Message/Hash/HAVAL192.php +++ pear/Message/Hash/HAVAL192.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL192.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the HAVAL192 algorithm */ class Message_Hash_HAVAL192 extends Message_Hash_Common { function Message_Hash_HAVAL192($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_HAVAL192', $ser, $enc); } } ?> Index: pear/Message/Hash/HAVAL224.php +++ pear/Message/Hash/HAVAL224.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL224.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the HAVAL224 algorithm */ class Message_Hash_HAVAL224 extends Message_Hash_Common { function Message_Hash_HAVAL224($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_HAVAL224', $ser, $enc); } } ?> Index: pear/Message/Hash/HAVAL256.php +++ pear/Message/Hash/HAVAL256.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL256.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the HAVAL256 algorithm */ class Message_Hash_HAVAL256 extends Message_Hash_Common { function Message_Hash_HAVAL256($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_HAVAL256', $ser, $enc); } } ?> Index: pear/Message/Hash/MD4.php +++ pear/Message/Hash/MD4.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: MD4.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the MD4 algorithm */ class Message_Hash_MD4 extends Message_Hash_Common { function Message_Hash_MD4($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_MD4', $ser, $enc); } } ?> Index: pear/Message/Hash/MD5.php +++ pear/Message/Hash/MD5.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: MD5.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the MD5 algorithm */ class Message_Hash_MD5 extends Message_Hash_Common { function Message_Hash_MD5($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_MD5', $ser, $enc); } } ?> Index: pear/Message/Hash/RIPEMD160.php +++ pear/Message/Hash/RIPEMD160.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: RIPEMD160.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the RIPEMD160 algorithm */ class Message_Hash_RIPEMD160 extends Message_Hash_Common { function Message_Hash_RIPEMD160($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_RIPEMD160', $ser, $enc); } } ?> Index: pear/Message/Hash/SHA1.php +++ pear/Message/Hash/SHA1.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: SHA1.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the SHA1 algorithm */ class Message_Hash_SHA1 extends Message_Hash_Common { function Message_Hash_SHA1($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_SHA1', $ser, $enc); } } ?> Index: pear/Message/Hash/SHA256.php +++ pear/Message/Hash/SHA256.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: SHA256.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the SHA256 algorithm */ class Message_Hash_SHA256 extends Message_Hash_Common { function Message_Hash_SHA256($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_SHA256', $ser, $enc); } } ?> Index: pear/Message/Hash/TIGER.php +++ pear/Message/Hash/TIGER.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: TIGER.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the TIGER algorithm */ class Message_Hash_TIGER extends Message_Hash_Common { function Message_Hash_TIGER($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_TIGER', $ser, $enc); } } ?> Index: pear/Message/Hash/TIGER128.php +++ pear/Message/Hash/TIGER128.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: TIGER128.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the TIGER128 algorithm */ class Message_Hash_TIGER128 extends Message_Hash_Common { function Message_Hash_TIGER128($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_TIGER128', $ser, $enc); } } ?> Index: pear/Message/Hash/TIGER160.php +++ pear/Message/Hash/TIGER160.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: TIGER160.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the TIGER160 algorithm */ class Message_Hash_TIGER160 extends Message_Hash_Common { function Message_Hash_TIGER160($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_TIGER160', $ser, $enc); } } ?> Index: pear/Message/Hash/common.php +++ pear/Message/Hash/common.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: common.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'PEAR.php'; require_once 'Message/common.php'; class Message_Hash_Common extends Message_Common { function Message_Hash_Common($hash_name, $ser = '', $enc = '') { $this->Message_Common($hash_name, $ser, $enc); } function calc($input, $ser = '', $enc = '') { if (!extension_loaded('mhash')) { return PEAR::raiseError('Extension mhash not found'); } else { $data = $this->getData($input); if (PEAR::isError($data)) return $data; if (!empty($ser)) $this->setSerialization($ser); if (!empty($enc)) $this->setEncoding($enc); $data = $this->serialize($data); $hash = mhash(constant($this->hash_name), $data); return $this->encode($hash); } } } ?> Index: pear/Message/misc/mkclasses.php +++ pear/Message/misc/mkclasses.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: mkclasses.php,v 1.1 2002/10/02 03:54:20 jmcastagnetto Exp $ // /** * Utility script to generate the wrapper classes */ $cannot_hmac = array('CRC32', 'GOST', 'CRC32B', 'ADLER32'); $hash_proto = implode('',file('./hash_proto')); $hmac_proto = implode('',file('./hmac_proto')); $nhashes = mhash_count(); for ($i=0; $i <= $nhashes ; $i++) { $hname = mhash_get_hash_name($i); if (trim($hname) == '') { continue; } else { $fname = "../Hash/{$hname}.php"; echo "Creating $fname\n"; $out = str_replace('##proto##', $hname, $hash_proto); $fp = fopen($fname, 'w'); fwrite($fp, $out); fclose($fp); if (!in_array($hname, $cannot_hmac)) { $fname = "../HMAC/{$hname}.php"; echo "Creating $fname\n"; $out = str_replace('##proto##', $hname, $hmac_proto); $fp = fopen($fname, 'w'); fwrite($fp, $out); fclose($fp); } } } ?> Index: pear/Message/misc/rfc2104_testvectors.php +++ pear/Message/misc/rfc2104_testvectors.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: rfc2104_testvectors.php,v 1.1 2002/10/02 03:54:20 jmcastagnetto Exp $ // /** * Test package by using the test vectors from the RFC 2104 */ require_once 'Message/Message.php'; echo "Test Vectors from rfc 2104\n\n"; echo "* Using static calls\n\n"; $key1 = str_repeat(chr(0x0b), 16); $data1 = "Hi There"; echo "rfc 2104 output: 0x9294727a3638bb1c13f48ef8158bfc9d\n"; echo 'key: 0x'.str_repeat('0b', 16)."\n"; echo "data: $data1\n"; echo "md5 HMAC: ".Message::calcHMAC('MD5', $data1, $key1)."\n\n"; $key2 = "Jefe"; $data2 = "what do ya want for nothing?"; echo "rfc 2104 output: 0x750c783e6ab0b503eaa86e310a5db738\n"; echo "key: $key2\n"; echo "data: $data2\n"; echo "md5 HMAC: ".Message::calcHMAC('MD5', $data2, $key2)."\n\n"; $key3 = str_repeat(chr(0xAA), 16); $data3 = str_repeat(chr(0xDD), 50); echo "rfc 2104 output: 0x56be34521d144c88dbb8c733f0e8b3f6\n"; echo 'key: 0x'.str_repeat('AA', 16)."\n"; echo 'data: 0x'.wordwrap(str_repeat('DD', 50),30,"\n",1)."\n"; echo "md5 HMAC: ".Message::calcHMAC('MD5', $data3, $key3)."\n\n"; echo "\n* Using a Message_HMAC_MD5 object\n\n"; $md5 =& Message::createHMAC('MD5', $key1); echo "rfc 2104 output: 0x9294727a3638bb1c13f48ef8158bfc9d\n"; echo 'key: 0x'.str_repeat('0b', 16)."\n"; echo "data: $data1\n"; echo "md5 HMAC: ".$md5->calc($data1)."\n\n"; $md5->setKey($key2); echo "rfc 2104 output: 0x750c783e6ab0b503eaa86e310a5db738\n"; echo "key: $key2\n"; echo "data: $data2\n"; echo "md5 HMAC: ".$md5->calc($data2)."\n\n"; $md5->setKey($key3); echo "rfc 2104 output: 0x56be34521d144c88dbb8c733f0e8b3f6\n"; echo 'key: 0x'.str_repeat('AA', 16)."\n"; echo 'data: 0x'.wordwrap(str_repeat('DD', 50),30,"\n",1)."\n"; echo "md5 HMAC: ".$md5->calc($data3)."\n\n"; ?> Index: pear/Message/misc/rfc2202_test.php +++ pear/Message/misc/rfc2202_test.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: rfc2202_test.php,v 1.1 2002/10/02 03:54:20 jmcastagnetto Exp $ // /** * Testing using test vectors from RFC 2202, for HMAC MD5 and HMAC SHA1 */ require_once 'Message/Message.php'; $key4 = ''; foreach (range(0x01,0x19) as $hex) $key4 .= chr($hex); $hmac_md5_list = array ( 1 => array( 'key' => str_repeat(chr(0x0b), 16), 'data' => 'Hi There', 'digest' => '9294727a3638bb1c13f48ef8158bfc9d' ), 2 => array( 'key' => 'Jefe', 'data' => 'what do ya want for nothing?', 'digest' => '750c783e6ab0b503eaa86e310a5db738' ), 3 => array( 'key' => str_repeat(chr(0xaa), 16), 'data' => str_repeat(chr(0xdd), 50), 'digest' => '56be34521d144c88dbb8c733f0e8b3f6' ), 4 => array( 'key' => $key4, 'data' => str_repeat(chr(0xcd), 50), 'digest' => '697eaf0aca3a3aea3a75164746ffaa79' ), 5 => array( 'key' => str_repeat(chr(0x0c), 16), 'data' => 'Test With Truncation', 'digest' => '56461ef2342edc00f9bab995690efd4c' ), 6 => array( 'key' => str_repeat(chr(0xaa), 80), 'data' => 'Test Using Larger Than Block-Size Key - Hash Key First', 'digest' => '6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd' ), 7 => array( 'key' => str_repeat(chr(0xaa), 80), 'data' => 'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data', 'digest' => '6f630fad67cda0ee1fb1f562db3aa53e' ) ); $hmac_sha1_list = array ( 1 => array( 'key' => str_repeat(chr(0x0b), 20), 'data' => 'Hi There', 'digest' => 'b617318655057264e28bc0b6fb378c8ef146be00' ), 2 => array( 'key' => 'Jefe', 'data' => 'what do ya want for nothing?', 'digest' => 'effcdf6ae5eb2fa2d27416d5f184df9c259a7c79' ), 3 => array( 'key' => str_repeat(chr(0xaa), 20), 'data' => str_repeat(chr(0xdd), 50), 'digest' => '125d7342b9ac11cd91a39af48aa17b4f63f175d3' ), 4 => array( 'key' => $key4, 'data' => str_repeat(chr(0xcd), 50), 'digest' => '4c9007f4026250c6bc8414f9bf50c86c2d7235da' ), 5 => array( 'key' => str_repeat(chr(0x0c), 20), 'data' => 'Test With Truncation', 'digest' => '4c1a03424b55e07fe7f27be1d58bb9324a9a5a04' ), 6 => array( 'key' => str_repeat(chr(0xaa), 80), 'data' => 'Test Using Larger Than Block-Size Key - Hash Key First', 'digest' => 'aa4ae5e15272d00e95705637ce8a3b55ed402112' ), 7 => array( 'key' => str_repeat(chr(0xaa), 80), 'data' => 'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data', 'digest' => 'e8e99d0f45237d786d6bbaa7965c7808bbff1a91' ) ); function run($digest_name, $testvector_list) { $re = '/([[:alnum:] -])+/'; echo "\n*** HMAC $digest_name ***\n\n"; foreach ($testvector_list as $case=>$test) { $digest = Message::calcHMAC($digest_name, $test['data'], $test['key']); $keylen = strlen($test['key']); $datalen = strlen($test['data']); $out = "test case: $case\n"; if (preg_match($re, $test['key'])) { $out .= sprintf("key:\t'%s'\n", $test['key']); } else { $out .= sprintf("key:\t0x%s\n", bin2hex($test['key'])); } $out .= sprintf("key_len:\t%d\n", $keylen); if (preg_match($re, $test['data'])) { $out .= sprintf("data:\t'%s'\n", $test['data']); } else { $out .= sprintf("data:\t0x%s\n", bin2hex($test['data'])); } $out .= sprintf("data_len:\t%d\n", $datalen). sprintf("digest (rfc):\t0x%s\n", $test['digest']). sprintf("digest (calc):\t0x%s\n", $digest). sprintf("\tdigest(rfc) == digest(calc) : %s\n", ($test['digest'] == $digest) ? 'true' : 'false'); echo "$out\n"; } } run('MD5', $hmac_md5_list); run('SHA1', $hmac_sha1_list); ?> Index: pear/Message/misc/testmessage.php +++ pear/Message/misc/testmessage.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: testmessage.php,v 1.1 2002/10/02 03:54:20 jmcastagnetto Exp $ // /** * Example of use of PEAR::Message */ include_once 'Message/Message.php'; $data = 'abc'; $data2 = 'abd'; $key = 'metalloproteins rule'; echo "Using 'abc' as data\n\n"; $hash = Message::createHash('MD5'); echo 'MD5: '.$hash->calc($data)."\n"; $hash2 = Message::createHash('SHA1'); echo 'SHA1: '.$hash2->calc($data)."\n"; echo "\nUsing '$key' as key\n\n"; $hmac = Message::createHMAC('MD5',$key); $sig_md5 = $hmac->calc($data); $valid = (int) $hmac->validate($data,$sig_md5); $hmac2 = Message::createHMAC('SHA1', $key); $sig_sha1 = $hmac2->calc($data); echo "HMAC MD5: {$sig_md5}\n"; echo "HMAC SHA1: {$sig_sha1}\n"; echo "Validating: hmac('$data', '$key') == sig_md5 --> {$valid}\n"; echo "\nUsing 'abd' as data:\n\n"; $valid2 = (int) $hmac->validate($data2,$sig_md5); echo "Validating: hmac('$data2', '$key') == sig_md5 --> {$valid2}\n"; echo "\nUsing a file resource as data input\n"; $fp = fopen('./testmessage.php', 'r'); // know thyself echo 'resource: '.get_resource_type($fp)."\n"; $file_hash = $hash->calc($fp); rewind($fp); $file_hmac = $hmac->calc($fp); rewind($fp); $file_validate = (int) $hmac->validate($fp, $file_hmac); fclose($fp); echo "MD5 hash: $file_hash\n"; echo "MD5 HMAC: $file_hmac\n"; echo "MD5 HMAC validate : $file_validate\n"; echo "\nUsing a gzip'ed file resource as data input\n"; $fp = gzopen('./testfile.gz', 'r'); // know thyself echo 'resource: '.get_resource_type($fp)."\n"; $file_hash = $hash->calc($fp); gzrewind($fp); $file_hmac = $hmac->calc($fp); gzrewind($fp); $file_validate = (int) $hmac->validate($fp, $file_hmac); gzclose($fp); echo "MD5 hash: $file_hash\n"; echo "MD5 HMAC: $file_hmac\n"; echo "MD5 HMAC validate : $file_validate\n"; echo "\nUsing a fsockopen resource as data input\n"; $fp = fsockopen("www.google.com", "80"); echo 'resource: '.get_resource_type($fp)."\n"; fputs($fp, "HEAD / HTTP/1.0\n\r\n\r"); $file_hash = $hash->calc($fp); fclose($fp); $fp = fsockopen("www.google.com", "80"); fputs($fp, "HEAD / HTTP/1.0\n\r\n\r"); $file_hmac = $hmac->calc($fp); fclose($fp); $fp = fsockopen("www.google.com", "80"); fputs($fp, "HEAD / HTTP/1.0\n\r\n\r"); $file_validate = (int) $hmac->validate($fp, $file_hmac); fclose($fp); echo "MD5 hash: $file_hash\n"; echo "MD5 HMAC: $file_hmac\n"; echo "MD5 HMAC validate : $file_validate\n"; echo "\t* it should not validate as the headers returned contain a timestamp\n"; echo "\nUsing static method calls\n\n"; $cannot_hmac = array('CRC32', 'GOST', 'CRC32B', 'ADLER32'); $nhashes = mhash_count(); for ($i=0; $i <= $nhashes ; $i++) { $hname = mhash_get_hash_name($i); if (trim($hname) == '') { continue; } else { echo "Message::calcHash('$hname','abc') : ".Message::calcHash($hname, $data)."\n"; if (!in_array($hname, $cannot_hmac)) { echo "Message::calcHMAC('$hname','abc', key) : ".Message::calcHMAC($hname, $data, $key)."\n"; } else { echo "\t** $hname cannot be used for HMAC\n"; } } } ?>
Index: pear/Message/Message.php +++ pear/Message/Message.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: Message.php,v 1.1 2002/10/02 03:54:18 jmcastagnetto Exp $ // require_once 'PEAR.php'; class Message extends PEAR { function &hash($hash_name, $ser = '', $enc = '') { if (!extension_loaded('mhash')) { return PEAR::raiseError('Could not find the mhash extension'); } else { // mangle hash name to compare to mhash's constants list($hash, $hash_name) = Message::_mangle($hash_name); $valid_hash = array ('MHASH_MD5', 'MHASH_SHA1'); if (!defined($hash)) { return PEAR::raiseError("Unsupported hash: $hash_name"); } else { include_once "Message/Hash/{$hash_name}.php"; $hash_class = "Message_Hash_{$hash_name}"; return new $hash_class($ser, $enc); } } } function &createHash($hash_name, $ser = '', $enc = '') { return Message::hash($hash_name, $ser, $enc); } function &hmac($hash_name, $key, $ser = '', $enc = '') { if (!extension_loaded('mhash')) { return PEAR::raiseError('Could not find the mhash extension'); } else { // mangle hash name to compare to mhash's constants list($hash, $hash_name) = Message::_mangle($hash_name); $cannot_hmac = array('CRC32', 'GOST', 'CRC32B', 'ADLER32'); if (!defined($hash) || in_array($hash_name, $cannot_hmac)) { return PEAR::raiseError("Unsupported hmac: $hash_name"); } else { include_once "Message/HMAC/{$hash_name}.php"; $hmac = "Message_HMAC_{$hash_name}"; return new $hmac($key, $ser, $enc); } } } function &createHMAC($hash_name, $key, $ser = '', $enc = '') { return Message::hmac($hash_name, $key, $ser, $enc); } function calcHash($hash_name, $data, $ser = 'none', $enc = 'hex') { if (!extension_loaded('mhash')) { return PEAR::raiseError('Could not find the mhash extension'); } else { $hash =& Message::hash($hash_name, $ser, $enc); if (PEAR::isError($hash)) return $hash; else return $hash->calc($data); } } function calcHMAC($hash_name, $data, $key, $ser = 'none', $enc = 'hex') { if (!extension_loaded('mhash')) { return PEAR::raiseError('Could not find the mhash extension'); } else { $hmac =& Message::hmac($hash_name, $key, $ser, $enc); if (PEAR::isError($hmac)) return $hmac; else return $hmac->calc($data); } } function validateHMAC($hash_name, $data, $signature, $key, $ser = '', $enc = '') { $hmac = Message::calcHMAC($hash_name, $data, $key, $ser, $enc); if (PEAR::isError($hmac)) return $hmac; else return (boolean) ($hmac == $signature); } function _mangle($hash_name) { if (preg_match('/^MHASH_/', $hash_name)) { $hash = $hash_name; } else { $hash = 'MHASH_'.$hash_name; } list(,$hash_name) = explode('_', $hash); return array($hash, $hash_name); } } ?> Index: pear/Message/common.php +++ pear/Message/common.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: common.php,v 1.1 2002/10/02 03:54:18 jmcastagnetto Exp $ // require_once 'PEAR.php'; /** * Class the implements the basic methods of the message hash and hmac classes */ class Message_Common { var $hash_name; var $serialization; var $encoding; function Message_Common($hash_name, $ser = '', $enc = '') { $this->hash_name = $hash_name; $this->setSerialization($ser); $this->setEncoding($enc); } function setSerialization($mode) { $valid_modes = array ('none', 'serialize', 'wddx'); if ($mode && in_array($mode, $valid_modes)) $this->serialization = $mode; else $this->serialization = 'none'; } function setEncoding($mode) { $valid_modes = array ('bin', 'hex', 'base64'); if ($mode && in_array($mode, $valid_modes)) $this->serialization = $mode; else $this->serialization = 'none'; } function serialize($data) { switch ($this->serialization) { case 'serialize' : return serialize($data); break; case 'wddx' : return wddx_serialize_value($data); break; case 'none' : default : return $data; break; } } function encode($data) { switch ($this->encoding) { case 'bin' : return $data; break; case 'base64' : return base64_encode($data); break; case 'hex' : default : return bin2hex($data); break; } } function getData($input) { if (is_resource($input)) { $data = ''; $restype = get_resource_type($input); switch ($restype) { case 'file' : case 'pipe' : case 'socket' : case 'stream' : while($part = fread($input, 1024)) $data .= $part; break; case 'zlib' : while($part = gzread($input, 4096)) $data .= $part; break; case 'bzip2' : while($part = bzread($input, 4096)) $data .= $part; break; default : return PEAR::raiseError('Resource not supported: '.$restype); break; } return $data; } else { return $input; } } } ?> Index: pear/Message/HMAC/HAVAL128.php +++ pear/Message/HMAC/HAVAL128.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL128.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the HAVAL128 algorithm */ class Message_HMAC_HAVAL128 extends Message_HMAC_Common { function Message_HMAC_HAVAL128($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_HAVAL128', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/HAVAL160.php +++ pear/Message/HMAC/HAVAL160.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL160.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the HAVAL160 algorithm */ class Message_HMAC_HAVAL160 extends Message_HMAC_Common { function Message_HMAC_HAVAL160($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_HAVAL160', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/HAVAL192.php +++ pear/Message/HMAC/HAVAL192.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL192.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the HAVAL192 algorithm */ class Message_HMAC_HAVAL192 extends Message_HMAC_Common { function Message_HMAC_HAVAL192($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_HAVAL192', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/HAVAL224.php +++ pear/Message/HMAC/HAVAL224.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL224.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the HAVAL224 algorithm */ class Message_HMAC_HAVAL224 extends Message_HMAC_Common { function Message_HMAC_HAVAL224($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_HAVAL224', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/HAVAL256.php +++ pear/Message/HMAC/HAVAL256.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL256.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the HAVAL256 algorithm */ class Message_HMAC_HAVAL256 extends Message_HMAC_Common { function Message_HMAC_HAVAL256($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_HAVAL256', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/MD4.php +++ pear/Message/HMAC/MD4.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: MD4.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the MD4 algorithm */ class Message_HMAC_MD4 extends Message_HMAC_Common { function Message_HMAC_MD4($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_MD4', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/MD5.php +++ pear/Message/HMAC/MD5.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: MD5.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the MD5 algorithm */ class Message_HMAC_MD5 extends Message_HMAC_Common { function Message_HMAC_MD5($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_MD5', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/RIPEMD160.php +++ pear/Message/HMAC/RIPEMD160.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: RIPEMD160.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the RIPEMD160 algorithm */ class Message_HMAC_RIPEMD160 extends Message_HMAC_Common { function Message_HMAC_RIPEMD160($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_RIPEMD160', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/SHA1.php +++ pear/Message/HMAC/SHA1.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: SHA1.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the SHA1 algorithm */ class Message_HMAC_SHA1 extends Message_HMAC_Common { function Message_HMAC_SHA1($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_SHA1', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/SHA256.php +++ pear/Message/HMAC/SHA256.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: SHA256.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the SHA256 algorithm */ class Message_HMAC_SHA256 extends Message_HMAC_Common { function Message_HMAC_SHA256($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_SHA256', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/TIGER.php +++ pear/Message/HMAC/TIGER.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: TIGER.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the TIGER algorithm */ class Message_HMAC_TIGER extends Message_HMAC_Common { function Message_HMAC_TIGER($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_TIGER', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/TIGER128.php +++ pear/Message/HMAC/TIGER128.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: TIGER128.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the TIGER128 algorithm */ class Message_HMAC_TIGER128 extends Message_HMAC_Common { function Message_HMAC_TIGER128($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_TIGER128', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/TIGER160.php +++ pear/Message/HMAC/TIGER160.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: TIGER160.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/HMAC/common.php'; /** * Wrapper class for HMAC signature calculation and validation using the TIGER160 algorithm */ class Message_HMAC_TIGER160 extends Message_HMAC_Common { function Message_HMAC_TIGER160($key, $ser = '', $enc = '') { $this->Message_HMAC_Common('MHASH_TIGER160', $key, $ser, $enc); } } ?> Index: pear/Message/HMAC/common.php +++ pear/Message/HMAC/common.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: common.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'PEAR.php'; require_once 'Message/common.php'; class Message_HMAC_Common extends Message_Common { var $key; function Message_HMAC_Common($hash_name, $key, $ser = '', $enc = '') { $this->Message_Common($hash_name, $ser, $enc); $this->key = $key; } function setKey($key) { $this->key = $key; } function calc($input, $ser = '', $enc = '') { if (!extension_loaded('mhash')) { return PEAR::raiseError('Extension mhash not found'); } else { $data = $this->getData($input); if (PEAR::isError($data)) return $data; if (!empty($ser)) $this->setSerialization($ser); if (!empty($enc)) $this->setEncoding($enc); $data = $this->serialize($data); $sig = mhash(constant($this->hash_name), $data, $this->key); return $this->encode($sig); } } function validate($input, $signature, $ser = '', $enc = '') { $data = $this->calc($input, $ser, $enc); if (PEAR::isError($data)) return $data; else return (boolean) ($data == $signature); } } ?> Index: pear/Message/Hash/ADLER32.php +++ pear/Message/Hash/ADLER32.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: ADLER32.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the ADLER32 algorithm */ class Message_Hash_ADLER32 extends Message_Hash_Common { function Message_Hash_ADLER32($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_ADLER32', $ser, $enc); } } ?> Index: pear/Message/Hash/CRC32.php +++ pear/Message/Hash/CRC32.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: CRC32.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the CRC32 algorithm */ class Message_Hash_CRC32 extends Message_Hash_Common { function Message_Hash_CRC32($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_CRC32', $ser, $enc); } } ?> Index: pear/Message/Hash/CRC32B.php +++ pear/Message/Hash/CRC32B.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: CRC32B.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the CRC32B algorithm */ class Message_Hash_CRC32B extends Message_Hash_Common { function Message_Hash_CRC32B($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_CRC32B', $ser, $enc); } } ?> Index: pear/Message/Hash/GOST.php +++ pear/Message/Hash/GOST.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: GOST.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the GOST algorithm */ class Message_Hash_GOST extends Message_Hash_Common { function Message_Hash_GOST($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_GOST', $ser, $enc); } } ?> Index: pear/Message/Hash/HAVAL128.php +++ pear/Message/Hash/HAVAL128.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL128.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the HAVAL128 algorithm */ class Message_Hash_HAVAL128 extends Message_Hash_Common { function Message_Hash_HAVAL128($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_HAVAL128', $ser, $enc); } } ?> Index: pear/Message/Hash/HAVAL160.php +++ pear/Message/Hash/HAVAL160.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL160.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the HAVAL160 algorithm */ class Message_Hash_HAVAL160 extends Message_Hash_Common { function Message_Hash_HAVAL160($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_HAVAL160', $ser, $enc); } } ?> Index: pear/Message/Hash/HAVAL192.php +++ pear/Message/Hash/HAVAL192.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL192.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the HAVAL192 algorithm */ class Message_Hash_HAVAL192 extends Message_Hash_Common { function Message_Hash_HAVAL192($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_HAVAL192', $ser, $enc); } } ?> Index: pear/Message/Hash/HAVAL224.php +++ pear/Message/Hash/HAVAL224.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL224.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the HAVAL224 algorithm */ class Message_Hash_HAVAL224 extends Message_Hash_Common { function Message_Hash_HAVAL224($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_HAVAL224', $ser, $enc); } } ?> Index: pear/Message/Hash/HAVAL256.php +++ pear/Message/Hash/HAVAL256.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: HAVAL256.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the HAVAL256 algorithm */ class Message_Hash_HAVAL256 extends Message_Hash_Common { function Message_Hash_HAVAL256($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_HAVAL256', $ser, $enc); } } ?> Index: pear/Message/Hash/MD4.php +++ pear/Message/Hash/MD4.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: MD4.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the MD4 algorithm */ class Message_Hash_MD4 extends Message_Hash_Common { function Message_Hash_MD4($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_MD4', $ser, $enc); } } ?> Index: pear/Message/Hash/MD5.php +++ pear/Message/Hash/MD5.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: MD5.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the MD5 algorithm */ class Message_Hash_MD5 extends Message_Hash_Common { function Message_Hash_MD5($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_MD5', $ser, $enc); } } ?> Index: pear/Message/Hash/RIPEMD160.php +++ pear/Message/Hash/RIPEMD160.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: RIPEMD160.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the RIPEMD160 algorithm */ class Message_Hash_RIPEMD160 extends Message_Hash_Common { function Message_Hash_RIPEMD160($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_RIPEMD160', $ser, $enc); } } ?> Index: pear/Message/Hash/SHA1.php +++ pear/Message/Hash/SHA1.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: SHA1.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the SHA1 algorithm */ class Message_Hash_SHA1 extends Message_Hash_Common { function Message_Hash_SHA1($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_SHA1', $ser, $enc); } } ?> Index: pear/Message/Hash/SHA256.php +++ pear/Message/Hash/SHA256.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: SHA256.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the SHA256 algorithm */ class Message_Hash_SHA256 extends Message_Hash_Common { function Message_Hash_SHA256($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_SHA256', $ser, $enc); } } ?> Index: pear/Message/Hash/TIGER.php +++ pear/Message/Hash/TIGER.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: TIGER.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the TIGER algorithm */ class Message_Hash_TIGER extends Message_Hash_Common { function Message_Hash_TIGER($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_TIGER', $ser, $enc); } } ?> Index: pear/Message/Hash/TIGER128.php +++ pear/Message/Hash/TIGER128.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: TIGER128.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the TIGER128 algorithm */ class Message_Hash_TIGER128 extends Message_Hash_Common { function Message_Hash_TIGER128($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_TIGER128', $ser, $enc); } } ?> Index: pear/Message/Hash/TIGER160.php +++ pear/Message/Hash/TIGER160.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: TIGER160.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'Message/Hash/common.php'; /** * Wrapper class for data hashing using the TIGER160 algorithm */ class Message_Hash_TIGER160 extends Message_Hash_Common { function Message_Hash_TIGER160($ser = '', $enc = '') { $this->Message_Hash_Common('MHASH_TIGER160', $ser, $enc); } } ?> Index: pear/Message/Hash/common.php +++ pear/Message/Hash/common.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: common.php,v 1.1 2002/10/02 03:54:19 jmcastagnetto Exp $ // require_once 'PEAR.php'; require_once 'Message/common.php'; class Message_Hash_Common extends Message_Common { function Message_Hash_Common($hash_name, $ser = '', $enc = '') { $this->Message_Common($hash_name, $ser, $enc); } function calc($input, $ser = '', $enc = '') { if (!extension_loaded('mhash')) { return PEAR::raiseError('Extension mhash not found'); } else { $data = $this->getData($input); if (PEAR::isError($data)) return $data; if (!empty($ser)) $this->setSerialization($ser); if (!empty($enc)) $this->setEncoding($enc); $data = $this->serialize($data); $hash = mhash(constant($this->hash_name), $data); return $this->encode($hash); } } } ?> Index: pear/Message/misc/mkclasses.php +++ pear/Message/misc/mkclasses.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: mkclasses.php,v 1.1 2002/10/02 03:54:20 jmcastagnetto Exp $ // /** * Utility script to generate the wrapper classes */ $cannot_hmac = array('CRC32', 'GOST', 'CRC32B', 'ADLER32'); $hash_proto = implode('',file('./hash_proto')); $hmac_proto = implode('',file('./hmac_proto')); $nhashes = mhash_count(); for ($i=0; $i <= $nhashes ; $i++) { $hname = mhash_get_hash_name($i); if (trim($hname) == '') { continue; } else { $fname = "../Hash/{$hname}.php"; echo "Creating $fname\n"; $out = str_replace('##proto##', $hname, $hash_proto); $fp = fopen($fname, 'w'); fwrite($fp, $out); fclose($fp); if (!in_array($hname, $cannot_hmac)) { $fname = "../HMAC/{$hname}.php"; echo "Creating $fname\n"; $out = str_replace('##proto##', $hname, $hmac_proto); $fp = fopen($fname, 'w'); fwrite($fp, $out); fclose($fp); } } } ?> Index: pear/Message/misc/rfc2104_testvectors.php +++ pear/Message/misc/rfc2104_testvectors.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: rfc2104_testvectors.php,v 1.1 2002/10/02 03:54:20 jmcastagnetto Exp $ // /** * Test package by using the test vectors from the RFC 2104 */ require_once 'Message/Message.php'; echo "Test Vectors from rfc 2104\n\n"; echo "* Using static calls\n\n"; $key1 = str_repeat(chr(0x0b), 16); $data1 = "Hi There"; echo "rfc 2104 output: 0x9294727a3638bb1c13f48ef8158bfc9d\n"; echo 'key: 0x'.str_repeat('0b', 16)."\n"; echo "data: $data1\n"; echo "md5 HMAC: ".Message::calcHMAC('MD5', $data1, $key1)."\n\n"; $key2 = "Jefe"; $data2 = "what do ya want for nothing?"; echo "rfc 2104 output: 0x750c783e6ab0b503eaa86e310a5db738\n"; echo "key: $key2\n"; echo "data: $data2\n"; echo "md5 HMAC: ".Message::calcHMAC('MD5', $data2, $key2)."\n\n"; $key3 = str_repeat(chr(0xAA), 16); $data3 = str_repeat(chr(0xDD), 50); echo "rfc 2104 output: 0x56be34521d144c88dbb8c733f0e8b3f6\n"; echo 'key: 0x'.str_repeat('AA', 16)."\n"; echo 'data: 0x'.wordwrap(str_repeat('DD', 50),30,"\n",1)."\n"; echo "md5 HMAC: ".Message::calcHMAC('MD5', $data3, $key3)."\n\n"; echo "\n* Using a Message_HMAC_MD5 object\n\n"; $md5 =& Message::createHMAC('MD5', $key1); echo "rfc 2104 output: 0x9294727a3638bb1c13f48ef8158bfc9d\n"; echo 'key: 0x'.str_repeat('0b', 16)."\n"; echo "data: $data1\n"; echo "md5 HMAC: ".$md5->calc($data1)."\n\n"; $md5->setKey($key2); echo "rfc 2104 output: 0x750c783e6ab0b503eaa86e310a5db738\n"; echo "key: $key2\n"; echo "data: $data2\n"; echo "md5 HMAC: ".$md5->calc($data2)."\n\n"; $md5->setKey($key3); echo "rfc 2104 output: 0x56be34521d144c88dbb8c733f0e8b3f6\n"; echo 'key: 0x'.str_repeat('AA', 16)."\n"; echo 'data: 0x'.wordwrap(str_repeat('DD', 50),30,"\n",1)."\n"; echo "md5 HMAC: ".$md5->calc($data3)."\n\n"; ?> Index: pear/Message/misc/rfc2202_test.php +++ pear/Message/misc/rfc2202_test.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: rfc2202_test.php,v 1.1 2002/10/02 03:54:20 jmcastagnetto Exp $ // /** * Testing using test vectors from RFC 2202, for HMAC MD5 and HMAC SHA1 */ require_once 'Message/Message.php'; $key4 = ''; foreach (range(0x01,0x19) as $hex) $key4 .= chr($hex); $hmac_md5_list = array ( 1 => array( 'key' => str_repeat(chr(0x0b), 16), 'data' => 'Hi There', 'digest' => '9294727a3638bb1c13f48ef8158bfc9d' ), 2 => array( 'key' => 'Jefe', 'data' => 'what do ya want for nothing?', 'digest' => '750c783e6ab0b503eaa86e310a5db738' ), 3 => array( 'key' => str_repeat(chr(0xaa), 16), 'data' => str_repeat(chr(0xdd), 50), 'digest' => '56be34521d144c88dbb8c733f0e8b3f6' ), 4 => array( 'key' => $key4, 'data' => str_repeat(chr(0xcd), 50), 'digest' => '697eaf0aca3a3aea3a75164746ffaa79' ), 5 => array( 'key' => str_repeat(chr(0x0c), 16), 'data' => 'Test With Truncation', 'digest' => '56461ef2342edc00f9bab995690efd4c' ), 6 => array( 'key' => str_repeat(chr(0xaa), 80), 'data' => 'Test Using Larger Than Block-Size Key - Hash Key First', 'digest' => '6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd' ), 7 => array( 'key' => str_repeat(chr(0xaa), 80), 'data' => 'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data', 'digest' => '6f630fad67cda0ee1fb1f562db3aa53e' ) ); $hmac_sha1_list = array ( 1 => array( 'key' => str_repeat(chr(0x0b), 20), 'data' => 'Hi There', 'digest' => 'b617318655057264e28bc0b6fb378c8ef146be00' ), 2 => array( 'key' => 'Jefe', 'data' => 'what do ya want for nothing?', 'digest' => 'effcdf6ae5eb2fa2d27416d5f184df9c259a7c79' ), 3 => array( 'key' => str_repeat(chr(0xaa), 20), 'data' => str_repeat(chr(0xdd), 50), 'digest' => '125d7342b9ac11cd91a39af48aa17b4f63f175d3' ), 4 => array( 'key' => $key4, 'data' => str_repeat(chr(0xcd), 50), 'digest' => '4c9007f4026250c6bc8414f9bf50c86c2d7235da' ), 5 => array( 'key' => str_repeat(chr(0x0c), 20), 'data' => 'Test With Truncation', 'digest' => '4c1a03424b55e07fe7f27be1d58bb9324a9a5a04' ), 6 => array( 'key' => str_repeat(chr(0xaa), 80), 'data' => 'Test Using Larger Than Block-Size Key - Hash Key First', 'digest' => 'aa4ae5e15272d00e95705637ce8a3b55ed402112' ), 7 => array( 'key' => str_repeat(chr(0xaa), 80), 'data' => 'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data', 'digest' => 'e8e99d0f45237d786d6bbaa7965c7808bbff1a91' ) ); function run($digest_name, $testvector_list) { $re = '/([[:alnum:] -])+/'; echo "\n*** HMAC $digest_name ***\n\n"; foreach ($testvector_list as $case=>$test) { $digest = Message::calcHMAC($digest_name, $test['data'], $test['key']); $keylen = strlen($test['key']); $datalen = strlen($test['data']); $out = "test case: $case\n"; if (preg_match($re, $test['key'])) { $out .= sprintf("key:\t'%s'\n", $test['key']); } else { $out .= sprintf("key:\t0x%s\n", bin2hex($test['key'])); } $out .= sprintf("key_len:\t%d\n", $keylen); if (preg_match($re, $test['data'])) { $out .= sprintf("data:\t'%s'\n", $test['data']); } else { $out .= sprintf("data:\t0x%s\n", bin2hex($test['data'])); } $out .= sprintf("data_len:\t%d\n", $datalen). sprintf("digest (rfc):\t0x%s\n", $test['digest']). sprintf("digest (calc):\t0x%s\n", $digest). sprintf("\tdigest(rfc) == digest(calc) : %s\n", ($test['digest'] == $digest) ? 'true' : 'false'); echo "$out\n"; } } run('MD5', $hmac_md5_list); run('SHA1', $hmac_sha1_list); ?> Index: pear/Message/misc/testmessage.php +++ pear/Message/misc/testmessage.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.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: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // // $Id: testmessage.php,v 1.1 2002/10/02 03:54:20 jmcastagnetto Exp $ // /** * Example of use of PEAR::Message */ include_once 'Message/Message.php'; $data = 'abc'; $data2 = 'abd'; $key = 'metalloproteins rule'; echo "Using 'abc' as data\n\n"; $hash = Message::createHash('MD5'); echo 'MD5: '.$hash->calc($data)."\n"; $hash2 = Message::createHash('SHA1'); echo 'SHA1: '.$hash2->calc($data)."\n"; echo "\nUsing '$key' as key\n\n"; $hmac = Message::createHMAC('MD5',$key); $sig_md5 = $hmac->calc($data); $valid = (int) $hmac->validate($data,$sig_md5); $hmac2 = Message::createHMAC('SHA1', $key); $sig_sha1 = $hmac2->calc($data); echo "HMAC MD5: {$sig_md5}\n"; echo "HMAC SHA1: {$sig_sha1}\n"; echo "Validating: hmac('$data', '$key') == sig_md5 --> {$valid}\n"; echo "\nUsing 'abd' as data:\n\n"; $valid2 = (int) $hmac->validate($data2,$sig_md5); echo "Validating: hmac('$data2', '$key') == sig_md5 --> {$valid2}\n"; echo "\nUsing a file resource as data input\n"; $fp = fopen('./testmessage.php', 'r'); // know thyself echo 'resource: '.get_resource_type($fp)."\n"; $file_hash = $hash->calc($fp); rewind($fp); $file_hmac = $hmac->calc($fp); rewind($fp); $file_validate = (int) $hmac->validate($fp, $file_hmac); fclose($fp); echo "MD5 hash: $file_hash\n"; echo "MD5 HMAC: $file_hmac\n"; echo "MD5 HMAC validate : $file_validate\n"; echo "\nUsing a gzip'ed file resource as data input\n"; $fp = gzopen('./testfile.gz', 'r'); // know thyself echo 'resource: '.get_resource_type($fp)."\n"; $file_hash = $hash->calc($fp); gzrewind($fp); $file_hmac = $hmac->calc($fp); gzrewind($fp); $file_validate = (int) $hmac->validate($fp, $file_hmac); gzclose($fp); echo "MD5 hash: $file_hash\n"; echo "MD5 HMAC: $file_hmac\n"; echo "MD5 HMAC validate : $file_validate\n"; echo "\nUsing a fsockopen resource as data input\n"; $fp = fsockopen("www.google.com", "80"); echo 'resource: '.get_resource_type($fp)."\n"; fputs($fp, "HEAD / HTTP/1.0\n\r\n\r"); $file_hash = $hash->calc($fp); fclose($fp); $fp = fsockopen("www.google.com", "80"); fputs($fp, "HEAD / HTTP/1.0\n\r\n\r"); $file_hmac = $hmac->calc($fp); fclose($fp); $fp = fsockopen("www.google.com", "80"); fputs($fp, "HEAD / HTTP/1.0\n\r\n\r"); $file_validate = (int) $hmac->validate($fp, $file_hmac); fclose($fp); echo "MD5 hash: $file_hash\n"; echo "MD5 HMAC: $file_hmac\n"; echo "MD5 HMAC validate : $file_validate\n"; echo "\t* it should not validate as the headers returned contain a timestamp\n"; echo "\nUsing static method calls\n\n"; $cannot_hmac = array('CRC32', 'GOST', 'CRC32B', 'ADLER32'); $nhashes = mhash_count(); for ($i=0; $i <= $nhashes ; $i++) { $hname = mhash_get_hash_name($i); if (trim($hname) == '') { continue; } else { echo "Message::calcHash('$hname','abc') : ".Message::calcHash($hname, $data)."\n"; if (!in_array($hname, $cannot_hmac)) { echo "Message::calcHMAC('$hname','abc', key) : ".Message::calcHMAC($hname, $data, $key)."\n"; } else { echo "\t** $hname cannot be used for HMAC\n"; } } } ?>