Python scapy.layers.inet.IP.name() Examples
The following are 24
code examples of scapy.layers.inet.IP.name().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scapy.layers.inet.IP
, or try the search function
.
Example #1
Source File: ipsec.py From arissploit with GNU General Public License v3.0 | 6 votes |
def decrypt(self, pkt, verify=True): """ Decrypt (and decapsulate) an IP(v6) packet containing ESP or AH. @param pkt: the packet to decrypt @param verify: if False, do not perform the integrity check @return: the decrypted/decapsulated packet @raise IPSecIntegrityError: if the integrity check fails """ if not isinstance(pkt, self.SUPPORTED_PROTOS): raise TypeError('cannot decrypt %s, supported protos are %s' % (pkt.__class__, self.SUPPORTED_PROTOS)) if self.proto is ESP and pkt.haslayer(ESP): return self._decrypt_esp(pkt, verify=verify) elif self.proto is AH and pkt.haslayer(AH): return self._decrypt_ah(pkt, verify=verify) else: raise TypeError('%s has no %s layer' % (pkt, self.proto.name))
Example #2
Source File: ipsec.py From smod-1 with GNU General Public License v2.0 | 6 votes |
def decrypt(self, pkt, verify=True): """ Decrypt (and decapsulate) an IP(v6) packet containing ESP or AH. @param pkt: the packet to decrypt @param verify: if False, do not perform the integrity check @return: the decrypted/decapsulated packet @raise IPSecIntegrityError: if the integrity check fails """ if not isinstance(pkt, self.SUPPORTED_PROTOS): raise TypeError('cannot decrypt %s, supported protos are %s' % (pkt.__class__, self.SUPPORTED_PROTOS)) if self.proto is ESP and pkt.haslayer(ESP): return self._decrypt_esp(pkt, verify=verify) elif self.proto is AH and pkt.haslayer(AH): return self._decrypt_ah(pkt, verify=verify) else: raise TypeError('%s has no %s layer' % (pkt, self.proto.name))
Example #3
Source File: ipsec.py From POC-EXP with GNU General Public License v3.0 | 6 votes |
def decrypt(self, pkt, verify=True): """ Decrypt (and decapsulate) an IP(v6) packet containing ESP or AH. @param pkt: the packet to decrypt @param verify: if False, do not perform the integrity check @return: the decrypted/decapsulated packet @raise IPSecIntegrityError: if the integrity check fails """ if not isinstance(pkt, self.SUPPORTED_PROTOS): raise TypeError('cannot decrypt %s, supported protos are %s' % (pkt.__class__, self.SUPPORTED_PROTOS)) if self.proto is ESP and pkt.haslayer(ESP): return self._decrypt_esp(pkt, verify=verify) elif self.proto is AH and pkt.haslayer(AH): return self._decrypt_ah(pkt, verify=verify) else: raise TypeError('%s has no %s layer' % (pkt, self.proto.name))
Example #4
Source File: ipsec.py From scapy with GNU General Public License v2.0 | 6 votes |
def decrypt(self, pkt, verify=True, esn_en=None, esn=None): """ Decrypt (and decapsulate) an IP(v6) packet containing ESP or AH. :param pkt: the packet to decrypt :param verify: if False, do not perform the integrity check :param esn_en: extended sequence number enable which allows to use 64-bit sequence number instead of 32-bit when using an AEAD algorithm :param esn: extended sequence number (32 MSB) :returns: the decrypted/decapsulated packet :raise scapy.layers.ipsec.IPSecIntegrityError: if the integrity check fails """ if not isinstance(pkt, self.SUPPORTED_PROTOS): raise TypeError('cannot decrypt %s, supported protos are %s' % (pkt.__class__, self.SUPPORTED_PROTOS)) if self.proto is ESP and pkt.haslayer(ESP): return self._decrypt_esp(pkt, verify=verify, esn_en=esn_en, esn=esn) elif self.proto is AH and pkt.haslayer(AH): return self._decrypt_ah(pkt, verify=verify, esn_en=esn_en, esn=esn) else: raise TypeError('%s has no %s layer' % (pkt, self.proto.name))
Example #5
Source File: ipsec.py From dash-hack with MIT License | 6 votes |
def decrypt(self, pkt, verify=True): """ Decrypt (and decapsulate) an IP(v6) packet containing ESP or AH. @param pkt: the packet to decrypt @param verify: if False, do not perform the integrity check @return: the decrypted/decapsulated packet @raise IPSecIntegrityError: if the integrity check fails """ if not isinstance(pkt, self.SUPPORTED_PROTOS): raise TypeError('cannot decrypt %s, supported protos are %s' % (pkt.__class__, self.SUPPORTED_PROTOS)) if self.proto is ESP and pkt.haslayer(ESP): return self._decrypt_esp(pkt, verify=verify) elif self.proto is AH and pkt.haslayer(AH): return self._decrypt_ah(pkt, verify=verify) else: raise TypeError('%s has no %s layer' % (pkt, self.proto.name))
Example #6
Source File: ipsec.py From dash-hack with MIT License | 6 votes |
def decrypt(self, pkt, verify=True): """ Decrypt (and decapsulate) an IP(v6) packet containing ESP or AH. @param pkt: the packet to decrypt @param verify: if False, do not perform the integrity check @return: the decrypted/decapsulated packet @raise IPSecIntegrityError: if the integrity check fails """ if not isinstance(pkt, self.SUPPORTED_PROTOS): raise TypeError('cannot decrypt %s, supported protos are %s' % (pkt.__class__, self.SUPPORTED_PROTOS)) if self.proto is ESP and pkt.haslayer(ESP): return self._decrypt_esp(pkt, verify=verify) elif self.proto is AH and pkt.haslayer(AH): return self._decrypt_ah(pkt, verify=verify) else: raise TypeError('%s has no %s layer' % (pkt, self.proto.name))
Example #7
Source File: ipsec.py From smod-1 with GNU General Public License v2.0 | 5 votes |
def __init__(self, name, mac, digestmod, icv_size, key_size=None): """ @param name: the name of this integrity algorithm @param mac: a Message Authentication Code module @param digestmod: a Hash or Cipher module @param icv_size: the length of the integrity check value of this algo @param key_size: an integer or list/tuple of integers. If specified, force the secret keys length to one of the values. Defaults to the `key_size` of the cipher. """ self.name = name self.mac = mac self.digestmod = digestmod self.icv_size = icv_size self.key_size = key_size
Example #8
Source File: ipsec.py From arissploit with GNU General Public License v3.0 | 5 votes |
def __init__(self, name, mac, digestmod, icv_size, key_size=None): """ @param name: the name of this integrity algorithm @param mac: a Message Authentication Code module @param digestmod: a Hash or Cipher module @param icv_size: the length of the integrity check value of this algo @param key_size: an integer or list/tuple of integers. If specified, force the secret keys length to one of the values. Defaults to the `key_size` of the cipher. """ self.name = name self.mac = mac self.digestmod = digestmod self.icv_size = icv_size self.key_size = key_size
Example #9
Source File: ipsec.py From POC-EXP with GNU General Public License v3.0 | 5 votes |
def __init__(self, name, mac, digestmod, icv_size, key_size=None): """ @param name: the name of this integrity algorithm @param mac: a Message Authentication Code module @param digestmod: a Hash or Cipher module @param icv_size: the length of the integrity check value of this algo @param key_size: an integer or list/tuple of integers. If specified, force the secret keys length to one of the values. Defaults to the `key_size` of the cipher. """ self.name = name self.mac = mac self.digestmod = digestmod self.icv_size = icv_size self.key_size = key_size
Example #10
Source File: ipsec.py From POC-EXP with GNU General Public License v3.0 | 5 votes |
def __init__(self, name, cipher, mode, block_size=None, iv_size=None, key_size=None): """ @param name: the name of this encryption algorithm @param cipher: a Cipher module @param mode: the mode used with the cipher module @param block_size: the length a block for this algo. Defaults to the `block_size` of the cipher. @param iv_size: the length of the initialization vector of this algo. Defaults to the `block_size` of the cipher. @param key_size: an integer or list/tuple of integers. If specified, force the secret keys length to one of the values. Defaults to the `key_size` of the cipher. """ self.name = name self.cipher = cipher self.mode = mode if block_size is not None: self.block_size = block_size elif cipher is not None: self.block_size = cipher.block_size else: self.block_size = 1 if iv_size is None: self.iv_size = self.block_size else: self.iv_size = iv_size if key_size is not None: self.key_size = key_size elif cipher is not None: self.key_size = cipher.key_size else: self.key_size = None
Example #11
Source File: ipsec.py From dash-hack with MIT License | 5 votes |
def __init__(self, name, mac, digestmod, icv_size, key_size=None): """ @param name: the name of this integrity algorithm @param mac: a Message Authentication Code module @param digestmod: a Hash or Cipher module @param icv_size: the length of the integrity check value of this algo @param key_size: an integer or list/tuple of integers. If specified, force the secret keys length to one of the values. Defaults to the `key_size` of the cipher. """ self.name = name self.mac = mac self.digestmod = digestmod self.icv_size = icv_size self.key_size = key_size
Example #12
Source File: ipsec.py From dash-hack with MIT License | 5 votes |
def __init__(self, name, cipher, mode, block_size=None, iv_size=None, key_size=None): """ @param name: the name of this encryption algorithm @param cipher: a Cipher module @param mode: the mode used with the cipher module @param block_size: the length a block for this algo. Defaults to the `block_size` of the cipher. @param iv_size: the length of the initialization vector of this algo. Defaults to the `block_size` of the cipher. @param key_size: an integer or list/tuple of integers. If specified, force the secret keys length to one of the values. Defaults to the `key_size` of the cipher. """ self.name = name self.cipher = cipher self.mode = mode if block_size is not None: self.block_size = block_size elif cipher is not None: self.block_size = cipher.block_size else: self.block_size = 1 if iv_size is None: self.iv_size = self.block_size else: self.iv_size = iv_size if key_size is not None: self.key_size = key_size elif cipher is not None: self.key_size = cipher.key_size else: self.key_size = None
Example #13
Source File: ipsec.py From dash-hack with MIT License | 5 votes |
def __init__(self, name, cipher, mode, block_size=None, iv_size=None, key_size=None): """ @param name: the name of this encryption algorithm @param cipher: a Cipher module @param mode: the mode used with the cipher module @param block_size: the length a block for this algo. Defaults to the `block_size` of the cipher. @param iv_size: the length of the initialization vector of this algo. Defaults to the `block_size` of the cipher. @param key_size: an integer or list/tuple of integers. If specified, force the secret keys length to one of the values. Defaults to the `key_size` of the cipher. """ self.name = name self.cipher = cipher self.mode = mode if block_size is not None: self.block_size = block_size elif cipher is not None: self.block_size = cipher.block_size else: self.block_size = 1 if iv_size is None: self.iv_size = self.block_size else: self.iv_size = iv_size if key_size is not None: self.key_size = key_size elif cipher is not None: self.key_size = cipher.key_size else: self.key_size = None
Example #14
Source File: ipsec.py From dash-hack with MIT License | 5 votes |
def __init__(self, name, mac, digestmod, icv_size, key_size=None): """ @param name: the name of this integrity algorithm @param mac: a Message Authentication Code module @param digestmod: a Hash or Cipher module @param icv_size: the length of the integrity check value of this algo @param key_size: an integer or list/tuple of integers. If specified, force the secret keys length to one of the values. Defaults to the `key_size` of the cipher. """ self.name = name self.mac = mac self.digestmod = digestmod self.icv_size = icv_size self.key_size = key_size
Example #15
Source File: ipsec.py From dash-hack with MIT License | 5 votes |
def __init__(self, name, cipher, mode, block_size=None, iv_size=None, key_size=None): """ @param name: the name of this encryption algorithm @param cipher: a Cipher module @param mode: the mode used with the cipher module @param block_size: the length a block for this algo. Defaults to the `block_size` of the cipher. @param iv_size: the length of the initialization vector of this algo. Defaults to the `block_size` of the cipher. @param key_size: an integer or list/tuple of integers. If specified, force the secret keys length to one of the values. Defaults to the `key_size` of the cipher. """ self.name = name self.cipher = cipher self.mode = mode if block_size is not None: self.block_size = block_size elif cipher is not None: self.block_size = cipher.block_size else: self.block_size = 1 if iv_size is None: self.iv_size = self.block_size else: self.iv_size = iv_size if key_size is not None: self.key_size = key_size elif cipher is not None: self.key_size = cipher.key_size else: self.key_size = None
Example #16
Source File: ipsec.py From scapy with GNU General Public License v2.0 | 5 votes |
def __init__(self, name, mac, digestmod, icv_size, key_size=None): """ :param name: the name of this integrity algorithm :param mac: a Message Authentication Code module :param digestmod: a Hash or Cipher module :param icv_size: the length of the integrity check value of this algo :param key_size: an integer or list/tuple of integers. If specified, force the secret keys length to one of the values. Defaults to the `key_size` of the cipher. """ self.name = name self.mac = mac self.digestmod = digestmod self.icv_size = icv_size self.key_size = key_size
Example #17
Source File: ipsec.py From smod-1 with GNU General Public License v2.0 | 5 votes |
def __init__(self, name, cipher, mode, block_size=None, iv_size=None, key_size=None): """ @param name: the name of this encryption algorithm @param cipher: a Cipher module @param mode: the mode used with the cipher module @param block_size: the length a block for this algo. Defaults to the `block_size` of the cipher. @param iv_size: the length of the initialization vector of this algo. Defaults to the `block_size` of the cipher. @param key_size: an integer or list/tuple of integers. If specified, force the secret keys length to one of the values. Defaults to the `key_size` of the cipher. """ self.name = name self.cipher = cipher self.mode = mode if block_size is not None: self.block_size = block_size elif cipher is not None: self.block_size = cipher.block_size else: self.block_size = 1 if iv_size is None: self.iv_size = self.block_size else: self.iv_size = iv_size if key_size is not None: self.key_size = key_size elif cipher is not None: self.key_size = cipher.key_size else: self.key_size = None
Example #18
Source File: ipsec.py From dash-hack with MIT License | 4 votes |
def __init__(self, proto, spi, seq_num=1, crypt_algo=None, crypt_key=None, auth_algo=None, auth_key=None, tunnel_header=None, nat_t_header=None): """ @param proto: the IPSec proto to use (ESP or AH) @param spi: the Security Parameters Index of this SA @param seq_num: the initial value for the sequence number on encrypted packets @param crypt_algo: the encryption algorithm name (only used with ESP) @param crypt_key: the encryption key (only used with ESP) @param auth_algo: the integrity algorithm name @param auth_key: the integrity key @param tunnel_header: an instance of a IP(v6) header that will be used to encapsulate the encrypted packets. @param nat_t_header: an instance of a UDP header that will be used for NAT-Traversal. """ if proto not in (ESP, AH, ESP.name, AH.name): raise ValueError("proto must be either ESP or AH") if isinstance(proto, basestring): self.proto = eval(proto) else: self.proto = proto self.spi = spi self.seq_num = seq_num if crypt_algo: if crypt_algo not in CRYPT_ALGOS: raise TypeError('unsupported encryption algo %r, try %r' % (crypt_algo, CRYPT_ALGOS.keys())) self.crypt_algo = CRYPT_ALGOS[crypt_algo] self.crypt_algo.check_key(crypt_key) self.crypt_key = crypt_key else: self.crypt_algo = CRYPT_ALGOS['NULL'] self.crypt_key = None if auth_algo: if auth_algo not in AUTH_ALGOS: raise TypeError('unsupported integrity algo %r, try %r' % (auth_algo, AUTH_ALGOS.keys())) self.auth_algo = AUTH_ALGOS[auth_algo] self.auth_algo.check_key(auth_key) self.auth_key = auth_key else: self.auth_algo = AUTH_ALGOS['NULL'] self.auth_key = None if tunnel_header and not isinstance(tunnel_header, (IP, IPv6)): raise TypeError('tunnel_header must be %s or %s' % (IP.name, IPv6.name)) self.tunnel_header = tunnel_header if nat_t_header: if proto is not ESP: raise TypeError('nat_t_header is only allowed with ESP') if not isinstance(nat_t_header, UDP): raise TypeError('nat_t_header must be %s' % UDP.name) self.nat_t_header = nat_t_header
Example #19
Source File: ipsec.py From dash-hack with MIT License | 4 votes |
def __init__(self, proto, spi, seq_num=1, crypt_algo=None, crypt_key=None, auth_algo=None, auth_key=None, tunnel_header=None, nat_t_header=None): """ @param proto: the IPSec proto to use (ESP or AH) @param spi: the Security Parameters Index of this SA @param seq_num: the initial value for the sequence number on encrypted packets @param crypt_algo: the encryption algorithm name (only used with ESP) @param crypt_key: the encryption key (only used with ESP) @param auth_algo: the integrity algorithm name @param auth_key: the integrity key @param tunnel_header: an instance of a IP(v6) header that will be used to encapsulate the encrypted packets. @param nat_t_header: an instance of a UDP header that will be used for NAT-Traversal. """ if proto not in (ESP, AH, ESP.name, AH.name): raise ValueError("proto must be either ESP or AH") if isinstance(proto, basestring): self.proto = eval(proto) else: self.proto = proto self.spi = spi self.seq_num = seq_num if crypt_algo: if crypt_algo not in CRYPT_ALGOS: raise TypeError('unsupported encryption algo %r, try %r' % (crypt_algo, CRYPT_ALGOS.keys())) self.crypt_algo = CRYPT_ALGOS[crypt_algo] self.crypt_algo.check_key(crypt_key) self.crypt_key = crypt_key else: self.crypt_algo = CRYPT_ALGOS['NULL'] self.crypt_key = None if auth_algo: if auth_algo not in AUTH_ALGOS: raise TypeError('unsupported integrity algo %r, try %r' % (auth_algo, AUTH_ALGOS.keys())) self.auth_algo = AUTH_ALGOS[auth_algo] self.auth_algo.check_key(auth_key) self.auth_key = auth_key else: self.auth_algo = AUTH_ALGOS['NULL'] self.auth_key = None if tunnel_header and not isinstance(tunnel_header, (IP, IPv6)): raise TypeError('tunnel_header must be %s or %s' % (IP.name, IPv6.name)) self.tunnel_header = tunnel_header if nat_t_header: if proto is not ESP: raise TypeError('nat_t_header is only allowed with ESP') if not isinstance(nat_t_header, UDP): raise TypeError('nat_t_header must be %s' % UDP.name) self.nat_t_header = nat_t_header
Example #20
Source File: ipsec.py From dash-hack with MIT License | 4 votes |
def __init__(self, proto, spi, seq_num=1, crypt_algo=None, crypt_key=None, auth_algo=None, auth_key=None, tunnel_header=None, nat_t_header=None): """ @param proto: the IPSec proto to use (ESP or AH) @param spi: the Security Parameters Index of this SA @param seq_num: the initial value for the sequence number on encrypted packets @param crypt_algo: the encryption algorithm name (only used with ESP) @param crypt_key: the encryption key (only used with ESP) @param auth_algo: the integrity algorithm name @param auth_key: the integrity key @param tunnel_header: an instance of a IP(v6) header that will be used to encapsulate the encrypted packets. @param nat_t_header: an instance of a UDP header that will be used for NAT-Traversal. """ if proto not in (ESP, AH, ESP.name, AH.name): raise ValueError("proto must be either ESP or AH") if isinstance(proto, basestring): self.proto = eval(proto) else: self.proto = proto self.spi = spi self.seq_num = seq_num if crypt_algo: if crypt_algo not in CRYPT_ALGOS: raise TypeError('unsupported encryption algo %r, try %r' % (crypt_algo, CRYPT_ALGOS.keys())) self.crypt_algo = CRYPT_ALGOS[crypt_algo] self.crypt_algo.check_key(crypt_key) self.crypt_key = crypt_key else: self.crypt_algo = CRYPT_ALGOS['NULL'] self.crypt_key = None if auth_algo: if auth_algo not in AUTH_ALGOS: raise TypeError('unsupported integrity algo %r, try %r' % (auth_algo, AUTH_ALGOS.keys())) self.auth_algo = AUTH_ALGOS[auth_algo] self.auth_algo.check_key(auth_key) self.auth_key = auth_key else: self.auth_algo = AUTH_ALGOS['NULL'] self.auth_key = None if tunnel_header and not isinstance(tunnel_header, (IP, IPv6)): raise TypeError('tunnel_header must be %s or %s' % (IP.name, IPv6.name)) self.tunnel_header = tunnel_header if nat_t_header: if proto is not ESP: raise TypeError('nat_t_header is only allowed with ESP') if not isinstance(nat_t_header, UDP): raise TypeError('nat_t_header must be %s' % UDP.name) self.nat_t_header = nat_t_header
Example #21
Source File: ipsec.py From POC-EXP with GNU General Public License v3.0 | 4 votes |
def __init__(self, proto, spi, seq_num=1, crypt_algo=None, crypt_key=None, auth_algo=None, auth_key=None, tunnel_header=None, nat_t_header=None): """ @param proto: the IPSec proto to use (ESP or AH) @param spi: the Security Parameters Index of this SA @param seq_num: the initial value for the sequence number on encrypted packets @param crypt_algo: the encryption algorithm name (only used with ESP) @param crypt_key: the encryption key (only used with ESP) @param auth_algo: the integrity algorithm name @param auth_key: the integrity key @param tunnel_header: an instance of a IP(v6) header that will be used to encapsulate the encrypted packets. @param nat_t_header: an instance of a UDP header that will be used for NAT-Traversal. """ if proto not in (ESP, AH, ESP.name, AH.name): raise ValueError("proto must be either ESP or AH") if isinstance(proto, basestring): self.proto = eval(proto) else: self.proto = proto self.spi = spi self.seq_num = seq_num if crypt_algo: if crypt_algo not in CRYPT_ALGOS: raise TypeError('unsupported encryption algo %r, try %r' % (crypt_algo, CRYPT_ALGOS.keys())) self.crypt_algo = CRYPT_ALGOS[crypt_algo] self.crypt_algo.check_key(crypt_key) self.crypt_key = crypt_key else: self.crypt_algo = CRYPT_ALGOS['NULL'] self.crypt_key = None if auth_algo: if auth_algo not in AUTH_ALGOS: raise TypeError('unsupported integrity algo %r, try %r' % (auth_algo, AUTH_ALGOS.keys())) self.auth_algo = AUTH_ALGOS[auth_algo] self.auth_algo.check_key(auth_key) self.auth_key = auth_key else: self.auth_algo = AUTH_ALGOS['NULL'] self.auth_key = None if tunnel_header and not isinstance(tunnel_header, (IP, IPv6)): raise TypeError('tunnel_header must be %s or %s' % (IP.name, IPv6.name)) self.tunnel_header = tunnel_header if nat_t_header: if proto is not ESP: raise TypeError('nat_t_header is only allowed with ESP') if not isinstance(nat_t_header, UDP): raise TypeError('nat_t_header must be %s' % UDP.name) self.nat_t_header = nat_t_header
Example #22
Source File: ipsec.py From scapy with GNU General Public License v2.0 | 4 votes |
def __init__(self, name, cipher, mode, block_size=None, iv_size=None, key_size=None, icv_size=None, salt_size=None, format_mode_iv=None): # noqa: E501 """ :param name: the name of this encryption algorithm :param cipher: a Cipher module :param mode: the mode used with the cipher module :param block_size: the length a block for this algo. Defaults to the `block_size` of the cipher. :param iv_size: the length of the initialization vector of this algo. Defaults to the `block_size` of the cipher. :param key_size: an integer or list/tuple of integers. If specified, force the secret keys length to one of the values. Defaults to the `key_size` of the cipher. :param icv_size: the length of the Integrity Check Value of this algo. Used by Combined Mode Algorithms e.g. GCM :param salt_size: the length of the salt to use as the IV prefix. Usually used by Counter modes e.g. CTR :param format_mode_iv: function to format the Initialization Vector e.g. handle the salt value Default is the random buffer from `generate_iv` """ self.name = name self.cipher = cipher self.mode = mode self.icv_size = icv_size if modes and self.mode is not None: self.is_aead = issubclass(self.mode, modes.ModeWithAuthenticationTag) else: self.is_aead = False if block_size is not None: self.block_size = block_size elif cipher is not None: self.block_size = cipher.block_size // 8 else: self.block_size = 1 if iv_size is None: self.iv_size = self.block_size else: self.iv_size = iv_size if key_size is not None: self.key_size = key_size elif cipher is not None: self.key_size = tuple(i // 8 for i in cipher.key_sizes) else: self.key_size = None if salt_size is None: self.salt_size = 0 else: self.salt_size = salt_size if format_mode_iv is None: self._format_mode_iv = lambda iv, **kw: iv else: self._format_mode_iv = format_mode_iv
Example #23
Source File: ipsec.py From arissploit with GNU General Public License v3.0 | 4 votes |
def __init__(self, name, cipher, mode, block_size=None, iv_size=None, key_size=None, icv_size=None, salt_size=None): """ @param name: the name of this encryption algorithm @param cipher: a Cipher module @param mode: the mode used with the cipher module @param block_size: the length a block for this algo. Defaults to the `block_size` of the cipher. @param iv_size: the length of the initialization vector of this algo. Defaults to the `block_size` of the cipher. @param key_size: an integer or list/tuple of integers. If specified, force the secret keys length to one of the values. Defaults to the `key_size` of the cipher. @param icv_size: the length of the Integrity Check Value of this algo. Used by Combined Mode Algorithms, e.g. GCM @param salt_size: the length of the salt to use as the IV prefix. Usually used by Counter modes e.g. CTR """ self.name = name self.cipher = cipher self.mode = mode self.icv_size = icv_size if self.mode is not None: self.is_aead = issubclass(self.mode, modes.ModeWithAuthenticationTag) else: self.is_aead = False if block_size is not None: self.block_size = block_size elif cipher is not None: self.block_size = cipher.block_size // 8 else: self.block_size = 1 if iv_size is None: self.iv_size = self.block_size else: self.iv_size = iv_size if key_size is not None: self.key_size = key_size elif cipher is not None: self.key_size = tuple(i // 8 for i in cipher.key_sizes) else: self.key_size = None if salt_size is None: self.salt_size = 0 else: self.salt_size = salt_size
Example #24
Source File: ipsec.py From smod-1 with GNU General Public License v2.0 | 4 votes |
def __init__(self, proto, spi, seq_num=1, crypt_algo=None, crypt_key=None, auth_algo=None, auth_key=None, tunnel_header=None, nat_t_header=None): """ @param proto: the IPSec proto to use (ESP or AH) @param spi: the Security Parameters Index of this SA @param seq_num: the initial value for the sequence number on encrypted packets @param crypt_algo: the encryption algorithm name (only used with ESP) @param crypt_key: the encryption key (only used with ESP) @param auth_algo: the integrity algorithm name @param auth_key: the integrity key @param tunnel_header: an instance of a IP(v6) header that will be used to encapsulate the encrypted packets. @param nat_t_header: an instance of a UDP header that will be used for NAT-Traversal. """ if proto not in (ESP, AH, ESP.name, AH.name): raise ValueError("proto must be either ESP or AH") if isinstance(proto, basestring): self.proto = eval(proto) else: self.proto = proto self.spi = spi self.seq_num = seq_num if crypt_algo: if crypt_algo not in CRYPT_ALGOS: raise TypeError('unsupported encryption algo %r, try %r' % (crypt_algo, CRYPT_ALGOS.keys())) self.crypt_algo = CRYPT_ALGOS[crypt_algo] self.crypt_algo.check_key(crypt_key) self.crypt_key = crypt_key else: self.crypt_algo = CRYPT_ALGOS['NULL'] self.crypt_key = None if auth_algo: if auth_algo not in AUTH_ALGOS: raise TypeError('unsupported integrity algo %r, try %r' % (auth_algo, AUTH_ALGOS.keys())) self.auth_algo = AUTH_ALGOS[auth_algo] self.auth_algo.check_key(auth_key) self.auth_key = auth_key else: self.auth_algo = AUTH_ALGOS['NULL'] self.auth_key = None if tunnel_header and not isinstance(tunnel_header, (IP, IPv6)): raise TypeError('tunnel_header must be %s or %s' % (IP.name, IPv6.name)) self.tunnel_header = tunnel_header if nat_t_header: if proto is not ESP: raise TypeError('nat_t_header is only allowed with ESP') if not isinstance(nat_t_header, UDP): raise TypeError('nat_t_header must be %s' % UDP.name) self.nat_t_header = nat_t_header