Struct orion::hmac::Hmac [−][src]
pub struct Hmac {
pub secret_key: Vec<u8>,
pub message: Vec<u8>,
pub sha2: ShaVariantOption,
}HMAC (Hash-based Message Authentication Code) as specified in the RFC 2104.
Fields
secret_key: Vec<u8>
message: Vec<u8>
sha2: ShaVariantOption
Methods
impl Hmac[src]
impl HmacHMAC (Hash-based Message Authentication Code) as specified in the RFC 2104.
Usage examples:
Generating HMAC:
use orion::hmac::Hmac; use orion::core::util::gen_rand_key; use orion::core::options::ShaVariantOption; let key = gen_rand_key(16).unwrap(); let message = gen_rand_key(16).unwrap(); let hmac_sha256 = Hmac { secret_key: key, message: message, sha2: ShaVariantOption::SHA256 }; hmac_sha256.hmac_compute();
Verifying HMAC:
use orion::hmac::Hmac; use orion::core::options::ShaVariantOption; let key = "Some key."; let msg = "Some message."; let hmac_sha256 = Hmac { secret_key: key.as_bytes().to_vec(), message: msg.as_bytes().to_vec(), sha2: ShaVariantOption::SHA256 }; let received_hmac = Hmac { secret_key: key.as_bytes().to_vec(), message: msg.as_bytes().to_vec(), sha2: ShaVariantOption::SHA256 }; assert_eq!(hmac_sha256.hmac_compare(&received_hmac.hmac_compute()).unwrap(), true);
pub fn pad_key(&self, secret_key: &[u8]) -> (Vec<u8>, Vec<u8>)[src]
pub fn pad_key(&self, secret_key: &[u8]) -> (Vec<u8>, Vec<u8>)Return the inner and outer padding used for HMAC.
pub fn hmac_compute(&self) -> Vec<u8>[src]
pub fn hmac_compute(&self) -> Vec<u8>Returns an HMAC for a given key and message.
pub fn pbkdf2_hmac(
&self,
ipad: Vec<u8>,
opad: Vec<u8>,
message: &[u8]
) -> Vec<u8>[src]
pub fn pbkdf2_hmac(
&self,
ipad: Vec<u8>,
opad: Vec<u8>,
message: &[u8]
) -> Vec<u8>HMAC used for PBKDF2 which also takes both inner and outer padding as argument.
pub fn hmac_compare(
&self,
received_hmac: &[u8]
) -> Result<bool, UnknownCryptoError>[src]
pub fn hmac_compare(
&self,
received_hmac: &[u8]
) -> Result<bool, UnknownCryptoError>Check HMAC validity by computing one from the current struct fields and comparing this to the passed HMAC. Comparison is done in constant time and with Double-HMAC Verification.