diff --git a/sys/crypto/openssl/ossl_chacha20.c b/sys/crypto/openssl/ossl_chacha20.c --- a/sys/crypto/openssl/ossl_chacha20.c +++ b/sys/crypto/openssl/ossl_chacha20.c @@ -88,7 +88,8 @@ out = outseg; /* Figure out how many blocks we can encrypt/decrypt at once. */ - todo = rounddown(MIN(inlen, outlen), CHACHA_BLK_SIZE); + todo = rounddown(MIN(resid, MIN(inlen, outlen)), + CHACHA_BLK_SIZE); #ifdef __LP64__ /* ChaCha20_ctr32() assumes length is <= 4GB. */ @@ -218,7 +219,8 @@ out = outseg; /* Figure out how many blocks we can encrypt/decrypt at once. */ - todo = rounddown(MIN(inlen, outlen), CHACHA_BLK_SIZE); + todo = rounddown(MIN(resid, MIN(inlen, outlen)), + CHACHA_BLK_SIZE); #ifdef __LP64__ /* ChaCha20_ctr32() assumes length is <= 4GB. */ @@ -389,7 +391,8 @@ out = outseg; /* Figure out how many blocks we can encrypt/decrypt at once. */ - todo = rounddown(MIN(inlen, outlen), CHACHA_BLK_SIZE); + todo = rounddown(MIN(resid, MIN(inlen, outlen)), + CHACHA_BLK_SIZE); #ifdef __LP64__ /* ChaCha20_ctr32() assumes length is <= 4GB. */