-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck_random.inc
143 lines (137 loc) · 4.33 KB
/
check_random.inc
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use Config;
sub warn_or_diag {
if ($INC{'Test/More.pm'}) {
diag(@_);
} else {
warn @_;
}
}
my $test_file_name = 'test.c';
my $binary_name = 'a.out';
my $output = q[];
open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!";
print FOO <<'_OUT_';
#include <sys/types.h>
#include <sys/random.h>
int main(void)
{
char buf[5];
int l = 5;
unsigned int o = 1;
int r = getrandom(buf, l, o);
return 0;
}
_OUT_
close FOO or die "Failed to close $test_file_name:$!";
$output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`;
unlink $test_file_name or die "Failed to unlink $test_file_name:$!";
if ($? == 0) {
warn_or_diag "getrandom from sys/random is AVAILABLE\n";
unlink $binary_name or die "Failed to unlink $binary_name:$!";
$optional{DEFINE} = '-DHAVE_CRYPT_URANDOM_NATIVE_GETRANDOM';
} else {
warn_or_diag "getrandom from sys/random is unavailable\n";
open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!";
print FOO <<'_OUT_';
#include <sys/syscall.h>
int main(void)
{
char buf[5];
int l = 5;
unsigned int o = 1;
int r = syscall(SYS_getrandom, buf, l, o);
return 0;
}
_OUT_
close FOO or die "Failed to close $test_file_name:$!";
$output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`;
if ($? == 0) {
warn_or_diag "SYS_getrandom from sys/syscall is AVAILABLE\n";
unlink $binary_name or die "Failed to unlink $binary_name:$!";
$optional{DEFINE} = '-DHAVE_CRYPT_URANDOM_SYSCALL_GETRANDOM';
} else {
warn_or_diag "SYS_getrandom from sys/syscall is unavailable\n";
open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!";
print FOO <<'_OUT_';
#include <sys/types.h>
#include <sys/random.h>
int main(void)
{
char buf[5];
int l = 5;
arc4random_buf(buf, l);
return l;
}
_OUT_
close FOO or die "Failed to close $test_file_name:$!";
$output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`;
if ($? == 0) {
warn_or_diag "arc4random_buf from sys/random is AVAILABLE\n";
unlink $binary_name or die "Failed to unlink $binary_name:$!";
$optional{DEFINE} = '-DHAVE_CRYPT_URANDOM_NATIVE_ARC4RANDOM_BUF';
} else {
warn_or_diag "arc4random_buf from sys/random is unavailable\n";
open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!";
print FOO <<'_OUT_';
#include <unistd.h>
int main(void)
{
char buf[5];
int l = 5;
arc4random_buf(buf, l);
return l;
}
_OUT_
close FOO or die "Failed to close $test_file_name:$!";
$output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`;
if ($? == 0) {
warn_or_diag "arc4random_buf from unistd is AVAILABLE\n";
unlink $binary_name or die "Failed to unlink $binary_name:$!";
$optional{DEFINE} = '-DHAVE_CRYPT_URANDOM_UNISTD_ARC4RANDOM_BUF';
} else {
warn_or_diag "arc4random_buf from unistd is unavailable\n";
open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!";
print FOO <<'_OUT_';
#include <stdlib.h>
int main(void)
{
char buf[5];
int l = 5;
arc4random_buf(buf, l);
return l;
}
_OUT_
close FOO or die "Failed to close $test_file_name:$!";
$output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`;
if ($? == 0) {
warn_or_diag "arc4random_buf from stdlib is AVAILABLE\n";
unlink $binary_name or die "Failed to unlink $binary_name:$!";
$optional{DEFINE} = '-DHAVE_CRYPT_URANDOM_STDLIB_ARC4RANDOM_BUF';
} else {
warn_or_diag "arc4random_buf from unistd is unavailable\n";
open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!";
print FOO <<'_OUT_';
int main(void)
{
return 0;
}
_OUT_
close FOO or die "Failed to close $test_file_name:$!";
$output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`;
if ($? == 0) {
warn_or_diag "C compiler is AVAILABLE\n";
if ($ENV{CRYPT_URANDOM_BUILD_DEBUG}) {
warn_or_diag $output;
}
unlink $binary_name or die "Failed to unlink $binary_name:$!";
$optional{DEFINE} = '-DUNKNOWN_ENVIRONMENT';
} else {
warn_or_diag "C compiler is unavailable\n";
$optional{DEFINE} = '-DNO_COMPILER_FOUND';
}
}
}
}
}
unlink $test_file_name or die "Failed to unlink $test_file_name:$!";
}