FreeBSD/sys/netinet/sctp_auth.c
/*-
 * verify the HMAC digest using the desired hash key, text, and HMAC
 * algorithm.
 * Returns -1 on error, 0 on success.
 */
verify the HMAC digest using the desired hash key, text, and HMAC
algorithm.
Returns -1 on error, 0 on success.
verify the HMAC digest using the desired hash key text and HMAC algorithm . Returns - 1 on error 0 on success .
int
sctp_verify_hmac(uint16_t hmac_algo, uint8_t * key, uint32_t keylen,
    uint8_t * text, uint32_t textlen,
    uint8_t * digest, uint32_t digestlen)
{
	uint32_t len;
	uint8_t temp[SCTP_AUTH_DIGEST_LEN_MAX];
	if ((key == NULL) || (keylen == 0) ||
	    (text == NULL) || (textlen == 0) || (digest == NULL)) {
		return (-1);
	}
	len = sctp_get_hmac_digest_len(hmac_algo);
	if ((len == 0) || (digestlen != len))
		return (-1);
	if (sctp_hmac(hmac_algo, key, keylen, text, textlen, temp) != len)
		return (-1);
	if (memcmp(digest, temp, digestlen) != 0)
		return (-1);
	else
		return (0);
}
int sctp_verify_hmac ( uint16_t hmac_algo , uint8_t * key , uint32_t keylen , uint8_t * text , uint32_t textlen , uint8_t * digest , uint32_t digestlen ) { uint32_t len ; uint8_t temp [ SCTP_AUTH_DIGEST_LEN_MAX ] ; if ( ( key == NULL ) || ( keylen == 0 ) || ( text == NULL ) || ( textlen == 0 ) || ( digest == NULL ) ) { return ( -1 ) ; } len = sctp_get_hmac_digest_len ( hmac_algo ) ; if ( ( len == 0 ) || ( digestlen != len ) ) return ( -1 ) ; if ( sctp_hmac ( hmac_algo , key , keylen , text , textlen , temp ) != len ) return ( -1 ) ; if ( memcmp ( digest , temp , digestlen ) != 0 ) return ( -1 ) ; else return ( 0 ) ; }
verify the HMAC digest using the desired hash key, text, and HMAC
 algorithm.
verify the HMAC digest using the desired hash key text and HMAC algorithm .
/* sanity check the material and length */ /* can't do HMAC with empty key or text or digest */ /* compute the expected hash */