Function orion::default::hmac [−][src]
pub fn hmac(
secret_key: &[u8],
data: &[u8]
) -> Result<Vec<u8>, UnknownCryptoError>
HMAC-SHA512/256.
Parameters:
secret_key
: The authentication keydata
: Data to be authenticated
See RFC for more information.
Exceptions:
An exception will be thrown if:
- The length of the secret key is less than 64 bytes.
Security:
The secret key should always be generated using a CSPRNG. The gen_rand_key
function
in util
can be used for this. The recommended length for a secret key is the SHA functions digest
size in bytes.
Example:
use orion::default; use orion::core::util; let key = util::gen_rand_key(64).unwrap(); let msg = "Some message.".as_bytes(); let hmac = default::hmac(&key, msg).unwrap();