Completed
Push — master ( a1466a...d2511d )
by Anthony
02:22
created

XorMixer::getStrength()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * The RandomLib library for securely generating random numbers and strings in PHP
5
 *
6
 * @author     Anthony Ferrara <[email protected]>
7
 * @copyright  2011 The Authors
8
 * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
9
 * @version    Build @@version@@
10
 */
11
12
/**
13
 * The Hash medium strength mixer class
14
 *
15
 * This class implements a mixer based upon the recommendations in RFC 4086
16
 * section 5.2
17
 *
18
 * PHP version 5.3
19
 *
20
 * @see        http://tools.ietf.org/html/rfc4086#section-5.2
21
 *
22
 * @category   PHPCryptLib
23
 * @package    Random
24
 * @subpackage Mixer
25
 *
26
 * @author     Anthony Ferrara <[email protected]>
27
 * @copyright  2011 The Authors
28
 * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
29
 *
30
 * @version    Build @@version@@
31
 */
32
namespace RandomLib\Mixer;
33
34
use SecurityLib\Strength;
35
36
/**
37
 * The Hash medium strength mixer class
38
 *
39
 * This class implements a mixer based upon the recommendations in RFC 4086
40
 * section 5.2
41
 *
42
 * @see        http://tools.ietf.org/html/rfc4086#section-5.2
43
 *
44
 * @category   PHPCryptLib
45
 * @package    Random
46
 * @subpackage Mixer
47
 *
48
 * @author     Anthony Ferrara <[email protected]>
49
 */
50
class XorMixer extends \RandomLib\AbstractMixer
51
{
52
53
    /**
54
     * Return an instance of Strength indicating the strength of the source
55
     *
56
     * @return \SecurityLib\Strength An instance of one of the strength classes
57
     */
58
    public static function getStrength()
59
    {
60
        return new Strength(Strength::VERYLOW);
61
    }
62
63
    /**
64
     * Test to see if the mixer is available
65
     *
66
     * @return bool If the mixer is available on the system
67
     */
68
    public static function test()
69
    {
70
        return true;
71
    }
72
73
    /**
74
     * Get the block size (the size of the individual blocks used for the mixing)
75
     *
76
     * @return int The block size
77
     */
78
    protected function getPartSize()
79
    {
80
        return 64;
81
    }
82
83
    /**
84
     * Mix 2 parts together using one method
85
     *
86
     * @param string $part1 The first part to mix
87
     * @param string $part2 The second part to mix
88
     *
89
     * @return string The mixed data
90
     */
91
    protected function mixParts1($part1, $part2)
92
    {
93
        return $part1 ^ $part2;
94
    }
95
96
    /**
97
     * Mix 2 parts together using another different method
98
     *
99
     * @param string $part1 The first part to mix
100
     * @param string $part2 The second part to mix
101
     *
102
     * @return string The mixed data
103
     */
104
    protected function mixParts2($part1, $part2)
105
    {
106
        // Both mixers are identical, this is for speed, not security
107
        return $part1 ^ $part2;
108
    }
109
}
110