class SCTPChunkParamRandom(_SCTPChunkParam, Packet): fields_desc = [ ShortEnumField("type", 0x8002, sctpchunkparamtypes), FieldLenField("len", None, length_of="random", adjust = lambda pkt,x:x+4), PadField(StrLenField("random", RandBin(32), length_from=lambda pkt: pkt.len-4), 4, padwith=b"\x00"),]
def in6_getRandomizedIfaceId(ifaceid, previous=None): # type: (str, Optional[str]) -> Tuple[str, str] """ 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 identifier is provided, a random one is generated. The function returns a tuple containing the randomized interface identifier and the history value (for possible future use). Input and output values are provided in a "printable" format as depicted below. ex:: >>> in6_getRandomizedIfaceId('20b:93ff:feeb:2d3') ('4c61:76ff:f46a:a5f3', 'd006:d540:db11:b092') >>> in6_getRandomizedIfaceId('20b:93ff:feeb:2d3', previous='d006:d540:db11:b092') ('fe97:46fe:9871:bd38', 'eeed:d79c:2e3f:62e') """ s = b"" if previous is None: b_previous = bytes(RandBin(8)) else: b_previous = inet_pton(socket.AF_INET6, "::" + previous)[8:] s = inet_pton(socket.AF_INET6, "::" + ifaceid)[8:] + b_previous import hashlib s = hashlib.md5(s).digest() s1, s2 = s[:8], s[8:] s1 = chb(orb(s1[0]) & (~0x04)) + s1[1:] # set bit 6 to 0 bs1 = inet_ntop(socket.AF_INET6, b"\xff" * 8 + s1)[20:] bs2 = inet_ntop(socket.AF_INET6, b"\xff" * 8 + s2)[20:] return (bs1, bs2)
def randval(self): if self.null_terminated: try: l = self.length_from(None) - 1 except: l = RandTermString(RandNum(0, self.max_length), "\x00") return RandBin(l) return StrFixedLenField.randval(self)
class CGA_Params(Packet): name = "CGA Parameters data structure" fields_desc = [ StrFixedLenField("modifier", RandBin(size=16), length=16), StrFixedLenField("subprefix", "", length=8), ByteField("cc", 0), PacketField("pubkey", X509_SubjectPublicKeyInfo(), X509_SubjectPublicKeyInfo) ]
def __init__(self, size=None, rndstr=None): if size is None: size = RandNumExpo(0.05) self.size = size if rndstr is None: rndstr = RandBin(RandNum(0, 255)) self.rndstr = rndstr self._opts = list(DHCPOptions.values()) self._opts.remove("pad") self._opts.remove("end")
def randval(self): try: l = self.length_from(None) except: l = RandTermString(RandNum(0, self.max_length), "\x00") return RandBin(l)
def gen_nonce(size): """Return a nonce of @size element of random bytes as a string""" return raw(RandBin(size))
def randval(self): return RandBin(RandNum(0, self.max_length() or 1200))