Skip to main content

Crypto

Trait Crypto 

Source
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§

Source

type Rand<'a>: CryptoRngCore + Copy where Self: 'a

Source

type WeakRand<'a>: RngCore + Copy where Self: 'a

Source

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.

Source

type Hash1<'a>: Digest<rs_matter::::crypto::Crypto::Hash1::{constant#0}> where Self: 'a

SHA-1 hasher type returned by Crypto::hash1.

Source

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.

Source

type Kdf<'a>: Kdf where Self: 'a

KDF type returned by Crypto::kdf.

As per the Matter spec, the KDF should be HKDF-SHA256.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Source

fn rand(&self) -> Result<Self::Rand<'_>, Error>

Create a new, cryptographically secure, random number generator instance.

Source

fn weak_rand(&self) -> Result<Self::WeakRand<'_>, Error>

Create a new NON-cryptographically secure (but potentially faster), random number generator instance.

Source

fn hash(&self) -> Result<Self::Hash<'_>, Error>

Create a new hasher instance.

Source

fn hash1(&self) -> Result<Self::Hash1<'_>, Error>

Create a new SHA-1 hasher instance.

Source

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.

Source

fn kdf(&self) -> Result<Self::Kdf<'_>, Error>

Create a new KDF instance.

Source

fn pbkdf(&self) -> Result<Self::PbKdf<'_>, Error>

Create a new PBKDF instance.

Source

fn aead(&self) -> Result<Self::Aead<'_>, Error>

Create a new AEAD instance.

Source

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.

Source

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.

Source

fn generate_secret_key(&self) -> Result<Self::SecretKey<'_>, Error>

Generate a new secret key instance.

Source

fn singleton_singing_secret_key( &self, ) -> Result<Self::SigningSecretKey<'_>, Error>

Get the singleton signing secret key instance.

This is used for device attestation.

Source

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.

Source

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.

Source

fn generate_ec_scalar(&self) -> Result<Self::EcScalar<'_>, Error>

Generate a new random EC scalar instance.

Source

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.

Source

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".

Implementations on Foreign Types§

Source§

impl<T> Crypto for &T
where T: Crypto,

Source§

type Rand<'a> = <T as Crypto>::Rand<'a> where &T: 'a

Source§

type WeakRand<'a> = <T as Crypto>::WeakRand<'a> where &T: 'a

Source§

type Hash<'a> = <T as Crypto>::Hash<'a> where &T: 'a

Source§

type Hash1<'a> = <T as Crypto>::Hash1<'a> where &T: 'a

Source§

type Hmac<'a> = <T as Crypto>::Hmac<'a> where &T: 'a

Source§

type Kdf<'a> = <T as Crypto>::Kdf<'a> where &T: 'a

Source§

type PbKdf<'a> = <T as Crypto>::PbKdf<'a> where &T: 'a

Source§

type Aead<'a> = <T as Crypto>::Aead<'a> where &T: 'a

Source§

type PublicKey<'a> = <T as Crypto>::PublicKey<'a> where &T: 'a

Source§

type SecretKey<'a> = <T as Crypto>::SecretKey<'a> where &T: 'a

Source§

type SigningSecretKey<'a> = <T as Crypto>::SigningSecretKey<'a> where &T: 'a

Source§

type EcScalar<'a> = <T as Crypto>::EcScalar<'a> where &T: 'a

Source§

type EcPoint<'a> = <T as Crypto>::EcPoint<'a> where &T: 'a

Source§

fn rand(&self) -> Result<<&T as Crypto>::Rand<'_>, Error>

Source§

fn weak_rand(&self) -> Result<<&T as Crypto>::WeakRand<'_>, Error>

Source§

fn hash(&self) -> Result<<&T as Crypto>::Hash<'_>, Error>

Source§

fn hash1(&self) -> Result<<&T as Crypto>::Hash1<'_>, Error>

Source§

fn hmac<const KEY_LEN: usize>( &self, key: CryptoSensitiveRef<'_, KEY_LEN>, ) -> Result<<&T as Crypto>::Hmac<'_>, Error>

Source§

fn kdf(&self) -> Result<<&T as Crypto>::Kdf<'_>, Error>

Source§

fn pbkdf(&self) -> Result<<&T as Crypto>::PbKdf<'_>, Error>

Source§

fn aead(&self) -> Result<<&T as Crypto>::Aead<'_>, Error>

Source§

fn pub_key( &self, key: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonPkcPublicKeyRef::{constant#0}>, ) -> Result<<&T as Crypto>::PublicKey<'_>, Error>

Source§

fn generate_secret_key(&self) -> Result<<&T as Crypto>::SecretKey<'_>, Error>

Source§

fn secret_key( &self, key: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonPkcSecretKeyRef::{constant#0}>, ) -> Result<<&T as Crypto>::SecretKey<'_>, Error>

Source§

fn singleton_singing_secret_key( &self, ) -> Result<<&T as Crypto>::SigningSecretKey<'_>, Error>

Source§

fn ec_scalar( &self, scalar: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonEcScalarRef::{constant#0}>, ) -> Result<<&T as Crypto>::EcScalar<'_>, Error>

Source§

fn ec_scalar_mod_p( &self, uint: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonUint320Ref::{constant#0}>, ) -> Result<<&T as Crypto>::EcScalar<'_>, Error>

Source§

fn generate_ec_scalar(&self) -> Result<<&T as Crypto>::EcScalar<'_>, Error>

Source§

fn ec_point( &self, point: CryptoSensitiveRef<'_, rs_matter::::crypto::canon::CanonEcPointRef::{constant#0}>, ) -> Result<<&T as Crypto>::EcPoint<'_>, Error>

Source§

fn ec_generator_point(&self) -> Result<<&T as Crypto>::EcPoint<'_>, Error>

Implementors§