MCPcopy Index your code
hub / github.com/secdev/scapy / in6_getRandomizedIfaceId

Function in6_getRandomizedIfaceId

scapy/utils6.py:435–467  ·  view source on GitHub ↗

Implements the interface ID generation algorithm described in RFC 3041. The function takes the Modified EUI-64 interface identifier generated as described in RFC 4291 and an optional previous history value (the first element of the output of this function). If no previous interface

(ifaceid, previous=None)

Source from the content-addressed store, hash-verified

433
434
435def in6_getRandomizedIfaceId(ifaceid, previous=None):
436 # type: (str, Optional[str]) -> Tuple[str, str]
437 """
438 Implements the interface ID generation algorithm described in RFC 3041.
439 The function takes the Modified EUI-64 interface identifier generated
440 as described in RFC 4291 and an optional previous history value (the
441 first element of the output of this function). If no previous interface
442 identifier is provided, a random one is generated. The function returns
443 a tuple containing the randomized interface identifier and the history
444 value (for possible future use). Input and output values are provided in
445 a "printable" format as depicted below.
446
447 ex::
448 >>> in6_getRandomizedIfaceId('20b:93ff:feeb:2d3')
449 ('4c61:76ff:f46a:a5f3', 'd006:d540:db11:b092')
450 >>> in6_getRandomizedIfaceId('20b:93ff:feeb:2d3',
451 previous='d006:d540:db11:b092')
452 ('fe97:46fe:9871:bd38', 'eeed:d79c:2e3f:62e')
453 """
454
455 s = b""
456 if previous is None:
457 b_previous = bytes(RandBin(8))
458 else:
459 b_previous = inet_pton(socket.AF_INET6, "::" + previous)[8:]
460 s = inet_pton(socket.AF_INET6, "::" + ifaceid)[8:] + b_previous
461 import hashlib
462 s = hashlib.md5(s).digest()
463 s1, s2 = s[:8], s[8:]
464 s1 = chb(orb(s1[0]) & (~0x04)) + s1[1:] # set bit 6 to 0
465 bs1 = inet_ntop(socket.AF_INET6, b"\xff" * 8 + s1)[20:]
466 bs2 = inet_ntop(socket.AF_INET6, b"\xff" * 8 + s2)[20:]
467 return (bs1, bs2)
468
469
470_rfc1924map = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', # noqa: E501

Callers

nothing calls this directly

Calls 6

RandBinClass · 0.90
inet_ptonFunction · 0.90
chbFunction · 0.90
orbFunction · 0.90
inet_ntopFunction · 0.90
digestMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…