Skip to content

Comments

Added DRBG_HMAC & DRBG_HASH#6779

Closed
slontis wants to merge 1 commit intoopenssl:masterfrom
slontis:drbg
Closed

Added DRBG_HMAC & DRBG_HASH#6779
slontis wants to merge 1 commit intoopenssl:masterfrom
slontis:drbg

Conversation

@slontis
Copy link
Member

@slontis slontis commented Jul 25, 2018

  • defaults can now be set for master/public/private
  • renamed generate_counter back to reseed_counter so it is not confusing and different from standard. (The value is actually used by the Hash DRBG, so I didnt want to use generate_counter+1 in that code.)
  • generated new cavs data tests.

I have not attempted to create any new API's, so some values have been added into flags parameters.

i.e-
(1) The DRBG_hmac uses the same type (nid's) as DRBG_hash - It just uses an additional flag to select HMAC.
(2) Since the DRBG’s don’t actually get setup until they are accessed via …master_get0() etc, the set_defaults() can be called multiple times to set default (type and flags) for master, public and private DRBG’s before they are used.

The uninstantiate() has been changed so that it can use any new defaults for type, flags. This mainly allows testing of different set_defaults (which you can’t really do any other way since the getters are static init_once methods that have Cleanups that only run on exit). (The uninstatiate() used to just clear the internal state and reset it back to the same type and flags).
There is also a set(type, flags) that can be also used to change the type & flags to a different DRBG. The set also now calls uninstatiate if required.

Checklist
  • documentation is added or updated
  • tests are added or updated

@slontis
Copy link
Member Author

slontis commented Jul 25, 2018

Test Failure(s) are related to the other pull request that was submitted today (6778)

@paulidale
Copy link
Contributor

Try make doc-nits for the documentation issue...

@kroeckx kroeckx added the FIPS label Jul 25, 2018
@slontis slontis mentioned this pull request Jul 25, 2018
@paulidale
Copy link
Contributor

I'm wondering if the label should be Post 1.1.1 rather than FIPS.

This change includes two other DRBGs, which are worthwhile as a fallback. FIPS requires a whole lot more testing etc.

I'm not fussed much either way.

Copy link
Member

Choose a reason for hiding this comment

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

Changing the value unnecessarily breaks ABI compat. Keep it as 1.

Copy link
Member

Choose a reason for hiding this comment

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

This is problematic. See #7182.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: issue #7182 has been fixed by #7190.

Copy link
Member

Choose a reason for hiding this comment

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

Why 2011? Copy & paste error?

Copy link
Contributor

Choose a reason for hiding this comment

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

The code was mostly lifted from the old FOM I believe.

Copy link
Member Author

Choose a reason for hiding this comment

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

The date is the same as the drbg_ctr.c file.
i.e- code was copied from old FOM and updated.

Copy link
Member

Choose a reason for hiding this comment

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

Multi line comments should start with a blank line like this:

/*
 * my multi
 * line comment
 */

Copy link
Member

Choose a reason for hiding this comment

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

Renaming this to be the same as what reseed_prop_counter used to be called seems like its going to be a source of errors when we cherry pick fixes from our new version to the 1.1.1 version.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bit unfortunate :) I will change it back and not match the standard :(

Copy link
Member

Choose a reason for hiding this comment

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

Well you could give it a different name that is almost the same as the standard (e.g. some suffix or other). Just calling it exactly the same as what something else was called sounds like a recipe for problems.

Copy link
Member

Choose a reason for hiding this comment

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

Describe params

Copy link
Member

Choose a reason for hiding this comment

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

Describe params

Copy link
Member

Choose a reason for hiding this comment

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

Where does this number come from?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added the following comments:
This one is a general one added up higher..
/* These are taken from SP 800-90 10.1 Table 2 */

/* Maximum number of bits per request = 2^19 = 2^16 bytes */

Copy link
Member

Choose a reason for hiding this comment

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

else on same line as }

Copy link
Member

Choose a reason for hiding this comment

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

Here we get a RANDerr call but nowhere else!

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean there are no RANDerr calls in drbg_ctr/drbg_hmac/drbg_hash?

Copy link
Member

Choose a reason for hiding this comment

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

Yes - that's my point. It seems inconsistent that there are no RANDerr calls elsewhere, but there is here. Not sure what the answer is - just pointing it out.

@slontis slontis force-pushed the drbg branch 2 times, most recently from dc1a287 to 17000d0 Compare September 17, 2018 01:00
Copy link
Member

Choose a reason for hiding this comment

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

I suspect some compilers will complain about the truncation here (size_t -> unsigned char) - even though we know it is safe. Might need a cast on each of these four lines, e.g.
tmp[tmp_sz++] = (unsigned char)(num_bits_returned & 0xff);

Copy link
Member

Choose a reason for hiding this comment

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

elseon same line as }. Also we need {} around the return 0 because we use them above (if you use {} on one branch, you must use them on all branches).

Copy link
Member

Choose a reason for hiding this comment

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

We never use OPENSSL_assert anymore (at least in the libraries). Use ossl_assert instead (or possibly just assert).

Copy link
Member

Choose a reason for hiding this comment

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

Possible cast required here (unsigned char)?

Copy link
Member

Choose a reason for hiding this comment

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

On all the other lines above you've used ctx, but here its hash->ctx. Why?

Copy link
Member

Choose a reason for hiding this comment

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

Possible casts needed?

Copy link
Member

Choose a reason for hiding this comment

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

Why the blank lines here?

Copy link
Member

Choose a reason for hiding this comment

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

Yes - that's my point. It seems inconsistent that there are no RANDerr calls elsewhere, but there is here. Not sure what the answer is - just pointing it out.

Copy link
Member

Choose a reason for hiding this comment

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

Why no 0x04or 0x08 flag?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have moved them down - I wanted to logically seperate the last 3 flags from the other flags - but it doesnt really matter.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I will leave the RANDerr call alone for now.. I think this is probably an issue across the entire code base that needs to be addressed.

…ter/public/private + renamed generate_counter back to reseed_counter + generated new cavs data tests
Copy link
Member

@mattcaswell mattcaswell left a comment

Choose a reason for hiding this comment

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

Approved. Ping @openssl/committers for second review

@paulidale
Copy link
Contributor

Merged. Thanks everyone.

@paulidale paulidale closed this Sep 27, 2018
levitte pushed a commit that referenced this pull request Sep 27, 2018
…ter/public/private + renamed generate_counter back to reseed_counter + generated new cavs data tests

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
(Merged from #6779)
calls are required to set the types to different values. If none of these 3
flags are used, then the same type and flags are used for all 3 DRBG's in the
B<drbg> chain (<master>, <public> and <private>). The default used if this
method is not called is to use RAND_DRBG_FLAGS.
Copy link
Member

Choose a reason for hiding this comment

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

This last sentence isn't making much sense to me.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it's not related to the 3 options above, and you want to write that after the =back? And it's probably more useful to say that the default is that all 3 DRBGs act as none of the options are set.

Copy link
Member Author

Choose a reason for hiding this comment

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

I could probably just shift it up to where it says
'If this method is not called then the default type is given by RAND_DRBG_TYPE.'

and change it to..

'If this method is not called then the default type is given by NID_aes_256_ctr and the default flags are zero.'

Copy link
Member Author

@slontis slontis Sep 28, 2018

Choose a reason for hiding this comment

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

Added PR #7326

NID_sha256, NID_sha384, NID_sha512, NID_sha512_224, NID_sha512_256,
NID_sha3_224, NID_sha3_256, NID_sha3_384 or NID_sha3_512.

If this method is not called then the default type is given by RAND_DRBG_TYPE.
Copy link
Member

Choose a reason for hiding this comment

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

This really doesn't tell anything, maybe explicitly say NID_aes_256_ctr?

drbg->meth->uninstantiate(drbg);
return RAND_DRBG_set(drbg, drbg->type, drbg->flags);

/* The reset uses the default values for type and flags */
Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Member Author

@slontis slontis Sep 28, 2018

Choose a reason for hiding this comment

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

The commit comment explains why it does this. i.e-

The uninstantiate() has been changed so that it can use any new defaults for type, flags. This mainly allows testing of different set_defaults (which you can’t really do any other way since the getters are static init_once methods that have Cleanups that only run on exit). (The uninstatiate() used to just clear the internal state and reset it back to the same type and flags).
There is also a set(type, flags) that can be also used to change the type & flags to a different DRBG. The set also now calls uninstatiate if required.

Copy link
Member

Choose a reason for hiding this comment

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

The commit message doesn't explain it, it's rather short.

The effect of this is if you did a RAND_DRBG_set(), and you uninstantiate it, it gets overridden by defaults now, which might be unexpected.


if (drbg->reseed_interval > 0) {
if (drbg->generate_counter >= drbg->reseed_interval)
if (drbg->reseed_gen_counter > drbg->reseed_interval)
Copy link
Member

Choose a reason for hiding this comment

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

Is the > vs >= some bug fix?

Copy link
Member Author

Choose a reason for hiding this comment

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

The counter starts at 1 instead of zero now.
(The value is actually used by the Hash DRBG)

@mattcaswell mattcaswell mentioned this pull request Oct 15, 2018
2 tasks
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.

5 participants