Location: PHPKode > scripts > PHP Time One Time Password > php-time-one-time-password/totp_p512.class.php
<?php

// include super class
require_once('totp.class.php');

/**
 * Project:     PHP Time One Time Password
 * File:        totp_p512.class.php
 * Purpose		One time password for PHP Version < 5.1.2
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * For questions, help, comments, discussion, etc., please send
 * e-mail to hide@address.com
 *
 * @link http://www.protung.ro/
 * @copyright 2008 Dragos Protung
 * @author Dragos Protung <hide@address.com>
 * @package PHP Time One Time Password
 * @version 1.0
 */ 
class TOTP_P512 extends TOTP {

	
	/**
	 * Generate a keyed hash value using the HMAC method
	 * for PHP < 5.1.2
	 *
	 * @param string $data - data to be hashed
	 * @param string $hashFunct - hash function to be used
	 * @param bool $rawOutput - if the output should be binary data or hex
	 * @return string
	 */
	private function hmac($data, $hashFunct = self::DEFAULT_HASH, $rawOutput = false) {
		
		if (!function_exists($hashFunct)) {
			$hashFunct = self::DEFAULT_HASH;
		}
		
		$blocksize = 64;
		if (strlen ( $this->secretKey ) > $blocksize) {
			$this->secretKey = pack('H*', $hashFunct($this->secretKey));
		}
		
		$this->secretKey = str_pad($this->secretKey, $blocksize, chr (0x00));
		$ipad = str_repeat(chr(0x36), $blocksize);
		$opad = str_repeat(chr(0x5c), $blocksize);
		$hmac = pack ('H*', $hashFunct(($this->secretKey^$opad).pack('H*', $hashFunct(($this->secretKey^$ipad).$data))));
		
		if ($rawOutput === true) {
			return $hmac;
		} else {
			return bin2hex($hmac);
		}
	}
}

?>
Return current item: PHP Time One Time Password