feat: implement remaining WASI-Crypto function
Summary
Description
This issue tracks the implementation of multiple previously unimplemented WASI-Crypto APIs in WasmEdge as part of #2669. These functions were previously returning __WASI_CRYPTO_ERRNO_NOT_IMPLEMENTED and have now been implemented or replaced with correct OpenSSL-backed or in-memory behavior where appropriate.
The changes span asymmetric cryptography, symmetric cryptography, key exchange handling, secrets management, and improvements to existing cryptographic operations and error handling.
Details
Implemented Changes
Secrets Manager
Implemented in-memory
SecretsManager(plugins/wasi_crypto/common/secrets_manager.h)Supports thread-safe storage and retrieval of:
- Asymmetric key pairs
- Symmetric keys
Added key lifecycle operations:
invalidate()removes keys by ID and versionstoreKp()stores key pairsstoreSk()stores symmetric keysgetKp()/getSk()retrieves stored keys
Context (Secrets Manager API)
plugins/wasi_crypto/common/ctx.cpp
Context::secretsManagerOpen()now creates a realSecretsManagerContext::secretsManagerClose()properly closes the manager handleContext::secretsManagerInvalidate()delegates toSecretsManager::invalidate
Asymmetric Key Management
plugins/wasi_crypto/asymmetric_common/ctx.cpp
Context::keypairGenerateManaged()implemented using:- Options handling
- Algorithm-based keypair generation
- Registration in
KeyPairManager
Context::keypairStoreManaged()implemented usingSecretsManagerContext::keypairFromId()implemented to retrieve keypairs fromSecretsManager
Key Conversion Improvements
Ecdsa::SecretKey::toKeyPair()implemented using OpenSSL key comparison and validationEddsa::SecretKey::toKeyPair()implemented with key compatibility checkRsa::SecretKey::toKeyPair()implemented with key validationX25519::SecretKey::toKeyPair()implemented with key comparison validation
X25519 Improvements
plugins/wasi_crypto/kx/dh/x25519.cpp
X25519::PublicKey::verify()implemented using OpenSSL public key checkX25519::SecretKey::toKeyPair()implemented with key consistency validation
Symmetric Key Management
plugins/wasi_crypto/symmetric/ctx.cpp
Context::symmetricKeyGenerateManaged()implemented with:- Options parsing
- Key generation via
Symmetric::generateKey - Registration in
SymmetricKeyManager
Context::symmetricKeyStoreManaged()implemented usingSecretsManagerContext::symmetricKeyFromId()implemented for retrieving symmetric keys by ID and version
HKDF Improvements
plugins/wasi_crypto/symmetric/kdf.cpp
Implemented
Expand::State::clone()with full state duplicationImplemented
Extract::State::clone()with salt preservationImproved internal state tracking:
- Info buffering
- Key persistence during state cloning
RSA Improvements
plugins/wasi_crypto/signatures/rsa.cpp
Implemented DER encoding support for:
Signature::import()(DER decoding)Signature::exportData()(DER encoding using ASN.1 OCTET STRING)
Key Exchange Improvements
plugins/wasi_crypto/kx/kx.cpp
Replaced
NOT_IMPLEMENTEDwithUNSUPPORTED_FEATUREfor:encapsulate()decapsulate()
Tests
- Removed outdated
notimplement.cpp - Updated asymmetric tests for managed key generation
- Updated KX tests to expect
UNSUPPORTED_FEATURE - Added validation for HKDF clone behavior
- Improved coverage for secrets manager integration
Appendix
Reference
Tracking issue: #2669
Source: WasmEdge/WasmEdge