The reference client has supported multisig for a while now.
Search for the rawtransaction API for more information. See
this thread and especially,
Gavin's gist.
Here is some PHP that takes an array of keys (
$keys) and a number of keys required to spend (
$nReq) and creates a P2SH multisig address and redeemScript. This isn't necessary, since the API can do the same task. This is just for those times when you want totally offline generation. Note that the hashing steps after
$rs is completed are exactly the same as the hashing done to normal addresses, just with a different magic number. Also, the sorting step is not necessary, I just do it to make it easier to recover in case the metadata is lost and I'm left with just a bunch of keys.
function createmultisig($nReq,$keys,$sortkeys=TRUE){
if($sortkeys)sort($keys,SORT_STRING);
if($nReq<2 OR $nReq>16 OR $nReq>count($keys))return FALSE;
$rs=chr(0x50+$nReq);
while(list($key,$val)=each($keys)){
$bpk=hex2bin($val);
$rs.=chr(strlen($bpk)).$bpk;
}
$rs.=chr(0x50+count($keys));
$rs.=chr(0xae);
$h=hash("sha256",$rs,TRUE);
$h2=hash("ripemd160",$h,TRUE);
$h3="\x05".$h2;
$h4=hash("sha256",$h3,TRUE);
$h5=hash("sha256",$h4,TRUE);
$chk=substr($h5,0,4);
$addr_bin=$h3.$chk;
$addr=encodeBase58($addr_bin);
return array("redeemScript"=>bin2hex($rs),"address"=>$addr);
}
?>