diff options
author | HyungKyu Song <hk76.song@samsung.com> | 2013-02-16 00:53:53 +0900 |
---|---|---|
committer | HyungKyu Song <hk76.song@samsung.com> | 2013-02-16 00:53:53 +0900 |
commit | 630bf4ddf6be4761ce511907bad30a9d7cffb29a (patch) | |
tree | 3b7e9e6c8da998871d335586b9a8d475b8a4aa68 /libtests/qtest/aes.test | |
parent | 004ea5d29ad94c8310c81ea071c0176bfddc46f7 (diff) | |
download | qpdf-630bf4ddf6be4761ce511907bad30a9d7cffb29a.tar.gz qpdf-630bf4ddf6be4761ce511907bad30a9d7cffb29a.tar.bz2 qpdf-630bf4ddf6be4761ce511907bad30a9d7cffb29a.zip |
Diffstat (limited to 'libtests/qtest/aes.test')
-rw-r--r-- | libtests/qtest/aes.test | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/libtests/qtest/aes.test b/libtests/qtest/aes.test new file mode 100644 index 0000000..7e48840 --- /dev/null +++ b/libtests/qtest/aes.test @@ -0,0 +1,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?"); +} |