Skip to content

Commit 76e408c

Browse files
committed
Added better testing of generateInt, removed SUHOSIN demoting of URandom source
1 parent 6109c77 commit 76e408c

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

lib/CryptLib/Random/Source/URandom.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ class URandom implements \CryptLib\Random\Source {
3838
* @return Strength An instance of one of the strength classes
3939
*/
4040
public static function getStrength() {
41-
//This source is over-used by Suhosin patch, the strength is lowered
42-
if (defined('S_ALL')) {
43-
return new Strength(Strength::LOW);
44-
} else {
45-
return new Strength(Strength::MEDIUM);
46-
}
41+
return new Strength(Strength::MEDIUM);
4742
}
4843

4944
/**

test/Unit/Random/Source/URandomTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ public static function provideGenerate() {
2121
* @covers CryptLib\Random\Source\URandom::getStrength
2222
*/
2323
public function testGetStrength() {
24-
if (defined('S_ALL')) {
25-
$strength = new Strength(Strength::LOW);
26-
} else {
27-
$strength = new Strength(Strength::MEDIUM);
28-
}
24+
$strength = new Strength(Strength::MEDIUM);
2925
$actual = URandom::getStrength();
3026
$this->assertEquals($actual, $strength);
3127
}

test/Vectors/Random/GeneratorTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,29 @@ public static function provideGenerateInt() {
2626
array(10, 100, 1),
2727
// Finally, let's try two large numbers
2828
array(100000, 100007, 5),
29-
array(100000000, 100002047, 5)
29+
array(100000000, 100002047, 5),
30+
// Now, let's force a few loops by setting a valid offset
31+
array(0, 5, 5, 2),
32+
array(0, 9, 4, 2),
33+
array(0, 27, 3, 4),
3034
);
3135
}
3236

3337
/**
3438
* This test asserts that the algorithm that generates the integers does not
35-
* actually introduce any bias into the generated numbers. If this test
39+
* actually introduce any bias into the generated numbers. If this test
3640
* passes, the generated integers from the generator will be as unbiased as
3741
* the sources that provide the data.
38-
*
42+
*
3943
* @dataProvider provideGenerateInt
4044
*/
41-
public function testGenerateInt($min, $max, $shift) {
42-
$generator = $this->getGenerator($max - $min, $shift);
45+
public function testGenerateInt($min, $max, $shift, $offset = 0) {
46+
$generator = $this->getGenerator($max - $min + $offset, $shift);
4347
for ($i = $max; $i >= $min; $i--) {
4448
$this->assertEquals($i, $generator->generateInt($min, $max));
4549
}
4650
}
47-
51+
4852
public function getGenerator($random, $shift) {
4953
$source1 = new Source(array(
5054
'generate' => function ($size) use (&$random, $shift) {

0 commit comments

Comments
 (0)