예제 #1
0
 function check_implementation()
 {
     $blowfish = new Blowfish("");
     $vectors = array(array(array(0x0, 0x0), array(0x0, 0x0), array(0x4ef99745, 0x6198dd78)), array(array(0xffffffff, 0xffffffff), array(0xffffffff, 0xffffffff), array(0x51866fd5, 0xb85ecb8a)), array(array(0x1234567, 0x89abcdef), array(0x11111111, 0x11111111), array(0x61f9c380, 0x2281b096)));
     //Correct implementation?
     $correct = true;
     //Test vectors, see http://www.schneier.com/code/vectors.txt
     foreach ($vectors as $vector) {
         $key = $vector[0];
         $plain = $vector[1];
         $cipher = $vector[2];
         $blowfish->key_setup($key);
         $return = $blowfish->block_encrypt($vector[1][0], $vector[1][1]);
         if ($return[0] != $cipher[0] || $return[1] != $cipher[1]) {
             $correct = false;
         }
     }
     return $correct;
 }