aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/qtest/aes.test
blob: 7e48840ac06af26e8d9f41c0787d2ec70da0c3ad (plain) (blame)
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
#!/usr/bin/env perl
require 5.008;
BEGIN { $^W = 1; }
use strict;
use File::stat;

chdir("aes") or die "chdir testdir failed: $!\n";

require TestDriver;

my $td = new TestDriver('AES');

cleanup();

my $key = '000102030405060708090a0b0c0d0e0f';
$td->runtest("encrypt test vector",
	     {$td->COMMAND => "aes -cbc -encrypt $key test-vector.clear tmp1"},
	     {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
	     {$td->FILE => "tmp1"},
	     {$td->FILE => "test-vector.cipher"});
$td->runtest("decrypt test vector",
	     {$td->COMMAND => "aes -cbc -decrypt $key tmp1 tmp2"},
	     {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
	     {$td->FILE => "tmp2"},
	     {$td->FILE => "test-vector.clear"});

$key = '243f6a8885243f6a8885243f6a888524';
foreach my $d (['data1', 17072], ['data2', 16032])
{
    my ($file, $size) = @$d;
    $td->runtest("encrypt $file",
		 {$td->COMMAND => "aes +cbc -encrypt $key $file tmp1"},
		 {$td->STRING => "", $td->EXIT_STATUS => 0});
    # sleep one second so random number will get a different seed
    sleep(1);
    $td->runtest("encrypt $file again",
		 {$td->COMMAND => "aes +cbc -encrypt $key $file tmp2"},
		 {$td->STRING => "", $td->EXIT_STATUS => 0});
    foreach my $f (qw(tmp1 tmp2))
    {
	$td->runtest("check size",
		     {$td->STRING => sprintf("%d\n", stat($f)->size)},
		     {$td->STRING => "$size\n"});
    }
    $td->runtest("verify files are different",
		 {$td->COMMAND => "cmp tmp1 tmp2"},
		 {$td->REGEXP => '.*', $td->EXIT_STATUS => '!0'});
    $td->runtest("decrypt $file",
		 {$td->COMMAND => "aes +cbc -decrypt $key tmp1 tmp3"},
		 {$td->STRING => "", $td->EXIT_STATUS => 0});
    $td->runtest("decrypt $file again",
		 {$td->COMMAND => "aes +cbc -decrypt $key tmp2 tmp4"},
		 {$td->STRING => "", $td->EXIT_STATUS => 0});
    $td->runtest("check output",
		 {$td->FILE => "tmp3"},
		 {$td->FILE => $file});
    $td->runtest("check output",
		 {$td->FILE => "tmp4"},
		 {$td->FILE => $file});
}

cleanup();

$td->report(22);

sub cleanup
{
    system("rm -f tmp?");
}