line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::Curve25519; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:AJGB'; |
3
|
|
|
|
|
|
|
#ABSTRACT: Generate shared secret using elliptic-curve Diffie-Hellman function |
4
|
|
|
|
|
|
|
$Crypt::Curve25519::VERSION = '0.05'; |
5
|
6
|
|
|
6
|
|
87874
|
use strict; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
151
|
|
6
|
6
|
|
|
6
|
|
19
|
use warnings; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
170
|
|
7
|
6
|
|
|
6
|
|
21
|
use Carp qw( croak ); |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
361
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
6
|
|
|
6
|
|
2518
|
use AutoLoader; |
|
6
|
|
|
|
|
6382
|
|
|
6
|
|
|
|
|
33
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
15
|
|
|
|
|
|
|
curve25519 |
16
|
|
|
|
|
|
|
curve25519_secret_key |
17
|
|
|
|
|
|
|
curve25519_public_key |
18
|
|
|
|
|
|
|
curve25519_shared_secret |
19
|
|
|
|
|
|
|
) ] ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our @EXPORT = qw( |
24
|
|
|
|
|
|
|
curve25519_secret_key |
25
|
|
|
|
|
|
|
curve25519_public_key |
26
|
|
|
|
|
|
|
curve25519_shared_secret |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
require XSLoader; |
30
|
|
|
|
|
|
|
XSLoader::load('Crypt::Curve25519', $Crypt::Curve25519::{VERSION} ? |
31
|
|
|
|
|
|
|
${ $Crypt::Curve25519::{VERSION} } : () |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
35
|
2
|
50
|
|
2
|
1
|
33
|
return bless(\(my $o = 1), ref $_[0] ? ref $_[0] : $_[0] ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub secret_key { |
39
|
4
|
|
|
4
|
1
|
157
|
my ($self, $psk) = (shift, shift); |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
31
|
my $masked = curve25519_secret_key( pack('H64', $psk) ); |
42
|
|
|
|
|
|
|
|
43
|
4
|
|
|
|
|
16
|
return unpack('H64', $masked); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub public_key { |
47
|
4
|
|
|
4
|
1
|
16
|
my ($self, $sk) = (shift, shift); |
48
|
4
|
|
|
|
|
13
|
my @args = pack('H64', $sk); |
49
|
4
|
50
|
|
|
|
14
|
if ( @_ ) { |
50
|
0
|
|
|
|
|
0
|
push @args, pack('H64', shift); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
4
|
|
|
|
|
509
|
my $pk = unpack('H64', curve25519_public_key( @args )); |
54
|
|
|
|
|
|
|
|
55
|
4
|
|
|
|
|
16
|
return $pk; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub shared_secret { |
59
|
4
|
|
|
4
|
1
|
19
|
my ($self, $sk, $pk) = @_; |
60
|
|
|
|
|
|
|
|
61
|
4
|
|
|
|
|
480
|
return unpack('H64', curve25519_shared_secret( pack('H64', $sk), pack('H64', $pk) )); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub generate { |
65
|
0
|
|
|
0
|
1
|
|
my ($self, $sk, $bp) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return unpack('H64', curve25519( pack('H64', $sk), pack('H64', $bp) )); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |