pub trait ECDHHandler {
// Required methods
fn public_key(&self) -> Result<Vec<u8>>;
fn ecdh(&self, peer_public_key: &[u8]) -> Result<Vec<u8>>;
}Expand description
Trait for ECDH operations that can be performed by TPM/HSM backends.
This trait allows custom hardware backends (TPM, HSM, etc.) to provide ECDH key exchange operations. Implementations should handle the key exchange using the hardware module and return the shared secret.
This is similar to gobottle’s ECDHHandler interface.
§Example
use rust_bottle::tpm::ECDHHandler;
use rust_bottle::errors::Result;
struct MyTpmHandler {
// TPM-specific fields
}
impl ECDHHandler for MyTpmHandler {
fn public_key(&self) -> Result<Vec<u8>> {
// Return the public key from TPM
Ok(vec![])
}
fn ecdh(&self, peer_public_key: &[u8]) -> Result<Vec<u8>> {
// Perform ECDH using TPM
Ok(vec![])
}
}Required Methods§
Sourcefn public_key(&self) -> Result<Vec<u8>>
fn public_key(&self) -> Result<Vec<u8>>
Get the public key associated with this handler.
The public key should be in the same format as the corresponding software key type (e.g., 32 bytes for X25519, 65 bytes for P-256).
§Returns
Ok(Vec<u8>)- The public key bytesErr(BottleError)- If the key cannot be retrieved
Sourcefn ecdh(&self, peer_public_key: &[u8]) -> Result<Vec<u8>>
fn ecdh(&self, peer_public_key: &[u8]) -> Result<Vec<u8>>
Perform ECDH key exchange with a peer’s public key.
This function computes the shared secret using the handler’s private key (stored in TPM/HSM) and the peer’s public key.
§Arguments
peer_public_key- The peer’s public key bytes
§Returns
Ok(Vec<u8>)- The shared secret bytesErr(BottleError)- If the ECDH operation fails