-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove cipher.h in 4.0 #8451
Comments
The general wisdom for API transitions is to have one full major version cycle where the new API is stable and the old API is present but deprecated. In Mbed TLS 3, we're at an intermediate stage where the new API is stable but old API is not deprecated. There are features of cipher that are not provided through the PSA API, but that we want to keep in the library: XTS, NIST KW. If we remove cipher, we really need to provide them through PSA, and that's a nontrivial amount of work. We're still working on an API that would be suitable for NIST KW and I'm not convinced we'll ship that in 4.0. There are nontrivial discrepancies between the legacy cipher API and the PSA cipher/AEAD APIs. So implementing even a useful subset of cipher on top of PSA is not easy. In addition to XTS and KW:
So I'm torn. From a user's perspective, we really should keep the cipher interface as deprecated. But it's a significant amount of work. |
I think there's an other option I forgot, which may be useful in cases like this (that is, where implementing the old API as a thin wrapper around PSA is not easy): keep People who want to keep using the Cipher API pay a higher price in code size (since Cipher's not a wrapper around PSA, there's some duplication between its implementation and PSA's cipher/aead implementation), but people who are using PSA only are not paying that price. For us, that's less work in that we don't have to re-implement Cipher on PSA, but OTOH that means we need to prioritize migrating internal users away from Cipher in order to improve code size - but unless I'm mistaken that's something we need to do anyway to optimize code size for people who only use PSA. |
And yet, unless I'm mistaken, we've done it with |
Note (just for reference, I don't think it influences the decision to keep Cipher or not): currently (with
|
Aw, I think I forgot a work item for "option 2 (remove)": what about uses of types from
Actually, I say that's a work item for option 2, but that's something we probably still want to do with option 1 anyway. |
This would mean that we still need to maintain a parallel implementation in the lifetime of 4.x. This could be quite expensive as we probably will want to adjust the low level APIs. If we still have the old cipher module implementation (I mean as opposed to being a thin wrapper) around when we do that, we will have additional constraints and update more code. Making cipher a thin wrapper around PSA would make this problem go away, but it is expensive and risky on its own. I think the cleanest solution here is removal (option 2). (From the user perspective in essence this is just like any other API break since we provide a stable alternative. It might only look like a removal because the stable alternative is already present.) |
The problem is the parts of cipher for which there isn't a stable alternative yet: XTS and NIST KW as Gilles pointed out. |
My current thinking is:
|
For reference, the two changes we need to make are:
The 2nd one is likely to require us to rework the module's implementation as well to work on top of PSA APIs, but that's desirable anyway, and in the past such transitions were found to be a reasonable amount of work. |
Decision: we're removing This is a minor loss of functionality (e.g. cipher names, some exotic padding modes, ...). We'll need to adapt a few things. A detailed investigation is needed. At least:
|
We decided to go for Option 3: keep but offer no interface stability. After the repo-split the remaining task here is to document this fact clearly. |
This issue is meant as a place to discuss what we want to do with Cipher in 4.0.
There are two main options:
Note: Cipher currently provides functionality similar to two PSA Crypto families:
psa_cipher_xxx()
andpsa_aead_xxx()
, plus it also wraps NIST-KW (which is not covered by PSA so far, and treated as an AEAD by Cipher). It provides both streaming and one-shot API for each family.Note: for low-level cipher/AEAD modules (
aes.h
,gcm.h
etc) I think the plan is to remove them from the public API, regardless of what we do with Cipher - the only exception beingnist_kw.h
.Rationale for option 1 (keep)
This gives users more time to move to PSA. People who were using low-level cipher/AEAD modules need to migrate immediately, but those who were using the generic Cipher/AEAD API can migrate at a convenient time between now and 5.0.
There is no PSA alternative for NIST_KW. One is coming, but we might not have it by the time 4.0 comes out.
Work needed for option 1 (keep)
In 4.0:
mbedtls_cipher_info_from_string()
,mbedtls_cipher_get_name()
- see Remove parts of md, cipher and pk #8133 item 1mbedtls_cipher_list()
as well (not used in the library)mbedtls_cipher_setup_psa()
mbedtls_cipher_info_t
from the API in order to make it slicker but that would require users to change their code, so it runs against the stated goal. (Alternatively, we can keep the structure but later make it trivial as it has no public field.)mbedtls_cipher_setup_psa()
- which we're not keeping, but at least it serves as a proof of concept for AES with ECB, CBC, GCM, CCM, and for ChachaPoly - reducing the risk of big API mismatch that can't be worked around.psa_crypto_cipher.c
currently heavily relies oncipher.c
so we'll need to change that in order to turncipher.c
into a thin wrapper. That's something we need to change anyway, but with option 2 it can be left for 4.x, while with option 1 we'll probably want to prototype it before 4.0.In 4.0 or 4.x:
Rationale for option 2 (remove)
This leaves us with only one cipher/AEAD API to maintain, document and test. For new users, this also gives more clarity.
I'll note the current cipher.h API is not very well designed, and often not documented and tested enough. (Examples that pop to mind: can I/O buffers overlap? At one point the documentation said no but TLS did it anyway. What's the default padding mode if not explicitly selected? What are the minimum sizes of the output buffers - yes, some of them are implicit...) Which I think makes it a more attractive candidate for removal than other parts of the code.
Work needed for option 2 (remove)
In 4.0:
cipher.h
to an internal location and adapt all files that#include
it.psa/aead_demo
andcipher/cipher_aead_demo.c
going in that direction for AEAD.)In 4.0 or 4.x:
psa_crypto_cipher.c
so that it no longerOther options
The text was updated successfully, but these errors were encountered: