Skip to content

Conversation

@karel-m
Copy link
Member

@karel-m karel-m commented Oct 4, 2018

The recent ECDSA related changes (ecc_recover_key & co.) made ecc_verify_hash_ex a little bit more stricter (I know, it was my idea).

However, it turned out that 2 tests from wycheproof test suite started to fail.

Both cases were in category "acceptable" (so basically it is fine to reject them but also to accept them).

The 100% correct signature looks like this (hexa):

00000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000001

The "acceptable" signature looks like this (hexa):

0501

So with this PR we will accept the "acceptable" signature as we did before ecc_recover_key.

I have added both failing test cases to ecc_test.c

@karel-m karel-m requested a review from sjaeckel October 4, 2018 21:26
@karel-m
Copy link
Member Author

karel-m commented Oct 4, 2018

Cc: @rmw42

@rmw42
Copy link
Contributor

rmw42 commented Oct 4, 2018

Ah... this is the checking the length of the r/s values, rather than just dividing the buffer length in 2? Fair enough. There's no great solution in a format which doesn't mark the lengths :(

tests/ecc_test.c Outdated
return err;
}

static int _ecc_issue443(void) /* https://github.com/libtom/libtomcrypt/issues/443 */
Copy link
Member

Choose a reason for hiding this comment

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

same

else if (sigformat == LTC_ECCSIG_RFC7518) {
/* RFC7518 format - raw (r,s) */
i = mp_unsigned_bin_size(key->dp.order);
if (siglen != (2*i)) {
Copy link
Member

Choose a reason for hiding this comment

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

I also preferred this version of the check TBH

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'm not convinced that {0x05, 0x01} should be a valid signature blob for ECDSA, let alone that it should be in a security/proofing library.

Copy link
Member

@sjaeckel sjaeckel Oct 4, 2018

Choose a reason for hiding this comment

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

I also don't like that it could be a valid signature, but it's a valid edge-case... :/

... and history has proven that there are always implementations who do worse than your implementation so this (0x000..05...) is a good another example of Postel's Law IMO :)

@karel-m karel-m force-pushed the pr/ecc-verify-was-too-strict branch from 5e7ad04 to 1ac1072 Compare October 4, 2018 21:39
@sjaeckel
Copy link
Member

sjaeckel commented Oct 4, 2018

The 100% correct signature looks like this (hexa):

00000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000001

The "acceptable" signature looks like this (hexa):

0501

I just thought that this check could then still be done after the mp_read_unsigned_bin() or would this be redundant with the "check for zero" tests after init of r and s?

@rmw42
Copy link
Contributor

rmw42 commented Oct 4, 2018

A rather more radical solution would be to throw the test out entirely, and consider every possible partition of the input string, one by one. That way we make no assumptions at all about the padded size of r and s, and could support 0501 or 0000050001 or 05000000000000000001...

Would probably want to be a flags parameter to ecc_verify_hash_ex_ex, for strict/normal/ludicrously_flexible... and I can't see any reason why anyone would want that functionality...

@karel-m
Copy link
Member Author

karel-m commented Oct 4, 2018

I do not have a strong opinion on this. Let's give it a day or two to think it over.

@sjaeckel
Copy link
Member

sjaeckel commented Oct 4, 2018

I do not have a strong opinion on this. Let's give it a day or two to think it over.

IMO it's good as it is now

@rmw42
Copy link
Contributor

rmw42 commented Oct 4, 2018

Yeah, agreed. I'd say there's a problem with wycheproof but, until/unless they fix it, the test needs to be the way it is now.

@karel-m
Copy link
Member Author

karel-m commented Oct 4, 2018

In fact there is newer wycheproof test suite than I am using - https://github.com/google/wycheproof

@rmw42
Copy link
Contributor

rmw42 commented Oct 4, 2018

In fact there is newer wycheproof test suite than I am using - https://github.com/google/wycheproof

It's still got that test in there, though :(

@karel-m
Copy link
Member Author

karel-m commented Oct 4, 2018

BTW my quick check - there is at least 20 new ECDSA edge-cases that we do not implement correctly 😞

@karel-m karel-m force-pushed the pr/ecc-verify-was-too-strict branch from 1ac1072 to 59bc3b5 Compare October 5, 2018 05:44
@karel-m karel-m merged commit 223ece7 into develop Oct 5, 2018
@karel-m karel-m deleted the pr/ecc-verify-was-too-strict branch October 5, 2018 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants