blib/lib/Net/DNS/SEC/RSA.pm

filter: Statementstmt 100% 44 / 44 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 100% 64 / 64 CC 5 SCAR 6.9
CC
5
Cov
100%
verify
4.0
sign
2.0
BEGIN
1.0
CRAP 2.0
« blib/lib/Net/DNS/SEC/ECDSA.pm ↑ Summary blib/lib/Net/DNS/SEC.pm »
1 package Net::DNS::SEC::RSA;
2  
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 10 our $VERSION = (qw$Id: RSA.pm 2042 2025-12-24 10:23:11Z willem $)[2];
7  
8  
9 =head1 NAME
10  
11 Net::DNS::SEC::RSA - DNSSEC RSA digital signature algorithm
12  
13  
14 =head1 SYNOPSIS
15  
16 require Net::DNS::SEC::RSA;
17  
18 $signature = Net::DNS::SEC::RSA->sign( $sigdata, $private );
19  
20 $validated = Net::DNS::SEC::RSA->verify( $sigdata, $keyrr, $sigbin );
21  
22  
23 =head1 DESCRIPTION
24  
25 Implementation of RSA digital signature
26 generation and verification procedures.
27  
28 =head2 sign
29  
30 $signature = Net::DNS::SEC::RSA->sign( $sigdata, $private );
31  
32 Generates the wire-format signature from the sigdata octet string
33 and the appropriate private key object.
34  
35 =head2 verify
36  
37 $validated = Net::DNS::SEC::RSA->verify( $sigdata, $keyrr, $sigbin );
38  
39 Verifies the signature over the sigdata octet string using the specified
40 public key resource record.
41  
42 =cut
43  
44 10 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 10 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 10 ▶use constant RSA_configured => Net::DNS::SEC::libcrypto->can('EVP_PKEY_new_RSA');
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 10 ▶BEGIN { die 'RSA disabled or application has no "use Net::DNS::SEC"' unless RSA_configured }
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51  
52 my %parameters = (
53 10 1 => scalar eval { Net::DNS::SEC::libcrypto::EVP_md5() }, ## deprecate DNSSEC entirely
54 10 5 => scalar eval { Net::DNS::SEC::libcrypto::EVP_sha1() }, ## MUST NOT DNSSEC sign
55 10 7 => scalar eval { Net::DNS::SEC::libcrypto::EVP_sha1() }, ## MUST NOT DNSSEC sign
56 10 8 => scalar eval { Net::DNS::SEC::libcrypto::EVP_sha256() },
57 10 10 => scalar eval { Net::DNS::SEC::libcrypto::EVP_sha512() },
58 );
59  
60 11 ▶sub _index { return keys %parameters }
Subroutine _index: called CC=1 SCAR=0.0
61  
62 11 ▶sub _deprecate { return ( 1, -5, -7 ) }
Subroutine _deprecate: called CC=1 SCAR=0.0
63  
64  
65 10 ▶sub sign {
Subroutine sign: called CC=2 SCAR=6.9
Pod documented
66 10 my ( $class, $sigdata, $private ) = @_;
67  
68 10 my $evpmd = $parameters{$private->algorithm};
69 10 ▶ die 'unsupported RSA algorithm ', $private->algorithm unless $evpmd;
Branch: 1 branch
BranchTrueFalseTotal
unless $evpmd 1 9 10
70  
71 9 my @key = qw(Modulus PublicExponent PrivateExponent Prime1 Prime2 Exponent1 Exponent2 Coefficient);
72 9 my ( $n, $e, $d, $p1, $p2, $e1, $e2, $c ) = map { decode_base64( $private->$_ ) } @key;
73 9 my $evpkey = Net::DNS::SEC::libcrypto::EVP_PKEY_new_RSA( $n, $e, $d, $p1, $p2, $e1, $e2, $c );
74  
75 9 return Net::DNS::SEC::libcrypto::EVP_sign( $sigdata, $evpkey, $evpmd );
76 }
77  
78  
79 30 ▶sub verify {
Subroutine verify: called CC=4 SCAR=13.9
Pod documented
80 30 my ( $class, $sigdata, $keyrr, $sigbin ) = @_;
81  
82 30 my $evpmd = $parameters{$keyrr->algorithm};
83 30 ▶ die 'unsupported RSA algorithm ', $keyrr->algorithm unless $evpmd;
Branch: 1 branch
BranchTrueFalseTotal
unless $evpmd 1 29 30
84  
85 29 ▶ return unless $sigbin;
Branch: 1 branch
BranchTrueFalseTotal
unless $sigbin 1 28 29
86  
87 28 my $keybin = $keyrr->keybin; # public key
88 28 my ( $short, $long ) = unpack( 'Cn', $keybin ); # RFC3110, section 2
89 28 ▶ my $keyfmt = $short ? "x a$short a*" : "x3 a$long a*";
Branch: 1 branch
BranchTrueFalseTotal
$short ? : 27 1 28
90 28 my ( $exponent, $modulus ) = unpack( $keyfmt, $keybin );
91  
92 28 my $evpkey = Net::DNS::SEC::libcrypto::EVP_PKEY_new_RSA( $modulus, $exponent );
93  
94 28 return Net::DNS::SEC::libcrypto::EVP_verify( $sigdata, $sigbin, $evpkey, $evpmd );
95 }
96  
97  
98 10 1;
99  
100 __END__
« blib/lib/Net/DNS/SEC/ECDSA.pm ↑ Summary blib/lib/Net/DNS/SEC.pm »