MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sctp_compute_hashkey

Function sctp_compute_hashkey

freebsd/netinet/sctp_auth.c:401–454  ·  view source on GitHub ↗

* 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 */

Source from the content-addressed store, hash-verified

399 * order for concatenation
400 */
401sctp_key_t *
402sctp_compute_hashkey(sctp_key_t *key1, sctp_key_t *key2, sctp_key_t *shared)
403{
404 uint32_t keylen;
405 sctp_key_t *new_key;
406 uint8_t *key_ptr;
407
408 keylen = sctp_get_keylen(key1) + sctp_get_keylen(key2) +
409 sctp_get_keylen(shared);
410
411 if (keylen > 0) {
412 /* get space for the new key */
413 new_key = sctp_alloc_key(keylen);
414 if (new_key == NULL) {
415 /* out of memory */
416 return (NULL);
417 }
418 new_key->keylen = keylen;
419 key_ptr = new_key->key;
420 } else {
421 /* all keys empty/null?! */
422 return (NULL);
423 }
424
425 /* concatenate the keys */
426 if (sctp_compare_key(key1, key2) <= 0) {
427 /* key is shared + key1 + key2 */
428 if (sctp_get_keylen(shared)) {
429 memcpy(key_ptr, shared->key, shared->keylen);
430 key_ptr += shared->keylen;
431 }
432 if (sctp_get_keylen(key1)) {
433 memcpy(key_ptr, key1->key, key1->keylen);
434 key_ptr += key1->keylen;
435 }
436 if (sctp_get_keylen(key2)) {
437 memcpy(key_ptr, key2->key, key2->keylen);
438 }
439 } else {
440 /* key is shared + key2 + key1 */
441 if (sctp_get_keylen(shared)) {
442 memcpy(key_ptr, shared->key, shared->keylen);
443 key_ptr += shared->keylen;
444 }
445 if (sctp_get_keylen(key2)) {
446 memcpy(key_ptr, key2->key, key2->keylen);
447 key_ptr += key2->keylen;
448 }
449 if (sctp_get_keylen(key1)) {
450 memcpy(key_ptr, key1->key, key1->keylen);
451 }
452 }
453 return (new_key);
454}
455
456sctp_sharedkey_t *
457sctp_alloc_sharedkey(void)

Callers 2

sctp_fill_hmac_digest_mFunction · 0.85
sctp_handle_authFunction · 0.85

Calls 4

sctp_get_keylenFunction · 0.85
sctp_alloc_keyFunction · 0.85
sctp_compare_keyFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected