Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to reverse a sha1?

Tags:

security

sha1

Is it possible to reverse a SHA-1?

I'm thinking about using a SHA-1 to create a simple lightweight system to authenticate a small embedded system that communicates over an unencrypted connection.

Let's say that I create a sha1 like this with input from a "secret key" and spice it with a timestamp so that the SHA-1 will change all the time.

sha1("My Secret Key"+"a timestamp")

Then I include this SHA-1 in the communication and the server, which can do the same calculation. And hopefully, nobody would be able to figure out the "secret key".

But is this really true?

If you know that this is how I did it, you would know that I did put a timestamp in there and you would see the SHA-1. Can you then use those two and figure out the "secret key"?

secret_key = bruteforce_sha1(sha1, timestamp)

Note1: I guess you could brute force in some way, but how much work would that actually be?

Note2: I don't plan to encrypt any data, I just would like to know who sent it.

like image 274
Johan Avatar asked Feb 10 '10 07:02

Johan


People also ask

Can you reverse a SHA-1?

You can't "reverse" or "invert" MD5, SHA256, bcrypt, SHA1, or similar hashes, salted or unsalted. You (usually) can't "decode" passwords, "decrypt" password hashes or "reverse" or "unscramble" password hashes at all. There's no such thing as "hash decryption".

Can you convert SHA-1 to SHA256?

Resolution. You cannot change a SHA1 certificate into a SHA256. The cryptographic hash (SHA1 or SHA256) used when a certificate is generated cannot be changed. To change from SHA1 to SHA256 new certificates are needed that are SHA256.

Can hash algorithms be reversed?

Hashing is a mathematical operation that is easy to perform, but extremely difficult to reverse. (The difference between hashing and encryption is that encryption can be reversed, or decrypted, using a specific key.) The most widely used hashing functions are MD5, SHA1 and SHA-256.

Can Sha 2 be reversed?

To answer your question, no, it's not possible to "unhash" 2 and obtain 1. In order to "crack" the second hash, you would have to brute force it by computing the sha256 of other strings and comparing the result with 2.


2 Answers

No, you cannot reverse SHA-1, that is exactly why it is called a Secure Hash Algorithm.

What you should definitely be doing though, is include the message that is being transmitted into the hash calculation. Otherwise a man-in-the-middle could intercept the message, and use the signature (which only contains the sender's key and the timestamp) to attach it to a fake message (where it would still be valid).

And you should probably be using SHA-256 for new systems now.

sha("My Secret Key"+"a timestamp" + the whole message to be signed)

You also need to additionally transmit the timestamp in the clear, because otherwise you have no way to verify the digest (other than trying a lot of plausible timestamps).

If a brute force attack is feasible depends on the length of your secret key.

The security of your whole system would rely on this shared secret (because both sender and receiver need to know, but no one else). An attacker would try to go after the key (either but brute-force guessing or by trying to get it from your device) rather than trying to break SHA-1.

like image 198
Thilo Avatar answered Oct 10 '22 05:10

Thilo


SHA-1 is a hash function that was designed to make it impractically difficult to reverse the operation. Such hash functions are often called one-way functions or cryptographic hash functions for this reason.

However, SHA-1's collision resistance was theoretically broken in 2005. This allows finding two different input that has the same hash value faster than the generic birthday attack that has 280 cost with 50% probability. In 2017, the collision attack become practicable as known as shattered.

As of 2015, NIST dropped SHA-1 for signatures. You should consider using something stronger like SHA-256 for new applications.

Jon Callas on SHA-1:

It's time to walk, but not run, to the fire exits. You don't see smoke, but the fire alarms have gone off.

like image 29
Mark Byers Avatar answered Oct 10 '22 04:10

Mark Byers