def __init__(self,
              aes_properties: bytes,
              password: str,
              blocksize: Optional[int] = None) -> None:
     firstbyte = aes_properties[0]
     numcyclespower = firstbyte & 0x3F
     if firstbyte & 0xC0 != 0:
         saltsize = (firstbyte >> 7) & 1
         ivsize = (firstbyte >> 6) & 1
         secondbyte = aes_properties[1]
         saltsize += secondbyte >> 4
         ivsize += secondbyte & 0x0F
         assert len(aes_properties) == 2 + saltsize + ivsize
         salt = aes_properties[2:2 + saltsize]
         iv = aes_properties[2 + saltsize:2 + saltsize + ivsize]
         assert len(salt) == saltsize
         assert len(iv) == ivsize
         assert numcyclespower <= 24
         if ivsize < 16:
             iv += bytes("\x00" * (16 - ivsize), "ascii")
         key = calculate_key(password.encode("utf-16LE"), numcyclespower,
                             salt, "sha256")
         self.cipher = AES.new(key, AES.MODE_CBC, iv)
         if blocksize:
             self.buf = Buffer(size=blocksize + 16)
         else:
             self.buf = Buffer(size=get_default_blocksize() + 16)
     else:
         raise UnsupportedCompressionMethodError
Beispiel #2
0
 def __init__(self, aes_properties: bytes, password: str,
              coders: List[Dict[str, Any]]) -> None:
     byte_password = password.encode('utf-16LE')
     firstbyte = aes_properties[0]
     numcyclespower = firstbyte & 0x3f
     if firstbyte & 0xc0 != 0:
         saltsize = (firstbyte >> 7) & 1
         ivsize = (firstbyte >> 6) & 1
         secondbyte = aes_properties[1]
         saltsize += (secondbyte >> 4)
         ivsize += (secondbyte & 0x0f)
         assert len(aes_properties) == 2 + saltsize + ivsize
         salt = aes_properties[2:2 + saltsize]
         iv = aes_properties[2 + saltsize:2 + saltsize + ivsize]
         assert len(salt) == saltsize
         assert len(iv) == ivsize
         assert numcyclespower <= 24
         if ivsize < 16:
             iv += bytes('\x00' * (16 - ivsize), 'ascii')
         key = calculate_key(byte_password, numcyclespower, salt, 'sha256')
         self.lzma_decompressor = self._set_lzma_decompressor(coders)
         self.cipher = AES.new(key, AES.MODE_CBC, iv)
         self.buf = b''
         self.flushed = False
     else:
         raise UnsupportedCompressionMethodError
Beispiel #3
0
 def __init__(self, password: str) -> None:
     self.cycles = 19  # FIXME
     self.iv = get_random_bytes(16)
     self.salt = b''
     self.method = CompressionMethod.CRYPT_AES256_SHA256
     key = calculate_key(password.encode('utf-16LE'), self.cycles, self.salt, 'sha256')
     self.iv += bytes(self.AES_CBC_BLOCKSIZE - len(self.iv))  # zero padding if iv < AES_CBC_BLOCKSIZE
     self.cipher = AES.new(key, AES.MODE_CBC, self.iv)
     self.flushed = False
     self.buf = Buffer(size=READ_BLOCKSIZE + self.AES_CBC_BLOCKSIZE * 2)
 def __init__(self, password: str, blocksize: Optional[int] = None) -> None:
     self.cycles = 19  # as same as p7zip
     self.iv = get_random_bytes(16)
     self.salt = b""
     self.method = CompressionMethod.CRYPT_AES256_SHA256
     key = calculate_key(password.encode("utf-16LE"), self.cycles,
                         self.salt, "sha256")
     self.iv += bytes(
         self.AES_CBC_BLOCKSIZE -
         len(self.iv))  # zero padding if iv < AES_CBC_BLOCKSIZE
     self.cipher = AES.new(key, AES.MODE_CBC, self.iv)
     self.flushed = False
     if blocksize:
         self.buf = Buffer(size=blocksize + self.AES_CBC_BLOCKSIZE * 2)
     else:
         self.buf = Buffer(size=get_default_blocksize() +
                           self.AES_CBC_BLOCKSIZE * 2)
Beispiel #5
0
 def __init__(self, aes_properties: bytes, password: str) -> None:
     firstbyte = aes_properties[0]
     numcyclespower = firstbyte & 0x3f
     if firstbyte & 0xc0 != 0:
         saltsize = (firstbyte >> 7) & 1
         ivsize = (firstbyte >> 6) & 1
         secondbyte = aes_properties[1]
         saltsize += (secondbyte >> 4)
         ivsize += (secondbyte & 0x0f)
         assert len(aes_properties) == 2 + saltsize + ivsize
         salt = aes_properties[2:2 + saltsize]
         iv = aes_properties[2 + saltsize:2 + saltsize + ivsize]
         assert len(salt) == saltsize
         assert len(iv) == ivsize
         assert numcyclespower <= 24
         if ivsize < 16:
             iv += bytes('\x00' * (16 - ivsize), 'ascii')
         key = calculate_key(password.encode('utf-16LE'), numcyclespower, salt, 'sha256')
         self.cipher = AES.new(key, AES.MODE_CBC, iv)
         self.buf = Buffer(size=READ_BLOCKSIZE + 16)
     else:
         raise UnsupportedCompressionMethodError