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

Function sctp_compare_key

freebsd/netinet/sctp_auth.c:350–394  ·  view source on GitHub ↗

- * given two keys of variable size, compute which key is "larger/smaller" * returns: 1 if key1 > key2 * -1 if key1 < key2 * 0 if key1 = key2 */

Source from the content-addressed store, hash-verified

348 * 0 if key1 = key2
349 */
350static int
351sctp_compare_key(sctp_key_t *key1, sctp_key_t *key2)
352{
353 uint32_t maxlen;
354 uint32_t i;
355 uint32_t key1len, key2len;
356 uint8_t *key_1, *key_2;
357 uint8_t val1, val2;
358
359 /* sanity/length check */
360 key1len = sctp_get_keylen(key1);
361 key2len = sctp_get_keylen(key2);
362 if ((key1len == 0) && (key2len == 0))
363 return (0);
364 else if (key1len == 0)
365 return (-1);
366 else if (key2len == 0)
367 return (1);
368
369 if (key1len < key2len) {
370 maxlen = key2len;
371 } else {
372 maxlen = key1len;
373 }
374 key_1 = key1->key;
375 key_2 = key2->key;
376 /* check for numeric equality */
377 for (i = 0; i < maxlen; i++) {
378 /* left-pad with zeros */
379 val1 = (i < (maxlen - key1len)) ? 0 : *(key_1++);
380 val2 = (i < (maxlen - key2len)) ? 0 : *(key_2++);
381 if (val1 > val2) {
382 return (1);
383 } else if (val1 < val2) {
384 return (-1);
385 }
386 }
387 /* keys are equal value, so check lengths */
388 if (key1len == key2len)
389 return (0);
390 else if (key1len < key2len)
391 return (-1);
392 else
393 return (1);
394}
395
396/*
397 * generate the concatenated keying material based on the two keys and the

Callers 1

sctp_compute_hashkeyFunction · 0.85

Calls 1

sctp_get_keylenFunction · 0.85

Tested by

no test coverage detected