note 101540 added to function.hash-hmac

From: Date: Thu, 23 Dec 2010 11:44:48 +0000
Subject: note 101540 added to function.hash-hmac
Groups: php.notes 
Request: Send a blank email to php-notes+get-175159@lists.php.net to get a copy of this message
The Implementation of the PBKDF2 key derivation function as described in RFC 2898 can be used to not only get the hashed KEY but also a specific IV. To use, one would use it as follows:- $p = str_hash_pbkdf2($pw, $salt, 10, 32, 'sha1'); $p = base64_encode($p); $iv = str_hash_pbkdf2($pw, $salt, 10, 16, 'sha1', 32); $iv = base64_encode($iv); The function should be:- // PBKDF2 Implementation (described in RFC 2898) // // @param string p password // @param string s salt // @param int c iteration count (use 1000 or higher) // @param int kl derived key length // @param string a hash algorithm // @param int st start position of result // // @return string derived key function str_hash_pbkdf2($p, $s, $c, $kl, $a = 'sha256', $st=0) { $kb = $start+$kl; // Key blocks to compute $dk = ''; // Derived key // Create key for ($block=1; $block<=$kb; $block++) { // Initial hash for this block $ib = $h = hash_hmac($a, $s . pack('N', $block), $p, true); // Perform block iterations for ($i=1; $i<$c; $i++) { // XOR each iterate $ib ^= ($h = hash_hmac($a, $h, $p, true)); } $dk .= $ib; // Append iterated block } // Return derived key of correct length return substr($dk, $start, $kl); } ---- Server IP: 64.71.164.2 Probable Submitter: 212.9.31.132 ---- Manual Page -- http://www.php.net/manual/en/function.hash-hmac.php Edit -- https://master.php.net/note/edit/101540 Del: integrated -- https://master.php.net/note/delete/101540/integrated Del: useless -- https://master.php.net/note/delete/101540/useless Del: bad code -- https://master.php.net/note/delete/101540/bad+code Del: spam -- https://master.php.net/note/delete/101540/spam Del: non-english -- https://master.php.net/note/delete/101540/non-english Del: in docs -- https://master.php.net/note/delete/101540/in+docs Del: other reasons-- https://master.php.net/note/delete/101540 Reject -- https://master.php.net/note/reject/101540 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175159) next »