Skip to content

DRBG: delay initialization of DRBG method until instantiation#11111

Closed
mspncp wants to merge 2 commits intoopenssl:masterfrom
mspncp:pr-wip
Closed

DRBG: delay initialization of DRBG method until instantiation#11111
mspncp wants to merge 2 commits intoopenssl:masterfrom
mspncp:pr-wip

Conversation

@mspncp
Copy link
Contributor

@mspncp mspncp commented Feb 17, 2020

Could not resist to reserve this beautiful number for my next pull request ;-)

Here it comes: This pull request is based on #11010, see #11010 (comment) for a detailed explanation of what it does. I had to rebase @slontis' pull request in order to pick up @levitte's fix f93a17f. Only the last two commits are relevant:

commit f428aec8bd1094a7bc0ca95bb99750fe3be7eba4

Check that the DRBG's internal state has been zeroized after uninstantiation

commit bc826c0f35c1176314c31e9fbd4fb68305b13863

DRBG: delay initialization of DRBG method until instantiation

Previously, the initialization was done immediately in RAND_DRBG_set(),
which is also called in RAND_DRBG_uninstantiate().

This made it difficult for the FIPS DRBG self test to verify that the
internal state had been zeroized, because it had the side effect that
the drbg->data structure was reinitialized immediately.

To solve the problem, RAND_DRBG_set() has been split in two parts

    static int rand_drbg_set(RAND_DRBG *drbg, int type, unsigned int flags);
    static int rand_drbg_init_method(RAND_DRBG *drbg);

and only the first part is called from RAND_DRBG_uninstantiate().

The pull request is marked WIP, because the test_rand is still failing. The internal logic of the delay initialization still needs some fine-tuning.

@mattcaswell
Copy link
Member

I note by the way that 11,111 is a product of 2 primes: 41 * 271

@mspncp
Copy link
Contributor Author

mspncp commented Feb 17, 2020

That's not enough for RSA, right?

@mattcaswell
Copy link
Member

That's not enough for RSA, right?

Not to do PKCS1 padding....not sure about "no padding". I think its safe to say I wouldn't trust my bank details with it.

@DDvO
Copy link
Contributor

DDvO commented Feb 17, 2020

I'm tempted to (ab-)use this PR as a degenerate test case for the latest ghmerge of openssl/tools#59

@mspncp mspncp changed the title WIP WIP: DRBG: delay initialization of DRBG method until instantiation Feb 17, 2020
@mspncp
Copy link
Contributor Author

mspncp commented Feb 17, 2020

I'm tempted to (ab-)use this PR as a degenerate test case for the latest ghmerge of openssl/tools#59

Sorry for spoiling your fun. I told you, it was only a placeholder for my next pull request ;-)

@mspncp mspncp mentioned this pull request Feb 17, 2020
2 tasks
@DDvO
Copy link
Contributor

DDvO commented Feb 17, 2020

I'm tempted to (ab-)use this PR as a degenerate test case for the latest ghmerge of openssl/tools#59

Sorry for spoiling your fun. I told you, it was only a placeholder for my next pull request ;-)

What a shame, I was going to approve the empty list of commits since I was sure it was error-free 🤣

@paulidale
Copy link
Contributor

I note by the way that 11,111 is a product of 2 primes: 41 * 271

I don't think we'll be around when the next repunit prime is reached.

@mspncp mspncp changed the title WIP: DRBG: delay initialization of DRBG method until instantiation DRBG: delay initialization of DRBG method until instantiation Feb 18, 2020
@mspncp mspncp added approval: review pending This pull request needs review by a committer branch: master Applies to master branch labels Feb 18, 2020
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a NULL access of drbg?

Copy link
Contributor

Choose a reason for hiding this comment

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

It isn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As Pauli already noted: it happens at compile time. So unless the compiler is buggy...

@slontis
Copy link
Member

slontis commented Feb 19, 2020

Should this be rebased after my PR goes in?

@mspncp
Copy link
Contributor Author

mspncp commented Feb 19, 2020

Yes, that was the intention.

@mspncp mspncp changed the title DRBG: delay initialization of DRBG method until instantiation [Pending on #11010] DRBG: delay initialization of DRBG method until instantiation Feb 19, 2020
Previously, the initialization was done immediately in RAND_DRBG_set(),
which is also called in RAND_DRBG_uninstantiate().

This made it difficult for the FIPS DRBG self test to verify that the
internal state had been zeroized, because it had the side effect that
the drbg->data structure was reinitialized immediately.

To solve the problem, RAND_DRBG_set() has been split in two parts

    static int rand_drbg_set(RAND_DRBG *drbg, int type, unsigned int flags);
    static int rand_drbg_init_method(RAND_DRBG *drbg);

and only the first part is called from RAND_DRBG_uninstantiate().
@mspncp
Copy link
Contributor Author

mspncp commented Feb 21, 2020

Rebased and squashed (without further changes) onto 980a880 (#11010).

@mspncp mspncp changed the title [Pending on #11010] DRBG: delay initialization of DRBG method until instantiation DRBG: delay initialization of DRBG method until instantiation Feb 21, 2020
@mspncp
Copy link
Contributor Author

mspncp commented Feb 21, 2020

Ready for review.

Copy link
Contributor

@paulidale paulidale left a comment

Choose a reason for hiding this comment

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

A nice clean break up of the functionality.

@paulidale paulidale added approval: done This pull request has the required number of approvals approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: review pending This pull request needs review by a committer approval: done This pull request has the required number of approvals labels Feb 24, 2020
@levitte
Copy link
Member

levitte commented Feb 25, 2020

Ready to merge!

@mspncp mspncp self-assigned this Feb 25, 2020
openssl-machine pushed a commit that referenced this pull request Feb 25, 2020
Previously, the initialization was done immediately in RAND_DRBG_set(),
which is also called in RAND_DRBG_uninstantiate().

This made it difficult for the FIPS DRBG self test to verify that the
internal state had been zeroized, because it had the side effect that
the drbg->data structure was reinitialized immediately.

To solve the problem, RAND_DRBG_set() has been split in two parts

    static int rand_drbg_set(RAND_DRBG *drbg, int type, unsigned int flags);
    static int rand_drbg_init_method(RAND_DRBG *drbg);

and only the first part is called from RAND_DRBG_uninstantiate().

Reviewed-by: Paul Dale <[email protected]>
(Merged from #11111)
openssl-machine pushed a commit that referenced this pull request Feb 25, 2020
@mspncp
Copy link
Contributor Author

mspncp commented Feb 25, 2020

Merged, thanks for the review!

e704521 Check that the DRBG's internal state has been zeroized after uninstantiation
75ff4f7 DRBG: delay initialization of DRBG method until instantiation

@mspncp mspncp closed this Feb 25, 2020
@mspncp mspncp deleted the pr-wip branch February 25, 2020 10:32
@slontis
Copy link
Member

slontis commented Feb 25, 2020

Thanks for doing this @mspncp

@mspncp
Copy link
Contributor Author

mspncp commented Feb 25, 2020

You're welcome. Always a pleasure :-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants