(self)
| 7083 | @unittest.expectedFailure # TODO: RUSTPYTHON; - AF_ALG not fully implemented |
| 7084 | @support.requires_linux_version(4, 9) # see gh-73510 |
| 7085 | def test_aead_aes_gcm(self): |
| 7086 | kernel_version = support._get_kernel_version("Linux") |
| 7087 | if kernel_version is not None: |
| 7088 | if kernel_version >= (6, 16) and kernel_version < (6, 18): |
| 7089 | # See https://github.com/python/cpython/issues/139310. |
| 7090 | self.skipTest("upstream Linux kernel issue") |
| 7091 | |
| 7092 | key = bytes.fromhex('c939cc13397c1d37de6ae0e1cb7c423c') |
| 7093 | iv = bytes.fromhex('b3d8cc017cbb89b39e0f67e2') |
| 7094 | plain = bytes.fromhex('c3b3c41f113a31b73d9a5cd432103069') |
| 7095 | assoc = bytes.fromhex('24825602bd12a984e0092d3e448eda5f') |
| 7096 | expected_ct = bytes.fromhex('93fe7d9e9bfd10348a5606e5cafa7354') |
| 7097 | expected_tag = bytes.fromhex('0032a1dc85f1c9786925a2e71d8272dd') |
| 7098 | |
| 7099 | taglen = len(expected_tag) |
| 7100 | assoclen = len(assoc) |
| 7101 | |
| 7102 | with self.create_alg('aead', 'gcm(aes)') as algo: |
| 7103 | algo.setsockopt(socket.SOL_ALG, socket.ALG_SET_KEY, key) |
| 7104 | algo.setsockopt(socket.SOL_ALG, socket.ALG_SET_AEAD_AUTHSIZE, |
| 7105 | None, taglen) |
| 7106 | |
| 7107 | # send assoc, plain and tag buffer in separate steps |
| 7108 | op, _ = algo.accept() |
| 7109 | with op: |
| 7110 | op.sendmsg_afalg(op=socket.ALG_OP_ENCRYPT, iv=iv, |
| 7111 | assoclen=assoclen, flags=socket.MSG_MORE) |
| 7112 | op.sendall(assoc, socket.MSG_MORE) |
| 7113 | op.sendall(plain) |
| 7114 | res = op.recv(assoclen + len(plain) + taglen) |
| 7115 | self.assertEqual(expected_ct, res[assoclen:-taglen]) |
| 7116 | self.assertEqual(expected_tag, res[-taglen:]) |
| 7117 | |
| 7118 | # now with msg |
| 7119 | op, _ = algo.accept() |
| 7120 | with op: |
| 7121 | msg = assoc + plain |
| 7122 | op.sendmsg_afalg([msg], op=socket.ALG_OP_ENCRYPT, iv=iv, |
| 7123 | assoclen=assoclen) |
| 7124 | res = op.recv(assoclen + len(plain) + taglen) |
| 7125 | self.assertEqual(expected_ct, res[assoclen:-taglen]) |
| 7126 | self.assertEqual(expected_tag, res[-taglen:]) |
| 7127 | |
| 7128 | # create anc data manually |
| 7129 | pack_uint32 = struct.Struct('I').pack |
| 7130 | op, _ = algo.accept() |
| 7131 | with op: |
| 7132 | msg = assoc + plain |
| 7133 | op.sendmsg( |
| 7134 | [msg], |
| 7135 | ([socket.SOL_ALG, socket.ALG_SET_OP, pack_uint32(socket.ALG_OP_ENCRYPT)], |
| 7136 | [socket.SOL_ALG, socket.ALG_SET_IV, pack_uint32(len(iv)) + iv], |
| 7137 | [socket.SOL_ALG, socket.ALG_SET_AEAD_ASSOCLEN, pack_uint32(assoclen)], |
| 7138 | ) |
| 7139 | ) |
| 7140 | res = op.recv(len(msg) + taglen) |
| 7141 | self.assertEqual(expected_ct, res[assoclen:-taglen]) |
| 7142 | self.assertEqual(expected_tag, res[-taglen:]) |
nothing calls this directly
no test coverage detected