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 
13 
17 abstract class Base implements
19  \fpoirotte\Pssht\Algorithms\AvailabilityInterface
20 {
22  protected $umac;
23 
25  protected $key;
26 
27  final public function compute($seqno, $data)
28  {
29  $encoder = new \fpoirotte\Pssht\Wire\Encoder();
30  $nonce = $encoder->encodeUint64($seqno)->getBuffer()->get(0);
31  $res = $this->umac->umac($this->key, $data, $nonce);
32  return $res;
33  }
34 
35  final public static function isAvailable()
36  {
37  if (!extension_loaded('mcrypt')) {
38  return false;
39  }
40 
41  if (!defined('MCRYPT_RIJNDAEL_128')) {
42  return false;
43  }
44  $res = @mcrypt_module_open(
45  MCRYPT_RIJNDAEL_128,
46  '',
47  'ecb',
48  ''
49  );
50  if ($res !== false) {
51  mcrypt_module_close($res);
52  }
53  return (bool) $res;
54  }
55 }
$umac
Underlying UMAC implementation.
Definition: Base.php:22