Skip to content

Move all MACs to the providers#8877

Closed
levitte wants to merge 18 commits intoopenssl:masterfrom
levitte:move-mac-to-provider
Closed

Move all MACs to the providers#8877
levitte wants to merge 18 commits intoopenssl:masterfrom
levitte:move-mac-to-provider

Conversation

@levitte
Copy link
Member

@levitte levitte commented May 3, 2019

Because EVP_MAC is a new API, there is no legacy code to keep around, and the API is entirely adapted to support provider based implementations. This affects code in all kinds of places, all the way up to how openssl list -mac-algorithms does its work.

It's recommended to read the commit messages for explanation of some of the changes.


This currently depends on #9303

@levitte levitte force-pushed the move-mac-to-provider branch from 3d2fd03 to 8200c35 Compare May 5, 2019 17:55
@levitte levitte force-pushed the move-mac-to-provider branch from 8200c35 to e5632c2 Compare June 4, 2019 17:24
@levitte
Copy link
Member Author

levitte commented Jun 4, 2019

I've put down quite a lot of work in this, and there are multiple parts this change affects.

The EVP_MAC API itself

Because the EVP_MAC API is completely new and unreleased, I chose to throw away all the legacy stuff and make this completely provider based.

Most notably, this means that MACs are always fetched and that control functions are replaced with parameter passing functions.
It also means that MACs have no presence in the OBJ databases, except for the cases where a legacy EVP_PKEY implementation exists.

Information services

openssl list -mac-algorithms needed new code to be able to display information on existing MAC algorithms, and since the OBJ based functionality is now gone, a re-implementation of EVP_MAC_do_all and EVP_MAC_do_all_sorted is now needed.

TODO

  • Parameter names are currently scattered all over the code and need to be collected as macros in include/openssl/core_names.h.
  • Some functions and libcrypto<->provider interfaces are not yet implemented.

@levitte
Copy link
Member Author

levitte commented Jun 4, 2019

A note on these functions:

const OSSL_PARAM *EVP_MAC_CTX_get_param_types(const EVP_MAC *mac);
const OSSL_PARAM *EVP_MAC_CTX_set_param_types(const EVP_MAC *mac);

According to design discussions, these should return OSSL_ITEM arrays. However, that type is poor in information, especially regarding expected value sizes, and rather than creating yet another type, I thought that re-using OSSL_PARAM for parameter declaration and discovery purposes could be a viable idea. Special semantics apply to the data_size field, which means "arbitrary length" in this use.

I submit this as a proposal of a common manner to figure out available parameters.

@levitte
Copy link
Member Author

levitte commented Jun 5, 2019

I would appreciate some commentary on this

@levitte levitte force-pushed the move-mac-to-provider branch from e5632c2 to 6f8126a Compare June 5, 2019 10:45
@beldmit
Copy link
Member

beldmit commented Jun 5, 2019

Current TLS implementation refers to MAC NIDs. How can we change it to avoid this reference for future algorithms?

@levitte
Copy link
Member Author

levitte commented Jun 5, 2019

Current TLS implementation refers to MAC NIDs. How can we change it to avoid this reference for future algorithms?

Refer to them by name and use EVP_MAC_fetch()

@beldmit
Copy link
Member

beldmit commented Jun 5, 2019

I mean places similar to ssl_cipher_get_evp() and ssl_load_ciphers(). So for TLS < 1.3 we either have to refactor this code or register NIDs for new primitives. It seems not a problem but should be taken into account.

@levitte levitte force-pushed the move-mac-to-provider branch 2 times, most recently from 7d9a649 to e4e1561 Compare June 6, 2019 07:53
@levitte
Copy link
Member Author

levitte commented Jun 6, 2019

TODO

  • Figure out OPENSSL_CTX passing (will be another PR, as this should be solved on a wider scale)
  • Figure out passing of properties (just pass as a utf8 string parameter, I presume)

@levitte levitte force-pushed the move-mac-to-provider branch from a05d833 to c3ef44a Compare June 12, 2019 08:17
@levitte levitte force-pushed the move-mac-to-provider branch from c3ef44a to 836f845 Compare June 19, 2019 07:11
@levitte
Copy link
Member Author

levitte commented Jun 19, 2019

OPENSSL_CTX passing was pretty much solved in #9160. I need to work a little bit more on this PR to integrate that, but it's getting close.

It currently builds, at least on my machine, and tests pretty fine, except for the BLAKE2 MACs...

@levitte levitte force-pushed the move-mac-to-provider branch 4 times, most recently from 041ab3d to 6d1e72f Compare June 24, 2019 07:06
@levitte levitte marked this pull request as ready for review June 24, 2019 07:13
@levitte
Copy link
Member Author

levitte commented Jun 24, 2019

This is no longer a draft

@levitte
Copy link
Member Author

levitte commented Jun 24, 2019

Argh, of course, the OSSL_PARAM return size change makes it all go belly up...

It might take a week before I get to this...

@paulidale
Copy link
Contributor

Apologies :(

@levitte
Copy link
Member Author

levitte commented Jun 24, 2019

I approved it, so it's as much on me.

@levitte levitte force-pushed the move-mac-to-provider branch from c130139 to b2b2629 Compare June 24, 2019 08:28
@levitte levitte force-pushed the move-mac-to-provider branch from ea8bc66 to 85f7480 Compare August 15, 2019 12:10
@mattcaswell mattcaswell added the approval: done This pull request has the required number of approvals label Aug 15, 2019
@levitte
Copy link
Member Author

levitte commented Aug 15, 2019

I did a larger squashing job and pushed here to ensure that CIs are still happy. Feel free to have a new look through to see if I messed up... I don't think I did. If nothing goes wrong and no one complains, I'll use the approvals made so far.

@levitte
Copy link
Member Author

levitte commented Aug 15, 2019

Merged.

e74bd29 Prepare EVP_MAC infrastructure for moving all MACs to providers
55a0a11 Move BLAKE2 MACs to the providers
2e5db6a Move CMAC to providers
d33313b Move GMAC to providers
5183ebd Move HMAC to providers
e23cda0 Move KMAC to providers
4657693 Move SipHash to providers
ae0b6b9 Move Poly1305 to providers
6a4f9cd Remove init of MACs from EVP
d747fb2 Adapt apps/mac.c to use provider based MACs
776796e Adapt diverse code to provider based MACs.
25446a6 Adapt the MAC tests, and tests for other things that use EVP_MAC
f73eb73 Adjust some provider reason codes
810a1d0 OSSL_PARAM_construct_from_text(): handle non-hex octet string input
bb31895 Rename the hash implementations KMAC{128,256} to KECCAK_KMAC{128,256}
7dd0f29 Add EVP_MAC_provider()
d1cafb0 Implement EVP_MAC_do_all_ex()
467b8e5 Re-implement 'openssl list -mac-algorithms'

@levitte levitte closed this Aug 15, 2019
levitte added a commit that referenced this pull request Aug 15, 2019
Quite a few adaptations are needed, most prominently the added code
to allow provider based MACs.

As part of this, all the old information functions are gone, except
for EVP_MAC_name().  Some of them will reappear later, for example
EVP_MAC_do_all() in some form.

MACs by EVP_PKEY was particularly difficult to deal with, as they
need to allocate and deallocate EVP_MAC_CTXs "under the hood", and
thereby implicitly fetch the corresponding EVP_MAC.  This means that
EVP_MACs can't be constant in a EVP_MAC_CTX, as their reference count
may need to be incremented and decremented as part of the allocation
or deallocation of the EVP_MAC_CTX.  It may be that other provider
based EVP operation types may need to be handled in a similar manner.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
This also moves the remaining parts of BLAKE2 digests to the default
provider, and removes the legacy EVP implementation.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
Instead of using evp_keccak_kmac128() and evp_keccak_kmac256(), we refer
to the hash implementation by name, and fetch it, which should get us the
implementation from providers/common/digests/sha3_prov.c.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
Now that all our MACs have moved to the default provider, we let it
take over completely

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
CRMF, SSKDF, TLS1_PRF and SIV are affected by this.

This also forces the need to check MAC names, which leads to storing
the names in the created methods, which affects all EVP APIs, not just
EVP_MAC.  We will want that kind of information anyway (for example
for 'openssl list')...  Consequently, EVP_MAC_name() is re-implemented.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
BLAKE2 MACs came with a set of new reason codes.  Those talking about
lengths are consistently called PROV_R_INVALID_FOO_LENGTH, for any
name FOO.  The cipher messages were briefer.  In the interest of
having more humanly readable messages, we adjust the reasons used by
the ciphers (that's just IV length and key length).

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
This avoids getting them confused with the MAC implementations.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
For information processing.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
levitte added a commit that referenced this pull request Aug 15, 2019
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from #8877)
@h-vetinari
Copy link
Contributor

Should be moved to "Done" in the project board.

@levitte
Copy link
Member Author

levitte commented Nov 25, 2019

Done

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants