2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00
git-svn-id: svn+q:///qpdf/trunk@813 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
Jay Berkenbilt 2009-10-17 23:58:59 +00:00
parent e25910b59a
commit aaeb71093d
6 changed files with 93 additions and 6 deletions

View File

@ -8,22 +8,33 @@
static void usage()
{
std::cerr << "Usage: aes { -encrypt | -decrypt }"
std::cerr << "Usage: aes [+-]cbc { -encrypt | -decrypt }"
<< " hex-key infile outfile" << std::endl;
exit(2);
}
int main(int argc, char* argv[])
{
if (argc != 5)
if (argc != 6)
{
usage();
}
char* action = argv[1];
char* hexkey = argv[2];
char* infilename = argv[3];
char* outfilename = argv[4];
char* cbc = argv[1];
char* action = argv[2];
char* hexkey = argv[3];
char* infilename = argv[4];
char* outfilename = argv[5];
bool cbc_mode = true;
if (strcmp(cbc, "-cbc") == 0)
{
cbc_mode = false;
}
else if (strcmp(cbc, "+cbc") != 0)
{
usage();
}
bool encrypt = true;
if (strcmp(action, "-decrypt") == 0)
@ -72,6 +83,10 @@ int main(int argc, char* argv[])
Pl_StdioFile* out = new Pl_StdioFile("stdout", outfile);
Pl_AES_PDF* aes = new Pl_AES_PDF("aes_128_cbc", out, encrypt, key);
if (! cbc_mode)
{
aes->disableCBC();
}
// 16 < buffer size, buffer_size is not a multiple of 8 for testing
unsigned char buf[83];

71
libtests/qtest/aes.test Normal file
View File

@ -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?");
}

BIN
libtests/qtest/aes/data1 Normal file

Binary file not shown.

BIN
libtests/qtest/aes/data2 Normal file

Binary file not shown.

View File

@ -0,0 +1 @@
iÄŕŘj{0ŘÍ·€p´ĹZ•OdňäčnžîŇhH™

Binary file not shown.