Skip to content

Commit

Permalink
Use a faster library for calculating pbkdf2
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouzierinverse authored and fdurand committed Oct 21, 2024
1 parent 1419566 commit 6cab3cc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/pf/util/wpa.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use List::Util qw(minstr maxstr);
use pf::log;
use Crypt::PBKDF2;
use Digest::SHA qw(hmac_sha1);
use Crypt::KeyDerivation qw(pbkdf2);
use bytes;

my $PKE = "Pairwise key expansion";
Expand Down Expand Up @@ -39,7 +40,7 @@ sub bytes_range {
return substr($str, $start, $size);
}

sub calculate_pmk {
sub calculate_pmk_slow {
my ($ssid, $psk) = @_;
my $pbkdf2 = Crypt::PBKDF2->new(
iterations => 4096,
Expand All @@ -52,6 +53,13 @@ sub calculate_pmk {
return $pmk;
}

sub calculate_pmk {
my ($ssid, $psk) = @_;
my $pmk = pbkdf2($psk, $ssid, 4096, 'SHA1', 32);
get_logger->debug("PTK is ".unpack("H*", $pmk));
return $pmk;
}

sub calculate_ptk {
my ($pmk, $mac_ap, $mac_cl, $anonce, $snonce) = @_;
my $key_data = minstr($mac_ap, $mac_cl) . maxstr($mac_ap, $mac_cl) . minstr($anonce,$snonce) . maxstr($anonce,$snonce);
Expand Down

0 comments on commit 6cab3cc

Please sign in to comment.