Add AEAD overhead

This commit is contained in:
Mark Spanbroek 2020-09-16 14:22:21 +02:00 committed by markspanbroek
parent bd32d3ecd9
commit 3f9d9050df
5 changed files with 14 additions and 3 deletions

View File

@ -0,0 +1 @@
const NGTCP2_FAKE_AEAD_OVERHEAD* = 16

View File

@ -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)

View File

@ -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)

View File

@ -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"
if plaintextlen.bool and plaintext != dest:
copyMem(dest, plaintext, plaintextlen)
zeroMem(cast[ptr uint8](cast[ByteAddress](dest) + ByteAddress(plaintextlen)), NGTCP2_FAKE_AEAD_OVERHEAD)

View File

@ -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)