[WASI-Crypto] Implement remaining functions
Motivation
WasmEdge implements partial of the WASI-Crypto functions. However, some functions keep the NOT_IMPLEMENTED status. In this PR, we are tracking those functions.
Details
Use grep "WasiCryptoUnexpect(__WASI_CRYPTO_ERRNO_NOT_IMPLEMENTED);" to get detailed lines of the unimplemented functions.
Appendix
Hi 👋🏻, @hydai I am new to open source could you point to some resources to get reference and work on this issue?
Hi @AtulRaghuvanshi73, from my understanding of the problem posed! After setting up the codebase locally,you need to string search the line in the double quotes,
grep "WasiCryptoUnexpect(__WASI_CRYPTO_ERRNO_NOT_IMPLEMENTED);"
which would give you the list of unused functions and lines where it is being used!
Hope this helps in any form, but I am unsure so please do look into this @hydai
Hi 👋🏻, @hydai I am new to open source could you point to some resources to get reference and work on this issue?
For the background, you may need the following information:
- Like @Bhardwaj-Himanshu said, using
grepto get a list of unimplemented functions. - Read the WASI-Crypto repo for the detailed spec of the above functions.
- Implement these functions with the OpenSSL library.
@hydai I would love to work on this issue. Could you pls assign it to me
@hydai I run grep "WasiCryptoUnexpect(__WASI_CRYPTO_ERRNO_NOT_IMPLEMENTED);" and The reason why these functions are not implemented is because the wasi_crypto plugin is not yet complete. It is still under development, and not all of the functions and methods that are defined in the WebAssembly Crypto API have been implemented yet.
could you pls give me a lead how to proceed next
Hello @hydai
I have been working on this issue lately. As a proof of concept, I am sharing my initial implementation for the keypairGenerateManaged function in plugins/wasi-crypto/asymmetric_common/ctx.cpp.
This implements the generation of a new managed keypair using the secrets manager, along with input validation for unsupported algorithms and features.
`WasiCryptoExpect<__wasi_keypair_t>
Context::keypairGenerateManaged(__wasi_secrets_manager_t secrets_manager,
AsymmetricCommon::Algorithm algorithm,
__wasi_opt_options_t options) noexcept {
if (secrets_manager == 0) {
return WasiCryptoUnexpect(__WASI_CRYPTO_ERRNO_UNSUPPORTED_FEATURE);
}
if (!isAlgorithmSupported(algorithm)) {
return WasiCryptoUnexpect(__WASI_CRYPTO_ERRNO_UNSUPPORTED_ALGORITHM);
}
auto key_pair_result = AsymmetricCommon::generateKp(algorithm, options);
if (!key_pair_result) {
return WasiCryptoUnexpect(key_pair_result.error());
}
auto key_pair = std::move(key_pair_result.value());
auto registration_result = KeyPairManager.registerManager(std::move(key_pair));
if (!registration_result) {
return WasiCryptoUnexpect(registration_result.error());
}
__wasi_keypair_t keypair;
keypair.public_key = key_pair.public_key();
keypair.public_key_length = key_pair.public_key().size();
keypair.private_key = key_pair.private_key();
keypair.private_key_length = key_pair.private_key().size();
return keypair;
}
where the function isAlgorithmSupported is as follows
bool Context::isAlgorithmSupported(AsymmetricCommon::Algorithm algorithm) noexcept {
switch (algorithm) {
case AsymmetricCommon::Algorithm::ED25519:
case AsymmetricCommon::Algorithm::X25519:
case AsymmetricCommon::Algorithm::ED448:
case AsymmetricCommon::Algorithm::X448:
return true;
default:
return false;
}
}
I have followed all the required specs mentioned for the function in the relevent sources in the wasi-crypto repository. I have also added a simple isAlgorithmSupported function to validate the passed algorithm enum. Please let me know if this approach is correct or any other change that needs to be looked at.
Hi @hydai , what is the status of this issue, can you assign me this if no one is working on it?
Hi @Arshdeep54,
Please grep WasiCryptoUnexpect(__WASI_CRYPTO_ERRNO_NOT_IMPLEMENTED) to find those unimplemented functions. Since this is an abstract issue, you can pick some of them and open a new issue to work on.