pub fn sign_hash(
    key: Id,
    alg: AsymmetricSignature,
    hash: &[u8],
    signature: &mut [u8],
) -> Result<usize> {
    initialized()?;

    let mut signature_length = 0;

    Status::from(unsafe {
        psa_crypto_sys::psa_sign_hash(
            key.0,
            alg.into(),
            hash.as_ptr(),
            hash.len(),
            signature.as_mut_ptr(),
            signature.len(),
            &mut signature_length,
        )
    })
    .to_result()?;
    Ok(signature_length)
}
/// Sign an already-calculated hash with a private key
///
/// The signature is written in `signature`. The function returns the number of bytes written.
///
/// # Example
///
/// ```
/// # use psa_crypto::operations::key_management::generate;
/// # use psa_crypto::operations::asym_signature::sign_hash;
/// # use psa_crypto::types::key::{Attributes, Type, Lifetime, Policy, UsageFlags};
/// # use psa_crypto::types::algorithm::{AsymmetricSignature, Hash};
/// # let mut usage_flags: UsageFlags = Default::default();
/// # usage_flags.set_sign_hash().set_verify_hash();
/// # let mut attributes = Attributes {
/// #     key_type: Type::RsaKeyPair,
/// #     bits: 1024,
/// #     lifetime: Lifetime::Volatile,
/// #     policy: Policy {
/// #         usage_flags,
/// #         permitted_algorithms: AsymmetricSignature::RsaPkcs1v15Sign {
/// #             hash_alg: Hash::Sha256.into(),
/// #         }.into(),
/// #     },
/// # };
/// # const HASH: [u8; 32] = [
/// #     0x69, 0x3E, 0xDB, 0x1B, 0x22, 0x79, 0x03, 0xF4, 0xC0, 0xBF, 0xD6, 0x91, 0x76, 0x37, 0x84, 0xA2,
/// #     0x94, 0x8E, 0x92, 0x50, 0x35, 0xC2, 0x8C, 0x5C, 0x3C, 0xCA, 0xFE, 0x18, 0xE8, 0x81, 0x37, 0x78,
/// # ];
/// psa_crypto::init().unwrap();
/// let my_key = generate(attributes, None).unwrap();
/// let alg = AsymmetricSignature::RsaPkcs1v15Sign {
///                          hash_alg: Hash::Sha256.into(),
///                      };
/// let buffer_size = attributes.sign_output_size(alg).unwrap();
/// let mut signature = vec![0; buffer_size];
///
/// let size = sign_hash(my_key,
///                      alg,
///                      &HASH,
///                      &mut signature).unwrap();
/// signature.resize(size, 0);
/// ```
Sign an already-calculated hash with a private key
The signature is written in `signature`. The function returns the number of bytes written.
Sign an already - calculated hash with a private key The signature is written in ` signature ` . The function returns the number of bytes written .
pub fn sign_hash(
    key: Id,
    alg: AsymmetricSignature,
    hash: &[u8],
    signature: &mut [u8],
) -> Result<usize> {
    initialized()?;
    let mut signature_length = 0;
    Status::from(unsafe {
        psa_crypto_sys::psa_sign_hash(
            key.0,
            alg.into(),
            hash.as_ptr(),
            hash.len(),
            signature.as_mut_ptr(),
            signature.len(),
            &mut signature_length,
        )
    })
    .to_result()?;
    Ok(signature_length)
}
pub fn sign_hash ( key : Id , alg : AsymmetricSignature , hash : & [ u8 ] , signature : & mut [ u8 ] , ) -> Result < usize > { initialized ( ) ? ; let mut signature_length = 0 ; Status :: from ( unsafe { psa_crypto_sys :: psa_sign_hash ( key . 0 , alg . into ( ) , hash . as_ptr ( ) , hash . len ( ) , signature . as_mut_ptr ( ) , signature . len ( ) , & mut signature_length , ) } ) . to_result ( ) ? ; Ok ( signature_length ) }
Sign an already-calculated hash with a private key
The signature is written in `signature`.
Sign an already - calculated hash with a private key The signature is written in ` signature ` .
key
Id
alg
AsymmetricSignature
hash
&[u8]
signature
&mut [u8]
key
Id
alg
AsymmetricSignature
hash
&[u8]
signature
&mut [u8]
example
None
use psa_crypto::operations::key_management::generate;
None
use psa_crypto::operations::asym_signature::sign_hash;
None
use psa_crypto::types::key::{attributes, type, lifetime, policy, usageflags};
None
use psa_crypto::types::algorithm::{asymmetricsignature, hash};
None
let mut usage_flags: usageflags = default::default();
None
usage_flags.set_sign_hash().set_verify_hash();
None
let mut attributes = attributes {
None
key_type: type::rsakeypair,
None
bits: 1024,
None
lifetime: lifetime::volatile,
None
policy: policy {
None
usage_flags,
None
permitted_algorithms: asymmetricsignature::rsapkcs1v15sign {
None
hash_alg: hash::sha256.into(),
None
}.into(),
None
},
None
};
None
const hash: [u8; 32] = [
None
0x69, 0x3e, 0xdb, 0x1b, 0x22, 0x79, 0x03, 0xf4, 0xc0, 0xbf, 0xd6, 0x91, 0x76, 0x37, 0x84, 0xa2,
None
0x94, 0x8e, 0x92, 0x50, 0x35, 0xc2, 0x8c, 0x5c, 0x3c, 0xca, 0xfe, 0x18, 0xe8, 0x81, 0x37, 0x78,
None
];
:init().unwrap();
let my_key = generate(attributes, None).unwrap();
let alg = AsymmetricSignature::RsaPkcs1v15Sign {
hash_alg: Hash::Sha256.into(),
};
let buffer_size = attributes.sign_output_size(alg).unwrap();
let mut signature = vec![0; buffer_size].

let size = sign_hash(my_key,
alg,
&HASH,
&mut signature).unwrap();
signature.resize(size, 0);
```
: init () . unwrap () ; let my_key = generate ( attributes None ) . unwrap () ; let alg = AsymmetricSignature :: RsaPkcs1v15Sign { hash_alg : Hash :: Sha256 . into () } ; let buffer_size = attributes . sign_output_size ( alg ) . unwrap () ; let mut signature = vec! [ 0 ; buffer_size ] . let size = sign_hash ( my_key alg &HASH &mut signature ) . unwrap () ; signature . resize ( size 0 ) ; ` ` `