{"id":13936,"date":"2021-01-25T12:34:59","date_gmt":"2021-01-25T17:34:59","guid":{"rendered":"https:\/\/www.thesslstore.com\/blog\/?p=13936"},"modified":"2024-11-05T07:29:56","modified_gmt":"2024-11-05T12:29:56","slug":"what-is-a-hash-function-in-cryptography-a-beginners-guide","status":"publish","type":"post","link":"https:\/\/www.thesslstore.com\/blog\/what-is-a-hash-function-in-cryptography-a-beginners-guide\/","title":{"rendered":"What Is a Hash Function in Cryptography? A Beginner\u2019s Guide"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-this-cryptographic-tool-aids-secure-authentication-and-ensures-data-message-integrity-across-digital-channels-here-s-what-to-know-about-what-a-hash-function-is-and-how-it-works\">This cryptographic tool aids secure authentication and ensures data message integrity across digital channels \u2014 here\u2019s what to know about what a hash function is and how it works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">What\u2019s four letters and is both a tasty breakfast item as well as a plant with pointy leaves? If you guessed \u201chash,\u201d then you\u2019re right! But hash has another meaning as well that relates to cryptography, and that\u2019s what we\u2019re going to discuss here.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A hash function is a serious mathematical process that holds a critical role in public key cryptography. Why? Because it\u2019s what helps you to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Securely store passwords in a database,<\/li>\n\n\n\n<li>Ensure data integrity (in a lot of different applications) by indicating when data has been altered,<\/li>\n\n\n\n<li>Make secure authentication possible, and<\/li>\n\n\n\n<li>Organize content and files in a way that increases efficiency.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You can find hash functions in use just about everywhere \u2014 from signing the software applications you use on your phone to securing the website connections you use to transmit sensitive information online. But what is a hash function in cryptography? What does it do exactly to help you protect your business\u2019s data? And how does hashing work?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s hash it out.<span id=\"newline\"><\/span><\/p>\n\n\n<span style=\"--tl-form-height-m:150.25px;--tl-form-height-t:121.4583px;--tl-form-height-d:121.4583px;\" class=\"tl-placeholder-f-type-shortcode_12753 tl-preload-form\"><span><\/span><\/span>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-a-hash-function\">What Is a Hash Function?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A term like \u201chash function\u201d can mean several things to different people depending on the context. For hash functions in cryptography, the definition is a bit more straightforward. <strong>A hash function is a unique identifier for any given piece of content. It\u2019s also<\/strong> <strong>a process that takes plaintext data of any size and converts it into a unique ciphertext of a specific length.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The first part of the definition tells you that no two pieces of content will have the same hash digest, and if the content changes, the hash digest changes as well. Basically, hashing is a way to ensure that any data you send reaches your recipient in the same condition that it left you, completely intact and unaltered.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But, wait, doesn\u2019t that sound a lot like encryption? Sure, they\u2019re similar, but encryption and hashing are not the same thing. They\u2019re two separate cryptographic functions that aid in facilitating secure, legitimate communications. So, if you hear someone talking about \u201cdecrypting\u201d a hash value, then you know they don\u2019t know what they\u2019re talking about because, well, hashes aren\u2019t <em>encrypted<\/em> in the first place.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We\u2019ll speak more to the difference between these two processes a little later. But for now, let\u2019s stick with the topic of hashing. So, what does hashing look like?<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"492\" src=\"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/12\/Hashing-Example-1024x492.png\" alt=\"Hash function graphic that shows how hashing works\" class=\"wp-image-9978 addshadow\" srcset=\"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/12\/Hashing-Example-1024x492.png 1024w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/12\/Hashing-Example-300x144.png 300w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/12\/Hashing-Example-768x369.png 768w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2018\/12\/Hashing-Example.png 1251w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>A basic illustration of how the hashing process works.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A simple illustration of what a hash function does by taking a plaintext data input and using a mathematical algorithm to generate an unreadable output.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Looks simple enough, right? But what happens under the surface of the hash function is where things get a lot more interesting (and complicated). Here\u2019s a great video that helps to break hash functions down:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Hashing Algorithms and Security - Computerphile\" width=\"960\" height=\"540\" src=\"https:\/\/www.youtube.com\/embed\/b4b8ktEV4Bg?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So, how do you define a hash in a more technical sense? <strong>A hash function is a versatile one-way cryptographic algorithm that maps an input of any size to a unique output of a fixed length of bits. <\/strong>The resulting output, which is known as a <strong>hash digest<\/strong>, <strong>hash value<\/strong>, or <strong>hash code, is the resulting unique identifier we mentioned earlier<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you hash data, the resulting digest is typically smaller than the input that it started with. (Probably the exception here is when you\u2019re hashing passwords.) With hashing, it doesn\u2019t matter if you have a one-sentence message or an entire book \u2014 the result will still be a fixed-length chunk of bits (1s and 0s). This prevents unintended parties from figuring out how big (or small) the original input message was.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hash functions are primarily used for authentication but also have other uses.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Are Hash Functions Reversible?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The answer isn&#8217;t quite as straightforward as you may think. A hash function is called a one-way function because of the computing power, time, and cost it would take to brute force it. In a cybercriminal&#8217;s perfect world, if they had the ideal computer, time, and resources at their disposal, there&#8217;s a possibility that they could brute force it. But in the real world, it&#8217;s virtually impossible.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The reality is that trying every possible combination leading to a hash value is entirely impractical. So, for all intents and purposes, a hash function is considered an irreversible, one-way function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-properties-of-a-strong-hash-algorithm\">Properties of a Strong Hash Algorithm<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">So, what makes for a strong hashing algorithm? There are a few key traits that all good ones share:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Determinism<\/strong> \u2014 A hash algorithm should be <strong>deterministic<\/strong>, meaning that it always gives you an output of identical size regardless of the size of the input you started with. This means that if you\u2019re hashing a single sentence, the resulting output should be the same size as one you\u2019d get when hashing an entire book.<\/li>\n\n\n\n<li><strong>Pre-Image Resistance<\/strong> \u2014 The idea here is that a strong hash algorithm is one that\u2019s <a href=\"https:\/\/csrc.nist.gov\/glossary\/term\/Preimage_resistance\">preimage resistance,<\/a> meaning that it\u2019s infeasible to reverse a hash value to recover the original input plaintext message. Hence, the concept of hashes being irreversible, one-way functions.<\/li>\n\n\n\n<li><strong>Collision Resistance<\/strong> \u2014 A collision occurs when two objects collide. Well, this concept carries over in cryptography with hash values. If two unique samples of input data result in identical outputs, it\u2019s known as a collision. This is bad news and means that the algorithm you\u2019re using to hash the data is broken and, therefore, insecure. Basically, the concern here is that someone could create a malicious file with an artificial hash value that matches a genuine (safe) file and pass it off as the real thing because the signature would match. So, a good and trustworthy hashing algorithm is one that is resistant to these collisions.<\/li>\n\n\n\n<li><strong>Avalanche Effect<\/strong> \u2014 What this means is that any change made to an input, no matter how small, will result in a massive change in the output. Essentially, a small change (such as adding a comma) snowballs into something much larger, hence the term \u201c<a href=\"https:\/\/en.wikipedia.org\/wiki\/Avalanche_effect\">avalanche effect<\/a>.\u201d<\/li>\n\n\n\n<li><strong>Hash Speed <\/strong>\u2014 Hash algorithms should operate at a reasonable speed. In many situations, hashing algorithms should compute hash values quickly; this is considered an ideal property of a cryptographic hash function. However, this property is a little more subjective. You see, faster isn\u2019t always better because the speed should depend on how the hashing algorithm is going to be used. Sometimes, you want a faster hashing algorithm, and other times it\u2019s better to use a slower one that takes more time to run through. The former is better for website connections and the latter is better for password hashing.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-does-a-hash-function-do\">What Does a Hash Function Do?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">One purpose of a hash function in cryptography is to take a plaintext input and generate a hashed value output of a specific size in a way that can\u2019t be reversed. But they do more than that from a 10,000-foot perspective. You see, hash functions tend to wear a few hats in the world of cryptography. In a nutshell, strong hash functions:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ensure data integrity,<\/li>\n\n\n\n<li>Secure against unauthorized modifications,<\/li>\n\n\n\n<li>Protect stored passwords, and<\/li>\n\n\n\n<li>Operate at different speeds to suit different purposes.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-ensure-data-integrity\">Ensure Data Integrity<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Hash functions are a way to ensure data integrity in <a href=\"https:\/\/www.thesslstore.com\/blog\/what-is-pki-a-crash-course-on-public-key-infrastructure-pki\/\">public key cryptography<\/a>. What I mean by that is that hash functions serve as a check-sum, or a way for someone to identify whether data has been tampered with after it\u2019s been signed. It also serves as a means of identity verification.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, let\u2019s say you\u2019ve logged on to public Wi-Fi to send me an email. (Don\u2019t do that, by the way. It\u2019s very insecure.) &nbsp;So, you write out the message, sign it using your digital certificate, and send it on its way across the internet. This is what you might call prime <a href=\"https:\/\/www.thesslstore.com\/blog\/man-in-the-middle-attack\/\">man-in-the-middle attack<\/a> territory \u2014 meaning that someone could easily intercept your message (again, because public wireless networks are notoriously insecure) and modify it to suit their evil purposes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"560\" src=\"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/hashing-email-example-1024x560.png\" alt=\"\" class=\"wp-image-13938 addshadow\" srcset=\"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/hashing-email-example-1024x560.png 1024w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/hashing-email-example-300x164.png 300w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/hashing-email-example-768x420.png 768w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/hashing-email-example.png 1193w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>The example above is of a digitally signed email that\u2019s been manipulated in transit via a MitM attack. The hash digest changes completely when any of the email content gets modified after being digitally signed, signaling that it can\u2019t be trusted.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So, now I receive the message and I want to know it\u2019s legitimate. What I can do then is use the hash value your digital signature provides (along with the algorithm it tells me you used) to re-generate the hash myself to verify whether the hash value I create matches the one you sent. If it matches, great, it means that no one has messed with it. But if it doesn\u2019t\u2026 well, metaphoric klaxons sound, red flags go up, and I know to not trust it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Even if something tiny changed in a message \u2014 you capitalize a letter instead of using one that\u2019s lowercase, or you swap an exclamation mark where there was a period \u2014 it\u2019s going to result in the generation of an entirely new hash value. But that\u2019s the whole idea here \u2014 no matter how big or small a change, the difference in hash values will tell you that it isn\u2019t legitimate. &nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-secure-against-unauthorized-modifications\">Secure Against Unauthorized Modifications<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">One of the best aspects of a cryptographic hash function is that it helps you to ensure data integrity. But if you apply a hash to data, does it mean that the message can\u2019t be altered? No. But what it does is inform the message recipient that the message has been changed. That\u2019s because even the smallest of changes to a message will result in the creation of an entirely new hash value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of hashing kind of like you would a smoke alarm. While a smoke alarm doesn\u2019t stop a fire from starting, it does let you know that there\u2019s danger before it\u2019s too late.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-enable-you-to-verify-and-securely-store-passwords\">Enable You to Verify and Securely Store Passwords<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Nowadays, many websites allow you to store your passwords so you don\u2019t have to remember them every time you want to log in. But storing plaintext passwords like that in a public-facing server would be dangerous because it leaves that information vulnerable to cybercriminals. So, what websites typically do is hash passwords to generate hash values, which is what they store instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But password hashes on their own isn\u2019t enough to protect you against certain types of attacks, including brute force attacks. This is why you first need to add a salt. A <strong><a href=\"https:\/\/csrc.nist.gov\/glossary\/term\/salt\">salt<\/a><\/strong> is a unique, random number that\u2019s applied to plaintext passwords before they\u2019re hashed. This provides an additional layer of security and can protect passwords from password cracking methods like rainbow table attacks. (Keep an eye out for our future article on rainbow tables in the next few weeks.)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-operate-at-different-speeds-suiting-different-purposes\">Operate at Different Speeds, Suiting Different Purposes<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It\u2019s also important to note that hash functions aren\u2019t one-size-fits-all tools. As we mentioned earlier, different hash functions serve different purposes depending on their design and hash speeds. They work at different operational speeds \u2014 some are faster while others are much slower. These speeds can aid or impede the security of a hashing algorithm depending on how you\u2019re using it. So, some fall under the umbrella of secure hashing algorithms while others do not.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An example of where you\u2019d want to use a fast hashing algorithm is when establishing secure connections to websites. This is an example of when having a faster speed matters because it helps to provide a better user experience. However, if you were trying to enable your websites to store passwords for your customers, then you\u2019d definitely want to use a slow hashing algorithm. At scale, this would require a password-cracking attack (such as brute force) that takes up more time and computing resources for cybercriminals. You don\u2019t want to make it easy for them, right?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-where-you-ll-find-hashes-in-use\">Where You\u2019ll Find Hashes in Use<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">But where do you find hash functions? Look no further than the technology surrounding you. Hashing is useful for everything from signing new software and verifying digital signatures to securing the website connections in your computer and mobile web browsers. It\u2019s also great for indexing and retrieving items in online databases. For example, hashing is used for verifying:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Data blocks in cryptocurrencies and other <a href=\"https:\/\/www.thesslstore.com\/blog\/what-is-blockchain-how-does-blockchain-work\/\">blockchain<\/a> technologies.<\/li>\n\n\n\n<li>Data integrity of software, emails, and documents.<\/li>\n\n\n\n<li>Passwords and storing password hashes (rather than the passwords themselves) in online databases. (Note: This process requires a little \u201cdash\u201d of something special to make those hashes more secure \u2014 a salt).<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Hash functions can be found throughout public key cryptography. For example, you\u2019ll find hash functions are facilitated through the use of:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.thesslstore.com\/products\/ssl.aspx\">SSL\/TLS certificates<\/a> (i.e., <a href=\"https:\/\/www.thesslstore.com\/blog\/what-is-a-website-security-certificate-and-what-does-it-do-for-your-business\/\">website security certificates<\/a>),<\/li>\n\n\n\n<li><a href=\"https:\/\/www.thesslstore.com\/products\/code-signing-certificates.aspx\">Code signing certificates<\/a>,<\/li>\n\n\n\n<li><a href=\"https:\/\/www.thesslstore.com\/products\/email-document-signing-certificates.aspx\">Document signing certificates<\/a>, and<\/li>\n\n\n\n<li><a href=\"https:\/\/www.thesslstore.com\/products\/email-document-signing-certificates.aspx\">Email signing certificates<\/a>.<\/li>\n<\/ul>\n\n\n<span style=\"--tl-form-height-m:861.156px;--tl-form-height-t:899.625px;--tl-form-height-d:899.625px;\" class=\"tl-placeholder-f-type-shortcode_12653 tl-preload-form\"><span><\/span><\/span>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-does-hashing-work\">How Does Hashing Work?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When you hash a message, you take a string of data of any size as your input, run it through a mathematical algorithm that results in the generation of an output of a fixed length.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In some methods of hashing, that original data input is broken up into smaller blocks of equal size. If there isn\u2019t enough data in any of the blocks for it to be the same size, then padding (1s and 0s) can be used to fill it out. Then those individual blocks of data are run through a hashing algorithm and result in an output of a hash value. The process looks something like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/how-hashing-works-breakdown-1024x640.png\" alt=\"Hash function diagram that illustrates how hashing works\" class=\"wp-image-13939 addshadow\" srcset=\"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/how-hashing-works-breakdown-1024x640.png 1024w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/how-hashing-works-breakdown-300x187.png 300w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/how-hashing-works-breakdown-768x480.png 768w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/how-hashing-works-breakdown.png 1109w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Another more in-depth illustration of how hashing works.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Of course, this process would look a bit different if you were hashing passwords for storage in an online server. That process would involve the use of a salt. Basically, you\u2019d add a unique, random value to the message before running it through the hashing algorithm. By even just adding a single character, then you get an entirely new hash value at the end of the process.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-hashing-examples-with-different-algorithms\">Hashing Examples with Different Algorithms<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Okay, now that we know what a hash function is and what it does in a theoretical context, let\u2019s consider how it works logistically with a few examples. Let\u2019s say you have the following <a href=\"https:\/\/www.cliffsnotes.com\/cliffsnotes\/subjects\/literature\/what-are-the-riddles-that-gollum-asked-bilbo-in-the-hobbit\">riddle from Gollum<\/a> in <em>The Hobbit<\/em> as your input:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><em>\u201cIt cannot be seen, cannot be felt,<\/em><br><em>Cannot be heard, cannot be smelt.<\/em><br><em>It lies behind stars and under hills,<\/em><br><em>And empty holes it fills.<\/em><br><em>It comes out first and follows after,<\/em><br><em>Ends life, kills laughter.\u201d<\/em><\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">No, I\u2019m not going to give you the answer to the riddle if you haven\u2019t already figured it out. But if you were to run that riddle through a SHA-256 hashing algorithm, the resulting output would look like this on your screen:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>49FCA16A2271B34066DAA46492C226C4D4F61D56452A1E1A01A3201B234509A2<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And here is an illustration that shows how we get from A to B:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"974\" height=\"422\" src=\"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/hash-function-example.png\" alt=\"A basic hash function graphic that illustrates how you run an input through a hashing algorithm and it results in the creation of a hash digest output\" class=\"wp-image-13940 addshadow\" srcset=\"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/hash-function-example.png 974w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/hash-function-example-300x130.png 300w, https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/hash-function-example-768x333.png 768w\" sizes=\"auto, (max-width: 974px) 100vw, 974px\" \/><figcaption>As simple illustration of how a hashing algorithm takes an input and generates a unique hexadecimal output of a fixed length.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">What if you also decide to hash a smaller message? Say, for example, \u201cThe Lord of the Rings.\u201d Then your output would look the same in terms of size (as shown below) so long as you use the same hashing algorithm:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>01912B8E8425CFF006F430C15DBC4991F1799401F7B6BEB0633E56529FE148B9<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s because both example strings are 256 bits, which display on your screen as 64 hexadecimal characters per string. No matter how large or how small the message, it\u2019s always going to return an output that is the same size. Remember, hash algorithms are <strong>deterministic<\/strong>, so this means that they always result in the same size output regardless of the size of the input.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, if you were to take the same six-line riddle input and run it through an MD5 hash function, then you\u2019d wind up with a hash value that looks something like this instead:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>B53CE8A3139752B10AAE878A15216598<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see, the output is quite a bit shorter. That\u2019s because MD5 gives you a hash digest that\u2019s only 32 hexadecimal characters long. It\u2019s literally half the size of the digests that result from a SHA-256 hashing algorithm. But every time you run an MD5 hashing algorithm on a plaintext message, the resulting output will be the same size.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What if you decided to run the riddle through a SHA-512 hashing algorithm? Then we go to the opposite end of the spectrum in terms of length and your digest would look something like this (a 512-bit hexadecimal string):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>6DC1AAE5D80E8F72E5AF3E88A5C0FA8A71604739D4C0618182303EEEB1F02A0DBA319987D5B5F717E771B9DA1EAD7F3F92DC8BA48C064D41DD790D69D7D98B44<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-hash-vs-encryption\">Hash vs Encryption<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">But aren\u2019t hashing and encryption the same thing? Nope. Yes, they\u2019re both cryptography functions that use algorithms as a part of their processes. But that\u2019s just about where the similarities end. We covered the <a href=\"https:\/\/www.thesslstore.com\/blog\/difference-encryption-hashing-salting\/\">differences between hashing and encryption<\/a> in another article, so we aren\u2019t going to rehash all of that here.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As you now know, a <strong>hash function<\/strong> is a <strong>one-way function<\/strong>. The idea is that you can use it to convert readable plaintext data into an unreadable hexadecimal string of digits but not the other way around. <strong>Encryption<\/strong>, on the other hand, is known as a <strong>two-way function<\/strong>. That\u2019s because the whole point of being able to encrypt something is to prevent unauthorized or unintended parties from accessing the data. So, you encrypt data so that it can only be decrypted by the person who has the key.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-examples-of-common-hashing-algorithms-families-of-algorithms\">Examples of Common Hashing Algorithms &amp; Families of Algorithms<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Okay, we now know what hash functions are and how hashing algorithms work. Now it\u2019s time to learn what some of the most common hash algorithms are. <a href=\"https:\/\/csrc.nist.gov\/projects\/hash-functions\">NIST provides guidance on hash functions<\/a> as do several Federal Information Processing Standards (FIPS).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A few examples of common hashing algorithms include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Secure Hash Algorithm (SHA)<\/strong> \u2014 This family of hashes contains SHA-1, SHA-2 (a family within a family that includes SHA-224, SHA-256, SHA-384, and SHA-512), and SHA-3 (SHA3-224, SHA3-256, SHA3-384, and SHA3-512). SHA-1 has been deprecated and the most commonly hashing algorithm now is SHA-256.<\/li>\n\n\n\n<li><strong>Message Digest (MD)<\/strong> \u2014 This family of hashes contains a variety of hash functions that include MD2, MD4, MD5, and MD6. MD5 was long considered a go-to hashing algorithm but it\u2019s now considered broken because it results in collisions in the wild.<\/li>\n\n\n\n<li><strong>Windows NTHash<\/strong> \u2014 Also known as a Unicode hash or NTLM, this hash is commonly used by Windows systems because it\u2019s more secure than its predecessor, LM hash. However, <a href=\"https:\/\/www.varonis.com\/blog\/closer-look-pass-hash-part-iii-ntlm-will-get-hacked\/\">NTHash also still has vulnerabilities<\/a> to worry about as well, but this particular algorithm is integral to Windows systems. While the use of NTLMv1 is pretty much frowned upon nowadays, NTLM2 is something that\u2019s still in use.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Other examples of hash algorithms includeBLAKE 2 and BLAKE 3, RIPEMD-160, and WHIRLPOOL, among others.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-we-hashed-out-tl-dr\">What We Hashed Out (TL;DR)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There\u2019s a lot to know about hash functions and hashing in general. What they are, what they do, how they operate, and where you\u2019ll find them in use in computer communications and technologies.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Hashing is useful in data structure for indexing and retrieving dataset items. It also enables verification by detecting modifications.<\/li>\n\n\n\n<li>In cryptography, hashing takes plaintext data (input) and runs is through a mathematical process known as a hashing algorithm. This process generates an output, called a hash value, of a fixed length.<\/li>\n\n\n\n<li>A hash function is <strong>deterministic<\/strong>, meaning that, regardless of the size of the input, the output will always be the same size. It\u2019s also <strong>collision<\/strong> and <strong>preimage resistant<\/strong>.\n<ul class=\"wp-block-list\">\n<li>Collision resistance means that you can\u2019t have two unique inputs resulting in the same output, and<\/li>\n\n\n\n<li>Preimage resistance refers to a hash being a one-way function that can\u2019t be reversed to uncover the original plaintext message. For all intents and purposes, hash functions are not reversible.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>You can\u2019t manipulate data or make even tiny changes without entirely changing the resulting hash value. This is known as the <strong>avalanche effect<\/strong>.<\/li>\n\n\n\n<li>Different hashing algorithms \u2014 of which there are many families and individual algorithms \u2014 operate at different speeds and work on different sizes of data. For example, SHA-256 has an output of 256 bits (or what equates to a string of 64 hexadecimal characters).<\/li>\n<\/ul>\n\n\n<span style=\"--tl-form-height-m:801.312px;--tl-form-height-t:638.344px;--tl-form-height-d:638.344px;\" class=\"tl-placeholder-f-type-shortcode_12763 tl-preload-form\"><span><\/span><\/span>","protected":false},"excerpt":{"rendered":"<p>This cryptographic tool aids secure authentication and ensures data message integrity across digital channels \u2014 here\u2019s what to know about what a hash function is and how it works What\u2019s&#8230;<\/p>\n","protected":false},"author":17,"featured_media":13942,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":"","tve_updated_post":"","tve_custom_css":"","tve_user_custom_css":"","tve_globals":{},"tcb2_ready":0,"tcb_editor_enabled":0,"tve_landing_page":"","_tve_header":"","_tve_footer":""},"categories":[130],"tags":[13113,159,667],"class_list":["post-13936","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-everything-encryption","tag-hash-function","tag-hashing","tag-hashing-algorithms","post-with-tags"],"views":105548,"jetpack_featured_media_url":"https:\/\/www.thesslstore.com\/blog\/wp-content\/uploads\/2021\/01\/what-is-hash-function-in-cryptography.jpg","_links":{"self":[{"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/posts\/13936","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/comments?post=13936"}],"version-history":[{"count":0,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/posts\/13936\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/media\/13942"}],"wp:attachment":[{"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/media?parent=13936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/categories?post=13936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thesslstore.com\/blog\/wp-json\/wp\/v2\/tags?post=13936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}