X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fgcrypt%2Fcipher.c;h=6a2cc5a1076a556675a5d471636d7983c60191da;hb=886a6f61a1f4cc48a77b42d10f34f9126377d904;hp=ad2a9505318475dcbd0fed871fc3df23d2219ee5;hpb=0ff44fc2417217d542bf0e9a7ecfd20020893bc7;p=tinc diff --git a/src/gcrypt/cipher.c b/src/gcrypt/cipher.c index ad2a9505..6a2cc5a1 100644 --- a/src/gcrypt/cipher.c +++ b/src/gcrypt/cipher.c @@ -196,7 +196,13 @@ bool cipher_encrypt(cipher_t *cipher, const void *indata, size_t inlen, void *ou if(!oneshot) return false; - size_t reqlen = ((inlen + 8) / cipher->blklen) * cipher->blklen; + size_t reqlen = ((inlen + cipher->blklen) / cipher->blklen) * cipher->blklen; + + if(*outlen < reqlen) { + logger(LOG_ERR, "Error while encrypting: not enough room for padding"); + return false; + } + uint8_t padbyte = reqlen - inlen; inlen = reqlen - cipher->blklen; @@ -259,7 +265,8 @@ bool cipher_decrypt(cipher_t *cipher, const void *indata, size_t inlen, void *ou } *outlen = origlen; - } + } else + *outlen = inlen; return true; }