FreeBSD/sys/netinet/sctp_auth.c
/*
 * compute and fill in the HMAC digest for a packet
 */
compute and fill in the HMAC digest for a packet
compute and fill in the HMAC digest for a packet
void
sctp_fill_hmac_digest_m(struct mbuf *m, uint32_t auth_offset,
    struct sctp_auth_chunk *auth, struct sctp_tcb *stcb, uint16_t keyid)
{
	uint32_t digestlen;
	sctp_sharedkey_t *skey;
	sctp_key_t *key;
	if ((stcb == NULL) || (auth == NULL))
		return;
	digestlen = sctp_get_hmac_digest_len(stcb->asoc.peer_hmac_id);
	bzero(auth->hmac, SCTP_SIZE32(digestlen));
	if ((keyid != stcb->asoc.authinfo.assoc_keyid) ||
	    (stcb->asoc.authinfo.assoc_key == NULL)) {
		if (stcb->asoc.authinfo.assoc_key != NULL) {
			sctp_free_key(stcb->asoc.authinfo.assoc_key);
		}
		skey = sctp_find_sharedkey(&stcb->asoc.shared_keys, keyid);
		if (skey != NULL)
			key = skey->key;
		else
			key = NULL;
		stcb->asoc.authinfo.assoc_key =
		    sctp_compute_hashkey(stcb->asoc.authinfo.random,
		    stcb->asoc.authinfo.peer_random, key);
		stcb->asoc.authinfo.assoc_keyid = keyid;
		SCTPDBG(SCTP_DEBUG_AUTH1, "caching key id %u\n",
		    stcb->asoc.authinfo.assoc_keyid);
#ifdef SCTP_DEBUG
		if (SCTP_AUTH_DEBUG)
			sctp_print_key(stcb->asoc.authinfo.assoc_key,
			    "Assoc Key");
#endif
	}
	auth->shared_key_id = htons(keyid);
	(void)sctp_compute_hmac_m(stcb->asoc.peer_hmac_id, stcb->asoc.authinfo.assoc_key,
	    m, auth_offset, auth->hmac);
}
void sctp_fill_hmac_digest_m ( struct mbuf * m , uint32_t auth_offset , struct sctp_auth_chunk * auth , struct sctp_tcb * stcb , uint16_t keyid ) { uint32_t digestlen ; sctp_sharedkey_t * skey ; sctp_key_t * key ; if ( ( stcb == NULL ) || ( auth == NULL ) ) return ; digestlen = sctp_get_hmac_digest_len ( stcb -> asoc . peer_hmac_id ) ; bzero ( auth -> hmac , SCTP_SIZE32 ( digestlen ) ) ; if ( ( keyid != stcb -> asoc . authinfo . assoc_keyid ) || ( stcb -> asoc . authinfo . assoc_key == NULL ) ) { if ( stcb -> asoc . authinfo . assoc_key != NULL ) { sctp_free_key ( stcb -> asoc . authinfo . assoc_key ) ; } skey = sctp_find_sharedkey ( & stcb -> asoc . shared_keys , keyid ) ; if ( skey != NULL ) key = skey -> key ; else key = NULL ; stcb -> asoc . authinfo . assoc_key = sctp_compute_hashkey ( stcb -> asoc . authinfo . random , stcb -> asoc . authinfo . peer_random , key ) ; stcb -> asoc . authinfo . assoc_keyid = keyid ; SCTPDBG ( SCTP_DEBUG_AUTH1 , " \n " , stcb -> asoc . authinfo . assoc_keyid ) ; #ifdef SCTP_DEBUG if ( SCTP_AUTH_DEBUG ) sctp_print_key ( stcb -> asoc . authinfo . assoc_key , " " ) ; #endif } auth -> shared_key_id = htons ( keyid ) ; ( void ) sctp_compute_hmac_m ( stcb -> asoc . peer_hmac_id , stcb -> asoc . authinfo . assoc_key , m , auth_offset , auth -> hmac ) ; }
compute and fill in the HMAC digest for a packet
compute and fill in the HMAC digest for a packet
/* zero the digest + chunk padding */ /* is the desired key cached? */ /* free the old cached key */ /* the only way skey is NULL is if null key id 0 is used */ /* compute a new assoc key and cache it */ /* set in the active key id */ /* compute and fill in the digest */