Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions scapy/layers/ipsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,17 @@ def data_for_encryption(self):
)
except ImportError:
decrepit_algorithms = algorithms

# cryptography's TripleDES can be used to simulate DES behavior
DES = lambda key: decrepit_algorithms.TripleDES(key * 3)
DES.key_sizes = decrepit_algorithms.TripleDES.key_sizes
DES.block_size = decrepit_algorithms.TripleDES.block_size
else:
log_loading.info("Can't import python-cryptography v1.7+. "
"Disabled IPsec encryption/authentication.")
default_backend = None
InvalidTag = Exception
Cipher = algorithms = modes = None
Cipher = algorithms = modes = DES = None

###############################################################################

Expand Down Expand Up @@ -573,9 +578,9 @@ def decrypt(self, sa, esp, key, icv_size=None, esn_en=False, esn=0):
format_mode_iv=_salt_format_mode_iv) # noqa: E501

# Using a TripleDES cipher algorithm for DES is done by using the same 64
# bits key 3 times (done by cryptography when given a 64 bits key)
# bits key 3 times
CRYPT_ALGOS['DES'] = CryptAlgo('DES',
cipher=decrepit_algorithms.TripleDES,
cipher=DES,
mode=modes.CBC,
key_size=(8,))
CRYPT_ALGOS['3DES'] = CryptAlgo('3DES',
Expand Down
15 changes: 12 additions & 3 deletions scapy/layers/tls/crypto/cipher_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
except ImportError:
decrepit_algorithms = algorithms

# cryptography's TripleDES can be used to simulate DES behavior
DES = lambda key: decrepit_algorithms.TripleDES(key * 3)

try:
# cryptography > 47.0
Camellia = decrepit_algorithms.Camellia
except AttributeError:
Camellia = algorithms.Camellia


_tls_block_cipher_algs = {}

Expand Down Expand Up @@ -134,7 +143,7 @@ class Cipher_AES_256_CBC(Cipher_AES_128_CBC):
key_len = 32

class Cipher_CAMELLIA_128_CBC(_BlockCipher):
pc_cls = algorithms.Camellia
pc_cls = Camellia
pc_cls_mode = modes.CBC
block_size = 16
key_len = 16
Expand All @@ -149,13 +158,13 @@ class Cipher_CAMELLIA_256_CBC(Cipher_CAMELLIA_128_CBC):

if conf.crypto_valid:
class Cipher_DES_ECB(_BlockCipher):
pc_cls = decrepit_algorithms.TripleDES
pc_cls = staticmethod(DES)
pc_cls_mode = modes.ECB
block_size = 8
key_len = 8

class Cipher_DES_CBC(_BlockCipher):
pc_cls = decrepit_algorithms.TripleDES
pc_cls = staticmethod(DES)
pc_cls_mode = modes.CBC
block_size = 8
key_len = 8
Expand Down
5 changes: 3 additions & 2 deletions scapy/libs/rfc3961.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@
raise ImportError("To use kerberos cryptography, you need to install cryptography.")


# cryptography's TripleDES allow the usage of a 56bit key, which thus behaves like DES
DES = decrepit_algorithms.TripleDES
# cryptography's TripleDES can be used to simulate DES behavior
def DES(key: bytes) -> decrepit_algorithms.TripleDES:
return decrepit_algorithms.TripleDES(key * 3)


# https://go.microsoft.com/fwlink/?LinkId=186039
Expand Down
Loading