pub struct DeriveKey(/* private fields */);Expand description
An operation for derive a shared key object.
Implementations§
Source§impl DeriveKey
impl DeriveKey
Sourcepub fn derive(&self, params: &[Attribute], object: &mut TransientObject)
pub fn derive(&self, params: &[Attribute], object: &mut TransientObject)
Take one of the key derivation algorithms that supports this operation as defined in AlgorithmId, and output a key object.
§Parameters
params: For algorithm DhDeriveSharedSecret, DhPublicValue is required as the passed in attribute. For the PBKDF2-HMAC algorithms (Pbkdf2HmacSha1 and similar), pass the salt, the iteration count and the derived key material length as attributes, and use a Pbkdf2Password object as the operation key.object: An uninitialized transient object to be filled with the derived key.
§Example
let attr_prime = AttributeMemref::from_ref(AttributeId::DhPrime, &[23u8]);
let attr_base = AttributeMemref::from_ref(AttributeId::DhBase, &[5u8]);
let mut public_1 = [0u8; 32];
match TransientObject::allocate(TransientObjectType::DhKeypair, 256) {
Ok(key_pair_1) => {
key_pair_1.generate_key(256, &[attr_prime.into(), attr_base.into()])?;
key_pair_1.ref_attribute(AttributeId::DhPublicValue, &mut public_1)?;
Ok(())
}
Err(e) => Err(e),
}
let attr_prime = AttributeMemref::from_ref(AttributeId::DhPrime, &[23u8]);
let attr_base = AttributeMemref::from_ref(AttributeId::DhBase, &[5u8]);
match TransientObject::allocate(TransientObjectType::DhKeypair, 256) {
Ok(key_pair_2) => {
key_pair_2.generate_key(256, &[attr_prime.into(), attr_base.into()])?;
match DeriveKey::allocate(AlgorithmId::DhDeriveSharedSecret, 256) {
Ok(mut operation) => {
operation.set_key(&key_pair_2)?;
match TransientObject::allocate(TransientObjectType::GenericSecret, 256) {
// Derived key is saved as an transient object
Ok(mut derived_key) => {
let attr_public = AttributeMemref::from_ref(AttributeId::DhPublicValue, &public_1);
operation.derive(&[attr_public.into()], &mut derived_key);
// ...
Ok(())
}
Err(e) => Err(e),
}
}
Err(e) => Err(e),
}
}
Err(e) => Err(e),
}§Panics
- If the algorithm is not a valid algorithm for
DeriveKey. - If the
objectis too small for generated value. - If no key is programmed in the operation.
- Hardware or cryptographic algorithm failure.
- If the Implementation detects any other error.
Sourcepub fn null() -> Self
pub fn null() -> Self
Create a DeriveKey operation without any specific algorithm or other data.
Sourcepub fn allocate(algo: AlgorithmId, max_key_size: usize) -> Result<Self>
pub fn allocate(algo: AlgorithmId, max_key_size: usize) -> Result<Self>
Function usage is similar to Digest::allocate.
Currently supports DhDeriveSharedSecret,
EcDhDeriveSharedSecret,
X25519 and the PBKDF2-HMAC algorithms as
algo.
Sourcepub fn info(&self) -> OperationInfo
pub fn info(&self) -> OperationInfo
Function usage is similar to Digest::info.
Sourcepub fn info_multiple(
&self,
info_buf: &mut [u8],
) -> Result<OperationInfoMultiple>
pub fn info_multiple( &self, info_buf: &mut [u8], ) -> Result<OperationInfoMultiple>
Function usage is similar to Digest::info_multiple.
Sourcepub fn set_key<T: GenericObject>(&mut self, object: &T) -> Result<()>
pub fn set_key<T: GenericObject>(&mut self, object: &T) -> Result<()>
Function usage is similar to Cipher::set_key.
Sourcepub fn set_key_2<T: GenericObject, D: GenericObject>(
&self,
object1: &T,
object2: &D,
) -> Result<()>
pub fn set_key_2<T: GenericObject, D: GenericObject>( &self, object1: &T, object2: &D, ) -> Result<()>
Function usage is similar to Cipher::set_key_2.
Sourcepub fn copy<T: OpHandle>(&mut self, src: &T)
pub fn copy<T: OpHandle>(&mut self, src: &T)
Function usage is similar to Digest::copy.
Trait Implementations§
Auto Trait Implementations§
impl !Send for DeriveKey
impl !Sync for DeriveKey
impl Freeze for DeriveKey
impl RefUnwindSafe for DeriveKey
impl Unpin for DeriveKey
impl UnsafeUnpin for DeriveKey
impl UnwindSafe for DeriveKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more