WebAssembly / wasi-crypto

WASI Cryptography API Proposal
162 stars 25 forks source link

Is wasi-crypto deterministic? #30

Closed sunfishcode closed 2 years ago

sunfishcode commented 3 years ago

Since wasi-crypto stores things like private keys outside of the normal program state, is the entropy used for things like private keys fully encapsulated? And if so, does this mean that the wasi-crypto API is deterministic, aside from the set of supported algorithms in an implementation?

This would be an interesting property for users wanting fully deterministic execution.

To be sure, WASI will likely still want to have raw entropy-source APIs, but it would help users that want deterministic execution if they could disable it while letting users do crypto through wasi-crypto.

jedisct1 commented 3 years ago

Hi Dan,

The wasi-crypto API doesn't allow applications to use a specific random number source.

Creating a key requires an algorithm identifier and optional parameters, but these intentionally don't include a seed or some RNG handle, for a couple reasons.

RNGs used for e.g. Monte Carlo simulation need different properties than RNGs needed for cryptography.

PCG, Xoroshiro, etc. are perfect algorithms for running simulations. But they should probably be part of an API that is distinct from wasi-crypto.

jedisct1 commented 3 years ago

So, the wasi-crypto APIs cannot be deterministic, if only because key management can be delegated to HSMs.

But the random module can still provide an RNG, accessible via new functions, that the application can optionally seed in so that it is deterministic. It won't affect key creation via the crypto APIs, though.

indolering commented 3 years ago

PCG, Xoroshiro, etc. are perfect algorithms for running simulations. But they should probably be part of an API that is distinct from wasi-crypto. ... But the random module can still provide an RNG, accessible via new functions, that the application can optionally seed in so that it is deterministic.

I did a review of random APIs a few years ago, but sadly never got around to writing something up. A few notes:

IMHO, I don't believe Xoroshiro provides the best set of trade-offs. Probably some vectorized version of PCG.