Hash Functions
Learn the core properties of cryptographic hash functions and how they're used to compute digital fingerprints.
In this lesson, we'll start learning how Ethereum works. But instead of jumping right into the technicalities of blockchain, we'll start with a foundational topic for understanding blockchains: cryptographic hash functions. While this might seem very theoretical at the moment, hash functions are used so often in Ethereum and other cryptocurrencies that it's worth spending some time to get a good grasp of this topic before we move forward.
Hash functions
A cryptographic hash function is a special algorithm that takes a binary of any size as an input, but always produces an output of a fixed size (e.g., a 32- or 64-byte number depending on the function used). The result of a cryptographic hash function is called a hash value or just a hash.
Hash functions are commonly used to calculate the digital fingerprint of a document, a long number that changes if the document’s content has changed even slightly. But how and why does this work? To understand it, let’s explore the core properties of hash functions.
While there are many hash functions, they all have the same core properties. Instead of just listing the features of hash functions, we think it would be more illustrative to see them in practice using a few code examples.
In our examples, we'll use JavaScript’s crypto
library. Because all hash functions have the same properties, this library provides a unified interface that ...