Implementacja algorytmu P_SHA1 w PHP

próbujemy zaimplementować funkcję P_SHA1 oznacza PHP. Wzór funkcji napisanej w Pythonie. Niestety, coś nie działa prawidłowo. Oto funkcja implementacji w JAVA:http://ws.apache.org/wss4j/xref/org/apache/ws/security/conversation/dkalgo/P_SHA1.html

nasz kod:

<?php
  $newSeed    = $label . $seed; // concat as strings
  // $p_sha1
  $psha1 = p_hash('sha1', $secret, $newSeed, $length);
  $string = arrayToBytes($psha1);
  /**
  * P_SHA1 crypto alg calculation
  *
  * @return array of bytes - key
  **/
  function p_hash($algo, $secret, $seed, $length) {
    $bytes = array_fill(0, $length, 0); 
    $tmp = null;
    $A = $seed;
    $index = 0;

    while (1) {
      // hmac sha1: secret + seed
      $A = hash_hmac($algo, $secret, $A, true);

      // hmac sha1: secret + 1st hash + seed
      $output = hash_hmac($algo, $secret, ($A . $seed), true);

      foreach (bytesToArray($output) as $c) {
          if ($index >= $length) {
              return $bytes;
          }

          $bytes[$index] = $c;
          $index++;
      }
    }
    return $bytes;
}

function bytesToArray($bytes) { return unpack('C*', $bytes); }
function arrayToBytes($array) { return call_user_func_array("pack", array_merge(array("C*"), $array)); }
?>

Może ktoś wie, gdzie mogę znaleźć gotowe rozwiązanie? Czy ktoś może pomóc w poprawnym działaniu skryptu?

questionAnswers(3)

yourAnswerToTheQuestion