Is it possible to do sha512 within a smart contract? Or, not?


Smart Pool has an implementation of sha3_512, https://github.com/SmartPool/contracts/blob/develop/contracts/Ethash.sol

If that could be turned into a stand-alone library, with a bit of documentation, then Ethereum would have on-state sha512.


By sha512() I'm assuming you mean SHA-2 with a digest length of 512 bits. If that's the case I think the recommendation would be to use SHA-3.

sha256() is natively supported in Solidity - see the documentation.

sha3() is also natively supported, and aliased to keccak256().

(For completeness, here's a Solidity implementation of SHA-1.)

  • any 512 bit hash function, sha3_512 would work – miyamoto Mar 5 '18 at 17:11
  • The sha3() implementation is 256 bits, I'm afraid. If what you're doing is going to be on the public network (and not a private chain), then I'd look into why you need it to be 512-bit, rather than 256-bit, which would be far less hassle :-) – Richard Horrocks Mar 5 '18 at 18:29
  • is that argument not status quo bias? I mean, from a logic perspective, a de facto bias rather than an argument? I see it from time to time – miyamoto Mar 5 '18 at 18:36
  • It's a bias based on the fact sha3() is natively implemented (i.e. its own opcode), and sha256() is available to the EVM as a precompiled contract, meaning any associated EVM overheads are either minimised or negated altogether. – Richard Horrocks Mar 5 '18 at 18:45
  • yes, I know that. I meant as an argument overall. I'm building a bounty that only needs to run sha3_512 once, and it is meant to demonstrate an idea for a signature cipher, proof-of-public-key = f(nextPublicKey) xor sha512(nextPublicKey) the 512-bit hash is to produce a hash that is of the same length as the message that it encrypts with a xor – miyamoto Mar 5 '18 at 18:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.