FreeBSD/sys/netinet/sctp_auth.c
/*
 * computes the requested HMAC using a key struct (which may be modified if
 * the keylen exceeds the HMAC block len).
 */
computes the requested HMAC using a key struct (which may be modified if
the keylen exceeds the HMAC block len).
computes the requested HMAC using a key struct ( which may be modified if the keylen exceeds the HMAC block len ) .
uint32_t
sctp_compute_hmac(uint16_t hmac_algo, sctp_key_t * key, uint8_t * text,
    uint32_t textlen, uint8_t * digest)
{
	uint32_t digestlen;
	uint32_t blocklen;
	sctp_hash_context_t ctx;
	uint8_t temp[SCTP_AUTH_DIGEST_LEN_MAX];
	if ((key == NULL) || (text == NULL) || (textlen == 0) ||
	    (digest == NULL)) {
		return (0);
	}
	digestlen = sctp_get_hmac_digest_len(hmac_algo);
	if (digestlen == 0)
		return (0);
	blocklen = sctp_get_hmac_block_len(hmac_algo);
	if (key->keylen > blocklen) {
		sctp_hmac_init(hmac_algo, &ctx);
		sctp_hmac_update(hmac_algo, &ctx, key->key, key->keylen);
		sctp_hmac_final(hmac_algo, &ctx, temp);
		key->keylen = digestlen;
		bcopy(temp, key->key, key->keylen);
	}
	return (sctp_hmac(hmac_algo, key->key, key->keylen, text, textlen,
	    digest));
}
uint32_t sctp_compute_hmac ( uint16_t hmac_algo , sctp_key_t * key , uint8_t * text , uint32_t textlen , uint8_t * digest ) { uint32_t digestlen ; uint32_t blocklen ; sctp_hash_context_t ctx ; uint8_t temp [ SCTP_AUTH_DIGEST_LEN_MAX ] ; if ( ( key == NULL ) || ( text == NULL ) || ( textlen == 0 ) || ( digest == NULL ) ) { return ( 0 ) ; } digestlen = sctp_get_hmac_digest_len ( hmac_algo ) ; if ( digestlen == 0 ) return ( 0 ) ; blocklen = sctp_get_hmac_block_len ( hmac_algo ) ; if ( key -> keylen > blocklen ) { sctp_hmac_init ( hmac_algo , & ctx ) ; sctp_hmac_update ( hmac_algo , & ctx , key -> key , key -> keylen ) ; sctp_hmac_final ( hmac_algo , & ctx , temp ) ; key -> keylen = digestlen ; bcopy ( temp , key -> key , key -> keylen ) ; } return ( sctp_hmac ( hmac_algo , key -> key , key -> keylen , text , textlen , digest ) ) ; }
computes the requested HMAC using a key struct (which may be modified if
 the keylen exceeds the HMAC block len).
computes the requested HMAC using a key struct ( which may be modified if the keylen exceeds the HMAC block len ) .
/* sanity check */ /* can't do HMAC with empty key or text or digest store */ /* validate the hmac algo and get the digest length */ /* hash the key if it is longer than the hash block size */ /* save the hashed key as the new key */