| 1 | package Net::DNS::SEC::EdDSA; | ||||||||||||
| 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: EdDSA.pm 2002 2025-01-07 09:57:46Z willem $)[2]; | |||||||||||
| 7 | |||||||||||||
| 8 | |||||||||||||
| 9 | =head1 NAME | ||||||||||||
| 10 | |||||||||||||
| 11 | Net::DNS::SEC::EdDSA - DNSSEC EdDSA digital signature algorithm | ||||||||||||
| 12 | |||||||||||||
| 13 | |||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||
| 15 | |||||||||||||
| 16 | require Net::DNS::SEC::EdDSA; | ||||||||||||
| 17 | |||||||||||||
| 18 | $signature = Net::DNS::SEC::EdDSA->sign( $sigdata, $private ); | ||||||||||||
| 19 | |||||||||||||
| 20 | $validated = Net::DNS::SEC::EdDSA->verify( $sigdata, $keyrr, $sigbin ); | ||||||||||||
| 21 | |||||||||||||
| 22 | |||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||
| 24 | |||||||||||||
| 25 | Implementation of EdDSA Edwards curve digital signature | ||||||||||||
| 26 | generation and verification procedures. | ||||||||||||
| 27 | |||||||||||||
| 28 | =head2 sign | ||||||||||||
| 29 | |||||||||||||
| 30 | $signature = Net::DNS::SEC::EdDSA->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::EdDSA->verify( $sigdata, $keyrr, $signature ); | ||||||||||||
| 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 EdDSA_configured => Net::DNS::SEC::libcrypto->can('EVP_PKEY_new_EdDSA'); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 48 | |||||||||||||
| 49 | 10 | ▶ | BEGIN { die 'EdDSA disabled or application has no "use Net::DNS::SEC"' unless EdDSA_configured } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 50 | |||||||||||||
| 51 | |||||||||||||
| 52 | 10 | my %parameters = ( | |||||||||||
| 53 | 15 => ['ED25519', 32, 64], | ||||||||||||
| 54 | 16 => ['ED448', 57, 114], | ||||||||||||
| 55 | ); | ||||||||||||
| 56 | |||||||||||||
| 57 | 11 | ▶ | sub _index { return keys %parameters } | ||||||||||
|
Subroutine
_index: called CC=1 SCAR=0.0
| |||||||||||||
| 58 | |||||||||||||
| 59 | |||||||||||||
| 60 | 3 | ▶ | sub sign { | ||||||||||
|
Subroutine
sign: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 61 | 3 | my ( $class, $sigdata, $private ) = @_; | |||||||||||
| 62 | |||||||||||||
| 63 | 3 | my $algorithm = $private->algorithm; | |||||||||||
| 64 | 3 | ▶ | my ( $curve, $keylen ) = @{$parameters{$algorithm} || []}; | ||||||||||
|
Condition100%2/2
$parameters{$algorithm} || []
MC/DC100%1/1
$parameters{$algorithm} || []
$parameters{$algorithm}
Truth table100%2/2
A
A= $parameters{$algorithm}
| |||||||||||||
| 65 | 3 | ▶ | die 'private key not EdDSA' unless $curve; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | |||||||||||||
| 67 | 2 | my $rawkey = pack "a$keylen", decode_base64( $private->PrivateKey ); | |||||||||||
| 68 | 2 | my $evpkey = Net::DNS::SEC::libcrypto::EVP_PKEY_new_EdDSA( $curve, '', $rawkey ); | |||||||||||
| 69 | |||||||||||||
| 70 | 2 | return Net::DNS::SEC::libcrypto::EVP_sign( $sigdata, $evpkey ); | |||||||||||
| 71 | } | ||||||||||||
| 72 | |||||||||||||
| 73 | |||||||||||||
| 74 | 6 | ▶ | sub verify { | ||||||||||
|
Subroutine
verify: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 75 | 6 | my ( $class, $sigdata, $keyrr, $signature ) = @_; | |||||||||||
| 76 | |||||||||||||
| 77 | 6 | my $algorithm = $keyrr->algorithm; | |||||||||||
| 78 | 6 | ▶ | my ( $curve, $keylen, $siglen ) = @{$parameters{$algorithm} || []}; | ||||||||||
|
Condition100%2/2
$parameters{$algorithm} || []
MC/DC100%1/1
$parameters{$algorithm} || []
$parameters{$algorithm}
Truth table100%2/2
A
A= $parameters{$algorithm}
| |||||||||||||
| 79 | 6 | ▶ | die 'public key not EdDSA' unless $curve; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | |||||||||||||
| 81 | 5 | ▶ | return unless $signature; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | |||||||||||||
| 83 | 4 | my $rawkey = pack "a$keylen", $keyrr->keybin; | |||||||||||
| 84 | 4 | my $evpkey = Net::DNS::SEC::libcrypto::EVP_PKEY_new_EdDSA( $curve, $rawkey ); | |||||||||||
| 85 | |||||||||||||
| 86 | 4 | my $sigbin = pack "a$siglen", $signature; | |||||||||||
| 87 | 4 | return Net::DNS::SEC::libcrypto::EVP_verify( $sigdata, $sigbin, $evpkey ); | |||||||||||
| 88 | } | ||||||||||||
| 89 | |||||||||||||
| 90 | |||||||||||||
| 91 | 10 | my $key448 = decode_base64 '69oJdWluramCzd28zK6E/LIZzL6MxVkQ0drFQ/dyeFQon2Tso03D0jCrP1NZ965ASnIC5N+sgwOA'; | |||||||||||
| 92 | 10 | my $evpkey = eval { Net::DNS::SEC::libcrypto::EVP_PKEY_new_EdDSA( 'ED448', $key448 ) }; | |||||||||||
| 93 | 10 | ▶ | delete $parameters{16} unless defined $evpkey; ## disallow ED448 if using BoringSSL|LibreSSL | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 94 | |||||||||||||
| 95 | |||||||||||||
| 96 | 10 | 1; | |||||||||||
| 97 | |||||||||||||
| 98 | __END__ | ||||||||||||