Calculating the RC5 encrypted size of any data is as simple as rounding up the plaintext length to the nearest multiple of 8. What I'm wondering is whether this can be done in the other direction, to get the length of the original plaintext data given the ciphertext. Obviously this information isn't revealed until the decryption actually happens, but can it be tracked/calculated during the decryption process?
I'm working with this implementation of RC-5 decryption (decompiled C++ binary, re-implemented in C#), which decrypts the data in groups of 4 bytes, and copies the result into the output buffer. The problem is, there's a lot of garbage in the output buffer after the end of the decrypted data, so it's hard to determine where the data actually ends. It's easy if the plaintext is a null-terminated string, but I'm looking for a more generic solution that can work on arbitrary binary data.