2
$\begingroup$

There is a lot of confusion between hash- and encryption algorithms; I would like to understand:

  1. When do we use a hash algorithm and when do we use an encryption algorithm (a cipher)?
  2. How difficult it is to reverse hash- and encryption algorithms?
  3. From the theoretical/mathematical perspective, what differentiates a hash- and encryption algorithm?
$\endgroup$
2
$\begingroup$

When do we use a hash algorithm and when do we use an encryption algorithm (a cipher)?

Hash functions are typically used to map an arbitrary-length (usually long) input into a fixed-length (usually short) and random-looking value. E.g., SHA-256 always outputs a 256-bit random-looking string (or digest) for any given input.

A very common property of hash functions is collision-resistance, i.e., it is very hard to find two inputs that generate the same output. This is very useful when the input size is very long, which implies that we can compress a big file/string into a small one while still maintaining its "uniqueness". (Of course, theoretically, there are many many long inputs that generate the same short output due to Pigeonhole principle, but they are very hard to find given reasonable computing resources.) Based on this property, hash functions have many good applications. For instance, one can use the hash values of big files to efficiently find duplicates, and some websites often publish the hash values of their downloadable application installation packages to guarantee integrity. However, hash functions themselves are not directly related to data privacy or confidentiality.

The other property that hash functions (are expected to) have is that they output random-looking values. This can be used to generate random keys given non-random (but high-entropy) inputs, i.e., the so-called key derivation functions.

Encryption algorithms (more precisely, encryption schemes) are designed to "hide" the input/plaintext with the output/ciphertext such that no one except those having secret keys can decrypt the ciphertext to get the original plaintext. They at least provide data confidentiality, and authenticated encryption schemes also provide integrity (hash functions can be used here).

How difficult it is to reverse hash- and encryption algorithms?

Hash functions by design are hard to reverse, so are encryption algorithms without knowing the secret key. But if you know the key or if you want to play with the encryption algorithm with any key, then you can easily reverse it with a decryption algorithm using the same key. So, here the simple difference is that hash functions do not have keys. (Note that keyed hash functions are often discussed in the topic of message authentication codes.)

From the theoretical/mathematical perspective, what differentiates a hash- and encryption algorithm?

Hash functions normally map long inputs into short ones while encryption algorithms often do the opposite to introduce randomness (to hide the input messages). Hash functions are deterministic while encryption algorithms are often probabilistic (otherwise the encryption scheme cannot be IND-CPA secure). Well, regarding similarities, they both generate random-looking outputs.

$\endgroup$
0
$\begingroup$

When do we use a hash algorithm and when do we use a cipher?

A (cryptographic) hash function allows one to easily verify that some input data maps to a given hash value. Hashing is also used to verify the integrity of a file after it has been transferred from one place to another, typically in a file backup program like SyncBack. To ensure the transferred file is not corrupted, a user can compare the hash value of both files. If they are the same, then the transferred file is an identical copy.

Hashes play also an important role in Key derivation functions (KDF).

Encryption on the other hand is the process of encoding a message or information in such a way that only authorized parties can access it and those who are not authorized cannot.

How difficult it is to reverse hash and encryption functions?

Encryptions are rather easy to reverse (that's the purpose), but they vary in difficulty to reverse on certain conditions. If the authorized party has the key, then some of these conditions include:

  • Symmetric or asymmetric encryption?
    • Symmetric encryption is usually easier to reverse than asymmetric encryption.
  • "Security-Degree" of encryption
    • AES-128 for example is easier to reverse than AES-256.

If the key is unknown it can be extremly hard, almost impossible, to reverse the encryption of a message (in this context: Reverse = Finding the key).

Good hashing-functions are a one-way-function, so it's very hard to reverse a hash. Almost no hash functions in today's use have been proven to be irreversible. More detailed info about provable secure hash functions can be found in this Wikipedia-section .

From the theoretical/mathematical perspective, what differentiates a hash or encryption algorithm?

Most hash functions take any length of message and return a fixed length hash value. A perfect hash function would be designed to be irreversible. That means that you cannot reverse the function to receive the input from the hash.

However, encryption algorithms can be reversed, as long as the key is known.

$\endgroup$
  • 3
    $\begingroup$ A cryptographic hash is the workhorse in current crypto. I don't think that first section does it justice. For instance, the use of a hash within a KDF or MGF doesn't involve comparison of input values. $\endgroup$ – Maarten Bodewes Sep 4 '18 at 10:14
  • 1
    $\begingroup$ You're welcome to edit my answer if you have corrections / additional info $\endgroup$ – AleksanderRas Sep 4 '18 at 10:15
  • 2
    $\begingroup$ As for section two: symmetric encryption is easier to reverse than asymmetric encryption: not necessarily. Reversal just requires you to know the key in both cases. You need at least explain that reversal here means finding the key. A trapdoor function is a function that is easy to compute in one direction, yet difficult to compute in the opposite direction (finding its inverse) without special information, called the "trapdoor". What is the trapdoor for SHA-256? $\endgroup$ – Maarten Bodewes Sep 4 '18 at 10:17
  • 1
    $\begingroup$ Almost no hash functions (in practical use) have been proven to be irreversible, there is a section on Wikipedia about provable secure hash functions here $\endgroup$ – Maarten Bodewes Sep 4 '18 at 10:17
  • 1
    $\begingroup$ In general I would expect some terms such as "confidentiality", PRP and PRF to be in the answer. $\endgroup$ – Maarten Bodewes Sep 4 '18 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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