Beispiel #1
0
 static function parse(&$input)
 {
     $s2k = new S2K();
     switch ($s2k->type = ord($input[0])) {
         case 0:
             $s2k->hash_algorithm = ord($input[1]);
             $input = substr($input, 2);
             break;
         case 1:
             $s2k->hash_algorithm = ord($input[1]);
             $s2k->salt = substr($input, 2, 8);
             $input = substr($input, 10);
             break;
         case 3:
             $s2k->hash_algorithm = ord($input[1]);
             $s2k->salt = substr($input, 2, 8);
             $s2k->count = \OpenPGP\Util::decode_s2k_count(ord($input[10]));
             $input = substr($input, 11);
             break;
     }
     return $s2k;
 }
Beispiel #2
0
 static function encode_s2k_count($iterations)
 {
     if ($iterations >= 65011712) {
         return 255;
     }
     $count = $iterations >> 6;
     $c = 0;
     while ($count >= 32) {
         $count = $count >> 1;
         $c++;
     }
     $result = $c << 4 | $count - 16;
     if (\OpenPGP\Util::decode_s2k_count($result) < $iterations) {
         return $result + 1;
     }
     return $result;
 }