test: add -macopt hexkey: to dgst command tests
authorPauli <pauli@openssl.org>
Wed, 4 Aug 2021 23:25:56 +0000 (09:25 +1000)
committerDmitry Belyavskiy <beldmit@gmail.com>
Thu, 5 Aug 2021 08:14:33 +0000 (10:14 +0200)
Comparison checksum generated using 1.1.1f.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/16212)

test/recipes/20-test_dgst.t

index d64d810edde3b2cc555e36e08370f64d5af13d53..5af74aec2acc2dbfd1b971293ae58a29cb0c6a54 100644 (file)
@@ -17,7 +17,7 @@ use OpenSSL::Test::Utils;
 
 setup("test_dgst");
 
-plan tests => 8;
+plan tests => 9;
 
 sub tsignverify {
     my $testtext = shift;
@@ -131,6 +131,21 @@ subtest "HMAC generation with `dgst` CLI, default digest" => sub {
        "HMAC: Check second HMAC value is consistent with the first ($hmacdata[1]) vs ($expected)");
 };
 
+subtest "HMAC generation with `dgst` CLI, key via option" => sub {
+    plan tests => 2;
+
+    my $testdata = srctop_file('test', 'data.bin');
+    #HMAC the data twice to check consistency
+    my @hmacdata = run(app(['openssl', 'dgst', '-sha256', '-hmac',
+                            '-macopt', 'hexkey:FFFF',
+                            $testdata, $testdata]), capture => 1);
+    chomp(@hmacdata);
+    my $expected = qr/HMAC-SHA2-256\(\Q$testdata\E\)= b6727b7bb251dfa65846e0a8223bdd57d244aa6d7e312cb906d8e21f2dee3a57/;
+    ok($hmacdata[0] =~ $expected, "HMAC: Check HMAC value is as expected ($hmacdata[0]) vs ($expected)");
+    ok($hmacdata[1] =~ $expected,
+       "HMAC: Check second HMAC value is consistent with the first ($hmacdata[1]) vs ($expected)");
+};
+
 subtest "Custom length XOF digest generation with `dgst` CLI" => sub {
     plan tests => 2;