update wycheproof tests
Karel Miko
5 years ago
7 | 7 | |
8 | 8 | plan skip_all => "No JSON::* module installed" unless eval { require JSON::PP } || eval { require JSON::XS } || eval { require Cpanel::JSON::XS }; |
9 | 9 | #plan skip_all => "Temporarily disabled"; |
10 | plan tests => 13299; | |
10 | plan tests => 14139; | |
11 | 11 | |
12 | 12 | use CryptX; |
13 | 13 | use Crypt::Misc 'read_rawfile'; |
14 | 14 | use Crypt::Digest 'digest_data'; |
15 | 15 | |
16 | if (0) { | |
16 | if (1) { | |
17 | 17 | use Crypt::AuthEnc::ChaCha20Poly1305 qw(chacha20poly1305_encrypt_authenticate chacha20poly1305_decrypt_verify); |
18 | 18 | |
19 | 19 | my $tests = CryptX::_decode_json read_rawfile 't/wycheproof/chacha20_poly1305_test.json'; |
117 | 117 | } |
118 | 118 | elsif ($result eq 'invalid') { |
119 | 119 | SKIP: { |
120 | skip "ltc bug", 1 if $comment eq "bit padding"; #XXX-FIXME | |
121 | skip "ltc bug", 1 if $comment eq "zero padding"; #XXX-FIXME | |
120 | skip "ltc bug CBC/PAD", 1 if $comment eq "bit padding"; #XXX-FIXME | |
121 | skip "ltc bug CBC/PAD", 1 if $comment eq "zero padding"; #XXX-FIXME | |
122 | 122 | is($pt2, undef, "$testname PT-i"); |
123 | 123 | } |
124 | 124 | } |
129 | 129 | } |
130 | 130 | } |
131 | 131 | |
132 | if (0) { | |
132 | if (1) { | |
133 | 133 | use Crypt::AuthEnc::GCM qw(gcm_encrypt_authenticate gcm_decrypt_verify); |
134 | 134 | |
135 | 135 | my $tests = CryptX::_decode_json read_rawfile 't/wycheproof/aes_gcm_test.json'; |
243 | 243 | is(unpack("H*", $pt2), $t->{msg}, "$testname PT-a"); |
244 | 244 | } |
245 | 245 | elsif ($result eq 'invalid') { |
246 | SKIP: { | |
247 | skip "ltc bug", 1 if $comment eq "Invalid tag size"; #XXX-FIXME | |
248 | is($pt2, undef, "$testname PT-i"); | |
249 | } | |
246 | is($pt2, undef, "$testname PT-i"); | |
250 | 247 | } |
251 | 248 | else { |
252 | 249 | ok(0, "UNEXPECTED result=$result"); |
257 | 254 | |
258 | 255 | if (1) { |
259 | 256 | use Crypt::PK::RSA; |
260 | use Crypt::PK::ECC; | |
261 | 257 | my @files = ( "t/wycheproof/rsa_signature_test.json" ); |
262 | 258 | push @files, glob("t/wycheproof/rsa_signature_*_test.json"); |
263 | 259 | push @files, glob("t/wycheproof/rsa_pss_*.json "); |
298 | 294 | } |
299 | 295 | elsif ($result eq 'invalid') { |
300 | 296 | SKIP: { |
301 | skip "ltc bug", 1 if $comment eq "changing tag value of sequence"; #XXX-FIXME | |
297 | skip "ltc bug RSA", 1 if $comment eq "changing tag value of sequence"; #XXX-FIXME | |
302 | 298 | ok(!$valid, $testname); |
303 | 299 | } |
304 | 300 | } |
347 | 343 | } |
348 | 344 | elsif ($result eq 'invalid') { |
349 | 345 | SKIP: { |
350 | skip "ltc bug", 1 if $comment eq "changing tag value of sequence"; #XXX-FIXME | |
346 | skip "ltc bug DSA", 1 if $comment eq "changing tag value of sequence"; #XXX-FIXME | |
351 | 347 | ok(!$valid, $testname); |
352 | 348 | } |
353 | 349 | } |
388 | 384 | my $valid = $pk->verify_message($sig, $message, $sha); |
389 | 385 | if ($result eq 'valid') { |
390 | 386 | SKIP: { |
391 | skip "ltc bug", 1 if $comment eq "Edge case for Shamir multiplication"; #XXX-FIXME | |
392 | skip "ltc bug", 1 if $comment eq "extreme value for k and edgecase s"; #XXX-FIXME | |
393 | skip "ltc bug", 1 if $comment eq "extreme value for k"; #XXX-FIXME | |
394 | skip "ltc bug", 1 if $comment eq "extreme value for k and s^-1"; #XXX-FIXME | |
395 | skip "ltc bug", 1 if $comment eq "extreme value for k and edgecase s"; #XXX-FIXME | |
387 | skip "ltc bug ECC", 1 if $comment eq "Edge case for Shamir multiplication"; #XXX-FIXME | |
388 | skip "ltc bug ECC", 1 if $comment eq "extreme value for k and edgecase s"; #XXX-FIXME | |
389 | skip "ltc bug ECC", 1 if $comment eq "extreme value for k"; #XXX-FIXME | |
390 | skip "ltc bug ECC", 1 if $comment eq "extreme value for k and s^-1"; #XXX-FIXME | |
391 | skip "ltc bug ECC", 1 if $comment eq "extreme value for k and edgecase s"; #XXX-FIXME | |
396 | 392 | ok($valid, "$testname verify_message=$valid"); |
397 | 393 | } |
398 | 394 | } |
399 | 395 | elsif ($result eq 'acceptable') { |
400 | 396 | SKIP: { |
401 | skip "ltc bug", 1 if $comment eq "Hash weaker than DL-group"; #XXX-FIXME | |
397 | skip "ltc bug ECC", 1 if $comment eq "Hash weaker than DL-group"; #XXX-FIXME | |
402 | 398 | #ok($valid, "$testname verify_message=$valid"); ## treat "acceptable" as "valid" |
403 | 399 | ok(!$valid, "$testname verify_message=$valid"); ## treat "acceptable" as "invalid" |
404 | 400 | #ok(1, "do not care about 'acceptable'"); ## ignore acceptable |
406 | 402 | } |
407 | 403 | elsif ($result eq 'invalid') { |
408 | 404 | SKIP: { |
409 | skip "ltc bug", 1 if $comment eq "changing tag value of sequence"; #XXX-FIXME | |
410 | skip "ltc bug", 1 if $comment eq "long form encoding of length"; #XXX-FIXME | |
411 | skip "ltc bug", 1 if $comment eq "length contains leading 0"; #XXX-FIXME | |
405 | skip "ltc bug ECC", 1 if $comment eq "changing tag value of sequence"; #XXX-FIXME | |
406 | skip "ltc bug ECC", 1 if $comment eq "long form encoding of length"; #XXX-FIXME | |
407 | skip "ltc bug ECC", 1 if $comment eq "length contains leading 0"; #XXX-FIXME | |
412 | 408 | ok(!$valid, "$testname verify_message=$valid"); |
413 | 409 | } |
414 | 410 | |
447 | 443 | my $valid = $pk->verify_message_rfc7518($sig, $message, $sha); |
448 | 444 | if ($result eq 'valid') { |
449 | 445 | SKIP: { |
450 | skip "ltc bug", 1 if $comment eq "Edge case for Shamir multiplication"; #XXX-FIXME | |
446 | skip "ltc bug ECC", 1 if $comment eq "Edge case for Shamir multiplication"; #XXX-FIXME | |
451 | 447 | ok($valid, "$testname verify_message=$valid"); |
452 | 448 | } |
453 | 449 | } |
454 | 450 | elsif ($result eq 'acceptable') { |
455 | 451 | SKIP: { |
456 | skip "ltc bug", 1 if $comment eq "Hash weaker than DL-group"; #XXX-FIXME | |
452 | skip "ltc bug ECC", 1 if $comment eq "Hash weaker than DL-group"; #XXX-FIXME | |
457 | 453 | #ok($valid, "$testname verify_message=$valid"); ## treat "acceptable" as "valid" |
458 | 454 | ok(!$valid, "$testname verify_message=$valid"); ## treat "acceptable" as "invalid" |
459 | 455 | #ok(1, "do not care about 'acceptable'"); ## ignore acceptable |