preImageResistantHashAs results in 3x hashing
When implementing a new hash algorithm via the DigestAlgorithm interface and only implementing its digest method, the DigestService's methods 'computeNonce' and 'componentHash' will calculate the hash via a 3x hashing.
The current workaround would be to override the DigestAlgorithm's preImageResistantDigest method with a method that simply returns the byte array, in the case of an algorithm that is resistant to length extension attacks, or calculating the digest once in the other case.
The proper fix would be to change
val firstHash = digest.preImageResistantDigest(bytes)
val hash = digest.preImageResistantDigest(bytes)
NOTE: after the fix, transactions created with nodes running in experimental mode will fail to validate. We should probably inform interested customers.
SecureHash's preImageResistantHashAs method
DigestAlgorithm's preImageResistantDigest method
- What needs to be QA’ed here? can you please elaborate any specific test cases?