<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Cryptography - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Cryptography - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 26 May 2026 04:43:41 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/cryptography/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ What Your Auth Library Isn't Telling You About Passwords: Hashing and Salting Explained ]]>
                </title>
                <description>
                    <![CDATA[ Before I started building auth into my own projects, I didn't think too deeply about what was happening to passwords behind the scenes. Like most developers, I installed a library, called a hash funct ]]>
                </description>
                <link>https://www.freecodecamp.org/news/passwords-hashing-and-salting-explained/</link>
                <guid isPermaLink="false">69b310eb93256dfc5303de72</guid>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ passwords ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Hashing ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Salting ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Tilda Udufo ]]>
                </dc:creator>
                <pubDate>Thu, 12 Mar 2026 19:15:55 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/61e84941-bb32-4029-9d58-39022488d29e.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Before I started building auth into my own projects, I didn't think too deeply about what was happening to passwords behind the scenes.</p>
<p>Like most developers, I installed a library, called a hash function, stored the result, and moved on. I see a random string like <code>\(2a11yMMbLgN9uY6J3LhorfU9iu....</code> in my database and assume my user's passwords are unbreakable. I knew it was a hashed password. But what was the <code>\)2a</code>? What was <code>11</code>? And if I couldn't reverse it, how was my app verifying logins at all?</p>
<p>If you've ever used bcrypt, Devise, Django's auth system, or really any authentication library, you've been protected from these details. That's good engineering. But understanding what's actually happening makes you a better developer, and it explains a lot of things that seem confusing or arbitrary until suddenly they don't.</p>
<p>By the end of this article, you'll be able to look at that string and know exactly what every part means.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>This article is written for developers who have used an auth library before but never looked closely at what it's doing. You don't need a cryptography background. If you've ever hashed a password and moved on, this is for you.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ol>
<li><p><a href="#heading-hashing-vs-encryption">Hashing vs Encryption</a></p>
</li>
<li><p><a href="#heading-why-a-plain-hash-isnt-enough">Why a Plain Hash Isn't Enough</a></p>
</li>
<li><p><a href="#heading-enter-salting">Enter Salting</a></p>
</li>
<li><p><a href="#heading-why-bcrypt-is-slow-and-why-thats-the-point">Why bcrypt Is Slow (and Why That's the Point)</a></p>
</li>
<li><p><a href="#heading-whats-actually-in-your-database">What's Actually in Your Database</a></p>
</li>
<li><p><a href="#heading-wrapping-up">Wrapping Up</a></p>
</li>
</ol>
<h2 id="heading-hashing-vs-encryption">Hashing vs Encryption</h2>
<p>Most developers use the terms <strong>hashing</strong> and <strong>encryption</strong> interchangeably. They're not the same thing, and the difference matters more than you might think.</p>
<p>Encryption is a two-way process. You take data, encrypt it with a key, and you can decrypt it later using that same key (or a related one). This is useful when you need to retrieve the original value. Storing a credit card number you'll need to charge later, or sending a message that the recipient needs to read.</p>
<p>Hashing is different. It's a one-way process. You put data in, you get a fixed-length string out, and there's no key that lets you reverse it. The original value is gone.</p>
<p>That might sound like a limitation. For passwords, it's actually exactly what you want.</p>
<p>Think about it: when a user logs in, you don't need to know their password. You just need to verify that what they typed matches what they set when they signed up. You can do that entirely with hashes. Hash what they typed, compare it to the stored hash, done. You never need the original.</p>
<p>This is why "forgot password" flows always ask you to set a new password rather than sending you your old one. Yes, sending you your old password over email might be risky but the actual reason is that they genuinely can't retrieve it. If they can email you your original password, that's a red flag. It means they stored it in a way that's reversible, which means it's not properly protected.</p>
<h2 id="heading-why-a-plain-hash-isnt-enough">Why a Plain Hash Isn't Enough</h2>
<p>So if hashing is one-way and irreversible, isn't that enough? Just hash every password before storing it and you're done?</p>
<p>Not quite.</p>
<p>The first problem is <strong>rainbow tables</strong>. A <a href="https://en.wikipedia.org/wiki/Rainbow_table">rainbow table</a> is a precomputed database of hashes for common passwords. An attacker who gets hold of your database doesn't need to reverse the hashes. They just look them up. If your user's password is "password123", its <a href="https://en.wikipedia.org/wiki/SHA-2">SHA-256</a> hash is always the same string, and that string is almost certainly already in a rainbow table somewhere.</p>
<p>The second problem is related. If two users have the same password, they'll have the same hash. So if an attacker cracks one, they've cracked all of them. In a database with thousands of users, that's a significant security risk.</p>
<p>Here's what that looks like in practice:</p>
<pre><code class="language-python">import hashlib

# Two users, same password
password = "password123"

hash_one = hashlib.sha256(password.encode()).hexdigest()
hash_two = hashlib.sha256(password.encode()).hexdigest()

print(hash_one == hash_two)  # True, every single time
</code></pre>
<p>The hash is deterministic. The same input always produces the same output. That's useful for a lot of things, but for passwords it creates a real vulnerability.</p>
<p>A plain hash gets you partway there. But it's not enough on its own.</p>
<h2 id="heading-enter-salting">Enter Salting</h2>
<p>The fix for both problems is something called a <strong>salt</strong>. And, no it's not your regular table salt.</p>
<p>A salt is a random string generated uniquely for each password. Before hashing, you combine the salt with the password, then hash the result.</p>
<pre><code class="language-python">import hashlib
import os

password = "password123"

# Generate a random salt
salt = os.urandom(16).hex()

# Combine salt and password, then hash
salted_password = salt + password
hashed = hashlib.sha256(salted_password.encode()).hexdigest()

print(f"Salt: {salt}")
print(f"Hash: {hashed}")
</code></pre>
<p>Now two users with the same password produce completely different hashes, because their salts are different. And because the salt is random and unique, it can't be precomputed into a rainbow table.</p>
<p>Here's the surprising part: <strong>the salt doesn't need to be secret</strong>. It gets stored alongside the hash in your database, in plain text. That might feel wrong at first. If an attacker has your database, they have the salt too.</p>
<p>But that's fine. The salt's job isn't to be secret. Its job is to make each hash unique so that precomputed tables are useless. An attacker who wants to crack a salted hash has to brute force each password individually, from scratch, using that specific salt. They can't reuse work across users.</p>
<p>That's a meaningful increase in the cost of an attack, even when the salt is visible.</p>
<h2 id="heading-why-bcrypt-is-slow-and-why-thats-the-point">Why bcrypt Is Slow (and Why That's the Point)</h2>
<p>Salting solves the rainbow table problem. But there's still a gap. If an attacker has your database and decides to brute force a password, they can just keep guessing. Hash a candidate password with the stored salt, compare it to the stored hash, repeat. With a fast hashing algorithm like SHA-256, a modern GPU can do billions of these comparisons per second.</p>
<p>That's the problem with using a general-purpose hash function for passwords. Algorithms like SHA-256 and MD5 were designed to be fast. That's great for things like verifying file integrity or generating checksums. For passwords, it's a liability.</p>
<p>This is where bcrypt comes in. <a href="https://en.wikipedia.org/wiki/Bcrypt">bcrypt</a> is a password hashing algorithm designed specifically to be slow. Not broken or inefficient by accident, but deliberately, configured-to-be slow. It has a <strong>cost factor</strong> (sometimes called a work factor) that controls how computationally expensive the hashing operation is.</p>
<pre><code class="language-python">import bcrypt

password = b"password123"

# The cost factor is set here (12 is a common production value)
hashed = bcrypt.hashpw(password, bcrypt.gensalt(rounds=12))

print(hashed)
</code></pre>
<p>Every time you increase the cost factor by 1, the hashing operation takes roughly twice as long. At a cost factor of 12, a single hash might take around 300 milliseconds on your server. That's imperceptible to a user logging in. But for an attacker trying to brute force millions of passwords, it turns a feasible attack into an impractical one.</p>
<p>The other advantage of a configurable cost factor is that you can increase it over time as hardware gets faster. What was slow enough in 2015 might not be slow enough today. bcrypt lets you adapt without changing the algorithm itself.</p>
<h2 id="heading-whats-actually-in-your-database">What's Actually in Your Database</h2>
<p>So far, we've talked about salting and cost factors as separate concepts. Here's the satisfying part: in bcrypt, they're all stored together in a single string. That string sitting in your database contains everything needed to verify a password, and once you know how to read it, it's not mysterious at all.</p>
<p>Here's a typical bcrypt hash:</p>
<pre><code class="language-plaintext">\(2a\)12$yMMbLgN9uY6J3LhorfU9iuLAUwKxyy8w42ubeL4MWy7Fh8B.CH/yO
</code></pre>
<p>Let's break it down:</p>
<ul>
<li><p><code>$2a</code> — the <strong>algorithm version</strong>. This tells your auth library which version of bcrypt was used to generate the hash.</p>
</li>
<li><p><code>$12</code> — the <strong>cost factor</strong>. This is the number we talked about in the previous section. A cost factor of 12 means the hashing operation was run 2¹² times.</p>
</li>
<li><p><code>\(yMMbLgN9uY6J3LhorfU9iu</code> — the <strong>salt</strong>. The first 22 characters after the final <code>\)</code> are the salt, stored right there in plain text alongside the hash. Your auth library reads this back out when verifying a login.</p>
</li>
<li><p><code>LAUwKxyy8w42ubeL4MWy7Fh8B.CH/yO</code> — the <strong>hash</strong> itself. The remaining characters are the actual output of the hashing operation.</p>
</li>
</ul>
<p>When a user logs in, your auth library doesn't need any extra information. It reads the algorithm version, cost factor, and salt directly from the stored string, hashes the login attempt using those same parameters, and compares the result. If they match, the password is correct.</p>
<p>This is why bcrypt verification works even though the salt is never stored separately. It was never separate to begin with.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>Next time you see a bcrypt string in your database, you'll know exactly what you're looking at. The algorithm version, the cost factor, the salt, and the hash, all encoded in a single string that your auth library knows how to read.</p>
<p>But the bigger takeaway is this: the libraries we rely on every day aren't magic. They're carefully designed systems built on top of concepts that are worth understanding.</p>
<p>Knowing why bcrypt is slow, why salting works even when the salt is visible, and why fast hash functions like SHA-256 are the wrong tool for passwords makes you a more intentional developer. You'll make better decisions about cost factors, you'll recognise a poorly implemented auth system when you see one, and you'll understand why a data breach where passwords were hashed with MD5 is so much worse than one where bcrypt was used.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Cryptography for Beginners: Full Python Course (SHA-256, AES, RSA, Passwords) ]]>
                </title>
                <description>
                    <![CDATA[ We just posted a course on the freeCodeCamp.org YouTube channel that will teach you all about cryptography. You'll learn essential techniques like hashing (SHA-256) for verifying file integrity, symmetric encryption (AES), and asymmetric encryption (... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/cryptography-for-beginners-full-python-course-sha-256-aes-rsa-passwords/</link>
                <guid isPermaLink="false">690bd280e9ceb53e15668053</guid>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ youtube ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Beau Carnes ]]>
                </dc:creator>
                <pubDate>Wed, 05 Nov 2025 22:41:04 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1762382425137/9fb68a83-e3ca-41a2-a1c0-ed203bae83b4.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>We just posted a course on the freeCodeCamp.org YouTube channel that will teach you all about cryptography. You'll learn essential techniques like hashing (SHA-256) for verifying file integrity, symmetric encryption (AES), and asymmetric encryption (RSA) using public and private keys. The practical focus of the tutorial involves building a fully functional command-line cryptography tool in Python. Upon completion, you'll have a complete practical toolkit and the skills to safeguard data, secure passwords, and deter tampering.</p>
<p>This course was developed by Thanishkka. She is part of Hack Club. Hack Club is a global non-profit organization that creates a community for high school students interested in coding and making things with technology.</p>
<p>Here are the sections in the course:</p>
<ul>
<li><p>Introduction: What is Cryptography?</p>
</li>
<li><p>About Hack Club and the Course Creator</p>
</li>
<li><p>Cryptography Basics &amp; Cybershe Demo</p>
</li>
<li><p>Three Main Areas: Hashing, Symmetric, and Asymmetric Encryption</p>
</li>
<li><p>Deep Dive into Hashing (SHA 256) and File Integrity</p>
</li>
<li><p>Symmetric Encryption with AES (Key, IV, and Modes)</p>
</li>
<li><p>Asymmetric Encryption with RSA (Public and Private Keys)</p>
</li>
<li><p>Setup: Python and VS Code Installation</p>
</li>
<li><p>Creating and Activating a Virtual Environment</p>
</li>
<li><p>Installing Required Python Libraries (cryptography, zxcvbn, bcrypt)</p>
</li>
<li><p>Coding the File Hashing Function (<a target="_blank" href="http://hash.py">hash.py</a>)</p>
</li>
<li><p>Coding the File Integrity Verification Function</p>
</li>
<li><p>Coding AES Symmetric Encryption/Decryption (<a target="_blank" href="http://encryption.py">encryption.py</a>)</p>
</li>
<li><p>Coding RSA Asymmetric Encryption/Decryption</p>
</li>
<li><p>Coding the Password Strength Checker (<a target="_blank" href="http://password.py">password.py</a>)</p>
</li>
<li><p>Coding Password Hashing and Verification (using bcrypt)</p>
</li>
<li><p>Building the Command Line UI (<a target="_blank" href="http://main.py">main.py</a>)</p>
</li>
<li><p>Final Toolkit Demo and Testing</p>
</li>
<li><p>Conclusion and Next Steps</p>
</li>
</ul>
<p>Watch the full course on the <a target="_blank" href="https://youtu.be/kb_scuDUHls">freeCodeCamp.org YouTube channel</a> (1-hour watch).</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/kb_scuDUHls" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The Cryptography Handbook: Exploring RSA PKCSv1.5, OAEP, and PSS ]]>
                </title>
                <description>
                    <![CDATA[ The RSA algorithm was introduced in 1978 in the seminal paper, "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems". Over the decades, as RSA became integral to secure communications, various vulnerabilities and attacks have emerg... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-cryptography-handbook-rsa-algorithm/</link>
                <guid isPermaLink="false">67edb47680c0ce2ff2faebb9</guid>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ MathJax ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Hamdaan Ali ]]>
                </dc:creator>
                <pubDate>Wed, 02 Apr 2025 22:04:38 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1743630655223/f7e0c094-2103-42cd-97bd-be79d14fff67.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>The RSA algorithm was introduced in 1978 in the seminal paper, "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems". Over the decades, as RSA became integral to secure communications, various vulnerabilities and attacks have emerged, underscoring the importance of understanding and implementing RSA correctly.</p>
<p>This handbook will help you understand the internal workings of the RSA algorithm, how they have evolved over the years, and the schemes defined under various RFCs. This knowledge will help you make informed choices about the most suitable RSA schemes depending on your business requirements.</p>
<p>In this handbook, we’ll begin by exploring the foundational principles of the RSA algorithm. By examining its mathematical underpinnings and historical evolution, you will gain insight into the diverse array of attacks that have emerged over the years.</p>
<p>The narrative unfolds as an evolutionary journey: from the original, straightforward (textbook) RSA implementation, through the discovery of vulnerabilities, to the development of effective countermeasures, and further refinements as new challenges were encountered. This progression illuminates how RSA has transformed over time and also demonstrates how modern cryptographic libraries have integrated these advancements to achieve secure implementations in today’s applications.</p>
<p>You can also watch the associated video here:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/jpcLbsuHWbU" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p> </p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-prerequisites">Prerequisites</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-alice-bob-paradigm">The Alice-Bob Paradigm</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-birth-of-the-rsa-cryptosystem">The Birth of the RSA Cryptosystem</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-prime-numbers-and-composite-moduli">Prime Numbers and Composite Moduli</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-euler-totient-function">The Euler Totient Function</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-computing-the-keys">Computing the Keys</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-rsa-operations">RSA Operations</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-encryption">Encryption</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-decryption">Decryption</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-digital-signatures">Digital Signatures</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-issues-with-eulers-totient-function-in-rsa">Issues with Euler’s Totient Function in RSA</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-carmichael-function">The Carmichael Function</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-mathematical-implication-of-the-carmichael-function">Mathematical Implication of The Carmichael function</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-carmichael-function-in-modern-implementations">The Carmichael Function in Modern Implementations</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-issues-with-raw-rsa">Issues with Raw RSA</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-exploiting-textbook-rsas-determinism-and-malleability">Exploiting Textbook RSA’s Determinism and Malleability</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-key-generation-setup">Key Generation (Setup)</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-encryption-process">Encryption Process</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-determinism-exploit-ciphertext-guessing-attack">Determinism Exploit (Ciphertext Guessing Attack)</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-malleability-exploit-ciphertext-manipulation-attack">Malleability Exploit (Ciphertext Manipulation Attack)</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-low-exponent-attacks">Low-Exponent Attacks</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-hastads-broadcast-attack-low-exponent-meets-multiple-recipients">Håstad’s Broadcast Attack: Low Exponent Meets Multiple Recipients</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-introduction-to-padding-schemes-in-rsa">Introduction to Padding Schemes in RSA</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-public-key-cryptography-standards-pkcs1-v15">Public Key Cryptography Standards (PKCS#1 v1.5)</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-the-mathematics-behind-pkcs1-v15">The Mathematics Behind PKCS#1 v1.5</a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-bleichenbacher-attack">The Bleichenbacher Attack</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-optimal-asymmetric-encryption-padding-oaep">Optimal Asymmetric Encryption Padding (OAEP)</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-the-mathematics-behind-oaep">The Mathematics Behind OAEP</a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-why-sha-1-or-md5-are-safe-in-rsa-oaep">Why SHA-1 or MD5 Are Safe in RSA-OAEP</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-label-hashing">Label Hashing</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-mask-generation-function-mgf1">Mask Generation Function (MGF1)</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-adoption-in-cryptographic-libraries-pkcs1-v15-vs-oaep">Adoption in Cryptographic Libraries (PKCS#1 v1.5 vs OAEP)</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-enhancing-digital-signatures-the-transition-to-pss">Enhancing Digital Signatures: The Transition to PSS</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-problems-with-early-rsa-signature-schemes">Problems with Early RSA Signature Schemes</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-birth-of-the-probabilistic-signature-scheme-pss">Birth of the Probabilistic Signature Scheme (PSS)</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-mathematics-behind-pss">The Mathematics Behind PSS</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-the-road-ahead-assessing-rsas-long-term-viability">The Road Ahead: Assessing RSA’s Long-Term Viability</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-references">References</a></p>
</li>
</ul>
<h2 id="heading-prerequisites">Prerequisites</h2>
<ol>
<li><strong>Linear Algebra:</strong> A foundational understanding of Linear Algebra and Modular Arithmetic will help you understand certain sections of the handbook, though it is not an absolute requirement. This handbook provides comprehensive explanations of mathematical expressions and their underlying concepts as they arise.</li>
</ol>
<p>For a concise and relevant introduction to the Chinese Remainder Theorem (CRT) in the context of the handbook, you may find this resource helpful: <a target="_blank" href="https://www.youtube.com/watch?v=Mt9v7-xBuaA">CRT, RSA, and Low Exponent Attacks | YouTube</a>.</p>
<ol start="2">
<li><strong>Patience (and a Sense of Adventure):</strong> RFCs can sometimes get dull to read, and research papers can feel intimidating at first glance. This handbook is designed to make standard cryptographic concepts accessible to everyone, guiding you through each step with clarity and intuition. Every concept is reinforced with clear, step-by-step examples, ensuring not only a thorough understanding but also familiarity with widely used standard notations. So take your time, take a deep breath, and embrace the journey.</li>
</ol>
<p>For visual learners, the associated video may offer a more engaging experience.</p>
<h2 id="heading-the-alice-bob-paradigm"><strong>The Alice-Bob Paradigm</strong></h2>
<p>Throughout this handbook, you will come across numerous sequence diagrams and mathematical proofs that use the Alice-Bob Paradigm.</p>
<p>The Alice-Bob paradigm is a common convention in cryptography where two generic entities, often named Alice and Bob, are used to illustrate various scenarios, protocols, or cryptographic principles.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742677993632/c9312974-4cb9-4496-8b23-b6d0d61c0a45.png" alt="The Alice Bob Paradigm" class="image--center mx-auto" width="818" height="483" loading="lazy"></p>
<p>These characters represent two parties engaged in communication, with Alice typically representing the sender or initiator, and Bob representing the receiver or responder.</p>
<p>We often introduce Eve as a third party, symbolizing an eavesdropper or potential attacker, adding an element of security risk, and illustrating scenarios where external entities might attempt to intercept or manipulate the communication.</p>
<h2 id="heading-the-birth-of-the-rsa-cryptosystem">The Birth of the RSA Cryptosystem</h2>
<p>The year 1978 witnessed the birth of a new era in cryptography with the introduction of the RSA cryptosystem, named after its inventors (Rivest, Shamir, and Adleman).</p>
<p>This development, introduced in the paper "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems", provided a method for secure digital communication and laid the foundation for modern public-key cryptography.  </p>
<p>At the heart of RSA lies elementary number theory – specifically, the properties of prime numbers and modular arithmetic. Let’s first understand how these key concepts form its mathematical foundations.</p>
<h3 id="heading-prime-numbers-and-composite-moduli">Prime Numbers and Composite Moduli</h3>
<p>The algorithm starts by selecting two large prime numbers, denoted as <em>p</em> and <em>q</em>. Their product (\(n = p \times q\)) forms the modulus for both the public and private keys.  </p>
<p>The security of RSA depends heavily on the fact that, while multiplying these primes is computationally straightforward, factoring the resulting large composite number <em>n</em> is considered infeasible for sufficiently large primes.  </p>
<p>At this point, it’s important to note that p and q must be large prime numbers to ensure RSA’s security. Fortunately, modern libraries handle this automatically by using well-established prime-generation algorithms. As a result, you can focus on higher-level aspects of your applications without having to manage the low-level details of prime selection.</p>
<p>For instance, let’s have a look at OpenSSL’s RSA key generation routine which performs several checks to ensure that the resulting modulus \(n = p \times q \) meets the desired bit-length requirements:</p>
<p>The below snippet right-shifts the product of the generated primes (stored in <code>r1</code>) by <code>bitse - 4</code> bits to isolate the top 4 bits, which are then checked to ensure that the modulus meets the desired size criteria.</p>
<pre><code class="lang-c"><span class="hljs-keyword">if</span> (!BN_rshift(r2, r1, bitse - <span class="hljs-number">4</span>))
    <span class="hljs-keyword">goto</span> err;
bitst = BN_get_word(r2);
</code></pre>
<p>The extracted bits (<code>bitst</code>) are then compared against a predefined range (from <code>0x9</code> to <code>0xF</code>). This range ensures that the most significant byte of the modulus isn’t too small or too large.</p>
<pre><code class="lang-c"><span class="hljs-keyword">if</span> (bitst &lt; <span class="hljs-number">0x9</span> || bitst &gt; <span class="hljs-number">0xF</span>) {
    bitse -= bitsr[i];
</code></pre>
<p>If the significant bits do not fall within the desired range, the bit length is adjusted and the prime-generation process is retried. If the number of retries exceeds a set limit, the entire process is restarted.</p>
<pre><code class="lang-c"><span class="hljs-keyword">if</span> (!BN_GENCB_call(cb, <span class="hljs-number">2</span>, n++))
    <span class="hljs-keyword">goto</span> err;
<span class="hljs-keyword">if</span> (primes &gt; <span class="hljs-number">4</span>) {
    <span class="hljs-keyword">if</span> (bitst &lt; <span class="hljs-number">0x9</span>)
        adj++;
    <span class="hljs-keyword">else</span>
        adj--;
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (retries == <span class="hljs-number">4</span>) {
    i = <span class="hljs-number">-1</span>;
    bitse = <span class="hljs-number">0</span>;
    sk_BIGNUM_pop_free(factors, BN_clear_free);
    factors = sk_BIGNUM_new_null();
    <span class="hljs-keyword">if</span> (factors == <span class="hljs-literal">NULL</span>)
        <span class="hljs-keyword">goto</span> err;
    <span class="hljs-keyword">continue</span>;
}
retries++;
<span class="hljs-keyword">goto</span> redo;
</code></pre>
<p>To ensure that the numbers are necessarily primes, these libraries use a combination of probabilistic tests, including the Rabin-Miler Primality Testing, and sieving methods to quickly eliminate non-prime candidates.</p>
<h3 id="heading-the-euler-totient-function">The Euler Totient Function</h3>
<p>For a number <em>n</em> that is the product of two primes, the Euler totient function is given by:</p>
<p>$$\varphi(n) = (p-1)(q-1)$$</p><p>This function counts the number of integers less than \(n\) that are co-prime to \(n\). Euler’s theorem, which states that for any integer <em>a</em> co-prime to <em>n</em>, \( a^{\varphi(n)} \equiv 1 \pmod{n}\) plays a central role in proving why RSA’s operations are reversible.</p>
<p>But most modern RSA cryptosystems use the Carmichael function instead of the Euler’s Totient Function. We will examine the reasoning behind this shift in the next few sections.</p>
<h3 id="heading-computing-the-keys">Computing the Keys</h3>
<p>Now we select an integer \(e\) such that \(1 &lt; e &lt; \varphi(n)\)and \(\gcd(e, \varphi(n)) = 1\). This \(e\) becomes the public exponent you see as a parameter in the RSA function calls you make.</p>
<p>With that done, now let’s determine \(d\) as the modular multiplicative inverse of \(e \, \, modulo \, \varphi(n)\). In other words, \(d\) is computed such that:</p>
<p>$$e \times d \equiv 1 \pmod{\varphi(n)}$$</p><p>This step is the mathematical linchpin ensuring that decryption is the inverse operation of encryption.</p>
<p>In the 1978 paper, the authors explicitly provided these formulas and steps. They showed that if you encrypt a message m using \(c = m^e \mod n\) and then decrypt using \(m = c^d \mod n \) , the original message is recovered – thanks to the properties of modular exponentiation and Euler’s theorem. This mathematical framework was novel at the time and immediately set the stage for a new era in cryptography.</p>
<h2 id="heading-rsa-operations">RSA Operations</h2>
<p>Now that the mathematical foundations are laid, the RSA algorithm can be seen as a set of three core operations: Encryption, Decryption, and Signing. Throughout this handbook's next sections, we will critically analyze these operations and learn about several pitfalls in each. Then we will examine how these were averted with the birth of new schemes, each to solve a new issue discovered on the way.</p>
<h3 id="heading-encryption">Encryption</h3>
<p>With the public key \((n, e)\) available to everyone, any user can encrypt a message \(m\) (where \(m\) is first encoded as an integer in the range \(0 \leq m &lt; n\) ) using the formula:</p>
<p>$$c = m^e \mod n$$</p><p>Here, c is the ciphertext. Because the operation is based on modular exponentiation, even if m is known, recovering m from c without knowing d is computationally hard.</p>
<h3 id="heading-decryption">Decryption</h3>
<p>The intended recipient, who possesses the private key \(d\), decrypts the cipher text \(c\) by computing:</p>
<p>$$m = c^d \bmod n$$</p><p>Using the relationship (\(e \times d \equiv 1 \pmod{\varphi(n)}\)) and properties from Euler’s theorem, the above operation exactly inverts the encryption step, recovering the original message \(m\).</p>
<p>This ensures that only the holder of the private key can read the encrypted message. This is the backbone of RSA’s use in secure communication.</p>
<p>The sequence diagram below wraps up our discussion so far:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742754978876/9b007639-8595-4d11-93ff-355820cb98c7.png" alt="Sequence Diagram: Textbook RSA Encryption" class="image--center mx-auto" width="732" height="540" loading="lazy"></p>
<h3 id="heading-digital-signatures">Digital Signatures</h3>
<p>Digital signatures fulfill a different security goal: authenticity and integrity rather than confidentiality. While encryption and decryption use the public key for “locking” and the private key for “unlocking,” digital signatures reverse these roles.</p>
<h4 id="heading-1-signing">1. Signing</h4>
<p>The author of a message uses their private key \(d\) to compute a signature \(s\) on the message \(m\), guided by the formula mentioned below:</p>
<p>$$s = m^d \bmod n$$</p><p>This can later be verified by others using the corresponding public key. The purpose here is not to recover a secret message but to create a proof of authenticity.</p>
<h4 id="heading-2-verification">2. Verification:</h4>
<p>Anyone with the public key \((n, e)\) can verify that the signature s indeed belongs to the message \(m\) by computing:</p>
<p>$$m \equiv s^e \bmod n$$</p><p>If the equivalence holds, it confirms two key points: That the message has not been tampered with (that is, integrity), and that the signature must have been generated using the private key d (that is, authenticity).<br>As long as \(d\) is kept secret, only the legitimate signer can produce a valid signature. Take at look at the sequence diagram below to understand the complete process.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742755268516/6dea4239-f214-42c4-96c7-5fc55c7249d9.png" alt="Sequence Diagram: Textbook RSA Signatures" class="image--center mx-auto" width="732" height="540" loading="lazy"></p>
<h2 id="heading-issues-with-eulers-totient-function-in-rsa">Issues with Euler’s Totient Function in RSA</h2>
<p>While using Euler’s Totient Function works well in theory, implementers of the scheme realized its practical downsides. Simply put, the primary issue was that Euler’s Totient Function can lead to a larger private exponent \(d\) than what was necessary.</p>
<p>To completely appreciate this fact, let’s take a step back to understand why the size of the private exponent \(d\) matters in RSA.</p>
<p>RSA decryption (or signing) involves computing \(m^d ~~mod ~n\) which is done via modular exponentiation. The time complexity of exponentiation algorithms (like square-and-multiply) grows with the number of bits in \(d\). A larger \(d\) means more multiplications and squarings, that is slower decryption.</p>
<p>In practice, if using the Euler’s Totient Function makes \(d\) roughly twice as large as what is required, then decryption can be almost twice as slow compared to using the minimal \(d\). This inefficiency is especially noticeable when \(e\) is small (common public exponents like 3 or 65537). A small \(e\) leads to a very large \(d\) under \(φ(n)\).</p>
<p>Beyond performance, having an unnecessarily large \(d\) can increase storage size slightly (a few more bytes for the key). This can also lead to interoperability quirks, which is why standards and protocols such as FIPS 186-4 [1] and RFC 8017 [2] expect \(d\) to be below a certain size. We will take a detailed look at this in the next section.</p>
<p>To combat these issues, cryptographers utilized the Carmichael function to generate RSA keys. Before we dive into how the Carmichael function helps our case, let’s quickly understand what the Carmichael function actually is.</p>
<h2 id="heading-the-carmichael-function">The Carmichael Function</h2>
<p>The Carmichael Function, represented by \(λ(n)\), also known as the reduced totient or least universal exponent, is defined as the smallest positive integer \(m\) such that for every integer \(a\) co-prime to \(n\), \( a^m ≡ 1 (mod n)\).</p>
<p>To put this in easy terms, \(λ(n)\) is the exponent of the multiplicative group modulo \(n\) (the least common multiple of the orders of all elements). For RSA-style moduli (product of primes), the Carmichael function is guided by the formula:</p>
<p>$$\lambda(n) = \operatorname{lcm}(p-1,\,q-1)$$</p><p>where \(n = p . q\) with \(p\) and \(q\) being the large primes.</p>
<p>You may now understand the Carmichael function better if we put it in the following way: \(λ(n)\) is the least common multiple of \(λ(n)\) of each prime power dividing n. So for a prime \(p\), \(λ(p) = φ(p) = p – 1\), and for two primes, we take the \(lcm\) of \(p-1 \) and \(q-1.\)</p>
<h3 id="heading-mathematical-implication-of-the-carmichael-function">Mathematical Implication of The Carmichael function</h3>
<p>The Carmichael function \(λ(n)\) is a “tighter” bound. What this means is that \(λ(n)\) divides \(φ(n)\) (since the exponent of a finite group always divides the group order by Lagrange’s Theorem [3])</p>
<p>If \(p\) and \(q\) are both odd primes, then \(p–1\) and \(q–1 \) are even, so their least common multiple is roughly half of \((p–1)(q–1)\). Mathematically:</p>
<p>$$λ(n) = \dfrac{(p–1)(q–1)} {gcd(p–1, q–1)}$$</p><p>We can observe that this \(λ(n)\) is lesser than or equal to \(φ(n)\) and often considerably smaller. This means \(λ(n)\) provides the minimal exponent needed for RSA’s correctness, whereas \(φ(n)\)might be a larger number that still works but isn’t necessary.</p>
<p>When you choose two large random primes \(p\) and \(q\), you have:</p>
<p>$$\varphi(n) = (p-1)(q-1) \approx n,$$</p><p>because for large primes, the subtracted ones make only a small difference compared to \(p\) and \(q\) themselves.</p>
<p>Now, since both \(p-1\) and \(q-1 \) are even, they each have a factor of 2. If those are their only common factors (which is often the case for random primes), then:</p>
<p>$$\lambda(n) = \mathrm{lcm}(p-1, q-1) \approx \frac{\varphi(n)}{2}.$$</p><p>When you compute the private exponent \(d\) as the modular inverse of \(e\) (a small number) modulo \( \varphi(n)\) versus modulo \(\lambda(n)\), the range from which \(d\) is chosen is roughly twice as large in the former case. That means the typical \(d\) when computed modulo \(\varphi(n)\) can be about twice as large as when computed modulo \(\lambda(n)\). A larger \(d\) means that during decryption (or signing) the modular exponentiation \(c^d \mod n\) takes slightly more time.</p>
<p>Intuitively, using \(λ(n)\) ensures we don’t “overshoot” the exponent required for the modular arithmetic to cycle back to 1.</p>
<p>A smaller \(d\) makes every RSA decryption and signature operation faster. For instance, if \(λ(n)\) is roughly half of \(φ(n)\), then \(d\) will have one less bit than it would otherwise, cutting the exponentiation work by about 50%. This is a free performance gain, as we aren’t changing the security assumptions or the key size \(n\), just using the mathematically tight value for the exponent. The RSA algorithm’s security is not weakened by this and now the \(d\) is different but functionally equivalent.</p>
<h3 id="heading-the-carmichael-function-in-modern-implementations">The Carmichael Function in Modern Implementations</h3>
<p>The critical property for RSA (\(e·d ≡ 1 ~mod ~~λ(n)\)) is both necessary and sufficient for correct decryption, thanks to Carmichael’s theorem. So there’s no need for \(d\) to also satisfy the stronger condition modulo \(φ(n)\).</p>
<p>By switching to computing \(d ~ modulo ~~ λ(n)\) (i.e., \(d = e^{-1} ~mod ~~λ(n)\)), we directly get the smallest working private exponent. Ronald Rivest himself noted this optimization in his 1999 seminal paper [4], stating that solving for \(d\) using \( λ(n)\) instead of \(φ(n)\) is slightly preferable because it can result in a smaller value for d.</p>
<p>Over time, the use of \( λ(n)\) in RSA moved from an academic suggestion to an industry standard. Today’s cryptographic standards explicitly acknowledge or require the \(λ(n)\) approach.</p>
<p>For example, the official RSA standard (PKCS #1 v2.2, RFC 8017 [2]) defines the RSA key generation in terms of \(λ(n)\). It specifies that the private exponent \(d\) is chosen such that \(e·d ≡ 1 (mod λ(n))\) (with \(λ(n) = lcm(p–1, q–1)\)). In other words, PKCS #1 expects the Carmichael function to be used for the modulus of the exponent. Likewise, NIST’s FIPS 186-4 (Digital Signature Standard) mandates that \(d\) be less than \(λ(n)\).</p>
<p>Any RSA key where \(d\) is larger than \(λ(n)\) is considered non-compliant in those strict contexts. This effectively forces implementations to use the smaller \(λ(n)\)-based exponent, since any “oversized” \(d\) can be reduced \(mod ~~λ(n)\) to meet the criterion.</p>
<p>Standards such as FIPS 186-4 [1] (the Digital Signature Standard) and RFC 8017 [2] (which specifies PKCS#1 v2.2 for RSA Cryptography) include requirements or recommendations that imply the private exponent \(d\) should be as small as possible and ideally less than \( \lambda(n)\). Using \(\lambda(n)\) (the least common multiple of \(p-1\) and \(q-1\)) directly produces the smallest valid \(d\), whereas using \(\varphi(n)\) often results in a \(d\) that is larger than necessary. This not only improves performance (by reducing the number of modular multiplications needed during decryption/signing) but also helps maintain interoperability with protocols that expect d to be below a certain size.</p>
<p>The Python cryptography library (PyCA cryptography) explicitly documents [5] that it uses Carmichael’s totient to generate the “smallest working value of \(d\),” noting that older implementations (including the original RSA paper) used Euler’s totient and ended up with larger exponents. OpenSSL also uses the Carmichael function in their low-level RSA APIs [6].</p>
<p>This shift to the Carmichael function ensures that under the hood your RSA key is a bit more efficient than the ones from the late 1970s while providing the same level of security.</p>
<h2 id="heading-issues-with-raw-rsa">Issues with Raw RSA</h2>
<p>Raw or “Textbook” RSA soon turned out to be insecure when two major weaknesses were discovered.</p>
<p>The operations involved in RSA are entirely deterministic, which means that for a given plaintext \(m\), encryption always produces the same cipher text \(C = m^e \mod n\).</p>
<p>An eavesdropper or an attacker, say Eve, can guess or derive plain texts by exploiting the predictability of outputs. Since RSA encryption is a public operation, an attacker can encrypt likely messages and compare results to a target cipher text – a trivial chosen plaintext <em>attack</em>.</p>
<p>Besides this, textbook RSA is also malleable. This means that its algebraic structure allows attackers to manipulate cipher texts in meaningful ways. For instance, given a cipher text \(C = RSA(M)\), an attacker can multiply it by the encryption of a known value (say, r) to produce a new cipher text \(C’ = C · r^e ~~mod ~n\), which decrypts to the plaintext \(M·r\). When the legitimate receiver decrypts \(C'\), the result is \(M·r\), from which the attacker can often recover \(M\).</p>
<p>Let’s understand these vulnerabilities with a small practical example.</p>
<h2 id="heading-exploiting-textbook-rsas-determinism-and-malleability">Exploiting Textbook RSA’s Determinism and Malleability</h2>
<h3 id="heading-key-generation-setup"><strong>Key Generation (Setup)</strong></h3>
<p>For our toy example, we’ll choose small prime numbers and generate an RSA key pair:</p>
<p>Let’s select the values of \(p =3\) and \(q=11\). Both of these values are prime. Now, compute the modulus and Totient Function as follows:</p>
<p>$$\begin{gather} \begin{split} n = p × q = 3 × 11 = 33 \\ φ(n) = (p – 1) × (q – 1) = 2 × 10 = 20 \end{split} \end{gather}$$</p><p>Now choose the public exponent. Let’s consider \(e=3\) since it is coprime with \( φ(n) = 20\), and \(gcd(3, 20) = 1\).</p>
<p>Now let’s compute the private exponent. We know that d is the modular inverse of \(e ~~mod ~φ(n)\). We need to find d such that \((d × e) ≡ 1~~ (mod ~20)\). Using this knowledge we can compute \(d = 7\) as \(3 × 7 = 21 ≡ 1 ~~ (mod~ 20)\).</p>
<p>Finally, the public key is \((n = 33, ~ e = 3)\) and the private key (secret) is \(d = 7\).</p>
<h3 id="heading-encryption-process">Encryption Process</h3>
<p>Now, let’s encrypt a simple message using the above key. Let us select our plaintext to be \(M = 4\). The cipher text in this case would be:</p>
<p>$$\begin{gather} \begin{split} C = 4^3 ~~mod ~33 \\ C = 64 ~~mod ~33 \\ C = 64 – 33×1 = 31 \end{split} \end{gather}$$</p><p>To consolidate the findings so far, if we encrypt message \(4\) with the public key \((e=3, n=33)\), we will produce the cipher text \(31\). Now, let’s try the exploits.</p>
<h3 id="heading-determinism-exploit-ciphertext-guessing-attack">Determinism Exploit (Ciphertext Guessing Attack)</h3>
<p>Textbook RSA is deterministic – the same plaintext always yields the same ciphertext (with no randomness involved). An attacker who intercepts the ciphertext \(C=31\) can exploit this by encrypting likely plaintext guesses and comparing results:</p>
<p>The adversary, say Eve, will try encrypting candidate plaintexts with the public key and see which one produces \(31\). They may pick randomized values to increase their efficiency:</p>
<p>$$\begin{gather} \begin{aligned} Guess~ M = 1 ⇒ 1^3~~ mod ~33 = 1 \\ Guess~ M = 2 ⇒ 2^3~~ mod ~33 = 8 \\ Guess~ M = 3 ⇒ 3^3~~ mod ~33 = 27 \\ Guess~ M = 4 ⇒ 4^3~~ mod ~33 = 31 \\ \end{aligned} \end{gather}$$</p><p>By simply comparing ciphertexts, the attacker finds that encrypting \(4\) yields 31, which matches the intercepted ciphertext. Thus, the attacker learns the original plaintext \(M\) was \(4\). This is possible because there’s no randomization in textbook RSA – an eavesdropper can identify a message by trial encryption of guesses, breaking confidentiality if the message space is small or guessable.</p>
<h3 id="heading-malleability-exploit-ciphertext-manipulation-attack">Malleability Exploit (Ciphertext Manipulation Attack)</h3>
<p>Raw RSA is also malleable. This means an attacker can take a ciphertext and modify it in a way that results in a predictable change in the decrypted plaintext. Let’s understand how this works.</p>
<p>RSA has a multiplicative property, that is, multiplying two ciphertexts corresponds to multiplying their plaintexts before encryption:</p>
<p>$$E(M_1) \cdot E(M_2) \mod n = (M_1^e \mod n)\times(M_2^e \mod n) \mod n = (M_1 \cdot M_2)^e \mod n$$</p><p>The sequence diagram below explains how the malleability exploit works in naive RSA.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1741314973046/6be306c5-3ca6-4ea8-8daf-d1937b6459df.png" alt="Sequence Diagram: Malleability Exploit" class="image--center mx-auto" width="828" height="640" loading="lazy"></p>
<p>Alice sends a ciphertext to Bob after the initialization phase. Note that by this point, n and e are public knowledge. Eve intercepts this ciphertext by using mechanisms such as a MiTM (Man in the Middle) attack.</p>
<p>Now, Eve picks a known value to manipulate the message. Let’s say the attacker chooses \(X = 2\) (with the intent to double the original plaintext).</p>
<p>Then they compute the encryption of X using the public key:</p>
<p>$$E(X) = 2^3 \mod 33 = 8.$$</p><p>Now, Eve multiplies the original ciphertext by this value (mod n) to get a new ciphertext:</p>
<p>$$\begin{gather} \begin{split} C{\prime} = C \times E(X) \mod n = 31 \times 8 \mod 33 \\ C{\prime} = 248~~ mod~ 33 = 248 – 33×7 = 248 – 231 = 17 \end{split} \end{gather}$$</p><p>This new ciphertext \(C{\prime}\) is the encryption of the product of the original plaintext and \(2\). If we directly encrypted \(M \times X = 4 \times 2 = 8\) with RSA, we would get \(8^3 \mod 33 = 512 \mod 33 = 17\). This means that \(C′\) corresponds to the plaintext \(8\), which is the original message \(4\) multiplied by \(2\).</p>
<p>In a real-world chosen ciphertext attack, the attacker may have access to a decryption oracle or observe a system response that reveals information about \(M{\prime}\). The decryption result \(8\) is exactly \(M \times 2\) (the original message multiplied by the attacker’s chosen factor). Knowing the factor \(X = 2\), the attacker can deduce the original message by dividing: \(8/ 2 = 4\).</p>
<p>Note that Eve has not broken the mathematical foundations behind RSA here. They have only used the public key to compute an encryption of \(2\), and then combined it with the intercepted ciphertext. They don’t know the original plaintext yet, but they have manipulated the ciphertext in a way that they know the new plaintext is twice the original message.</p>
<h2 id="heading-low-exponent-attacks">Low-Exponent Attacks</h2>
<p>Beyond determinism and malleability exploits, textbook RSA is also vulnerable to Low-Exponent Attacks. Using a small public exponent like \(e = 3\) (or sometimes \(17\)) was popular because it used to speed up encryption and signature verification. But this soon turned out to be a security concern.</p>
<p>When RSA uses a small public exponent (say, \(e = 3\)) and the plaintext is very short (so that \(M^3\) is smaller than the modulus \(n\)), the encryption does not “wrap around” modulo \(n\). Mathematically:</p>
<p>$$c = M^3 \mod n = M^3 \quad \text{(if \( M^3 &lt; n \))}$$</p><p>Let’s understand this with an easy example:</p>
<p>Consider our plaintext to be: \(M = 5\). We compute \(M^3\) as \(M^3 = 5^3 = 125\).</p>
<p>Now assume \(n\) is a \(4096\)‑bit number which is large compared to \(125\). In this case, the ciphertext is simply \(c = 125\). Eve intercepting \(c = 125\) can compute the cube root of \(125\) to get the plaintext: \(\sqrt[3]{125} = 5\) thus recovering \(M\) directly.</p>
<p>This shows that if \(M\) is small enough, the ciphertext leaks the plaintext when \(e\) is low.</p>
<h2 id="heading-hastads-broadcast-attack-low-exponent-meets-multiple-recipients">Håstad’s Broadcast Attack: Low Exponent Meets Multiple Recipients</h2>
<p>In 1985, Johan Håstad’s highlighted the broadcast attack that illustrates the danger of a low exponent, \(e\), when the same message is sent to multiple parties as a broadcast.</p>
<p>Imagine Alice wants to send the same plaintext message M to three different recipients. Each recipient has their own RSA public key with modulus \(N_1, N_2, N_3,\) but for speed all use \(e = 3\) (a common practice historically). Alice encrypts \(M\) with each public key, yielding ciphertexts:</p>
<p>$$\begin{gather} \begin{split} C_1 = M^3 \bmod N_1 \\ C_2 = M^3 \bmod N_2 \\ C_3 = M^3 \bmod N_3 \end{split} \end{gather}$$</p><p>Eve, who intercepts all three \(C_1, C_2, C_3\) can recover <em>M</em> without breaking any single RSA key.</p>
<p>Since each \(N_i \) is different (and we assume they are pairwise coprime, as RSA keys should be), the attacker can use the Chinese Remainder Theorem (CRT) to combine the three congruences \(x \equiv C_i \pmod{N_i}\). Note that at this point Eve only has \(C_1\), \(C_2\) and \(C_3\). They do not have the plaintext \(M\) or \(M^3\) and yet they can reconstruct \(M^3\) with the intercepted data. To understand the Chinese Remainder Theorem and this reconstruction, you may follow this: <a target="_blank" href="https://www.youtube.com/watch?v=Mt9v7-xBuaA">CRT, RSA, and Low Exponent Attacks | Youtube</a>.</p>
<p>There is a unique solution modulo \(N_1N_2N_3\) for \(x\), and that solution turns out to be an integer, \(x = M^3\) (because the true integer \(M^3\) is smaller than the product \(N_1N_2N_3\) of each \(M &lt; N_i \) ). In essence, CRT lets Eve reconstruct \(M^3\) exactly. Once they have \(M^3\) as an ordinary integer, they simply take the cube root to find \(M\). There’s no need to factor any modulus or invert the RSA function – the math falls out due to the low exponent.</p>
<p>The sequence diagram below aims to provide a high-level understanding of the attack:</p>
<p><img src="https://mermaid.ink/img/pako:eNqNlN9P2zAQx_-VmyWkIpWqSeostTQkFvawh-6h7AFNEcgk19RSY3e2A3RV__dd-gNoExB5is_f-_jum3PWLDcFMsEc_q1R53itZGlllWmgZymtV7laSu3haqFyhN4N6gLteXv_u3mA3hRppZCWQYckldYs3orCDtG1fMS3mqhD86ORXBWPaJ20KxLsJL-MRzAUPSlW7NdPlOvAG3AUhwqdkyXCpIn4uUUEezjVDQ7MYxJcXF62OxXQbDugyBytx2cPvfQ-gG8wuYugMgXo-4MfHbwOW7qJ4RExfJ_Y9rAbGB0Boxcjz862Fivt0ea4JNP2ZjnoFcZ7LEBaa57cvoST7wEX79j08xVI_nyQ22nJUXb4QXZX-0fJUXtiTkACKN1o522dU0rvdufUOdRO6RLS6e8DolUBFdCCpaZa1p7sS-sHhKkxHswMbj9RRhOgsWw2aXTnJLOqVFouXuf3S6ZZn1VoK6kKusrrBpoxEleYMUGvBc5kvfAZy_SGpLL25malcyaoPeyzellIf7j5TMzkwlGUbhoTa_bMRMCHAx7xMU84j5I4HPfZiolRMhgNR-NkxOM45FE8ijd99s8YIgwH4zCMEp4EQTLkX0MebHF_tpu7M7FQ3tjJ7uez_Qf1mTV1OX85v7RNNzu13Q53amrtmUjGm_8gLoH2?type=png" alt="Sequence Diagram: Håstad’s Broadcast Attack" width="1329" height="664" loading="lazy"></p>
<p>Now let’s see this attack in action with a sample:</p>
<p>Suppose three different RSA public keys all use exponent \(e=3\), with moduli \( n_b = 187\) (for Bob),<br>\(n_c = 115 \) (for Carol), and \(n_d = 87\)  (for Dave).</p>
<p>These \(n_i\) are pairwise coprime (\(gcd\) of each pair is \(1\)). Now assume the same plaintext message \(M\) is encrypted with each public key. Let’s take a concrete \(M\). For example with \(M=42\), we will have:</p>
<p>$$\begin{gather} \begin{split} c_b = M^3 \bmod n_b \\ c_c = M^3 \bmod n_c \\ c_d = M^3 \bmod n_d \\ \end{split} \end{gather}$$</p><p>On calculating these, we have:</p>
<p>$$\begin{gather} \begin{split} c_b = 42^3 \bmod 187 = 36 \\ c_c = 42^3 \bmod 115 = 28 \\ c_d = 42^3 \bmod 87 = 51 \\ \end{split} \end{gather}$$</p><p>So the three ciphertexts observed are \(36\), \(28\), and \(51\), respectively. Eve who knows \(n_b, n_c, n_d\) and these ciphertexts can now recover \(M\) as follows:</p>
<ol>
<li><p>Eve will compute the total modulus \(N = n_b \cdot n_c \cdot n_d = 187 \times 115 \times 87 = 1,870,935.\) (This is the modulus for the combined system of congruences).</p>
</li>
<li><p>Now Eve will compute the partial products for each congruence:</p>
</li>
</ol>
<p>$$\begin{gather} \begin{split} N_b = \frac{N}{n_b} = \frac{1,870,935}{187} = 10,005 \\ N_c = \frac{N}{n_c} = \frac{1,870,935}{115} = 16,269 \\ N_d = \frac{N}{n_d} = \frac{1,870,935}{87} = 21,505 \end{split} \end{gather}$$</p><ol start="3">
<li><p>At this point, Eve needs the inverses of each \(N_i\) modulo its corresponding \(n_i\):</p>
<ul>
<li><p>First Eve computes \(M_b = (N_b)^{-1} \bmod n_b\), i.e. the number \(M_b\) such that \(N_b \cdot M_b \equiv 1 \pmod{187}\). In this case, \(N_b = 10005\). Using the extended Euclidean algorithm, Eve can find \(M_b = 2\) (since \(10005 \times 2 = 20010 \equiv 1 \pmod{187}\)).</p>
</li>
<li><p>Then Eve computes \(M_c = (N_c)^{-1} \bmod n_c\). Here \(N_c = 16269\). The inverse mod \(115\) turns out to be \(M_c = 49\) (For verification: \(16269 \times 49 \equiv 1 \pmod{115}\)).</p>
</li>
<li><p>Next up, Eve computes \(M_d = (N_d)^{-1} \bmod n_d\). For \(N_d = 21505\), the inverse mod \(87\) is \(M_d = 49\) as well (coincidentally the same value in this case, since \(21505 \times 49 \equiv 1 \pmod{87}\)).</p>
</li>
</ul>
</li>
</ol>
<p>Now Eve reconstructs the combined value using the Chinese Remainder Theorem for three congruencies. The construction of this formula is beyond the scope of this handbook, but to completely understand how this springs into action, you may go through this video: <a target="_blank" href="https://www.youtube.com/watch?v=Mt9v7-xBuaA">CRT, RSA and Low Exponent Attacks | Youtube</a>.</p>
<p>$$C \;=\; c_b \cdot N_b \cdot M_b \;+\; c_c \cdot N_c \cdot M_c \;+\; c_d \cdot N_d \cdot M_d \pmod{N}$$</p><p>On substituting the numbers:</p>
<p>$$C = 36 \cdot 10005 \cdot 2 \;+\; 28 \cdot 16269 \cdot 49 \;+\; 51 \cdot 21505 \cdot 49 \pmod{1,870,935}$$</p><p>Let’s carefully evaluate each term:</p>
<p>$$\begin{gather} \begin{split} 36 \cdot 10005 \cdot 2 = 720,360 \\ 28 \cdot 16269 \cdot 49 = 22,341,348 \\ 51 \cdot 21505 \cdot 49 = 5,37,40,995 \\ \end{split} \end{gather}$$</p><p>Summing these gives a raw total of \(7,20,360 +  2,23,21,068 + 5,37,40,995 = 7,67,82,423\). Now reduce this modulo \(N = 1,870,935\):</p>
<p>$$\begin{align} \begin{split} C \equiv 7,67,82,423 \pmod{1,870,935}\\ C = 74,088 \\ \end{split} \end{align}$$</p><p>Now Eve will simply take the cube root of \(C: \sqrt[3]{74088} = 42\), which is the original plaintext.<br>Eve has successfully recovered \(M\).</p>
<p>The key takeaway from these attacks is that without proper defenses. RSA alone does not satisfy modern definitions of security. It is not resistant to chosen-plaintext or chosen-cipher text attacks. This gap between the theoretical one-way function (RSA’s trapdoor permutation) and a secure encryption scheme became evident as implementers found that naive RSA could be “broken” by various clever tricks.</p>
<p>To counter these weaknesses, standards bodies introduced padding schemes to strengthen RSA encryption. In the following sections, you will learn about each of these paddings schemes and how they’ve been exploited over the years.</p>
<h2 id="heading-introduction-to-padding-schemes-in-rsa">Introduction to Padding Schemes in RSA</h2>
<p>Before we dive into the padding schemes and how it helps our case, let’s quickly recap the need for padding in RSA.</p>
<p>Textbook RSA encryption is deterministic. The same plaintext always produces the same ciphertext under a given public key. This determinism makes raw RSA insecure. An attacker can guess possible messages, encrypt them with the public key, and compare with the target ciphertext to see which guess matches.</p>
<p>Beyond determinism, small-exponent attacks illustrate why padding is critical. If the message \(m\) is too small relative to the modulus, raising it to a small public exponent (like \(e=3\)) might not wrap around \(N\). Padding the plaintext with random data before encryption remedies these problems by making the ciphertext unpredictable and ensuring \(m^e\) spans the modulus’ range.</p>
<h2 id="heading-public-key-cryptography-standards-pkcs1-v15"><strong>Public Key Cryptography Standards (PKCS#1 v1.5)</strong></h2>
<p>In 1998, Kaliski and RSA Laboratories introduced PKCS#1 v1.5 to the world in a public publication [7]. In PKCS#1 v1.5, every RSA‐encrypted message is wrapped inside a special “encryption block” \(EB\). This block ensures that the raw message is both the right size for RSA and padded in a way that’s hard to tamper with.</p>
<p>In this scheme, the plaintext is padded to the size of the modulus \(N\) (in bytes) as:</p>
<p>$$EB = 00 ~||~ BT ~||~ PS ~||~ 00 ~||~ M$$</p><p>Here, \(0x00\) (Leading Zero Byte) is always at the front. It ensures that, when the concatenated string \(EB\) is converted to a big‐endian integer, the value is less than the RSA modulus (that is, we don’t end up with a number too large for RSA to handle). You will better appreciate this fact when we dive into the mathematics behind this.</p>
<p>The next octet is the Block Type, \(BT\), which tells us the “type” of padding being used. The standard defines three possible \(BT\) values: \(00, 01, \) and \(02\)- to support different operations. For example, \(BT=00\) and \(BT = 01\) is used for private-key operations (such as digital signatures) and \(BT = 02\) is used for public-key operations. For encryption under PKCS#1 v1.5, this is always \(0x02\). It’s basically a label that says, “This is an encryption block, not something else”.</p>
<p>The next block is the Padding String \(PS\). This is a string of nonzero random bytes. This is crucial for security because it introduces randomness into each encryption. If the same message is encrypted multiple times, these random bytes ensure that each ciphertext looks different, foiling many simple attacks that rely on seeing repeated patterns.</p>
<p>The next octet, \(0x00\), is a Delimiter<strong>.</strong> This single zero byte marks the end of the padding. During decryption, this helps the recipient quickly identify where the padding stops and the real message begins.</p>
<p>Finally, we have the actual data you want to protect – \(M\). Once the recipient has verified the padding, they know exactly where to find this message.</p>
<p>This mechanism helped solve the deterministic issue of naive RSA. In the next sections, let’s understand the mathematics involved in PKCS#1 v1.5 padding and its security implications.</p>
<h3 id="heading-the-mathematics-behind-pkcs1-v15">The Mathematics Behind PKCS#1 v1.5</h3>
<p>Before we begin, let’s get our symbols and abbreviations correct. We will use upper-case symbols (such as \(EB\)) to denote octet strings and bit strings. We will use lower-case symbols (such as \(n\)) to denote integers.</p>
<p>In PKCS#1 v1.5, we will use \(k\) to represents the length of the RSA modulus \(n\) in bytes. For example, if you have a \(1024\)-bit RSA key, then the RSA modulus \(n\) is a \(1024\)-bit number. Since there are \(8\) bits in a byte, if your RSA modulus is \(L\) bits long, then:</p>
<p>$$k = \left\lceil \frac{L}{8} \right\rceil = \frac{1024}{8} = 128 \text{ bytes}$$</p><p>The total length of the encryption block will be equal to this RSA key length \(k\) (in bytes). Now here the length of the data \(M\) shall not be more than \(k-11\) octets, since the 11 bytes are consumed by the blocks – \(0x00  ~||~ 0x02 ~||~ PS ~||~ 0x00\). This limitation guarantees that the length of the padding string \(PS\) is at least eight octets, which is a security condition in PKCS#1v1.5:</p>
<p>$$∣PS∣=k~−∣M∣−~3$$</p><p>For example, with a \(1024\)-bit RSA modulus, the value of \(k\) comes out to be \(128\). Here Alice could encrypt up to \(128 - 11 = 117\) bytes of data. The \(11\) bytes are used for the \(0x00  ~||~ 0x02 ~||~ PS ~||~ 0x00\) structure. The random \(PS \) ensures that each encryption of the same message produces a different ciphertext, preventing the deterministic encryption problem.</p>
<p>RSA doesn’t directly operate on the bytes. Once the padded string \(EB\) is ready, it needs to be converted into an integer guided by the Octet String to Integer Primitive (OS2IP) formula:</p>
<p>$$x = \sum_{i=1}^{k} 2^{8(k - i)} \,\mathrm{EB}_i$$</p><p>where \(EB_i\) are the octets of \(EB\) from first to last. In other words, \(EB_1\) (the first byte) is the most significant byte, and \(EB_k\) (the last byte) is the least significant. Now Alice can simply encrypt this block using \(C = x^c \mod n\).</p>
<p>To solidify our learnings so far, let’s apply this to a sample plaintext and find the padded blocks.</p>
<p>Let’s assume the RSA modulus is \(8\) bytes long (\(k=8\)). Suppose we want to encrypt a message \(M\) that is \(2\) bytes long. Then the padding string \(PS\) must fill the remaining space:</p>
<p>$$Total ~ bytes=k=8=1(0x00)+1(BT)+∣PS∣+1(delimiter)+∣M∣$$</p><p>Since \(∣M∣=2\) and there are \(∣M∣=2∣\) fixed bytes, can find the required length of the padding string:</p>
<p>$$∣PS∣=8−3−2=3 ~ bytes$$</p><p>Let’s pick 3 arbitrary nonzero bytes for \(PS\), say - \(0xA3, ~0x5F, ~0xC2\). And let’s say the message is the ASCII text “Hi”. In hexadecimal, that’s: \(0x48\) for 'H' and \(0x69\) for 'i'.</p>
<p>Thus, the complete encryption block becomes:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742368983011/f682532c-6664-4197-8e77-60ea034f82c5.png" alt="Sample Encryption Block in PKCS#1 v1.5" class="image--center mx-auto" width="1191" height="437" loading="lazy"></p>
<p>Now we will convert this octet string to an integer using the OS2IP formula we discussed above:</p>
<p>$$x = \sum_{i=1}^{k} 2^{8(k - i)} \,\mathrm{EB}_i$$</p><p>For our example, with \(k=8\) the conversion is:</p>
<p>$$x=  0x00×256^7+0x02×256^6+0xA3×256^5+0x5F×256^4+0xC2×256^3+0x00×256^2+0x48×256^1+0x69×256^0$$</p><p>Note that the hexadecimal values can be converted to decimal as needed. For instance, \(0xA3 = 163, 0x5F = 95, 0xC2 = 194, 0x48 = 72,\) and \(0x69 = 105\).</p>
<p>There is an interesting observation in the application of this formula. Because the first two bytes are fixed (\(0x00\) and \(0x02\)), the integer \(x\) has a known lower bound. The contribution of the first two bytes is:</p>
<p>$$0×256^ 7 +2×256^ 6 =2×256^ 6$$</p><p>The rest of the bytes (\(PS\), the delimiter, and \(M\)) add some value that is at least \(0\) and at most just less than \(256^6\) (since the second byte is fixed as \(0x02\) and cannot be \(0x03\)). Thus, \(x\) is in the range:</p>
<p>$$2×256 ^ 6 ≤x&lt;3×256 ^ 6$$</p><p>This property which makes the range predictable, paved the way for the Bleichenbacher attack (also known as the “padding oracle” attack). If a system reveals whether a decrypted block is “correctly padded,” an attacker can systematically probe different ciphertexts and narrow down the plaintext – because the attacker knows it must lie in that narrow range. Let’s take a detailed look at the Bleichenbacher attack in the next sections and understand how the exploit works.</p>
<h2 id="heading-the-bleichenbacher-attack">The Bleichenbacher Attack</h2>
<p>In 1998, Daniel Bleichenbacher published a seminal paper [8] demonstrating an adaptive chosen-ciphertext attack against RSA with PKCS#1 v1.5 padding. The Bleichenbacher Attack, also dubbed as the “million messages” attack, demonstrated that if an attacker has access to an oracle that tells whether a submitted ciphertext decrypts to a properly padded plaintext (that is, whether the PKCS#1 v1.5 formatting is correct), the attacker can gradually recover the full plaintext. Let’s break down how this attack works:</p>
<p>First, Eve needs an Oracle. The attack assumes the attacker can query a system, such as an SSL/TLS server, and find out if a given ciphertext \(C\) is PKCS#1 v1.5 conformant. In the 1998 paper, Bleichenbacher exploited the fact that a TLS server, when presented with an improperly padded RSA-encrypted premaster secret, would respond with a specific error alert if the padding was wrong. Essentially, the server acted as an oracle: it would decrypt \(C\) with its private key and simply tell the attacker “padding OK” or “padding error” (the error could be timing-based or an explicit alert).</p>
<p>Note that the oracle does not reveal the plaintext. It only reveals a single bit of information at a time: “valid padding or not.” This might seem harmless, but Bleichenbacher showed that it’s enough to eventually recover the plaintext.</p>
<p>To quickly recap, the attacker’s goal is to find the unknown message integer \(m\) (the PKCS#1-padded plaintext as an integer) given its ciphertext \(C = m^e \bmod N\), using the oracle. We know that if \(m\) is properly padded, it lies in a specific numeric range: \(2B \le m &lt; 3B\) where \(B = 2^{8*(k-2)}\), as defined earlier.</p>
<p>If \(k=128\) bytes, then \(B=2^{8*126}\), and a correctly padded \(m\) will start with \(0x00 ~||~0x02\), so it’s between \(2B\) and \(3B\). The attacker, Eve, initially only knows that \(m\) is in the range \([2B, 3B)\).</p>
<p>In the Bleichenbacher Attack, Eve will exploit RSA’s multiplicative property. They will choose a number \(s\) (called the multiplier) and compute a new ciphertext \(C' = (C  s^e) \bmod N\). This \(C'\) here corresponds to a new plaintext: \(m' = m  s \bmod N\) (because \(C' \equiv m^e * s^e \equiv (ms)^e \pmod{N}\)).</p>
<p>To begin the attack, Eve finds some \(s_0\) such that \(C_0 = C * (s_0)^e \mod N\) yields a valid padding. This is referred to as the Blinding step. This is usually easy – for example, \(s_0\) can be chosen so that \(m * s_0\) is just slightly above \(N\), which almost certainly will wrap around and land in \([2B,3B)\). The attacker does not know \(m\) to verify this directly. They rely on the padding oracle’s yes/no response to infer that the blinded plaintext \((m×s_0)\mod  N\) falls in the correct range.</p>
<p>If the oracle returns “valid padding” for a given \( s_0\), it tells the attacker that \(s_0 \mod N\)lies between \(2B\)and \(3B\). Mathematically:</p>
<p>$$2B≤(m×s_0)~mod  N&lt;3B$$</p><p>Now, Eve will try to try to narrow down this range in a loop, which is often referred to as the interval having step. Initially, Eve had one wide interval \([a, b] = [2B, 3B)\) that contains \(m\). In each iteration, Eve tries increasing values of \(s\) (starting from a certain minimum) until the oracle returns “padding OK” for \(C' = C_0 * s^e\). Suppose this happens at some \(s = s_i\). Given this feedback, Eve now knows:</p>
<p>$$2𝐵 ≤  (𝑚 × 𝑠_i) ~ mod 𝑁 &lt; 3𝐵$$</p><p>This congruence implies there exists some integer \(r\) such that:</p>
<p>$$2B  ≤ ( m×s_i)−rN  &lt;  3B$$</p><p>Rearranging, we get a constraint on \(m\):</p>
<p>$$\frac{2B+rN}{s_i}  ≤  m  &lt;  \frac{3B+rN}{s_i}$$</p><p>Eve doesn’t know \(r\) outright, but they can solve for the possible range of \(r\) by considering the current interval \([a,b]\) for \(m\). Essentially, Eve uses the previous bounds on \(m\) to guess which \(r\) would make the inequality true, then updates the new bounds \([a, b]\) as the intersection of all possible solutions for \(m\). This dramatically shrinks the interval.</p>
<p>Each oracle query yields such a constraint. Eventually, the interval \([a,b]\) collapses to a single value, \([a,a]\). Now, Eve can find the plaintext using:</p>
<p>$$m = (a × s_i^{-1}) ~ mod N$$</p><p>At that point, Eve has recovered the entire padded plaintext \(m\), and by stripping off the padding, the original message itself.</p>
<p>The sequence diagram below consolidates our learning of the attack:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742498318544/6e297215-ca3e-451d-9574-117c0f8a12cb.png" alt="Sequence Diagram: The Bleichenbacher’s Attack" class="image--center mx-auto" width="819" height="640" loading="lazy"></p>
<p>The Bleichenbacher attack showed that the format of the padding in PKCS#1 v1.5 leaked just enough info to enable a full private-key operation (decrypting the message) without ever factoring N. The attack leveraged the fact that it’s possible to craft ciphertexts that will decrypt to a valid-looking plaintext without knowing the plaintext​. In essence, PKCS#1 v1.5 padding allowed about \(1\) in \(2^{16}\) chance (roughly) for a random blob to appear as “valid padding.” That was enough for an adaptive attack to succeed with feasible queries.</p>
<p>This is precisely what later padding designs like OAEP fixed. OAEP’s design makes such random valid ciphertexts astronomically unlikely (plaintext aware). We will learn about RSA-OAEP in the next sections.</p>
<p>To mitigate the Bleichenbacher attack without immediately changing the padding scheme, practitioners implemented defensive measures. For example, TLS should treat all decryption failures the same way (so an attacker can’t distinguish padding vs. other errors), and servers would generate a fake premaster secret on padding failure to continue the handshake and avoid timing leaks. Nonetheless, the safest course has been to deprecate PKCS#1 v1.5 encryption in favor of schemes like RSA-OAEP.<a target="_blank" href="https://archiv.infsec.ethz.ch/education/fs08/secsem/bleichenbacher98.pdf#:~:text=plaintext%20is%20PKCS%20conforming,chosen%20ciphertexts%3B%20thus%2C%20we%20show">​</a></p>
<h2 id="heading-optimal-asymmetric-encryption-padding-oaep">Optimal Asymmetric Encryption Padding (OAEP)</h2>
<p>By the end of 1995, Bellare and Rogaway proposed Optimal Asymmetric Encryption Padding (OAEP) with the goal of achieving provable security. This padding aimed to make RSA encryption resistant not just to passive attacks but also to adaptive chosen-ciphertext attacks. In other words, even if an attacker can trick a system into decrypting chosen ciphertexts (as an “oracle”), they should learn nothing useful about the plaintext. OAEP was subsequently standardized in PKCS#1 v2.0 (published as RFC 2437 in 1998) and later versions.</p>
<p>Compared to PKCS#1 v1.5, OAEP has a more complex encoding that uses hash functions and a mask generation function (MGF) to thoroughly randomize the plaintext before RSA encryption, providing stronger guarantees.</p>
<p>OAEP’s design can be viewed as a two-layer Feistel-like network using a random seed. It takes the input message and randomizes it in a way that is reversible only with the correct seed. The scheme was proven plaintext-aware in the random oracle model which means that an adversary cannot concoct a valid ciphertext without knowing the corresponding plaintext. If an attacker tries to forge or tamper with ciphertexts, they almost surely produce an <em>invalid</em> padding that will be rejected. This property directly counters padding-oracle attacks.</p>
<p>OAEP (with a proper hash/MGF) is semantically secure against adaptive chosen ciphertext attacks, assuming RSA is hard to invert and treating the hash functions as random oracles. Unlike PKCS#1 v1.5, which lacked a formal proof, OAEP comes with a proof sketch that breaking RSA-OAEP is as hard as breaking RSA itself.</p>
<p>In practice, this means OAEP drastically reduces the risk of any padding oracle: an attacker can no longer easily find ciphertexts that slip through the padding check except by brute force which has a \(2^{-hLen*8}\) success probability. For example, the success probability with SHA-1 would be \(2^{-160}\).</p>
<p>The block diagram below is a visual representation of the OAEP encoding schema:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742663541136/1c418939-80f6-45ea-8667-cacdc5cdab2b.png" alt="Optimal Asymmetric Encryption Padding" class="image--center mx-auto" width="1434" height="1102" loading="lazy"></p>
<p>Let’s understand what these mathematical notions mean and the workings of RSA-OEAP, up next.</p>
<h3 id="heading-the-mathematics-behind-oaep">The Mathematics Behind OAEP</h3>
<p>Optimal Asymmetric Encryption Padding requires a hash function for two operations we will discuss in this section. We will choose SHA-1 as a hash function in OAEP and \(hLen\) denotes the length in octets of the hash function output. We will later demonstrate why even MD5 or SHA-1 is a secure choice for OAEP even if it is not collision resistant.</p>
<p>Before we dive into the mathematics, let’s recap a few notations and define the main pieces we’ll be using:</p>
<p>In RSA, \(N\)is the modulus, and \(k\) is the size of \(N\) in <em>bytes</em>. For a \(2048\)-bit modulus, \(k=256\) bytes.<br>\(M \) is the message or plaintext to be encrypted. This plaintext must be short enough to fit into the padded block (at most \(k−2⋅hLen−2\) bytes). In our notation, \(Hash\) refers to the cryptographic hash function (for example, SHA-1, SHA-256) of output length \(hLen\). For example: If using SHA-1, \(hLen=20\) bytes.</p>
<p>We will also use an optional string associated with the message (often empty). This is the Label \(L\). If this label is empty, its hash is a fixed value. (For example: the SHA-1 of an empty string).</p>
<p>The hash of this label \(L\) is represented by \(lHash\), where \(lHash=Hash(L)\). As mentioned earlier, if \(L\) is empty, \(lHash\) is simply \(Hash('')\). This means that in any case \(lHash\) will hold a value.</p>
<p>We will also use a Mask Generation Function, \(MGF\), which is often mentioned as \(MGF1\). This function takes an input (seed or masked data) and produces an output of a specified length by iterating the underlying hash function. We’ll write \(MGF(input,length)\) to indicate “generate a mask of \(length\) bytes from \(input\)”.</p>
<p>Now that you are familiar with all the necessary notations, we are ready to begin the encoding step.</p>
<h4 id="heading-step-1-constructing-the-data-block-db">Step 1: Constructing the Data Block (DB)</h4>
<p>We will compute \(lHash=Hash(L)\). If \(L\) is empty, \(lHash\) is a constant (For example, the SHA-1 of the empty string).</p>
<p>Form the padding string \(PS\), the length of \(PS\) is chosen so that the entire block \(DB\) has length \((k−hLen−1)\) bytes. Numerically, \(PS\) has \((k−mLen−2⋅hLen−2)\) bytes of \(0x00\), where \(mLen\) is the length of the message \(M\).</p>
<p>Now we simply concatenate the blocks to generate the octet string for the Data Block (\(DB\)):</p>
<p>$$DB=lHash~∣∣~PS~∣∣~0x01~∣∣~M$$</p><p>Here the single byte \(0x01\) acts as a delimiter which marks where the zero padding ends and the actual message \(M\) begins. \(DB\) ends up being \((k−hLen−1)\) bytes.</p>
<h4 id="heading-step-2-generating-a-mask-for-the-data-block">Step 2: Generating a Mask for the Data Block</h4>
<p>First, we pick a random string called \(seed\) of length \(hLen\) bytes. For example, when using SHA-1 where \(hLen=20\), then we say that the seed consists of \(20\) random bytes.</p>
<p>Now we use the mask generation function, \(MGF\), on the \(seed\) to create a mask the same length as \(DB\):</p>
<p>$$dbMask=MGF(seed,k−hLen−1)$$</p><p>The idea is to spread the randomness of the seed across the entire \(DB\).</p>
<h4 id="heading-step-3-mask-the-data-block">Step 3: Mask the Data Block</h4>
<p>Now, we will Combine \(DB\) and \(dbMask\) with the bitwise \(XOR\) operation:</p>
<p>$$maskedDB=DB \oplus dbMask$$</p><p>This step “scrambles” \(DB\) with the random seed.</p>
<h4 id="heading-step-4-generate-a-mask-for-the-seed">Step 4: Generate a Mask for the Seed</h4>
<p>Next, we will produce a mask for the seed itself, based on \(maskedDB\):</p>
<p>$$seedMask=MGF(maskedDB,hLen)$$</p><p>This step simply ensures that the seed is not left in the clear.</p>
<h4 id="heading-step-5-mask-the-seed">Step 5: Mask the Seed</h4>
<p>Now we will combine the original seed and the new mask with an \(XOR\) operation:</p>
<p>$$maskedSeed=seed \oplus seedMask$$</p><p>Now the seed is also “scrambled” by the data block.</p>
<h4 id="heading-step-6-form-the-final-encoded-message-em">Step 6: Form the Final Encoded Message (EM)</h4>
<p>We are now ready to build our final block. Simply concatenate everything into a \(k\)-byte string:</p>
<p>$$EM=0x00~∣∣~maskedSeed~∣∣~maskedDB$$</p><p>The leading \(0x00\) byte ensures that when \(EM\) is interpreted as an integer, it’s less than the RSA modulus \(N\). At this point, \(EM\) is your OAEP-padded message of length \(k\).</p>
<h4 id="heading-step-7-covert-concatenated-string-to-integer">Step 7: Covert concatenated String to Integer</h4>
<p>Remember from our discussion before on PKCS#1v1.5 that RSA cannot directly operate on this concatenated string of bytes. We need to convert the \(EM\) block to a non-negative integer using the OS2IP formula:</p>
<p>$$x = \sum_{i=1}^{k} 2^{8(k - i)} \,\mathrm{EB}_i$$</p><h4 id="heading-step-8-perform-rsa-encryption">Step 8: Perform RSA Encryption</h4>
<p>Now that we have the encoded message (\(EM\)) as an integer \(x\), we are ready to perform RSA guided by the formula:</p>
<p>$$C =x^e \bmod N$$</p><p>where \((e,N)\) is the public key. The thus computed \(C\) is our ciphertext generated using RSA-OAEP.</p>
<p>When decrypting, the process is reversed: the recipient uses their private key \(d\) to compute \(m = c^d \bmod N\), recovers the \(EM\), then splits it into the \(0x00\), \(maskedSeed\), and \(maskedDB\), and uses the same \(MGF\) and hash function to unravel the \(XORs\) in reverse order​. Finally, they check that the recovered \(lHash'\) matches the expected hash and that the block contains the proper structure​ (\(...||0x01||...\)).</p>
<p>If any check fails, the padding is invalid. Only if everything checks out is the message \(M\) returned. The result is that an invalid ciphertext will almost always be detected and rejected without giving an attacker any useful information.</p>
<p>By design, OAEP effectively foiled the padding oracle problem. The chance that a random guess produces a valid OAEP encoding is negligible: on the order of \(2^{-hLen*8}\)). In fact, Daniel Bleichenbacher (after breaking PKCS#1 v1.5) advocated for exactly such a “plaintext-aware” padding where forging a valid padding is infeasible.</p>
<h2 id="heading-why-sha-1-or-md5-are-safe-in-rsa-oaep"><strong>Why SHA-1 or MD5 Are Safe in RSA-OAEP</strong></h2>
<p>Earlier in the section above, we mentioned that we’d be using SHA-1 for our mathematical formulation and examples. When you see SHA-1 or MD5 used in the context of RSA-OAEP, don’t let the fact that these hash functions are considered broken for collision resistance alarm you. If you notice carefully in the previous section, the hash functions serve two very specific roles that do not rely on their collision resistance. Let’s break them down one by one:</p>
<h3 id="heading-label-hashing"><strong>Label Hashing</strong></h3>
<p>The hash function is used to compute a fixed-length hash of an optional label \(L\) (often empty).</p>
<p>Now let’s see why is this safe in the context. This hash, called \(lHash\), acts as a domain separator. Its job is simply to ensure that the label is correctly associated with the ciphertext during decryption. As long as the label is chosen wisely (that is, not built from adversary-controlled parts), collision resistance isn’t critical here.</p>
<h3 id="heading-mask-generation-function-mgf1"><strong>Mask Generation Function (MGF1)</strong></h3>
<p>The hash function is also used inside \(MGF1\) to create a pseudorandom mask. This mask is applied both to the data block \(DB\) and to the random seed used in the encoding process.</p>
<p>In this context, the hash function is treated as a random oracle. The job is to spread the randomness of the seed across a larger block of data. For this purpose, properties like length extension or collision resistance are not relevant. What matters is that the output appears random, and even SHA-1 or MD5 can deliver that when used in this controlled, fixed-input scenario.</p>
<h2 id="heading-adoption-in-cryptographic-libraries-pkcs1-v15-vs-oaep">Adoption in Cryptographic Libraries (PKCS#1 v1.5 vs OAEP)</h2>
<p>After the Bleichenbacher attack, standards and libraries migrated to OAEP or at least added support for it, while treating PKCS#1 v1.5 as a legacy option. Modern cryptographic libraries and protocols reflect these lessons.</p>
<p>In 1998, the RSA standard was updated. PKCS#1 v2.0 introduced RSAES-OAEP as the new recommended encryption scheme, and by PKCS#1 v2.1 and v2.2 (RFC 3447 and RFC 8017), OAEP is required for new applications, with PKCS#1 v1.5 included only for backward compatibility.</p>
<p>OpenSSL discourages users from using PKCS#1 v1.5 as it leaks information that can potentially be used to mount a Bleichenbacher padding oracle attack [10]. The documentation clearly mentions that it is highly recommended to use <code>RSA_PKCS1_OAEP_PADDING</code> in new applications.</p>
<p>The Python cryptography library (PyCA cryptography) also asks developers to use OAEP for encryption instead of PKCS#1 v1.5 [11].</p>
<p>After Bleichenbacher’s 1998 attack, it was impractical to instantly replace PKCS#1 v1.5 everywhere. Instead, protocol designers issued countermeasures.</p>
<p>TLS, for example, responded by changing the error handling: the server would not reveal a padding failure distinctly. It would generate a fake premaster secret and proceed to prevent timing clues, and always return a generic handshake failure at a later stage, making it harder for the attacker to distinguish why decryption failed.</p>
<p>These countermeasures reduced the oracle’s fidelity but were tricky to get right across different implementations. In fact, not everyone got it right – the Bleichenbacher attack continued to resurface in various forms when implementations made mistakes in error handling.</p>
<p>In 2018, researchers discovered the ROBOT attack (Return Of Bleichenbacher’s Oracle Threat): several TLS implementations had subtle bugs that recreated a padding oracle, allowing the attack to succeed 19 years later. The ROBOT paper showed that even with countermeasure guidelines, the complexity of uniformly handling errors led to slip-ups in popular products.</p>
<p>This underscores that patching an insecure scheme is often error-prone – a design that is secure by construction (like OAEP) is preferable.</p>
<p>PKCS#1 v1.5 continues to exist because of these patchwork security measures and the fact that it cannot be abruptly removed from all existing systems. It is generally regarded as "legacy" or maintained "for compatibility" purposes. The collective wisdom is clear: use OAEP for RSA encryption whenever possible.</p>
<h2 id="heading-enhancing-digital-signatures-the-transition-to-pss">Enhancing Digital Signatures: The Transition to PSS</h2>
<p>Now that you understand how OAEP transformed RSA encryption by mitigating vulnerabilities in deterministic padding, it’s time to turn our attention to RSA digital signatures – a critical function for ensuring message integrity and authenticity.</p>
<p>Early RSA signature schemes suffered from similar problems as raw encryption: their deterministic nature made them prone to forgery and replay attacks. This vulnerability paved the way for an improvement: the Probabilistic Signature Scheme (PSS).</p>
<p>Before we dive into PSS itself, let’s quickly understand the pain points with early RSA signatures.</p>
<h3 id="heading-problems-with-early-rsa-signature-schemes">Problems with Early RSA Signature Schemes</h3>
<p>Traditional RSA signatures were generated by simply applying the RSA decryption function on a message digest (often with minimal formatting):</p>
<p>$$s=m^d \bmod N$$</p><p>where \(m\) is the hash (or encoded hash) of the message. This approach was deterministic which meant that each time the same message was signed, the exact signature was produced. Such determinism had two major drawbacks:</p>
<ol>
<li><h4 id="heading-predictability-and-replay">Predictability and Replay</h4>
<p> Since the signature for a given message was always identical, an attacker could replay a captured signature with impunity or forge signatures if they could deduce patterns in the signature scheme.</p>
</li>
<li><h4 id="heading-forgery-risks">Forgery Risks</h4>
<p> In a deterministic setting, if an attacker finds any structure or mathematical relationship in the signature, they might be able to forge a valid signature for a new message. In certain scenarios, weak formatting could allow an adversary to create a “signature transformation” that produces a valid signature without having access to the private key.</p>
</li>
</ol>
<p>These issues highlighted that a signature scheme must be probabilistic to be secure against adaptive forgery attempts and to ensure non-repudiation. This means that the signer should not be able to repudiate a signature because it is bound to a random value known only at signing time.</p>
<h3 id="heading-birth-of-the-probabilistic-signature-scheme-pss">Birth of the Probabilistic Signature Scheme (PSS)</h3>
<p>Towards the end of 1998, Bellare and Rogaway also proposed a scheme to overcome the inherent limitations of deterministic RSA signatures [12]. The core idea was to introduce randomness into the signature generation process so that even when signing the same message twice, the resulting signatures would be different. This randomness comes from a salt value and a carefully designed encoding process. The result is a signature method with strong, provable security guarantees.</p>
<p>This randomness prevents attackers from exploiting patterns in the signature process. The probabilistic Signature Scheme was designed to be provably secure in the random oracle model, meaning that forging a signature would be as hard as breaking RSA itself under certain assumptions [13].</p>
<p>The block diagram below is a visual representation of the PSS encoding schema:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742669558156/8137f535-deb7-4437-887a-53cf7a412089.png" alt="Probabilistic Signature Scheme" class="image--center mx-auto" width="1580" height="1258" loading="lazy"></p>
<p>Let’s understand what these mathematical notions mean as well as the workings of RSA-PSS, up next.</p>
<h3 id="heading-the-mathematics-behind-pss">The Mathematics Behind PSS</h3>
<p>Before diving into the mechanics of RSA-PSS, it’s helpful to define the notations and terms you’ll see in the steps ahead.</p>
<p>In RSA, \(N\)is the modulus, a large integer that is the product of two primes. \(k\) is the length of \(N\) in <em>bytes</em>. For an \(2048\)-bit key, \(k=256\) bytes.</p>
<p>\(M\)represents the message data or document you want to sign. In RSA-PSS, you’ll typically first compute a hash of \(M\). \(Hash\) refers to a cryptographic hash function (for example, SHA-256) that maps data to a fixed-size output. The output length is denoted \(hLen\). For SHA-256, \(hLen=32\) bytes.</p>
<p>We will use a salt, \(S\), randomly generated string of fixed length (often the same as \(hLen\)). This randomness is essential in ensuring that each signature is unique, even for the same message.</p>
<p>\(H\) or \(mHash\) is the hash of the message \(M\)and \(H'\) is a secondary hash that includes both \(M\) and the salt \(S\). This appears in the PSS encoding step.</p>
<p>The Mask Generation Function, \(MGF\), is a function that uses the hash internally to produce a pseudorandom output of arbitrary length. In PSS, it is used to “mask” parts of the data block so that the signature is hard to forge.</p>
<p>A fixed byte, \(0xbc\) (in hex) is appended at the end of the encoded message to mark the boundary of the PSS structure. This serves as a simple integrity check during decoding. After a successful encoding we receive an encoded message \(EM\) which is an octet string of length \(emLen = \left\lceil{\frac{emBits}{8}}\right\rceil\).</p>
<p>Now that you are familiar with all the necessary notations, we are ready to begin the encoding step.</p>
<h4 id="heading-step-1-message-hashing-and-salt-generation">Step 1: Message Hashing and Salt Generation</h4>
<p>We compute the hash of the message as \(H~( mHash)=Hash(M)\) where \(M\) is our message. We will also create a random salt \(S\) (of fixed length, say 20 bytes if you use SHA-1).</p>
<h4 id="heading-step-2-encoding-the-hash-with-the-salt-pss-encode">Step 2: Encoding the Hash with the Salt (PSS-Encode)</h4>
<p>We will construct a Data Block, \(DB\), by combining a padding with the hash and the salt. The padding is a sequence of \(0\)’s that fills space and ensures a fixed length. Mathematically:</p>
<p>$$M' = (0x)~00 ~00 ~00 ~00 ~00 ~00 ~00 ~00 ~||~ mHash ~||~ salt$$</p><p>Now we compute the Hash of this block as \(H' = Hash(M')\). We will generate another octet string \(PS\) and concatenate it with the salt and \(0x01\) as a delimiter:</p>
<p>$$DB = PS ~||~ 0x01 ~||~ salt$$</p><p>Note that DB is an octet string of length \(emLen - hLen - 1\). The mask that you see in the visual representation above must be of this length. Mathematically:</p>
<p>$$dbMask = MGF(H, emLen - hLen - 1)$$</p><p>We will then apply this mask on the \(DB\) block using an \(XOR\) operation to produce our \(maskedDB\):</p>
<p>$$maskedDB = DB \oplus dbMask$$</p><p>Recollect that \(emLen\) is the intended length of the Encoded Message \(EM\) and \(hLen\) is the length of the hash output. Now we append a fixed trailer field \(0xbc\) and produce the encoded message in its octet string representation:</p>
<p>$$EM = maskedDB ~||~ H ~||~ 0xbc$$</p><p>This encoding process ensures that both the salt and the hash are mixed together in a non-reversible, pseudorandom manner. The randomness from the salt is “spread” over the data block by the \(MGF\), making it extremely difficult for any adversary to manipulate the signature.</p>
<h4 id="heading-step-3-rsa-signature-generation">Step 3: RSA Signature Generation</h4>
<p>Once you have the encoded message \(EM\), the RSA signature is produced by using the RSA private key. First, convert the Octet String to its integer representation using the OS2IP method we’ve discussed before. Then apply the RSA Private Key Operation:</p>
<p>$$s=m^d \bmod N$$</p><p>where \(d\) is the private exponent and \(N\) is the RSA modulus.</p>
<h4 id="heading-step-4-signature-verification">Step 4: Signature Verification</h4>
<p>At the receiver end, when any recipient wants to verify a signature, they reverse the process:</p>
<p>$$m′= s^e \bmod N$$</p><p>and convert \(m'\) back to an encoded message \(EM\). The verifier then extracts the components \((MaskedDB, H′, trailer)\) and recomputes \(H'\) from the message and salt. The verifier confirms that the hash and salt embedded in \(EM\) match what is expected. If everything checks out, the signature is valid.</p>
<h2 id="heading-the-road-ahead-assessing-rsas-long-term-viability"><strong>The Road Ahead: Assessing RSA’s Long-Term Viability</strong></h2>
<p>In 1994, Peter Shor’s algorithm [14], demonstrated that a quantum computer can factor large integers in polynomial time, thereby efficiently breaking RSA’s underlying hard problem – the difficulty of factoring \(N = p \times q\).</p>
<p>Although experimental quantum computers have made progress, they remain far from having the number of stable qubits required to break RSA keys of practical sizes (2048 or 4096 bits).</p>
<p>In anticipation of large-scale quantum computers, the cryptographic community is actively developing and standardizing algorithms believed to be resistant to quantum attacks. These include lattice-based schemes (such as CRYSTALS-Kyber and NTRU), code-based cryptography (such as the McEliece cryptosystem), hash-based signatures (such as XMSS), and multivariate polynomial cryptosystems.</p>
<p>It’s important to note that while OAEP and PSS improve the security of RSA against classical attacks, they do not protect RSA from quantum attacks. In a post-quantum world, even the most secure classical padding will not prevent a quantum computer from breaking RSA using Shor’s algorithm.</p>
<p>In the near term, RSA remains in widespread use and, when implemented with padding schemes such as OAEP and PSS, continues to provide strong security against classical adversaries. But looking ahead, it’s expected that organizations will gradually migrate to post-quantum algorithms as they mature and become standardized.</p>
<h2 id="heading-references">References</h2>
<p>[1] FIPS 186-5: <a target="_blank" href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-5.pdf">Digital Signature Standard (DSS)</a></p>
<p>[2] RFC 8017 PKCS #1: <a target="_blank" href="https://www.rfc-editor.org/rfc/rfc8017.html">RSA Cryptography Specifications</a></p>
<p>[3] <a target="_blank" href="https://en.wikipedia.org/wiki/Lagrange%27s_theorem_\(number_theory\)">Lagrange's theorem</a></p>
<p>[4] Ronald L. Rivest, Robert D. Silverman: <a target="_blank" href="https://people.csail.mit.edu/rivest/pubs/pubs/RS01.version-1999-11-22.pdf">Are Strong Primes Needed for RSA</a>?</p>
<p>[5] <a target="_blank" href="https://cryptography.io/en/latest/hazmat/primitives/asymmetric/rsa/">pyca/cryptography</a></p>
<p>[6] <a target="_blank" href="https://github.com/openssl/openssl/blob/85cabd94958303859b1551364a609d4ff40b67a5/crypto/rsa/rsa_chk.c">OpenSSL Github</a>: <code>rsa_chk.c</code></p>
<p>[7] RFC 2313: <a target="_blank" href="https://www.rfc-editor.org/rfc/rfc2313.html">PKCS #1: RSA Encryption</a></p>
<p>[8 ] Daniel Bleichenbacher: <a target="_blank" href="https://archiv.infsec.ethz.ch/education/fs08/secsem/bleichenbacher98.pdf">Chosen Ciphertext Attacks Against Protocols Based on the RSA Encryption Standard PKCS #1</a></p>
<p>[9] RFC 8017: <a target="_blank" href="https://www.rfc-editor.org/rfc/rfc8017#section-7.1">PKCS #1 RSA Cryptography Specifications Version 2.2</a></p>
<p>[10] RSA_public_encrypt: <a target="_blank" href="https://docs.openssl.org/3.5/man3/RSA_public_encrypt/#warnings">Warnings</a></p>
<p>[11] <a target="_blank" href="https://cryptography.io/en/latest/hazmat/primitives/asymmetric/rsa/#cryptography.hazmat.primitives.asymmetric.padding.PKCS1v15">pyca/PKCS1v1</a></p>
<p>[12] <a target="_blank" href="https://en.wikipedia.org/wiki/Probabilistic_signature_scheme">Probabilistic signature scheme</a></p>
<p>[13] RFC 8017: <a target="_blank" href="https://www.rfc-editor.org/rfc/rfc8017#section-8.1">RSASSA-PSS</a></p>
<p>[14] <a target="_blank" href="https://ieeexplore.ieee.org/abstract/document/365700/">Algorithms for quantum computation</a>: discrete logarithms and factoring</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Decoding Chaos: How True Randomness Works in Software Engineering ]]>
                </title>
                <description>
                    <![CDATA[ Understanding Randomness When you hear the word "randomness," what usually comes to mind? You may think of  something intangible, an abstract concept without a specific shape or form  – it's random.  But randomness is much more than an abstract idea ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/true-randomness-in-software-engineering/</link>
                <guid isPermaLink="false">66c3770d86ad38fd983838a6</guid>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ randomness ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Software Engineering ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Gor Grigoryan ]]>
                </dc:creator>
                <pubDate>Mon, 06 May 2024 16:27:18 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/04/0_VRBzKmnCSxIHtVVQ.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <h2 id="heading-understanding-randomness">Understanding Randomness</h2>
<p>When you hear the word "randomness," what usually comes to mind? You may think of  something intangible, an abstract concept without a specific shape or form  – it's random. </p>
<p>But randomness is much more than an abstract idea – it's a fundamental aspect of our daily decisions and choices. Whether it's deciding what to eat for breakfast or picking a number from 1 to 10 in a game, randomness plays a crucial role. </p>
<p>Randomness isn't just about unpredictability. It's also about the lack of pattern or predictability in events. For instance, when you toss a coin, the outcome of heads or tails is random because it's equally likely and unpredictable. </p>
<h3 id="heading-why-is-randomness-important-in-software-engineering">Why is Randomness Important in Software Engineering?</h3>
<p>This concept is incredibly important in the field of software engineering, where generating true randomness can enhance security, simulations, and algorithms. In software development, this unpredictability is not just a feature—it's a fundamental requirement for various critical functions.</p>
<h4 id="heading-security">Security</h4>
<p>The most crucial role of randomness in software is in the realm of security. Random numbers are used to generate secure keys for encryption, ensuring that sensitive data—be it personal information, financial details, or confidential communications—is protected from unauthorized access. </p>
<p>The randomness ensures that these keys cannot be easily predicted or replicated, fortifying the security barriers (see more in the <a class="post-section-overview" href="#heading-randomness-in-cryptographic-systems">Randomness in Cryptographic Systems</a> section)</p>
<h4 id="heading-testing-and-quality-assurance">Testing and Quality Assurance</h4>
<p>Developers use random inputs to simulate how software might perform under different conditions. This approach helps uncover unexpected bugs and ensures that the software can handle a variety of scenarios, improving its reliability and stability. </p>
<p>Companies like Netflix, Facebook, Google use Chaos Engineering to make their systems more reliable (learn more in the <a class="post-section-overview" href="#heading-chaos-monkey-developed-my-netflix">Chaos Engineering section</a>).</p>
<h4 id="heading-simulation-and-modeling">Simulation and Modeling</h4>
<p>Randomness is a key component in simulations that mimic real-world phenomena, which can be inherently unpredictable. Whether it's modeling climate patterns, economic markets, or traffic flows, randomness helps create more accurate models that better reflect the complexity of these systems.</p>
<h4 id="heading-additional-applications">Additional Applications</h4>
<p>Randomness is used in many areas and it helps distribute tasks across servers in load balancing, improves efficiency in traffic routing, and adds realism in image generation. Also, its crucial for creating unique identifiers like GUIDs (Globally Unique Identifiers) and shuffling playlists to enhance user experience. As you can see, the use cases for randomness are numerous.</p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<p>This article is designed to be accessible, with explanations straightforward enough for readers with various backgrounds. However, a few basic prerequisites can enhance your understanding:</p>
<ol>
<li><strong>Basic Programming Knowledge</strong>: While not essential, some familiarity with programming concepts in languages like C#, Java, or Python could help you grasp examples of how randomness is implemented in code more quickly.</li>
<li><strong>Elementary Math Skills</strong>: A basic understanding of probability and statistics is beneficial but not necessary, as the article aims to explain these concepts in simple terms.</li>
<li><strong>Introductory Cryptography</strong>: If you're curious about the security aspects of randomness, some background in cryptography concepts like encryption and key generation could be helpful.</li>
</ol>
<p>Overall, the article is structured to be easy to follow, with no advanced knowledge required. It's meant to introduce the concept of randomness in software engineering broadly, making it suitable for readers from diverse fields.</p>
<h3 id="heading-heres-what-well-cover-in-this-article">Here's what we'll cover in this article:</h3>
<ul>
    <li><a href="#understanding-randomness">Understanding Randomness</a></li>
    <li><a href="#coin-toss-paradigm">Coin Toss Paradigm</a></li>
    <li><a href="#the-illusion-of-human-randomness">The Illusion of Human Randomness</a></li>
    <li><a href="#how-random-number-generators-work">How Random Number Generators Work</a>
        <ul>
            <li><a href="#simple-random-number-generator">Simple random number generator</a></li>
        </ul>
    </li>
    <li><a href="#true-random-number-generation-trng-and-entropy-sources">True Random Number Generation (TRNG) and Entropy Sources</a>
        <ul>
            <li><a href="#earthquakes-in-trng">Earthquakes in TRNG</a></li>
            <li><a href="#hardware-events-in-trng">Hardware Events in TRNG</a></li>
            <li><a href="#human-factors-in-trng">Human Factors in TRNG</a></li>

        </ul>
    </li>
    <li>
        <a href="#randomness-in-software-testing">Randomness in software testing</a>
        <ul>
            <li><a href="#chaos-monkey-developed-my-netflix">Chaos Monkey developed my Netflix
</a></li>
        </ul>
    </li>
    <li><a href="#randomness-in-cryptographic-systems">Randomness in Cryptographic Systems</a>
        <ul>
            <li><a href="#could-you-hack-the-encryption">Could you hack the encryption?</a></li>
        </ul>
    </li>
    <li><a href="#randomness-in-simulation-and-modeling">Randomness in Simulation and Modeling</a>
        <ul>
            <li><a href="#monte-carlo-simulation">Monte Carlo Simulation</a></li>
        </ul>
    </li>
    <li><a href="#future-of-randomness-in-software-engineering">Future of Randomness in Software Engineering</a>
        <ul>
            <li><a href="#quantum-computing-and-quantum-randomness">Quantum Computing and Quantum Randomness</a></li>
        </ul>
    </li>
    <li><a href="#wrapping-up">Wrapping Up</a></li>
</ul>


<h2 id="heading-coin-toss-paradigm">Coin Toss Paradigm</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/Phantom_Slowmo_Coin_Flip--1-.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Is tossing a coin truly a random event?</strong> At first glance, a coin toss represents the paradigm of randomness : two outcomes, each with an equal chance of occurring. </p>
<p>But if we dive deeper into the physics behind a coin toss, the story starts to unfold differently. Hypothetically, if we could control and replicate every variable involved in the toss  – the force applied, the angle of the toss, the air resistance, and even the surface it lands on –  would the outcome still be unpredictable?</p>
<p>The answer leans towards a surprising declaration: in a perfectly controlled environment, the result of a coin toss could be predicted with near certainty. This challenges our understanding of randomness, suggesting that what we often perceive as random is influenced by numerous factors, many of which are beyond our control or too complex to replicate in practice.</p>
<p>Thus, we arrive at an insightful conclusion that randomness ≈ the result of variables that are exceedingly difficult to replicate.</p>
<p>Big research from the University of California at Berkeley, titled “<a target="_blank" href="https://www.stat.berkeley.edu/~aldous/157/Papers/diaconis_coinbias.pdf"><strong>Dynamical Bias in the Coin Toss</strong></a>”, delves into this phenomenon:</p>
<blockquote>
<p>Abstract: We analyze the natural process of flipping a coin which is caught in the hand. We show that vigorously flipped coins tend to come up the same way they started. The limiting chance of coming up this way depends on a single parameter, the angle between the normal to the coin and the angular momentum vector. Measurements of this parameter based on high-speed photography are reported. For natural flips, the chance of coming up as started is about .51</p>
</blockquote>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/image-36.png" alt="Image" width="600" height="400" loading="lazy">
_[<strong>Dynamical Bias in the Coin Toss</strong>](https://www.stat.berkeley.edu/~aldous/157/Papers/diaconis<em>coinbias.pdf" rel="noopener)</em></p>
<h2 id="heading-the-illusion-of-human-randomness">The Illusion of Human Randomness</h2>
<p>For humans, it's an easy task to generate a random number, say a random word, or make a random decision. But again, is it really a random thing and can it be somehow predicted like we have stated for a coin toss? </p>
<p>If you have seen the 2015 movie Focus, you may remember the "priming" scene where they spend the day "priming" their victim to subconsciously recognize and choose the number 55 by having it represented all around him.</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/otWiLwwxo5o" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p>Priming is one of the most important psychological principles to understand because it influences behavior through implicit memory. In other words, exposure to a cue in one setting can form an association that carries into another.</p>
<p>One of the examples of priming comes to us from a supermarket bottle shop. Imagine one week you go into the bottle shop and there’s some French music playing in the background. You buy your wine and leave. </p>
<p>Now imagine you return a week later, but this time German music is piping through the speakers. Again, you buy your wine and leave. Chances are that when French music was playing, you purchased French wine, and when German music was playing, German wine – just like 77% and 73% of research participants did. </p>
<p>Were these consumers aware of the music and its impact on their decision? 86% of people said no, the music had no effect.</p>
<p>This phenomenon underscores a profound truth: <a target="_blank" href="https://www.quora.com/What-is-the-psychological-theory-behind-the-priming-scene-in-Will-Smiths-movie-Focus">whether knowingly or not, we are both the primers and the primed</a>. Our perceived randomness in decision-making is continuously shaped by the stimuli around us. This reveals that the essence of human randomness is far more complex and influenced than we might initially believe.</p>
<h2 id="heading-how-random-number-generators-work">How Random Number Generators Work</h2>
<p>Let’s take a journey back to the early days of computing to understand the evolution of random number generators. </p>
<p>Initially, computers were quite basic compared to today’s sophisticated machines. Essentially, a computer operates on a strict set of instructions :  it cannot spontaneously generate a number as humans might randomly choose a number from 1 to 10.</p>
<p>For a computer, generating a random number requires specific instructions. Today, this task has become straightforward in many programming languages through built-in functions. For example, in C#, you can generate a random number between 1 and 10 with this simple command:</p>
<pre><code class="lang-c#">Random.Next(<span class="hljs-number">1</span>, <span class="hljs-number">10</span>) <span class="hljs-comment">// &lt;-- Generates a radom number from 1 to 10</span>
</code></pre>
<p>The interesting part begins when we look under the hood.</p>
<h3 id="heading-simple-random-number-generator">Simple random number generator</h3>
<p>What if you were given a task to create a function that generates a random number? Let’s say you have this function:</p>
<pre><code class="lang-c#"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span> <span class="hljs-title">GenerateRandomNumber</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> start, <span class="hljs-keyword">int</span> end</span>)</span>
{
  <span class="hljs-keyword">return</span> ✨🪄 magic ✨🪄
}
</code></pre>
<p>One of the simplest ways to do this is using a Linear Congruential Generator (LCG). The example below is a simplistic approach and you shouldn't use it for cryptographic purposes or applications requiring high levels of randomness.</p>
<pre><code class="lang-c#"><span class="hljs-keyword">using</span> System;

<span class="hljs-keyword">class</span> <span class="hljs-title">SimpleRandomGenerator</span>
{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">long</span> seed;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">const</span> <span class="hljs-keyword">long</span> a = <span class="hljs-number">25214903917</span>;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">const</span> <span class="hljs-keyword">long</span> c = <span class="hljs-number">11</span>;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">long</span> m = (<span class="hljs-keyword">long</span>)Math.Pow(<span class="hljs-number">2</span>, <span class="hljs-number">48</span>);

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">SimpleRandomGenerator</span>(<span class="hljs-params"><span class="hljs-keyword">long</span> seed</span>)</span>
    {
        <span class="hljs-keyword">this</span>.seed = seed;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">Next</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> min, <span class="hljs-keyword">int</span> max</span>)</span>
    {
        <span class="hljs-comment">// Update the seed</span>
        seed = (a * seed + c) % m;

        <span class="hljs-comment">// Ensure the result is within the bounds [min, max)</span>
        <span class="hljs-keyword">int</span> result = (<span class="hljs-keyword">int</span>)(min + (seed % (max - min)));
        <span class="hljs-keyword">return</span> result;
    }
}

<span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
{
    <span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)</span>
    {
        <span class="hljs-keyword">var</span> generator = <span class="hljs-keyword">new</span> SimpleRandomGenerator(DateTime.Now.Ticks);

        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">15</span>; i++)
        {
            <span class="hljs-keyword">var</span> rndNumber = generator.Next(<span class="hljs-number">1</span>, <span class="hljs-number">101</span>);

            Console.WriteLine(<span class="hljs-string">$"Random number between 1 and 100: <span class="hljs-subst">{rndNumber}</span>"</span>);        
        }
    }
}

<span class="hljs-comment">/* Output
Random number between 1 and 100: 78
Random number between 1 and 100: 9
Random number between 1 and 100: -48
Random number between 1 and 100: 71
Random number between 1 and 100: 6
Random number between 1 and 100: 45
Random number between 1 and 100: 64
Random number between 1 and 100: 99
Random number between 1 and 100: -34
Random number between 1 and 100: 85
Random number between 1 and 100: -44
Random number between 1 and 100: -25
Random number between 1 and 100: 26
Random number between 1 and 100: -27
Random number between 1 and 100: 24
*/</span>
</code></pre>
<p>This example uses the <a target="_blank" href="https://www.geeksforgeeks.org/linear-congruence-method-for-generating-pseudo-random-numbers/">Linear Congruential Generator</a> (LCG) method, which is a basic pseudorandom number generator. </p>
<p>LCGs are one of the oldest and simplest methods for generating sequences of pseudo-random numbers, and they operate based on a simple mathematical formula: "<em>new seed = (a×seed+c) mod m" .</em> The seed is typically initialized using a value with sufficient entropy, such as the current time (<code>DateTime.Now.Ticks</code> in this case). The <code>Next</code> method generates a new "random" number within the specified range [min, max). </p>
<p>Here's the step-by-step logic:</p>
<ol>
<li><strong>Update the Seed</strong>: The seed is updated using the LCG formula mentioned above. This step is critical, as it uses the old seed to produce a new one, ensuring that each call to <code>Next</code> results in a different output.</li>
<li><strong>Scaling the Output</strong>: Once the new seed is calculated, it needs to be adjusted to fall within the user-specified range <code>[min, max)</code>.<br>– The modulus operation <code>seed % (max - min)</code> scales the seed to a value within the range of 0 to <code>(max - min) - 1</code>.<br>– Adding <code>min</code> shifts this scaled value into the desired range, ensuring that the result is at least <code>min</code> but less than <code>max</code>.</li>
</ol>
<h2 id="heading-true-random-number-generation-trng-and-entropy-sources">True Random Number Generation (TRNG) and Entropy Sources</h2>
<p>Random number generation based on natural events or hardware characteristics involves using unpredictable, non-deterministic sources to generate randomness. This approach is often referred to as using "entropy sources" or "true random number generation" (TRNG). </p>
<p>Unlike pseudo-random number generators (PRNGs) that use mathematical algorithms and require a seed value, true random number generators derive their randomness from physical events that are almost unpredictable. Here are a few examples:</p>
<h3 id="heading-earthquakes-in-trng">Earthquakes in TRNG</h3>
<p>Earthquakes generate seismic data that is almost unpredictable and can be used as a source of randomness. By measuring seismic activity through geophones or seismographs, the minute variations in the Earth's movement can be converted into random numbers. </p>
<p>Earthquakes occur due to the sudden release of energy in the Earth's crust, resulting in the ground shaking. This energy release is unpredictable and varies in magnitude, location, and frequency. The unpredictability of the timing, duration, and intensity of seismic events makes this a viable entropy source.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/image-37.png" alt="Image" width="600" height="400" loading="lazy">
<em>[USGS Magnitude 2.5+ Earthquakes data, Past Day](https://earthquake.usgs.gov/earthquakes/map/?currentFeatureId=pr71446783&amp;extent=9.79568,-147.39258&amp;extent=58.99531,-42.62695" rel="noopener)</em></p>
<h4 id="heading-additional-technical-details">Additional technical details</h4>
<p>Here are some additional technical details about earthquakes in TRNG:</p>
<p>Data collection is typically done using instruments called seismometers or geophones, which are sensitive to ground vibrations. These devices convert the kinetic energy of ground movements into electrical signals that can then be digitized and analyzed. </p>
<p>This process might include:</p>
<ul>
<li><strong>Signal Conditioning and Filtering:</strong> Filtering the seismic signals to isolate the random components from predictable noise or background vibrations.</li>
<li><strong>Digitization:</strong> Converting the analog signals into digital values, which typically involves sampling the signal at regular intervals and quantizing these samples into digital values.</li>
</ul>
<p>The raw digital data derived from seismic activity might not be uniformly random due to natural biases in how earthquakes occur or how data is collected. </p>
<p>To ensure that the numbers generated are suitable for use in applications requiring high-quality randomness (such as cryptographic systems), further processing might be necessary. </p>
<p>Here are the common techniques:</p>
<ul>
<li><strong>Debiasing</strong>: Applying algorithms to remove any predictable patterns or biases from the data.</li>
<li><strong>Whitening</strong>: Transforming the data to ensure a uniform distribution across all possible values. This often involves statistical tests to adjust the output until it meets the criteria for randomness.</li>
</ul>
<p>Using earthquakes for random number generation could be particularly valuable in applications where an external, unpredictable source of randomness is beneficial. </p>
<p>But there are cons and practical considerations:</p>
<ul>
<li><strong>Geographical Limitations</strong>: Not all locations experience frequent seismic activity, which could limit the availability of this method to specific regions.</li>
<li><strong>Event Rarity</strong>: Significant seismic events are relatively rare and unpredictable in timing, which might not provide a steady or reliable source of randomness when needed.</li>
<li><strong>Data Collection and Processing Overhead:</strong> The infrastructure and computational effort required to capture, process, and utilize seismic data for random number generation can be significant.</li>
</ul>
<h3 id="heading-hardware-events-in-trng">Hardware Events in TRNG</h3>
<p>Hardware-based random number generators (HRNGs) use physical processes within computing devices to generate randomness. Examples include:</p>
<h4 id="heading-thermal-noise-johnson-nyquist-noise">Thermal Noise (Johnson-Nyquist Noise):</h4>
<p>Thermal noise, also known as Johnson-Nyquist noise, is a type of interference naturally present in all electronic devices and circuits. It’s caused by the random motion of electrons within a material due to heat. This phenomenon can be used as a source of randomness for generating random numbers in hardware devices.</p>
<p>Every material that conducts electricity has electrons, which are tiny particles that move around and carry electrical current. Even when a device isn’t actively being used, these electrons are never completely still – they move randomly because of the heat energy within the material. The higher the temperature, the more active the electrons become.</p>
<p>Thermal noise is generated by the inherent energy present in all materials at temperatures above absolute zero (-273.15°C or -459.67°F). At these temperatures, electrons gain energy and start moving randomly. This movement causes tiny, random fluctuations in the electrical current when measured across components like resistors.</p>
<p>Thermal noise is ideal for cryptographic applications where high security is essential. This includes key generation and secure communications where unpredictability is paramount to preventing attacks. </p>
<p>In developing secure communication protocols for applications like instant messaging, VoIP, or data transmission systems, thermal noise can be used to generate encryption keys that are nearly impossible to predict, enhancing security.</p>
<h4 id="heading-clock-drift">Clock Drift</h4>
<p>Clock drift occurs due to the slight and unpredictable variations in the timing mechanisms (like crystal oscillators) of computers and other digital devices. Clock drift exploits the natural variability in hardware clocks, which are designed to measure time but can drift apart due to minor differences in the frequency of their oscillators.</p>
<p>By comparing the time reported by two or more independent clocks, small differences that occur naturally and unpredictably can be measured. These differences are influenced by factors such as temperature changes, hardware imperfections, and supply voltage variations.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/image-38.png" alt="Image" width="600" height="400" loading="lazy">
_[A USB-pluggable hardware true random number generator](https://en.wikipedia.org/wiki/Hardware_random_number_generator#Clock<em>drift" rel="noopener)</em></p>
<h4 id="heading-photonic-emission">Photonic Emission</h4>
<p>Photonic emission-based random number generation uses the process of light emission to create random numbers. This approach relies on the quantum nature of light  – specifically, the behavior of photons, which are tiny particles that make up the light. </p>
<p>Photonic emission occurs when energy is released from atoms in the form of light. This happens in devices like LEDs (light-emitting diodes) and lasers. </p>
<p>In an LED, when electricity flows through the device, it excites electrons (tiny negatively charged particles) to higher energy states. As these electrons return to their normal states, they release energy in the form of photons. </p>
<p>The exact moment a photon is emitted is inherently unpredictable due to the principles of quantum mechanics, where particles like electrons behave in a probabilistic manner.</p>
<p>To turn photonic emission into random numbers, we first need to detect these photons. We can do this using a device called a photodetector, which captures the light and converts each photon hit into an electrical signal. </p>
<p>The key to randomness lies in the timing of each photon’s arrival at the detector. Since the emission of each photon is random, the times they are detected are also random. These times are then recorded with high precision.</p>
<h4 id="heading-cloudflares-lava-lamps-for-randomness">Cloudflare’s Lava Lamps for Randomness</h4>
<p>Cloudflare, a web performance and security company, has set up a wall of lava lamps in the lobby of their San Francisco office. The setup is known as the “LavaRand” system. It leverages the unpredictable and ever-changing movements of the “lava” inside these lamps to generate randomness.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/image-39.png" alt="Image" width="600" height="400" loading="lazy">
<em>Cloudflare’s Lava Lamps. The view from the camera</em></p>
<p><strong>How LavaRand Works:</strong><br>The process starts with visual capturing. A camera is pointed at the wall of lava lamps. The lamps contain blobs of wax in a liquid that expand and move in unpredictable ways when heated. </p>
<p>As the wax heats up, it rises, and as it cools, it falls, creating an ever-changing, visually chaotic display. </p>
<p>The camera takes images of the lava lamps at regular intervals. Each image captures a unique, random pattern of swirling wax. These images are then processed using computer algorithms to extract random data from the patterns observed in the images.</p>
<p><strong>Relation to Photonic Emission:</strong><br>While Cloudflare’s Lava Lamps use a form of photonic emission, it’s indirect. The photonic emission in this context is the light emitted by the lamps, which illuminates the wax inside. </p>
<p>The random number generation process, however, primarily relies on the chaotic physical movements of the wax, which are captured by the light and recorded by a camera. The randomness comes from how the light and shadows play off the moving lava, rather than the emission and detection of photons at a quantum level (which is more typical in photonic emission RNG systems using LEDs or lasers).</p>
<p><strong>Information from Cloudflare's official website:</strong></p>
<blockquote>
<p>LavaRand is a system that uses lava lamps as a secondary source of randomness for our production servers. A wall of lava lamps in the lobby of our San Francisco office provides an unpredictable input to a camera aimed at the wall. A video feed from the camera is fed into a CSPRNG, and that CSPRNG provides a stream of random values that can be used as an extra source of randomness by our production servers. Since the flow of the “lava” in a lava lamp is very unpredictable,1 “measuring” the lamps by taking footage of them is a good way to obtain unpredictable randomness. Computers store images as very large numbers, so we can use them as the input to a CSPRNG just like any other number.  </p>
<p>We’re not the first ones to do this. Our LavaRand system was inspired by a similar system first <a target="_blank" href="https://en.wikipedia.org/wiki/Lavarand">proposed and built</a> by Silicon Graphics and <a target="_blank" href="https://www.google.com/patents/US5732138">patented</a> in 1996 (the patent has since expired).  </p>
<p>Hopefully, we’ll never need it. Hopefully, the primary sources of randomness used by our production servers will remain secure, and LavaRand will serve little purpose beyond adding some flair to our office. But if it turns out that we’re wrong, and that our randomness sources in production are actually flawed, then LavaRand will be our hedge, making it just a little bit harder to hack Cloudflare.   </p>
<p>Read more <a target="_blank" href="https://blog.cloudflare.com/randomness-101-lavarand-in-production">here</a>.</p>
</blockquote>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/image-40.png" alt="Image" width="600" height="400" loading="lazy">
<em>[First proposed and patented LavaLend in 1996](https://patents.google.com/patent/US5732138" rel="noopener)</em></p>
<h3 id="heading-human-factors-in-trng">Human Factors in TRNG</h3>
<h4 id="heading-mouseware">Mouseware</h4>
<p>Some tools like <a target="_blank" href="https://www.mouseware.org/">Mouseware</a> use human factors to generate randomness. Mouseware uses a cryptographically secure random number generator based on your mouse movements to generate secure, memorable passwords. Passwords are generated entirely in the browser, and no data is ever sent over the network. </p>
<p>For those generated passwords, it would take 22400.7 years to guess at 1000 guesses/second and 2.0 hours to guess at 100 billion guesses/second.</p>
<ul>
<li>1000 guesses/second is a worst-case web-based attack. Typically this is the only type of attack feasible against a secure website.</li>
<li>100 billion guesses/second is a worst-case offline attack when a hashed password database is stolen by someone with nontrivial technical and financial resources.</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/Screen-Recording-2024-04-27-at-22.02.43.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Example of the flow to generate random numbers based on mouse movements</em></p>
<p>You can <a target="_blank" href="https://www.mouseware.org/">read more about Mouseware</a> on their website.</p>
<h2 id="heading-randomness-in-software-testing">Randomness in Software Testing</h2>
<h3 id="heading-chaos-monkey-developed-my-netflix">Chaos Monkey developed my Netflix</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/image-7.png" alt="Image" width="600" height="400" loading="lazy">
<em>Chaos Monkey</em></p>
<p>Chaos Monkey is an innovative tool developed by Netflix. It's responsible for randomly terminating Netflix's instances in <em>production</em> to ensure that engineers implement their services to be resilient to instance failures. </p>
<p>Imagine a virtual, mischievous monkey randomly tinkering with the network—shutting down instances, disconnecting servers, or overloading systems to simulate possible failures. </p>
<p>Although it might seem counterintuitive, the purpose of Chaos Monkey is to proactively provoke controlled failures. This strategy allows Netflix's engineers to test how well their systems can handle unexpected disruptions. The aim is to identify and resolve weaknesses before they impact users, ensuring that the infrastructure is robust enough to withstand real-world issues.</p>
<p>For instance, if Chaos Monkey randomly terminates a server and everything continues to run smoothly, that’s a win. If problems arise, engineers quickly analyze and rectify them, thereby strengthening the system. This continuous testing and improvement cycle helps ensure that when you settle in to binge-watch your favorite series, you experience uninterrupted streaming.</p>
<p>Thanks to tools like Chaos Monkey and the principles of Chaos Engineering, Netflix can deliver a seamless viewing experience. Next time you watch a show without any glitches, remember the behind-the-scenes efforts of these unsung heroes keeping your entertainment flawless.</p>
<p>This tool is also available for open source usage. <a target="_blank" href="https://netflix.github.io/chaosmonkey/">Check out the docs here</a>. </p>
<h2 id="heading-randomness-in-cryptographic-systems">Randomness in Cryptographic Systems</h2>
<p>Randomness plays a critical role in cryptographic systems, forming the backbone of security protocols across the digital landscape. This section explores why randomness is essential in cryptography, how it is generated, and the challenges involved in ensuring its effectiveness. </p>
<p>In cryptographic systems, randomness is used to generate keys, initialize cryptographic algorithms, and for non-repudiation processes like digital signatures and secure communications. </p>
<p>The strength and security of almost all cryptographic techniques depend on the quality of the randomness used. If the randomness is predictable, so too are the cryptographic keys, making the system vulnerable to attacks.</p>
<p>If we encrypt the text “<code>Hello World</code>”, we will get this text “<code>oO64D2IzNWKSQnDM8fcZ/w==</code>”. To see the power of encryption, let’s also encrypt variations of the text: “HelloWorld” (without a space) and “Hello world” (with lowercase), while also experimenting with a different encryption key. </p>
<p>Here are the outcomes:</p>
<pre><code class="lang-text">╔═════════════╦═══════════╦══════════════════════════╗
║    Text     ║ Password  ║      Encoded value       ║
╠═════════════╬═══════════╬══════════════════════════╣
║ Hello World ║      1234 ║ oO64D2IzNWKSQnDM8fcZ/w== ║
╠─────────────╬───────────╬──────────────────────────╣
║ HelloWorld  ║      1234 ║ KvqAEHQhP9iBdFWhOUcYVg== ║
╠─────────────╬───────────╬──────────────────────────╣
║ Hello world ║      1234 ║ jdKRaAw9ULCFb627e3mNpQ== ║
╠─────────────╬───────────╬──────────────────────────╣
║ Hello World ║       123 ║ S/eGTyDQsgLwcEIrCWUAJw== ║
╠─────────────╬───────────╬──────────────────────────╣
║ HelloWorld  ║       123 ║ /JRa5+mllydL/F0m7NuxYA== ║
╠─────────────╬───────────╬──────────────────────────╣
║ Hello world ║       123 ║ s3AydwlvlgHCcpiAhaurXg== ║
╚═════════════╩═══════════╩══════════════════════════╝
</code></pre>
<p>If you consider the above table, you’ll notice that even a small change, such as a change in spacing or a single character, leads to a complete transformation of the encrypted text. </p>
<p>This means that if the intruder manages to obtain both the original text and its encrypted form, they would still face a significant challenge in trying to guess the password required to unlock the entire database.</p>
<h3 id="heading-could-you-hack-the-encryption">Could you hack the encryption?</h3>
<p>Brute force attacks are a straightforward yet powerful method used by attackers to crack passwords and encryption keys. </p>
<p>A brute force attack involves systematically checking <strong>all possible combinations</strong> until the correct one is found. Attackers use brute force methods to try every possible key or password until they decrypt the targeted data.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/image-6.png" alt="Image" width="600" height="400" loading="lazy">
<em><a target="_blank" href="https://www.imperva.com/learn/application-security/brute-force-attack/">Ream more about brute force attacks</a></em></p>
<p>In our case, for decrypting the word we will need to try every possible combination (even like a, aa, b, bb strings and so on).</p>
<p>Now lets calculate how much time is needed to decrypt/check every possible combination for our password. Suppose you own an exceptionally powerful supercomputer, coupled with cutting-edge technology and virtually unlimited resources. </p>
<p>Let’s say the computer has a whopping 1 terabyte (TB) of RAM allowing it to handle lots of tasks at once. For the CPU, this supercomputer boasts a mind-boggling speed of 1 exaflop, which means it can do about 1 quintillion calculations in just one second. 1 exaflop is equal to 1,000,000 gigaflops. So, to achieve 1 exaflop of computing power using Intel i9 processors with a performance of 300 gigaflops each, you would need 1,000,000 gigaflops / 300 gigaflops = 3,333,333 Intel i9 processors. </p>
<p>This hypothetical supercomputer, performing mind-blowing calculations at lightning speed, could do a brute-force attack on an encryption algorithm.</p>
<p>If our hypothetical supercomputer were to attempt every possible combination of text to decipher the encrypted data, it would be faced with an astronomical number of possibilities — ²²⁵⁶. It’s estimated that it would take not just years, not even centuries, <strong>but potentially tens of thousands of decades.</strong> </p>
<p>To read more about this, you can <a target="_blank" href="https://gor-grigoryan.medium.com/encryption-and-data-security-in-clean-architecture-using-ef-core-value-converters-a-guide-to-911711a1ec52">refer to this article that I wrote</a>.</p>
<h2 id="heading-randomness-in-simulation-and-modeling">Randomness in Simulation and Modeling</h2>
<h3 id="heading-monte-carlo-simulation">Monte Carlo Simulation</h3>
<p>The Monte Carlo Simulation is a mathematical technique used to understand the impact of risk and uncertainty in prediction and forecasting models. Essentially, it’s a method used to predict the probability of different outcomes when the intervention of random variables is present. </p>
<p>Named after the famous Monte Carlo Casino due to its reliance on randomness, this method is widely used across finance, engineering, research, and more.</p>
<p>In the context of finance, Monte Carlo simulation is commonly used to assess the risk and value of financial instruments, such as options or portfolios. By generating a large number of random scenarios for different input variables, such as asset prices or interest rates, Monte Carlo simulation can provide a range of possible outcomes and their associated probabilities. This method is mostly used when there is no analytical solution for the given problem.</p>
<p>Telecoms use them to assess network performance in various scenarios, which helps them to optimize their networks. Financial analysts use Monte Carlo simulations to assess the risk that an entity will default, and to analyze derivatives such as options. Insurers and oil well drillers also use them to measure risk. </p>
<p>To read more, <a target="_blank" href="https://www.investopedia.com/terms/m/montecarlosimulation.asp">check out this article</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/image-41.png" alt="Image" width="600" height="400" loading="lazy">
<em>Monte Carlo Simulation Output of a Stock price. Retrieved from <a target="_blank" href="https://medium.com/@rmenghani21/computing-option-price-and-greeks-using-monte-carlo-simulation-21a3a24d11ba">this article</a></em></p>
<h2 id="heading-future-of-randomness-in-software-engineering">Future of Randomness in Software Engineering</h2>
<p>The future of randomness in software engineering looks particularly promising, with significant advancements expected from emerging technologies like quantum computing.</p>
<h3 id="heading-quantum-computing-and-quantum-randomness">Quantum Computing and Quantum Randomness</h3>
<p>Quantum computing introduces an inherently <a target="_blank" href="https://en.wikipedia.org/wiki/Stochastic">stochastic</a> element known as quantum randomness. </p>
<p>Unlike classical computing, which relies on deterministic processes, quantum processes are unpredictable by nature. Quantum random number generators (QRNGs) exploit this property to generate true random numbers directly from quantum phenomena, such as the superposition of quantum states or the measurement of entangled particles. </p>
<p>These devices are expected to provide a more secure and fundamentally unpredictable source of randomness than is currently possible.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/image-42.png" alt="Image" width="600" height="400" loading="lazy">
<em>IBM’s new 53-qubit quantum computer</em></p>
<p>Quantum computing has the potential to revolutionize cryptography. Current cryptographic systems rely on the computational difficulty of certain problems (like factoring large numbers) <strong>which quantum computers could solve effortlessly</strong>. But quantum cryptography, utilizing quantum randomness for key distribution, promises to be virtually unbreakable due to the laws of quantum mechanics.</p>
<h3 id="heading-current-state-of-quantum-computing">Current State of Quantum Computing</h3>
<p>As of now, quantum computing is in an experimental phase. Researchers and companies like Google, IBM, and D-Wave are actively developing quantum computers and have made significant progress in recent years. </p>
<p>For instance, Google announced "quantum supremacy" in 2019, claiming that their quantum computer solved a problem that would be practically impossible for a classical computer to solve in any reasonable amount of time. </p>
<p>Quantum bits, or qubits, which are the basic units of information in quantum computing, are highly susceptible to interference from their environment. This leads to high error rates in quantum computations. Developing error-correcting codes and finding ways to make qubits more stable is a significant focus of current research. </p>
<p>Currently, quantum computers have a limited number of qubits. To be practical for widespread use, quantum computers need to scale up the number of qubits significantly without a corresponding increase in error rates. </p>
<p>Also those computers need to operate at extremely low temperatures, close to absolute zero, to maintain the quantum state of the qubits. Maintaining such conditions is technically challenging and expensive.</p>
<p>The consensus among experts is cautiously optimistic, but varies widely regarding when quantum computing will become practical for broad use. </p>
<p>Some experts believe that within the next decade, we'll begin to see quantum computers solving more practical, real-world problems, potentially revolutionizing fields like cryptography, materials science, and complex system simulation. Others think that these applications might remain out of reach for <strong>several more decades</strong>.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>The future of randomness in software engineering holds vast potential to drive innovation across multiple domains. </p>
<p>As we delve deeper into quantum computing and enhance our current technologies, randomness will play an increasingly critical role in shaping the next generation of software solutions, making them more secure, efficient, and reflective of the complex world they model.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/image-8.png" alt="Image" width="600" height="400" loading="lazy"></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is Steganography? How to Hide Data Inside Data ]]>
                </title>
                <description>
                    <![CDATA[ Ladies and Gentlemen, welcome to the world of Spies 🕵️. In the movie Uncharted (great movie by the way), Tom Holland and his brother have a secret form of communication. They would write a message on a plain postcard with special ink that became inv... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-steganography-hide-data-inside-data/</link>
                <guid isPermaLink="false">66bb9027d2bda3e4315491cd</guid>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ data ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Daniel Iwugo ]]>
                </dc:creator>
                <pubDate>Thu, 13 Jul 2023 17:15:06 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/08/pexels-cottonbro-4966171.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Ladies and Gentlemen, welcome to the world of Spies 🕵️.</p>
<p>In the movie Uncharted (great movie by the way), Tom Holland and his brother have a secret form of communication. They would write a message on a plain postcard with special ink that became invisible and then send it to the other person. </p>
<p>On the outside, it seemed like another plain old postcard. But if a lighter was lit just behind the paper, the ink would reappear, and a new message would be found 🔥. </p>
<p>This is one of the coolest hidden information tricks seen in movies. But what if we could do this on computers?</p>
<p>Well, turns out we sorta can. Using Steganography.</p>
<p><strong>Disclaimer: This concept can be used for both good and bad. The content of this article is for educational purposes only and is not to be used to play pranks, or harm people and infrastructure.</strong></p>
<p>And with that out of the way, here’s what we’re going to explore in this article:</p>
<ol>
<li>What is Steganography?</li>
<li>Types of Steganography – Text, Image, Video, Audio, Network</li>
<li>Image steganography using Steghide</li>
</ol>
<h2 id="heading-what-is-steganography">What is Steganography?</h2>
<p>Steganography is the art of hiding secret data in plain sight. It sounds kind of counter-intuitive, but you’d be surprised how effective it is. </p>
<p>Hiding things such as source code, passwords, IP addresses, and other confidential information in pictures, music, or other random files tends to be the last place anyone would think of finding them.</p>
<p>You should note that steganography and cryptography are not mutually exclusive from each other. One may contain elements of the other or both. For example, you could perform steganography with an encryption algorithm or password, as you’ll find out soon.</p>
<h2 id="heading-types-of-steganography">Types of Steganography</h2>
<p>There are various types of steganography, and we’ll look at five of them in this tutorial.</p>
<h3 id="heading-text-steganography">Text Steganography</h3>
<p>This form involves hiding a message within a text. A common way to do this is substitution. It involves replacing certain characters with others and then substituting them back to retrieve the original data. </p>
<p>For example, take the following text.</p>
<pre><code class="lang-markdown">Thi follow eng tixt contaens a sicrit missagi
</code></pre>
<p>Doesn’t really make sense right? But what if we replace the i’s with e’s and the e’s with i’s?</p>
<pre><code class="lang-markdown">The follow ing text contains a secret message
</code></pre>
<p>I think that’s a little easier on the eyes. This is a pretty easy example, but there are much more complicated ones and even some you could come up with on your own.</p>
<h3 id="heading-image-steganography">Image Steganography</h3>
<p>Frankly, this is my favourite. It involves hiding data behind digital images. There are various techniques for image steganography which include the Least Significant Bit technique, Masking and Filtering, and Coding and Cosine Transformation. </p>
<p>Take a look at the two images below and spot the difference:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/image-75.png" alt="Image" width="600" height="400" loading="lazy">
<em>Groot on Linux ¦ Credit: Mercury</em></p>
<p>Basically, no human on earth can tell the visual difference. But if you take a closer look at the file details…</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/image-76.png" alt="Image" width="600" height="400" loading="lazy">
<em>Comparing the images ¦ Credit: Mercury</em></p>
<p>The only difference is the size of the images. That’s because the one on the right is hiding 260 words of text in it. How cool is that?</p>
<h3 id="heading-video-steganography">Video Steganography</h3>
<p>In Video steganography, you can literally hide entire videos inside another video. Videos are basically a sequence of images with audio playing as the sequence progresses. This type of steganography allows each video frame to encode an image of the one you want to hide.</p>
<p>This technique can also be used to hide text as demonstrated in the software <a target="_blank" href="https://steganosaur.us">Steganosaurus</a> by James Ridgeway. He shows how it works in this <a target="_blank" href="https://youtu.be/YhnlHmZolRM">video</a>.</p>
<h3 id="heading-audio-steganography">Audio Steganography</h3>
<p>This type of steganography enables hidden messages to be encoded inside an audio file. A common technique used in this is called Backmasking. Backmasking is hiding a message in the audio file and it can only be heard when played backwards.</p>
<p>The famous rapper, Eminem, did some backmasking in the song ‘Stimulate’ back in 2002.</p>
<h3 id="heading-network-steganography">Network Steganography</h3>
<p>This is relatively rare, but nevertheless, it is a technique in which messages are passed by hiding them in network traffic. The messages could be found in the payload or headers of data packets when captured and analysed by the receiver.</p>
<p>Now let’s take a look at how to do some image steganography.</p>
<h2 id="heading-steganography-using-steghide">Steganography using Steghide</h2>
<p>Steghide is an open source image steganography tool that uses the least significant bit (LSB) method to hide data in images. </p>
<p>Images are made up of pixels, which are made up of bits. The bit depth determines how many colours are present in an image. The higher the bit depth, the more colourful the image tends to look.</p>
<p>What LSB does is change the last bit of each byte (or pixel) in the image to one that represents the data you want to hide. This changes the image data, but if done properly is not perceivable. The higher the bit depth and resolution, the more data can be stored in the image.</p>
<p>Now that you understand how it works, let’s play a little hide and seek (no pun intended 👀).</p>
<p>First we’ll be needing a few things:</p>
<ol>
<li>A Linux OS</li>
<li>An Internet Connection</li>
<li>An Image</li>
<li>A Text file</li>
</ol>
<h3 id="heading-install-steghide">Install Steghide</h3>
<p>First we need to install Steghide. Open your terminal and run the following command to do that:</p>
<pre><code class="lang-markdown">sudo apt install steghide
</code></pre>
<p>You can always run <code>steghide --help</code> to get the command list to see all your options.</p>
<h3 id="heading-get-your-image-ready">Get your image ready</h3>
<p>Next, have an image and a text file in a directory. My files are ‘information.txt’ and ‘image.png’. I’ve also put some text in the file to hide in the image later.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/image-77.png" alt="Image" width="600" height="400" loading="lazy">
<em>Setting up files ¦ Credit: Mercury</em></p>
<p>Open up your terminal again and go to the directory you stored the files. Mine is in <code>~/Documents/steganography_tutorial</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/image-78.png" alt="Image" width="600" height="400" loading="lazy">
<em>Looking for the files ¦ Credit: Mercury</em></p>
<h3 id="heading-create-a-new-image">Create a new image</h3>
<p>Next, run the following command to create a new image that contains the text file you want hide.</p>
<pre><code class="lang-markdown">steghide embed -ef <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">data</span>&gt;</span></span> -cf <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">image</span>&gt;</span></span> -sf <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">stego_image</span>&gt;</span></span> -v
</code></pre>
<p>Let’s take a look at the command:</p>
<ul>
<li><code>steghide</code> – We specify the tool to use</li>
<li><code>embed</code> – Tells the tool we want to embed data</li>
<li><code>-ef</code> – Embed file, specifies the file to hide</li>
<li><code>-cf</code> – Cover file, specifies the cover image</li>
<li><code>-sf</code> – Stego file, creates a duplicate of the original image with the embedded file in it</li>
<li><code>-v</code> – Verbose, gives us more information about the process</li>
</ul>
<p>When the command is run, you’ll be asked to enter a password. If you want an extra layer of security, you might want to do this. If you don’t, just hit enter twice. Here’s the result of what I ran:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/image-79.png" alt="Image" width="600" height="400" loading="lazy">
<em>Embedding the information ¦ Credit: Mercury</em></p>
<h3 id="heading-inspect-the-new-file">Inspect the new file</h3>
<p>Now let’s take a look at the new file.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/image-80.png" alt="Image" width="600" height="400" loading="lazy">
<em>Comparing the images side by side ¦ Credit: Mercury</em></p>
<p>There’s seems to be no difference. We can take a closer look with a site called <a target="_blank" href="https://www.diffchecker.com/image-compare/">diffchecker.com</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/image-81.png" alt="Image" width="600" height="400" loading="lazy">
<em>Comparing the images details ¦ Credit: Mercury</em></p>
<h3 id="heading-extract-the-data">Extract the data</h3>
<p>The stego file is slightly bigger than the original because it contains information. We can extract the data from the stego file using the command below.</p>
<pre><code class="lang-markdown">steghide extract -sf <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">stego_image</span>&gt;</span></span> -xf <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">extracted_data</span>&gt;</span></span>
</code></pre>
<p>Let’s review the command above:</p>
<ul>
<li><code>-sf</code> – stego file, the image containing hidden data</li>
<li><code>-xf</code> – extract file, the file with extracted data</li>
</ul>
<p>Below is the screenshot from running the command. The extracted text is also shown below.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/image-82.png" alt="Image" width="600" height="400" loading="lazy">
<em>Extracting the information ¦ Credit: Mercury</em></p>
<p>If you extracted the text, Congratulations 🎉🎊. You have successfully hidden and extracted the text from the image. You can do this with a number of things, even whole books.</p>
<p>Using a different tool called Stegcore, I hid a text file containing Quincy Larson’s new book, “<strong><a target="_blank" href="https://www.freecodecamp.org/news/learn-to-code-book/">How to Learn to Code &amp; Get a Developer Job</a></strong>”, behind an image of the book🔍.</p>
<p>Here’s an excerpt from the book.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/image-83.png" alt="Image" width="600" height="400" loading="lazy">
<em>An excerpt from the book ¦ Credit: Quincy Larson</em></p>
<p>And just like before, the text was embedded into a new image. Here is the original and the stego image side by side.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/image-84.png" alt="Image" width="600" height="400" loading="lazy">
<em>The original image compared to the stego image ¦ Credit: Mercury</em></p>
<p>And as expected, the stego image is slightly larger in size than the original.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/07/image-85.png" alt="Image" width="600" height="400" loading="lazy">
<em>The image details side by side ¦ Credit: Mercury</em></p>
<p>Talk about hiding a book behind a book (bad joke, I know 🤧). If you want to try it out, you can check out the Github <a target="_blank" href="https://github.com/elementmerc/Stegcore">repository</a> or the <a target="_blank" href="https://sourceforge.net/projects/stegcore/">app</a>.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>You’ve learned what steganography is and how to implement it using tools. Keep in mind that steganography is a tool and can be used for both good and bad. Companies can hide sensitive information using these means. On the other hand, a hacker could use it to hide malicious code.</p>
<p>Once again, this tutorial is for educational purposes only and is to be used to help and defend information from black hat hackers. Stay safe in the online jungle and happy hacking 🙃.</p>
<h3 id="heading-acknowledgements"><strong>Acknowledgements</strong></h3>
<p>Thanks to <a target="_blank" href="https://twitter.com/Anuoluwap__o">Anuoluwapo Victor</a>, <a target="_blank" href="https://www.linkedin.com/in/chinaza-nwukwa-22a256230/">Chinaza Nwukwa</a>, <a target="_blank" href="https://www.linkedin.com/in/mercy-holumidey-88a542232/">Holumidey Mercy</a>, <a target="_blank" href="https://www.linkedin.com/in/favour-ojo-906883199/">Favour Ojo</a>, <a target="_blank" href="https://www.linkedin.com/in/georgina-awani-254974233/">Georgina Awani</a>, and my family for the inspiration, support and knowledge used to put this together. I appreciate all of you.</p>
<p>If you want articles similar to this one, hit me up on <a target="_blank" href="https://www.upwork.com/freelancers/~01b1dea916f784d554">Upwork</a> or read more of my articles <a target="_blank" href="https://flipboard.com/@elementmerc">here</a>.</p>
<p>Cover image credit: Abstract Data Cube ¦ Credit: <a target="_blank" href="https://unsplash.com/@theshubhamdhage?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Shubham Dhage</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ SSH Keygen Tutorial – How to Generate an SSH Public Key for RSA Login ]]>
                </title>
                <description>
                    <![CDATA[ Cryptography uses encryption and decryption to conceal messages. This introduces secrecy in information security. The purpose of cryptography is to ensure secure communication between two people or devices who are connecting through insecure channels... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/ssh-keygen-how-to-generate-an-ssh-public-key-for-rsa-login/</link>
                <guid isPermaLink="false">66d84e28ec0a9800d5b8e6b5</guid>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ information security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ssh ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Bolaji Ayodeji ]]>
                </dc:creator>
                <pubDate>Tue, 30 Aug 2022 15:51:22 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/08/article-banner.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Cryptography uses encryption and decryption to conceal messages. This introduces secrecy in information security.</p>
<p>The purpose of cryptography is to ensure secure communication between two people or devices who are connecting through insecure channels.</p>
<p>The sender often employs an encryption key to lock the message, while the recipient uses a decryption key to unlock the message.</p>
<p>In general, cryptography employs two strategies:</p>
<ol>
<li><p><strong>Symmetric-key Cryptography (Private key):</strong> With this technique, the encryption and decryption keys are both known to the sender and receiver. Some examples of algorithms that use this technique include One Time Pad cipher, Vernam cipher, Playfair, Row column cipher, and Data Encryption Standard (DES).</p>
</li>
<li><p><strong>Asymmetric Key Cryptography (Public key):</strong> With this technique, each person has two keys: the Private (secret and accessible to the creator) and Public keys (freely available to anyone). The sender and receiver use different keys for encryption and decryption. Some examples of algorithms that use this technique include the Rivest–Shamir–Adleman algorithm (RSA), Diffie - Hellman Key Exchange (DHE), and the Digital Signature Algorithm (DSA).</p>
</li>
</ol>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Cryptography--2-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The Encryption Model for Secured Data Transmission</em></p>
<p>Software engineers generally have to authenticate with servers or other services like GitHub for version control.</p>
<p>As opposed to using password authentication, they can use public key authentication to generate and store a pair of cryptographic keys on their computer. Then they can configure the server running on another computer to recognize and accept those keys.</p>
<p>This is the asymmetric key cryptography technique flow we discussed earlier and it is a more secure authentication process.</p>
<p>In this tutorial, you will learn how it all works, what SSH means, and how to generate SSH keys with an RSA algorithm using SSH keygen.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<ul>
<li><p>A working computer running on any operating system.</p>
</li>
<li><p>Basic knowledge of navigating around the command-line.</p>
</li>
<li><p>A smile on your face :)</p>
</li>
</ul>
<h2 id="heading-brief-introduction-to-ssh-secure-shell-protocol">Brief Introduction to SSH (<strong>S</strong>ecure <strong>Sh</strong>ell Protocol)</h2>
<p>Public key authentication using SSH is a more secure approach for logging into services than passwords. Understanding SSH is easier once you understand how cryptography works from the above intro.</p>
<p>Here's a helpful basic definition:</p>
<blockquote>
<p>"The <strong>S</strong>ecure <strong>Sh</strong>ell Protocol is a <strong>cryptographic network protocol</strong> for operating network services securely <strong>over an unsecured network</strong>." (<a target="_blank" href="https://en.wikipedia.org/wiki/Secure_Shell">Source</a>)</p>
</blockquote>
<p>SSH is used between a client and a server both running on the SSH protocol to remotely login into the server and access certain resources through the command line.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/image-197.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Source: SSH Academy</em></p>
<p>There is an open-source version of the SSH protocol (version 2) with a suite of tools called <a target="_blank" href="https://www.openssh.com">OpenSSH</a> (also known as OpenBSD Secure Shell). This project includes the following tools:</p>
<ul>
<li><p>Remote operations: <a target="_blank" href="https://man.openbsd.org/ssh.1">ssh</a>, <a target="_blank" href="https://man.openbsd.org/scp.1">scp</a>, and <a target="_blank" href="https://man.openbsd.org/sftp.1">sftp</a>.</p>
</li>
<li><p>Key generation: <a target="_blank" href="https://man.openbsd.org/ssh-add.1">ssh-add</a>, <a target="_blank" href="https://man.openbsd.org/ssh-keysign.8">ssh-keysign</a>, <a target="_blank" href="https://man.openbsd.org/ssh-keyscan.1">ssh-keyscan</a>, and <a target="_blank" href="https://man.openbsd.org/ssh-keygen.1"><strong>ssh-keygen</strong></a>.</p>
</li>
<li><p>Service side: <a target="_blank" href="https://man.openbsd.org/sshd.8">sshd</a>, <a target="_blank" href="https://man.openbsd.org/sftp-server.8">sftp-server</a>, and <a target="_blank" href="https://man.openbsd.org/ssh-agent.1">ssh-agent</a>.</p>
</li>
</ul>
<h2 id="heading-how-to-generate-an-ssh-public-key-for-rsa-login">How to Generate an SSH Public Key for RSA Login</h2>
<p>Our goal is to use ssh-keygen to generate an SSH public key using the RSA algorithm. This will create a key pair containing a private key (saved to your local computer) and a public key (uploaded to your chosen service).</p>
<p>Now to proceed, follow the steps below to achieve this:</p>
<ol>
<li>Install OpenSSH if you don't have it installed already using the command below:</li>
</ol>
<pre><code class="lang-python">// <span class="hljs-keyword">for</span> mac

brew install openssh

// <span class="hljs-keyword">for</span> linux

sudo apt install openssh-client &amp;&amp; sudo apt install openssh-server
</code></pre>
<ol start="2">
<li>Create a private/public key pair with an RSA algorithm (2046-bit encryption by default), using the command:</li>
</ol>
<pre><code class="lang-python">ssh-keygen -t rsa
</code></pre>
<ol start="3">
<li>Or, if you want to create with an RSA algorithm with 4096-bit encryption, use the command:</li>
</ol>
<pre><code class="lang-python">ssh-keygen -t rsa -b <span class="hljs-number">4096</span>
</code></pre>
<ol start="4">
<li><p>Enter a file location to save the key to (by default it will save to your users directory (for example, <code>(/Users/bolajiayodeji/.ssh/id_rsa)</code> ).</p>
</li>
<li><p>Enter a passphrase for extra security to your private key. Generally, a good passphrase should have at least 15 characters (including at least one upper case letter, lower case letters, numerical digits, and special characters) and must be difficult to guess. You can use one of those password generators online or use hexdump to generate a paraphrase easily like so:</p>
</li>
</ol>
<pre><code class="lang-python">hexdump -vn16 -e<span class="hljs-string">'4/4 "%08X" 1 "\n"'</span> /dev/urandom
</code></pre>
<ol start="6">
<li>Once you've successfully created your password, your private key will be saved in <code>/&lt;your_chosen_directory&gt;/.ssh/id_rsa</code> and your public key will be saved in <code>/&lt;your_chosen_directory&gt;/.ssh/id_rsa.pub</code>.</li>
</ol>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/Screenshot-2022-08-30-at-1.18.15-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now you can copy the created key into the authorized_keys file of the server you want to connect to using ssh-copy-id (this tool is a part of openSSH) like so:</p>
<pre><code class="lang-python">ssh-copy-id username@remote_host
</code></pre>
<p>Alternatively, you'd want to add your SSH private key to the ssh-agent and store your passphrase in the keychain. You can then add the SHH key to your server's account via a dashboard UI or so (for example, using tools like Git or GitHub).</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Although a strong password helps prevent brute-force attacks, public key authentication provides a much more secure authentication process using cryptography.</p>
<p>I hope you found this article helpful. In addition, you can check out the <a target="_blank" href="https://man.openbsd.org/ssh-keygen.1">ssh-keygen manual page</a> and the following resources for further learning:</p>
<ul>
<li><p><a target="_blank" href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh">Connecting to GitHub with SSH</a></p>
</li>
<li><p><a target="_blank" href="https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse">Get started with OpenSSH for Windows</a></p>
</li>
</ul>
<p>Cheers! 💙</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Cipher Definition – What is a Block Cipher and How Does it Work to Protect Your Data? ]]>
                </title>
                <description>
                    <![CDATA[ By Megan Kaczanowski Cryptography is the science of using codes and ciphers to protect messages. And encryption involves encoding messages so that only the intended recipient can understand the meaning of the message. It's often used to protect data ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-a-block-cipher/</link>
                <guid isPermaLink="false">66d4607733b83c4378a5181a</guid>
                
                    <category>
                        <![CDATA[ ciphers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 03 Jun 2021 16:21:19 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/06/block-and-stream-cipher.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Megan Kaczanowski</p>
<p>Cryptography is the science of using codes and ciphers to protect messages. And encryption involves encoding messages so that only the intended recipient can understand the meaning of the message. It's often used to protect data in transit.</p>
<p>Encryption is a two way function – that is, you need to be able to undo whatever scrambling you’ve done to the message. </p>
<p>Today, there are two basic types of algorithms — symmetric and asymmetric. </p>
<p>Symmetric algorithms are also known as ‘secret key’ algorithms, and asymmetric algorithms are known as ‘public key’ algorithms. </p>
<p>The key difference between the two is that symmetric algorithms use the same key for encryption and decryption, while asymmetric algorithms use different keys for encryption and decryption. </p>
<p>For a general overview of cryptography and the difference between symmetric and asymmetric ciphers, check out <a target="_blank" href="https://www.freecodecamp.org/news/how-to-send-secret-messages/">this article</a>. </p>
<h2 id="heading-what-principles-are-important-when-youre-developing-a-cipher">What Principles are Important When You're Developing a Cipher?</h2>
<p>Kerckhoff's principle states that a cryptographic system should be secure, even if all the details (other than the key) are known publicly. Claude Shannon later rewrote this message as 'The enemy knows the system.' </p>
<p>Essentially, a very well designed system should be able to send secret messages even if an attacker can encrypt and decrypt their own messages using the same algorithm (with a different key). The security of the encrypted message should depend entirely on the key. </p>
<p>Additionally, in order to hinder statistical analysis (attempts to break an encryption algorithm), a good cryptographic system should employ the principles of confusion and diffusion. </p>
<p>Confusion requires that the key does not relate to the ciphertext in a simple manner. Each character of the ciphertext should depend on multiple parts of the key. The goal is to make it very difficult for an attacker to determine the key from the ciphertext.</p>
<p>Diffusion means that if a single character of the plaintext is changed, then several characters of the ciphertext should change. And if a single character of the ciphertext is changed, then several characters of the plaintext should change. </p>
<p>Ideally, the relationship between the ciphertext and the plaintext is hidden. No diffusion is perfect (all will have some patterns), but the best diffusion scatters patterns widely, even scrambling several patterns together. </p>
<p>Diffusion makes patterns hard for an attacker to spot, and requires the attacker to have more data in order to mount a successful attack.</p>
<p>If you want to read up on this a bit more, check out <a target="_blank" href="https://www.iacr.org/museum/shannon/shannon45.pdf">A Mathematical Theory of Cryptography</a>.</p>
<h2 id="heading-what-are-block-and-stream-ciphers">What are Block and Stream Ciphers?</h2>
<p>Both block and stream ciphers are symmetric key ciphers (like DES, RCx, Blowfish, and Rijndael AES). Block ciphers convert plaintext to ciphertext block by block, while stream ciphers convert one byte at a time. </p>
<p>Most modern symmetric algorithms are block ciphers, though the block sizes vary (such as DES (64 bits), AES (128, 192, and 256 bits), and so on).</p>
<h3 id="heading-what-is-the-advantage-of-a-stream-cipher">What is the advantage of a stream cipher?</h3>
<p>Stream encryption is faster (linear in time) and constant in space. It is unlikely to propagate errors, as an error in one byte's translation won't impact the next byte. </p>
<p>However, there's little diffusion as one plaintext symbol is directly translated to one ciphertext symbol. Also, the ciphertext is susceptible to insertions or modifications. If an attacker is able to break the algorithm, they may be able to insert text which looks authentic.</p>
<p>You typically use a stream cipher when the amount of plaintext is unknown (like audio or video streaming), or when extreme performance is important (like with very high speed connections, or for devices which need to be very efficient and compact, like smart cards).</p>
<p>A stream cipher works by generating a series of pseudorandom bytes which depend on the key (for any given key, the series of bytes is the same for encryption and decryption). Different keys will produce different strings of bytes. </p>
<p>In order to encrypt data the plaintext bytes are XORed with the string of pseudorandom bytes. To decrypt, the ciphertext is XORed with the same string in order to see the plaintext.</p>
<h3 id="heading-what-is-the-advantage-of-a-block-cipher">What is the advantage of a block cipher?</h3>
<p>A block cipher has high diffusion (information from one plaintext symbol is spread into several cipher-text symbols). It is also fairly difficult for an attacker to insert symbols without detection, because they can't easily insert them into the middle of a block.</p>
<p>However, it is slower than a stream cipher (an entire block needs to be transmitted before encryption/decryption can happen) and if an error does occur, it can propagate throughout the block, corrupting the entire section.</p>
<p>Block ciphers are a better choice when you know the transmission size – such as in file transfer. </p>
<h2 id="heading-what-are-the-common-modes-of-block-ciphers">What are the common modes of Block Ciphers?</h2>
<p>In order to encrypt data which is longer than a single block, there are several 'modes' which have been developed. These describe how to apply the single block principles to longer messages.</p>
<p>There are 5 confidentiality modes for block ciphers. Some of these modes require an initialization vector (IV) in order to function.</p>
<h3 id="heading-what-is-an-initialization-vector-iv">What is an Initialization Vector (IV)?</h3>
<p>An IV is essentially just another input (in addition to the plaintext and the key) used to create ciphertext. It's a data block, used by several modes of block ciphers to randomize encryption so that different cipher text is created even if the same plain text is repeatedly encrypted. </p>
<p>It usually does not need to be secret, though it cannot be re-used. Ideally, it should be random, unpredictable, and single-use. </p>
<p>Two of the same messages encrypted with the same key, but different IVs, will result in different ciphertext. This makes an attacker's job more difficult.</p>
<h3 id="heading-electronic-code-book-mode-ecb">Electronic Code Book Mode (ECB)</h3>
<p>There is a fixed mapping between input blocks of plaintext and output blocks of ciphertext (essentially like an actual code book where ciphertext words directly relate to plaintext words). </p>
<p>ECB applies the cipher function independently to each block of plaintext to encrypt it (and the inverse function to each block of ciphertext to decrypt it). This means that CBC can encrypt and decrypt multiple blocks in parallel (since they don't depend on each other), speeding up the process. </p>
<p><img src="https://megankaczanowski.com/content/images/2020/12/Screen-Shot-2020-12-31-at-8.22.20-PM.png" alt="Image" width="600" height="400" loading="lazy">
_https://en.wikipedia.org/wiki/Block_cipher_mode_of<em>operation</em></p>
<p>For this mode to work correctly, either the message length needs to be a multiple of the block size or you need to use padding for the length condition to be met. </p>
<p>Padding is essentially extra data that's added in order to ensure that the block size is met. With this mode, given the same key, the same plaintext block will always result in the same ciphertext block. That makes it vulnerable to attack, so this mode is rarely used (and should be avoided). </p>
<h3 id="heading-cipher-block-chaining-mode-cbc">Cipher Block Chaining Mode (CBC)</h3>
<p>This mode 'chains' or combines new plaintext blocks with the previous ciphertext block when encrypting them which requires an IV for the first block. The IV doesn't need to be secret, but it needs to be unpredictable.</p>
<p>CBC exclusive ors (XORs) the first block of plaintext with the IV ciphertext block to create the first ciphertext block. The IV is sent separately as a short message using ECB Mode. </p>
<p>Then, CBC applies the encryption algorithm to the block, creating the first block of ciphertext. CBC then XORs this block with the second plaintext block and the applies the encryption algorithm to produce the second ciphertext block, and so on until the end of the message.</p>
<p>In order to decrypt the message, CBC does the reverse - applies the inverse of the encryption algorithm to the first ciphertext block and then XORs the block with the IV to obtain the first plaintext block. </p>
<p>CBC then applies the inverse of the encryption algorithm to the second ciphertext block and XORs the block with the first ciphertext block to obtain the second plaintext block. This process continues until the message is decrypted.</p>
<p><img src="https://megankaczanowski.com/content/images/2020/12/Screen-Shot-2020-12-31-at-8.22.37-PM.png" alt="Image" width="600" height="400" loading="lazy">
_https://en.wikipedia.org/wiki/Block_cipher_mode_of<em>operation</em></p>
<p>Because each input block (except the first) relies on the previous block being encrypted, CBC can't perform encryption in parallel. However, since the decryption requires XORing with the (immediately available) ciphertext blocks, it can be done in parallel. CBC is one of the most commonly used modes.</p>
<p>Similarly to ECB, for this mode to work correctly, either the message length needs to be a multiple of the block size or you need to use padding for the length condition to be met.</p>
<h3 id="heading-cipher-feedback-mode-cfb">Cipher Feedback Mode (CFB)</h3>
<p>CFB is similar to CBC, but instead of using the entire previous ciphertext block to compute the next block, CFB uses a fraction of the previous block. </p>
<p>CFB starts with an IV of the same block size as expected by the block cipher, and encrypts it with the encryption algorithm. </p>
<p>CFB retains s (significant) bytes from this output and XORs them with s bytes of plaintext to be transmitted. </p>
<p>Then, CFB shifts the IV s bytes to the left, inserting the ciphertext bytes produced by step 2 as the righthand bytes (IV stays the same length).</p>
<p>Then it repeats these steps.</p>
<p>To decrypt a message, CFB uses the IV as the first block and forms each following block by performing step 3 above and applying the encryption algorithm to form blocks. CFB then XORs s bites with the corresponding ciphertext to reveal the plaintext.</p>
<p>Within CFB, the encryption system processes s &lt; b plaintext bits at a time, even though the algorithm itself carries out b-bits to b-bits transformation. This means that s can be any number, including 1 byte and CFP can functionally operate as a stream cipher. </p>
<p><img src="https://megankaczanowski.com/content/images/2020/12/Screen-Shot-2020-12-31-at-8.24.31-PM.png" alt="Image" width="600" height="400" loading="lazy">
_https://en.wikipedia.org/wiki/Block_cipher_mode_of<em>operation</em></p>
<p>Unfortunately, this means that CFB can propagate errors downstream. If a byte is received with an error, when CFB uses it to decrypt the first byte, it will produce an erroneous decryption, causing downstream errors when fed back into the decryption.</p>
<p>Like CBC, when CFB encrypts, the input to each round relies on the result of the previous round, meaning that encryption cannot be done in parallel, though decryption can be performed in parallel if the input blocks are first created from the IV and ciphertext.</p>
<h3 id="heading-output-feedback-ofb">Output Feedback (OFB)</h3>
<p>OFB is similar to CFB, but instead of processing s &lt; b bits into a b-bits to b-bits transformation, it processes s bits directly. Similarly to CFB, OFB can be functionally used as a stream cipher.</p>
<p>OFB requires that the IV be a unique nonce (number used once) for each execution with a given key. </p>
<p>First, OFB encrypts the IV with the encryption algorithm, to produce an output block. OFB then XORs this block with the first plaintext block, producing the first ciphertext block. </p>
<p>OFB encrypts the first output block with the encryption algorithm to produce the second output block. It then XORs this block with the second plaintext block to produce the second ciphertext block. OFB repeats this process for the length of the message.</p>
<p><img src="https://megankaczanowski.com/content/images/2020/12/Screen-Shot-2020-12-31-at-8.22.54-PM.png" alt="Image" width="600" height="400" loading="lazy">
_https://en.wikipedia.org/wiki/Block_cipher_mode_of<em>operation</em></p>
<p>When decrypting, OFB encrypts the IV with the encryption algorithm, producing an output block. OFB then XORs this block with the first ciphertext block, recovering the first plaintext block. </p>
<p>OFB encrypts the first output block with the encryption algorithm to produce the second output block. OFB then XORs it with the second ciphertext block to recover the second plaintext block. OFB repeats this process for the length of the message.</p>
<p>Because the output blocks for decryption are locally generated, OFB is more resistant to transmission errors than CFB.</p>
<h3 id="heading-counter-ctr">Counter (CTR)</h3>
<p>CTR applies the encryption algorithm to a set of unique input blocks (counters) in order to produce outputs which are XORed with the plaintext to produce ciphertext. </p>
<p>CTR encrypts the first counter with the encryption algorithm, then XORs the resulting output with the first plaintext block to produce the first ciphertext block. CTR repeats this for each block (with a new counter – counters must be unique across all messages encrypted using a single key). </p>
<p>If the final block is a partial block of s bytes, the most significant bits, s, of the output block are used for the XOR, while the b - s bytes of the output block are discarded.</p>
<p><img src="https://megankaczanowski.com/content/images/2020/12/Screen-Shot-2020-12-31-at-8.23.02-PM.png" alt="Image" width="600" height="400" loading="lazy">
_https://en.wikipedia.org/wiki/Block_cipher_mode_of<em>operation</em></p>
<p>The decryption follows the same pattern. CTR encrypts the counter with the encryption algorithm, then XORs the output with the corresponding ciphertext block to produce the plaintext block. </p>
<p>If the final block is a partial block of s bytes, the most significant bits, s, of the output block are used for the XOR, while the b - s bytes of the output block are discarded.</p>
<p>CTR has been shown to be at least as secure as the other four modes, while also being able to be executed in parallel (both encryption and decryption), meaning that it is very fast. </p>
<p>Each block can be recovered independently if its counter block can be determined and the encryption can be applied to the counters in advance of receiving the plaintext or ciphertext (if memory is no constraint).</p>
<p>Further Reading: <a target="_blank" href="https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf">NIST Recommendation for Block Cipher Modes of Operation</a></p>
<h2 id="heading-how-do-attackers-attempt-to-break-ciphers">How do Attackers Attempt to Break Ciphers?</h2>
<p>There are a number of techniques attackers use, but they broadly fall into the following categories of attack, based on information required to carry it out. </p>
<p>This isn't an exhaustive list (there are other attacks such side channel attacks), but many of the most common fall into one of these categories.</p>
<h3 id="heading-known-ciphertext-attack">Known Ciphertext Attack</h3>
<p>An attacker has some ciphertext, but does not know what plaintext was used to generate this ciphertext. The attacker does not get to choose which ciphertext they have and they cannot obtain/produce more. </p>
<p>This is the easiest type of attack to try, since it's easiest to eavesdrop on an encrypted conversation (since presumably the people having the conversation are using strong encryption and aren't as worried about eavesdroppers). But it's the hardest to be successful, as long as the people sending messages used appropriately strong encryption. </p>
<p>_For example: David finds an encrypted message (ciphertext) in a <a target="_blank" href="https://en.wikipedia.org/wiki/Dead_drop#:~:text=A%20dead%20drop%20or%20dead,individuals%20can%20maintain%20operational%20security.">dead drop</a>, but has no idea what the message means._</p>
<h3 id="heading-known-plaintext-attack">Known Plaintext Attack</h3>
<p>An attacker has some plaintext and ciphertext pairs which they didn't choose (so the attacker didn't choose the message that was encrypted, but was able to successfully steal a plaintext message and its associated ciphertext). The attacker cannot obtain/produce more pairs.</p>
<p><em>For example: David finds an enemy spy's hiding place and interrupts him while he is sending an encrypted message. The spy is silly enough to have fled, leaving both the plaintext message and its associated ciphertext written down.</em></p>
<h3 id="heading-chosen-plaintext-attack">Chosen Plaintext Attack</h3>
<p>An attacker can choose any plaintext and obtain the ciphertext in return (but they can't see the key itself).</p>
<p>This is further broken down into batch chosen plaintext (where the attacker can submit a set of plaintexts and receive the ciphertext, but cannot do so again) and adaptive chosen-plaintext (where the attacker can submit plaintext, receive the ciphertext and submit additional plaintext based on the previous ciphertext.)</p>
<p><em>For example: One nation-state is eavesdropping on another's encrypted communication and knows they use the same key for all of their encryption. They send a sensitive diplomatic communication to the other nation-state, knowing it will be transmitted via the encrypted channel, thus giving them a chosen plaintext - ciphertext pair.</em></p>
<h3 id="heading-chosen-ciphertext-attack">Chosen Ciphertext Attack</h3>
<p>This is the opposite of the last attack, where the attacker can choose any ciphertext and obtain the plaintext in return (but they can't see the key itself).</p>
<p><em>For example:  David knows an enemy spy is going to send an encrypted message tomorrow, so he replaces the text with his own chosen ciphertext, then spies on the recipient, listening as they read out the plaintext of the message.</em></p>
<h3 id="heading-sourcesfurther-reading">Sources/Further Reading:</h3>
<ul>
<li><a target="_blank" href="https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf">NIST Recommendations for Block Cipher Modes of Operation</a></li>
<li><a target="_blank" href="https://www.nku.edu/~christensen/diffusionandconfusion">Diffusion and Confusion</a></li>
<li><a target="_blank" href="https://en.wikipedia.org/wiki/Confusion_and_diffusion">Confusion and Diffusion</a></li>
<li><a target="_blank" href="https://en.wikipedia.org/wiki/Kerckhoffs%27s_principle">Kerckhoffs's Principle</a></li>
<li><a target="_blank" href="http://www.crypto-it.net/eng/theory/padding.html">Padding Mechanisms</a></li>
<li><a target="_blank" href="https://www.cs.utexas.edu/~byoung/cs361/lecture45.pdf">Foundations of Computer Science: Stream and Block Encryption</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is Commit Signing in Git? ]]>
                </title>
                <description>
                    <![CDATA[ Git has a feature to "sign" commits, but what is signing, and what are the benefits? TL;DR: If you don't care for the details, and just need to get commit signing setup quickly, skip to How to Sign Commits. Signing, or code signing specifically, is t... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-commit-signing-in-git/</link>
                <guid isPermaLink="false">66d460fc51f567b42d9f84bc</guid>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Git ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Seth Falco ]]>
                </dc:creator>
                <pubDate>Wed, 02 Jun 2021 23:14:01 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/05/cover-1.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p><a target="_blank" href="https://git-scm.com/">Git</a> has a feature to "sign" commits, but what is signing, and what are the benefits?</p>
<p><strong>TL;DR:</strong> If you don't care for the details, and just need to get commit signing setup quickly, skip to <a class="post-section-overview" href="#heading-how-to-sign-commits-in-git">How to Sign Commits</a>.</p>
<p>Signing, or code signing specifically, is the process of using cryptography to digitally add a signature to data. The receiver of the data can verify that the signature is authentic, and therefore must've come from the signatory.</p>
<p>It's like physical signatures, but digital and more reliable.</p>
<h1 id="heading-gits-default-behavior">Git's Default Behavior</h1>
<p>First let's note that all commits have the following properties:</p>
<ul>
<li><p>Author – The contributor who did the work, this is <em>informational.</em></p>
</li>
<li><p>Committer – The user who committed the change.</p>
</li>
</ul>
<p>In most cases, these will be the same, but they can be overridden when committing, so it's important to note the difference.</p>
<p>When you first installed Git, you probably had to configure a few settings, namely <code>user.email</code> and <code>user.name</code>. This may've been handled for you depending on your Git client.</p>
<p>In the command line, this requires executing the following commands:</p>
<pre><code class="lang-shell">git config --global user.email "seth@example.org"
git config --global user.name "Seth Falco"
</code></pre>
<p>Git commits are trust-based, so it'll assume you put in your real email and name. You can then commit and push to remote providers like GitHub and GitLab with the details provided.</p>
<p>What happens when someone else uses your email address, and then pushes changes remotely?</p>
<pre><code class="lang-shell">git config --global user.email "seth@example.org"
git commit -m "Jen did this."
git push origin main
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/figure-1-c.png" alt="Jen made a commit, but it shows my name and links to my GitHub profile." width="600" height="400" loading="lazy"></p>
<p>The result looks normal, but I'm not the one who did this commit. Jen committed to her repository, authenticating with her GitHub credentials, but it's showing my name and linking to my profile. The default behavior sets both the author and committer to the details in <code>git config</code>.</p>
<p>On GitHub, the commit is already indistinguishable from my own. If a user set both <code>user.email</code> and <code>user.name</code> to mine, which they can get from doing <code>git log</code> on any of my commits, then even locally it'd look the same.</p>
<p>This means that anyone can set their <code>user.email</code> to your email address, and it'd look like you made the commit.</p>
<h1 id="heading-why-does-git-do-this">Why Does Git Do This?</h1>
<p>You might wonder why this is possible. You authenticate to your account when you push to the repository after all, shouldn't it use that email? Doesn't this seem a bit flawed?</p>
<p>When you authenticate to push to remote repositories, you're authenticating to do just that– push changes. The commits don't require authentication regardless of who authored or committed them.</p>
<p>If commits required authentication by default, it'd be impossible to migrate or mirror projects to other platforms. The commit history will include former employees, dead users, inactive accounts, or email addresses that aren't on other platforms.</p>
<p>The only solution would be to rewrite the history to remove that they ever worked on the project, which isn't ideal.</p>
<p>Another scenario would be if I forked a project on GitHub, but want to maintain my fork on GitLab. My first push would include all commits from previous committers. For a large project, it's not feasible to authenticate every committer.</p>
<p>The author of a commit signifies attribution for who did the work, not proof of who did the work.</p>
<p>In fact, you can always override the author when committing just for this purpose. Using the <code>--author</code> argument, you can specify a different name and email to your global settings, even details that aren't associated with an account where the repository is hosted.</p>
<p>On public repositories, be mindful when committing on behalf of someone without an account, though. Names and email addresses become public information once pushed, and are accessible to anyone using <code>git log</code>!</p>
<pre><code class="lang-shell">git commit -m "Jen didn't even author this." --author "Jen &lt;jen@example.org&gt;"
git push origin main
</code></pre>
<p>This has different behavior than using another email in <code>git config</code>. This makes the author what we specified in <code>--author</code>, but the committer what we specified in <code>git config</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/figure-2-c.png" alt="GitHub displays that Jen is the author and that I am the committer." width="600" height="400" loading="lazy"></p>
<p>Translation platforms like <a target="_blank" href="https://weblate.org/">Weblate</a> rely on this feature to ensure translators still get attribution, even though an automated user commits and opens the pull requests, not the translator.</p>
<h1 id="heading-how-to-prove-youre-the-committer-in-git">How to Prove You're the Committer in Git</h1>
<p><a target="_blank" href="https://gnupg.org/">GNU Privacy Guard</a> (GnuPG or GPG) allows you to create cryptographic asymmetric key pairs that can be used for the encryption and signing of data. They consist of a public and private key.</p>
<p>You can share the public-key with anyone – you may upload this to your GitHub and GitLab accounts, or put it on the internet for anyone to access.</p>
<p>The private-key, as the name suggests, is private. You should treat this like a password, and under no circumstances should you ever share your private-key with anyone.</p>
<p>We'll be generating a key pair, and then uploading the public key to GitHub and GitLab. Using your private-key, you can sign your commits, and servers with the public key will use it to confirm it was really you.</p>
<h1 id="heading-how-to-sign-commits-in-git">How to Sign Commits in Git</h1>
<p>I'll only cover how to do this in the terminal, since this provides a uniform experience across operating systems. If you're uncomfortable with the terminal, you pretty much just have to copy the commands.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>The only prerequisite, other than Git itself, is to install the GPG command-line utility.</p>
<p>You can verify if it's installed with <code>gpg --version</code>.</p>
<h3 id="heading-windows">Windows</h3>
<h4 id="heading-git-bash">Git BASH</h4>
<p>If you have Git BASH installed (optionally bundled with <a target="_blank" href="https://gitforwindows.org/">Git for Windows</a>), then you already have access to GPG. Just launch an instance of Git BASH, and it'll be available immediately.</p>
<h4 id="heading-gpg4win">Gpg4win</h4>
<p>If you don't have Git BASH, then there's no need to install it. You can install <a target="_blank" href="https://gpg4win.org/download.html">Gpg4win</a>, which will provide GPG globally, so you can just use it from PowerShell.</p>
<p>When installing Gpg4win, you can untick all the additional components, as we won't be needing them since we plan to use the terminal.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/figure-3-1.png" alt="The Choose Components screen on Gpg4win Setup with all additional components unchecked." width="600" height="400" loading="lazy"></p>
<p>If you already had PowerShell open, you'll have to restart it before you can use GPG.</p>
<h3 id="heading-linux">Linux</h3>
<p>Your distribution most likely already includes GPG. If not, then you can install it through your package manager.</p>
<h4 id="heading-apt-debian-ubuntu">apt (Debian / Ubuntu)</h4>
<p><code>sudo apt install gnupg</code></p>
<h4 id="heading-pacman-arch-manjaro">pacman (Arch / Manjaro)</h4>
<p><code>sudo pacman -S gnupg</code></p>
<h2 id="heading-how-to-generate-gpg-keys">How to Generate GPG Keys</h2>
<p>If you already have a GPG key, you can skip this step. It's perfectly fine to reuse GPG keys. Just read below and verify that your key is compatible with Git and GitHub.</p>
<p>You can get a list of your GPG keys with:</p>
<pre><code class="lang-shell">gpg --list-keys
</code></pre>
<p>First we need to generate an RSA key pair. The following will start an interactive script that will ask questions so we can provide the necessary information.</p>
<pre><code class="lang-shell">gpg --full-gen-key
</code></pre>
<ol>
<li><p>For what kind of key you want, input <code>1</code> which is "RSA and RSA".</p>
</li>
<li><p>For key size, input <code>4096</code>. This is the minimum size for GitHub and GitLab, and the maximum size GPG will let us generate.</p>
</li>
<li><p>For how long the key should last, use whatever suits you. The default is <code>0</code>, which means to never expire.</p>
</li>
<li><p>Verify the information is correct by inputting <code>y</code>.</p>
</li>
</ol>
<p>GPG will ask for personal information which is stored in your key.</p>
<ol>
<li><p>Your name, this can be anything at least 5 characters in length.</p>
</li>
<li><p>Your email address, use an email you plan to commit with. You must've verified this email on the remote account you'll push with.</p>
</li>
<li><p>A comment, you can type whatever, or press enter to leave it blank.</p>
</li>
<li><p>Verify the information is correct by inputting <code>o</code>.</p>
</li>
</ol>
<pre><code class="lang-plaintext">root@799d1cc3c99c:/# gpg --full-gen-key
gpg (GnuPG) 2.2.19; Copyright (C) 2019 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
  (14) Existing key from card
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 4096
Requested keysize is 4096 bits
Please specify how long the key should be valid.
         0 = key does not expire
      &lt;n&gt;  = key expires in n days
      &lt;n&gt;w = key expires in n weeks
      &lt;n&gt;m = key expires in n months
      &lt;n&gt;y = key expires in n years
Key is valid for? (0) 0
Key does not expire at all
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name: Seth Falco
Email address: seth@example.org
Comment: 
You selected this USER-ID:
    "Seth Falco &lt;seth@example.org&gt;"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
</code></pre>
<p>GPG will ask for a passphrase to protect the key. You can set this to anything, or leave it blank for no passphrase at all. Of course, it's ideal to use a good passphrase, rely on your password manager if you use one.</p>
<p>The password prompt is environment-dependent, so this step will look different for different users, but what it's asking is effectively the same.</p>
<p>It'll start generating the key, which requires a lot of randomly generated data. Performing actions on your PC will help make it more random, so I'd recommend moving your mouse around while the key is generating.</p>
<h2 id="heading-how-to-export-your-keys">How to Export Your Keys</h2>
<p>Next you need to get the identifier of the newly generated key so we can refer to it when exporting your key and configuring Git.</p>
<p>GPG keys can be referred to in multiple ways. It's a good a habit to use and share the full fingerprint, to minimize the risk of ambiguity when users request it from a key server. Long (64-bit) IDs are fine <em>for now</em>, but short (32-bit) IDs are best avoided, as it's easy to produce a collision. (<a target="_blank" href="https://evil32.com/">More Info</a>)</p>
<p>We'll be using the full GPG fingerprint, which we can get with the command:</p>
<pre><code class="lang-shell">gpg --list-keys
</code></pre>
<p>You'll get output like the following:</p>
<pre><code class="lang-shell">pub   rsa4096 2021-05-23 [SC]
      C6656513A0F9B7B7F4E76389EF39187D04795745
uid           [ultimate] Seth Falco &lt;seth@example.org&gt;
sub   rsa4096 2021-05-23 [E]
</code></pre>
<p>For me, it's <code>C6656513A0F9B7B7F4E76389EF39187D04795745</code>. Make sure to use your fingerprint instead of mine when you do the rest of the commands.</p>
<p>You need to export the public-key so you can upload it to GitHub. We use the <code>--armor</code> argument to indicate that we want to export it in an <a target="_blank" href="https://en.wikipedia.org/wiki/Binary-to-text_encoding">ASCII armored</a> format instead of binary. This writes the public-key to a file named <code>gpg-key.pub</code>.</p>
<pre><code class="lang-shell">gpg --export --armor C6656513A0F9B7B7F4E76389EF39187D04795745 &gt; ./gpg-key.pub
</code></pre>
<h3 id="heading-how-to-back-up-your-keys">How to Back Up Your Keys</h3>
<p>It's worth having a remote backup of your GPG keys because you'll likely use them across services. If you lose it, it'd be a pain to have to update everything.</p>
<p>You can export your private-key in the same way we exported the public-key, this writes the private-key to a file named <code>gpg-key.asc</code>:</p>
<pre><code class="lang-shell">gpg --export-secret-keys --armor C6656513A0F9B7B7F4E76389EF39187D04795745 &gt; ./gpg-key.asc
</code></pre>
<p>You can now back up both your public and private keys, but remember that you should never send the non-encrypted copy of the private-key to the cloud. Always use end-to-end encrypted cloud storage, or a password manager like <a target="_blank" href="https://bitwarden.com/">Bitwarden</a> to back up sensitive data.</p>
<h2 id="heading-how-to-enable-commit-signing">How to Enable Commit Signing</h2>
<p>Then to enable signing all commits, set the <code>commit.gpgsign</code> setting using <code>git config</code>. This will make <code>git commit</code> sign commits by default.</p>
<pre><code class="lang-shell">git config --global commit.gpgsign true
</code></pre>
<p>If you have multiple GPG keys, or just for future reference, you may want to set <code>user.signingkey</code> as well. This will indicate specifically which key Git should use for signing to avoid ambiguity.</p>
<pre><code class="lang-shell">git config --global user.signingkey C6656513A0F9B7B7F4E76389EF39187D04795745
</code></pre>
<h2 id="heading-how-to-use-your-key">How to Use your Key</h2>
<p>Finally, you have to upload your public key. You can use the same GPG key for both GitHub and GitLab, or any other Git provider.</p>
<p>We'll need the exported public-key for the following steps, so open the <code>gpg-key.pub</code> file in any editor like Visual Studio Code, and copy the contents to your clipboard.</p>
<p>On GitHub, you can go to your <a target="_blank" href="https://github.com/settings/profile">settings</a>, under "<a target="_blank" href="https://github.com/settings/keys">SSH and GPG keys</a>", then click "<a target="_blank" href="https://github.com/settings/gpg/new">New GPG key</a>". Paste the contents of <code>gpg-key.pub</code> into the Key field on GitHub, and click "Add GPG key".</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/figure-4-c-1.png" alt="Adding a GPG key in the GitHub settings." width="600" height="400" loading="lazy"></p>
<p>On GitLab, the steps are almost identical, just go to your <a target="_blank" href="https://gitlab.com/-/profile/preferences">preferences</a>, then "<a target="_blank" href="https://gitlab.com/-/profile/gpg_keys">GPG Keys</a>". Paste the contents of <code>gpg-key.pub</code> into the Key field on GitLab, and click "Add key".</p>
<p>Now you're able to make signed commits to your repositories! The next commit will prompt for your GPG key password, since it's the first time using it. Subsequent commits will be seamless.</p>
<h1 id="heading-how-to-verify-commits-in-git">How to Verify Commits in Git</h1>
<p>GitHub and GitLab will show a "Verified" badge next to your new commits.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/figure-5-c.png" alt="A signed commit on GitHub, it shows a verified badge on the side." width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/figure-6-c-2.png" alt="A signed commit on GitLab, it shows a verified badge on the side." width="600" height="400" loading="lazy"></p>
<p>The final thing to remember is that commit signing will only verify the committer, not the author. That means when you see a verified commit, the author has nothing to do with the verified status.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/figure-7-c-1.png" alt="A signed commit with the verified badge, but Jen didn't author this commit." width="600" height="400" loading="lazy"></p>
<h2 id="heading-vigilant-mode">Vigilant Mode</h2>
<p>As a bonus, on GitHub specifically there is a setting called <a target="_blank" href="https://docs.github.com/en/github/authenticating-to-github/managing-commit-signature-verification/displaying-verification-statuses-for-all-of-your-commits">vigilant mode</a>.</p>
<p>You can optionally enable this if you want all unsigned commits to explicitly say "Unverified". This can be enabled in your <a target="_blank" href="https://github.com/settings/profile">settings</a>, under "<a target="_blank" href="https://github.com/settings/keys">SSH and GPG keys</a>", then tick "Flag unsigned commits as unverified".</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/figure-8-c-2.png" alt="The vigilant mode setting on GitHub." width="600" height="400" loading="lazy"></p>
<p>Now the commit that Jen did with my email address shows "Unverified" next to it, to indicate that it wasn't signed with a key associated with my account.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/figure-9-c.png" alt="The commit that Jen did with my details earlier, now showing an unverified badge next to it." width="600" height="400" loading="lazy"></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Diffie-Hellman: The Genius Algorithm Behind Secure Network Communication ]]>
                </title>
                <description>
                    <![CDATA[ Let's start with a quick thought experiment. You have a network of 3 computers, used by Alice, Bob, and Charlie. All 3 participants can send messages, but just in a way that all other clients who connected to the network can read it. This is the only... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/diffie-hellman-key-exchange/</link>
                <guid isPermaLink="false">66be1f210eaa7ceb6eaeaa16</guid>
                
                    <category>
                        <![CDATA[ algorithms ]]>
                    </category>
                
                    <category>
                        <![CDATA[ computer network ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ cybersecurity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ David Karolyi ]]>
                </dc:creator>
                <pubDate>Mon, 11 May 2020 18:53:11 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9b21740569d1a4ca29e4.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Let's start with a quick thought experiment.</p>
<p>You have a network of 3 computers, used by Alice, Bob, and Charlie. All 3 participants can send messages, but just in a way that all other clients who connected to the network can read it. This is the only possible communication form between participants.</p>
<p>If Alice sends a message through the wires, both Bob and Charlie get it. In other words, Alice cannot send a direct message to Bob without Charlie receiving it as well.</p>
<p>But Alice wants to send a confidential message to Bob and doesn't want Charlie to be able to read it.</p>
<p>Seems impossible with these strict rules, right? The beautiful thing that this problem is solved in 1976 by Whitfield Diffie and Martin Hellman.</p>
<p>This is a simplified version of the real world, but we face the same problem when communicating through the biggest network that's ever existed.</p>
<p>Usually, you are not directly connected to the internet, but you are part of a local smaller network, called Ethernet. </p>
<p>This smaller network can be wired or wireless (Wi-Fi), but the base concept remains. If you send a signal through the network this signal can be read by all other clients connected to the same network.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/10/network-ethernet.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Once you emit a message to your bank's server with your credit card information, all other clients in the local network will get the message, including the router. It will then forward it to the actual server of the bank. All other clients will ignore the message.</p>
<p>But what if there is a malicious client in the network who won't ignore your confidential messages, but read them instead? How is it possible you still have money on your bank account?</p>
<h2 id="heading-encryption">Encryption</h2>
<p>It's kind of clear at this point that we need to use some kind of encryption to make sure that the message is readable for Alice and Bob, but complete gibberish for Charlie.</p>
<p>Encrypting information is done by an encryption algorithm, which takes a key (for example a string) and gives back an encrypted value, called ciphertext. The ciphertext is just a completely random-looking string.</p>
<p>It's important that the encrypted value (ciphertext) can be decrypted only with the original key. This is called a symmetric-key algorithm because you need the same key for decrypting the message as it was encrypted with. There are also asymmetric-key algorithms, but we don't need them right now.</p>
<p>To make it easier to understand this, here is a dummy encryption algorithm implemented in JavaScript:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">encrypt</span>(<span class="hljs-params">message, key</span>) </span>{
    <span class="hljs-keyword">return</span> message.split(<span class="hljs-string">""</span>).map(<span class="hljs-function"><span class="hljs-params">character</span> =&gt;</span> {
        <span class="hljs-keyword">const</span> characterAsciiCode = character.charCodeAt(<span class="hljs-number">0</span>)
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">String</span>.fromCharCode(characterAsciiCode+key.length)
    }).join(<span class="hljs-string">""</span>);
}
</code></pre>
<p>In this function, I mapped each character into another character based on the length of the given key.</p>
<p>Every character has an integer representation, called ASCII code. There is a dictionary that contains all characters with its code, called the ASCII table. So we incremented this integer by the length of the key:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/image-13.png" alt="Image" width="600" height="400" loading="lazy">
<em>Character mapping</em></p>
<p>Decrypting the ciphertext is pretty similar. But instead of addition, we subtract the key length from every character in the ciphertext, so we get back the original message.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">decrypt</span>(<span class="hljs-params">cipher, key</span>) </span>{
    <span class="hljs-keyword">return</span> cipher.split(<span class="hljs-string">""</span>).map(<span class="hljs-function"><span class="hljs-params">character</span> =&gt;</span> {
        <span class="hljs-keyword">const</span> characterAsciiCode = character.charCodeAt(<span class="hljs-number">0</span>)
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">String</span>.fromCharCode(characterAsciiCode-key.length)
    }).join(<span class="hljs-string">""</span>);
}
</code></pre>
<p>Finally here is the dummy encryption in action:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> message = <span class="hljs-string">"Hi Bob, here is a confidential message!"</span>;
<span class="hljs-keyword">const</span> key = <span class="hljs-string">"password"</span>;

<span class="hljs-keyword">const</span> cipher = encrypt(message, key);
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Encrypted message:"</span>, cipher);
<span class="hljs-comment">// Encrypted message: Pq(Jwj4(pmzm(q{(i(kwvnqlmv|qit(um{{iom)</span>

<span class="hljs-keyword">const</span> decryptedMessage = decrypt(cipher, key);
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Decrypted message:"</span>, decryptedMessage);
<span class="hljs-comment">// Decrypted message: Hi Bob, here is a confidential message!</span>
</code></pre>
<p>We applied some degree of encryption to the message, but this algorithm was only useful for demonstration purposes, to get a sense of how symmetric-key encryption algorithms behave. </p>
<p>There are a couple of problems with this implementation besides handling corner cases and parameter types poorly.</p>
<p>First of all every 8 character-long key can decrypt the message which was encrypted with the key "password". We want an encryption algorithm to only be able to decrypt a message if we give it the same key that the message was encrypted with. A door lock that can be opened by every other key isn't that useful.</p>
<p>Secondly, the logic is too simple – every character is shifted the same amount in the ASCII table, which is too predictable. We need something more complex to make it harder to find out the message without the key.</p>
<p>Thirdly, there isn't a minimal key length. Modern algorithms work with at least 128 bit long keys (~16 characters). This significantly increases the number of possible keys, and with this the secureness of encryption.</p>
<p>Lastly, it takes too little time to encrypt or decrypt the message. This is a problem because it doesn't take too much time to try out all possible keys and crack the encrypted message. </p>
<p>This is hand in hand with the key length: An algorithm is secure if I as an attacker want to find the key, then I need to try a large number of key combinations and it takes a relatively long time to try a single combination.</p>
<p>There is a wide range of symmetric encryption algorithms that addressed all of these claims, often used together to find a good ratio of speed and secureness for every situation.</p>
<p>The more popular symmetric-key algorithms are <a target="_blank" href="http://en.wikipedia.org/wiki/Twofish">Twofish</a>, <a target="_blank" href="http://en.wikipedia.org/wiki/Serpent_%28cipher%29">Serpent</a>, <a target="_blank" href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard">AES</a> (<a target="_blank" href="http://en.wikipedia.org/wiki/Rijndael">Rijndael</a>), <a target="_blank" href="http://en.wikipedia.org/wiki/Blowfish_%28cipher%29">Blowfish</a>, <a target="_blank" href="http://en.wikipedia.org/wiki/CAST5">CAST5</a>, <a target="_blank" href="http://en.wikipedia.org/wiki/RC4">RC4</a>, <a target="_blank" href="http://en.wikipedia.org/wiki/Triple_DES">TDES</a>, and <a target="_blank" href="http://en.wikipedia.org/wiki/International_Data_Encryption_Algorithm">IDEA</a>.</p>
<p>If you want to learn more about cryptography in general check out <a target="_blank" href="https://www.youtube.com/watch?v=cqgtdkURzTE">this talk</a>.</p>
<h2 id="heading-key-exchange">Key exchange</h2>
<p>It looks like we reduced the original problem space. With encryption, we can create a message which is meaningful for parties who are eligible to read the information, but which is unreadable for others.</p>
<p>When Alice wants to write a confidential message, she would pick a key and encrypt her message with it and send the ciphertext through the wires. Both Bob and Charlie would receive the encrypted message, but none of them could interpret it without Alice's key.</p>
<p>Now the only question to answer is how Alice and Bob can find a common key just by communicating through the network and prevent Charlie from finding out that same key.</p>
<p>If Alice sends her key directly through the wires Charlie would intercept it and would be able to decrypt all Alice's messages. So this is not a solution. This is called the key exchange problem in computer science.</p>
<h3 id="heading-diffiehellman-key-exchange">Diffie–Hellman key exchange</h3>
<p>This cool algorithm provides a way of generating a shared key between two people in such a way that the key can't be seen by observing the communication.</p>
<p>As a first step, we'll say that there is a huge prime number, known to all participants, it's public information. We call it <strong>"p" or modulus</strong>. </p>
<p>There is also another public number called <strong>"g" or base</strong>, which is less than <strong>p</strong>. </p>
<p>Don't worry about how these numbers are generated. For the sake of simplicity let's just say Alice picks a very big prime number (<strong>p</strong>) and a number which is considerably less than <strong>p</strong>. She then sends them through the wires without any encryption, so all participants will know these numbers.</p>
<p><strong>Example:</strong> To understand this through an example, we'll use small numbers. Let's say <strong>p=23</strong> and <strong>g=5</strong>.</p>
<p>As a second step both Alice (<strong>a</strong>) and Bob (<strong>b</strong>) will pick a secret number, which they won't tell anybody, it's just locally living in their computers.</p>
<p><strong>Example:</strong> Let's say Alice picked 4 (<strong>a=4</strong>), and Bob picked 3 (<strong>b=3</strong>).</p>
<p>As a next step, they will do some math on their secret numbers, they will calculate:</p>
<ol>
<li>the base (<strong>g</strong>) in the power of their secret number,</li>
<li>and take the calculated number's modulo to <strong>p</strong>.</li>
<li>Call the result <strong>A</strong> (for Alice) and <strong>B</strong> (for Bob).</li>
</ol>
<p>Modulo is a simple mathematical statement, and we use it to find the remainder after dividing one number by another. Here is an example: <strong>23 mod 4 = 3</strong>, because 23/4 is 5 and 3 remains.</p>
<p>Maybe it's easier to see all of this in code:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// base</span>
<span class="hljs-keyword">const</span> g = <span class="hljs-number">5</span>;
<span class="hljs-comment">// modulus</span>
<span class="hljs-keyword">const</span> p = <span class="hljs-number">23</span>;

<span class="hljs-comment">// Alice's randomly picked number</span>
<span class="hljs-keyword">const</span> a = <span class="hljs-number">4</span>;
<span class="hljs-comment">// Alice's calculated value</span>
<span class="hljs-keyword">const</span> A = <span class="hljs-built_in">Math</span>.pow(g, a)%p;

<span class="hljs-comment">// Do the same for Bob</span>
<span class="hljs-keyword">const</span> b = <span class="hljs-number">3</span>;
<span class="hljs-keyword">const</span> B = <span class="hljs-built_in">Math</span>.pow(g, b)%p;

<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Alice's calculated value (A):"</span>, A);
<span class="hljs-comment">// Alice's calculated value (A): 4</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Bob's calculated value (B):"</span>, B);
<span class="hljs-comment">// Bob's calculated value (B): 10</span>
</code></pre>
<p>Now both Alice and Bob will send their calculated values (<strong>A</strong>, <strong>B</strong>) through the network, so all participants will know them.</p>
<p>As a last step Alice and Bob will take each other's calculated values and do the following:</p>
<ol>
<li>Alice will take Bob's calculated value (<strong>B</strong>) in the power of his secret number (<strong>a</strong>),</li>
<li>and calculate this number's modulo to <strong>p</strong> and will call the result <strong>s</strong> (secret).</li>
<li>Bob will do the same but with Alice's calculated value (<strong>A</strong>), and his secret number (<strong>b</strong>).</li>
</ol>
<p>At this point, they successfully generated a common secret (<strong>s</strong>), even if it's hard to see right now. We will explore this in more detail in a second.</p>
<p>In code:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Alice calculate the common secret</span>
<span class="hljs-keyword">const</span> secretOfAlice = <span class="hljs-built_in">Math</span>.pow(B, a)%p;
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Alice's calculated secret:"</span>, secretOfAlice);
<span class="hljs-comment">// Alice's calculated secret: 18</span>

<span class="hljs-comment">// Bob will calculate</span>
<span class="hljs-keyword">const</span> secretOfBob = <span class="hljs-built_in">Math</span>.pow(A, b)%p;
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Bob's calculated secret:"</span>, secretOfBob);
<span class="hljs-comment">// Bob's calculated secret: 18</span>
</code></pre>
<p>As you can see both Alice and Bob got the number 18, which they can use as a key to encrypt messages. It seems magic at this point, but it's just some math. </p>
<p>Let's see why they got the same number by splitting up the calculations into elementary pieces:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/Screenshot-2020-05-09-at-12.11.18.png" alt="Image" width="600" height="400" loading="lazy">
<em>The process as an equation</em></p>
<p>In the last step, we used a <a target="_blank" href="https://en.wikipedia.org/wiki/Modulo_operation#Properties_(identities)">modulo arithmetic identity</a> and its distributive properties to simplify nested modulo statements.</p>
<p>So Alice and Bob have the same key, but let's see what Charlie saw from all of this. We know that <strong>p</strong> and <strong>g</strong> are public numbers, available for everyone. </p>
<p>We also know that Alice and Bob sent their calculated values (<strong>A</strong>, <strong>B</strong>) through the network, so that can be also caught by Charlie.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/Screenshot-2020-05-09-at-20.12.35.png" alt="Image" width="600" height="400" loading="lazy">
<em>Charlie's perspective</em></p>
<p>Charlie knows almost all parameters of this equation, just <strong>a</strong> and <strong>b</strong> remain hidden. To stay with the example, if he knows that <strong>A</strong> is 4 and <strong>p</strong> is 23, <strong>g</strong> to the power of <strong>a</strong> can be 4, 27, 50, 73, ... and infinite other numbers which result in 4 in the modulo space.</p>
<p>He also knows that only the subset of these numbers are possible options because not all numbers are an exponent of 5 (<strong>g</strong>), but this is still an infinite number of options to try.</p>
<p>This doesn't seem too secure with small numbers. But at the beginning I said that <strong>p</strong> is a really large number, often 2000 or 4000 bits long. This makes it almost impossible to guess the value of <strong>a</strong> or <strong>b</strong> in the real world.</p>
<p>The common key Alice and Bob both possess only can be generated by knowing <strong>a</strong> or <strong>b</strong>, besides the information that traveled through the network.</p>
<p>If you're more visual, here is a great diagram shows this whole process by mixing buckets of paint instead of numbers.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/Diffie-Hellman_Key_Exchange.svg" alt="Image" width="600" height="400" loading="lazy">
_source: <a target="_blank" href="https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange">Wikipedia</a>_</p>
<p>Here <strong>p</strong> and <strong>g</strong> shared constants represented by the yellow "Common paint". Secret numbers of Alice and Bob (<strong>a</strong>, <strong>b</strong>) is "Secret colours", and "Common secret" is what we called <strong>s</strong>.</p>
<p>This is a great analogy because it's representing the irreversibility of the modulo operation. As mixed paints can't be unmixed to their original components, the result of a modulo operation can't be reversed.</p>
<h2 id="heading-summary">Summary</h2>
<p>Now the original problem can be solved by encrypting messages using a shared key, which was exchanged with the Diffie-Hellman algorithm. </p>
<p>With this Alice and Bob can communicate securely, and Charlie cannot read their messages even if he is part of the same network.</p>
<p>Thanks for reading this far! I hope you got some value from this post and understood some parts of this interesting communication flow.</p>
<p>If it was hard to follow the math of this explanation, <a target="_blank" href="https://www.youtube.com/watch?v=NmM9HA2MQGI">here</a> is a great video to help you understand the algorithm without math, from a higher level.</p>
<p>If you liked this post, you may want to follow me on <a target="_blank" href="https://twitter.com/karolyidav">Twitter</a> to find some more exciting resources about programming and software development.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Send Secret Messages ]]>
                </title>
                <description>
                    <![CDATA[ By Megan Kaczanowski Cryptography is the science of using codes and ciphers to protect messages, at its most basic level. Encryption is encoding messages with the intent of only allowing the intended recipient to understand the meaning of the message... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-send-secret-messages/</link>
                <guid isPermaLink="false">66d4605bd14641365a05092b</guid>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 08 Jul 2019 21:04:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9ca196740569d1a4ca4f7c.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Megan Kaczanowski</p>
<p>Cryptography is the science of using codes and ciphers to protect messages, at its most basic level. Encryption is encoding messages with the intent of only allowing the intended recipient to understand the meaning of the message. It is a two way function (you need to be able to undo whatever scrambling you’ve done to the message). This is designed to protect data in transit. </p>
<p>One of the earliest ciphers involved a simple shift. For example, if you just shift all the letters in the alphabet by a few, the alphabet might look like the following:</p>
<p>ABCDEFGHIJKLMNOPQRSTUVWXYZ</p>
<p>NOPQRSTUVWXYZABCDEFGHIJKLM</p>
<p>Then, each letter of the alphabet corresponds to a different letter, but it is difficult to figure out which one, if you don’t already know. Using this cipher, the message, ‘Hello’ translates to ‘Uryyb’.</p>
<p>Unfortunately, advances in analysis, particularly pattern analysis driven by very powerful computers, made these types of cyphers very easy to break. </p>
<p>In response to that, we’ve developed very strong, complex algorithms. These can be broken down into two basic types of encryptions — symmetric algorithms and asymmetric algorithms. </p>
<p>Symmetric algorithms are also known as ‘secret key’ algorithms, and asymmetric algorithms are known as ‘public key’ algorithms. The key difference between the two is that symmetric algorithms use the same key to encode and decode (see the first figure below), while asymmetric algorithms use different keys for encryption and decryption (see the second figure below).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/Screen-Shot-2019-06-13-at-4.56.58-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>As you can see in the above figure, with symmetric encryption, if Bob and Midge want to communicate, Bob first encrypts his message with the secret key (the encrypted message is called ciphertext). Then he sends it to Midge. Midge then decrypts the message with the same secret key and is able to read the message. To send a message back, the process is reversed. </p>
<p>This process is fast, scalable, and very secure. The problem with it is that it requires both parties to already have the same secret key. If they don’t, they need to pass it along insecure channels, which essentially removes the security of the encryption.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/Screen-Shot-2019-06-13-at-4.57.02-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>With Asymmetric encryption, as in the above figure, if Bob and Midge want to communicate, Bob encrypts his message with Midge’s public key and sends it to her. She then decrypts the message with her private key to read it. To send a message back, the process is reversed. </p>
<p>In this way, anyone can send Midge a message, as she can make her public key available to anyone, but only she can decrypt a message (as she keeps her private key secret). It also solves the need to pass a secret key along insecure channels, because there is no need to pass a secret at all. The disadvantage is that it requires everyone who wants to communicate to have two different keys (not scalable), and it is relatively slow.</p>
<p>In general, when talking about encryption, the most important considerations are:</p>
<ul>
<li>Authentication/Nonrepudiation — Whether or not you can prove where messages originated (Am I sure who sent this message?).</li>
<li>Reuse — Can I continue to use this key or will it need to be regenerated for each new communication?</li>
<li>Effectiveness — How fast can I transfer large amounts of data?</li>
<li>Scalability — Is this feasible for large groups?</li>
<li>Distribution — how do you distribute keys to the people who you’re communicating with, without divulging the secret to anyone else?</li>
</ul>
<p>That’s where significant differences start to come up between symmetric and asymmetric encryption, summarized below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/Screen-Shot-2019-06-13-at-4.57.55-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>In order to use the best of both worlds, many modern encryption protocols will use asymmetric encryption to establish a connection and create a shared secret. Then, they will switch to symmetric encryption to benefit from the speed difference. </p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/preinheimer/status/841273046317060105"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ An Introduction to Cryptography and Linear Feedback Shift Registers ]]>
                </title>
                <description>
                    <![CDATA[ By Magdalena Stenius All around us data is transferred faster than ever. Sensitive data is also part of our everyday life. To protect that data, we use encryption. When we encrypt data, it changes in some way that renders it useless to the possible v... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/cryptography-and-lfsr/</link>
                <guid isPermaLink="false">66d4601251f567b42d9f848d</guid>
                
                    <category>
                        <![CDATA[ ciphers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ encryption ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Mathematics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 22 Jun 2019 12:02:44 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/06/tommy-lee-walker-409690-unsplash-1.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Magdalena Stenius</p>
<p>All around us data is transferred faster than ever. Sensitive data is also part of our everyday life. To protect that data, we use encryption. When we encrypt data, it changes in some way that renders it useless to the possible viewer, but that can be changed back to its original state when it arrives safely to the meant receiver. These transformations rely heavily on math, and particularly on a field of math called number theory. This text takes us through the basics of cryptography both from a mathematical perspective and as a programming matter.</p>
<h4 id="heading-ciphers-yesterday-and-today">Ciphers Yesterday and Today</h4>
<p>For as long as writing has existed, the concept of encryption has lived and developed alongside the plain text writing. The idea of rendering text seemingly incomprehensible for purposes of guarding a secret has been central especially in military use and politics. The word cipher originates from the medieval times, from words such as the latin <em>cifra</em> and Arabic <em>صفر</em> (sifr), which means “zero”. There are numerous theories on why zero would have been used to describe encryption, including that the concept of zero was not part of the roman number system and seen as a mystery among numbers. One of the oldest and most widely known ciphers used in military context is Caesars cipher, also known as Caesars shift.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*IehC7dyPV4f4mFcAUwQtfA.png" alt="Image" width="800" height="263" loading="lazy">
<em>Caesars Shift in Python3.</em></p>
<p>Caesars shift takes one key, which is used to shift each character in the plaintext. This single key is the weakness of the cipher: once the correct shift is figured out, the whole message is revealed. Mathematically, this type of cipher can be written as a problem in modular arithmetic, which works with values wrapped up in a specific range. We’ll discuss this in more depth later.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/1_Mt2X5MKczLf0WpslKCUvkA.png" alt="Image" width="600" height="400" loading="lazy">
<em>Shift encryption and decryption as modular arithmetic using a 26-letter alphabet.</em></p>
<p>The way we can solve the plaintext from the encrypted text is by finding the key. In the case of a Caesars cipher of value 3, finding out the key (3) lets us decrypt the whole text in one chunk. The key specifies the output of the encryption algorithm.</p>
<h4 id="heading-factors-and-primes">Factors and Primes</h4>
<p>Perhaps surprisingly, one of the foundational concepts that lays the ground for encryption is that of divisibility. To define what it means, let’s lay down some rules. Firstly, if we have <em>a</em> and <em>b</em> that are integers and <em>a</em> is not 0, a divides <em>b</em> if there is such an integer <em>k</em> that satisfies the following statement.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*bBWKJzCZ7cSSXjV3Mdk6Og.png" alt="Image" width="155" height="79" loading="lazy">
<em>A is a factor of b.</em></p>
<p>In case we find an integer which is larger than 1 and that does not have other positive factors than 1 and itself, we call it a <em>prime</em>. Integers larger than one which are not primes are known as <em>composite numbers</em>, due to their composed nature. For example, 4 is larger than 1 and it has a factor 2. Hence, it is a composite. On the other hand, 3 is an integer larger than one, but it does not have any other positive factors than 1 and itself. It is a prime. Other small primes are 2, 5, 7, 11 and 13.</p>
<p>According to the fundamental theorem of arithmetic, every integer larger than 1 can be written as an unique product of primes. This is good news for cryptographers, since they love working with primes. Why would that be? Well, one of the most straightforward reasons is that prime factorisation of large numbers takes up a lot of time. Many well known encryption systems such as RSA is fully based on this fact. The principal it works on is that there exists a public key (a product of two large primes) which is used to encrypt the message, and a secret key (containing those primes) which is used to decrypt the message. These primes are usually around 300 digits long.</p>
<h4 id="heading-a-matter-of-congruence">A Matter of Congruence</h4>
<p>Modularity is one of the foundational pillars of cryptography. Let’s approach this concept first from a perspective of division. What happens if we have 5 small candies and three students? Each student gets a candy, and 2 remain. This can be described as the following.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/rremainder.png" alt="Image" width="600" height="400" loading="lazy">
<em>R is the remainder of a when divided by n.</em></p>
<p>Can you find the other amounts of candies which leave 2 as a remainder when divided to the 3 students? The next amount would be 8, since each student would get two candies and again 2 would be left over. This can be described using congruence. 8 and 5 are congruent is modulo 3, meaning that they leave the same remainder when divided by 3.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*F0-jvG8EMA5hPMNJAgchxA.png" alt="Image" width="249" height="91" loading="lazy">
<em>5 is congruent to 8 in modulo 3.</em></p>
<p>In the example of Caesars shift, we use an alphabet that consists of 26 letters. We only work with those 26 values. After ‘Z’, we go back to ‘A’. This is modularity in practice. ‘A’ will always be at position 1 in our 26-letter list, so any count of position we get, if we divide it by 26 and the remainder is 1, we know to use ‘A’. This wraps up our numbers into a finite field, in which the largest value is 26. In practice, if my secret message would be ‘ABC’, I would first convert this to the numbers 123. After that, I would apply the shift. In case the key would be 3, the shift would produce 456. After this, I would point the numbers back to their letter representations, which are in the class of modulo 26. The encrypted message becomes ‘DEF’.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/again.png" alt="Image" width="600" height="400" loading="lazy">
<em>Again, encryption and decryption as modular arithmetic using a 26-letter alphabet.</em></p>
<p>You can think of this like a clock. When the arrow has gone around the clock, it ends up where it started. In modular arithmetics, the last integer is followed by the first. Another way to understand this is that the world of a specific modulo, only that amount of values exist. For example in modulo 2, only 2 values exist. In our alphabet, 26 values exist, and so on.</p>
<h4 id="heading-types-of-ciphers">Types of Ciphers</h4>
<p>What kind of keys a cipher uses can be used to categorise the cipher into asymmetric and symmetric keys. They differ in the question of which key is used for encryption and decryption. Symmetric ciphers are encrypted and decrypted using the same key (such as Caesars Cipher). Asymmetric key ciphers are decrypted with a different key than they are created with, such as the RSA encryption system which we briefly discussed earlier. This results in a longer time for creating the encryption, but the result is also much more secure.</p>
<p>Another way to categorise ciphers is by their way of operating in streams or blocks. Stream ciphers are symmetric key ciphers that operate on continuous streams of symbols. For example the encryptions used in Bluetooth is a stream cipher. Needless to say, in the age of wireless communication with a need for encryption, stream ciphers have become a vital part of mobile technology.</p>
<h4 id="heading-a-look-at-stream-ciphers">A Look at Stream Ciphers</h4>
<p>Remember that we discussed the concept of modular arithmetic earlier? In short, modular arithmetics are arithmetics in a finite field. Now, let’s take a look at another cipher that works with a finite field of values (also known as a Galois field). This cipher, however, does not always produce the same values given the same input, like shifting does. Its purpose is to produce a stream of keys used to encrypt another stream. Like a snake eating its own tail (a symbol often used for eternity), linear feedback shift registers work by feeding on their own output. They are constructed in a way that makes them endlessly cycle through a pattern of values while outputting that seemingly random pattern. The seed and all the outputted values are binary, meaning they get values 0 or 1. The way new values are created is by using a logical operator, usually exclusive or (XOR).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/logical.png" alt="Image" width="600" height="400" loading="lazy">
<em>Logical Gate XOR.</em></p>
<p>To describe this in a practical way, lets start looking at what we need to create a LFSR. We need a seed, which is a list of ones and zeros. The seed will be what we start shifting. In addition to our seed (or shift register) we have a collection of taps. The taps tell us which parts of the register we use when feeding back into it. Say that we have a seed 001 and two taps, 1 and 3. This means that when we start shifting, the new value will be a combination of the first and third numbers of the seed, 0 and 1. We use an operation called exclusive or to combine the two. 0 xor 1 gives 1. Since we are working with binary values, the feedback from our taps can be expressed as a polynomial in modulo 2.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*o9K4JH2YxEzjieQco9pTxA.png" alt="Image" width="165" height="83" loading="lazy">
<em>The feedback polynomial from taps 3 and 1.</em></p>
<p>So, if our shift register is 001 and we get a new value, 1, we insert it in the beginning and drop the last number out. Our new shift register state is now 100. We continue this shifting until we notice that our shift register has returned to it’s initial state, 001. Depending on the seed and taps we select, we can get loops of different lengths. A loop is called <em>maximal length</em> if it passes through all possible different combinations before reaching its original state. Since we’re using the binary system, the maximal length of a loop will be 2^n-1. The loop can also end up leaving its original state and getting stuck in a shorter loop within, never returning to its original state. Finding the seeds and taps that lead to a maximal-length cycle is essential. Some of the criterions for finding these taps is that the number of taps must be even and that the taps are setwise co-primes, meaning that they have no common divisor except 1.</p>
<p>Wait, that doesn’t seem so random! Wouldn’t a cycle like that be pretty easy to crack? The thing about shift registers is that they get pretty long, pretty quickly. Say we choose a seed of 20 bits and a tap of two values, 2 and 19. The length of the loop produced is 1 048 575, meaning we would get quite a large amount of seemingly random binary values.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/lfsrpy.png" alt="Image" width="600" height="400" loading="lazy">
<em>Linear Feedback Shift Register in Python3.</em></p>
<p>The flavour of LFSR we have briefly gone through is called Fibonacci LFSR. There are also other variations, in which the way the register is shifted differs. They all work to produce a pseudorandom stream of bits used to encrypt streams. The range of applications for this type of encryption ranges from bluetooth to GSM (cellphone communication) standards.</p>
<h4 id="heading-in-conclusion">In Conclusion</h4>
<p>As a programmer, learning about the concept of modular arithmetics and division opens new ways in thinking about everyday coding problems. However, in security-critical projects using ready-made systems and standards for encryption is always recommended, since specialists in the field of cryptography probably find a safer and more effective solution than an enthusiastic hobbyist.</p>
<p>Sources:</p>
<p><a target="_blank" href="http://delta.utu.fi/about/monistemyynti/">Algebraic Structures in Cryptography by V. Niemi</a></p>
<p><a target="_blank" href="https://www.eetimes.com/document.asp?doc_id=1274550">Tutorial on Linear Feedback Shift Registers by EETimes</a></p>
<p><a target="_blank" href="https://www.rocq.inria.fr/secret/Anne.Canteaut/MPRI/chapter3.pdf">Encyclopedia of Cryptography and Security by Anne Canteout</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How Devise keeps your Rails app passwords safe ]]>
                </title>
                <description>
                    <![CDATA[ By Tiago Alves Devise is an incredible authentication solution for Rails with more than 40 million downloads. However, since it abstracts most of the cryptographic operations, it’s not always easy to understand what’s happening behind the scenes. One... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-does-devise-keep-your-passwords-safe-d367f6e816eb/</link>
                <guid isPermaLink="false">66c34d0c5ced6d98e4bd331a</guid>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ruby on Rails ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 15 Oct 2018 10:45:18 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*iOXaisZyDdgXEPpwHaFrRQ.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Tiago Alves</p>
<p><a target="_blank" href="https://github.com/plataformatec/devise">Devise</a> is an incredible authentication solution for Rails with <a target="_blank" href="https://rubygems.org/gems/devise">more than 40 million downloads</a>. However, since it abstracts most of the cryptographic operations, it’s not always easy to understand what’s happening behind the scenes.</p>
<p>One of those abstractions culminates in the persistence of an <code>encrypted_password</code> directly on the database. So I’ve always been curious about what it actually represents. Here’s an example:</p>
<p><code>$2a$11$yMMbLgN9uY6J3LhorfU9iuLAUwKxyy8w42ubeL4MWy7Fh8B.CH/yO</code></p>
<p>But what does that gibberish mean?</p>
<p>Devise uses <a target="_blank" href="https://github.com/codahale/bcrypt-ruby">Bcrypt</a> to securely store information. On its website it mentions that it uses “<em>OpenBSD bcrypt() password hashing algorithm, allowing you to easily store a secure hash of your users’ passwords</em>”. But what exactly is this hash? How does it work and how does it keep stored passwords safe?</p>
<p>That’s what I want to show you today.</p>
<p>Let’s work backwards — from the stored hash on your database to the encryption and decryption process.</p>
<p>That hash <code>$2a$11$yMMbLgN9uY6J3LhorfU9iuLAUwKxyy8w42ubeL4MWy7Fh8B.CH/yO</code> is actually comprised of several components:</p>
<ul>
<li><strong>Bcrypt version</strong> (<code>2a</code>) - the version of the bcrypt() algorithm used to produce this hash (stored after the first <code>$</code> sign)</li>
<li><strong>Cost</strong> (<code>11</code>) - the cost factor used to create the hash (stored after the second <code>$</code> sign)</li>
<li><strong>Salt</strong> (<code>$2a$11$yMMbLgN9uY6J3LhorfU9iu</code>) - a random string that when combined with your password makes it unique (first 29 characters)</li>
<li><strong>Checksum</strong> (<code>LAUwKxyy8w42ubeL4MWy7Fh8B.CH/yO</code>) - the actual hash portion of the stored <code>encrypted_password</code> (remaining string after the 29 chars)</li>
</ul>
<p><img src="https://cdn-media-1.freecodecamp.org/images/C1o8LTw8UCfepc7Tq3m5Yd1VGcMcT4XpRkBD" alt="Image" width="800" height="219" loading="lazy"></p>
<p>Let’s explore the last 3 parameters:</p>
<ul>
<li>When using Devise, the <code>**Cost**</code> value is set by a class variable called <a target="_blank" href="https://github.com/plataformatec/devise/blob/715192a7709a4c02127afb067e66230061b82cf2/lib/devise.rb#L74">stretches</a> and the default value is <code>11</code>. It specifies the number of times the password is hashed. (_On your <a target="_blank" href="https://github.com/plataformatec/devise/blob/715192a7709a4c02127afb067e66230061b82cf2/test/rails_app/config/initializers/devise.rb#L70">devise.rb initializer</a>, you can configure this to a lower value for the test environment to make your test suite run faster._) *</li>
<li>The <strong>salt</strong> is the random string used to combine with the original password. This is what makes the same password have different values when stored encrypted. (_See more below about why that matters and what are Rainbow Table Attack_s.) **</li>
<li>The <strong>checksum</strong> is the actual generated hash of the password after being combined with the random salt.</li>
</ul>
<p>When a user registers on your app, they must set a password. Before this password is stored in the database, a random salt is generated via <a target="_blank" href="https://www.rubydoc.info/github/codahale/bcrypt-ruby/BCrypt%2FEngine.generate_salt">BCrypt::Engine.generate_salt(cost)</a> by taking into account the cost factor previously mentioned. <em>(Note: if the <code>[pepper](https://github.com/plataformatec/devise/blob/715192a7709a4c02127afb067e66230061b82cf2/lib/devise.rb#L155)</code> <a target="_blank" href="https://github.com/plataformatec/devise/blob/715192a7709a4c02127afb067e66230061b82cf2/lib/devise.rb#L155">class variable value</a> is set it will <a target="_blank" href="https://github.com/plataformatec/devise/blob/715192a7709a4c02127afb067e66230061b82cf2/lib/devise/encryptor.rb#L9">append its value to the password</a> before salting it.)</em></p>
<p>With that salt (ex. <code>$2a$11$yMMbLgN9uY6J3LhorfU9iu</code>, which includes the cost factor) it will call <a target="_blank" href="https://www.rubydoc.info/github/codahale/bcrypt-ruby/BCrypt%2FEngine.hash_secret">BCrypt::Engine.hash_secret(password, salt)</a> that computes the final hash to be stored using the generated salt and the password selected by the user. This final hash (for example, <code>$2a$11$yMMbLgN9uY6J3LhorfU9iuLAUwKxyy8w42ubeL4MWy7Fh8B.CH/yO</code>) will in turn be stored in the <code>encrypted_password</code> column of the database.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/mKgk9fAildsnwkuXhmOU0SDIiflG-nI8FPUa" alt="Image" width="800" height="509" loading="lazy"></p>
<p>But if this hash is nonreversible and the salt is randomly generated on the <code>BCrypt::Password.create</code> call by <code>BCrypt::Engine.generate_salt(cost)</code>, <strong>how can it be used to sign in the user?</strong></p>
<p>That’s where those different hash components are useful. After finding the record that matches the email supplied by the user to sign in, the encrypted password is retrieved and broken down into the different components mentioned above (<strong>Bcrypt version</strong>, <strong>Cost</strong>, <strong>Salt</strong> and <strong>Checksum</strong>).</p>
<p>After this initial preparation, here’s what happens next:</p>
<ol>
<li>Fetch the <strong>input password</strong> (<code>1234</code>)</li>
<li>Fetch the <strong>salt</strong> of the stored password (<code>$2a$11$yMMbLgN9uY6J3LhorfU9iu</code>)</li>
<li>Generate the <strong>hash</strong> from the password and salt using the same bcrypt version and cost factor (<code>BCrypt::Engine.hash_secret(“1234”, “$2a$11$yMMbLgN9uY6J3LhorfU9iu”)</code>)</li>
<li>Check if the <strong>stored hash</strong> is the same one as the computed on step 3 (<code>$2a$11$yMMbLgN9uY6J3LhorfU9iuLAUwKxyy8w42ubeL4MWy7Fh8B.CH/yO</code>)</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/kJxy3TSK0VJ3fVqfFcVjmCCPCdgm1HyBb9C8" alt="Image" width="800" height="481" loading="lazy"></p>
<p>And that’s how Devise stores passwords securely and protects you from a range of attacks even if your database is compromised.</p>
<p>Get in touch on Twitter <a target="_blank" href="https://twitter.com/alvesjtiago">@alvesjtiago</a> and let me know if you found this article interesting! Thank you for reading.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Lo-yU9BkzXFiqwgk5JS4RAKntUaE4KffvT5-" alt="Image" width="800" height="533" loading="lazy"></p>
<blockquote>
<p>PS: I’m by no means a security or cryptography expert so please do reach out if you find something wrong. I’m hoping that by simplifying some of the concepts it will be easier to understand what’s happening.</p>
</blockquote>
<p>_Thank you <a target="_blank" href="https://twitter.com/filipepina">@filipepina</a>, <a target="_blank" href="https://twitter.com/ivobenedito">@ivobenedito</a>, <a target="_blank" href="https://twitter.com/jackveiga">@jackveiga</a>, <a target="_blank" href="https://twitter.com/joao_mags">@joao_mags</a> and <a target="_blank" href="https://twitter.com/pedrosmmoreira">@pedrosmmoreira</a> for the reviews and suggestions. This article is also available at <a target="_blank" href="http://blog.tiagoalves.me/how-does-devise-keep-your-passwords-safe/">http://blog.tiagoalves.me/how-does-devise-keep-your-passwords-safe</a>._</p>
<p>More information about some of the topics.</p>
<p><strong>Cost factor *</strong></p>
<ul>
<li><a target="_blank" href="https://labs.clio.com/bcrypt-cost-factor-4ca0a9b03966">Perils of the default bcrypt cost factor</a></li>
<li><a target="_blank" href="https://security.stackexchange.com/questions/17207/recommended-of-rounds-for-bcrypt">Recommended number of rounds for bcrypt</a></li>
</ul>
<p><strong>Rainbow Table Attacks **</strong></p>
<ul>
<li><a target="_blank" href="https://en.wikipedia.org/wiki/Rainbow_table">Rainbow table — Wikipedia</a></li>
<li><a target="_blank" href="https://security.stackexchange.com/a/440">What are rainbow tables and how are they used?</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ HTTPS explained with carrier pigeons ]]>
                </title>
                <description>
                    <![CDATA[ By Andrea Zanin Korean translationPortuguese translationSpanish translationMongolian translationPersian translationVietnamese translation Cryptography can be a hard subject to understand. It’s full of mathematical proofs. But unless you are actually ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/https-explained-with-carrier-pigeons-7029d2193351/</link>
                <guid isPermaLink="false">66c356fd0cede4e9b1329c7c</guid>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ humor ]]>
                    </category>
                
                    <category>
                        <![CDATA[ messaging ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 10 Jan 2018 22:07:10 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*vHF6NNdZX9ziiW_uRYzvAA.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Andrea Zanin</p>
<p><a target="_blank" href="https://www.vobour.com/%EB%B9%84%EB%91%98%EA%B8%B0%EB%A1%9C-%EC%84%A4%EB%AA%85%ED%95%98%EB%8A%94-https-https-explained-with-car">Korean translation</a><br><a target="_blank" href="https://medium.com/inpaas/explicando-https-com-pombos-correio-68270a5b0c28">Portuguese translation</a><br><a target="_blank" href="https://www.transparentcdn.com/https-explicado-palomas-mensajeras/">Spanish translation</a><br><a target="_blank" href="https://medium.com/unimediasolutions/https-ыг-шууданч-тагтаагаар-адилтган-тайлбарлах-нь-f094d38a7dc5">Mongolian translation</a><br><a target="_blank" href="https://virgool.io/@raminpay/https-explained-hkxu4qmijmfc">Persian translation</a><br><a target="_blank" href="https://blogchanhday.com/p/nhat-ky-anh-bo-cau-dua-thu-va-https/">Vietnamese translation</a></p>
<p>Cryptography can be a hard subject to understand. It’s full of mathematical proofs. But unless you are actually developing cryptographic systems, much of that complexity is not necessary to understand what is going on at a high level.</p>
<p>If you opened this article hoping to create the next HTTPS protocol, I’m sorry to say that pigeons won’t be enough. Otherwise, brew some coffee and enjoy the article.</p>
<h3 id="heading-alice-bob-and-pigeons">Alice, Bob and … pigeons?</h3>
<p>Any activity you do on the Internet (reading this article, buying stuff on Amazon, uploading cat pictures) comes down to sending and receiving messages to and from a server.</p>
<p>This can be a bit abstract so let’s imagine that those messages were delivered by <strong>carrier pigeons</strong>. I know that this may seem very arbitrary, but trust me HTTPS works the same way, albeit a lot faster.</p>
<p>Also instead of talking about servers, clients and hackers, we will talk about Alice, Bob and Mallory. If this isn’t your first time trying to understand cryptographic concepts you will recognize those names, because they are widely used in technical literature.</p>
<h3 id="heading-a-first-naive-communication">A first naive communication</h3>
<p>If Alice wants to send a message to Bob, she attaches the message on the carrier pigeon’s leg and sends it to Bob. Bob receives the message, reads it and it’s all is good.</p>
<p>But what if Mallory intercepted Alice’s pigeon in flight and changed the message? Bob would have no way of knowing that the message that was sent by Alice was modified in transit.</p>
<p>This is how <strong>HTTP</strong> works. Pretty scary right? I wouldn’t send my bank credentials over HTTP and neither should you.</p>
<h3 id="heading-a-secret-code">A secret code</h3>
<p>Now what if Alice and Bob are very crafty. They agree that they will write their messages using a secret code. They will shift each letter by 3 positions in the alphabet. For example D → A, E → B, F → C. The plain text message “secret message” would be “pbzobq jbppxdb”.</p>
<p>Now if Mallory intercepts the pigeon she won’t be able to change the message into something meaningful nor understand what it says, because she doesn’t know the code. But Bob can simply apply the code in reverse and decrypt the message where A → D, B → E, C → F. The cipher text “pbzobq jbppxdb” would be decrypted back to “secret message”.</p>
<p>Success!</p>
<p>This is called <strong>symmetric key cryptography</strong>, because if you know how to encrypt a message you also know how to decrypt it.</p>
<p>The code I described above is commonly known as the <strong>Caesar cipher</strong>. In real life, we use fancier and more complex codes, but the main idea is the same.</p>
<h3 id="heading-how-do-we-decide-the-key">How do we decide the key?</h3>
<p>Symmetric key cryptography is very secure if no one apart from the sender and receiver know what key was used. In the Caesar cipher, the <strong>key is an offset</strong> of how many letters we shift each letter by. In our example we used an offset of 3, but could have also used 4 or 12.</p>
<p>The issue is that if Alice and Bob don’t meet before starting to send messages with the pigeon, they would have no way to establish a key securely. If they send the key in the message itself, Mallory would intercept the message and discover the key. This would allow Mallory to then read or change the message as she wishes before and after Alice and Bob start to encrypt their messages.</p>
<p>This is the typical example of a <strong>Man in the Middle Attack</strong> and the only way to avoid it is to change the encryption system all together.</p>
<h3 id="heading-pigeons-carrying-boxes">Pigeons carrying boxes</h3>
<p>So Alice and Bob come up with an even better system. When Bob wants to send Alice a message she will follow the procedure below:</p>
<ul>
<li>Bob sends a pigeon to Alice without any message.</li>
<li>Alice sends the pigeon back carrying a box with an open lock, but keeping the key.</li>
<li>Bob puts the message in the box, closes the locks and sends the box to Alice.</li>
<li>Alice receives the box, opens it with the key and reads the message.</li>
</ul>
<p>This way Mallory can’t change the message by intercepting the pigeon, because she doesn’t have the key. The same process is followed when Alice wants to send Bob a message.</p>
<p>Alice and Bob just used what is commonly known as <strong>asymmetric key cryptography</strong>. It’s called asymmetric, because even if you can encrypt a message (lock the box) you can’t decrypt it (open a closed box).<br>In technical speech the box is known as the <strong>public key</strong> and the key to open it is known as the <strong>private key</strong>.</p>
<h3 id="heading-how-do-i-trust-the-box">How do I trust the box?</h3>
<p>If you paid attention you may have noticed that we still have a problem. When Bob receives that open box how can he be sure that it came from Alice and that Mallory didn’t intercept the pigeon and changed the box with one she has the key to?</p>
<p>Alice decides that she will sign the box, this way when Bob receives the box he checks the signature and knows that it was Alice who sent the box.</p>
<p>Some of you may be thinking, how would Bob identify Alice’s signature in the first place? Good question. Alice and Bob had this problem too, so they decided that, instead of Alice signing the box, Ted will sign the box.</p>
<p>Who is Ted? Ted is a very famous, well known and trustworthy guy. Ted gave his signature to everyone and everybody trusts that he will only sign boxes for legitimate people.</p>
<p>Ted will only sign an Alice box if he’s sure that the one asking for the signature is Alice. So Mallory cannot get an Alice box signed by Ted on behalf of her as Bob will know that the box is a fraud because Ted only signs boxes for people after verifying their identity.</p>
<p>Ted in technical terms is commonly referred to as a <strong>Certification Authority</strong> and the browser you are reading this article with comes packaged with the signatures of various Certification Authorities.</p>
<p>So when you connect to a website for the first time you trust its box because you trust Ted and Ted tells you that the box is legitimate.</p>
<h3 id="heading-boxes-are-heavy">Boxes are heavy</h3>
<p>Alice and Bob now have a reliable system to communicate, but they realize that pigeons carrying boxes are slower than the ones carrying only the message.</p>
<p>They decide that they will use the box method (asymmetric cryptography) only to choose a key to encrypt the message using symmetric cryptography with (remember the Caesar cipher?).</p>
<p>This way they get the best of both worlds. The reliability of asymmetric cryptography and the efficiency of symmetric cryptography.</p>
<p>In the real world there aren’t slow pigeons, but nonetheless encrypting messages using asymmetric cryptography is slower than using symmetric cryptography, so we only use it to exchange the encryption keys.</p>
<p>Now you know how <strong>HTTPS</strong> works and your coffee should also be ready. Go drink it you deserved it ?</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How “Gravity Falls” can help you teach your kids basics of cryptography ]]>
                </title>
                <description>
                    <![CDATA[ By Kamil Tustanowski It’s Wednesday evening. My two sons and daughter are ready. I press play and we start a journey that takes us all farther than we ever anticipated. We watched the first episode of Gravity Falls. The visuals, characters, plot and ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-gravity-falls-can-help-you-teach-your-kids-basics-of-cryptography-18e1c6f9ac39/</link>
                <guid isPermaLink="false">66c34d2b5ced6d98e4bd331e</guid>
                
                    <category>
                        <![CDATA[ children ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ life ]]>
                    </category>
                
                    <category>
                        <![CDATA[ self-improvement  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sun, 06 Aug 2017 12:37:42 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*i1wUMam8Rgkq-XMwmu7YlA.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Kamil Tustanowski</p>
<p>It’s Wednesday evening. My two sons and daughter are ready. I press play and we start a journey that takes us all farther than we ever anticipated.</p>
<p>We watched the first episode of <a target="_blank" href="http://www.imdb.com/title/tt1865718/">Gravity Falls</a>. The visuals, characters, plot and humor are top notch and we definitely wanted more but… we spotted something at the end of credits. Something we didn’t expect. Something that made watching this series far more interesting and engaging.</p>
<p>An <code>encrypted message</code>.</p>
<p>Here’s how we deciphered the codes. And we had a great fun doing this on our own. Without checking any of this in the internet. If I’ve caught your interest, I recommend you to stop reading and try doing this yourself. Then you can come back and read my solutions and explanations below later.</p>
<h4 id="heading-zhofrph-wr-judylwb-idoov"><strong>ZHOFRPH WR JUDYLWB IDOOV</strong></h4>
<p>We were certain this was a message. By the looks of it I was guessing that it’s encrypted with some kind of substitution cipher.</p>
<blockquote>
<p>Encrypting using substitution cipher basically substitutes letters with other letters based on some general rule. Decrypting is done by applying this rule in reverse to encrypted text. This kinds of ciphers are not used anymore because they are easy to break i.e. with <a target="_blank" href="http://practicalcryptography.com/ciphers/simple-substitution-cipher/#cryptanalysis">cryptoanalysis</a>. You can find more details on this <a target="_blank" href="https://en.wikipedia.org/wiki/Substitution_cipher">wiki page</a>.</p>
</blockquote>
<p>At first we were too excited about the story to focus on the ciphers just yet. We just acknowledged that the ciphers exist and we didn’t know how to decrypt them. I thought we would just break them later but…</p>
<p>After one episode my son had an idea. He wanted to watch show intro. Backwards. I thought <code>why not</code> ? Guess what! When you watch it backwards at some point you can hear hidden message:</p>
<p><strong>Three letters back</strong></p>
<p>Hmm… <code>three letters back</code>. Normally this would’t make any sense. But we had ciphers which we didn’t know how to decode. For us this made perfect sense.</p>
<h4 id="heading-hello-mr-caesar">Hello Mr. Caesar</h4>
<blockquote>
<p>The Caesar cipher is one of the earliest known and simplest ciphers. It is a type of substitution cipher in which each letter in the plaintext is ‘shifted’ a certain number of places down the alphabet. For example, with a shift of 1, A would be replaced by B, B would become C, and so on. The method is named after Julius Caesar, who apparently used it to communicate with his generals. Read more <a target="_blank" href="http://practicalcryptography.com/ciphers/classical-era/caesar/">here</a>.</p>
</blockquote>
<p>I printed english alphabet for everyone from <a target="_blank" href="https://en.wikipedia.org/wiki/English_alphabet">here</a> and decrypting started:</p>
<p><code>Z</code> → <code>W</code> because if we move <code>3</code> letters back from <code>Z</code> we end up with <code>W</code><br><code>H</code> → <code>E</code><br>…<br><code>B</code>→ <code>Y</code> because if we move <code>1</code> letter back we end up on <code>A</code> and the next <code>2</code> we have to <code>count</code> from the end of alphabet so in the end it’s <code>Y</code></p>
<p>After a while we knew that <strong>ZHOFRPH WR JUDYLWB IDOOV</strong> is actually <strong>WELCOME TO GRAVITY FALLS.</strong></p>
<p>My kids loved it.</p>
<p>When they were <code>manually</code> decrypting next messages I thought that this is great opportunity to actually show them what I’m doing at work. In the way it’s easier for them to understand.</p>
<p>I started new <code>Swift Playground</code> because it’s offering awesome way for working with code. And started coding. I wrote this just for fun so please don’t judge ?:</p>
<p>When manual decoding was done I sit down with my children in front of a computer. I explained that my code is doing the same things they were doing when decrypting messages. But instead of doing this manually it’s automatic and can used many times. They didn’t understood the code, I would be surprised if they did, but I’m pretty sure they got <code>the idea</code>.</p>
<h4 id="heading-kzkvi-qzn-wrkkvi-hzbh-zfftsdcjtstzwhzwfs">KZKVI QZN WRKKVI HZBH: “ZFFTSDCJTSTZWHZWFS!”</h4>
<p>Everything was great until episode <code>7</code>. We started decoding first word and:<br><code>KZKVI</code> → <code>HWHSF</code><br>Oh-oh, our luck just run out. It was clear that cipher has changed. Luckily there was a <code>clue</code> in message we did decrypt for episode <code>6</code> :</p>
<p>MR. <strong>CEASAR</strong>IAN WILL BE OUT NEXT WEEK MR. <strong>ATBASH</strong> WILL SUBSTITUTE</p>
<p><code>Ceasar cipher</code> → <code>Atbash cipher</code></p>
<h4 id="heading-hello-mr-atbash">Hello Mr. Atbash</h4>
<blockquote>
<p>The Atbash cipher is a substitution cipher with a specific key where the letters of the alphabet are reversed. I.e. all ‘A’s are replaced with ‘Z’s, all ‘B’s are replaced with ‘Y’s, and so on. It was originally used for the Hebrew alphabet, but can be used for any alphabet. Read more <a target="_blank" href="http://practicalcryptography.com/ciphers/classical-era/atbash-cipher/">here</a>. Atbash encrypted strings can be found even in a Bible. You can read a bit more about this in <a target="_blank" href="https://www.gotquestions.org/Atbash-code.html">here</a>.</p>
</blockquote>
<p>This time it was a bit more time consuming because we had to check character index from beginning and then find letter with this index counted from the end of alphabet. Again my kids were decrypting this manually:<br><code>K</code> → <code>P</code> because index of <code>K</code> is <code>11</code> and when we count <code>11</code> from the end of alphabet we get <code>P</code><br><code>Z</code> → <code>A</code><br><code>K</code> → <code>P</code><br><code>V</code> → <code>E</code><br><code>I</code> → <code>R</code><br><code>KZKVI</code> → <code>PAPER</code> This made sense again.</p>
<p>After a few minutes my daughter approached me and asked whether she decrypted the message properly. She did. But this wasn’t most interesting. I noticed that she wrote something on the printed alphabet page. Above the alphabet indexes <code>1, 2, 3, …, 26</code> she added reversed index numbers <code>26, 25, 24, …, 1</code>.</p>
<p>Thanks to this she didn’t have to count from the end of alphabet anymore. We, programmers, call this <code>optimization</code>. I was amazed that she already started to improve her toolset to make job easier.<br>Again I prepared small piece of code that was able to decode the messages:</p>
<h4 id="heading-1452420-2116-615152021520-202315-71821141112519-71852251475">14–5–24–20 21–16: “6–15–15–20–2–15–20 20–23–15: 7–18–21–14–11–12–5'19 7–18–5–22–5–14–7–5”</h4>
<p>All was good until episode <code>14.</code> Then out of the blue cipher changed again. We didn’t get any clue this time. Or maybe just missed it?</p>
<p>Well… maybe not exactly without any <code>clue</code>. The greatest number in ciphered text was <code>24</code> smallest was <code>2</code>. Alphabet letters has indexes from <code>1</code> to <code>26</code>. Based on this we made educated guess that:<br><code>1</code> → <code>A</code><br><code>2</code> → <code>B</code><br>…<br><code>26</code> → <code>Z</code></p>
<p>When <code>14–5–24–20</code> decoded to <code>NEXT</code> we knew that our assumption was correct.</p>
<p>It was a bit more annoying because I didn’t want to strip the message from any characters when decoded. If it doesn’t work for you — please remove unsupported <code>non-aplhanumeric-characters</code> or add currently unsupported characters to <code>.replacingOccurrences</code>. Like I said. Don’t judge ?</p>
<h4 id="heading-5192362116-1896-41619-2212151020192519">5–19–23–6–21–16 18–9–6 4–16–19 22–12–15–10–20–19–25–19</h4>
<p>We failed again when we tried to decrypt first word from message from episode <code>20</code>.<br><code>5–19–23–6–21–16</code> → <code>ESWFUP</code></p>
<p>Cipher changed. But we didn’t give up easily. <code>Hint</code> there is an , encrypted<code>clue</code>, that says how to decode this message. But I’m leaving this to you. It’s just too much fun to work on this stuff.</p>
<p>Please note that this series has <code>two seasons</code> filled with <code>mysteries and encrypted messages</code>. You won’t get bored.</p>
<h4 id="heading-the-end">The end?</h4>
<p>Now when I know that my children like to play with cryptography I have a few ideas on the<code>next step</code>. Definitely it’s not the last time they were working with ciphers and encrypted messages.</p>
<p>Thanks for reading! I hope that I was able to interest you a bit with this. If you actually try this with your kids please add a comment about it. I’m very curious whether it was as fun to you as it was for us.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The many, many ways that cryptographic software can fail ]]>
                </title>
                <description>
                    <![CDATA[ By Nabeel Yoosuf When cryptographic software fails, what’s to blame? Algorithms? Cryptography libraries? Apps incorrectly using those libraries? Or is it something else entirely? We rely on cryptographic algorithms and protocols every day for secure ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/why-does-cryptographic-software-fail-often-d660d3cdfdc5/</link>
                <guid isPermaLink="false">66c36695b737bb2ce7073205</guid>
                
                    <category>
                        <![CDATA[ Cryptography ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ startup ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 25 Jan 2017 02:25:49 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*eHaISV7BciMhq8o0AHmftg.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Nabeel Yoosuf</p>
<p>When cryptographic software fails, what’s to blame?</p>
<p>Algorithms?</p>
<p>Cryptography libraries?</p>
<p>Apps incorrectly using those libraries?</p>
<p>Or is it something else entirely?</p>
<p>We rely on cryptographic algorithms and protocols every day for secure communication over the Internet. We’re able to access our bank accounts online because cryptography protects us. We’re able to send private messages to our friends because cryptography protects us. We’re able to buy and sell things using credit cards and Bitcoin because cryptography protects us.</p>
<p>Let me give you a concrete example of this. When you check your email through your favorite browser, the connection between your browser and the email server is secured using the TLS (transport level security) protocol, so that no one can eavesdrop on your emails or modify them in transit without your knowledge.</p>
<p>In short, without cryptography, the Internet we know today could not be possible. Law and order on the internet depends on cryptography.</p>
<p>But this tool that we all rely upon so heavily is also quite brittle. Our cryptographic software often <a target="_blank" href="http://fortune.com/2016/05/18/linkedin-data-breach-email-password/">lets us down</a>. Sometime it <a target="_blank" href="http://money.cnn.com/2013/12/22/news/companies/target-credit-card-hack/">really lets us down</a>.</p>
<p>Have you ever wondered why the <a target="_blank" href="https://www.cl.cam.ac.uk/~rja14/Papers/wcf.pdf">cryptographic software</a> — including implementations of the TLS protocol — <a target="_blank" href="https://www.schneier.com/essays/archives/1998/01/security_pitfalls_in.html">fail</a> over and over again?</p>
<p>According Veracode’s state of security reports, our cryptographic software is just as vulnerabilities as it was two years ago.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/fe3A-m3hCNxrQMhkYQeuRcvTJB287TL-ot73" alt="Image" width="800" height="678" loading="lazy">
<em>Veracode ranked cryptographic issues as #2 vulnerability found in apps in 2015</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/H94qJr0QwDiVakmegPWDXbYSmRMMb9tZED-O" alt="Image" width="800" height="290" loading="lazy">
<em>Veracode again ranked cryptographic issues as #2 vulnerability found in apps in 2o16</em></p>
<p>Are these failing because of weaknesses in the underlying cryptographic algorithms?</p>
<p>Well, several past attacks (<a target="_blank" href="https://www.imperialviolet.org/2014/02/22/applebug.html">Apple iOS TLS</a>, <a target="_blank" href="http://hardwear.io/wp-content/uploads/2015/10/got-HW-crypto-slides_hardwear_gunnar-christian.pdf">WD self encrypting drives</a>, <a target="_blank" href="https://www.us-cert.gov/ncas/alerts/TA14-098A">Heartbleed</a>, <a target="_blank" href="https://www.theguardian.com/technology/2017/jan/16/whatsapp-vulnerability-facebook">WhatsApp messages</a>, <a target="_blank" href="https://www.google.com/webhp?sourceid=chrome-instant&amp;ion=1&amp;espv=2&amp;ie=UTF-8#q=juniper%20screenos%20vulnerability">Juniper’s ScreenOS</a>, <a target="_blank" href="https://drownattack.com/">DROWN</a>, <a target="_blank" href="http://karl-voit.at/2016/02/27/android-encryption/">Android N-encryption</a> and so on) show us that our cryptographic software is less likely to be broken due to the weaknesses in the underlying cryptographic algorithms. In other words, cryptanalysis is one of the less likely threats to our cryptographic software.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/9w3A4G6y-5zto71XmJxbTyDz8b5A6SwyVtaV" alt="Image" width="576" height="451" loading="lazy">
_A sketch of the AES algorithm ([image credit](http://www.moserware.com/2009/09/stick-figure-guide-to-advanced.html" rel="noopener" target="<em>blank" title=")) AKA why you don’t want to roll your own cryptography.</em></p>
<p>Have you ever heard an attacker breaking a 256-bit AES encryption algorithm to recover the secret hidden within it? None that I know of. (Of course, if you use a vulnerable obsolete cryptographic protocol like <a target="_blank" href="https://en.wikipedia.org/wiki/Data_Encryption_Standard">DES</a> or <a target="_blank" href="http://www.securityweek.com/new-attack-rc4-based-ssltls-leverages-13-year-old-vulnerability">RC4</a>, cryptanalysis might help break the software). So if the culprit isn’t cryptanalysis, then what is it?</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/aK1G79PpqMPtvs478FBokRR0Imh5j-1rDK3j" alt="Image" width="500" height="373" loading="lazy">
<em>Your security is only as good as its weakest link.</em></p>
<p>Well, it’s everything but cryptanalysis. In other words, cryptanalysis is not the weakest link of cryptographic software. Bad actors use numerous other weak links to break cryptographic software.</p>
<h3 id="heading-cause-of-failure-1-bugs-in-crypto-libraries"><strong>Cause of failure #1: bugs in crypto libraries</strong></h3>
<p>One popular example is the Heartbleed bug.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/VwqT62a1y1lEhMiMcUkOwUnt7yaVV5a6pj5I" alt="Image" width="341" height="413" loading="lazy"></p>
<p>What’s the matter with <a target="_blank" href="http://heartbleed.com/">Heartbleed</a>? This bug (<a target="_blank" href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=cve-2014-0160">CVE-2014–0160</a>) was introduced due to an incorrect implementation of the TLS heartbeat extension in the widely-used OpenSSL (read 66% of the internet), which is used to support TLS in web servers. What does this extension do? As the the name suggests, it’s a keep-alive feature where one end of the connection sends a payload of arbitrary data and the other end is supposed to send the exact copy of the data to prove that all is fine and well.</p>
<p>The bug turned out to be an age-old mistake of not bound checking before <code>memcpy()</code> that uses non-sanitized data. The vulnerable OpenSSL implementation <a target="_blank" href="http://www.theregister.co.uk/2014/04/09/heartbleed_explained/">does not validate the payload length against the actual payload</a>. An attacker could lie about the length and get the victim to send more bytes from its memory, as shown in the following diagram.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/iukZ8VzrmG8b3MRRD6xad7xNMBJV186XrGzp" alt="Image" width="800" height="545" loading="lazy">
<em>Attacker sends only one byte payload but sets the length to 65535; the victim blindly copies 65535 from its memory and sends back to the attacker.</em></p>
<p>This in turn allowed the attacker to obtain session keys and other secret information (like your username and password) from any websites currently in your browser’s memory.</p>
<p>Let me show you the code. The patch is essentially a bound check added to the patched version 1.0.1g as shown below.</p>
<pre><code>====== Vulnerable code =======<span class="hljs-comment">/* Enter response type, length and copy payload */</span>*bp++ = TLS1_HB_RESPONSE;s2n(payload, bp);memcpy(bp, pl, payload);
</code></pre><pre><code>====== Patched code =========hbtype = *p++;n2s(p, payload);<span class="hljs-keyword">if</span> (<span class="hljs-number">1</span> + <span class="hljs-number">2</span> + payload + <span class="hljs-number">16</span> &gt; s-&gt;s3-&gt;rrec.length)  <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>; <span class="hljs-comment">/* silently discard per RFC 6520 sec. 4 */</span>pl = p;
</code></pre><p><strong>Lesson learned:</strong> Always bound check your strings before using them. Sanitization is vital for stopping bad inputs from getting into your system.</p>
<h3 id="heading-cause-of-failure-2-operating-systems-and-apps"><strong>Cause of failure #2: operating systems and apps</strong></h3>
<p>You probably remember <a target="_blank" href="https://www.imperialviolet.org/2014/02/22/applebug.html">Apple’s “goto” bug</a> (<a target="_blank" href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-1266">CVE-2014–1266</a>) in its SSL/TLS implementation, disclosed in February 2014.</p>
<p>Apple’s code with the “goto” bug:</p>
<pre><code><span class="hljs-number">1</span> <span class="hljs-keyword">static</span> OSStatus2 SSLVerifySignedServerKeyExchange(SSLContext *ctx, bool isRsa,                                  SSLBuffer signedParams,<span class="hljs-number">3</span>                       uint8_t *signature, UInt16 signatureLen)<span class="hljs-number">4</span> {<span class="hljs-number">5</span>   OSStatus err;<span class="hljs-number">6</span> …<span class="hljs-number">78</span>   <span class="hljs-keyword">if</span> ((err = SSLHashSHA1.update(&amp;hashCtx, &amp;serverRandom)) != <span class="hljs-number">0</span>)<span class="hljs-number">9</span>     goto fail;<span class="hljs-number">10</span>  <span class="hljs-keyword">if</span> ((err = SSLHashSHA1.update(&amp;hashCtx, &amp;signedParams)) != <span class="hljs-number">0</span>)<span class="hljs-number">11</span>    goto fail;<span class="hljs-number">12</span>    goto fail;<span class="hljs-number">13</span>  <span class="hljs-keyword">if</span> ((err = SSLHashSHA1.final(&amp;hashCtx, &amp;hashOut)) != <span class="hljs-number">0</span>)<span class="hljs-number">14</span>    goto fail;<span class="hljs-number">15</span>  …<span class="hljs-number">1617</span> fail:<span class="hljs-number">18</span>   SSLFreeBuffer(&amp;signedHashes);<span class="hljs-number">19</span>   SSLFreeBuffer(&amp;hashCtx);<span class="hljs-number">20</span>   <span class="hljs-keyword">return</span> err;<span class="hljs-number">21</span> }
</code></pre><p>So, what’s the issue here? The extra goto statement on line 12 bypasses all certificate checks for SSL/TLS connections in iOS and Mac devices. This makes lines 13 to 16 effectively dead code. This simple implementation mistake accepts any invalid certificate, making the connection susceptible to Man in the Middle attacks.</p>
<p>I was curious to find out whether the implementation bugs in crypto software are more due to bugs in the crypto libraries themselves than in the way apps use them. Well <a target="_blank" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwj--OSC7NrRAhXrJcAKHd2nDiEQFggbMAA&amp;url=https%3A%2F%2Fpeople.csail.mit.edu%2Fnickolai%2Fpapers%2Flazar-cryptobugs.pdf&amp;usg=AFQjCNGJvctaCQ8jDTUsZUgLX_AVl-LdKQ&amp;sig2=P919CUo8W5fG7g7g1AroWQ">researchers from MIT</a> analyzed 269 cryptographic bugs reported in the Common Vulnerabilities and Exposures database between January 2011 and May 2014. They found that only 17% of bugs are caused by the crypto libraries themselves. The remaining 83% are due to misuse of crypto libs by app developers.</p>
<p>But just because the majority of bugs are due to misuse of crypto libraries in apps doesn’t mean that we can just blame app developers and get on with our day.</p>
<p>There could be many reasons behind the above statistics on the crypto misuse. The crypto libraries themselves may not be providing safe default options, may not have adequate documentation or may be difficult to use. Further, many developers may not have a formal understanding of applying cryptography in their software, even though they are experts at software development itself. These all could result in the misuse of crypto libs.</p>
<p><strong>Lesson learned:</strong> always use tools to analyze your code. A dead code analysis tool should have caught this specific case.</p>
<h3 id="heading-cause-of-failure-3-bad-design"><strong>Cause of failure #3: bad design</strong></h3>
<p>In 2015, researchers uncovered a series of issues in WD self-encrypting drives. There were serious design flaws in their use of cryptographic algorithms. I wrote about this in a <a target="_blank" href="https://decentralize.today/encryption-is-useless-completely-useless-part-1-14a5e3bd069b#.h94ta28eu">previous post</a>. Let me show a couple of flaws here.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ViJwzCkWz2D6nmxHoE4YQHOahxXMhkPzv-85" alt="Image" width="384" height="296" loading="lazy">
<em>WD’s self encrypting drive architecture</em></p>
<p>Following the best practices, WD did use two levels of keys to encrypt documents stored in the drive — master KEK (Key Encryption Key) and per file DEK (Data Encryption Key). Further, they did use a key derivation function to derive KEKs from the password.</p>
<p>But the way they designed the key derivation function itself was totally insecure. They used a fixed salt and a fixed number of iterations. Thus, it was susceptible to pre-computed hash table-based attacks. Attackers could recover keys much faster than a pure brute force attack would have been able to.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/xNOCC3T-Ejcup3h89XWOtgE103A8VD-2Hj3H" alt="Image" width="756" height="365" loading="lazy">
<em>WD’s vulnerable key derivation algorithm</em></p>
<p>And if this vulnerability weren’t enough, WD used a dismal random number generator to generate KEKs. It was not only predictable — it also didn’t have enough complexity (only 40 bits).</p>
<p>Cryptographic protocols critically rely on cryptographically secure pseudorandom number generators. If these aren’t secure enough, any cryptographic algorithm or protocol using these random numbers will be quite easy to break.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/GrNo2Nf1RAlPVyTrANT0mmHLv9bAevCTSgAz" alt="Image" width="703" height="262" loading="lazy">
<em>WD’s weak random number generator</em></p>
<p><strong>Lesson learned:</strong> Have a good understanding of cryptographic constructs and know their limitations. Follow industry best practices for key derivation.</p>
<h3 id="heading-cause-of-failure-4-misconfigurations-or-insecure-default-configurations"><strong>Cause of failure #4: misconfigurations or insecure default configurations</strong></h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/3-VGZNwxuYBBHi5dmH588z5M9lmD9YA9VlEb" alt="Image" width="792" height="542" loading="lazy">
_Exploiting the weaknesses of SSLv2 ([source](https://drownattack.com/" rel="noopener" target="<em>blank" title="))</em></p>
<p><a target="_blank" href="https://drownattack.com/drown-attack-paper.pdf">DROWN attack</a> of breaking TLS connections via SSLv2 is a good example of this. You may be using fairly secure TLS connection to communicate with a web server, but if the web server still supports (which it shouldn’t) old SSLv2, an attacker can exploit it to break the security provided by TLS and get at your keys and other sensitive information.</p>
<p>SSLv2 has long considered to be broken, and none of the clients today use it for secure connections. But researchers have found that out of 36 million HTTPS servers they probed, 6 million (about 17%) still supported SSLv2.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/DMIkoMXQS6V0KBwPI1whg2KPQTUkaFHYhADT" alt="Image" width="800" height="388" loading="lazy"></p>
<p>The above research also uncovers another common lazy practice of using the same key pair in different servers of an organization. It shows how even when one server supports only TLS, if there are other servers supporting SSLv2 with a shared certificate, the server that only supports TLS is vulnerable as well.</p>
<p><strong>Lesson learned:</strong> a system is only as secure as its weakest link. Try to protect all of your systems at least reasonably well.</p>
<h3 id="heading-there-are-lots-of-other-ways-cryptographic-software-can-fail">There are lots of other ways cryptographic software can fail</h3>
<p>Can you think of some additional ways?</p>
<p>It fails due to users. How? Think about social engineering attacks. <a target="_blank" href="http://www.theregister.co.uk/2011/04/04/rsa_hack_howdunnit/">RSA SecureID breach is said to originate from phishing emails exploiting users and a zero day vulnerability</a>.</p>
<p>It fails due to unrealistic threat models (<a target="_blank" href="https://eprint.iacr.org/2016/920.pdf">Breaking web applications built on top of encrypted data</a>).</p>
<p>It fails due to hardware (<a target="_blank" href="https://www.blackhat.com/docs/us-16/materials/us-16-Sharkey-Breaking-Hardware-Enforced-Security-With-Hypervisors.pdf">Breaking hardware enforced technologies such as TPM with hypervisors</a>).</p>
<p>It fails due to side channels (<a target="_blank" href="http://www.cryptography.com/resources/whitepapers/TimingAttacks.pdf">Timing attacks on RSA, DH and DSS algorithms</a>).</p>
<p>As you can see, cryptographic software can fail due to many reasons. Are we really doomed to never get cryptographic software right? Or can we at least can reduce the number of such failures? Why can’t we learn from the past and avoid the same mistakes happening again and again? What tools will help us spot most of these issues?</p>
<p>Our situation actually isn’t all that bleak. There are ways to prevent most of the failures discussed above. In a follow up post, I’ll explore the topic of how we can make cryptographic software fail less often.</p>
<p>Thanks for reading. If you found this article useful, please click the ? below so that others can see this on Medium.</p>
<h4 id="heading-further-reading"><strong>Further Reading</strong></h4>
<ul>
<li>[Aderson, Why cryptosystems fail, CCS 1993](http://Why Cryptosystems Fail - University of Cambridge Computer Laboratory)</li>
<li><a target="_blank" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwidioe4yOnRAhXIcBoKHYalBWAQFggbMAA&amp;url=https%3A%2F%2Fpeople.csail.mit.edu%2Fnickolai%2Fpapers%2Flazar-cryptobugs.pdf&amp;usg=AFQjCNGJvctaCQ8jDTUsZUgLX_AVl-LdKQ&amp;sig2=jNxWe1fBL5LSymGIjNdhig">Lazar et. al., Why does cryptographic software fail? A case study and open problems, APSys, 2014</a></li>
<li><a target="_blank" href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwi_093EyOnRAhXDQBoKHVyBDEkQFggnMAE&amp;url=https%3A%2F%2Fcs.ucsb.edu%2F~chris%2Fresearch%2Fdoc%2Fccs13_cryptolint.pdf&amp;usg=AFQjCNEmwGK1lobalVteyWAzgvzThSPafg&amp;sig2=5eV_mxv-XvkdcjprP_7SMQ">Egele et. al., An empirical study of cryptographic misuse in Android applications, CCS, 2013</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
