3 # stunt userv-ipif standin which generates random data
5 # This file is part of secnet.
6 # See README for full list of copyright holders.
8 # secnet is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # secnet is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # version 3 along with secnet; if not, see
20 # https://www.gnu.org/licenses/gpl.html.
25 open R, '/dev/urandom' or die $!;
27 system 'cat >/dev/null &';
32 my $r = read R, $s, $count;
33 die $! unless $r==$count;
39 my ($r) = unpack 'C', $b;
44 my ($min,$maxplus1) = @_;
46 return floor(($b/256.0) * ($maxplus1-$min)) + $min;
50 my $lenbits = randvalue 0,14;
51 my $len= (randbyteval << 8) | randbyteval;
52 $len &= (1 << $lenbits)-1;
53 my $data = randbytes $len;
54 if (randbyteval >= 0x80) {
55 $data =~ s{[\xc0\xdb]}{
56 $& eq "\xc0" ? "\xcb\xdc" :
57 $& eq "\xdb" ? "\xcb\xdd" :