Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evp parser tweak #3506

Closed
wants to merge 2 commits into from
Closed

Evp parser tweak #3506

wants to merge 2 commits into from

Conversation

richsalz
Copy link
Contributor

This is the evp_test part of #3471. It moves the parsing to be more similar to bn_test. I hope my text PR in this area will refactor out common code.

@@ -90,7 +91,8 @@ Digest = BLAKE2b512
Input = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F8081
Output = DF0A9D0C212843A6A934E3902B2DD30D17FBA5F969D2030B12A546D8A6A45E80CF5635F071F0452E9C919275DA99BED51EB1173C1AF0518726B75B0EC3BAE2B5

# SHA tests from RFC6234 section 8.5
Title = SHA(1) tests (from shatest.c)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shatest.c is not present anymore, no point to mention it. I'd suggest just "SHA1 tests" here and either "SHA2 tests" prior SHA224/256/384/512 or separate SHAxxx titles...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just made it "SHA tests"

test/evppbe.txt Outdated
Result = SCRYPT_ERROR
#maxmem = 10000000000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does move of #maxmem mean? That parser wouldn't tolerate it in old position?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. that will be fixed in a future PR.

test/evppkey.txt Outdated
# TEST CURVE secp112r1
Title = ECDH Tests: test with randomly generated keys for all the listed curves
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind broken. In this case Title refers to multiple curves, secp112r1 being just one, and flipping order kind of suggests that there is one curve and we exercise different algorithms on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@richsalz
Copy link
Contributor Author

additional commit pushed

@@ -90,7 +91,8 @@ Digest = BLAKE2b512
Input = 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F8081
Output = DF0A9D0C212843A6A934E3902B2DD30D17FBA5F969D2030B12A546D8A6A45E80CF5635F071F0452E9C919275DA99BED51EB1173C1AF0518726B75B0EC3BAE2B5

# SHA tests from RFC6234 section 8.5
Title = SHA tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say it's inappropriate to drop the reference to doc/spec.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anything there should be more references, not less...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense; restored comment; updated commit pushed.

test/evppkey.txt Outdated


# TEST CURVE secp112r1
Title = TEST CURVE secp112r1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this implies that you would have to entitle changes from one curve to next. Suggestion was rather to entitle it with "EDCH tests" and then have comments delimiting different curves...

@richsalz
Copy link
Contributor Author

I misunderstood. Updated commit pushed.

test/evppkey.txt Outdated
@@ -693,7 +695,7 @@ Result = KEYOP_INIT_ERROR
Function = pkey_pss_init
Reason = invalid salt length

# ECDH tests
Title ECDH tests
Copy link
Contributor

@dot-asm dot-asm May 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[When red-crossing] CI says

        # ERROR: 
        # Line 364993016: Missing '=' in test file

I assume it's talking about this line. But error message calls even for question about line number!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error message calls even for question about line number!

I naturally mean 364993016, which is not helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. that's a puzzle. looking at it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think i fixed it. updated commit pushed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no extra commits...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doh! pushed.

@dot-asm
Copy link
Contributor

dot-asm commented May 23, 2017

Line numbering is still broken. If I corrupt first Title in evpciph.txt it complains about line number -1185918280. But line numbers for corrupted test data are correct.

@dot-asm
Copy link
Contributor

dot-asm commented May 23, 2017

While you are at it and since you refer to bn_test. Can you look at line numbering in failed tests in bn_test? For example if you corrupt first test, it gets attributed to line 0. If you corrupt other than first, it gets attributed to line past previous test. While they should be attributed to first significant line of current test [like evp_test].

@richsalz
Copy link
Contributor Author

I don't see the Title line number bug:

1..1
    # Subtest: run_file_tests
    1..1
    # INFO:  @ test/evp_test.c:2521
    # Reading test/evpciph.txt

    # ERROR:  @ test/evp_test.c:2297
    # Line 22: Missing '=' in test file

    # INFO:  @ test/evp_test.c:2536
    # Completed 0 tests with 1 errors and 0 skipped

    not ok 1 - test/evpciph.txt
not ok 1 - run_file_tests
        exit 1

I'll look at bn_test. My plan is for the next PR to merge the parsing routines...

@dot-asm
Copy link
Contributor

dot-asm commented May 23, 2017

Speaking of Titles. There are too little of them. For example if you run evpciph.txt it test starting reports "DES EDE3 CFB1", "AES (from FIPS-197 test vectors)" and "AES tests from NIST document SP800-38A". But past last one there are loads of non-AES tests, then followed by AES-GCM, AES-OCB, AES-XTS, and again non-AES tests. Bottom line is that output from evp_test is effectively misleading.

@dot-asm
Copy link
Contributor

dot-asm commented May 23, 2017

   # ERROR:  @ test/evp_test.c:2297
   # Line 22: Missing '=' in test file

What can I say? I get different number every time I run, e.g. 1751751624, -2011814616, -525217528, 1936404088... What's your top? Mine is 135cffc27b9adb6df2a0d071e7f5168ddd59b73a

@richsalz
Copy link
Contributor Author

#3528 to fix the bntest issue you found.
My top is

commit f672095875ab6c5a0bfe03586a15020422234a66
Author: Rich Salz <rsalz@openssl.org>
Date:   Mon May 22 08:29:44 2017 -0400

    Fix Title comments (via Andy)

And I just now did a push -f.

@dot-asm
Copy link
Contributor

dot-asm commented May 23, 2017

I've got f672095875ab6c5a0bfe03586a15020422234a66 now, but it still prints random line numbers in reply to Title without =...

@richsalz
Copy link
Contributor Author

I'm using clang with debug flags. I'll try GCC.
Also pushed new commit to add more titles to evpciph.txt

@richsalz
Copy link
Contributor Author

ah, gcc shows the error. dang.

@richsalz
Copy link
Contributor Author

well this is strange:

(gdb) b 2297
Breakpoint 1 at 0x40910d: file test/evp_test.c, line 2297.
(gdb) r test/evpciph.txt
Starting program: /home/rsalz/openssl/github/test/evp_test test/evpciph.txt
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
1..1
    # Subtest: run_file_tests
    1..1
    # INFO:
    # Reading test/evpciph.txt


Breakpoint 1, split_line (t=0x7fffffff9ad0, keyword=0x7fffffff9a78,
    value=0x7fffffff9a80) at test/evp_test.c:2297
2297            TEST_error("Line %d: Missing '=' in test file", t->line);
(gdb) p t->line
$1 = 22
(gdb) n
    # ERROR:
    # Line -26296: Missing '=' in test file

I believe the problem is that test_error_c90 calls va_start/va_end`` and then calls test_fail_message``` which also does. Those nested calls break. This diff seems to fix it:

diff --git a/test/testutil/tests.c b/test/testutil/tests.c
index 3f75691..a5538e7 100644
--- a/test/testutil/tests.c
+++ b/test/testutil/tests.c
@@ -524,7 +524,7 @@ void test_error_c90(const char *desc, ...)
     va_list ap;

     va_start(ap, desc);
-    test_fail_message(NULL, NULL, -1, NULL, NULL, NULL, NULL, desc, ap);
+    test_fail_message_va(NULL, NULL, -1, NULL, NULL, NULL, NULL, desc, ap);
     va_end(ap);
 }

@richsalz
Copy link
Contributor Author

pushed a new commit with that fix.

@dot-asm
Copy link
Contributor

dot-asm commented May 23, 2017

add more titles to evpciph.txt

What about others? E.g. evpdigest.txt says ISO/IEC 10118-3 and does Whirlpool test. Yes, Whirlpool is there, but so are SHA and RIPEMD-160... evpmac.txt has only SIPHASH Title, but more algorithms than that...

@richsalz
Copy link
Contributor Author

I promise to do this in a separate PR. Will start shortl. Don't want to distract from this, which is all asbout the C code.

@dot-asm
Copy link
Contributor

dot-asm commented May 23, 2017

I promise to do this in a separate PR

Fair enough. Then it makes perfect sense to omit evpciph.txt commit here :-)

@dot-asm
Copy link
Contributor

dot-asm commented May 23, 2017

test_error_c90 calls va_start/va_end ... fix pushed

Confirmed.

@richsalz
Copy link
Contributor Author

#3529 has the additional titles stuff.
So still waiting on approval for this :)

@richsalz richsalz self-assigned this May 23, 2017
@richsalz
Copy link
Contributor Author

Moved all title changes to #3529

@dot-asm
Copy link
Contributor

dot-asm commented May 23, 2017

I expect this to be re-based after #3529 is merged, and pass through travis, only then I'll look into it...

Re-order and comment on the functions
@richsalz
Copy link
Contributor Author

rebased an squashed and pushed. waiting for travis.

}
return 1;
}

static int compare_mem(unsigned char *expected, size_t expected_len,
unsigned char *got, size_t got_len)
{
if (!TEST_mem_eq(expected, expected_len, got, got_len))
return 0;
return 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On side note one can probably argue that it calls to compare_mem should be replaced with TEST_mem_eq with rationale that __LINE__ would be more meaningful if it was compare_mem caller's.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that was done because the diff output wasn't totally useful before and having the local variables named expected and got was more helpful. Removing it is trivial, should I?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note "probably" in the side note. It means it's just an idea that might be worth considering. It might be sensible or it might not. But I can't prevent you from testing and telling how it looks. For example with regard to expected appearing in printout. It might be important, but then it might be possible to solve it by renaming some structure fields... Once again, something to consider...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know. But you're the one who has raised this issue before. So tell me which you prefer:

  # ERROR: (memory) 'mdata->output == mac' failed @ test/evp_test.c:1381
    # --- mdata->output
    # +++ mac
    # 0000:-b3817f04ba25a8e6 6df67214c7550293
    # 0000:+a3817f04ba25a8e6 6df67214c7550293
    #       ^^

Or this

    # ERROR: (memory) 'expected == got' failed @ test/evp_test.c:328
    # --- expected
    # +++ got
    # 0000:-b3817f04ba25a8e6 6df67214c7550293
    # 0000:+a3817f04ba25a8e6 6df67214c7550293
    #       ^^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I for one do care for line number in first output. And it's possible to make output more explicit by renaming output field to expected, so that it would read mdata->expected. However! Since going through this request was hell (coloured "Files changed" is impossible to follow), I'd insist on merging it as it is now and do further improvements in separate request. I can't handle going trough it again...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) It's not like you're review @levitte's STORE stuff :) Merged this. New PR coming to rename the fields. Thanks for the careful review and feedback!

@dot-asm dot-asm added branch: master Merge to master branch approval: done This pull request has the required number of approvals labels May 23, 2017
levitte pushed a commit that referenced this pull request May 24, 2017
Re-order and comment on the functions

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from #3506)
levitte pushed a commit that referenced this pull request May 24, 2017
Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from #3506)
@richsalz richsalz closed this May 24, 2017
@richsalz richsalz deleted the evp-parser-tweak branch May 24, 2017 12:43
@richsalz
Copy link
Contributor Author

See #3539

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: done This pull request has the required number of approvals branch: master Merge to master branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants