]> git.meshlink.io Git - meshlink/commitdiff
Do not use hardcoded cipher block length when padding.
authorGuus Sliepen <guus@tinc-vpn.org>
Sat, 19 Dec 2009 22:23:25 +0000 (23:23 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Sat, 19 Dec 2009 22:23:25 +0000 (23:23 +0100)
src/gcrypt/cipher.c

index ad2a9505318475dcbd0fed871fc3df23d2219ee5..6a2cc5a1076a556675a5d471636d7983c60191da 100644 (file)
@@ -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;
 }