-
Notifications
You must be signed in to change notification settings - Fork 280
Draft wasi_ephemeral_crypto.witx module #231
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
Conversation
b741eb4
to
e6749a9
Compare
I have been thinking about this, too, and I imagined a very low-level API, that doesn't make strong assumptions about the algorithms themselves. Key management will also be a major issue.
|
This is a really good starting point, and we definitely need such an interface. However, the proposed interface seems a little bit limited, and not future-proof. Supporting modern constructions and proposals wouldn’t be possible without a major revision of this interface.
For AEAD/HASH/MAC, I’d suggest avoiding the Also, should we have ways to list the set of supported algorithms? To summarize, before jumping the gun and implementing an API, we should make sure that it can support current and forthcoming algorithms. Or else, extending it to do so may be hacky and ugly. The semantics also need some further discussion. For example, what happens after |
When I first thought about this, I thought a low-level API might make more sense. Maybe something similar to what OpenSSL is doing internally: Generic APIs to create contexts, perform operations on contexts, and destroy contexts, where the context types and operations are not precisely specified and up to the algorithm. Ideally, it should be possible to use existing crypto libraries which are implemented on top of the WASI crypto interface, instead of having to rewrite all applications and libraries to use this specific high-level API. |
Sounds like a sensible approach for a stable and future-proof API. And it doesn't prevent safer and simpler abstractions a la libsodium to be built later on top of such a low-level API, as a different module. |
That's exactly my motivation. I had a somewhat detailed draft somewhere, that would allow most crypto operations to be implemented, but I struggled with asymmetric key management, and that is absolutely necessary. |
e6749a9
to
7f72f16
Compare
Thank you for the thoughtful comments! I would like to clarify that, with the terms "low-level" and "high-level", do you mean:
? I'm a bit confused because a generic API is usually built upon a specific API in crypto library implementations. Each approach has pros and cons (flexibilty, complexity, error proneness, etc), so I was aiming at somewhere in the middle.
The idea is to provide a way to directly feed the input/output of
This is because IV can be per message, while the same key can be used for encrypting multiple messages. Conceptually, this can be seen as a simplified version of PKCS#11 message based encryption/decryption model, but I agree that moving nonce (and AAD) to the handle creation makes more sense if it is the typical use-case.
Would you mind providing examples of such algorithms?
In PKCS#11, XOF falls into the category of key derivation mechanism, as those operations are quite similar.
Yes, this is meant to be used in a DH scenario only, to support the
I tend to agree, but if we go too further with this approach, the semantics of calling those function would become more complex; so I guess we need a compromise at some point.
I think that makes sense.
I expanded the documentation of this particular case ( |
That would imply that the underlying encryption function would do far more than encryption, and implement a complete protocol handling fragmentation and rekeying. Essentially implementing something like TLS. While it would be a nice thing to have and would solve your particular use case, it goes way beyond what the initial layer of a WASI crypto module should do. Encrypting a new message should probably go through an |
While an API that doesn't require a context and uses a fixed set of parameters would be easier to use, WASI is not meant to be directly used by applications. It is rather akin to a set of system calls, and its API stability is critical, especially as we need implementers to build an ecosystem around it. Which is why I'd strongly advocate for something that can be extended without breaking changes, or quirks ( |
Ignoring the MAC part, that would be the case for any block cipher used in a mode that is not counter-based or doesn't do ciphertext stealing. CBC is an example. Depends if you allow traditional AE to be supported in the AEAD interface and if you trust all future AEADs to never require any padding. |
I would consider anything low-level that would allow existing libraries such as OpenSSL (and its variants), libsodium etc. to be implemented on top of it, without having to implement the primitives themselves, and in a future-proof way, meaning that the design shouldn't arbitrarily limit algorithm interfaces, options etc.
Technically, you can also fix an IV and just use a different key for each message.
I don't think any of the "real" AEAD algorithms would be in that category, but my inability to come up with an example shouldn't be a justification for an arbitrary limitation.
@jedisct1 I agree. |
@ueno This is a really great start and is definitely needed. Others have provided good feedback. So I'll focus on things that haven't already been said.
This is a really great start, though. The problem of key management is definitely something we should tackle sooner rather than later. For example, in the Enarx project, we're going to need to do crypto operations on keys that reside in hardware (i.e. we don't have access to the raw bytes). One strategy we might consider is to define (a) key type(s) that can be used everywhere and can always be constructed in the standard way using bytes. Then implementations can provide additional ways of constructing the key types for their specific use cases. I'm just brainstorming though. |
Cryptography modules for WASI require more discussions around their design in order to get the APIs as good as possible for the vast majority of applications. If you are interested in working on WASI crypto APIs design and their implementations, please join the working group: |
@jedisct1 I certainly recognize the need for focused discussions for a Cryptography API. However, the Google Group is outside of the WebAssembly CG Umbrella, which may affect community participation and make it harder for us to be sure that contributions are covered by the W3C Community Group CLA. If we created a new Github repository for this (within the WebAssembly organization), or set up a new mailing list for this, would those work for you? |
Yes, that would be perfect! |
This adds functions needed for implementing TLS 1.3 as a start, namely: symmetric cipher, hashing, MAC, key generation and shared secret derivation.
7f72f16
to
1b97eb5
Compare
While I'm not completely sure how better mailing list would fit than using github issues/PRs, I agree that this topic needs some high level discussion with interested parties before moving forward. In any case, I've updated this PR to v3, with the following changes:
|
Thanks for the update! This is looking really good. A GitHub repository maybe a more convenient, then. So that we can start from a document, and keep improving it, similar to what is being done on the A single, very long thread such as comments on a PR makes the discussions very difficult to follow where multiple topics need to be addressed. @sunfishcode would it be possible to get a dedicated |
Yes, I think there's sufficient motivation here to create a new repo, so I've now requested and gotten approval for one, and have now created https://github.com/WebAssembly/WASI-crypto, so we can continue development there. |
@ueno I suspect you should re-submit this to the new repo. We can continue reviews there. |
I believe this PR is subsumed by WebAssembly/wasi-crypto#5. |
This adds a small set of interface functions that allow host implementations of cryptographic primitives for certification / acceleration purposes. Currently, our primary target is to enable TLS-like encrypted streams based on those primitives, namely: AEAD, hashing, MAC, HKDF, and shared secret derivation.
Comments appreciated.
Related to #65.