FreeBSD/sys/netinet/sctp_auth.c
/*
 * generate the concatenated keying material based on the two keys and the
 * shared key (if available). draft-ietf-tsvwg-auth specifies the specific
 * order for concatenation
 */
generate the concatenated keying material based on the two keys and the
shared key (if available). draft-ietf-tsvwg-auth specifies the specific
order for concatenation
generate the concatenated keying material based on the two keys and the shared key ( if available ) . draft - ietf - tsvwg - auth specifies the specific order for concatenation
sctp_key_t *
sctp_compute_hashkey(sctp_key_t * key1, sctp_key_t * key2, sctp_key_t * shared)
{
	uint32_t keylen;
	sctp_key_t *new_key;
	uint8_t *key_ptr;
	keylen = sctp_get_keylen(key1) + sctp_get_keylen(key2) +
	    sctp_get_keylen(shared);
	if (keylen > 0) {
		new_key = sctp_alloc_key(keylen);
		if (new_key == NULL) {
			return (NULL);
		}
		new_key->keylen = keylen;
		key_ptr = new_key->key;
	} else {
		return (NULL);
	}
	if (sctp_compare_key(key1, key2) <= 0) {
		if (sctp_get_keylen(shared)) {
			bcopy(shared->key, key_ptr, shared->keylen);
			key_ptr += shared->keylen;
		}
		if (sctp_get_keylen(key1)) {
			bcopy(key1->key, key_ptr, key1->keylen);
			key_ptr += key1->keylen;
		}
		if (sctp_get_keylen(key2)) {
			bcopy(key2->key, key_ptr, key2->keylen);
		}
	} else {
		if (sctp_get_keylen(shared)) {
			bcopy(shared->key, key_ptr, shared->keylen);
			key_ptr += shared->keylen;
		}
		if (sctp_get_keylen(key2)) {
			bcopy(key2->key, key_ptr, key2->keylen);
			key_ptr += key2->keylen;
		}
		if (sctp_get_keylen(key1)) {
			bcopy(key1->key, key_ptr, key1->keylen);
		}
	}
	return (new_key);
}
sctp_key_t * sctp_compute_hashkey ( sctp_key_t * key1 , sctp_key_t * key2 , sctp_key_t * shared ) { uint32_t keylen ; sctp_key_t * new_key ; uint8_t * key_ptr ; keylen = sctp_get_keylen ( key1 ) + sctp_get_keylen ( key2 ) + sctp_get_keylen ( shared ) ; if ( keylen > 0 ) { new_key = sctp_alloc_key ( keylen ) ; if ( new_key == NULL ) { return ( NULL ) ; } new_key -> keylen = keylen ; key_ptr = new_key -> key ; } else { return ( NULL ) ; } if ( sctp_compare_key ( key1 , key2 ) <= 0 ) { if ( sctp_get_keylen ( shared ) ) { bcopy ( shared -> key , key_ptr , shared -> keylen ) ; key_ptr += shared -> keylen ; } if ( sctp_get_keylen ( key1 ) ) { bcopy ( key1 -> key , key_ptr , key1 -> keylen ) ; key_ptr += key1 -> keylen ; } if ( sctp_get_keylen ( key2 ) ) { bcopy ( key2 -> key , key_ptr , key2 -> keylen ) ; } } else { if ( sctp_get_keylen ( shared ) ) { bcopy ( shared -> key , key_ptr , shared -> keylen ) ; key_ptr += shared -> keylen ; } if ( sctp_get_keylen ( key2 ) ) { bcopy ( key2 -> key , key_ptr , key2 -> keylen ) ; key_ptr += key2 -> keylen ; } if ( sctp_get_keylen ( key1 ) ) { bcopy ( key1 -> key , key_ptr , key1 -> keylen ) ; } } return ( new_key ) ; }
generate the concatenated keying material based on the two keys and the
 shared key (if available).
generate the concatenated keying material based on the two keys and the shared key ( if available ) .
/* get space for the new key */ /* out of memory */ /* all keys empty/null?! */ /* concatenate the keys */ /* key is shared + key1 + key2 */ /* key is shared + key2 + key1 */