pssht  latest
SSH server library written in PHP
Base.php
1 <?php
2 
3 /*
4 * This file is part of pssht.
5 *
6 * (c) François Poirotte <clicky@erebot.net>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 
12 namespace fpoirotte\Pssht\MAC;
13 
17 
21 abstract class Base implements
25 {
27  protected $key;
28 
29  final public function __construct($key)
30  {
31  $this->key = $key;
32  }
33 
34  final public function compute($seqno, $data)
35  {
36  $cls = get_called_class();
37  return hash_hmac($cls::getHash(), pack('N', $seqno) . $data, $this->key, true);
38  }
39 
40  final public static function getKeySize()
41  {
42  $cls = get_called_class();
43  return strlen(hash($cls::getHash(), '', true));
44  }
45 
46  final public static function getSize()
47  {
48  return static::getKeySize();
49  }
50 
51  final public static function isAvailable()
52  {
53  if (!function_exists('hash_algos') ||
54  !function_exists('hash') ||
55  !function_exists('hash_hmac')) {
56  return false;
57  }
58  $cls = get_called_class();
59  return in_array($cls::getHash(), hash_algos(), true);
60  }
61 }
compute($seqno, $data)
Definition: Base.php:34
static isAvailable()
Definition: Base.php:51
$key
Secret key for MAC operations.
Definition: Base.php:27
static getKeySize()
Definition: Base.php:40