31

I have been reviewing keccak256 implementation and sha3-256 that follows the FIPS standard. The sponge function is taking a while to set in, but I have noticed a difference in implementation :

I noticed web3.js uses crypto-js implementation of sha3: https://github.com/brix/crypto-js/blob/develop/src/sha3.js From that I gather the var LFSR = 0x01;

which is set to 0x06 in sha3-256. Am I correct in this observation?

What other differences are there?

2

2 Answers 2

18

from an answer to What are the key differences between the draft SHA-3 standard and the Keccak submission?:

  1. No they did not, the internals and security levels have not been changed from the draft Keccak submission, only the padding rule has changed.
  2. The padding change is the only difference, this allows future tree hashing modes as well as the current SHAKE outputs to generate different digests given the same security parameters and message inputs. Up to 4 additional bits are added, which keeps the full padding inside a byte boundary, making implementations with octet only input able to switch to SHA-3 from Keccak with change to only a single line of code.
  3. The padding change has no negative impact on the security of SHA-3.
7

Keccak and sha-3 are not the same. In 2007, U.S. National Institute of Standard and Technology (NIST) initiated a competition about SHA-3. In 2012, Keccak team won the competition. From then on, developers implemented lots of “sha3” solution based on Keccak. However, in 2014, NIST modified Keccak solution and released FIPS 202, and this updated proposal becomes official SHA-3 standard on Aug 2015. Many “old” program still use Keccak, and do not upgrade to official SHA-3 standard.

“old” code based on Keccak does not generate the same hash value as SHA-3 does. So, if using a “sha3” library, you should be crystal clear that the library is based on Keccak or based on standard SHA-3. A simple solution is doing a test for empty input:

SHA-3 standard output is:

a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a

Many old Keccak-256 outputs are:

c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470

from here

The key idea behind SHA-3 is based on unkeyed permutations, as opposed to other typical hash function constructions that used keyed permutations. Keccak also does not make use of the Merkle- Damgard transformation that is commonly used to handle arbitrary-length input messages in hash functions. A newer approach, called sponge and squeeze construction, is used in Keccak. It is a random permutation model. Different variants of SHA-3 have been standardized, such as SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE128, and SHAKE256

If you ever used this:

  web3.utils.soliditySha3()

eben though name is Sha3 but its actually implemented by keccak256

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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