[Ethereum] solidity ..which hashing algorithm to use

contract-developmentkeccaksolidity

I have tried using many hashing algorithms but there output in solidity doesn't match with the one given in online converters.

Here is my program:-
pragma solidity ^0.4.18;  
contract C {  
bytes32 public temp;  
function hashingsha3 (uint s)   {  
temp= sha3(s);  
}

    function hashingsha256 (uint s) {
        temp= sha256(s); 
    }
     function kec (uint s)   returns  (bytes32 hash){
        temp= keccak256(s); 
    }

}

this is the online site to convert

I have read solidity doesn't use the current keccak256 approved by NIST.
But then what does it use that matches any online output?
Any help would be useful.

List of outputs :
Solidity
sha3(12)
0xdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c7

sha256(12)
0xa82872b96246dac512ddf0515f5da862a92ecebebcb92537b6e3e73199694c45

keccak256(12)
0xdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c7

online converter
SHA256(12)
6b51d431df5d7f141cbececcf79edf3dd861c3b4069f0b11661a3eefacbba918

SHA512/256 (12)
d0d0b58b8cad7a27781cb78b3212d8abce1a4eb4192882e703f7f2e1ea5158da

SHA3-256(12)
1a9a118cb653759c3fcb3bd5060e6f9910c8c27008dd11fe4315f4635c9caa98

SHA3-512 (12)
f235c129089233ce3c9c85f1d1554b9cb21952b27e0765bcbcf75d550dd4d2874e546889da5c44db9c066e05e268f4742d672889ff62fb9cb18a3d1b57f00658

Keccak-256 (12)
7f8b6b088b6d74c2852fc86c796dca07b44eed6fb3daf5e6b59f7c364db14528

Thankyou

EDITED:

pragma solidity ^0.4.18;  
contract C {  
bytes32 public temp;  
function hashingsha3 (bytes s)   {  
temp= sha3(s);  
}  
function hashingsha256 (bytes s) {  
temp= sha256(s);  
}  
function kec (bytes s)  {  
temp= keccak256(s);  
}  
}

I changed the code :
but still the outputs now for this are:
Passed as a string in solidity:
sha256(12)
0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

sha3(12)
0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470

keccak256(12)
0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470

enter image description here

enter image description here

Best Answer

Completely agree with Mr. Marx. I'm just adding another answer as a commentary for consideration.

Your question turns attention to a hidden assumption. That is, that it's currently possible and convenient to find a suitable library for any given client, and always will be.

In my opinion, it would be a good idea to expose read-only function to assist clients and to provide a guarantee that they will always be able to compute the hash by the same method as today's compiled contract. Something simple ...

function hashHelper(uint value) public pure returns(bytes32 hash) {
  return keccak256(value);
}

The idea would be to use the same function internally, thus avoiding possible future divergence between the compiled bytecode and clients of all shapes and sizes.

Hope it helps.

Related Topic