Skip to content

DSA cdf tests#280

Merged
karel-m merged 15 commits intorelease/1.18.0from
pr/fix-dsa-cdf
Sep 14, 2017
Merged

DSA cdf tests#280
karel-m merged 15 commits intorelease/1.18.0from
pr/fix-dsa-cdf

Conversation

@karel-m
Copy link
Copy Markdown
Member

@karel-m karel-m commented Aug 29, 2017

Another crypto test bench https://github.com/kudelskisecurity/cdf

Good news - our RSA implementation seems to pass. But we have couple of DSA related troubles.

The first commit fixes failures when ltc is on "validating" side. There are still some failures when ltc is on "signing" side, I'll try to analyze those later.

@karel-m
Copy link
Copy Markdown
Member Author

karel-m commented Aug 29, 2017

Well, it turned out that the case when ltc is on "signing" side is OK. So this PR is complete.

@karel-m
Copy link
Copy Markdown
Member Author

karel-m commented Sep 10, 2017

@sjaeckel ping

Copy link
Copy Markdown
Member

@sjaeckel sjaeckel left a comment

Choose a reason for hiding this comment

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

Looks good, but somehow it seems now to be slightly inconsistent with what dsa_verify_key() checks, shouldn't this be updated as well? or should we probably have two versions of dsa_verify_key()? I'm just thinking that dsa_set_pqg_dsaparam() does the same as dsa_set_pqg() but lacks these newly added checks...

@sjaeckel
Copy link
Copy Markdown
Member

sjaeckel commented Sep 11, 2017

We could e.g. have an internal (say LTC_SOURCE protected) dsa_check_key() which is then called from within dsa_verify_key(), dsa_set_pqg_dsaparam() and dsa_set_pqg() (and probably others that I missed?). This one would then only have these trivial checks without all the more complex stuff.

@karel-m
Copy link
Copy Markdown
Member Author

karel-m commented Sep 11, 2017

something like this?

@sjaeckel
Copy link
Copy Markdown
Member

Do we really need such extensive tests? (the 2 exptmod's?)
Besides that I realized that the name verify_key() is nonsense, therefore I've pushed my proposal to the pr/fix-dsa-cdf-2 branch. What do you think?

  1. Can we make dsa_int_validate_key() a bit less computational expensive by moving the 2 exptmods to dsa_validate_key()?
  2. Wouldn't it make sense to use LTC_MILLER_RABIN_REPS for the prime checks?
  3. With your last commit you removed stuff that you added in the commit before (in dsa_set_pqg())
    a. Was that accidental or itentional?
    b. The 'newly added' was three mp_cmp_d() whereas dsa_verify_key_ex() has only two + a different logic, can you please check back which is correct!?

@karel-m
Copy link
Copy Markdown
Member Author

karel-m commented Sep 11, 2017

we should perhaps keep the name dsa_verify_key as it is part of 1.17 API

@sjaeckel
Copy link
Copy Markdown
Member

we should perhaps keep the name dsa_verify_key as it is part of 1.17 API

damn, sorry - sure

I'll just update the branch

@karel-m
Copy link
Copy Markdown
Member Author

karel-m commented Sep 11, 2017

With your last commit you removed stuff that you added in the commit before (in dsa_set_pqg())

The thing is that at the end of dsa_set_pqg() we do not have a complete key, therefore we cannot do the key check/validation.

@sjaeckel
Copy link
Copy Markdown
Member

The thing is that at the end of dsa_set_pqg() we do not have a complete key, therefore we cannot do the key check/validation.

but it looks to me like part of it was required for the cdf tests to pass, right?

@sjaeckel
Copy link
Copy Markdown
Member

I'll just update the branch

pushed

@karel-m
Copy link
Copy Markdown
Member Author

karel-m commented Sep 11, 2017

What we need is to avoid loading/setting/creating a DSA key with p or g or q (not sure what was the main trouble maker) with value 0.

It would be better to check it in dsa_set_pqg but it is IMO fine to do it a bit later during dsa_set_key (where we have the key complete).

@karel-m
Copy link
Copy Markdown
Member Author

karel-m commented Sep 12, 2017

I have slightly updated your pr/fix-dsa-cdf-2 - which works and can be merged

@sjaeckel
Copy link
Copy Markdown
Member

sjaeckel commented Sep 12, 2017

What we need is to avoid loading/setting/creating a DSA key with p or g or q (not sure what was the main trouble maker) with value 0.

Okay, but the different parts of the implementation I saw had checks for {p,g,q} > 1 |p| > 1 and I don't know what else. Reading quickly through FIPS 186-4 I couldn't determine what is the correct approach so can you please check again what we really have to do?

I think it'd make sense to have 2 private functions dsa_int_validate_group_params() and dsa_int_validate_key() and 1 API function dsa_verify_key(). This allows us to correctly verify each step of the key import/generation.

Flow could be something like this:

int dsa_verify_key() {
 check_prime(q);
 check_prime(p);
 return dsa_int_validate_key();
}

int dsa_int_validate_group_params() {
 ...
}

int dsa_int_validate_key() {
 if (dsa_int_validate_group_params()) return;
 ...
}

What do you think?

@karel-m
Copy link
Copy Markdown
Member Author

karel-m commented Sep 14, 2017

I'll check FIPS 186-4 but meanwhile another approach for dsa_int_validate_*

@karel-m
Copy link
Copy Markdown
Member Author

karel-m commented Sep 14, 2017

@sjaeckel could you please review this PR again?

Copy link
Copy Markdown
Member

@sjaeckel sjaeckel left a comment

Choose a reason for hiding this comment

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

Looks very good! Thanks!

Comment thread src/pk/dsa/dsa_verify_key.c Outdated
void *tmp1, *tmp2;
int err;

*stat = 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ew, de-referencing stat before checking for NULL

Comment thread src/headers/tomcrypt_pk.h
int dsa_export(unsigned char *out, unsigned long *outlen, int type, dsa_key *key);
int dsa_verify_key(dsa_key *key, int *stat);

#ifdef LTC_SOURCE
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you please add the obligatory /* internal helper functions */ comment

Comment thread src/pk/dsa/dsa_verify_key.c Outdated
err = CRYPT_OK;
*stat = 1;
error:
mp_clear_multi(tmp1, tmp2, NULL);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you please (always) reverse the order when clearing MPI's

Comment thread src/pk/dsa/dsa_import.c
goto LBL_ERR;
}
if (stat == 0) {
err = CRYPT_INVALID_PACKET;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like we inconsistently return either CRYPT_INVALID_PACKET or CRYPT_INVALID_ARG, we should always use the same error code. I'd say we should go for CRYPT_INVALID_PACKET (an alternative could be to introduce a new error code, but not sure if that's really necessary).

/* first make sure key->q and key->p are prime */
if ((err = mp_prime_is_prime(key->q, 8, &res)) != CRYPT_OK) {
/* key->q prime? */
if ((err = mp_prime_is_prime(key->q, LTC_MILLER_RABIN_REPS, &res)) != CRYPT_OK) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@karel-m karel-m merged commit 5934eb3 into release/1.18.0 Sep 14, 2017
@karel-m karel-m deleted the pr/fix-dsa-cdf branch September 14, 2017 17:10
@karel-m
Copy link
Copy Markdown
Member Author

karel-m commented Sep 14, 2017

Oh sorry, I should perhaps wait for Travis-CI

@sjaeckel
Copy link
Copy Markdown
Member

Too late, the build's going to fail ;)

@sjaeckel
Copy link
Copy Markdown
Member

but nvm, as the merge will be built as well...

@sjaeckel sjaeckel added this to the v1.18.0 milestone Sep 14, 2017
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.

2 participants