Let's start from some quotes, because that's what I started with, before creating this topic.
Now, how do we build collision resistant and efficient cryptographic hash functions? That is right. We use mostly reversible components or at least components that can be made (mostly) reversible with a moderate computational overhead.
Many people cannot understand it, especially the last sentence about "mostly reversible components". Which means, they repeat like a parrot that "hash functions can be executed only in one direction". They think that hash functions are "irreversible", which means, they treat it like a black box, and they think, that whatever gets in, then never can get out, or get in another direction. This is only partially true, and I will try to show you, why.
The first thing to note is that I already demonstrated a practical example, to show exactly, how to execute some hash function backwards:
https://bitcointalksearch.org/topic/m.60342783Also, I repeated that again in some other topics, for example here:
https://bitcointalksearch.org/topic/m.62397317So, let's talk more about "mostly reversible components". What they are, how they are defined, how to use them, and so on. Because I started my journey from SHA-1, I will use that in my examples, but a lot of things can be also applied to SHA-256, or other hash functions. The most important thing is the internal construction of a particular hash function: if it is identical for two different hash functions, then guess what: similar attacks can be performed on both, which I also demonstrated by attacking the first 16 rounds of SHA-256, exactly in the same way, as I did it for SHA-1:
https://bitcointalksearch.org/topic/hardened-sha-1-vs-weakened-sha-256-how-to-test-them-5467882The main keyword that helps a lot is called "ARX". Which is an abbreviation of "
Addition,
Rotation and
Xor". Those three operations, combined together, can be used to make new hash functions, and reach certain properties. In case of SHA-1 and SHA-256, they both use that ARX model. Which also means, if you can think about any successful attack for ARX, then you can use that on both SHA-1, and SHA-256.
So, let's dig deeper, and explain, what I promised, step by step. First, we can take Addition. If we work with integers, we all know that addition can be reversed by using subtraction. Those two operations are connected. If you have "a+b=c", then you can also go back, and write it as "a=c-b". Which means, if you start from "a", combine it with "b", and reach "c" as a result, then you can obviously throw away your "b", and claim that your operation is "irreversible". But this is not the case!
So, how to write the same thing in a reversible way? Well, the answer is quite simple: you can just save your "b", instead of throwing it away. Which means, if you write "(a,b)" as your input, instead of just writing "a", and "c" as your output, then it is perfectly reversible operation. Then, you can take subtraction, pass "(c,b)" as your input, and reach "a" as your output.
Also, the best news is that using modulo, for example modulo 2^32, which is used in both SHA-1 and SHA-256, is not going to change anything. Addition modulo 2^32 can be simply reversed by using subtraction modulo 2^32. Other operations are also reversible. If you take Rotations, then left rotation by 30 bits can be reversed, if you just apply left rotation by 2 bits. Because left rotation by 32 bits is just a "do nothing" operation, so you can easily complete it. With Xor, it is even easier, because you can just Xor again by the same value, and you are done.