library HashLadder{ function genPubKey(bytes32[2][32] privKey) returns (bytes32[2][32]){ bytes32[2][32] memory pubKey; for(uint8 i; i< 32; i++){ bytes32 pa = privKey[i][0]; bytes32 pb = privKey[i][1]; for(uint k; k<258; k++){ pa = sha3(pa); pb = sha3(pb); } pubKey[i] = [pa,pb]; } return pubKey; } function sign_chunk(byte chunk, bytes32[2] privKey) constant returns(bytes32[2]){ bytes32[2] memory pubKey; uint n = uint8(chunk); bytes32 a = privKey[0]; bytes32 b = privKey[1]; for(uint i; i < n+1; i++){ a = sha3(a); } for(uint j; j < 256-n; j++){ b = sha3(b); } return([a,b]); } function sign(bytes message, bytes32[2][32] privKey) returns(bytes32[2][32]){ bytes32 hash = sha3(message); bytes32[2][32] memory sig; bytes32[2][32] memory key; for(uint8 i; i<32;i++){ sig[i] = sign_chunk(hash[i],privKey[i]); } return (sig); } function verify_chunk(byte chunk, bytes32[2] pubKey, bytes32[2] signature) constant returns (bool){ uint a_i; uint b_i; bytes32 a = signature[0]; bytes32 b = signature[1]; while(b_i <= 258 && b != pubKey[1]){ b = sha3(b); b_i++; } while(a_i <= 258 && a != pubKey[0]){ a = sha3(a); a_i++; } return (uint(chunk) == b_i - 2 && b_i == 259 - a_i); //return true; } function verify(bytes32 msgHash, bytes32[2][32] pubKey, bytes32[2][32] signature) public returns (bool){ for(uint8 i; i<32; i++){ if(!verify_chunk(msgHash[i],pubKey[i],signature[i])) return false; } return true; } }