1Data::Entropy::RawSourcUes:e:rCrCyopnttCroiubnutteerdD(a3Pt)ear:l:EDnotcruompeyn:t:aRtaiwoSnource::CryptCounter(3)
2
3
4
6 Data::Entropy::RawSource::CryptCounter - counter mode of block cipher
7 as I/O handle
8
10 use Data::Entropy::RawSource::CryptCounter;
11
12 my $rawsrc = Data::Entropy::RawSource::CryptCounter
13 ->new(Crypt::Rijndael->new($key));
14
15 $c = $rawsrc->getc;
16 # and the rest of the I/O handle interface
17
19 This class provides an I/O handle connected to a virtual file which
20 contains the output of a block cipher in counter mode. This makes a
21 good source of pseudorandom bits. The handle implements a substantial
22 subset of the interfaces described in IO::Handle and IO::Seekable.
23
24 For use as a general entropy source, it is recommended to wrap an
25 object of this class using "Data::Entropy::Source", which provides
26 methods to extract entropy in more convenient forms than mere octets.
27
28 The amount of entropy the virtual file actually contains is only the
29 amount that is in the key, which is at most the length of the key. It
30 superficially appears to be much more than this, if (and to the extent
31 that) the block cipher is secure. This technique is not suitable for
32 all problems, and requires a careful choice of block cipher and keying
33 method. Applications requiring true entropy should generate it (see
34 Data::Entropy::RawSource::Local) or download it (see
35 Data::Entropy::RawSource::RandomnumbersInfo and
36 Data::Entropy::RawSource::RandomOrg).
37
39 Data::Entropy::RawSource::CryptCounter->new(KEYED_CIPHER)
40 KEYED_CIPHER must be a cipher object supporting the standard
41 "blocksize" and "encrypt" methods. For example, an instance of
42 "Crypt::Rijndael" (with the default "MODE_ECB") would be
43 appropriate. A handle object is created and returned which refers
44 to a virtual file containing the output of the cipher's counter
45 mode.
46
48 A subset of the interfaces described in IO::Handle and IO::Seekable are
49 provided:
50
51 $rawsrc->read(BUFFER, LENGTH[, OFFSET])
52 $rawsrc->getc
53 $rawsrc->ungetc(ORD)
54 $rawsrc->eof
55 Buffered reading from the source, as in IO::Handle.
56
57 $rawsrc->sysread(BUFFER, LENGTH[, OFFSET])
58 Unbuffered reading from the source, as in IO::Handle.
59
60 $rawsrc->close
61 Does nothing.
62
63 $rawsrc->opened
64 Retruns true to indicate that the source is available for I/O.
65
66 $rawsrc->clearerr
67 $rawsrc->error
68 Error handling, as in IO::Handle.
69
70 $rawsrc->getpos
71 $rawsrc->setpos(POS)
72 $rawsrc->tell
73 $rawsrc->seek(POS, WHENCE)
74 Move around within the buffered source, as in IO::Seekable.
75
76 $rawsrc->sysseek(POS, WHENCE)
77 Move around within the unbuffered source, as in IO::Seekable.
78
79 The buffered ("read" et al) and unbuffered ("sysread" et al) sets of
80 methods are interchangeable, because no such distinction is made by
81 this class.
82
83 "tell", "seek", and "sysseek" only work within the first 4 GiB of the
84 virtual file. The file is actually much larger than that: for Rijndael
85 (AES), or any other cipher with a 128-bit block, the file is 2^52 YiB
86 (2^132 B). "getpos" and "setpos" work throughout the file.
87
88 Methods to write to the file are unimplemented because the virtual file
89 is fundamentally read-only.
90
92 Crypt::Rijndael, Data::Entropy::RawSource::Local,
93 Data::Entropy::RawSource::RandomOrg,
94 Data::Entropy::RawSource::RandomnumbersInfo, Data::Entropy::Source
95
97 Andrew Main (Zefram) <zefram@fysh.org>
98
100 Copyright (C) 2006, 2007, 2009, 2011 Andrew Main (Zefram)
101 <zefram@fysh.org>
102
104 This module is free software; you can redistribute it and/or modify it
105 under the same terms as Perl itself.
106
107
108
109perl v5.32.0 2020D-a0t7a-:2:8Entropy::RawSource::CryptCounter(3)