Skip to content

Instantly share code, notes, and snippets.

Created February 19, 2016 16:51
Show Gist options
  • Select an option

  • Save anonymous/65366582c6e1dfc36403 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/65366582c6e1dfc36403 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Feb 19, 2016.
    75 changes: 75 additions & 0 deletions HashLadder
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,75 @@
    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;
    }

    }
    31 changes: 31 additions & 0 deletions Untitled
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    import "HashLadder";
    contract qETH {
    HashLadder hashLib;

    enum AuthType {Transfer, Withdrawl}

    struct Account {
    bytes32 pubKeyHash;
    Authorization[] auths;
    }

    struct Authorization {
    AuthType _authType;
    address from;
    address to;
    uint value;
    //Todo: add gas reimbursement for miners

    uint8 chunksProcessed;
    bytes32 msgHash;
    bytes32 authHash; //Should equal pubKeyHash
    }

    mapping(address => Account) accounts;

    function send(address _from, address _to, uint _value){
    bytes32 _msgHash = sha3(_from,_to,_value,)
    Authorization memory auth = Authorization(AuthType.Transfer,_from,_to,_value,0);
    accounts[_from].auths;
    }
    }