sha512_256

Git Source

Hash the input data with SHA-512/256, according to NIST.FIPS.180-4.

Precompile address

0x0100000000000000000000000000000000000102

Gas cost

115 gas, then 13 gas per word

Example

bytes32 result = sha512_256(abi.encodePacked("input data"));

Warning: SHA-512 vs SHA-512/256 Length-Extension Attacks

SHA-512 is vulnerable to length-extension attacks, which are relevant if you are computing the hash of a secret message. The SHA-512/256 variant is not vulnerable to length-extension attacks.

Notes:

  • standard: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf

  • see: @oasisprotocol/oasis-sdk :: precompile/sha2.rs :: call_sha512_256

function sha512_256(bytes memory input) view returns (bytes32 result);

Parameters

NameTypeDescription
inputbytesBytes to hash.

Returns

NameTypeDescription
resultbytes3232 byte digest.