Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Fix PSS param sLen
Browse files Browse the repository at this point in the history
sLen is supposed to be the length of the hash output, not the length of the
input data. Was just lucky that it worked before because all my test files were
small.
  • Loading branch information
ioanrogers committed Jun 27, 2016
1 parent 84a0917 commit 882ca3e
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions lib/Crypt/PKCS11/Easy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ has _flags => (

has [qw/_token_flags _mechanism_flags _slot_flags/] => (is => 'lazy');

has _sig_length => (
is => 'ro',
lazy => 1,
default => sub {
{
1 => 20,
224 => 28,
256 => 32,
384 => 48,
512 => 64,
};
},
);

sub _build__mechanism_flags {
_flags_to_hash($_[0]->_flags->{mechanism});
}
Expand Down Expand Up @@ -592,10 +606,20 @@ sub get_verification_key {
}

sub _get_pss_params {
my ($self, $hash, $sig_length) = @_;
my ($self, $hash, $hash_number) = @_;

$log->debug("Finding params for a $hash RSA PSS signature");

# comes in bits, need bytes. Instead of simply dividing by 8 we use a mapping
# hash to verify that the length is correct
my $sig_length = $self->_sig_length->{$hash_number};
unless ($sig_length) {
die
'Unsupported hash type: not SHA1/SHA2-224/SHA2-256/SHA2-384/SHA2-512';
}

$log->debug("slen $sig_length");

my $pss_param = Crypt::PKCS11::CK_RSA_PKCS_PSS_PARAMS->new;

no strict 'refs'; ## no critic
Expand Down Expand Up @@ -662,8 +686,8 @@ sub _handle_common_args {

# does this mechanism need parameters?
my $params;
if ($args->{mech} =~ /(^SHA\d+)_RSA_PKCS_PSS$/) {
$params = $self->_get_pss_params($1, length $args->{data});
if ($args->{mech} =~ /(^SHA(\d+))_RSA_PKCS_PSS$/) {
$params = $self->_get_pss_params($1, $2);
}

if ($params) {
Expand Down

0 comments on commit 882ca3e

Please sign in to comment.