Hashing in Cryptocurrency

 


A while ago, we explored the fundamentals of cryptography and how a plaintext message is converted to a cipher text, only to be converted back again into plaintext form in order to be transferred safely over an insecure network. 

We have also looked at cryptocurrency and concluded that it is one of the most secure forms of currency (if not, the most secure form out there today). Cryptocurrency transactions are stored in blocks, and multiple blocks make up what's called a blockchain. 

In this post, we'll be looking at hashing, what it is, how it works, and where it is used in today's world of technology, including cryptocurrency. 


Here is a plaintext message:

"Hello world"

Now, if we were implementing cryptography to turn this into a cipher text, we would have to use an encryption key and would get some sort of cipher text, such as

"2s4f bh80i"

Then, if we wanted to access the plaintext form, we would use a decryption key to convert it back to 'Hello world'. 

Now let's talk about hashing. By implementing a mathematical function known as a hashing algorithm onto a message (of any length), a cryptic code is produced. This is called a hash value (or digest).

It is important to note that whilst the length of a ciphertext will be dependant on the length of the plaintext, with hashing the hash value is of fixed length all the time. 

For example, if I used a certain hashing algorithm to hash "lorem ipsum", I would get something like this:

5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269

If I wanted to hash something much longer using the same algorithm, say "raining cats and dogs", I would get:

1d03841d7e08f14d6b021260f253192c82319e24d5ded9d5a3b53bc3536f47cd

Both hash values are exactly 64 characters long, even though the actual length of the plaintext message varies. 

Now that's a lot of characters. Which is why the number of possible alphanumeric hash values is quite a lot, making it rather secure (we'll go into that later on). 

There are many hashing algorithms out there, including SHA-1, Tiger, MD5 etc (the one used in the example above was SHA-256). We won't go into much detail about how each one works - all you need to know is that they convert plaintext into hashes. 

One of the most important features of hashing that separates it from cryptography is that it is a one-way process i.e. you can turn a plaintext value into a hash value, however converting a hash value back into a plaintext form is like putting toothpaste back into the tube. 

Now why would anyone want to do that? Believe it or not, hashing is often implemented by companies for storing precious information such as passwords and other personal data. This method is actually quite secure. Let's use an example.

Suppose Company X was a social media platform. John's password (and that of all the other users of the service) would be stored in X's databases. If a hacker gained unauthorized access into the database and steal this confidential information, they would only be able to see a hash value for John's password. Instead of seeing the plaintext form of his password, say "iLoveC4ts20!", they would be met with a very long alphanumeric string. And since hashing is a one-way process, it would be rather infeasible to convert it back to a plaintext. If X used cryptography instead of hashing, it would be slightly easier to decrypt the password - all they would need is the cipher and the key. Therefore, the features of hashing do make it very secure indeed. 

One more thing about hashing. The hash value generated for a certain plaintext value is not a random string. Hashing is a complex, mathematical algorithm, which means that I would expect to get the same hash value for the same plaintext value every time (provided I use the same hashing algorithm of course). Given how many possible hash values there are out there, every unique block of plaintext would have its own unique hash. In the rare event that two different plaintext values have the same hash, this would be called a hash collision. Depending on the situation, this would not be such a big deal, given that the hash value is still almost impossible to decode. 

Now the main focus of this post: cryptocurrency.


A bit of a red herring, yet most cryptocurrencies (the secure ones that is) don't implement cryptography. You would have thought it would, as suggested by the name. However, we've already had a look at why cryptography isn't the most secure process as a result of its two-way nature. This is where hashing comes in. 

Each block in the blockchain contains information about the sender, the recipient and the amount sent. Combining all this information together and then running a hashing algorithm on it, we get a hash value. This is repeated for each subsequent block in the chain. However, each subsequent block also contains the hash value of the directly previous block. So if a hacker wanted to change the contents of a block in the blockchain, they would also have to change all the subsequent hash values of the all the subsequent blocks in the chain. Not too easy to do, which is why cryptocurrencies like Bitcoin (which uses SHA-256) and Ethereum are the most secure forms of currencies. 

From storing passwords to cryptocurrency transactions, hashing is everywhere. It is so much more than just an unintelligible mathematical equation: hashing practices are getting more and more complex as technology advances, with the algorithms implemented constantly undergoing refinement to be as secure as possible. However, advancements in technology have also worked in favour of the likes of hackers. The precarious position of our technological infrastructure could swing either way. We'll just have to wait and see.   

Comments

Popular posts from this blog

World Autism Awareness Month

My Journey As A Young Carer

The Political Crusades: Independent India