File: crypt16.t

package info (click to toggle)
libauthen-passphrase-perl 0.008-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 376 kB
  • sloc: perl: 1,932; makefile: 2
file content (79 lines) | stat: -r--r--r-- 1,973 bytes parent folder | download | duplicates (5)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use warnings;
use strict;

use Test::More tests => 83;

BEGIN { use_ok "Authen::Passphrase::Crypt16"; }

my $ppr = Authen::Passphrase::Crypt16
		->new(salt => 1234, hash => "abcdefghABCDEFGH");
ok $ppr;
is $ppr->salt, 1234;
is $ppr->salt_base64_2, "GH";
is $ppr->hash, "abcdefghABCDEFGH";
is $ppr->hash_base64, "MK7XN4JaNqUEI71F2J4FoU";
my $h0 = $ppr->first_half;
ok $h0;
is $h0->fold, !!0;
is $h0->initial, "\0\0\0\0\0\0\0\0";
is $h0->nrounds, 20;
is $h0->salt, 1234;
is $h0->hash_base64, "MK7XN4JaNqU";
my $h1 = $ppr->second_half;
ok $h1;
is $h1->fold, !!0;
is $h1->initial, "\0\0\0\0\0\0\0\0";
is $h1->nrounds, 5;
is $h1->salt, 1234;
is $h1->hash_base64, "EI71F2J4FoU";

$ppr = Authen::Passphrase::Crypt16
		->new(salt => 1234, passphrase => "wibble");
ok $ppr;
is $ppr->salt, 1234;
is $ppr->hash_base64, "QYUQgj6nmd.g/xAujudtXo";

$ppr = Authen::Passphrase::Crypt16
		->new(salt => 1234, passphrase => "wibblewobble");
ok $ppr;
is $ppr->salt, 1234;
is $ppr->hash_base64, "1ndJ4WMAo3s.CbKCSyRbco";

$ppr = Authen::Passphrase::Crypt16
		->new(salt_random => 12, passphrase => "wibblewobble");
ok $ppr;
is length($ppr->salt_base64_2), 2;
is length($ppr->hash), 16;
ok $ppr->match("wibblewobble");

my %pprs;
while(<DATA>) {
	chomp;
	s/([^ \n]+) ([^ \n]+) *//;
	my($salt, $hash) = ($1, $2);
	$ppr = Authen::Passphrase::Crypt16
			->new(salt_base64 => $salt, hash_base64 => $hash);
	ok $ppr;
	is $ppr->salt_base64_2, $salt;
	is $ppr->hash_base64, $hash;
	eval { $ppr->passphrase }; isnt $@, "";
	eval { $ppr->as_crypt }; isnt $@, "";
	eval { $ppr->as_rfc2307 }; isnt $@, "";
	$pprs{$_} = $ppr;
}

foreach my $rightphrase (sort keys %pprs) {
	my $ppr = $pprs{$rightphrase};
	foreach my $passphrase (sort keys %pprs) {
		ok ($ppr->match($passphrase) xor $passphrase ne $rightphrase);
	}
}

1;

__DATA__
7S ...........4VBRyAvp9nw
Ur ImG9Kp15IQsO2OoWANp2qc 0
QZ 7Dztte564Tsv/MSAT.EjMA 1
Qe tZVtOlWcUdEgK.3Asz6yo. foo
Uk uSoh3oV2exsgb27c/7adao supercalifragilisticexpialidocious