| 1 | package Net::DNS::SEC::MLDSA; | ||
| 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 | our $VERSION = (qw$Id: MLDSA.pm 2063 2026-10-05 11:02:58Z willem $)[2]; | ||
| 7 | |||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | Net::DNS::SEC::MLDSA - DNSSEC Module-Lattice digital signature algorithm | ||
| 12 | |||
| 13 | |||
| 14 | =head1 SYNOPSIS | ||
| 15 | |||
| 16 | require Net::DNS::SEC::MLDSA; | ||
| 17 | |||
| 18 | $signature = Net::DNS::SEC::MLDSA->sign( $sigdata, $private ); | ||
| 19 | |||
| 20 | $validated = Net::DNS::SEC::MLDSA->verify( $sigdata, $keyrr, $sigbin ); | ||
| 21 | |||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | Implementation of Module-Lattice digital signature | ||
| 26 | generation and verification procedures. | ||
| 27 | |||
| 28 | =head2 sign | ||
| 29 | |||
| 30 | $signature = Net::DNS::SEC::MLDSA->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::MLDSA->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 MLDSA_configured => Net::DNS::SEC::libcrypto->can('EVP_PKEY_new_MLDSA'); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 48 | |||
| 49 | 10 | ▶ | BEGIN { die 'MLDSA disabled or application has no "use Net::DNS::SEC"' unless MLDSA_configured } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 50 | |||
| 51 | |||
| 52 | my %parameters = ( 18 => ['ML-DSA-44', 1312, 2420], ); | ||
| 53 | |||
| 54 | sub _index { return keys %parameters } | ||
| 55 | sub _deprecate { return my @empty } | ||
| 56 | |||
| 57 | |||
| 58 | sub sign { | ||
| 59 | my ( $class, $sigdata, $private ) = @_; | ||
| 60 | |||
| 61 | my $algorithm = $private->algorithm; | ||
| 62 | my ( $flavour, $keylen ) = @{$parameters{$algorithm} || []}; | ||
| 63 | return unless $flavour; | ||
| 64 | |||
| 65 | my $rawkey = decode_base64( $private->PrivateKey ); | ||
| 66 | my $evpkey = Net::DNS::SEC::libcrypto::EVP_PKEY_new_MLDSA( $flavour, $rawkey ); | ||
| 67 | |||
| 68 | return Net::DNS::SEC::libcrypto::EVP_sign( $sigdata, $evpkey ); | ||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | sub verify { | ||
| 73 | my ( $class, $sigdata, $keyrr, $signature ) = @_; | ||
| 74 | |||
| 75 | my $algorithm = $keyrr->algorithm; | ||
| 76 | my ( $flavour, $keylen, $siglen ) = @{$parameters{$algorithm} || []}; | ||
| 77 | return unless $flavour; | ||
| 78 | |||
| 79 | return unless $signature; | ||
| 80 | |||
| 81 | my $rawkey = pack "a$keylen", $keyrr->keybin; | ||
| 82 | my $evpkey = Net::DNS::SEC::libcrypto::EVP_PKEY_new_MLDSA( $flavour, $rawkey ); | ||
| 83 | |||
| 84 | my $sigbin = pack "a$siglen", $signature; | ||
| 85 | return Net::DNS::SEC::libcrypto::EVP_verify( $sigdata, $sigbin, $evpkey ); | ||
| 86 | } | ||
| 87 | |||
| 88 | |||
| 89 | 1; | ||
| 90 | __END__ | ||