3 * The DES medium strength mixer class
5 * This class implements a mixer based upon the recommendations in RFC 4086
10 * @see http://tools.ietf.org/html/rfc4086#section-5.2
11 * @category PHPCryptLib
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@@
20 namespace CryptLib\Random\Mixer
;
22 use \CryptLib\Cipher\Factory
as CipherFactory
;
23 use \CryptLib\Core\Strength
;
26 * The DES medium strength mixer class
28 * This class implements a mixer based upon the recommendations in RFC 4086
31 * @see http://tools.ietf.org/html/rfc4086#section-5.2
32 * @category PHPCryptLib
35 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
37 class DES
extends \CryptLib\Random\AbstractMixer
{
40 * An instance of a DES symmetric encryption cipher
42 * @var Cipher The DES cipher instance
44 protected $cipher = 'des';
47 * Return an instance of Strength indicating the strength of the source
49 * @return Strength An instance of one of the strength classes
51 public static function getStrength() {
52 return new Strength(Strength
::MEDIUM
);
56 * Test to see if the mixer is available
58 * @return boolean If the mixer is available on the system
60 public static function test() {
65 * Build a new instance of the DES mixing function
67 * @param Factory $factory The optional encryption factory to use
71 public function __construct(\CryptLib\Cipher\Factory
$factory = null) {
72 if (is_null($factory)) {
73 $factory = new CipherFactory();
75 $this->cipher
= $factory->getBlockCipher($this->cipher
);
79 * Get the block size (the size of the individual blocks used for the mixing)
81 * @return int The block size
83 protected function getPartSize() {
84 return $this->cipher
->getBlockSize();
88 * Mix 2 parts together using one method
90 * @param string $part1 The first part to mix
91 * @param string $part2 The second part to mix
93 * @return string The mixed data
95 protected function mixParts1($part1, $part2) {
96 $this->cipher
->setKey($part2);
97 return $this->cipher
->encryptBlock($part1);
101 * Mix 2 parts together using another different method
103 * @param string $part1 The first part to mix
104 * @param string $part2 The second part to mix
106 * @return string The mixed data
108 protected function mixParts2($part1, $part2) {
109 $this->cipher
->setKey($part1);
110 return $this->cipher
->decryptBlock($part2);