line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::OpenPGP::Key::Public::RSA; |
2
|
3
|
|
|
3
|
|
19
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
154
|
|
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
1829
|
use Crypt::RSA::Key::Public; |
|
3
|
|
|
|
|
36372
|
|
|
3
|
|
|
|
|
125
|
|
5
|
3
|
|
|
3
|
|
27
|
use Crypt::OpenPGP::Digest; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
106
|
|
6
|
3
|
|
|
3
|
|
18
|
use Crypt::OpenPGP::Util qw( bitsize bin2mp mp2bin ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
244
|
|
7
|
3
|
|
|
3
|
|
18
|
use Crypt::OpenPGP::Key::Public; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
101
|
|
8
|
3
|
|
|
3
|
|
18
|
use Crypt::OpenPGP::ErrorHandler; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
89
|
|
9
|
3
|
|
|
3
|
|
16
|
use base qw( Crypt::OpenPGP::Key::Public Crypt::OpenPGP::ErrorHandler ); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
2370
|
|
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
1
|
25
|
sub can_encrypt { 1 } |
12
|
0
|
|
|
0
|
1
|
0
|
sub can_sign { 1 } |
13
|
0
|
|
|
0
|
0
|
0
|
sub abbrev { 'R' } |
14
|
|
|
|
|
|
|
|
15
|
33
|
|
|
33
|
0
|
135
|
sub public_props { qw( n e ) } |
16
|
3
|
|
|
3
|
0
|
10
|
sub crypt_props { qw( c ) } |
17
|
4
|
|
|
4
|
0
|
14
|
sub sig_props { qw( c ) } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub init { |
20
|
18
|
|
|
18
|
0
|
31
|
my $key = shift; |
21
|
18
|
|
66
|
|
|
164
|
$key->{key_data} = shift || Crypt::RSA::Key::Public->new; |
22
|
18
|
|
|
|
|
323
|
$key; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub keygen { |
26
|
2
|
|
|
2
|
1
|
6
|
my $class = shift; |
27
|
2
|
|
|
|
|
12
|
my %param = @_; |
28
|
2
|
|
|
|
|
7
|
$param{Password} = $param{Passphrase}; |
29
|
2
|
|
|
|
|
765
|
require Crypt::RSA::Key; |
30
|
2
|
|
|
|
|
71810
|
my $chain = Crypt::RSA::Key->new; |
31
|
2
|
|
|
|
|
360
|
my($pub, $sec) = $chain->generate( %param ); |
32
|
2
|
100
|
66
|
|
|
357001513
|
return $class->error( $chain->errstr ) unless $pub && $sec; |
33
|
1
|
|
|
|
|
22
|
($pub, $sec); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
7
|
|
|
7
|
1
|
85
|
sub size { bitsize($_[0]->{key_data}->n) } |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
0
|
1
|
0
|
sub check { $_[0]->{key_data}->check } |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub encrypt { |
41
|
3
|
|
|
3
|
0
|
8
|
my $key = shift; |
42
|
3
|
|
|
|
|
6
|
my($M) = @_; |
43
|
3
|
|
|
|
|
782
|
require Crypt::RSA::Primitives; |
44
|
3
|
|
|
|
|
3978
|
my $prim = Crypt::RSA::Primitives->new; |
45
|
3
|
50
|
|
|
|
29
|
my $c = $prim->core_encrypt( Key => $key->{key_data}, Plaintext => $M ) or |
46
|
|
|
|
|
|
|
return $key->error($prim->errstr); |
47
|
3
|
|
|
|
|
94579
|
{ c => $c } |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub verify { |
51
|
1
|
|
|
1
|
0
|
2
|
my $key = shift; |
52
|
1
|
|
|
|
|
3
|
my($sig, $dgst) = @_; |
53
|
1
|
|
|
|
|
16
|
my $k = $key->bytesize; |
54
|
1
|
|
|
|
|
1205
|
require Crypt::RSA::Primitives; |
55
|
1
|
|
|
|
|
6
|
my $prim = Crypt::RSA::Primitives->new; |
56
|
1
|
|
|
|
|
5
|
my $c = $sig->{c}; |
57
|
1
|
50
|
|
|
|
5
|
my $m = $prim->core_verify( Key => $key->{key_data}, Signature => $c) or |
58
|
|
|
|
|
|
|
return; |
59
|
1
|
|
|
|
|
22057
|
$m = mp2bin($m, $k - 1); |
60
|
1
|
|
|
|
|
9
|
my $hash_alg = Crypt::OpenPGP::Digest->alg($sig->{hash_alg}); |
61
|
1
|
|
|
|
|
3
|
my $M = encode($dgst, $hash_alg, $k - 1); |
62
|
1
|
|
|
|
|
11
|
$m eq $M; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
{ |
66
|
|
|
|
|
|
|
my %ENCODING = ( |
67
|
|
|
|
|
|
|
MD2 => pack('H*', '3020300C06082A864886F70D020205000410'), |
68
|
|
|
|
|
|
|
MD5 => pack('H*', '3020300C06082A864886F70D020505000410'), |
69
|
|
|
|
|
|
|
SHA1 => pack('H*', '3021300906052B0E03021A05000414'), |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub encode { |
73
|
2
|
|
|
2
|
0
|
2351
|
my($dgst, $hash_alg, $mlen) = @_; |
74
|
2
|
|
|
|
|
8
|
my $alg = $ENCODING{$hash_alg}; |
75
|
2
|
|
|
|
|
7
|
my $m = $alg . $dgst; |
76
|
2
|
|
|
|
|
6
|
my $padlen = $mlen - length($m) - 2; |
77
|
2
|
|
|
|
|
690
|
my $pad = chr(255) x $padlen; |
78
|
2
|
|
|
|
|
48
|
chr(1) . $pad . chr(0) . $m; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |