From 3f9d9050df0c7d54d56513c4a801df2e3c52278f Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 16 Sep 2020 14:22:21 +0200 Subject: [PATCH] Add AEAD overhead --- tests/quic/helpers/aead.nim | 1 + tests/quic/helpers/client.nim | 4 ++++ tests/quic/helpers/decrypt.nim | 4 +++- tests/quic/helpers/encrypt.nim | 5 ++++- tests/quic/helpers/server.nim | 3 ++- 5 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 tests/quic/helpers/aead.nim diff --git a/tests/quic/helpers/aead.nim b/tests/quic/helpers/aead.nim new file mode 100644 index 0000000..d2bcc9d --- /dev/null +++ b/tests/quic/helpers/aead.nim @@ -0,0 +1 @@ +const NGTCP2_FAKE_AEAD_OVERHEAD* = 16 diff --git a/tests/quic/helpers/client.nim b/tests/quic/helpers/client.nim index c85d8b6..0cb524a 100644 --- a/tests/quic/helpers/client.nim +++ b/tests/quic/helpers/client.nim @@ -3,6 +3,7 @@ import ngtcp2 import ids import encrypt import decrypt +import aead import hp import log @@ -93,3 +94,6 @@ proc setupClient*(path: ptr ngtcp2_path, sourceId: ptr ngtcp2_cid, destinationId ) ngtcp2_conn_set_retry_aead(result, addr retryAead, addr aeadContext) + + ngtcp2_conn_set_aead_overhead(result, NGTCP2_FAKE_AEAD_OVERHEAD) + diff --git a/tests/quic/helpers/decrypt.nim b/tests/quic/helpers/decrypt.nim index 08361f5..a1970b3 100644 --- a/tests/quic/helpers/decrypt.nim +++ b/tests/quic/helpers/decrypt.nim @@ -1,4 +1,5 @@ import ngtcp2 +import aead proc dummyDecrypt*(dest: ptr uint8, aead: ptr ngtcp2_crypto_aead, @@ -10,5 +11,6 @@ proc dummyDecrypt*(dest: ptr uint8, ad: ptr uint8, adlen: uint): cint {.cdecl.} = echo "DECRYPT" - copyMem(dest, ciphertext, ciphertextlen) + assert ciphertextlen >= NGTCP2_FAKE_AEAD_OVERHEAD + moveMem(dest, ciphertext, ciphertextlen - NGTCP2_FAKE_AEAD_OVERHEAD) diff --git a/tests/quic/helpers/encrypt.nim b/tests/quic/helpers/encrypt.nim index 02f2a9e..8c79598 100644 --- a/tests/quic/helpers/encrypt.nim +++ b/tests/quic/helpers/encrypt.nim @@ -1,4 +1,5 @@ import ngtcp2 +import aead proc dummyEncrypt*(dest: ptr uint8, aead: ptr ngtcp2_crypto_aead, @@ -10,4 +11,6 @@ proc dummyEncrypt*(dest: ptr uint8, ad: ptr uint8, adlen: uint): cint{.cdecl.} = echo "ENCRYPT" - copyMem(dest, plaintext, plaintextlen) + if plaintextlen.bool and plaintext != dest: + copyMem(dest, plaintext, plaintextlen) + zeroMem(cast[ptr uint8](cast[ByteAddress](dest) + ByteAddress(plaintextlen)), NGTCP2_FAKE_AEAD_OVERHEAD) diff --git a/tests/quic/helpers/server.nim b/tests/quic/helpers/server.nim index 456532e..8fcd798 100644 --- a/tests/quic/helpers/server.nim +++ b/tests/quic/helpers/server.nim @@ -2,6 +2,7 @@ import std/monotimes import ngtcp2 import encrypt import decrypt +import aead import hp import ids import log @@ -116,4 +117,4 @@ proc setupServer*(path: ptr ngtcp2_path, sourceId: ptr ngtcp2_cid, destinationId addr hpContext ) - ngtcp2_conn_set_aead_overhead(result, 0) + ngtcp2_conn_set_aead_overhead(result, NGTCP2_FAKE_AEAD_OVERHEAD)