initial import
This commit is contained in:
commit
7bc527c769
28 changed files with 2071 additions and 0 deletions
25
wycheproof/Makefile
Normal file
25
wycheproof/Makefile
Normal file
|
@ -0,0 +1,25 @@
|
|||
.PATH: ${.CURDIR}/..
|
||||
|
||||
AEAD= wycheproof_aead
|
||||
|
||||
PROGS= ${AEAD}
|
||||
NOMAN= noman
|
||||
|
||||
SRCS_wycheproof_aead= wycheproof_aead.c
|
||||
|
||||
LDADD+= ${.CURDIR}/../lib/obj/liblilcrypto.a
|
||||
|
||||
|
||||
tests: all tests-aead
|
||||
|
||||
tests-aead:
|
||||
.ifndef WYCHEPROOF_DIR
|
||||
@echo Undefined WYCHEPROOF_DIR; false
|
||||
.endif
|
||||
.for p in ${AEAD}
|
||||
perl ${.CURDIR}/aead.pl -x ./${p} \
|
||||
${WYCHEPROOF_DIR}/testvectors/chacha20_poly1305_test.json \
|
||||
${WYCHEPROOF_DIR}/testvectors_v1/chacha20_poly1305_test.json
|
||||
.endfor
|
||||
|
||||
.include <bsd.prog.mk>
|
69
wycheproof/aead.pl
Normal file
69
wycheproof/aead.pl
Normal file
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env perl
|
||||
use v5.38;;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Getopt::Std;
|
||||
use JSON::PP;
|
||||
|
||||
my $progname = $0 =~ s@.*/@@r;
|
||||
|
||||
sub slurp ($fh) { local $/; <$fh> }
|
||||
|
||||
sub usage ()
|
||||
{
|
||||
say STDERR "Usage: $progname -x runner json_file [json_files ...]";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
sub main ()
|
||||
{
|
||||
my %opts;
|
||||
my $rc = 0;
|
||||
|
||||
getopts("x:", \%opts) && @ARGV > 0 or usage;
|
||||
usage unless defined $opts{"x"};
|
||||
|
||||
for my $f (@ARGV) {
|
||||
open(my $fh, "<", $f) or die "open failed: $!";
|
||||
|
||||
my $json = decode_json(slurp($fh));
|
||||
for my $testgroup ($json->{testGroups}->@*) {
|
||||
for my $test ($testgroup->{tests}->@*) {
|
||||
my @args;
|
||||
|
||||
push(@args, $json->{algorithm});
|
||||
push(@args, "-a", $test->{aad});
|
||||
push(@args, "-c", $test->{ct});
|
||||
push(@args, "-I", $testgroup->{ivSize});
|
||||
push(@args, "-i", $test->{iv});
|
||||
push(@args, "-K", $testgroup->{keySize});
|
||||
push(@args, "-k", $test->{key});
|
||||
push(@args, "-m", $test->{msg});
|
||||
push(@args, "-T", $testgroup->{tagSize});
|
||||
push(@args, "-t", $test->{tag});
|
||||
|
||||
open(my $th, "-|", $opts{"x"}, @args) or die;
|
||||
my $result = slurp($th);
|
||||
close($th);
|
||||
|
||||
chomp($result);
|
||||
if ($result ne $test->{result}) {
|
||||
$rc = 1;
|
||||
say STDERR "case $test->{tcId}: ",
|
||||
"expected $test->{result}: ",
|
||||
"$test->{comment} [",
|
||||
join(",", $test->{flags}->@*),
|
||||
"]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close($fh);
|
||||
}
|
||||
|
||||
say "ALL TESTS PASSED!" if $rc == 0;
|
||||
return $rc;
|
||||
}
|
||||
|
||||
exit main;
|
Loading…
Add table
Add a link
Reference in a new issue