WasmEdge icon indicating copy to clipboard operation
WasmEdge copied to clipboard

[WASI-Crypto] Implement remaining functions

Open hydai opened this issue 2 years ago • 8 comments

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

hydai avatar Jul 20 '23 22:07 hydai

Hi 👋🏻, @hydai I am new to open source could you point to some resources to get reference and work on this issue?

AtulRaghuvanshi73 avatar Jul 21 '23 13:07 AtulRaghuvanshi73

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

Bhardwaj-Himanshu avatar Jul 22 '23 06:07 Bhardwaj-Himanshu

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:

  1. Like @Bhardwaj-Himanshu said, using grep to get a list of unimplemented functions.
  2. Read the WASI-Crypto repo for the detailed spec of the above functions.
  3. Implement these functions with the OpenSSL library.

hydai avatar Jul 23 '23 22:07 hydai

@hydai I would love to work on this issue. Could you pls assign it to me

sarthaksarthak9 avatar Aug 05 '23 01:08 sarthaksarthak9

@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

sarthaksarthak9 avatar Aug 05 '23 11:08 sarthaksarthak9

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.

arnabnandikgp avatar Oct 02 '23 17:10 arnabnandikgp

Hi @hydai , what is the status of this issue, can you assign me this if no one is working on it?

Arshdeep54 avatar Jan 26 '25 12:01 Arshdeep54

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.

hydai avatar Jan 26 '25 13:01 hydai