line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Stream::ChaCha; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
963
|
use strict; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
57
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
83
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.080_001'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
11
|
use CryptX; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
75
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
1; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=pod |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Crypt::Stream::ChaCha - Stream cipher ChaCha |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Crypt::Stream::ChaCha; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# encrypt |
22
|
|
|
|
|
|
|
$key = "1234567890123456"; |
23
|
|
|
|
|
|
|
$iv = "123456789012"; |
24
|
|
|
|
|
|
|
$stream = Crypt::Stream::ChaCha->new($key, $iv); |
25
|
|
|
|
|
|
|
$ct = $stream->crypt("plain message"); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# decrypt |
28
|
|
|
|
|
|
|
$key = "1234567890123456"; |
29
|
|
|
|
|
|
|
$iv = "123456789012"; |
30
|
|
|
|
|
|
|
$stream = Crypt::Stream::ChaCha->new($key, $iv); |
31
|
|
|
|
|
|
|
$pt = $stream->crypt($ct); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Provides an interface to the ChaCha stream cipher. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 METHODS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 new |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$stream = Crypt::Stream::ChaCha->new($key, $iv); |
42
|
|
|
|
|
|
|
#or |
43
|
|
|
|
|
|
|
$stream = Crypt::Stream::ChaCha->new($key, $iv, $counter, $rounds); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# $key .. 32 or 16 bytes |
46
|
|
|
|
|
|
|
# $iv .. 8 or 12 bytes |
47
|
|
|
|
|
|
|
# $counter .. initial counter value (DEFAULT: 0) |
48
|
|
|
|
|
|
|
# $rounds .. rounds (DEFAULT: 20) |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 crypt |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$ciphertext = $stream->crypt($plaintext); |
53
|
|
|
|
|
|
|
#or |
54
|
|
|
|
|
|
|
$plaintext = $stream->crypt($ciphertext); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 keystream |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$random_key = $stream->keystream($length); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 clone |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$stream->clone(); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 SEE ALSO |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=over |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item * L, L, L, L |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item * L |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=back |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |