File: null_data.t

package info (click to toggle)
libcrypt-cbc-perl 3.07-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 364 kB
  • sloc: perl: 2,074; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,190 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

use strict;
use lib './lib','./blib/lib';

sub test;

my (@mods,@pads,@in,$pad,$test_data,$mod,$tnum,$c,$i,$p);

@mods = qw/
    Cipher::AES
    Rijndael
    Blowfish
    Blowfish_PP
    IDEA
    DES
    /;
@pads = qw/standard oneandzeroes space null/;

for $mod (@mods) {
   eval "use Crypt::$mod(); 1" && push @in,$mod;
}

unless ($#in > -1) {
   print "1..0 # Skipped: no cryptographic modules found\n";
   exit;
}

print '1..', 128*($#in + 1) * ($#pads + 1) + 1, "\n";

sub test {
    local($^W) = 0;
    my($num, $true,$msg) = @_;
    $$num++;
    print($true ? "ok $$num\n" : "not ok $$num $msg\n");
}

$tnum = 0;

eval "use Crypt::CBC";
test(\$tnum,!$@,"Couldn't load module");

for my $mod (@in) {
  for my $pad (@pads) {
    my $cipher = Crypt::CBC->new(-key     => 'secret',
				 -cipher  => $mod,
				 -padding => $pad,
				 -pbkdf  => 'opensslv2',
				);
    for my $length (1..128) {
      my $test_data = 'a'x$length . '0';
      my $encrypted = $cipher->encrypt_hex($test_data);
      my $decrypted = $cipher->decrypt_hex($encrypted);
      test(\$tnum,$test_data eq $decrypted,"$mod/$pad: match failed on zero-terminated data length $length");
    }
  }
}