Encrypt a PSP packet :param key: the secret key used for encryption :raise scapy.layers.psp.PSPCipherError: if the requested cipher is unsupported
(self, key)
| 111 | return aead.AESGCM |
| 112 | |
| 113 | def encrypt(self, key): |
| 114 | """ |
| 115 | Encrypt a PSP packet |
| 116 | |
| 117 | :param key: the secret key used for encryption |
| 118 | :raise scapy.layers.psp.PSPCipherError: if the requested cipher |
| 119 | is unsupported |
| 120 | """ |
| 121 | cipher = self.sanitize_cipher() |
| 122 | encrypt_start_offset = 16 + self.cryptoffset * 4 |
| 123 | iv = struct.pack("!L", self.spi) + self.iv |
| 124 | plain = b'' |
| 125 | to_encrypt = bytes(self.data) |
| 126 | self.data = b'' |
| 127 | psp_header = bytes(self) |
| 128 | header_length = len(psp_header) |
| 129 | # Header should always be fully plaintext |
| 130 | if header_length < encrypt_start_offset: |
| 131 | plain = to_encrypt[:encrypt_start_offset - header_length] |
| 132 | to_encrypt = to_encrypt[encrypt_start_offset - header_length:] |
| 133 | cipher = cipher(key) |
| 134 | payload = cipher.encrypt(iv, to_encrypt, psp_header + plain) |
| 135 | self.data = plain + payload |
| 136 | |
| 137 | def decrypt(self, key): |
| 138 | """ |
no test coverage detected