You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cryptography is the core functionality of the enclave, so it's worth designing it properly.
Ideally, we'd like to not map 1-on-1 with the C ledger SDK when the interface could be better (the Vanadium app can proxy to the C implementation appropriately). For the native implementation of the ecalls, we'll need to reimplement them as we no longer link with speculos binaries.
Tasks:
Bignums
BIP32
Hash Functions
Elliptic Curves
ECDSA/Schnorr signatures
Public-key only API?
One thing we might consider is if it's worth not allowing private keys derived from the seed in the V-App's RAM.
The reason for that is that while the RAM will be encrypted, yet the access pattern is not completely hidden (the client can see what pages are accessed and when); therefore, there is the potential footgun of implementing cryptographic algorithms where the access pattern depends on the bits of the secret. Probably not the case very often, but it can't be excluded.
Two options:
give access to private keys, clearly document the risk and explicitly name the functions as _dangerous (which forces the developers to at least think about the issue, and possible write safe wrappers around it)
provide an API that allows to allocate private keys in the Vanadium VM's memory, while the V-App only has access to it via a handle.
For now, I think the first option is the easiest, and most flexible (no limits to what crypto can be built). We can later add a safer API if necessary, with more experience on the V-App needs.
For the common needs (derive bip-32 public keys, sign messages with specific keys in the BIP-32 paths, the SDK can already provide a safe wrapper), so that V-Apps don't need to use unsafe blocks.
It might be useful to think about how to make sure that the private keys are always inside a single page, as that at least hides which part of the private key was accessed.
ecall_derive_node_bip32 should probably be renamed, as it's actually more generic than that: only the secp256k1 curve is define in BIP32, while for other curves it's based on SLIP-10.
Instead of ecall_get_master_fingerprint, we could have a different version of derive_node that only returns the public key, and get_master_fingerprint could be implemented in the Rust SDK on top of it.
To be added: SLIP-21 symmetric key derivation (possibly not based on the implementation from the C SDK, which isn't very good and only supports 1 level of derivation IIRC).
These functions where somewhat weird to implement in vanadium-legacy (see the restore_ctx_from_guest/save_ctx_from_host pair of functions). The general principle of operating on the midstate and having a function to finalize, however, is sound and should be easily portable (e.g. for the native reimplementation in Rust).
In theory, these could be built without ecalls on top of bignums, but that's a lot more work, so the pragmatic choice is to just have ecalls for now; they can be deprecated in the future.
ecall_cx_ecfp_generate_pair has a weird interface, rethink a more appropriate one.
Cryptography is the core functionality of the enclave, so it's worth designing it properly.
Ideally, we'd like to not map 1-on-1 with the C ledger SDK when the interface could be better (the Vanadium app can proxy to the C implementation appropriately). For the native implementation of the ecalls, we'll need to reimplement them as we no longer link with speculos binaries.
Tasks:
Public-key only API?
One thing we might consider is if it's worth not allowing private keys derived from the seed in the V-App's RAM.
The reason for that is that while the RAM will be encrypted, yet the access pattern is not completely hidden (the client can see what pages are accessed and when); therefore, there is the potential footgun of implementing cryptographic algorithms where the access pattern depends on the bits of the secret. Probably not the case very often, but it can't be excluded.
Two options:
_dangerous
(which forces the developers to at least think about the issue, and possible write safe wrappers around it)For now, I think the first option is the easiest, and most flexible (no limits to what crypto can be built). We can later add a safer API if necessary, with more experience on the V-App needs.
For the common needs (derive bip-32 public keys, sign messages with specific keys in the BIP-32 paths, the SDK can already provide a safe wrapper), so that V-Apps don't need to use
unsafe
blocks.It might be useful to think about how to make sure that the private keys are always inside a single page, as that at least hides which part of the private key was accessed.
Vanadium-legacy ECALLs
General bignums:
These are probably reasonable to keep as-is. No big changes required on the interface.
BIP32-related
ecall_derive_node_bip32
should probably be renamed, as it's actually more generic than that: only the secp256k1 curve is define in BIP32, while for other curves it's based on SLIP-10.Instead of
ecall_get_master_fingerprint
, we could have a different version ofderive_node
that only returns the public key, and get_master_fingerprint could be implemented in the Rust SDK on top of it.To be added: SLIP-21 symmetric key derivation (possibly not based on the implementation from the C SDK, which isn't very good and only supports 1 level of derivation IIRC).
Random bytes
Useful to give access to the TRNG; keep verbatim.
Hash functions
These functions where somewhat weird to implement in vanadium-legacy (see the
restore_ctx_from_guest
/save_ctx_from_host
pair of functions). The general principle of operating on the midstate and having a function to finalize, however, is sound and should be easily portable (e.g. for the native reimplementation in Rust).Elliptic Curves
In theory, these could be built without ecalls on top of bignums, but that's a lot more work, so the pragmatic choice is to just have ecalls for now; they can be deprecated in the future.
ecall_cx_ecfp_generate_pair
has a weird interface, rethink a more appropriate one.ECDSA / Schnorr signing
TBD if we need ecalls for these, or we instead can easily reimplement it in Vanadium SDK.
The text was updated successfully, but these errors were encountered: