-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.php
55 lines (52 loc) · 1.13 KB
/
benchmark.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
function unHex( $str ) {
return pack( 'H*', $str );
}
function randomString( $len ) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$str = '';
for( $j = 0; $j < $len; $j++ ) {
$str .= $characters[rand(0, strlen($characters)-1)];
}
return $str;
}
function runTestString( $str ) {
$parts = explode( "+", trim($str) );
if( count( $parts ) < 3 ) {
print "Bad input data...\n";
return false;
}
$pk = $parts[0];
$sig = $parts[1];
$msg = unHex( $parts[2] );
$v = sqrl_verify( $msg, $sig, $pk );
if( strlen( $msg == 0 ))
$alteredMsg = randomString( 1 );
else
$alteredMsg = randomString( strlen( $msg ));
$av = sqrl_verify( $alteredMsg, $sig, $pk );
if( $v && !$av ) {
return true;
}
return false;
}
for( $i = 0; $i < 100; $i++ ) {
$handle = @fopen( "tests/003.input", "r" );
$error = false;
$line = 1;
if( $handle ) {
while(( $buffer = fgets( $handle, 8192 )) !== false ) {
if( !runTestString( $buffer )) {
$error = true;
}
$line++;
}
fclose( $handle );
} else {
print "Unable to open file...\n";
}
if( $error ) {
print "Something went wrong...\n";
}
}
?>