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
.endif
.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_v1/chacha20_poly1305_test.json
.endfor

View File

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

View File

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