add methods to decrypt return data from router
[GitHub/Stricted/speedport-hybrid-php-api.git] / CryptLib / Random / Mixer / DES.php
1 <?php
2 /**
3 * The DES medium strength mixer class
4 *
5 * This class implements a mixer based upon the recommendations in RFC 4086
6 * section 5.2
7 *
8 * PHP version 5.3
9 *
10 * @see http://tools.ietf.org/html/rfc4086#section-5.2
11 * @category PHPCryptLib
12 * @package Random
13 * @subpackage Mixer
14 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
15 * @copyright 2011 The Authors
16 * @license http://www.opensource.org/licenses/mit-license.html MIT License
17 * @version Build @@version@@
18 */
19
20 namespace CryptLib\Random\Mixer;
21
22 use \CryptLib\Cipher\Factory as CipherFactory;
23 use \CryptLib\Core\Strength;
24
25 /**
26 * The DES medium strength mixer class
27 *
28 * This class implements a mixer based upon the recommendations in RFC 4086
29 * section 5.2
30 *
31 * @see http://tools.ietf.org/html/rfc4086#section-5.2
32 * @category PHPCryptLib
33 * @package Random
34 * @subpackage Mixer
35 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
36 */
37 class DES extends \CryptLib\Random\AbstractMixer {
38
39 /**
40 * An instance of a DES symmetric encryption cipher
41 *
42 * @var Cipher The DES cipher instance
43 */
44 protected $cipher = 'des';
45
46 /**
47 * Return an instance of Strength indicating the strength of the source
48 *
49 * @return Strength An instance of one of the strength classes
50 */
51 public static function getStrength() {
52 return new Strength(Strength::MEDIUM);
53 }
54
55 /**
56 * Test to see if the mixer is available
57 *
58 * @return boolean If the mixer is available on the system
59 */
60 public static function test() {
61 return true;
62 }
63
64 /**
65 * Build a new instance of the DES mixing function
66 *
67 * @param Factory $factory The optional encryption factory to use
68 *
69 * @return void
70 */
71 public function __construct(\CryptLib\Cipher\Factory $factory = null) {
72 if (is_null($factory)) {
73 $factory = new CipherFactory();
74 }
75 $this->cipher = $factory->getBlockCipher($this->cipher);
76 }
77
78 /**
79 * Get the block size (the size of the individual blocks used for the mixing)
80 *
81 * @return int The block size
82 */
83 protected function getPartSize() {
84 return $this->cipher->getBlockSize();
85 }
86
87 /**
88 * Mix 2 parts together using one method
89 *
90 * @param string $part1 The first part to mix
91 * @param string $part2 The second part to mix
92 *
93 * @return string The mixed data
94 */
95 protected function mixParts1($part1, $part2) {
96 $this->cipher->setKey($part2);
97 return $this->cipher->encryptBlock($part1);
98 }
99
100 /**
101 * Mix 2 parts together using another different method
102 *
103 * @param string $part1 The first part to mix
104 * @param string $part2 The second part to mix
105 *
106 * @return string The mixed data
107 */
108 protected function mixParts2($part1, $part2) {
109 $this->cipher->setKey($part1);
110 return $this->cipher->decryptBlock($part2);
111 }
112
113 }