(self)
| 7133 | # Ubuntu 15.10 with Kernel 4.2.0-19. |
| 7134 | @support.requires_linux_version(4, 3) |
| 7135 | def test_aes_cbc(self): |
| 7136 | key = bytes.fromhex('06a9214036b8a15b512e03d534120006') |
| 7137 | iv = bytes.fromhex('3dafba429d9eb430b422da802c9fac41') |
| 7138 | msg = b"Single block msg" |
| 7139 | ciphertext = bytes.fromhex('e353779c1079aeb82708942dbe77181a') |
| 7140 | msglen = len(msg) |
| 7141 | with self.create_alg('skcipher', 'cbc(aes)') as algo: |
| 7142 | algo.setsockopt(socket.SOL_ALG, socket.ALG_SET_KEY, key) |
| 7143 | op, _ = algo.accept() |
| 7144 | with op: |
| 7145 | op.sendmsg_afalg(op=socket.ALG_OP_ENCRYPT, iv=iv, |
| 7146 | flags=socket.MSG_MORE) |
| 7147 | op.sendall(msg) |
| 7148 | self.assertEqual(op.recv(msglen), ciphertext) |
| 7149 | |
| 7150 | op, _ = algo.accept() |
| 7151 | with op: |
| 7152 | op.sendmsg_afalg([ciphertext], |
| 7153 | op=socket.ALG_OP_DECRYPT, iv=iv) |
| 7154 | self.assertEqual(op.recv(msglen), msg) |
| 7155 | |
| 7156 | # long message |
| 7157 | multiplier = 1024 |
| 7158 | longmsg = [msg] * multiplier |
| 7159 | op, _ = algo.accept() |
| 7160 | with op: |
| 7161 | op.sendmsg_afalg(longmsg, |
| 7162 | op=socket.ALG_OP_ENCRYPT, iv=iv) |
| 7163 | enc = op.recv(msglen * multiplier) |
| 7164 | self.assertEqual(len(enc), msglen * multiplier) |
| 7165 | self.assertEqual(enc[:msglen], ciphertext) |
| 7166 | |
| 7167 | op, _ = algo.accept() |
| 7168 | with op: |
| 7169 | op.sendmsg_afalg([enc], |
| 7170 | op=socket.ALG_OP_DECRYPT, iv=iv) |
| 7171 | dec = op.recv(msglen * multiplier) |
| 7172 | self.assertEqual(len(dec), msglen * multiplier) |
| 7173 | self.assertEqual(dec, msg * multiplier) |
| 7174 | |
| 7175 | @support.requires_linux_version(4, 9) # see gh-73510 |
| 7176 | def test_aead_aes_gcm(self): |
nothing calls this directly
no test coverage detected