Blockchain technology would not exist without cryptography. It is not necessary to be a math genius, but any blockchain user or cryptocurrency holder should understand some basic cryptographic primitives. Many coins have been lost or stolen because users did not understand the basics of cryptographic key management.
For a fascinating history of cryptography, “The Code Book” by Simon Singh is highly recommendable. But let’s summarize a few concepts relevant to blockchain technology.
What Does Cryptography Do?
Cryptography solves three problems at once: First of all, it allows secrets to be kept through data encryption. Bob can send a message to Alice through a public network without compromising privacy. Secondly, the origin of the data can be verified. Alice can make sure the message he has received really is from Bob. Finally, Alice can verify that the data sent by Bob is unchanged and has not been modified.
Symmetric versus Asymmetric Cryptography
In modern cryptography, there are two main classes of algorithms. In symmetric cryptography, a single key or passphrase is used. This key has to be kept secret and is shared by those that are to be provided with access to the data. Symmetric encryption is very efficient but is problematic in communication systems. In order for Bob to send a message to Alice, he first has to solve the problem of how to get the key to her. If the key itself is intercepted, all messages are compromised. For this reason, symmetric cryptography is used in applications, such as hard drive encryption, but in communication systems and blockchains, we tend to use asymmetric encryption.
In asymmetric cryptography, a pair of keys is used. Each user has a public key which can be publicly shared, and private key, which has to be kept secret. If Bob wants to send a message to Alice, he uses Alice’s public key to encrypt the message. Only Alice can decrypt the message, using her private key. You can see how messages cannot be compromised through intercepted keys in this system.
Private keys can also be used to sign data. The matching public key can then be used to verify the data signer or message sender and the integrity of the data.
Transaction signing in blockchains such as Bitcoin and Ethereum, makes use of this functionality. You may have noticed that blockchain systems typically use private and public key pairs for their users. Account numbers are derived from public keys. By signing a transaction the sender can be identified and by addressing a transaction to a certain public key, the owner of the corresponding private key can prove he is the intended recipient.
There is one more cryptographic primitive essential for blockchains to work. Hashing is a mathematical method to create digital fingerprints of data. An irreversible function is used to calculate a large number (or hash value) that uniquely identifies the data. Should a single bit in the data change, the number changes. This can be used to prove that data has not been tampered with.
Blockchains use this in order to “cryptographically seal” blocks. In Bitcoin, for example, each block of transactions includes an SHA-256 hash value of the previous block. This ensures that any modification of the transaction history can be detected instantly. Bitcoin mining also uses the SHA-256 hashing algorithm for the mining process.
The above primitives are key concepts every blockchain user should be familiar with. Whilst the underlying math can become quite complicated, the basic functionalities are shared between most blockchains.