wycheproof: hide debug output behind -v flag

This commit is contained in:
Lucas Gabriel Vuotto 2024-05-31 16:53:05 +00:00
parent e62534925b
commit afc2e4b721
3 changed files with 37 additions and 25 deletions

View File

@ -18,7 +18,7 @@ tests-aead:
@echo Undefined WYCHEPROOF_DIR; false @echo Undefined WYCHEPROOF_DIR; false
.endif .endif
.for p in ${AEAD} .for p in ${AEAD}
perl ${.CURDIR}/aead.pl -x ./${p} \ perl ${.CURDIR}/aead.pl ${TESTOPTS} -x ./${p} \
${WYCHEPROOF_DIR}/testvectors/chacha20_poly1305_test.json \ ${WYCHEPROOF_DIR}/testvectors/chacha20_poly1305_test.json \
${WYCHEPROOF_DIR}/testvectors_v1/chacha20_poly1305_test.json ${WYCHEPROOF_DIR}/testvectors_v1/chacha20_poly1305_test.json
.endfor .endfor

View File

@ -21,7 +21,7 @@ sub main ()
my %opts; my %opts;
my $rc = 0; my $rc = 0;
getopts("x:", \%opts) && @ARGV > 0 or usage; getopts("vx:", \%opts) && @ARGV > 0 or usage;
usage unless defined $opts{"x"}; usage unless defined $opts{"x"};
for my $f (@ARGV) { for my $f (@ARGV) {
@ -42,6 +42,7 @@ sub main ()
push(@args, "-m", $test->{msg}); push(@args, "-m", $test->{msg});
push(@args, "-T", $testgroup->{tagSize}); push(@args, "-T", $testgroup->{tagSize});
push(@args, "-t", $test->{tag}); push(@args, "-t", $test->{tag});
push(@args, "-v") if $opts{"v"};
open(my $th, "-|", $opts{"x"}, @args) or die; open(my $th, "-|", $opts{"x"}, @args) or die;
my $result = slurp($th); my $result = slurp($th);

View File

@ -159,7 +159,7 @@ main(int argc, char *argv[])
size_t l, encoutlen, decoutlen; size_t l, encoutlen, decoutlen;
int aflag, cflag, Iflag, iflag, Kflag, kflag, mflag, int aflag, cflag, Iflag, iflag, Kflag, kflag, mflag,
Tflag, tflag; Tflag, tflag;
int ch; int ch, verbose;
if (argc < 2) if (argc < 2)
usage(); usage();
@ -171,7 +171,8 @@ main(int argc, char *argv[])
optind = 2; optind = 2;
aflag = cflag = Iflag = iflag = Kflag = kflag = mflag = Tflag = tflag = aflag = cflag = Iflag = iflag = Kflag = kflag = mflag = Tflag = tflag =
0; 0;
while ((ch = getopt(argc, argv, "a:c:I:i:K:k:m:T:t:")) != -1) { verbose = 0;
while ((ch = getopt(argc, argv, "a:c:I:i:K:k:m:T:t:v")) != -1) {
switch (ch) { switch (ch) {
case 'a': case 'a':
aflag = 1; aflag = 1;
@ -268,6 +269,9 @@ main(int argc, char *argv[])
if (!hexparse(optarg, tag, &l) || l != taglen) if (!hexparse(optarg, tag, &l) || l != taglen)
errx(1, "invalid hex string: %s", optarg); errx(1, "invalid hex string: %s", optarg);
break; break;
case 'v':
verbose = 1;
break;
default: default:
usage(); usage();
break; break;
@ -298,25 +302,30 @@ main(int argc, char *argv[])
if (ctlen != encoutlen - LC_POLY1305_TAGLEN || if (ctlen != encoutlen - LC_POLY1305_TAGLEN ||
lc_ct_cmp(encout, ct, ctlen) != 0) { lc_ct_cmp(encout, ct, ctlen) != 0) {
if (verbose) {
fprintf(stderr, "ct (%zu, %zu)\n", ctlen, fprintf(stderr, "ct (%zu, %zu)\n", ctlen,
encoutlen - LC_POLY1305_TAGLEN); encoutlen - LC_POLY1305_TAGLEN);
hexdump(stderr, msg, msglen); hexdump(stderr, msg, msglen);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
hexdump(stderr, ct, ctlen); hexdump(stderr, ct, ctlen);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
hexdump(stderr, encout, encoutlen - LC_POLY1305_TAGLEN); hexdump(stderr, encout,
encoutlen - LC_POLY1305_TAGLEN);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
}
puts("invalid"); puts("invalid");
return 1; return 1;
} }
if (taglenarg != LC_POLY1305_TAGLEN || if (taglenarg != LC_POLY1305_TAGLEN ||
lc_ct_cmp(encout + ctlen, tag, LC_POLY1305_TAGLEN) != 0) { lc_ct_cmp(encout + ctlen, tag, LC_POLY1305_TAGLEN) != 0) {
if (verbose) {
fprintf(stderr, "tag (%zu, %zu)\n", taglenarg, fprintf(stderr, "tag (%zu, %zu)\n", taglenarg,
(size_t)LC_POLY1305_TAGLEN); (size_t)LC_POLY1305_TAGLEN);
hexdump(stderr, tag, taglen); hexdump(stderr, tag, taglen);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
hexdump(stderr, encout + ctlen, LC_POLY1305_TAGLEN); hexdump(stderr, encout + ctlen, LC_POLY1305_TAGLEN);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
}
puts("invalid"); puts("invalid");
return 1; return 1;
} }
@ -344,6 +353,7 @@ main(int argc, char *argv[])
} }
if (msglen != decoutlen || lc_ct_cmp(decout, msg, msglen) != 0) { if (msglen != decoutlen || lc_ct_cmp(decout, msg, msglen) != 0) {
if (verbose) {
fprintf(stderr, "ct (%zu, %zu)\n", msglen, decoutlen); fprintf(stderr, "ct (%zu, %zu)\n", msglen, decoutlen);
hexdump(stderr, msg, msglen); hexdump(stderr, msg, msglen);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
@ -351,6 +361,7 @@ main(int argc, char *argv[])
fprintf(stderr, "\n"); fprintf(stderr, "\n");
hexdump(stderr, decout, decoutlen); hexdump(stderr, decout, decoutlen);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
}
puts("invalid"); puts("invalid");
return 1; return 1;
} }