File: pbkdf2.pm

package info (click to toggle)
libcrypt-cbc-perl 3.07-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 364 kB
  • sloc: perl: 2,074; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 738 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package Crypt::CBC::PBKDF::pbkdf2;
use strict;

use base 'Crypt::CBC::PBKDF';
use Crypt::PBKDF2;

our $VERSION = '3.07';
# options:
# key_len    => 32    default
# iv_len     => 16    default
# iterations => 10000  default
# hash_class => 'HMACSHA2' default

sub create {
    my $class = shift;
    my %options = @_;
    $options{key_len}      ||= 32;
    $options{iv_len}       ||= 16;
    $options{iterations}   ||= 10_000;
    $options{hash_class}   ||= 'HMACSHA2';
    return bless \%options,$class;
}

sub generate_hash {
    my $self = shift;
    my ($salt,$passphrase) = @_;
    my $pbkdf2 = Crypt::PBKDF2->new(%$self,
				    output_len => $self->{key_len} + $self->{iv_len});
    return $pbkdf2->PBKDF2($salt,$passphrase);
}

1;