Indeed, what got it to work was a call to strncpy (which I used because of the possibility of NULL bytes in the input), and then I was able to do the call to mcrypt_generic, copy the output into a Python bytestring, free the temporary buffer, and return.