[gnutls-devel] GnuTLS | crypto-api: add gnutls_aead_cipher_{en, de}crypt_vec (!1052)

Development of GNU's TLS library gnutls-devel at lists.gnutls.org
Wed Aug 7 17:27:07 CEST 2019

Merge request https://gitlab.com/gnutls/gnutls/merge_requests/1052 was reviewed by Simo Sorce

Simo Sorce started a new discussion on lib/iov.h: https://gitlab.com/gnutls/gnutls/merge_requests/1052#note_201215482

> +
> +		if (iter->block_offset > 0) {
> +			if ((size_t) len >= iter->block_size - iter->block_offset) {

seem like you are using iter->block_size - iter->block_offset quite a few times here, and it makes the code harder to read and more verbose.
What about:
size_t block_left = iter->block_size - iter->block_offset;
if (len >= block_left) {
    mempcy(iter->block + iter->block_offset, p, block_left);
    iter->iov_offset += block_left;

Simo Sorce started a new discussion on lib/iov.h: https://gitlab.com/gnutls/gnutls/merge_requests/1052#note_201215497

> +		const giovec_t *iov = &iter->iov[iter->iov_index];
> +		uint8_t *p = iov->iov_base;
> +		ssize_t len = iov->iov_len;

Why declare len signed and then cast it later tounsigned during comparison?
Sounds like that could lead to wraparound errors. I would declare len size_t, in no case a length can ever be negative.

Simo Sorce started a new discussion on lib/iov.h: https://gitlab.com/gnutls/gnutls/merge_requests/1052#note_201215498

> +		}
> +
> +		memcpy(iter->block + iter->block_offset, p, len);

I found it hard to figure out why this block was ok without a return (which is instead in the other 2 conditional blocks above. At the very least I would put a comment that says what is the chopping in blocks strategy here.

however I also think a different organization of the code might make it more readable:
*blocks = 0;
if (iter->block_offest == 0 &&  len >= iter->block_size) {
    /* We have at least one full block, return a whole set of full blocks immediately */
    [code from second block here - except return statemnt]
} else if (len >= iter->block_size - iter->block_offset) {
   /* We can complete one full block to return */
   [code from first block - except return statement]
} else {
   /* Not enough data for a full block, store in temp memory */
   [final block]
if (*blocks > 0)
    return 0;

Simo Sorce started a new discussion on lib/iov.h: https://gitlab.com/gnutls/gnutls/merge_requests/1052#note_201215499

> +
> +/* Initialize the iterator. */
> +static inline int

Why put these functions inline in a header file ?
They are rather big, I would let the compiler decide what is more efficient speed/space wise.

Simo Sorce started a new discussion on lib/iov.h: https://gitlab.com/gnutls/gnutls/merge_requests/1052#note_201215502

> +		iter->iov_offset = 0;
> +	}

If I read this function right this return statement makes it so that the function requires iovecs with a total size that is as big or larger than a blocksize, is that intended, if so it should be in the comment that describes the function.

Reply to this email directly or view it on GitLab: https://gitlab.com/gnutls/gnutls/merge_requests/1052
You're receiving this email because of your account on gitlab.com.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gnutls-devel/attachments/20190807/2ccca972/attachment-0001.html>

More information about the Gnutls-devel mailing list