You can set this up using a crypttab keyscript, example crypttab entry:
# target,sourcedev,keyfile,options cdisk3 /dev/sda3 none cipher=twofish,hash=ripemd160,size=256,keyscript=/path/to/script
The script will be executed with keyfile (in this case, "none") as the only argument, and the output from the script will be used as the key.
It gets the rest of the input as environment variables:
CRYPTTAB_NAME The target name CRYPTTAB_SOURCE The source device CRYPTTAB_KEY The key file CRYPTTAB_OPTIONS A list of exported crypttab options CRYPTTAB_OPTION_<option> The value of the appropriate crypttab option, with value set to 'yes' in case the option is merely a flag.
I got most of this from Manual page crypttab(5), it's better written than what i can provide.
Of course, a setup like this will be difficult to make secure, and it depends a lot on what you put in your script.