| 1 | package Crypt::KDF::_base; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | ### ($VERSION) = sprintf '%i.%03i', split(/\./,('$Revision: 0.1 $' =~ /Revision: (\S+)\s/)[0]); # $Date: $ | ||||||||||
| 7 | 3 | $VERSION = '0.02'; | |||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | Crypt::KDF::_base | ||||||||||
| 12 | |||||||||||
| 13 | =cut | ||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub new { die "must subclass"; } | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 16 | |||||||||||
| 17 | 0 | ▶ | sub init { die "must subclass"; } | ||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 18 | |||||||||||
| 19 | sub kdf_hex | ||||||||||
| 20 | 8 | ▶ | { | ||||||||
|
Subroutine
kdf_hex: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||
| 21 | 8 | my $self = shift @_; | |||||||||
| 22 | 8 | my $ret; | |||||||||
| 23 | 8 | ▶ | if($_[0]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | { | ||||||||||
| 25 | 8 | $ret=$self->kdf($_[0]); | |||||||||
| 26 | } | ||||||||||
| 27 | else | ||||||||||
| 28 | { | ||||||||||
| 29 | 0 | $ret=$self->kdf(); | |||||||||
| 30 | } | ||||||||||
| 31 | 8 | return unpack('H*',$ret); | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | sub kdf { die "must subclass"; } | ||||||||
|
Subroutine
kdf: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 35 | |||||||||||
| 36 | =head1 METHODS | ||||||||||
| 37 | |||||||||||
| 38 | =head2 $digest = $kdf->digest( $digest ) | ||||||||||
| 39 | |||||||||||
| 40 | Sets/gets the digest to be used as the source of derived keys. | ||||||||||
| 41 | |||||||||||
| 42 | =cut | ||||||||||
| 43 | |||||||||||
| 44 | sub digest | ||||||||||
| 45 | 0 | ▶ | { | ||||||||
|
Subroutine
digest: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 46 | 0 | my $self = shift @_; | |||||||||
| 47 | 0 | ▶ | if($_[0]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | { | ||||||||||
| 49 | 0 | ▶ | $self->{-digest} = (ref($_[0]) ? ref($_[0]) : $_[0]); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | } | ||||||||||
| 51 | 0 | return $self->{-digest}; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | =head2 $digestparam = $kdf->digestparam( $digestparam ) | ||||||||||
| 55 | |||||||||||
| 56 | Sets/gets the optional parameters for the digest used to derive keys. | ||||||||||
| 57 | |||||||||||
| 58 | =cut | ||||||||||
| 59 | |||||||||||
| 60 | sub digestparam | ||||||||||
| 61 | 0 | ▶ | { | ||||||||
|
Subroutine
digestparam: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 62 | 0 | my $self = shift @_; | |||||||||
| 63 | 0 | ▶ | if($_[0]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | { | ||||||||||
| 65 | 0 | $self->{-digestparam} = $_[0]; | |||||||||
| 66 | } | ||||||||||
| 67 | 0 | return $self->{-digestparam}; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | =head2 $seed = $kdf->seed( $seed ) | ||||||||||
| 71 | |||||||||||
| 72 | Sets/gets the seed to be used to derive keys. | ||||||||||
| 73 | |||||||||||
| 74 | =cut | ||||||||||
| 75 | |||||||||||
| 76 | sub seed | ||||||||||
| 77 | 0 | ▶ | { | ||||||||
|
Subroutine
seed: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 78 | 0 | my $self = shift @_; | |||||||||
| 79 | 0 | ▶ | if($_[0]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | { | ||||||||||
| 81 | 0 | $self->{-seed} = $_[0]; | |||||||||
| 82 | } | ||||||||||
| 83 | 0 | return $self->{-seed}; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | =head2 $counter = $kdf->counter( $counter ) | ||||||||||
| 87 | |||||||||||
| 88 | Sets/gets the start value of counter used to derive keys. | ||||||||||
| 89 | |||||||||||
| 90 | =cut | ||||||||||
| 91 | |||||||||||
| 92 | sub counter | ||||||||||
| 93 | 0 | ▶ | { | ||||||||
|
Subroutine
counter: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 94 | 0 | my $self = shift @_; | |||||||||
| 95 | 0 | ▶ | if($_[0]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | { | ||||||||||
| 97 | 0 | $self->{-counter} = $_[0]; | |||||||||
| 98 | } | ||||||||||
| 99 | 0 | return $self->{-counter}; | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | =head2 $iv = $kdf->iv( $iv ) | ||||||||||
| 103 | |||||||||||
| 104 | Sets/gets the optional iv to be used to derive keys. | ||||||||||
| 105 | |||||||||||
| 106 | =cut | ||||||||||
| 107 | |||||||||||
| 108 | sub iv | ||||||||||
| 109 | 0 | ▶ | { | ||||||||
|
Subroutine
iv: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 110 | 0 | my $self = shift @_; | |||||||||
| 111 | 0 | ▶ | if($_[0]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | { | ||||||||||
| 113 | 0 | $self->{-iv} = $_[0]; | |||||||||
| 114 | } | ||||||||||
| 115 | 0 | return $self->{-iv}; | |||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | =head2 ( $derivedKey, $derivedIV ) = $kdf->kdf_iv( $kLen, $ivLen ) | ||||||||||
| 119 | |||||||||||
| 120 | Return length bytes generated from the derivation function. | ||||||||||
| 121 | |||||||||||
| 122 | =cut | ||||||||||
| 123 | |||||||||||
| 124 | sub kdf_iv | ||||||||||
| 125 | 0 | ▶ | { | ||||||||
|
Subroutine
kdf_iv: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 126 | 0 | my $self = shift @_; | |||||||||
| 127 | 0 | my $kLen = 16; | |||||||||
| 128 | 0 | ▶ | if($_[0]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 129 | { | ||||||||||
| 130 | 0 | $kLen = $_[0]; | |||||||||
| 131 | } | ||||||||||
| 132 | 0 | my $ivLen = 16; | |||||||||
| 133 | 0 | ▶ | if($_[1]) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 134 | { | ||||||||||
| 135 | 0 | $ivLen = $_[1]; | |||||||||
| 136 | } | ||||||||||
| 137 | 0 | my $len=$kLen+$ivLen; | |||||||||
| 138 | 0 | my $out=$self->kdf($len); | |||||||||
| 139 | 0 | return (substr($out,0,$kLen), substr($out,$kLen,$ivLen)); | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | 3 | 1; | |||||||||
| 143 | __END__ | ||||||||||