pub trait Crypto {
Show 30 associated items
type Rand<'a>: CryptoRngCore + Copy
where Self: 'a;
type WeakRand<'a>: RngCore + Copy
where Self: 'a;
type Hash<'a>: Digest<rs_matter::::crypto::Crypto::Hash::{constant#0}>
where Self: 'a;
type Hash1<'a>: Digest<rs_matter::::crypto::Crypto::Hash1::{constant#0}>
where Self: 'a;
type Hmac<'a>: Digest<rs_matter::::crypto::Crypto::Hmac::{constant#0}>
where Self: 'a;
type Kdf<'a>: Kdf
where Self: 'a;
type PbKdf<'a>: PbKdf
where Self: 'a;
type Aead<'a>: Aead<rs_matter::::crypto::Crypto::Aead::{constant#0}, rs_matter::::crypto::Crypto::Aead::{constant#1}>
where Self: 'a;
type PublicKey<'a>: PublicKey<'a, rs_matter::::crypto::Crypto::PublicKey::{constant#0}, rs_matter::::crypto::Crypto::PublicKey::{constant#1}>
where Self: 'a;
type SigningSecretKey<'a>: SigningSecretKey<'a, rs_matter::::crypto::Crypto::SigningSecretKey::{constant#0}, rs_matter::::crypto::Crypto::SigningSecretKey::{constant#1}, PublicKey<'a> = Self::PublicKey<'a>>
where Self: 'a;
type SecretKey<'a>: SecretKey<'a, rs_matter::::crypto::Crypto::SecretKey::{constant#0}, rs_matter::::crypto::Crypto::SecretKey::{constant#1}, rs_matter::::crypto::Crypto::SecretKey::{constant#2}, rs_matter::::crypto::Crypto::SecretKey::{constant#3}, PublicKey<'a> = Self::PublicKey<'a>>
where Self: 'a;
type EcScalar<'a>: EcScalar<'a, rs_matter::::crypto::Crypto::EcScalar::{constant#0}>
where Self: 'a;
type EcPoint<'a>: EcPoint<'a, rs_matter::::crypto::Crypto::EcPoint::{constant#0}, rs_matter::::crypto::Crypto::EcPoint::{constant#1}, Scalar<'a> = Self::EcScalar<'a>>
where Self: 'a;
// Required methods
fn rand(&self) -> Result<Self::Rand<'_>, Error>;
fn weak_rand(&self) -> Result<Self::WeakRand<'_>, Error>;
fn hash(&self) -> Result<Self::Hash<'_>, Error>;
fn hash1(&self) -> Result<Self::Hash1<'_>, Error>;
fn hmac<const KEY_LEN: usize>(
&self,
key: CryptoSensitiveRef<'_, KEY_LEN>,
) -> Result<Self::Hmac<'_>, Error>;
fn kdf(&self) -> Result<Self::Kdf<'_>, Error>;
fn pbkdf(&self) -> Result<Self::PbKdf<'_>, Error>;
fn aead(&self) -> Result<Self::Aead<'_>, Error>;
fn pub_key(
&self,
key: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonPkcPublicKeyRef::{constant#0}>,
) -> Result<Self::PublicKey<'_>, Error>;
fn secret_key(
&self,
key: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonPkcSecretKeyRef::{constant#0}>,
) -> Result<Self::SecretKey<'_>, Error>;
fn generate_secret_key(&self) -> Result<Self::SecretKey<'_>, Error>;
fn singleton_singing_secret_key(
&self,
) -> Result<Self::SigningSecretKey<'_>, Error>;
fn ec_scalar(
&self,
scalar: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonEcScalarRef::{constant#0}>,
) -> Result<Self::EcScalar<'_>, Error>;
fn ec_scalar_mod_p(
&self,
uint: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonUint320Ref::{constant#0}>,
) -> Result<Self::EcScalar<'_>, Error>;
fn generate_ec_scalar(&self) -> Result<Self::EcScalar<'_>, Error>;
fn ec_point(
&self,
point: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonEcPointRef::{constant#0}>,
) -> Result<Self::EcPoint<'_>, Error>;
fn ec_generator_point(&self) -> Result<Self::EcPoint<'_>, Error>;
}Expand description
Trait representing a cryptographic backend.
The backend should provide all the cryptographic primitives required by the Matter spec.
The trait is designed in a way where it allows customizing a concrete implementation by swapping out its out of the box algorithms with custom (potentially HW-accelerated) ones, by decorating the original implementation and replacing only the required types and methods.
Required Associated Types§
type Rand<'a>: CryptoRngCore + Copy where Self: 'a
type WeakRand<'a>: RngCore + Copy where Self: 'a
Sourcetype Hash<'a>: Digest<rs_matter::::crypto::Crypto::Hash::{constant#0}>
where
Self: 'a
type Hash<'a>: Digest<rs_matter::::crypto::Crypto::Hash::{constant#0}> where Self: 'a
Hasher type returned by Crypto::hash.
As per the Matter spec, the hasher should be SHA-256.
Sourcetype Hash1<'a>: Digest<rs_matter::::crypto::Crypto::Hash1::{constant#0}>
where
Self: 'a
type Hash1<'a>: Digest<rs_matter::::crypto::Crypto::Hash1::{constant#0}> where Self: 'a
SHA-1 hasher type returned by Crypto::hash1.
Sourcetype Hmac<'a>: Digest<rs_matter::::crypto::Crypto::Hmac::{constant#0}>
where
Self: 'a
type Hmac<'a>: Digest<rs_matter::::crypto::Crypto::Hmac::{constant#0}> where Self: 'a
HMAC hasher type returned by Crypto::hmac.
As per the Matter spec, the HMAC hasher should be HMAC-SHA-256.
Sourcetype Kdf<'a>: Kdf
where
Self: 'a
type Kdf<'a>: Kdf where Self: 'a
KDF type returned by Crypto::kdf.
As per the Matter spec, the KDF should be HKDF-SHA256.
Sourcetype PbKdf<'a>: PbKdf
where
Self: 'a
type PbKdf<'a>: PbKdf where Self: 'a
PBKDF type returned by Crypto::pbkdf.
As per the Matter spec, the PBKDF should be PBKDF2-HMAC-SHA256.
Sourcetype Aead<'a>: Aead<rs_matter::::crypto::Crypto::Aead::{constant#0}, rs_matter::::crypto::Crypto::Aead::{constant#1}>
where
Self: 'a
type Aead<'a>: Aead<rs_matter::::crypto::Crypto::Aead::{constant#0}, rs_matter::::crypto::Crypto::Aead::{constant#1}> where Self: 'a
AEAD type returned by Crypto::aead.
As per the Matter spec, the AEAD algorithm used is AES-CCM with 128-bit keys, 13-byte nonces and 16-byte tags.
Sourcetype PublicKey<'a>: PublicKey<'a, rs_matter::::crypto::Crypto::PublicKey::{constant#0}, rs_matter::::crypto::Crypto::PublicKey::{constant#1}>
where
Self: 'a
type PublicKey<'a>: PublicKey<'a, rs_matter::::crypto::Crypto::PublicKey::{constant#0}, rs_matter::::crypto::Crypto::PublicKey::{constant#1}> where Self: 'a
Public key type returned by Crypto::pub_key.
As per the Matter spec, the used Public Key Cryptograqphy should be Elliptic-Curve based, and specifically secp256r1 (NIST P-256).
In other words, the public key is a point on the secp256r1 curve.
With that said, the implementation is free to choose a different internal
representation of the public key type as compared to the EcPoint type.
The only requirement is that both should be possible to convert from/to
the same canonical representation.
Sourcetype SigningSecretKey<'a>: SigningSecretKey<'a, rs_matter::::crypto::Crypto::SigningSecretKey::{constant#0}, rs_matter::::crypto::Crypto::SigningSecretKey::{constant#1}, PublicKey<'a> = Self::PublicKey<'a>>
where
Self: 'a
type SigningSecretKey<'a>: SigningSecretKey<'a, rs_matter::::crypto::Crypto::SigningSecretKey::{constant#0}, rs_matter::::crypto::Crypto::SigningSecretKey::{constant#1}, PublicKey<'a> = Self::PublicKey<'a>> where Self: 'a
Signing secret key type returned by Crypto::singleton_singing_secret_key.
As per the Matter spec, the used Public Key Cryptograqphy should be Elliptic-Curve based, and specifically secp256r1 (NIST P-256).
In other words, the signing secret key is a scalar on the secp256r1 curve.
With that said, the implementation is free to choose a different internal
representation of the signing secret key type as compared to the EcScalar type.
The only requirement is that both should be possible to convert from/to
the same canonical representation.
Sourcetype SecretKey<'a>: SecretKey<'a, rs_matter::::crypto::Crypto::SecretKey::{constant#0}, rs_matter::::crypto::Crypto::SecretKey::{constant#1}, rs_matter::::crypto::Crypto::SecretKey::{constant#2}, rs_matter::::crypto::Crypto::SecretKey::{constant#3}, PublicKey<'a> = Self::PublicKey<'a>>
where
Self: 'a
type SecretKey<'a>: SecretKey<'a, rs_matter::::crypto::Crypto::SecretKey::{constant#0}, rs_matter::::crypto::Crypto::SecretKey::{constant#1}, rs_matter::::crypto::Crypto::SecretKey::{constant#2}, rs_matter::::crypto::Crypto::SecretKey::{constant#3}, PublicKey<'a> = Self::PublicKey<'a>> where Self: 'a
Secret key type returned by Crypto::secret_key and Crypto::generate_secret_key.
As per the Matter spec, the used Public Key Cryptograqphy should be Elliptic-Curve based, and specifically secp256r1 (NIST P-256).
In other words, the secret key is a scalar on the secp256r1 curve.
With that said, the implementation is free to choose a different internal
representation of the secret key type as compared to the EcScalar type.
The only requirement is that both should be possible to convert from/to
the same canonical representation.
Sourcetype EcScalar<'a>: EcScalar<'a, rs_matter::::crypto::Crypto::EcScalar::{constant#0}>
where
Self: 'a
type EcScalar<'a>: EcScalar<'a, rs_matter::::crypto::Crypto::EcScalar::{constant#0}> where Self: 'a
EC scalar type returned by Crypto::ec_scalar and Crypto::generate_ec_scalar.
As per the Matter spec, the curve used is secp256r1 (NIST P-256).
In other words, the EC scalar is a scalar on the secp256r1 curve.
Sourcetype EcPoint<'a>: EcPoint<'a, rs_matter::::crypto::Crypto::EcPoint::{constant#0}, rs_matter::::crypto::Crypto::EcPoint::{constant#1}, Scalar<'a> = Self::EcScalar<'a>>
where
Self: 'a
type EcPoint<'a>: EcPoint<'a, rs_matter::::crypto::Crypto::EcPoint::{constant#0}, rs_matter::::crypto::Crypto::EcPoint::{constant#1}, Scalar<'a> = Self::EcScalar<'a>> where Self: 'a
EC point type returned by Crypto::ec_point and Crypto::ec_generator_point.
As per the Matter spec, the curve used is secp256r1 (NIST P-256).
In other words, the EC point is a point on the secp256r1 curve.
Required Methods§
Sourcefn rand(&self) -> Result<Self::Rand<'_>, Error>
fn rand(&self) -> Result<Self::Rand<'_>, Error>
Create a new, cryptographically secure, random number generator instance.
Sourcefn weak_rand(&self) -> Result<Self::WeakRand<'_>, Error>
fn weak_rand(&self) -> Result<Self::WeakRand<'_>, Error>
Create a new NON-cryptographically secure (but potentially faster), random number generator instance.
Sourcefn hmac<const KEY_LEN: usize>(
&self,
key: CryptoSensitiveRef<'_, KEY_LEN>,
) -> Result<Self::Hmac<'_>, Error>
fn hmac<const KEY_LEN: usize>( &self, key: CryptoSensitiveRef<'_, KEY_LEN>, ) -> Result<Self::Hmac<'_>, Error>
Create a new HMAC hasher instance with the given key.
Sourcefn pub_key(
&self,
key: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonPkcPublicKeyRef::{constant#0}>,
) -> Result<Self::PublicKey<'_>, Error>
fn pub_key( &self, key: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonPkcPublicKeyRef::{constant#0}>, ) -> Result<Self::PublicKey<'_>, Error>
Create a public key instance from its canonical representation.
Sourcefn secret_key(
&self,
key: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonPkcSecretKeyRef::{constant#0}>,
) -> Result<Self::SecretKey<'_>, Error>
fn secret_key( &self, key: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonPkcSecretKeyRef::{constant#0}>, ) -> Result<Self::SecretKey<'_>, Error>
Create a secret key instance from its canonical representation.
Sourcefn generate_secret_key(&self) -> Result<Self::SecretKey<'_>, Error>
fn generate_secret_key(&self) -> Result<Self::SecretKey<'_>, Error>
Generate a new secret key instance.
Sourcefn singleton_singing_secret_key(
&self,
) -> Result<Self::SigningSecretKey<'_>, Error>
fn singleton_singing_secret_key( &self, ) -> Result<Self::SigningSecretKey<'_>, Error>
Get the singleton signing secret key instance.
This is used for device attestation.
Sourcefn ec_scalar(
&self,
scalar: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonEcScalarRef::{constant#0}>,
) -> Result<Self::EcScalar<'_>, Error>
fn ec_scalar( &self, scalar: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonEcScalarRef::{constant#0}>, ) -> Result<Self::EcScalar<'_>, Error>
Create an EC scalar instance from its canonical representation.
Sourcefn ec_scalar_mod_p(
&self,
uint: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonUint320Ref::{constant#0}>,
) -> Result<Self::EcScalar<'_>, Error>
fn ec_scalar_mod_p( &self, uint: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonUint320Ref::{constant#0}>, ) -> Result<Self::EcScalar<'_>, Error>
Create an EC scalar instance from a 320-bit unsigned integer modulo the EC prime modulus.
Sourcefn generate_ec_scalar(&self) -> Result<Self::EcScalar<'_>, Error>
fn generate_ec_scalar(&self) -> Result<Self::EcScalar<'_>, Error>
Generate a new random EC scalar instance.
Sourcefn ec_point(
&self,
point: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonEcPointRef::{constant#0}>,
) -> Result<Self::EcPoint<'_>, Error>
fn ec_point( &self, point: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonEcPointRef::{constant#0}>, ) -> Result<Self::EcPoint<'_>, Error>
Create an EC point instance from its canonical representation.
Sourcefn ec_generator_point(&self) -> Result<Self::EcPoint<'_>, Error>
fn ec_generator_point(&self) -> Result<Self::EcPoint<'_>, Error>
Get the EC Generator point.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".