// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // Copyright by contributors to this project. // SPDX-License-Identifier: (Apache-2.0 OR MIT)
use mls_rs_crypto_traits::{DhType, KdfType, KemResult, KemType, SamplingMethod};
use mls_rs_core::{
crypto::{HpkePublicKey, HpkeSecretKey},
error::{AnyError, IntoAnyError},
}; use zeroize::Zeroizing;
impl<DH: DhType, KDF: KdfType> DhKem<DH, KDF> { #[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] asyncfn derive_with_rejection_sampling(
&self,
dkp_prk: &[u8],
bitmask: u8,
) -> Result<(HpkeSecretKey, HpkePublicKey), DhKemError> { // The RFC specifies we get 255 chances to generate bytes that will be within range of the order for the curve for i in0u8..255 { letmut secret_key = self
.kdf
.labeled_expand(dkp_prk, b"candidate", &[i], self.dh.secret_key_size())
.await
.map_err(|e| DhKemError::KdfError(e.into_any_error()))?;
secret_key[0] &= bitmask; let secret_key = secret_key.into();
// Compute the public key and if it succeeds, return the key pair iflet Ok(pair) = self
.dh
.to_public(&secret_key)
.await
.map(|pk| (secret_key, pk))
{ return Ok(pair);
}
}
// If we never generate bytes that work, throw an error
Err(DhKemError::KeyDerivationError)
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.