diff options
| author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2026-01-22 21:34:42 +0100 |
|---|---|---|
| committer | Sander Vrijders <sander@ouroboros.rocks> | 2026-01-23 08:29:30 +0100 |
| commit | fb1aeb3ffff2948edeb710e65aef261b589c7403 (patch) | |
| tree | 944843762ff07c6b19d4a7a12170fbe5357d75d0 /src/lib/dev.c | |
| parent | 47d786fbabe456acb2d89c898185366bc88bebbc (diff) | |
| download | ouroboros-fb1aeb3ffff2948edeb710e65aef261b589c7403.tar.gz ouroboros-fb1aeb3ffff2948edeb710e65aef261b589c7403.zip | |
lib: Fix allocation of IV and tags
The packet buffer was allocating a fixed header for the IV, but did
not account for the tag at all (remnant of the old hardcoded CBC
mode-only proof-of-concept). Never ran into issues because we always
reserved ample space. But it now properly reserves the correct space
for IV and tag.
Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/lib/dev.c')
| -rw-r--r-- | src/lib/dev.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index 2c0dbf28..31f4fb78 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -100,6 +100,8 @@ struct flow { ssize_t part_idx; struct crypt_ctx * crypt; + int headsz; /* IV */ + int tailsz; /* Tag + CRC */ struct timespec snd_act; struct timespec rcv_act; @@ -269,11 +271,11 @@ static int sdb_encrypt(struct flow * flow, if (crypt_encrypt(flow->crypt, in, &out) < 0) goto fail_encrypt; - head = shm_du_buff_head_alloc(sdb, IVSZ); + head = shm_du_buff_head_alloc(sdb, flow->headsz); if (head == NULL) goto fail_alloc; - tail = shm_du_buff_tail_alloc(sdb, (out.len - in.len) - IVSZ); + tail = shm_du_buff_tail_alloc(sdb, flow->tailsz); if (tail == NULL) goto fail_alloc; @@ -305,8 +307,8 @@ static int sdb_decrypt(struct flow * flow, return -ENOMEM; - head = shm_du_buff_head_release(sdb, IVSZ) + IVSZ; - shm_du_buff_tail_release(sdb, (in.len - out.len) - IVSZ); + head = shm_du_buff_head_release(sdb, flow->headsz) + flow->headsz; + shm_du_buff_tail_release(sdb, flow->tailsz); memcpy(head, out.data, out.len); @@ -543,11 +545,15 @@ static int flow_init(struct flow_info * info, flow->snd_act = now; flow->rcv_act = now; flow->crypt = NULL; + flow->headsz = 0; + flow->tailsz = 0; if (IS_ENCRYPTED(sk)) { flow->crypt = crypt_create_ctx(sk); if (flow->crypt == NULL) goto fail_crypt; + flow->headsz = crypt_get_ivsz(flow->crypt); + flow->tailsz = crypt_get_tagsz(flow->crypt); } assert(flow->frcti == NULL); @@ -1235,10 +1241,14 @@ static int chk_crc(struct shm_du_buff * sdb) static int add_crc(struct shm_du_buff * sdb) { - uint8_t * head = shm_du_buff_head(sdb); - uint8_t * tail = shm_du_buff_tail_alloc(sdb, CRCLEN); + uint8_t * head; + uint8_t * tail; + + tail = shm_du_buff_tail_alloc(sdb, CRCLEN); if (tail == NULL) - return -1; + return -ENOMEM; + + head = shm_du_buff_head(sdb); mem_hash(HASH_CRC32, tail, head, tail - head); |
