Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup(self):
self.cipher = AES.new(self.key, AES.MODE_CFB, iv=self.iv, segment_size=128)
class AES128CFBCipher(AES256CFBCipher):
KEY_LENGTH = 16
class AES192CFBCipher(AES256CFBCipher):
KEY_LENGTH = 24
class BFCFBCipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 8
def setup(self):
self.cipher = Blowfish.new(self.key, Blowfish.MODE_CFB, iv=self.iv, segment_size=64)
class CAST5CFBCipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 8
def setup(self):
self.cipher = CAST.new(self.key, CAST.MODE_CFB, iv=self.iv, segment_size=64)
class DESCFBCipher(BaseCipher):
KEY_LENGTH = 8
IV_LENGTH = 8
def setup(self):
self.cipher = DES.new(self.key, DES.MODE_CFB, iv=self.iv, segment_size=64)
MAPPINGS = {\
'table': TableCipher,
'rc4': RC4Cipher,
'rc4-md5': RC4MD5Cipher,
'chacha20': ChaCha20Cipher,
def setup(self):
self.cipher = ARC4.new(hashlib.md5(self.key + self.iv).digest())
class ChaCha20Cipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 8
def setup(self):
self.cipher = ChaCha20.new(key=self.key, nonce=self.iv)
class Salsa20Cipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 8
def setup(self):
self.cipher = Salsa20.new(key=self.key, nonce=self.iv)
class AES256CFBCipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 16
def setup(self):
self.cipher = AES.new(self.key, AES.MODE_CFB, iv=self.iv, segment_size=128)
class AES128CFBCipher(AES256CFBCipher):
KEY_LENGTH = 16
class AES192CFBCipher(AES256CFBCipher):
KEY_LENGTH = 24
class BFCFBCipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 8
def setup(self):
self.cipher = Blowfish.new(self.key, Blowfish.MODE_CFB, iv=self.iv, segment_size=64)
def setup(self):
self.cipher = ARC4.new(self.key)
class RC4MD5Cipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 16
def setup(self):
self.cipher = ARC4.new(hashlib.md5(self.key + self.iv).digest())
class ChaCha20Cipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 8
def setup(self):
self.cipher = ChaCha20.new(key=self.key, nonce=self.iv)
class Salsa20Cipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 8
def setup(self):
self.cipher = Salsa20.new(key=self.key, nonce=self.iv)
class AES256CFBCipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 16
def setup(self):
self.cipher = AES.new(self.key, AES.MODE_CFB, iv=self.iv, segment_size=128)
class AES128CFBCipher(AES256CFBCipher):
KEY_LENGTH = 16
class AES192CFBCipher(AES256CFBCipher):
KEY_LENGTH = 24
table.sort(key = lambda x: a % (x + i))
self.encrypt_table = bytes(table)
self.decrypt_table = bytes.maketrans(self.encrypt_table, bytes(range(256)))
self.CACHE[self.key] = self.encrypt_table, self.decrypt_table
def decrypt(self, s):
return bytes.translate(s, self.decrypt_table)
def encrypt(self, s):
return bytes.translate(s, self.encrypt_table)
class RC4Cipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 0
def setup(self):
self.cipher = ARC4.new(self.key)
class RC4MD5Cipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 16
def setup(self):
self.cipher = ARC4.new(hashlib.md5(self.key + self.iv).digest())
class ChaCha20Cipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 8
def setup(self):
self.cipher = ChaCha20.new(key=self.key, nonce=self.iv)
class Salsa20Cipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 8
def setup(self):
self.cipher = Salsa20.new(key=self.key, nonce=self.iv)
assert checksum_server[:10] == checksum
chunk_id += 1
return data
reader.read_ = patched_read
def patch_ota_writer(self, writer):
chunk_id = 0
write = writer.write
def patched_write(data):
nonlocal chunk_id
if not data: return
checksum = hmac.new(self.iv+chunk_id.to_bytes(4, 'big'), data, 'sha1').digest()
chunk_id += 1
return write(len(data).to_bytes(2, 'big') + checksum[:10] + data)
writer.write = patched_write
class TableCipher(BaseCipher):
KEY_LENGTH = 0
IV_LENGTH = 0
def setup(self):
if self.key in self.CACHE:
self.encrypt_table, self.decrypt_table = self.CACHE[self.key]
else:
a, _ = struct.unpack('
def encrypt(self, s):
return bytes.translate(s, self.encrypt_table)
class RC4Cipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 0
def setup(self):
self.cipher = ARC4.new(self.key)
class RC4MD5Cipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 16
def setup(self):
self.cipher = ARC4.new(hashlib.md5(self.key + self.iv).digest())
class ChaCha20Cipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 8
def setup(self):
self.cipher = ChaCha20.new(key=self.key, nonce=self.iv)
class Salsa20Cipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 8
def setup(self):
self.cipher = Salsa20.new(key=self.key, nonce=self.iv)
class AES256CFBCipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 16
def setup(self):
self.cipher = AES.new(self.key, AES.MODE_CFB, iv=self.iv, segment_size=128)
if self.key in self.CACHE:
self.encrypt_table, self.decrypt_table = self.CACHE[self.key]
else:
a, _ = struct.unpack('
class AES192CFBCipher(AES256CFBCipher):
KEY_LENGTH = 24
class BFCFBCipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 8
def setup(self):
self.cipher = Blowfish.new(self.key, Blowfish.MODE_CFB, iv=self.iv, segment_size=64)
class CAST5CFBCipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 8
def setup(self):
self.cipher = CAST.new(self.key, CAST.MODE_CFB, iv=self.iv, segment_size=64)
class DESCFBCipher(BaseCipher):
KEY_LENGTH = 8
IV_LENGTH = 8
def setup(self):
self.cipher = DES.new(self.key, DES.MODE_CFB, iv=self.iv, segment_size=64)
MAPPINGS = {\
'table': TableCipher,
'rc4': RC4Cipher,
'rc4-md5': RC4MD5Cipher,
'chacha20': ChaCha20Cipher,
'salsa20': Salsa20Cipher,
'aes-128-cfb': AES128CFBCipher,
'aes-192-cfb': AES192CFBCipher,
'aes-256-cfb': AES256CFBCipher,
'bf-cfb': BFCFBCipher,
'cast5-cfb': CAST5CFBCipher,
def setup(self):
self.cipher = Salsa20.new(key=self.key, nonce=self.iv)
class AES256CFBCipher(BaseCipher):
KEY_LENGTH = 32
IV_LENGTH = 16
def setup(self):
self.cipher = AES.new(self.key, AES.MODE_CFB, iv=self.iv, segment_size=128)
class AES128CFBCipher(AES256CFBCipher):
KEY_LENGTH = 16
class AES192CFBCipher(AES256CFBCipher):
KEY_LENGTH = 24
class BFCFBCipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 8
def setup(self):
self.cipher = Blowfish.new(self.key, Blowfish.MODE_CFB, iv=self.iv, segment_size=64)
class CAST5CFBCipher(BaseCipher):
KEY_LENGTH = 16
IV_LENGTH = 8
def setup(self):
self.cipher = CAST.new(self.key, CAST.MODE_CFB, iv=self.iv, segment_size=64)
class DESCFBCipher(BaseCipher):
KEY_LENGTH = 8
IV_LENGTH = 8
def setup(self):
self.cipher = DES.new(self.key, DES.MODE_CFB, iv=self.iv, segment_size=64)