Cryptography Algorithms Protocols - Zoubir Mammeri
Cryptography Algorithms Protocols - Zoubir Mammeri
Zoubir Mammeri
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical,
photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act,
without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright
Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4470, or on the web at www.copyright.com.
Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street,
Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permission.
Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates in the United
States and other countries and may not be used without written permission. All other trademarks are the property of their respective owners.
John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.
Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no
representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied
warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives or written
sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where
appropriate. Further, readers should be aware that websites listed in this work may have changed or disappeared between when this work was
written and when it is read. Neither the publisher nor authors shall be liable for any loss of profit or any other commercial damages, including
but not limited to special, incidental, consequential, or other damages.
For general information on our other products and services or for technical support, please contact our Customer Care Department within the
United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic formats.
For more information about Wiley products, visit our web site at www.wiley.com.
Set in 9.5/12.5pt STIXTwoText by Integra Software Services Pvt. Ltd, Pondicherry, India
Contents
Preface xviii
2 Introduction to Cryptography 33
2.1 Definitions of Basic Terms 33
2.1.1 Cryptography, Cryptanalysis, and Cryptology 33
2.1.2 Brief History of Cryptography 34
2.1.3 Basic Terms Related to Encryption Systems 36
2.1.4 Symmetric and Asymmetric Cryptographic Systems 37
2.1.4.1 Symmetric Cryptosystems 37
2.1.4.2 Asymmetric Cryptosystems 37
2.1.4.3 Symmetric vs Asymmetric Cryptosystems and Their Combination 37
2.1.4.4 Trapdoor Functions 38
2.2 Cryptographic Primitives 39
2.2.1 Encryption 40
2.2.2 Hash Functions and Data Integrity 40
2.2.3 Message Authentication Codes 40
2.2.4 Digital Signature 41
2.2.5 Digital Certificates and Non-Repudiation 42
2.2.6 Shared-Secret Generation 42
2.2.7 Pseudorandom Number Generation 43
2.3 Fundamental Properties of Cryptographic Algorithms 43
2.3.1 Should Cryptographic Algorithms Be Secret or Not? 43
2.3.2 Models of Security Proof 43
2.3.2.1 Computational Infeasibility 43
2.3.2.2 Provable Security 43
2.3.3 Perfect Secrecy 44
Preface
For millennia, human beings have used multiple forms of codes to protect their oral communications, entries of castles,
their messages, and other belongings. Indeed, cryptography existed early in human history and civilizations, before the
event of computers. Cryptography has been developed and improved over the centuries, in particular for protecting mili-
tary secrets and spying on enemies, then for protecting industrial and economical secrets, then for protecting recent appli-
cations made possible with the use of the internet, and ultimately for protecting the privacy of electronic devices’ users. In
a highly computerized world, cryptography is the pillar of security. Encrypting and signing are the most performed crypto-
graphic operations in the digital world.
Cryptography provides services to secure websites, electronic transmissions, and data repositories. For more than
three decades, public-key cryptography has been enabling people, who never met before, to securely communicate and
trust each other. Cryptography is not only used over the internet, but also in phones, bank cards, televisions, cars, air-
crafts, door locks, implants, and a variety of other devices. Without cryptography, hackers could get into victims’ emails,
listen to their phone conversations, tap into their cable companies and acquire free cable services, or break into their
bank accounts.
Cryptography is the discipline at the intersection of computer science and mathematics. It provides algorithms for guar-
anteeing confidentiality, integrity, authentication, and non-repudiation for parties that share data or exchange messages to
perform operations and transactions in cyberspace. For example, customers’ bank accounts or citizens’ votes must remain
confidential and not altered by any unauthorized third party. E-merchants, as well as clients, must be protected from each
other; a customer, who ordered an article, could not deny ordering; and a merchant, who has been paid, could not deny
having been. A person, who digitally signed an agreement or a contract, cannot deny having signed. Such protections, and
many others, are provided thanks to cryptography.
Cryptography standards are needed to enable interoperability in cyberspace. In general, standard protocols follow rig-
orous procedures of testing before their adoption. Therefore, it is highly recommended to use only standard security pro-
tocols to build information security systems. Security, in general, and cryptography, in particular, have evolved at a rapid
pace in the past two decades. Security technology has gone through tremendous changes in terms of protocols and stan-
dards. The continuous evolution of information technology, on one hand, and the discovery of vulnerabilities in standards,
on the other hand, motivate the development of new standards. In the last 15 years, cryptography standards made tremen-
dous advances that are not included in existing books. Some standards have become obsolete and others have recently been
recommended. This book aims at providing a comprehensive description of recent advances in cryptographic protocols.
The focus is on the NIST (National Institute for Standards and Technology, US) and IETF (Internet Engineering Task
Force) standards, which are commonly used in the internet and networking applications.
This book, also, aims at providing a comprehensive description of notions, algorithms, protocols, and standards in the
cryptographic field. It addresses algorithms through examples and problems, highlights vulnerabilities of deprecated
standards, and describes in detail algorithms and protocols recommended in recent standards. In addition, it focuses on
the basic notions and methods of security analysis and cryptanalysis of symmetric ciphers. The book is designed to serve
as a textbook for undergraduate and graduate students, as well as a reference for researchers and practitioners in
cryptography.
Definitions included in this book are inspired by NIST and IETF glossaries [1,2]. They are not formal definitions. Rather, they
are provided to summarize the basic notions of cryptography and facilitate the learning of algorithms and protocols.
1) Paulsen C, Byers RD. Glossary of Key Information Security Terms. NIST; 2019.
2) Shirey R. Internet Security Glossary, RFC 4949. Internet Engineering Task Force; 2007.
Chapter 1: This chapter introduces aims at introducing the main issues and notions of security in computer-based systems.
The main properties of security (namely confidentiality, integrity, authenticity, and non-repudiation) are introduced. A
taxonomy of attacks on digital assets is provided. Multiple components and practices, required to address from different
perspectives the security of computer-based systems, are introduced in this chapter. The main technical components of
security include cryptography, which is the focus of the remainder of the book.
Chapter 2: Cryptography has developed and improved over time. Chapter 2 aims at providing a brief history of cryptog-
raphy and presenting its main notions and techniques. Breaking cryptographic codes is a very ancient activity to disclose
secrets. An overall categorization of attacks on modern cryptographic algorithms is discussed in this chapter. There exist
two main categories of cryptographic systems: symmetric and asymmetric (also called public-key) cryptosystems. The
design differences between both categories are briefly discussed. Message digest, digital signature, and digital certificate
are of prime importance to establish trust between parties that share data and exchange messages. These notions are intro-
duced in Chapter 2.
Chapter 3: This chapter aims at reviewing and presenting, with examples and exercises, the mathematical background
useful to address cryptography algorithms. In particular, modular arithmetic and finite fields are of prime importance to
understand the design of cryptographic algorithms. Fundamental theorems for cryptography are provided. In addition, to
mathematical notions, computation algorithms (such as Extended Euclidean algorithm, square-and-multiply method to
perform modular exponentiation, modular multiplication, Gauss’s algorithm to solve congruence systems, Tonelli-Shanks’s
algorithm to find modular square roots, and Rabin’s algorithm to test irreducibility of polynomials), which are often used
in cryptographic algorithms, are introduced with examples and exercises. Readers who have a sufficient background in the
reminded notions and algorithms can skip this chapter.
Chapter 4: Shift and substitution ciphers have been used in written text transmission; and dominated the art of secret
writing for at least two millenniums. The most known historical ciphers in this category include Caesar’s, Vigenere’s,
Affine, One Time Pad, and Enigma ciphers. All those ciphers are original inventions, with ideas and principles that inspired
authors of modern cryptographic algorithms. Before presenting modern cryptographic algorithms, Chapter 4 aims at
providing an overview of historical ciphers and their ingenious ideas. Methods used to break historical ciphers have widely
been exploited to design modern ciphers.
Chapter 5: This chapter introduces three notions of cryptography: hash functions, message authentication codes, and
digital signature. All of them are of paramount importance for providing integrity and authentication guarantees. Hash
functions produce digital fingerprints, also called message tags, which are mainly used to verify the integrity of messages
and files, to generate and verify digital signatures, and to generate random numbers. Approaches to design hash functions
and standard hash functions (i.e. SHA-1, SHA-2, and SHA-3) and standard Message Authentication Codes (i.e. HMAC and
KMAC) are described in detail. Common attacks against MAC algorithms and digital signatures are discussed.
Chapter 6: Stream ciphers are symmetric ciphers that encrypt and decrypt bits individually. They are used, in particular,
to secure communications in wireless and cellular networks. Stream ciphers are well-suited to hardware implementation
and they are generally faster than block ciphers. They also are well-suited to encrypt and decrypt continuous data at high
rate and when devices have limited memory to store long messages. Often, stream ciphers are designed using LFSRs
(Linear-Feedback Shift Registers) combined with nonlinear filtering functions. Chapter 6 aims at providing a discussion of
the design principles of LFSRs and stream ciphers to produce keystream bits, used to encrypt plaintexts and decrypt cipher-
texts. It also provides a detailed description of the most known and standard stream ciphers: A5/1, E0, SNOW 3G, ZUC,
Chacha20, RC4, Trivium, and Enocoro.
Chapter 7: This chapter addresses block ciphers, which are the most used algorithms to secure data and messages. Data
or messages are split into blocks of a fixed size (e.g. 128 bits) and plaintext blocks are encrypted individually to generate
ciphertext blocks of the same bit-length than that of a plaintext block. In addition to ciphering, block ciphers can be used
to generate pseudorandom numbers or to build hash functions and MACs (Message Authentication Codes). A huge
number of block ciphers are published in literature. However, a very small number of them are standards that are used in
operational cryptosystems. This chapter introduces the basics of construction of block ciphers and presents in detail the
standard block ciphers, currently in use, namely TDEA (Triple Data Encryption Algorithm) and AES (Advanced Encryption
Standard). Known attacks against block ciphers are discussed.
Chapters 8 and 9: A block cipher, such as AES or TDEA, takes a fixed-size plaintext block and returns a ciphertext block
of the same size. However, in many applications, a plaintext (e.g. a text file or an image) is composed of several (maybe in
thousands or even more) blocks. When plaintext blocks are repeated in the same data or message and identically encrypted,
an attacker may infer some information regarding the ciphertexts that he/she intercepted. In addition, in many applica-
tions, the recipient of a message may need to authenticate the message sender. Chapter 8 addresses standard operation
modes of block ciphers to guarantee confidentiality. The NIST recommends 11 modes (ECB, CBC, CBC-S1, CBC-S2, CBC-
S3, OCB, CTR, CFB, FF1, FF-3, and XTS-AES) for guaranteeing confidentiality. Chapter 9 focuses on modes of operation
of block ciphers to provide either authentication or confidentiality and authentication. NIST recommends three modes
(CMAC, GMAC, and Poly1305-AES), for authentication-only, and six modes (CCM, GMAC, AED-ChaCha20-Poly1305,
KW, KWP, and TKW) for authentication and confidentiality. All the 20 operation modes recommended by NIST are
addressed in detail in Chapters 8 and 9. Known attacks against operation modes are also discussed.
Chapter 10: Modern cryptographic security relies on the computational difficulty to break ciphers rather than on the the-
oretical impossibility to break them. If adversaries have enough resources and time, they can break any cipher. The secu-
rity analysis of block ciphers and their modes of operation is a wide field in cryptanalysis. It aims at finding bounds on the
amount of data to encrypt with the same key without compromising the security of encrypted data. Chapter 10 introduces
security analysis in which adversaries are given black boxes that simulate block ciphers or their modes of operation. Then,
adversaries query black boxes, receive ciphertexts, plaintexts, or tags, and try to guess some information about the used
keys or to forge signatures or message tags. Secure ciphers are those ciphers for which the advantage of adversaries is neg-
ligible if their resources and time remain below some limits. The analysis of different scenarios of attacks is an approach to
assess the security of ciphers from a probabilistic point of view.
Chapter 11: Cryptanalysis is the science and techniques of analyzing and breaking cryptographic algorithms and proto-
cols. It is a very exciting and challenging field. There exist hundreds of cryptanalysis attack variants. Chapter 11 aims at
presenting the most known cryptanalysis attacks against symmetric ciphers, namely memory-time trade-off attacks, linear
cryptanalysis, differential cryptanalysis algebraic cryptanalysis, cube attacks, divide-and-conquer attacks, and correlation
attacks.
Chapter 12: The turning point in modern cryptography occurred in 1976–1977, when Diffie and Hellman on one side and
Rivest, Shamir, and Adleman, on the other, proposed original schemes to secure systems without requiring a unique cipher
key shared by both parties. The proposed schemes were and are still used to design public-key cryptosystems. The latter
provide support to secure communications worldwide between people who do not a priori know each other. The first and
still most widely used public-key cryptosystem is with no doubt RSA. Modern cryptography is founded on the idea that the
key used to encrypt messages can be made public, while the key used to decrypt messages must be kept private. Chapter 12
aims to describe public-key algorithms and protocols, for providing confidentiality, integrity, and authentication guaran-
tees. They include RSA, Diffie-Hellman key exchange, Menezes-Qu-Vanstone, and ElGamal cryptosystems. The security of
public-key cryptosystems is based on either the integer factorization problem or the discrete logarithm problem over cyclic
groups. Those problems are known to be computationally infeasible for large numbers; and they are discussed in this
chapter. Known attacks against addressed algorithms are introduced.
Chapter 13: The second generation of public-key cryptosystems are based on elliptic curve theory. Elliptic curve (EC)
cryptography algorithms entered wide use in 2004. After a slow start, EC-based algorithms are gaining popularity and
the pace of adoption is accelerating. EC cryptosystems have been adopted by Amazon, Google, and many others to
secure communications with their customers. EC cryptosystems amply outperform RSA-based cryptosystems. Until
2015, the NSA (National Security Agency, US) recommended 256-bit EC cryptography for protecting classified
information up to the secret level and 384-bit for Top-secret level. Since 2015, the NSA has recommended 384-bit for all
classified information. IETF standards have been proposed to support EC for Transport Layer Security. Chapter 13 aims
at addressing different forms of EC-based algorithms, such as ECDSA, to provide confidentiality, integrity, and authen-
ticity guarantees. Compared to RSA, EC-based algorithms make use of more difficult mathematical operations, which
are addressed in this chapter.
Chapter 14: Keys are owned and used by entities that interact with each other to perform specific operations in different
fields of activities. These keys are analogous to the combination of a safe. If adversaries know the combination of a safe,
then the latter does not provide any security against attacks, even it is very complex. Keys are the most valuable items in
computer security. Therefore, their protection is of paramount importance. Chapter 14 focuses on key management, which
provides functions to secure cryptographic keys throughout their lifetime. It mainly includes key generation, storage, dis-
tribution, recovery, suspension, and withdrawal. This chapter aims at introducing the main mechanisms and protocols for
key generation, key agreement, key transport, and key distribution over unsecure channels.
Chapter 15: Parties, which exchange encrypted messages over the internet, need to trust each other to secure their oper-
ations and transactions in e-commerce, e-banking, e-voting, etc. In addition, parties that exchange messages or access
encrypted data inside a company or an institution, where messages/data are encrypted using symmetric keys, need to
securely share their keys. Chapter 15 addresses both situations and presents different notions, including key distribution
center, digital certificate, certification authority, and Public-key infrastructures (PKIs). PKIs are of paramount impor-
tance to establish trust between partners that do not a priori trust each other in the open digital world. Today, digital
certificates are used by billions of end-entities, including web servers and their clients, to authenticate each other. The
main protocol to secure communications over the internet is with no doubt TLS (Transport Layer Security); it is intro-
duced in this chapter.
Chapter 16: Modern cryptography is fundamentally based on large random and prime numbers. In particular, keys
should be generated using large random numbers; and RSA keys are generated using large prime numbers. Any weak-
ness (in term of randomness) in a selected key may result in damage of data and messages protected by that weak key.
Chapter 16 addresses algorithms and methods recommended to generate random and prime numbers. True random
numbers are hard to produce by computer. In consequence, deterministic random number generators (DRNGs) are of
common use in cryptography. However, it is of prime importance to use only DRNGs recommended by NIST and IETF.
DRNGs cannot guarantee that generated integers are prime. Therefore, algorithms for testing primality are of common
use in cryptography. When prime numbers are required, only provable and probable primes should be used. Probable
primes are those integers shown to be prime by probabilistic tests. Both types of primes are discussed in this chapter.
Appendix: A series of 200 multiple choice questions (with answers), relating to computer security in general and to cryp-
tography in particular, are proposed for knowledge testing. These MCQs were collected from various sources, including
questions for job applicants, course certification, and exams in IT security field.
Information and computer technologies (ICT), or simply IT technologies, are everywhere, in all fields of activities (business,
commerce, transportation systems, health, leisure, education, administration, national security, army, etc.). Nowadays,
human beings are more than ever dependent on IT technologies. Therefore, IT security became a paramount concern for
any owner or user of electronic devices.
Since the early stage of computers, cyberattacks have never stopped. Worse, statistics provided annually by cybercrime
observers and experts often show increases in attacks worldwide. In particular, ransom attacks have become the most
lucrative criminal activities in the cyberspace. Partial or total shutdown of systems, as long as ransoms are not paid, results
in losses in billions of dollars for companies, hospitals, e-merchants, banks, and individuals.
This chapter aims at providing an introduction to the main issues and notions of security in computer-based systems and
tries to answer the following questions:
● What are the security issues and requirements?
● Why and how do security attacks occur?
● How to face security attacks? That is, what are the countermeasures to security attacks?
Security techniques encompass at least two distinct domains:
● Technical domain, including hardware and software design to address security;
● Organizational domain, including education, staff training, and laws to make involved people aware of IT security.
This book addresses security from a technical point of view only; in particular, it addresses cryptography. However, it
should be clear that technology alone is not enough to address security. Imagine that you use a sophisticated alarm system
in your home, but the code to access the system is “1234”; or if a teenager in your family does not protect the house alarm
code when he/she is at school or at sport club; or even worse, he/she forgets switching on the alarm system when he/she
leaves your home. Therefore, organizational issues (including education to security) are of prime importance.
Several books (including [1–9] and journal papers [10, 11]) addressed in detail IT security. This chapter aims only to
present the notions of IT security, in particular the security services that can be supported by cryptographic algorithms.
1.1 Introduction
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
2 1 Introduction to Computer Security
Definition 1.1 Cyberspace: it is the space composed of electromechanical devices, computers, communication links, and
applications servers where humans interact using the provided facilities.
Cyber comes from Cybernetics, which is a large discipline including control systems, electrical theory, mechanical engi-
neering, logic modeling, and others. The main component of cybernetics is the computer. Starting from the 1960s most of
engineering studies in cybernetics have been specialized and became computer science, electronics, automation, telecom-
munications, and so on.
From security point of view, protections focus on:
● Physical entities: including plants, labs, stores, parking areas, loading areas, warehouses, offices, machines, robots, vehi-
cles, products, materials, etc. At this level, the protection is physical (e.g. protect doors, PCs, cables, etc.).
1.1 Introduction 3
● People: protect life, health, the privacy of staff members, customers, and guests.
● Data: protect files, databases, messages, programs, servers…
This book focuses on data protection only. However, before focusing on data protection, below is a brief introduction to
barriers used for physical protection to enforce data protection.
i) Physical barriers
They are used to deter the potential attackers; they include:
● Guards: deploy security agents in and around vulnerable areas.
● Fences: build high and impassable fences and walls.
● Restricted access technologies (alarms, locks): deploy alarm systems to detect intrusions and highly-resistant locks to
prevent unauthorized access.
● Information security is defined as: the protection of information and information systems from unauthorized access,
use, disclosure, disruption, modification, or destruction in order to provide confidentiality, integrity, and
availability.
● Cybersecurity is defined as: the ability to protect or defend the use of cyberspace from cyberattacks. Cybersecurity is about
securing devices (computers, mobile devices, applications, and data) that are accessible through ICT.
In practice, cybersecurity term is often used by people not directly involved or specialized in computer science (e.g.
police officers, judges, presidents, and mayors) to talk about attacks made via Internet. Whereas IT security or simply secu-
rity terms are used by those people directly involved in computers and software. In this book, security is used to designate
IT security. Figure 1.1 provides an overall comparison of IT security to Cybersecurity, where:
● Information (of a company, country, or an individual) includes digital and non-digital (i.e. papers, frames, books, films,
etc.). Non-digital information is not under the control of computers, while digital information is. Information security is
concerned by the security of information whatever is the support and ways of access.
● Cyberspace is composed of computers and by other equipment (e.g. trains, cars, grid installations, robots, and water
provisioning equipment). All those categories of equipment are vulnerable to attacks through ICT. Their protection
requires specific methods and techniques; some of them are out of the computer field (e.g. smart grids and industrial
equipment). Cybersecurity is concerned with the security of any assets vulnerable because they are connected to ICT
systems.
● Intersection of information and cyberspace security is the IT security focusing on digital data, which are vulnerable to
threats via ICT.
Definition 1.3 Adversary: it is any entity that attacks or that is a potential threat to a system. It is also called attacker or
threat agent.
Definition 1.4 Attack vector: it refers to any path or means by which an attacker can gain access to an asset. The adversary
uses attack vectors (such as email, web servers, physical access, etc.) to gain access to protected assets.
Definition 1.5 Vulnerability: it refers to a known weakness of an asset that can be exploited by attackers.
Example 1.1
– No password change for years, open account with no user in a company, and secret data stored in a place easy to access
are examples of vulnerabilities.
– No update of phone software with recent security recommendations and a web camera with code 1234 are other exam-
ples of vulnerabilities.
Any entities, including the following, using computer-based systems are vulnerable:
● Companies, banks, and financial institutions
● Internet service providers and Telecom operators
● Hospitals, museums, and universities
● Government and defense agencies
● Smart cities and smart grids
● Industrial installations and factories
● Nuclear plants
Definition 1.6 Attack surface: it is defined as the set of all vulnerability points of an asset, a system, or a network.
The larger the attack surface is, the more difficult the protection is.
Definition 1.7 Threat: it refers to any incident that has the potential to harm a system. A threat is something that may or
may not happen; but if happens, it has the potential to cause serious damage.
Threats depend on targets, for example:
● Threats on hardware: theft and sabotage.
● Threats on software: deletion, server access blocking, theft, alteration of functions or configurations, content change of
web pages, and web server hacking.
● Threats on data: theft of private data, theft of intellectual properties, file deletion, file access blocking, and data
alteration.
Definition 1.8 Risk: It is defined as the potential for loss or damage, if a threat exploits a vulnerability.
Example 1.2 Financial lofsses, loss of privacy, reputational damage, legal implications, and even loss of life are examples
of security risks.
Figure 1.2 summarizes the relationships between the main terms of security:
– The legitimate owner of assets needs protection of his/her assets.
– The adversary threatens to use, alter, or destroy the assets.
– The assets have vulnerabilities, which may be exploited by the adversary.
– Vulnerabilities are loopholes for the adversary to design and mount attacks.
– The owner deploys countermeasures to minimize the risks relevant to the threats.
6 1 Introduction to Computer Security
The three basic security services are referred to as the CIA triad. CIA stands for Confidentiality-Integrity-Availability.
Sometimes, CIA are called basic properties of security. In addition to CIA, authentication, authorization, and non-repudi-
ation are services often required in the cyberspace. Depending on the asset owner’s needs, a single, two, or several services
may be required. Figure 1.3 summarizes the main security services used to protect assets.
Example 1.3 The following are examples of information that require confidentiality protection:
– industrial secrets of companies
– business agreements
– defense secrets
– health data, bank accounts, and private meetings of individuals
1.3.2 Integrity
Asset integrity is a property whereby asset content and/or behavior have not been modified in an unauthorized manner
after being created, updated, maintained, stored, or transmitted. According to the category of asset, three types of integrity
are distinguished: data, system/software, and hardware integrity.
Data integrity: it is a property whereby data has not been modified in an unauthorized manner after being created, stored,
or transmitted. Data modification includes the insertion, deletion, and substitution of data.
System/software integrity: it is a property whereby a system (e.g. a web server) or a software (e.g. a library) has not been
modified in an unauthorized manner after being created, stored, or transmitted. Software modification includes deletion
and alteration of some functions or some configuration parameters. System/software integrity aims at guaranteeing that
a system or the software performs its intended functions in an unimpaired manner, free from deliberate or inadvertent
unauthorized manipulations of system or software.
1.3 Security Services 7
Hardware integrity: it is a property whereby a hardware component (e.g. a camera, a sensor, or a card reader) has not been
modified in an unauthorized manner after being created and acquired or after maintenance operation.
1.3.3 Availability
Asset availability is a property whereby asset content or services are available to be used by its legitimate users. An asset
may become temporarily or definitely inaccessible, thus unavailable because of attacks. In a similar way to integrity,
according to asset category, three types of availability are distinguished: data, system/software, and hardware availability.
Data availability: it is a property whereby data (i.e. files and databases) is accessible whenever requested by legitimate
users. Both data deletion and data server blocking impact data availability.
System/software availability: it is a property whereby the function/service of a system (e.g. a web server) or a software is not
slowed down or stopped by an attack. Therefore, it is not denied to authorized users. For example, a web server should
process legitimate requests and not be blocked (totally or partially) by fraudulent requests.
Hardware availability: it is a property whereby a hardware component is available for use.
Notes
– Attacks targeting asset availability are frequent in today’s Internet. In general, after stopping partially or entirely a
system, attackers demand a ransom.
– Attacks against asset availability are the most difficult to address.
Source authentication service is used to verify the identity of the entity that created a data and sent a message, that contains
that data, is the one included, as a source, in the message. The question addressed by source authentication is the follow-
ing: is the sender of a message really the entity that created the data included in the message?
Identity authentication and source authentication are very similar, but have different purposes. The first authentication
aims at controlling access to services, while the second aims at verifying the authenticity of a message. The latter is the prop-
erty whereby the recipient of a message has guarantees that the message was generated and sent by a trusted source.
1.3.6 Authorization
Authorization is concerned with providing permissions to perform specific operations or activities on assets; for
example, read or copy files, use specific printers, or access some rooms or factories in a company. In general, authori-
zation follows authentication; i.e. the person identity is authenticated, and then, the requesting person is granted some
rights to access assets.
1.4 Attacks
– IT experts who maintain a cybercriminal organization IT infrastructure, such as servers, encryption technologies, and
databases. Very experienced IT engineers are employed by cybercrime organizations.
– Hackers who exploit systems, applications, and network vulnerabilities.
– Fraudsters who create and deploy schemes like spam and phishing.
– Distributors who distribute and sell stolen data to associated cybercriminals.
– System hosts and providers, which host sites that possess illegal contents.
● Business and finance experienced staff (who usually lack technical knowledge):
– Cashiers who provide account names to cybercriminals and control drop accounts.
– Money mules who manage bank account wire transfers.
– Tellers who transfer and launder illegal money by using digital and foreign exchange facilities.
– Leaders who are often connected to big bosses of large criminal organizations. They assemble and direct cybercriminal
teams.
Figure 1.6 summarizes the motivations of common attackers and cyberterrorists. Starting from the bottom, which is the
lowest complexity of organization:
● Insider threats that come from employees who are not happy because of salary, position, tasks, or simply because they
have been fired. It also can come from jealous friends or classmates.
● Thrill-seekers who want to show to others (friends and colleagues) that they at the top of their field and can act on
anything.
● Hacktivists who are guided by ideology (politics and other) and who try to spread their points of view through fake news
and sabotage of web servers.
● Terrorist groups that are guided by ideological violence (in other words, anyone who does not agree with their believes
should pay).
● Cybercriminals, whose objective is profit.
● Government-sponsored: for economical and/or geopolitical reasons some (may be all but with different capacities) coun-
tries use their citizens or foreign cybercriminals to collect data to disclose industry secrets, to threaten or worse to attack
other countries.
1.4.3.1 Virus
Virus is the most known term of cyberattack. A virus is a program (often referred to as malicious code) that can link itself
to the executable files of a computer. It can replicate itself or modify the files to which it is attached and seek the other
programs appended to those files. It then infects other programs simultaneously.
Viruses in ICT inherited their name from biology. In biology, a virus infects a plant, an animal, or a human being and
compromises the health or the life of the infected host. The virus can spread quickly from host to another. In ICT, a virus
attacks digital assets to compromise their contents and can duplicate itself locally or via the network.
1.4.3.2 Worm
A worm is a self-replicating code that resides in the memory of an infected computer. Worm differs from a virus in the way
it is triggered. A worm is self-contained; i.e. it does not need to attach itself to another program. A worm is able to replicate
itself locally or send copies of itself to other machines. A worm triggers itself without relying on human actions.
1.4.3.3 Trojan
Trojan is a term derived from the ancient Greek story of the deceptive Trojan horse, which permitted the fall of the city of Troy.
Trojan is any malware, which misleads users about its true intents. Generally, Trojans are spread by some form of social engi-
neering (including emails, images, music, etc.). Therefore, a trojan may be embedded in a piece of code that actually does
something useful, but with a hidden malicious part, which is intended to perform compromising or destructive actions.
Trojans may allow attackers to access personal information of victims, such as passwords or IDs. They can delete files or
infect other devices connected to the network. Finally, they can create connections between infected system and the
attacker, to monitor some activities of infected devices (e.g. any captured image or keystroke on keyboard can be made
known to attackers).
1.4.3.4 Ransomware
Ransomware is a type of malware that threatens to publish victim’s data or perpetually blocks access to it unless a ransom
is paid. It is a means of performing ransom attacks.
Spyware aims to gather information about a person (e.g. his/her credit card or health file) or an organization (e.g. industrial
and business secrets) and sends such information to other entities, without the owner’s consent.
Adware is the contraction of ADvertizing softWARE. Today, multiple forms of advertising, over the internet, are used to
generate revenues to software and website developers. Developers provide free content (including games, movies,
courses, etc.), which are consumed daily by millions of users worldwide. Unfortunately, adware may become spyware;
i.e. some of free software and websites may include links, which are used to collect private data. Therefore, before click-
ing any link, be aware that, may be, somebody is collecting data about you somewhere.
1.4 Attacks 15
1.4.3.6 Botnet
Botnet is the contraction of roBOT NETwork. A botnet is a set of compromised computers or electronic devices used to
create and send spams or viruses or to flood a network or a server. Any equipment in a botnet is called bot. Trojans or other
malware variants are used to infect a large network of computers or devices. Then, all infected computers (which become
bots) are monitored remotely by a supervisor under the control of a single attacker or a group of cybercriminals. In general,
bots are not used to collect data from the infected computers; rather, they are used by cybercriminals to commit attacks,
such as DDoS or to monitor specific areas, using for example infected cameras.
Any device or computer connected to the internet may become a member of a botnet. Often, the bots consume few
resources (computation and bandwidth), because they operate very infrequently. Therefore, infected devices and com-
puters cannot be easily detected by legitimate users when they just observe their computers. Fortunately, most antiviruses
can help detect infected computers.
Keylogger also is referred to as keylogging or keyboard capturing. It is the action of recording keystrokes on a keyboard.
Using a keylogger, the attacker can know some of the actions the users is performing.
Screen scraper is a malicious code to record and collect contents displayed on monitors of victim users. Using a screen
scraper, the attacker can see exactly the content seen by a victim.
Web shell is a malicious code, which can be uploaded to a web server to allow remote access to the web server and manip-
ulate its service.
Exploit is a generic term to designate any piece of software or a sequence of commands that takes advantage of a vulnera-
bility to cause an unanticipated behavior to occur on a system.
Logic bomb is a generic term to designate any piece of code intentionally inserted into a software system that will initiate a
malicious function on the attacked system, when specified conditions are met.
Backdoor is a typically covert method of bypassing normal authentication or encryption in a system. Roughly speaking, there
exist two categories of backdoors; those installed by attackers using trojans or other methods and those installed by the
manufacturers of the software and hardware. In today’s international ICT business competition, backdoors raise much
disputes (e.g. between USA and China regarding 5G infrastructures). Regarding the second category of backdoors, the
question is how one can trust the manufacturers of the software and hardware components? Hard question to answer.
Rootkit is any collection of malicious software installed by an attacker on a computer. It is designed to enable access to some
components of the computer that are not otherwise allowed; and it often masks its existence. Rootkits include keystroke
logging and recording of other user activities. In general, rootkits provide partial or full access to infected computers.
● Install security updates on your computer as soon as possible after being notified.
● Use the up-to-date antivirus software.
● Update your software regularly (outdated software have vulnerabilities).
● Use software certified, or at least approved, by trusted parties.
● Any new installed device (e.g. a webcam or a home alarm) should be secured by changing the default password.
1.5 Countermeasures/Defenses
● Deter attacks by making them impossible (e.g. deploying a permanent and armed guard team in front of the entrance of
a bank deters almost all the thieves!)
● Deter attacks with an ingenious idea based on the use of resources imitating the resource to protect (i.e. lures) to draw
attackers’ attention. Fake systems used to deter attacks are often referred to as honeypots.
The cost of prevention methods may be high, which prevents their use. For example, a university cannot pay to have a
permanent guard in front of each lab and each classroom.
Detection methods: these methods are based on the ability to detect attacks when they occur. Intrusion detection systems
are commonly used as tools to detect attacks.
Reaction methods: it is the capability to deploy mitigation actions including recovery actions. For example, database
management systems store multiple copies of the DB and the list and dates of transactions. Whenever an attack is
detected, the stored data is used to recover the operational database. Depending on the attack, some of transactions may
be irretrievably lost. The mitigating actions aim at minimizing the data loss and unavailability.
Example 1.5 Let us take a simple example to see what security defense actions could be. The example is a simplified
version of e-shopping activities. The threat of interest in this example is: someone may steal your money.
– Prevention: multiple countermeasures are used in nowadays e-commerce: encrypt your order and card number, enforce
merchants to do some extra checks, use PIN and trusted tier (example banks), and do not send your card number in
cleartext via an insecure channel.
– Detection: be careful and check periodically your account to detect any unauthorized transaction appearing on your
credit card statement.
– Reaction: in the event of a fraud, notify your bank and complain, dispute and prosecute, ask for a new card number or
pay and forget (because you were not careful and you disclosed your data through social networks or by any other
channel; it is your mistake!).
● Secure-by-design approach: for a long time, application software developers and security components developers did not
collaborate; and the end-users buy and deploy applications and security components separately. Recently, both commu-
nities understood that IT security would be more efficient when they work in tandem. Consequently, application soft-
ware developers learn from security software developers and vice versa. Such a collaboration is more likely to dominate
in the future. It is more dynamic and efficient than secure-by-default approach. In secure-by-design approach, each com-
ponent of an application follows guidelines and methodology of vulnerability investigation. The security requirements
are taken into consideration throughout the life cycle of application development. For example, many OS functions
(such as gets or TCP socket use) have been identified as system vulnerabilities. Therefore, the application developer
should not use them, if he/she is not aware of their vulnerabilities.
Secure-by-design approach implies inclusion of security procedures in all the steps of software engineering (from
requirements specification to software maintenance). Secure-by-design does not mean that conventional security com-
ponents are no more useful. Rather, it means that in each step of software development, developers should 1) produce
attack resistant codes 2) determine which security components to use and which security components to include in the
system if they are not present. For more on security-by-design, refer [6, 26, 27].
Finally, remember what we mentioned regarding castle’s security. Castles were designed according to the secure-
by-design approach. Castle architects did not follow an orientation such as built smart, spacious, and all-round view
castles. They had important requirements from the king, which may be summarized in one requirement: the first concern
is to deter enemies.
● Contingency plans: define the procedures to resume normal operation for each attack likely to occur. Train people to do
local and remote (cloud) backups.
● Certification label: for some organizations (e.g. banking, cloud services, stock exchange, and e-commerce), which store
and manipulate client data, it is more and more required that those organizations should have provable high-level secu-
rity systems. To reassure their clients, those organizations must receive and explicitly show a certification regarding their
good security practices. There exist specialized companies, which provide security certification services.
Figure 1.8 illustrates the main defense systems to deal with intrusions (i.e. attacks) made easy by communication net-
works. They include firewalls, IDSs (Intrusion Detection Systems), IPSs (Intrusion Protection Systems), honeypots, prox-
ies, Network Address Translation (NAT), and VPNs (Virtual Private Networks). The ultimate objectives of defense systems
are to continuously monitor incoming/outgoing traffic in order to prevent and detect intrusions and to limit their impacts.
The main objectives and characteristics of those systems are briefly discussed in this section.
Definition 1.10 Intrusion detection: it is the process of monitoring the events occurring in a computer system or network
and analyzing them for signs of possible intrusions (incidents).
Definition 1.11 Intrusion prevention: it is the process of discarding any suspicious traffic to avoid intrusions.
Definition 1.12 Packet filtering: it is a method to inspect packets and to reject packets issued by untrusted hosts or users.
Definition 1.13 Content filtering: it is a method that allows blocking internal users from receiving some types of content.
In general, “Is a traffic an intrusion or not?” is a hard question. To address intrusions, some knowledge or assumptions
should be considered:
● System activities are observable (i.e. the defense systems should know the activities of the assets to protect);
● Attacker behavior is (sufficiently) different from legitimate user behavior. In other words, the actions of the attackers
should exhibit some signs to detect them. Is any person entering a shop is a thief? Definitely not. However, any armed
person entering a shop is very likely to be an attacker.
● In practice, there exist overlaps between legitimate and illegal actions:
– Some legitimate behavior may appear malicious. For example, when the number of requests per second entering a web
server is beyond a given limit, should we immediately conclude that there is a DoS attack?
– Intruders can attempt to disguise their behavior as that of legitimate users. For example, forged mails are very similar
to those sent by the bank of the victim or any other entity known to him/her.
● Asset owners should assess intrusion detection risks: what would be the risks if intrusions were not detected?
1.6.1 Firewalls
Firewalls are the most commonly used defense systems in IT security. Like security guards at the entrance of a building
and specific areas, firewalls monitor and control incoming and outgoing packets based on predetermined security rules. A
firewall provides a central choke point for all traffic entering and exiting the system. Therefore, it provides perimeter
defense, aiming the following:
Example 1.6 Below are examples of configuration rules (in a high-level language)
– Rule 1: remote host with name Zebra is denied any access and all its packets must be dropped.
– Rule 2: if local port is 25, then accept and forward packets.
– Rule 3: if local port is greater than 1024, then reject packets.
Anomaly-based approach. In this approach, the security administrator must first describe what is normal and what is
abnormal. There are multiple forms of anomaly-based detection depending on how normal and abnormal activities have
been described:
● Use of performance metrics (e.g. bandwidth utilization, frequency of requests, interval between remote logins, duration
of sessions, number of login failures) and thresholds associated with metrics.
● Use of the frequency of occurrence of specific events, within a specific period of time (e.g. activities during weekends).
● Use of traffic profile and deviation from a user-specific baseline.
● Sample network activity to compare to traffic that is known to be normal. When measured activity is outside baseline
parameters, IDS triggers an alert. For example, DoS results in abnormal bursts of packets received by the victim.
24 1 Introduction to Computer Security
Stateful protocol analysis approach. Any standard protocol follows a predefined order of actions. IDS can store the states of
a session running a protocol. Deviation of states of a session from the normal states of the used protocol may be considered
as intrusion. The basic example in this category is an IDS that checks how the segments received over a TCP connection
deviate from the normal operation of TCP. For example, when too many connections are opened without sending data and
these connections are not closed, there is a high probability of DoS attack.
1.6.5 Honeypots
One defense system of interest is honeypot. It is used in infrastructures requiring a high level of security. The basic principle
is to deploy (in parallel to assets to protect) fake assets to lure potential attackers. Instead of accessing genuine assets, the
attackers are deviated to fake assets that imitate the original ones. For example, make a copy of customer accounts with
fake data and lure the attackers to steal the fake copy. With the honeypot:
1.6 Overview of Defense Systems 25
Definition 1.15 Privacy: it refers to the ability of individuals to isolate themselves, or information about themselves, and
thereby express themselves selectively.
Definition 1.16 Data protection: it refers to legislation that is intended to protect the right to privacy of individuals and to
ensure that their personal data is used appropriately by organizations that may have it.
Definition 1.17 Data consent: it is any freely given, specific, informed, and unambiguous indication of the data owner’s
wishes by which he/she, by a statement or by a clear affirmative action, signifies agreement to the processing of personal data
relating to him/her.
Every day, each of us is receiving messages relating to commercial advertising he/she never asked for or worse he/she
receives threats regarding his/her privacy or ransom messages. In the same way, companies and institutions are attacked
via Internet. Consequently, citizens request protection laws to preserve their privacy and business. Roughly, protection
laws should clearly state:
● Who can use data of citizens?
● Who can store data and where data must be stored?
● How to file a complaint for damages?
Today’s picture of legislation may be seen at two levels:
● Protection inside a country: the protection is good to average depending on countries. National laws are applied when
the attacker and victim are in the same country and all the means used to deploy the attack are deployed entirely in the
same country. Federal (e.g. in USA), national (e.g. in France), or country union laws exist.
● Today’s laws for inter-countries protection are bad or even worse in some situations. There are multiple reasons, including
cultural, geostrategic, or competition reasons. Some attacks are considered as minor or meaningless if they occur in
other countries; and other attacks are encouraged by some hostile countries against others.
Notice that protecting private data in any country is required, but it is insufficient, because attackers can connect from
outside and mount their attacks. Therefore, worldwide collaboration is required. For more on privacy, refer to [7, 31].
The objectives of GDPR are to support rights of individuals, which include rights [32, 33]:
● to be informed
● to rectification
● of access
● of erasure
● to restrict processing
● to object to processing
● to data portability
● to be forgotten
The GDPR states (and clarifies) the responsibilities of data processors (i.e. any entities which store and/or process citizen
data). First, the GDPR provides guidelines to comply with GDPR (i.e. what should the data processors do to comply with
GDPR?). Second, the GDPR specifies, in general terms, the incurred penalties when the GDPR is violated: up to €20M or
4% of the global turnover for the preceding financial year in case of violation; national courts have responsibility to fix pen-
alties. It should be noticed that the compliance with GDPR has just started and it would take a long time to be fully
observed in Europe. GDPR defines notions useful to privacy protection, including concept of personal data, acts of
processing, data protection principles, and obligations of data processors. A brief presentation of the above concepts is
given below.
● Legitimate interest in the collected data; for example, a bank (which controls some of client data) has legitimate interest
to transmit client data (e.g. client phone numbers) to its partners (e.g. credit companies). The balance between citizen
rights and the business or interest to data processors is far from being clearly understood by concerned parties; much
effort remains to do.
● Integrity and confidentiality, which means processing data while ensuring appropriate security.
● Accountability, which means keeping necessary records to demonstrate compliance, when requested by citizens or by
courts.
It should be noticed that the principles above are hard to verify in practice, because:
● It is not easy for citizens with few skills in IT systems to understand the risks when they accept data collection.
● Is the data collector fully complying with the principles? Who can check the compliance with principles at a fine granu-
larity? Hard question to answer.
● Nowadays, there is an atmosphere of mistrust regarding current usages of IT technologies by companies, and worse by
governments. Citizens are watched and tracked in their daily life. Not all what is considered as conspiracy is wrong or
false. Much work remains to be done to reassure citizens.
This chapter provided an overview of IT security, which is a complex discipline, because of several reasons, including:
● The top issue is related to the malicious nature of human beings, which is limitless in terms of creativity.
● Users and managers are often unaware of the value of computing resources to decide which ones to protect. Frequently,
it is only when a confidential information is disclosed or destroyed that the owner becomes aware of its value. Example,
one may lose just an SMS, which would cause a disaster (in private life) some years later.
● Deploying a security architecture comes with a cost. Return on investment of security deployment is difficult to assess.
Therefore, users invest little. However, the way of addressing security investment is changing in recent years, because of
attacks that spread and affect all sectors; even hospitals have been blocked by cybercriminals requiring ransoms.
● Legal definitions are often vague or nonexistent in many countries. Therefore, legal prosecution is difficult even when
the attacker and the victim are in the same country. Legal prosecution becomes (nearly) impossible when the attacker is
hosted by an unfriendly state.
● Finally, from the technical point of view, many subtle technical issues to address and master, including protocols, algo-
rithms, infrastructures, and tools. Attack techniques are constantly changing and users and security managers have to
adapt all the time.
The objectives of this book are to address a fundamental field of security that is cryptography.
Exercise 1.1
List some good practices to prevent identity theft.
Exercise 1.2
Consider a shop owner and show why some CIA properties are required. The assets are products (e.g. electronic devices),
agreements with suppliers, client invoices, and cash register.
Exercise 1.3
Consider six assets: a medical file, a university website, an aircraft design document, home camera, a video-surveillance
camera in a city, and a camera in a ski station (that broadcasts pictures). Use a table and show which CIA properties are
required for each type of asset.
Exercise 1.4
Cite some threats against e-voting system.
30 1 Introduction to Computer Security
Exercise 1.5
Suggest actions of protection against ransomware attacks, virus infection, and spam attacks.
Exercise 1.6
You receive an email with the name of your bank as sender name. The message looks like a message from your bank,
which asks you to use a link in order to update your profile. The message may be genuine or fake. What do you do?
Exercise 1.7
Why DDoS attacks are (nearly) impossible to block?
Exercise 1.8
Somebody has subscribed to four free online magazines that belong to a unique company, but the subscribers do not
know the companies owning the magazines. To activate the subscription, the first magazine asked for the name, the
second asked for the birthday date, the third asked for the complete mailing address, and the fourth asked for the phone
number. What threat do you infer from this situation? How to prevent the identified threat?
Exercise 1.1
Below are some of good practices to prevent identity theft:
– Use well-constructed and unique password to access each server
– Avoid sharing confidential information on social networks
– Limit commercial transactions to known and trusted websites
– Install the latest versions of antiviruses
– Update your browser when you receive update notification
Exercise 1.2
Examples of requirements:
– Confidentiality: the content of the cash register is confidential; agreements (including prices of articles) with suppliers
are confidential.
– Integrity: the products on the shelves must not be damaged or altered by visitors or clients; customer invoices must not
be altered.
– Availability: no blockage of shop entrance to prevent business with customers; no blockage of the invoice-editing server.
Exercise 1.3
Exercise 1.4
The following are threats on an e-voting system:
– Preventing citizens to vote after a given hour
– Inclusion of votes of unregistered people
– Disclosing votes
– Double voting
– Tampering the results
– Blocking access to the results
References 31
Exercise 1.5
Below are some protection actions
– Against ransomware attacks: regular back up of critical data in safe location; set up backup computers and internet
connections.
– Against virus infection: be aware of any file download; run antivirus regularly.
– Against spams: verify the source of any message that asks to click on a link or to send private data; do not blindly trust
any email attachments.
Exercise 1.6
– First of all, banks do not, in general, ask their clients to provide personal data using links included in emails. Rather, they
ask clients to connect to their account (using credentials and codes) and then perform actions. Therefore, an email
including a link, and with a bank as sender, is very likely to be a spam.
– If you can call your bank, do it to know more about the received message.
– In the extended header of the email, you can see the original source IP address of the sender. Copy the IP address and use
an online IP address locator, which helps you to see on a map the location of the IP address, say location X. Compare
location X to one of the website of your bank. Often, the location of the original source IP address of an attacker is very
different from that of your bank. For example, the attacker is located in a Russian city, while your bank is located in
Spain. Be careful, some attackers may use a cloud server located in the same zone than that of your bank to send their
email.
Exercise 1.7
DDoS attacks are (nearly) impossible to block, because they do not exploit vulnerabilities of the victim; they do not install
a malware on the attacked system. The requests from the attacking hosts are similar to legitimate requests. The more
widely distributed is a DDoS attack, the more difficult it is to distinguish legitimate requests from those that are not. The
harmfulness power of DDoS attacks relies only on the number of requests and the number and locations of attacking hosts.
One solution would be to increase the local resources to absorb the traffic and wait until the storm ends. Another solution
would be to use secondary resources, unknown to the attacker, and activate them when DDoS attack on the primary
resources is detected.
Exercise 1.8
If the publishing company is malicious, it can combine the four data provided by the subscriber and then either sell them
(to whom may be interested in the provided profile) or worse use them for identity theft.
To prevent the threat above, never provide personal data when you feel it is not necessary or to entities, you do not
personally trust. In the considered scenario, there is no legitimate need for an online magazine to know the complete
mailing address, the phone number, and the birthday date.
Notes
References
Introduction to Cryptography
For millennia, human beings used multiple forms of cryptographic codes to protect their oral communications, entries of
castles, their messages (in particular between armies and their commanders), their money, etc. Therefore, cryptography
had existed very early in human history and civilizations, before the advent of computers.
Since the early times, Human beings were in need to communicate, share information, and communicate selectively.
These two needs gave rise to the art of message coding (i.e. encrypting) in such a way that only the intended people could
have access to the information.
Cryptography has been developed and improved over centuries; in particular for military and defense reasons (protec-
tion of military secrets and spying of enemies), then for industrial reasons (protection of industrial secrets), afterward for
securing the recent applications made possible thanks to the internet (e-banking, e-commerce, bitcoins, …), and ultimately
for protecting the privacy of electronic devices’ users.
In modern digitalized society, cryptography is the pillar of security. Cryptography is used to protect data while in transit
over unsecure channels and data on storage devices (i.e. USB devices, disks, etc.). Encryption is everywhere in the cyber-
space. Encrypting and signing are the most performed cryptographic operations. Cryptography secures websites and
makes electronic transmissions safe. In particular, public-key cryptography enables people (e.g. a client and a merchant),
who never met before, to securely communicate and trust each other. Cryptography is not only used over the internet, but
also in phones, television, cars, aircrafts, door locks, implants, and a variety of other devices. Without cryptography,
hackers could get into users’ emails, listen to their phone conversations, tap into their cable companies and acquire free
cable service, or break into their bank accounts.
As cryptographic algorithms protect sensitive data, they have been (and still they are) the target of attackers. Who can
imagine what would happen if suddenly the cryptographic techniques used in the cyberspace were to be broken?
In Chapter 1, we saw that confidentiality, integrity, non-repudiation, and authentication services are of paramount
importance for IT security. Cryptographic algorithms and protocols provide all those services. This chapter succinctly
introduces the terminology, notions, algorithms, and attacks relating to cryptography, which will be addressed in more
detail in the subsequent chapters.
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
34 2 Introduction to Cryptography
concept of polyalphabetic ciphers, which are harder to break than Caesar’s cipher. Vigenere’s cipher is presented in more
detail in Section 4.4.
Jefferson’s wheel cipher. In the late 1700s, Thomas Jefferson came up with a cipher system similar to that of Vigenere,
but with higher security, because it has much more combinations to select keys. As illustrated by Figure 2.3, Jefferson’s
cylinder is composed of 36 disks (or wells), stacked on top of each other around an axle. The 26 Latin letters are randomly
inscribed on each disk. The disks are numbered; they are removable and can be mounted on the axle in any desired order.
The order of disk mounting represents the secret key. Both the sender and receiver of a message had to mount the disks in
the same way.
The message to encrypt is split into 36-letter fragments. To encrypt a 36-letter fragment, the sender rotates each disk, so
that the fragment appears on a horizontal row parallel to the rotation axis. Then, he/she chooses any row parallel to the
plaintext row and sends it as ciphertext. Upon reception of a ciphertext, the recipient rotates the disks so that the ciphertext
appears on a horizontal row parallel to the rotation axis; then, looks for the row, which contains the plaintext. There is a
very low probability that the recipient keeps a row, which does not correspond to the correct plaintext. Jefferson’s wheel
cipher may be considered as the ancestor of the Enigma machine presented below.
Enigma machine. The Enigma machine, invented during World War I and improved during World War II, was mainly
used by the army of the third Reich. Enigma is one of the first electromechanical devices used for encryption and decryp-
tion; and the most used in practice at that time. It is a very sophisticated version of Jefferson’s cylinder. Enigma was very
hard to break; but Alan Turing did it. Enigma machine is presented in more detail in Section 4.5.
Vernam’s cipher. In 1917, the one-time pad (OTP) cipher was (re)invented by Gilbert Vernam and patented in the US. OTP
cannot be cracked, because a single-use random key is required for each message, and the key must be at least of the same
bit-length than that of the message to encrypt. Vernam’s cipher was a cipher that combined a message with a key read from a
paper tape or pad; hence, the word pad in the name of the cipher. OTP was used in limited number of applications, including
military applications, because a new key is required for each message. OTP is discussed in more detail in Section 4.6.
Modern cryptography. Much progress has been achieved since the early 1970s and many cryptographic algorithms
were proposed; they are discussed in this book. From our point of view, the following six steps are the most prominent in
the modern cryptography:
● In the early 1970s, IBM developed Lucifer cipher, which became the Data Encryption Standard (DES) in 1976.
● In 1976, Whitfield Diffie and Martin Hellman introduced the principle of public-key cryptography.
● In 1977, Ronald Rivest, Adi Shamir, and Leonard Adleman came up with the RSA algorithm.
● In 1987, Neal Koblitz proposed elliptic curves to design public-key ciphers.
● In 1995, the first Secure Hash Algorithm (SHA1) was approved by the NIST.
● In 1998, Joan Daemen and Vincent Rijmen came up with the symmetric cipher Rijndael, which became AES in 2001.
Note. [5] is an excellent book for readers who are interested in the history of cryptography.
Definition 2.6 Decryption algorithm: it is the process of transforming a ciphertext into a plaintext; i.e. it is the reverse pro-
cess of encryption.
Definition 2.7 Encryption key: it is a secret value that is known to the sender.
Definition 2.8 Decryption key: it is a value that is known to the receiver. The decryption key is related to the encryption key,
but it is not always identical to it.
Definition 2.9 Cipher (also called encryption system): encryption and decryption algorithms form together a cipher.
The second advantage is that symmetric keys are shorter in length for the same security strength. The key length may be
an important consideration, if memory for storing the keys or the bandwidth for transporting the keys are limited. In
addition, advances in cryptanalysis and computational efficiency have tended to reduce the level of protection provided by
public-key cryptography more rapidly than that provided by symmetric-key cryptography. The third advantage of symmet-
ric-key algorithms is that they are based on simple bit operations (substitution, XORing, shifting, swapping), while public-
key algorithms are based on mathematical notions (modular arithmetic and operations over finite fields). In the next
chapter, we introduce the useful theorems and facts before going in depth in cryptography. Public-key cryptography has,
at least, two advantages compared to symmetric cryptography:
1) Increased security of private keys: unlike symmetric cryptosystems, the private keys never need to be transmitted or
shared with anyone, when public-key cryptosystems are used.
2) Asymmetric cryptography provides digital signatures, so that authentication of message can be assured. In addition,
using digital certificates and signature provides non-repudiation assurance.
In operational security systems, symmetric and asymmetric algorithms are combined to provide performant security ser-
vices. Roughly, public-key algorithms are used to generate shared session keys, to sign messages and verify signatures, and
to authenticate users, while symmetric-key algorithms are used to encrypt and decrypt messages using shared session keys.
– Any hash function H is a one-way function, because given a, it is easy to compute t , such that H (a) = t , while given t ,
it is not easy to find a, such that H (a) = t .
Definition 2.11 Trapdoor function: it is a one-way function for which the inverse direction is easy if some useful
information is known, but difficult otherwise.
Generally, public-key cryptosystems are based on trapdoor functions. The public key gives information about the
particular instance of the function; and the private key gives information about the trapdoor. Anyone who knows the
trapdoor can compute the function easily in both directions, but anyone who does not know the trapdoor can only easily
perform the function in the forward direction. In public-key cryptosystems, the forward direction (i.e. the public key) is
used for encryption and signature verification; the inverse direction (i.e. the private key) is used for decryption and signa-
ture generation.
Note. Public-key cryptosystems used in practice are based on functions that are believed to be one-way. However, no
function has been mathematically proven to be so.
Primitives
Confidentiality Yes No No No
Integrity No No4 Yes Yes
Availability No No No No
Message authentication No No Yes Yes
Entity authentication No No No Yes
Non-repudiation No No No Yes
2.2.1 Encryption
The main objective of encryption primitives is to assure confidentiality. Scrambling data makes it unusable (i.e. looks
like a noise) by those who do not know the decryption key. There exist two families of symmetric ciphers: block and
stream ciphers.
● Stream ciphers are encryption algorithms that apply encryption algorithms on a bit-by-bit basis (one bit at a time) to
plaintext using a keystream. If P is the plaintext and S is the keystream (of the same length than the plaintext), then the
ciphertext C is defined by C = P ⊕ S , where ⊕ is the bitwise XOR operator. Inversely, P = C ⊕ S . Therefore, encryption
and decryption are identical operations. In general, stream ciphers are by far faster than block ciphers.
● Block ciphers are encryption algorithms that encrypt/decrypt plaintexts of a fixed size (e.g. 128 bits), called blocks. The
encryption (or decryption) operation works in the form of a series of sequential rounds. Each round makes use of substi-
tutions and permutations of fragments of its input (initial plaintext, secret key, and output of the preceding round). In
general, the decryption operation performs substitutions and permutations operations in the inverse order of encryption.
Two of the most known and used blocks ciphers are DES and AES. To encrypt plaintexts longer than a single block,
modes of operation are used to split a plaintext into blocks, and then call the block cipher to encrypt each block. Blocks
of ciphertext and plaintext may be combined to prevent some attacks.
The main public-key encryption algorithms include RSA, ElGamal, and ECIES (Elliptic Curve Integrated Encryption
Scheme) cryptosystems.
● Algorithms that rely on hash functions and a key; that is why they are called hash MAC (or HMAC) or keyed-hash
functions. The data and the key are hashed together to produce a MAC, which is then stored or transmitted with
data.
● Algorithms based on stream ciphers, where the final state of internal cipher registers contain the MAC.
● Algorithms based on block ciphers, where data is encrypted block by block and the ciphertext of each block is used to
encrypt the next block. The encryption of the final block represents the MAC.
The sender generates a MAC using data to protect and a key shared with the recipient. At reception of a pair (data, MAC),
the recipient computes a MAC using the received data and the shared key and then compares it to the received MAC. If
both are equal, the recipient concludes that the received data has not been altered (i.e. integrity verification) and it has been
sent by an entity that shares the secret key (i.e. source authentication).
Definition 2.13 Digital signature: it is a message hash encrypted with a private key; and used to authenticate the message
source.
As illustrated by Figure 2.9, a digital signature is obtained as follows: the data to sign is hashed to yield a tag, then the tag
is encrypted with the private key of the signer; the signed tag is called digital signature. When a message-signature pair is
received, the recipient computes a tag H of the received data, decrypts the received signature, and obtains a tag H ′. If both
tags are identical, the recipient concludes that the data was signed by the entity owning the private key associated with the
used public key and the message was not altered in transit. In the event the data or the signature is altered, the authentica-
tion fails. Therefore, digital signature provides assurance regarding the message integrity as well as the authenticity of
message.
Both digital and handwritten signatures rely on the fact that it is very hard to find two people with the same signature.
While the handwritten signature is the same on all the signed documents, a distinct digital signature is associated with
each signed message. Handwritten signatures can be reproduced (mimicked), which results in fraudulent documents.
Unlike handwritten signatures, digital signatures are very unlikely to be mimicked. Therefore, they are considered as fool-
proof. In addition, handwritten signatures do not protect the integrity of a signed document (the fraudster can change a
picture, words or letters, while keeping the authentic signature), while any alteration of the original data results in an
invalid signature.
42 2 Introduction to Cryptography
Definition 2.14 Digital certificate or public-key certificate: it is an electronic document used to prove the ownership of a
public key.
Public-key cryptosystems have one primary challenge; the recipient of a signed message needs to trust that the public key
that he/she/it is using to authenticate the message is really owned by the entity who signed the message and not stolen
by a malicious adversary. The trust can be established using digital certificate. The latter is an electronic document
signed by using the private key of a trusted authority, called Certificate authority, to certify that the name of the entity on
the certificate owns the public key included in the certificate. A digital certificate functions like a physical certificate, such
as a passport delivered by an administrative authority. Two entities (individuals or organizations) with distinct names and
IP addresses cannot have the same certificate.
Digital certificates are used in the cyberspace to prevent malicious entities (individuals or organizations) impersonate
others and receive sensitive data or send fake data to their target. They allow verification of the claim that a specific public key
does in fact belong to a specific individual or organization. To verify a signature included in a message, the recipient requests
the signer to send his/her/its certificate. Then, he/she/it makes use of the public key in the certificate to verify the signature.
In addition to data integrity and message authentication, digital certificates provide a second service, which is of prime
importance for electronic transactions (e-shopping, e-banking, e-voting, etc.). It is non-repudiation assurance. Since it is
assumed that only the entity owning a key-pair (private and public) can sign using his/her/its private key, he/she/it can
only create unique signature on a given data. Thus, the recipient can present data and the digital signature to a third party
as evidence if any dispute arises in the future. The legitimate signer cannot deny having signed the message.
specific operations, such as hashing, and then truncates the hash function result to yield a key. This issue is addressed in
detail in Chapter 14.
transactions or personal communications) have a format known to attackers, who can infer, using traffic analysis,
information that could help breaking the encryption algorithm. Therefore, the security of cryptographic algorithms is
based on probabilistic approach; and not on a formal proof.
In practice, given a cryptographic algorithm and a set of talented cryptanalysts, if none of them can break it after a long
time, using reasonable computation resources, users of the algorithm can reasonably assume that it is secure. After the
publication of a weakness that resulted in breaking (partially5 or totally) an algorithm, the use of the algorithm should be
stopped as soon as possible.
One of the best citations regarding proof of security was stated by Brice Schneier, who wrote, “Anyone, from the most
clueless amateur to the best cryptographer, can create an algorithm that himself can’t break. It’s not even hard. What is hard is
creating an algorithm that no one else can break, even after years of analysis. And the only way to prove that is to subject the
algorithm to years of analysis by the best cryptographer around” [6].
The lifetime cycle of a cryptographic algorithm may be summarized in four steps:
1) A talented cryptograph publishes a new algorithm, either spontaneously or to participate to a call6 for new algorithms.
He/she believes that the algorithm is secure. Publishing a new cryptographic algorithm is understood as a challenge for
cryptanalysts, as try to break my algorithm. Sometimes, organizations, such as the NIST, publish security challenges,
with rewards for those who succeed in breaking the algorithms.
2) Worldwide talented cryptanalysts deeply analyze the robustness of the published algorithm regarding known attacks.
3) When a weakness is discovered by cryptanalysts, the algorithm is updated as soon as possible; and a new version is
published.
4) If the discovered weakness is critical (i.e. no cure exists without deeply redesigning the algorithm), the algorithm is
deprecated.
An encryption scheme over plaintext space M has the perfect secrecy property, if for every probability distribution over
M, every message m∈M, and every ciphertext c∈ C, for which Pr C = c > 0,
Pr M = m | C = c = Pr M = m (2.1)
where M and C are random variables associated with plaintext and ciphertext, respectively.
Example 2.2 Consider the Caesar’s cipher, where 26 keys (from 0 to 25) can be used equally (i.e. with a probability of
1/26) to encrypt one letter of the Latin alphabet. Each plaintext letter is encrypted with a key randomly selected. Observing
a ciphertext of one letter does not provide any information about the encrypted letter. Therefore, the cipher has the perfect
secrecy property.
Perfect forward secrecy (PFS) property: a cryptosystem is said to have the PFS property, if the compromise of long-term keys
does not allow an attacker to obtain past session keys. In other words, PFS property protects past sessions against future
compromises of long-term keys. In addition, by generating a unique session key for every session initiated by a party, the
compromise of a single session key will not affect any data other than that exchanged in the specific session protected by
that particular session key.
We will see in Chapter 14 that Diffie-Hellman exchange protocol and its variants have the PFS property.
Example 2.3 At time t, a client and a server make use of the following protocol to agree on a session key. The client sends
its public key to the server. The latter computes a session key, encrypts it using the client public key, and sends it to the
2.4 Attacks Against Cryptographic Algorithms 45
client, over an unsecure channel. No other entity, with the exception of the client, can read the session key. Next, parties
exchange messages encrypted using the session key and terminate the session. An attacker listening to the channel, copies
all the encrypted messages, but he/she cannot decrypt them. Sometime later (may be after months), the same attacker
recovers the public key of the client. He/she decrypts the message containing the encrypted session key, and then discloses
all the messages he/she intercepted some time ago. The key agreement protocol above has not the PFS property. That is, a
compromise of the long-term public-key of the client results in disclosing ciphertexts sent in the past.
In Chapter 1, we presented cyberattacks, including phishing, spam, DDoS, and ransoming. Those attacks mainly aim to
collect sensitive and personal data, block system access, threaten private life, and demand ransoms. Most of those attacks
exploit vulnerabilities due to naivety, recklessness, and greed of users, weaknesses of operating systems, and broadcasting
and dissemination capacities provided by networks. They are launched by cybercriminals who, in general, are not cryptan-
alysts. Attacks discussed in this section address weaknesses of cryptographic algorithms; they mainly aim:
● To disclose one or several plaintexts associated with known ciphertexts.
● To forge a tag or a signature without knowledge of the secret key.
● To recover the secret key (used to encrypt, to compute MAC, or to sign).
● To infer a partial internal state of a cipher (e.g. a key round used in block cipher or a fragment of keystream of a stream
cipher).
Malleability is the ability to transform a ciphertext into a different ciphertext that will produce a new and different plaintext
when decrypted in the recipient side. It also is the ability to transform a data, while keeping the same tag or signature, so
that the recipient will consider the data authentic, while it is not. Malleability is generally an undesirable property. For
example, a bit-flipping attack takes advantage of the malleability of stream ciphers.
Attacks against cryptographic algorithms are designed and performed by cryptanalysts. They take advantage of the
design weaknesses of algorithms, their implementation, and/or their usages. In particular, social networks are used by
attackers to infer some useful information regarding targeted individuals (or organizations). For example, from discussions
between individuals, attackers may infer some parts of encrypted plaintexts (infer names, greetings, and discussion topics)
and then use the inferred knowledge to disclose more information about targeted individuals.
Figure 2.10 summarizes the common attacks on cryptographic algorithms. In the following chapters, we only focus on
cryptanalysis attacks.
Note. Cryptanalysis is not always a malicious activity. Indeed, all the standard cryptographic algorithms currently in use
have been improved and secured due to the valuable involvement of cryptanalysts worldwide.
Ciphertext-only attack (COA): in this type of attack, the adversary has access to a subset or all ciphertexts; but, he/she
has no access to plaintexts. The attacker tries to disclose some or all plaintexts from known ciphertexts or to recover the
encryption key. COA is the easiest attack to mount in practice, because ciphertexts can be collected easily when wireless
communications are used. However, COA alone is very unlikely to succeed, because the attacker lacks useful information
on plaintexts.
Known-plaintext attack (KPA): in this attack type, the adversary has access to limited number of pairs of plaintexts and
the corresponding ciphertexts. The KPA aims to recover the key. For example, spies can collect plaintext–ciphertext pairs
and try to recover the key in order to disclose other plaintexts. Different methods (such as linear cryptanalysis) can be used
to guide the key search.
Chosen-plaintext attack (CPA): in general, this attack type is used to identify the vulnerabilities of an algorithm. CPA
assumes that the adversary has access to a black box (called oracle) which implements or emulates the algorithm to be
analyzed. The attacker randomly chooses some plaintexts and queries the oracle to process the plaintexts. The returned
result may be a ciphertext or signature, depending on the algorithm. Then, the adversary makes use of the collected plain-
text–ciphertext pairs or data–tag pairs in order to recover the key or to generate message tags without knowing the key
(so that a forged message–tag pair is validated by the recipient, which compromises the security of the authentication
service). The adaptive CPA is a specific variant of the generic CPA, where the adversary selects the subsequent plaintexts
to be processed by the oracle, depending on what has been learned from the previous queries. Examples of adaptive CPA
are discussed in Chapter 10.
Chosen-ciphertext attack (CCA): like CPA, this attack type is used to identify vulnerabilities of a cryptographic algorithm.
CCA assumes that the adversary has access to an oracle, which implements or emulates the algorithm to be analyzed. The
attacker randomly chooses some ciphertexts or message tags and queries the oracle to process them. The returned result
may be plaintexts or a signature validation results (i.e. the input tags are valid with regard to the provided messages),
depending on the algorithm. Then, the adversary makes use of the collected plaintext–ciphertext pairs or data–tag pairs in
order to recover the key or to generate message tags without knowing the key. The adaptive CCA is a specific variant of the
generic CCA, where the adversary selects the subsequent ciphertexts or data–tag pairs to be processed by the oracle,
depending on what has been learned from the previous queries.
Related-key attack: in this attack type, it is assumed that the adversary has access to a set of ciphertexts produced for the
same plaintext, using two or several unknown keys (e.g. the attacker intercepted the traffic generated in several sessions;
and in each session, a new key is used to encrypt a subset of plaintexts known to the adversary). In addition, the adversary
knows that the keys have some mathematical relationships (for example, keys are generated with the same pseudorandom
number generator,7 which is initialized one time for all the sessions; or more naïvely, the session keys are generated with
a linear function, i.e. K i = f ( K i−1 ) , where f is a linear function). The adversary tries to infer the key currently in use from
the known plaintext–ciphertext pairs and relationships between keys. Notice that related-key attack is unrealistic against
commonly used algorithms, mainly because key generation does not yield keys that have linear relationships.
Birthday attack: it refers to the birthday paradox (see Section 3.4), which states that given a group of persons, if one
picks randomly 1.18 * 365 ≈ 23 persons, the probability to have two persons with the same birthday date is close to ½.
Intuitively, one may think that more persons are required to get two individuals with the same birthday date at a prob-
ability of ½. In cryptanalysis, birthday attack is a variant of brute-force technique, which is mainly used against hash
functions and signature algorithms. For example, given a 128-bit signature algorithm, when the attacker knows a sig-
nature S for a message M, he/she can find, with a probability of ½, another message M ′, among 264 messages, distinct
from M, such that M and M’ have the same signature S. Then, he/she can send a signed message, which will be vali-
dated by the recipient, while the message has never been signed by a legitimate user. Brute-force attack requires trying
in average 2127 messages, while birthday attack requires 2128 = 264 , which results in a significant reduction of the
search space.
Meet-in-the-middle attack: it is another variant of brute-force attack, which drastically reduces the effort to perform a
brute-force attack. It is a compromise (hence the term meet in the middle) between memory space and computation time.
For example, a brute-force attack that requires 2192 time can be reduced to 296 time and 296 memory space. We’ll see in
Section 7.2.3.3 how the meet-in the middle attack was used to break block ciphers. Notice that meet-in-the-middle attack
has no similarity with man-in-the-middle attack.
Man-in-the-middle attack: it is one of the most known attacks, which targets mainly public-key algorithms. In this attack,
it is assumed that the attacker can intercept and modify messages exchanged between two legitimate users. Such an
assumption is realistic in wireless networks and when the attacker can take control of routers. To illustrate how the attack
works, consider the following scenario: a user A wants to receive encrypted messages from user B (see Figure 2.11). User A
sends his/her public key to B. The attacker intercepts A’s public key and instead sends his/her public key to B. Upon recep-
tion of a public key, user B is misled, thinking he/she is communicating with user A. User B encrypts messages with
attacker’s public key, and not with that of A. The attacker intercepts and reads any message sent to A; and can encrypt the
received plaintexts using A’s public key and send them to A or alternatively, he/she can relay fake messages. Notice that
digital certificates, when available, prevent the attack above, because the attacker cannot modify the certificate of A to
include his/her public key.
Dictionary attacks: there exist many variants referred to as dictionary attacks, among which:
● Build a list of passwords that are likely to be used by the target. Then, try one by one the selected passwords to log into
the attacked system.
● Build a table (also called dictionary), which contains all the pairs of plaintext–ciphertext learned over a long period.
Then, for each intercepted ciphertext, search in the table the corresponding plaintext. This attack is efficient when the
vocabulary of plaintexts is limited.
● Build a subset of the key space composed of the keys that are the most likely to be used by the attacked entity. Then, for
each intercepted ciphertext, try each key in the subset to recover the correct key. The probability of success depends on
how the key subset is selected.
Replay attack: it is a variant of man-in-the-middle attack, where
the attacker intercepts messages sent to the victim. Then, he/she
resends some or all messages to the victim, in such a way that the
victim receives multiple copies of some fragments of the original
traffic, which results in undertaking inconsistent actions, thus
compromising integrity. Imagine that the attacker knows an
intercepted message, which corresponds to money transfer to
his/her account. He/she can resend several times the same mes-
sage to the bank to have his/her account credited multiple times.
Fortunately, protocols used by banks are resistant to replay
attacks; they use techniques such as assigning a unique number
(such as a timestamp) to each transaction.
Bit-flipping attack: it is an attack against stream ciphers in
which the attacker changes one or several bits in the cipher-
text, at specific positions, in such a way that the plaintext
changes at the same positions. The attacker cannot control the
resulting plaintext, if he/she does not know the original plain-
Figure 2.11 Illustration of Man-in-the-middle attack. text format. However, if he/she knows the message format and
2.4 Attacks Against Cryptographic Algorithms 49
the content of the bits to change, he/she can control the modified plaintext, because the ciphertext in stream ciphers is
yielded by XORing the plaintext with the key. For example, if the attacker knows the format of a bank transaction,
which contains the value 50 in bits at positions 100 to 120, he/she can change the value to 50+1024. Another example
is discussed in Problem 4.9.
Frequency analysis: it is an attack particularly efficient when the attacker tries to disclose ciphertexts corresponding to
texts in a natural language. The attacker exploits the frequency of letters in texts, the frequency of the first letter in words,
the repetitions of words and spaces in texts; all these features differ from a language to another. For example, Table 2.2
shows the relative frequency of letters in English texts. When the same letter is always mapped to the same code, the
attacker can compute the frequency of each code in the ciphertext, and then assumes that the code with the highest fre-
quency is space, then the next is letter E, etc. In World War II, this technique (partially) helped to disclose some messages
encrypted with the Enigma machine.
additions) exhibit different power profiles. In addition, when transferring data from a memory to CPU, the ratio of 1s vs 0s
is reflected in the power profile. Therefore, the attacker can infer what type of function is being performed at any given
time and what data pattern is being transferred or processed. Devices protected against simple PA create noise (by
performing random computations) to avoid collecting the correct physical traces. Differential PA is a statistical method for
analyzing power consumption to identify data-dependent correlations in order to improve the quality of information
inferred by the attacker. It is more difficult to thwart than simple PA.
Electromagnetic emission attacks: these attacks exploit the electromagnetic radiations emitted by the attacked device,
while running cryptographic code. Codes and their execution are characterized by electromagnetic radiation emission pro-
files. From the electromagnetic emission traces, the attacker can infer useful information on attacked device.
Temperature attacks: these attacks exploit the observed temperatures of the attacked device, while running cryptographic
code. Codes and their execution are characterized by temperature profiles. From the temperature traces, the attacker can
infer useful information on attacked device.
2.5 Steganography
The last section is a brief overview of steganography, which is another complex and ingenious category of techniques to hide
contents. Unlike cryptography where intruders are aware that sensitive data is being communicated, because they can see the
scrambled messages, in steganography, an unintended recipient or an intruder is unaware of the fact that observed data or
message contains hidden information. With steganography, people not only want to protect the secrecy of an information by
concealing it, but they also want to make sure any unauthorized person gets no evidence that the information even exists.
Steganography may be defined as the art and techniques of information hiding in other contents, referred to as con-
tainers. It existed before the advent of computers. Containers used by steganography may be texts, images, videos, audio
files, etc. Since the early 2000s, steganography is used by spying and security agencies and by terrorists to disseminate mes-
sages through the internet. Before discussing some examples, it is worth noticing the limitations of steganography:
● Steganography results in a high overhead, because hiding a secret at an undetectable position in a container is not easy;
and it requires time for the receiver to retrieve the hidden secret.
● Steganography requires some genius of concealment for both parties, the sender and the receiver of a content.
Steganography applications are easy to understand once explained, but they are (very) difficult to design.
● Steganography looks like a symmetric cipher. Therefore, the sender and recipient must agree on the container to use and
locations to retrieve the hidden secret.
First version:
President’s embargo ruling should have immediate notice. Grave situation affecting
international law. Statement foreshadows ruin of many neutrals. Yellow journals uni-
fying national excitement immensely.
Second version:
Apparently, neutral’s protest is thoroughly discounted and ignored. Isman hard hit.
Blockade issue affects pretext for embargo on by-products, ejecting suets and veg-
etable oils.
Tacking the first letter (in first message) or second letter (in second message), the following message emerges: Pershing
sails from NY June I. (Pershing was the name of a warship of US.)
The second example is to hide secrets in paintings. The technique consists of hiding letters in trees, people’s hair, flowers,
etc. Then, by retrieving and grouping the letters, texts are discovered.
other details. Some hours after posting the content, crackers published on social networks, a message to explain how white
house services have included call-for-hackers. The included secret was in an HTML comment line and says: <!-- If
you're reading this, we need your help building back better >. The lesson to learn from this
example is that comment lines in a code (of any programming language) may be used to hide secrets without affecting the
code itself. This form of steganography is the easiest technique to hide secrets, which can reach not only a single person,
but also a wider public in a country or worldwide.
The last example is related to the terrorist attack of September 11, 2001. Many people claim that the terrorist attack was
planned using steganography over Internet. On February 5, 2001, USA Today reported the following: “Lately, al-Qaeda
operatives have been sending hundreds of encrypted messages that have been hidden in files on digital photographs on the
auction site eBay.com.” The lesson to be learned from this example is that banal web pages can serve as vectors for the dis-
semination of messages, thus escaping security agencies that can break ciphers with very large keys.
Exercise 2.1
How many distinct keys can be generated?
– using five distinct Latin letters
– using five Latin letters
– using 10 decimal digits
Exercise 2.2
What is the primary difference between Meet-in-the-middle and Man-in-the-middle attacks?
Exercise 2.3
Explain why a cipher designed according to Kerckhoffs’s principle is very likely to be stronger than one that does not follow
the same principle.
Exercise 2.4
What is the main drawback of One-time pad cipher?
Exercise 2.5
How computational security differs from unconditional security? Which one is realistic when we consider existing crypto-
graphic algorithms?
Exercise 2.6
Assuming that an attacker can test, per second, 220 keys of a bit-length of 50. How long would a brute-force attack take?
Problem 2.1
Consider the following cryptosystem:
Plaintext space: M = {a, b, c}
Ciphertext space: C = {1, 2, 3}
Key space: K = {k1 , k2 , k3 }
With the following probability distributions:
– Probability distribution of plaintexts: Pr M = a = 1 / 2 , Pr M = b = 1 / 3, Pr M = c = 1 / 6
– Probability distribution of keys: Pr K = ki = 1 / 3 , for i ∈ {1, 2, 3}.
The encryption matrix is as follows:
a b c
k1 3 2 1
k2 1 3 2
k3 2 1 3
Does the cryptosystem as defined above satisfy the perfect secrecy condition?
2.6 Exercises and Problems 53
Problem 2.2
Consider the following cryptosystem:
Plaintext space: M = {a, b, c}
Ciphertext space: C = {1, 2, 3, 4}
Key space: K = {k1 , k2 , k3 }
With the following distributions:
– Probability distribution of plaintexts: Pr M = a = 1 / 2 , Pr M = b = 1 / 3, Pr M = c = 1 / 6.
– Probability distribution of keys: Pr K = ki = 1 / 3 , for i ∈ {1, 2, 3}.
The encryption matrix is as follows:
a b c
k1 1 2 3
k2 2 3 4
k3 3 4 1
Does the cryptosystem as defined above satisfy the perfect secrecy condition?
Problem 2.3
Consider the following cryptosystem:
Plaintext space: M = {0, 1, 2}
Ciphertext space: C = {0, 1, 2}
Key space: K = {k1 , k2 , k3 , k4 }
With the following distributions:
– Probability distribution of plaintexts: Pr M = 0 = 1 / 3, Pr M = 1 = 1 / 4 , Pr M = 2 = 5 / 12
– Probability distribution of keys: Pr K = ki = 1 / 4 for i∈ {1, 2, 3, 4}.
The encryption operation is defined by Ek (m) = 2m + i mod 3, for m ∈ {0,1, 2} and i∈ {1, 2, 3, 4}.
i
Does the cryptosystem as defined above satisfy the perfect secrecy condition?
Problem 2.4
Prove that One-time pad cipher satisfies the perfect secrecy condition. Assume that all plaintexts and ciphertexts have the
same probability distribution of 2−n , where n denotes the bit-length of plaintext (or ciphertext). Also assume that each
plaintext is encrypted using a distinct 2n-bit key.
Problem 2.5
Consider a cryptosystem where messages of two Latin letters are encrypted using Caesar’s cipher; both letters of a message
are encrypted with the same key. Prove that the cryptosystem does not satisfy the perfect secrecy condition. Assume that
all letters and all keys (0 to 25) have the same probability distribution.
Exercise 2.1
– 26 * 25 * 24 * 23 * 22 keys can be generated using five distinct letters.
– 265 keys can be generated using five letters.
– 1010 keys can be generated using 10 decimal digits.
Exercise 2.2
The primary difference between Man-in-the-middle and Meet-in-the-middle attacks is that the first one is interactive (i.e.
the attacker participates online in the communication), while the second one is not (i.e. the attacker collects some plain-
text–ciphertext pairs, prepares some encryption or decryption operations, and stores them in memory, and then tries a set
of keys to disclose the correct one).
Exercise 2.3
Kerckhoffs’s principle states that “a cryptosystem should be secure even if everything about the system, with the exception
of the key, is public knowledge.” This means that the only secret that the adversary can discover is the key. If the design of
54 2 Introduction to Cryptography
a cipher does not fulfill Kerckhoffs’s principle, it means that some design features (e.g. computation formulas, constants,
format of data) are hidden because they increase the security of the cipher. Therefore, the cipher has multiple points of
weaknesses, and discovering each point provides more information to the attacker to break the cipher. In addition, when
the design of a cipher is public, the honest cryptanalysts may participate in its analysis and then address any discovered
weakness to make the cipher stronger. However, when the internal design of a cipher is hidden, only malicious cryptana-
lysts may be interested in breaking the cipher and disclose sensitive data.
Exercise 2.4
The main drawback of OTP cipher is that it is impractical when a huge number of messages are to be encrypted. Each mes-
sage requires to use a distinct key, which is communicated to the recipient before sending the encrypted message.
Exercise 2.5
Unconditional security means that whatever the resources used by adversaries, the cryptographic algorithm cannot be
broken, while computational security means that the code cannot be broken, assuming that the adversaries make use of
limited and reasonable resources. All existing cryptographic algorithms used in practice are (assumed to be) computation-
ally secure.
Exercise 2.6
230
The key space has 250 elements. The time required to test all keys is 250 / 220 seconds. ≈ 34 years.
60 * 60 * 24 * 365
Problem 2.1
In general, given the plaintext probability distribution (i.e. Pr M = m is known for each m ∈ M ), the probability distribu-
tion of a ciphertext c ∈ C yielded by any key k ∈ K using a plaintext space M is defined by:
Pr C = c = ∑ ( Pr K = k * Pr M = Dk (c ) )
k ∈K
where M , C , and K denote the plaintext, ciphertext, and key spaces, respectively; M, C, and K denote the random variables
associated with plaintext, ciphertext, and key, respectively. Dk (c ) denotes the decryption of ciphertext c using the key k.
Compute the probability distribution of the ciphertexts:
1 1 1 1
* *
Pr M = b | C = 3 = 3 3 =1 Pr M = c | C = 1 = 6 3 =
1
1 3 1 6
3 3
1 1 1 1
* 1 * 1
Pr M = c | C = 2 = 6 3 = Pr M = c | C = 3 = 6 3 = .
1 6 1 6
3 3
1 1 1 1 2
Pr C = 1 = * + * =
3 2 3 6 9
1 1 1 1 5
Pr C = 2 = * + * =
3 2 3 3 18
1 1 1 1 1 1 1
Pr C = 3 = * + * + * =
3 2 3 3 3 6 3
1 1 1 1 1
Pr C = 4 = * + * = .
3 3 3 6 6
1 1
Pr M = a * Pr c = 3 | M = a 2 * 3 1
Pr M = a | C = 3 = = =
Pr C = 3 1 2
3
1
Pr M = a * Pr C = 4 | M = a 2 * 0
Pr M = a | C = 4 = = =0
Pr C = 4 1
6
1 1 1
*0 *
Pr M = b | C = 1 = 3 =0
Pr M = b | C = 2 = 3 3=2
2 5 5
9 18
1 1 1 1
* *
Pr M = b | C = 3 = 3 3 =1 Pr M = b | C = 4 = 3 3=2
1 3 1 3
3 6
56 2 Introduction to Cryptography
1 1 1
* 1 *0
Pr M = c | C = 1 = 6 3 = Pr M = c | C = 2 = 6 =0
2 4 5
9 18
1 1 1 1
* 1 * 1
Pr M = c | C = 3 = 6 3 = Pr M = c | C = 4 = 6 3 = .
1 6 1 3
3 6
The cryptosystem does not satisfy the perfect secrecy condition.
Problem 2.3
Matrix of encryption is as follows:
0 1 2
k1 1 0 2
k2 2 1 0
k3 0 2 1
k4 1 0 2
We reuse the solution to Problem 2.1 (which provides the general formula to compute the probability distribution of
ciphertexts):
1 1 1 1 1 1 1 5 5
Pr (C = 0) = * + * + * + * =
4 3 4 4 4 4 4 12 16
1 1 1 1 1 1 1 5 1
Pr (C = 1) = * + * + * + * =
4 3 4 3 4 4 4 12 3
1 1 1 1 1 5 1 5 17
Pr (C = 2) = * + * + * + * = .
4 3 4 4 4 12 4 12 48
Compute the conditional probability distribution of the plaintexts
1 1
Pr M = 0 * Pr C = 0 | M = 0 3 * 4 4
Pr M = 0 | C = 0 = = =
Pr C = 0 5 155
16
1 1
Pr M = 0 * Pr C = 1 | M = 0 3 * 2 * 4 1
Pr M = 0 | C = 1 = = =
Pr C = 1 1 2
3
1 1
Pr M = 1 * Pr C = 2 | M = 1 4 * 4 3
Pr M = 1 | C = 2 = = = .
Pr C = 2 17 17
48
None of the three pairs above satisfies the perfect secrecy condition. Notice that a single pair is sufficient to state that the
cryptosystem does not satisfy the perfect secrecy condition.
Problem 2.4
Let M , C , and K denote the plaintext, ciphertext, and key spaces, respectively. Let M, C, and K denote the random vari-
ables associated with plaintext, ciphertext, and key, respectively. Let m∈ M be a plaintext and c ∈ C, a ciphertext. Let n
denote the bit-length of plaintext, ciphertext, and key.
By definition of OTP cipher, given c and m, ∃ k ∈ K | m ⊕ k = c .
Since all plaintexts and ciphertexts have the same probability of 2−n and each plaintext is encrypted using a distinct key,
References 57
Pr M = m * 2−n
Pr M = m | C = c = =
∑m′∈M (2 )
−n
* Pr M = m′
Pr M = m Pr M = m
= .
∑m′∈M (Pr M = m′ )
1
the perfect secrecy condition (2.1), we need just to find a counterexample. By Bayes’s theorem, condition (2.1) becomes:
Pr C = c | M = m * Pr M = m
= Pr M = m.
Pr C = c
Take a plaintext m = " AC " and a ciphertext c = " ZZ ". When all the plaintexts have the same probability distribution,
1
Pr M = " AC " = .
26 * 26
Pr C = " ZZ" | M = "AC" = 0, because no key can associate the ciphertext " ZZ" with the plaintext " AC". Therefore,
0 * Pr M = m 1
Pr M = " AC "| C = " ZZ " = =0≠ , which contradicts condition (2.1). Therefore, the considered
Pr C = c 26 * 26
Caesar’s cipher does not satisfy the perfect secrecy condition.
Notes
References
Cryptography is a discipline that requires a background in mathematics. All encryption, decryption, and signature algo-
rithms are based on notions and theorems known in number theory, modular arithmetic, and abstract algebra. Before we
start the presentation and analysis of cryptographic algorithms, we need to review basics from number theory and abstract
algebra. This chapter aims to review and present, with examples and exercises, the mathematical background to address
cryptography algorithms. Seminal theorems are given with the names of their authors. Proofs of theorems are not included
in this chapter and can be found in many books and papers on the topics [1–6].
To make attacks against cryptosystems computationally infeasible, numbers used in cryptographic algorithms are very
large (in magnitude of 2160 , 2256 , 22048, etc.). Therefore, optimized (in term of execution time) computation methods are
needed. In addition to mathematical basics, algorithms commonly used to do fast computations in cryptographic algo-
rithms are addressed in this chapter. Finally, the birthday paradox is presented; it is useful for the analysis of attack
complexity.
According to the mathematics and computation algorithms skills of the reader, he/she may:
● Skip this chapter and address directly cryptographic algorithms.
● Learn basics, move to cryptographic algorithms, and return to this chapter to retrieve the needed facts and results.
● Learn the basics and theorems and deepen through the examples and exercises included, then move to cryptographic
algorithms.
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Z. Mammeri.
© 2024 John Wiley & Sons Inc. Published 2024 by John Wiley & Sons Inc.
60 3 Mathematical Basics and Computation Algorithms for Cryptography
Definition 3.1 Greatest common divider: a positive integer c is the greatest common divider of two integers a and b if
i) (c | a ) ∧ (c | b)
ii) ∀c ′ | (c ′ | a) ∧ (c ′ | b) ⇒ (c ′ | c ) ∧ (c ≥ c ′)
Example 3.1
Definition 3.2 Least common multiplier: a positive integer m is the least common multiple of two integers, a and b, if
i) (a | m) ∧ (b | m)
ii) ∀ m′ | (a | m′) ∧ (b | m′) ⇒ (m | m′) ∧ (m ≤ m′)
Example 3.2
Definition 3.3 Prime: a prime is an integer greater than 1 that is not a product of two (or more) smaller integers.
Example 3.3
3, 11, 47, 73, 97 , and 103 are primes.
Definition 3.4 Coprime or relatively prime: two positive integers a and b are coprime (also called relatively prime) if
GCD (a, b) = 1.
Example 3.4 (12, 49) and (39, 32) are two pairs of coprimes.
Definition 3.5 Prime power: a prime power is an integer that can be expressed as pm , where p is a prime and m a positive
integer.
Definition 3.6 Integer factorization and composite number: every integer N > 2 can be written as a product of powers,
i.e. N = p1n1 * p2n2 * … * pknk , where p1 , p2 , …, pk are distinct prime factors of N and n1 , n2 , …, nk are positive integers. For
every integer N , the factorization is unique (the order of the primes in the product does not matter). A number is said to be
composite if it has at least two factors.
3.1 Number Theory Notations, Definitions, and Theorems 61
Example 3.6
91476 = 22 ∗ 33 ∗ 7 ∗ 112 .
2, 3, 7, and 9 are primes and are factors of the composite number 91476.
Definition 3.7 Euler’s totient function (or Euler’s phi function): for an integer N ≥ 1, the number of integers in the
interval 1, N which are coprime to N is denoted ϕ ( N ). ϕ is called Euler totient function (or Euler phi function).
Theorem 3.2 For integers a, b, c if a|c and b | c and a and b are coprime, then ab | c.
Example 3.8 Let a = 7, b = 12, and c = 420; a and b are coprime. The following hold:
7 | 420, because 420 is multiple of 7. 12 | 420, because 420 is a multiple of 12 .
(7 * 12) | 420 , because 420 is a multiple of 84.
3.1.2 Sets
Example 3.9
S1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} is a finite set composed of 10 integers.
S2 = {….,−2,−1, 0, 1, 2, 3, …} is an infinite set of negative and positive integers.
Definition 3.9 Order (or cardinality): the order, also referred to as cardinality, of a set S is the number of elements of S. It
is denoted S or ord (S ).
Example 3.10
S1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ⇒ ord( S1 ) = S1 = 10.
Definition 3.10 Congruence: let a, b, and n be three positive integers. a is congruent to b modulo n , which is denoted
a ≡ b mod n, if n | (a − b) . In other words, a ≡ b mod n ⇒ ∃ k ∈ Z | a = b + kn. In the congruence relation a ≡ b mod n, n is
called the modulus and b the residue (or the remainder).
62 3 Mathematical Basics and Computation Algorithms for Cryptography
The congruence also is denoted a ≡ b (mod n). The remainder b is such b < n . In the usual convention, b is the least
positive residue. Negative residue also can be used.
Example 3.11
17 ≡ 2 mod 5, which is the same as 17 ≡ −3 mod 5.
17 ≡ 1 mod 8, which is the same as 17 ≡ −7 mod 8.
In general, computations in cryptography algorithms make use of least positive residues.
Definition 3.11 Congruence class (or residue class): the congruence class modulo n of an integer a ∈ Z, such that a < n,
is the set of all integers x that have the same residue modulo n : {x ∈ Z | x ≡ a mod n}. An equivalence class is an infinite set.
All elements of an equivalence class mod n are equivalent, i.e. they are congruent to the same value mod n. Congruence class
of integer a modulo n is denoted an. It also is called residue class or simply residue of integer a.
Example 3.12
– 19 = {…,−17,−8, 1, 10, 19, 28, 37, …} is the congruence class mod 9 associated with element 1.
– 1317 = {…,−21,−4, 13, 30, 47, 64, 81, …} is the congruence class mod 17 associated with element 13.
Lemma 3.11 Modular arithmetic exponentiation rule: if a, n, and k are positive integers, then:
k
ak mod n ≡ (a mod n) mod n.
Lemma 3.22 Let N be a product of primes n1 , n2 , …, nk. If x ≡ a mod n, then x ≡ a mod ni for 1 ≤ i ≤ k.
Example 3.13
– Z2 = {0,1} : 100 mod 2 = 4 mod 2 = 1000 mod 2 = 0
– Z12 = {0, 1, 2, 3, …, 11} : 1 mod 12 = 13 mod 12 = 25 mod 12 = 1. Z12 may be used to represent the set of hours of day).
Definition 3.12 Modular multiplicative inverse3: let a ∈ Z p . The modular multiplicative inverse of a, if it exists, is an
element a−1 ∈ Z p such that a * a−1 ≡ 1 mod p.
3.1 Number Theory Notations, Definitions, and Theorems 63
Example 3.14
– In Z9 : 2−1 = 5, because 2 ∗ 5 ≡ 1 mod 9
– In Z23 : 2−1 = 12 , because 2 ∗ 12 ≡ 1 mod 23
Definition 3.13 Invertible element: an element a ∈ Z p is said to be invertible if its multiplicative inverse exists in Z p.
Theorem 3.3 Existence of multiplicative inverse: an element a ∈ Zn has a multiplicative inverse modulo n if and
only if GCD(a,n ) = 1G.
Definition 3.14 Z*n: the multiplicative group of Zn denoted Zn* is the set of invertible elements of Zn. Formally,
Zn* = {a ∈ Zn | GCD(a, n) = 1}.
Theorem 3.5 Fermat’s little theorem: if p is a prime and a is a positive integer coprime with p, then a p−1 ≡ 1 mod p.
Fermat’s little theorem is a special case of Euler’s theorem. If p is a prime, by Euler’s totient function properties,
ϕ ( p) = p −1.
Note. Euler’s and Fermat’s little theorems are of prime importance to cryptography.
Definition 3.15 Modular square root: a modular square root r of an integer a modulo n is an integer greater than 1 such
that: r 2 ≡ a mod n .
Definition 3.16 Quadratic residue: an integer a is called quadratic residue of n, if there exists an integer r, such that
r 2 ≡ a mod n . Otherwise, a is called a quadratic nonresidue.
Theorem 3.6 Modular square root: if a square r mod n exists, then there exists a second square root −r modulo n .
Example 3.15
– 5 is a modular square root of 4 mod 7 , because 52 ≡ 4 mod 7 . Thus, −5, which is equal to 2 mod 7, also is a modular
square root of 4 mod 7 , because 22 ≡ 4 mod 7 .
– 9 is a modular square root of 3 mod 13 , because 92 ≡ 3 mod 13. Thus, −9, which is equal to 4 mod 13, also is a modular
square root of 3 mod 13, because 42 ≡ 3 mod 13 .
Theorem 3.7 Euler’s criterion: given two integers a and p, such that p > 2 and a and p are coprime,
p−1
i) a 2 ≡ 1 mod p, if there exists r such that r 2 ≡ a mod p
p−1
ii) a 2 ≡ −1 mod p , if there does not exist r such that r 2 ≡ a mod p.
a
Definition 3.17 Legendre symbol: let p be a prime greater than 2 and a an integer, Legendre symbol, denoted , is
defined by: p
0 if GCD(a, p) ≠ 1
a
= +1 if a is quadratic residue .
p
−1 if a is quadratic nonresidue
Example 3.16
1
= 1, because 13 ≡ 1 mod 7 2 = 1, because 23 ≡ 1 mod 7
7 7
3
= −1, because 33 ≡ 1 mod 7 4 = 1, because 43 ≡ 1 mod 7
7 7
5
= −1, because 53 ≡ 1 mod 7 6 = −1, because 63 ≡ 1 mod 7
7 7
7
= 0 , because GCD(7, 7) ≡ 1.
7
p−1
The Euler’s criterion tells us that r 2 ≡ a mod p has a solution if and only if a 2 ≡ 1 mod p. However, it does not tell us
how to find the solution.
Example 3.17
– Does r 2 ≡ 3 mod 13 have a solution?
13−1
Since 3 2 = 36 ≡ 1 mod 13 , there are two solutions to r 2 ≡ 3 mod 13.
2
– Does r ≡ 31 mod 83 have a solution?
83−1
Since 31 2 = 3141 ≡ 1 mod 83 , there are two solutions to r 2 ≡ 31 mod 83 .
Lemma 3.45
p−1 p−1
if p is a prime greater than 2, then 2
elements of Z *p are quadratic residues; and 2
are quadratic nonresidues.
The Euler’s criterion is used to test if a solution exists. However, it does not tell us how to find the solution. Therefore,
we need to do some (not easy) work. Given a prime p, there are three6 alternatives to address: p = 2, p ≡ 1 mod 4, and
p ≡ 3 mod 4 .
3.1 Number Theory Notations, Definitions, and Theorems 65
i) Case p = 2
In such a case, a ≡ 0 mod 2 or a ≡ 1 mod 2 .
r = 0, if a ≡ 0 mod 2 and r = 1, if a ≡ 1 mod 2.
ii) Case p ≡ 3 mod 4
Lemma 3.57 If p is a prime such that p ≡ 3 mod 4 and a is a quadratic residue of p, then a solution to r 2 ≡ a mod p is
p +1
given by r = a 4 .
Exercise 3.1
Determine the integers, which are coprime with N , and then apply the Euler’s totient function ϕ() to check the result.
Consider N = 17, 42, 25.
Exercise 3.2
*
1) Find the additive and multiplicative inverses of 27 in Z100 .
2) Find the Euler totient: ϕ (101), ϕ (102), and ϕ (500).
Exercise 3.3
1) Find an integer x such that 3 x ≡ 13 mod 17.
2) Show that there does not exist an integer x such that 4 x ≡ 5 mod 31.
3) In general, how hard is it to find x | a x ≡ b mod n with known integers a, b, and n?
Exercise 3.4
Apply Euler’s theorem (Theorem 3.4) to find modular inverses of integers from 1 to 8 in Z9* .
Exercise 3.5
Use (if applicable) theorems of Euler and Fermat (Theorems 3.4 and 3.5) to find a−1 mod n:
1) a = 6, n = 7
2) a = 7, n = 15
3) a = 19, n = 101. Hint: 1925 ≡ 1 mod 101, 1919 ≡ 5 mod 101, and 195 ≡ 84 mod 101
4) a = 97, n = 100. Hint: 9720 ≡ 1 mod 100 and 9719 ≡ 33 mod 100 .
Exercise 3.6
Find x such that:
x ≡ 4100 mod 17
9 x ≡ 13 mod 17
5 x ≡ 13 mod 17
7 x = 11 mod 13
66 3 Mathematical Basics and Computation Algorithms for Cryptography
Problem 3.1
Prove Lemma 3.1.
Problem 3.2
Prove Lemma 3.2.
Problem 3.3
Prove Lemma 3.3.
Problem 3.4
1) Prove that if p is even, then any even integer has no multiplicative inverse in Z *p .
2) Prove that the cardinality of Z2* m is at most 2m−1 .
Problem 3.5
p−1 p−1
Let p = 11. Show that 2
elements of Z *p are square residues and 2
are square nonresidues.
Problem 3.6
Prove Lemma 3.4.
Problem 3.7
Prove Lemma 3.5.
Problem 3.8
Let u be an element Z *p. Prove that:
(p−1)/2
1) a = u is a square root of 1
(p−1)/2
2) u is 1 or −1.
Problem 3.9
Prove the following lemma:
( ) (
Given two distinct primes p and q, p p−1mod q + q q−1mod p = pq + 1. )
Definition 3.18 Group: a group, denoted (G, o) , is a set equipped with an operation o, which is usually the addition or the
multiplication modulo n, satisfying the following properties for all elements x , y, z ∈ G:
Definition 3.20 Subgroup: H, a subset of a group G, is called a subgroup of G if H is a group with respect to the operation o
over G.
Definition 3.21 Additive and multiplicative groups: if a group G is equipped with the addition operation (+), it is called
additive group and denoted (G, +) and its neutral element is 0. If a group G is equipped with the multiplication operation (×) ,8
it is called multiplicative group and denoted (G,×) and its neutral element is 1.
3.2 Basic Algebraic Structures 67
Definition 3.22 Order of a group: the order of a group G, denoted G , is the number of elements in G. A group G is infinite
if G is infinite.
Example 3.20
– R (the set of real numbers) is a group under the addition operation as well as under the multiplication operation. Any
number x ∈ R has an additive inverse (i.e. −x ∈ R) and a multiplicative inverse (i.e. x −1 ∈ R ).
– N (the set of positive integers) is neither a group under the addition operation nor a group under multiplication
operation, because additive inverses are negatives and multiplicative inverses of most integers are not integers.
– Z p (the set of integers modulo p) is a group under the addition operation, but it is not a group under multiplication
operation, because some multiplicative inverses do not exist in Z p when p is not prime.
Definition 3.23 Order of element: the order of an element a ∈ G , denoted ord(a), is the smallest positive integer k such that
ak = a o a o…o a ≡ e, where e is the neutral element of G. If no such k exists, the element a is said to have an infinite order.
Theorem 3.8
Let G denote a group (Z p , ∗) and a ∈ G. If ak ≡ 1 mod p, then am* k ≡1 mod p for any positive integers m and k.
Theorem 3.8 is very useful to compute modular exponentiation. For example, one can immediately find that 26 = 64 ≡ 1 mod 9.
However, finding 266666666666666 mod 9 is more complex without using Theorem 3.8. Indeed, since the exponent is a multiple of 6 and
26 mod 9 is known, by the previous theorem, one can easily find that 266666666666666 mod 9 = 1.
Example 3.21
– Let (Z7 , +) denote the group over the set {0, 1, 2, 3, 4, 5, 6} equipped with the addition operation. (Z7 , +) is a finite group.
Its cardinality is Z7 = 7. The order of element 4 is 3, because 4 ∗ 4 ∗ 4 = 1 mod 7.
– Let S denote the set {1, 2, 3, 4, 5, 6, 7, 8}. Let us check if S is a finite group under the multiplication operation. We have to
check if all elements have inverses:
1 ∗ 1 ≡ 1 mod 9 2 ∗ 5 ≡ 1 mod 9 4 ∗ 7 ≡ 1 mod 9
5 2 1 mod 9 7 ∗ 4 ≡ 1 mod 9 8 ∗ 8 ≡ 1 mod 9
Elements 3 and 6 have no multiplicative inverses. Therefore, the set S is not a finite group under the multiplication oper-
ation, while S ′ = {1, 2, 4, 5, 7, 8} is.
– Let G = {1, 2, 4, 5, 7, 8} be a finite group under the multiplication operation. We check if all element orders are finite:
ord(1) = 1, because 1 * 1 = 1 mod 9
ord(2) = 6, because 2 ∗ 2 ∗ 2 ∗ 2 ∗ 2 ∗ 2 = 1 mod 9
ord( 4) = 3, because 4 ∗ 4 ∗ 4 = 1 mod 9
ord(5) = 6, because 5 ∗ 5 ∗ 5 ∗ 5 ∗ 5 ∗ 5 = 1 mod 9
ord(7) = 3, because 7 ∗ 7 ∗ 7 = 1 mod 9
ord(8) = 2, because 8 ∗ 8 = 1 mod 9
Therefore, all the elements of the group have an order less or equal to 6, which is the order of the group.
Definition 3.24 Ring: a ring, denoted ( R, +, ×), is a set R equipped with two operations, addition and multiplication, satisfying
the following properties:
Definition 3.25 Commutative ring: a commutative ring, denoted ( R, +, × ), is a ring satisfying the following property:
Commutativity of operation × : a × b = b × a, for all a, b ∈ R.
68 3 Mathematical Basics and Computation Algorithms for Cryptography
Definition 3.26 Cyclic group: a cyclic group is a finite group that is generated by a single element g, called generator (or
primitive element) of the group.
Definition 3.27 Primitive root modulo n: a number α is called primitive root modulo n, if every number coprime to n is
congruent to a power of α modulo n. Formally, α is a primitive root if for any integer a such that GCD(a, n) = 1, there exists
an integer k such that α k ≡ a mod n.
ii) Given an integer n, if primitive roots mod n exist, then the number of primitive roots mod n is equal to ϕ (ϕ (n)).
iii) If α is a primitive root mod n, then the smallest k such that α k ≡ 1 mod n is equal to ϕ(n).
Theorem 3.10 For every prime p, Z *p is an abelian finite cyclic group under the multiplication operation.
Example 3.22
– Let G = (Z11 , +) be a cyclic group. Elements of G are {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. Element 5 is a generator of Z11 , because:
0 * 5 ≡ 0 mod 11 9 * 5 ≡ 1 mod 11 7 * 5 ≡ 2 mod 11
5 * 5 ≡ 3 mod 11 3 * 5 ≡ 4 mod 11 5 * 1 ≡ 5 mod 11
10 * 5 ≡ 6 mod 11 8 * 5 ≡ 7 mod 11 6 * 5 ≡ 8 mod 11
4 * 5 ≡ 9 mod 11 2 * 5 ≡ 10 mod 11
*
– Let G = ( Z11 , ∗) be a cyclic group. Elements of G are {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. Element 2 is a generator of G, since all its
elements are generated as follows:
20 ≡ 1 mod 11 21 ≡ 2 mod 11 28 ≡ 3 mod 11
22 ≡ 4 mod 11 24 ≡ 5 mod 11 29 ≡ 6 mod 11
27 ≡ 7 mod 11 23 ≡ 8 mod 11 26 ≡ 9 mod 11
25 ≡ 10 mod 11
* * *
– Let G = (Z11 , ∗) be a cyclic group. Let us check if the orders of all elements of Z11 divide Z11 , which is equal to10 :
3.2.2 Fields
Definition 3.28 Field: a field F is a set of elements9 together with two operations, Addition (+) and Multiplication (×), satis-
fying the following properties:
i) ( F , +) is an abelian group with a neutral element denoted 0 such that a + b = b + a and a + 0 = a, ∀a, ∀b ∈ F .
ii) ( F − {0},×) is a commutative group under the multiplication operation with an identity element 1 :a × b = b × a and
a ×1 = a, ∀a, ∀b ∈ F . F − {0} is often denoted F * .
iii) Associativity: (a + b) + c = a + (b + c ), (a × b) × c = a × (b × c ), ∀a, ∀b, ∀c ∈ F .
iv) Distributivity: a × (b + c ) = a × b + a × c, for a, b, c ∈ F .
v) Every nonzero element a ∈ F has a multiplicative inverse a−1 ∈ F | a × a−1 = 1.
In other words, a commutative ring where all nonzero elements have multiplicative inverses is a field.
Definition 3.29 Finite field: a finite field Fp , also called Galois field and denoted GF ( p), is a field with a finite number of
elements p. It is a set with two operations, addition (+) and multiplication (×), which are both commutative and associative.
Notations:
Finite field with prime p is denoted Fp, F ( p), or GF ( p).
Finite field with prime power pm is denoted Fpm , F ( pm ), or GF ( pm ) .
F * is the set of nonzero elements of finite F (i.e. F * = F − {0}).
70 3 Mathematical Basics and Computation Algorithms for Cryptography
Theorem 3.12 Finite field: a field Fp is finite if and only if p is prime or a prime power.
Definition 3.30 Prime field: any field Fp , also denoted10 Z p,with prime p, is unique and called prime field.
Theorem 3.14 Multiplicative inverse property in prime fields: let a be an element of a prime field Fp and g a gen-
erator of Fp. Element a and its multiplicative inverse a−1 ∈ Fp are linked by the following property:
a ∈ Fp , a ≠ 0, ∃i ∈ N, 0 ≤ i ≤ p − 2 | g i ≡ a mod p and g p−i−1 ≡ a−1 mod p
Example 3.23
– 3 − 5 mod 7 = 3 + 2 = 5, because −5 ≡ 2 mod 7
– 53 mod 7 = 3× (5−1 ) = 2, because 3 is the multiplicative inverse of 5 mod 7.
Example 3.24 Z7 , under the usual addition and multiplication operations + and * is a finite field, because:
– The number of elements of Z7 is finite.
– (Z7 , +) and (Z *p , ∗) are commutative groups.
– Each nonzero element of Z7 has its multiplicative inverse in Z7 . Below is the table of computations for Z7 :
+ 0 1 2 3 4 5 6 * 0 1 2 3 4 5 6 a −a a−1
0 0 1 2 3 4 5 6 0 0 0 0 0 0 0 0 0 0 -
1 1 2 3 4 5 6 0 1 0 1 2 3 4 5 6 1 6 1
2 2 3 4 5 6 0 1 2 0 2 4 6 1 3 5 2 5 4
3 3 4 5 6 0 1 2 3 0 3 6 2 5 1 4 3 4 5
4 4 5 6 0 1 2 3 4 0 4 1 5 2 6 3 4 3 2
5 5 6 0 1 2 3 4 5 0 5 3 1 6 4 2 5 2 3
6 6 0 1 2 3 4 5 6 0 6 5 4 3 2 1 6 1 6
Example 3.25
– Z100, with the usual addition and multiplication operations + and *, is not a finite field, because some elements (i.e. even
elements and multiples of 5) have no multiplicative inverse mod 100 . Recall that the multiplicative inverse of a ∈ Z p
exists only if GCD(a, p) = 1.
3.2 Basic Algebraic Structures 71
– Z8 , with the usual addition and multiplication operations + and * is not a finite field, because even elements (i.e. 2, 4,
and 6) have no multiplicative inverse mod 8. However, Z8 can be written as F23 and by Theorem 3.12, Z8 should be a
field. To make Z8 a field, we need to redefine addition and multiplication (see Section 3.2.3).
Example 3.26 Elements of the field F23 are {0, 1, 2, 3, …, 21, 22} . Element 5 is a generator of F23*, since its powers give all
the elements of F23*, as follows:
50 ≡ 1 mod 23 51 ≡ 5 mod 23 52 ≡ 2 mod 23 53 ≡ 10 mod 23
54 ≡ 4 mod 23 55 ≡ 20 mod 23 56 ≡ 8 mod 23 57 ≡ 17 mod 23
58 ≡ 16 mod 23 59 ≡ 11 mod 23 510 ≡ 9 mod 23 511 ≡ 22 mod 23
512 ≡ 18 mod 23 513 ≡ 21 mod 23 514 ≡ 13 mod 23 515 ≡ 19 mod 23
516 ≡ 3 mod 23 517 ≡ 15 mod 23 518 ≡ 6 mod 23 519 ≡ 7 mod 23
520 ≡ 12 mod 23 521 ≡ 14 mod 23 522 ≡ 1 mod 23
Definition 3.31 Extension field: a field F is said to be an extension of a field E , if E is a subfield of F . That is denoted
F / E or F over E. An extension field also is called extended field.
Definition 3.32 Characteristic of extension field: if Fpm is an extension of field Fp , it has a characteristic of p. That is,
adding p copies of any elements of Fpm results in adding the neutral element 0.
Example 3.27
– R, the set of real numbers, is an extension of Q, the set of rational numbers, and Q is an extension of Z, the set of
integers.
– F23 = {0, 1, 2, 3, 4, 5, 6, 7} is an extension field of Z2 . It has a characteristic of 2. Hence, ∀a ∈ F23 , a + a = 0 , because
addition is done modulo 2.
– F32 = {0, 1, 2, 3, 4, 5, 6, 7, 8} is an extension field of Z3. It has a characteristic of 3. Hence,∀a ∈ F32 , a + a + a = 0 , because
addition is done modulo 3.
To do operations on elements of extension fields Fpm , we need to represent them as polynomials. That is, any element of
an extension field is a polynomial with coefficients in a subfield Fp .
Definition 3.33 Polynomial: a polynomial P ( x ) of degree d is an expression of the form P ( x ) = cd−1 x d−1 + cd−2 x d−2 +⋅⋅⋅ +
c1 x 1 + c0 , where ci , i = 0,1, …, d − 1 are called coefficients and are elements of some field F . x is called the unknown.
72 3 Mathematical Basics and Computation Algorithms for Cryptography
Example 3.28
Let A( x ) = x 3 + x 2 + x + 1 and B ( x ) = x 2 + 1 .
– Computations over Z5 :
A( x ) + B ( x ) = x 3 + 2 x 2 + x + 2
A( x ) ∗ B ( x ) = x 5 + x 4 + 2 x 3 + 2 x 2 + x + 1
– Computations over Z2:
A( x ) − B ( x ) = x 3 + x
A( x ) ∗ B ( x ) = x 5 + x 4 + x + 1
Notation:
G x denotes the set of polynomials over the group G.
Definition 3.34 Polynomial congruence: let A( x ), P ( x ) , and R( x ) be polynomials with coefficients in some field F .
A( x ) is said to be congruent to R( x ) modulo P ( x ), if P ( x ) divides A( x ) − R( x ). The congruence relation is denoted
A( x ) ≡ R( x ) mod P ( x ).
Example 3.29
– ( x 2 + 1) ≡ ? mod ( x + 1) in Z2 x
Since ( x + 1) ∗ ( x + 1) = x 2 + 2 x + 1, ( x 2 + 1) ≡ 0 mod ( x + 1)
– ( x 2 + 1) ≡ ? mod ( x + 1) in Z3 x
Since ( x 1) ( x 1) 2 x 2 1, ( x 2 1) 2 mod ( x 1)
– ( x 3 + 11 x 2 + x + 7) ≡ (?) mod ( x 2 + 2 x + 9) in Z101 x
( x 2 + 2 x + 9) ∗ ( x + 9) = x 3 + 11 x 2 + 27 x + 81
= x 3 + 11 x 2 + x + 7 + (26 x + 74)
Hence, ( x 3 + 11 x 2 + x + 7) ≡ −(26 x + 74) mod ( x 2 + 2 x + 9)
– ( x 3 + 11 x 2 + x + 7) ≡ (?) mod ( x 2 + 2 x + 9) in Z13 x
In Z13 , − (26 x + 74) = −(2 * 13 x + 5 * 13 + 9) ≡ −9 mod 13 = 4
Hence, ( x 3 + 11 x 2 + x + 7) ≡ 4 mod ( x 2 + 2 x + 9)
Properties of polynomial congruence
Let A( x ), B ( x ), C ( x ), A1 ( x ), B1 ( x ), …, Ak ( x ), Bk ( x ) , and P ( x ) be polynomials and k a positive integer. The following prop-
erties hold:
i) A( x ) ≡ A( x ) mod P ( x )
ii) If A( x ) ≡ B ( x ) mod P ( x ) , then B ( x ) ≡ A( x )mod P ( x )
iii) If A( x ) ≡ B ( x ) mod P ( x ) and B ( x ) ≡ C ( x ) mod P ( x ) , then A( x ) ≡ C ( x ) mod P ( x )
iv) If A( x ) ≡ A1 ( x ) mod P ( x ) and B ( x ) ≡ B1 ( x ) mod P ( x ) , then
A( x ) + B ( x ) ≡ ( A1 ( x ) + B1 ( x )) mod P ( x ) and
A( x ) ∗ B ( x ) ≡ ( A1 ( x ) ∗ B1 ( x )) mod P ( x )
v) If Ai ( x ) ≡ Bi ( x ) mod P ( x ), for i = 1, 2, …, k , then
k k
∑ i=1 Ai ( x ) ≡∑ i=k Bi ( x ) mod P ( x )
∏ik=1 Ai ( x ) ≡ ∏ik=1 Bi ( x ) mod P ( x )
A j ( x ) − Ai ( x ) ≡ B j ( x ) − Bi ( x ) mod P ( x ), 1 ≤ i ≤ k, 1 ≤ j ≤ k
Definition 3.35 Polynomial root: a ∈ Z p is a root of polynomial f ( x ), if f (a) = 0. Therefore, if a is a root of f ( x ), there
exists a polynomial g ( x ) of degree less than that of f ( x ), such that f ( x ) = ( x − a) * g ( x ).
Definition 3.36 Irreducible polynomial: a polynomial f ( x ) is said to be irreducible in Z p if it does not factor as a product
of two or more polynomials with coefficients in Z p each of degree less than that of f ( x ).
3.2 Basic Algebraic Structures 73
In other words, an irreducible polynomial over Z p has no root in Z p. Irreducible polynomials are counterpart of primes:
irreducible polynomials cannot be expressed as a product of two other polynomials like primes cannot be factorized.
Therefore, irreducible polynomials are used as polynomial moduli to construct finite fields.
In general, if a polynomial has no root, it does not necessarily mean that it is irreducible. For example, in Z3, x 4 + 2 x 2 + 1 can
be written as a product ( x 2 + 1) ( x 2 + 1). Therefore, it is reducible, but it has no roots in Z3, because ( x 2 + 1) has no roots in Z3.
Example 3.30
– Reducible polynomial over F2: P ( x ) = x 2 + 1.
Since P(1) = 0, 1 is a root; and P ( x ) can be written as a product, i.e. x 2 + 1 = ( x − 1)( x − 1).
– Reducible polynomial over F5:
P ( x ) = x 4 + 2 x 3 + 3 x + 1.
Since P (3) = 145 ≡ 0 mod 5, 3 is a root; and P ( x ) can be written as a product, i.e.
( x − 3)( x 3 + 3) = ( x + 2)( x 3 + 3) = x 4 + 2 x 3 + 3 x + 6 = x 4 + 2 x 3 + 3 x + 1.
– Irreducible polynomials over F2
P ( x ) = x 2 + x + 1 : P (0) = 1 and P(1) = 1. Thus, P ( x ) has no root over F2. Hence, by Theorem 3.14, P ( x ) is irreducible.
P ( x ) = x 4 + x + 1: check if there exist two polynomials Q ( x ) and R( x ) of degree less than 4 such that P ( x ) = Q( x ) ∗ R( x ):
candidate polynomials for Q( x ) and R( x ) are: x +1, x 2 + 1, x 2 + x + 1, x 3 + 1, x 3 + x + 1, and x 3 + x 2 + x + 1. No product
of a pair of candidate polynomials results in P ( x ). Therefore, the latter is irreducible.
Theorem 3.16 Let f ( x ) be an irreducible polynomial of degree m with coefficients in Fp . Fpm x / f ( x ) is a finite field
of order pm .
Note. Fpm x / f ( x ) denotes the set of polynomials yielded by operations modulo f ( x ) on polynomials in the set Fpm x .
Addition of two polynomials is done by usual polynomial addition with modulo p on the coefficients. Multiplication of
two polynomials is performed with modulo f ( x ) on the usual product of two polynomials.
Definition 3.37 Reduction polynomial: the irreducible polynomial f ( x ) used to reduce the product of polynomials in
Fpm x is called reduction polynomial.
Example 3.31
{ }
– F23 = {0, 1, 2, 3, 4, 5, 6, 7} is represented by the set of polynomials F23 x = 0, 1, x , x + 1, x 2 , x 2 + 1, x 2 + x , x 2 + x + 1 .
With the reduction polynomial f ( x ) = x 3 + x + 1 over F2, examples of operations are:
( x 2 + x ) + ( x 2 ) + (1) = x + 1
( x 2 + 1)( x + 1) mod f ( x ) = ( x 3 + x 2 + x + 1) mod f ( x ) = x 2
74 3 Mathematical Basics and Computation Algorithms for Cryptography
Definition 3.38 Primitive polynomial: f ( x ), a polynomial of degree m, irreducible in Fp x , and with coefficients in Fp , is
{ } is the entire field F
m−2
said to be primitive polynomial if it has a root α ∈ Fpm such that 0, 1, α, α 2 , α,3 …, α p pm
. In other words,
a root of a primitive polynomial is a field generator.
Example 3.32 Below is a non-comprehensive list of primitive polynomials with degree up to 32.
2 x2 + x +1 13 x 13 + x 12 + x 11 + x 8 + 1
3 2
3 x + x +1 14 x 14 + x 11 + x 6 + x + 1
4 x 4 + x3 +1 15 x 15 + x 4 + 1
5 3
5 x + x +1 16 x 16 + x 12 + x 7 + x 2 + 1
6 x6 + x5 +1 17 x 17 + x 6 + 1
7 6
7 x + x +1 18 x 18 + x 11 + 1
8 x8 + x6 + x5 + x 4 +1 19 x 19 + x 18 + x 17 + x 14 + 1
9 5
9 x + x +1 20 x 20 + x 17 + 1
10 x 10 + x 7 + 1 30 x 30 + x 23 + x 2 + x + 1
11 9
11 x + x +1 31 x 31 + x 3 + 1
12 x 12 + x 5 + 1 32 x 32 + x 22 + x 2 + x + 1
Theorem 3.19 Properties of primitive polynomials: let f ( x ) be a primitive polynomial of degree m, with coefficients in Fp.
2
i) If α ∈ Fpm is a root of f ( x ), then all the roots of f ( x ) are given by elements α, α p , α p , …, α p .
m−1
The consequence of Theorem 3.19 is that given a root α of a primitive polynomial f ( x ) of degree m and with coefficients in
Fp , we can generate all elements of the extension field Fpm as powers of α modulo f ( x ).
Example 3.33 Let f ( x ) = x 3 + x + 1 be a primitive polynomial over F2 x . According to Theorem 3.19, f ( x ) has three
roots α, α 2, and α 4 in F23 x . By definition of a root, if α is a root of f ( x ), then f (α ) = α3 + α + 1 = 0 in F23 x / f ( x ) .
Let us show that if α = 2 is a root, then α 2 and α 4 are roots, too.
Since operations in extension fields are done modulo the reduction polynomial f ( x ), x 3 + x + 1 ≡ 0 mod f ( x ).
Since α = x, f (α 2 ) = ( x 2 )3 + x 2 + 1 = x 6 + x 2 + 1 ≡ 0 mod f ( x ). Hence, α 2 is a root to f ( x ).
f (α 4 ) = ( α 4 ) 3 + α 4 + 1 .
Since α = x, f (α 4 ) = ( x 4 )3 + x 4 + 1 = x 12 + x 4 + 1 ≡ 0 mod f ( x ). Hence, α 4 is a root to f ( x ). Notice that: x 4 ≡ x 2 + x mod f ( x ).
Polynomials x, x 2 , and x 2 + x represent elements 2, 4, and 6 in F23 , respectively.
Let us check the roots above:
f (2) = 23 + 2 + 1 = 11 is represented by polynomial x 3 + x + 1. Since, x 3 + x + 1 ≡ 0 mod f ( x ), f (2) = 0 .
f ( 4) = 43 + 4 + 1 is represented by polynomial x 6 + x 2 + 1. Since, x 6 + x 2 + 1 ≡ 0 mod f ( x ), f ( 4) = 0
f (6) = 63 + 6 + 1 is represented by polynomial ( x 2 + x )3 + ( x 2 + x ) + 1 = x 6 + x 5 + x 3 + x 3 + x 2 + x + 1. Since
x 6 + x 5 + x 3 + x 3 + x 2 + x + 1 ≡ 0 mod f ( x ), f (6) = 0 .
Definition 3.39 Polynomial basis: given a polynomial f ( x ) of degree m and irreducible in Fp and α a root of f ( x ) and α
{ }
a primitive element in Fpm , the set of polynomials 1, α1 ,…, αm−2 , α m−1 is called polynomial basis of Fpm .
3.2 Basic Algebraic Structures 75
Theorem 3.20 Any element a ∈ Fpm can be expressed as a linear combination of elements of the polynomial basis.
That is, a = am−1αm−1 + am−2αm−2 +⋅⋅⋅ + a1α + a0, with ai ∈ Fp for 0 ≤ i ≤ m − 1.
Alternatively, a ∈ Fpm can be expressed as a power of f ( x ) root. That is,
∀a ∈ Fpm , ∃k ∈ N, 0 ≤ k ≤ pm − 2 | α k ≡ a mod f ( x ) . Therefore, F { }
m
pm
= 0, 1, α 1 ,…, αm ,…, α p −2
Lemma 3.611: It is not true that a root α of any polynomial f ( x ) of degree m, irreducible over Fp, can generate all ele-
ments of field Fpm.
Example 3.34 Let us consider the extension field F23 under the irreducible polynomial f ( x ) = x 3 + x + 1 and check that
{1, α, α2 } is a polynomial basis to F2 . 3
The eight elements of the binary field F23 over F2, in polynomial and binary representations, are as follows:
F32 = {0, 1, 2, 3, 4, 5, 6, 7 }
{ 0
= 0, α , α , α , 1 3 2
α , α , 6
α , 4
α 5
}
= {0, 1, α, α + 1, α , 2 2 2
α + 1, α + α, α 2
+ α + 1}
To see polynomials in unknown x, we have just to replace α by x. Since α can generate all nonzero elements of F23 ,
{ }
1, α, α 2 is a polynomial basis.
Additive inverse: 1 + 1 = 0 . Thus, 1 is the additive inverse of 1; and 0 + 0 = 0; so, 0 is the additive inverse of 0.
Multiplicative inverse: 1 * 1 = 1. Thus, 1 is the multiplicative inverse of 1. 0 has no multiplicative inverse.
76 3 Mathematical Basics and Computation Algorithms for Cryptography
Definition 3.40 Binary polynomial: a binary polynomial is a polynomial over F2, i.e. with coefficients in {0,1}.
Definition 3.41 Binary field: a field of the form F2m is called binary field and it has exactly 2m elements, which are usually
represented as m-bit strings (am−1am−2 …a1a0 ) ranging from (000…000) to (111…111).
Each element a ∈ F2m is commonly represented as an m-bit string (am−1am−2 …a1a0 ) and a polynomial
A( x ) = (am−1 x m−1 + am−2 x m−2 +⋅⋅⋅+ a1 x 1 + a0 ) ∈ F2m x is associated with it.
{ }
Definition 3.42 Polynomial basis of F2m : the set of polynomials x m−1 , x m−2 ,…, x 1 ,1 forms a basis to the field F2m .
Corollary 3.3 Existence of binary reduction polynomial: for every field F2m , there exists at least one polynomial of degree
m irreducible over F2.
Corollary 3.3 is a consequence of Theorem 3.18.
Operations over field F2m
Let a, b, and c be elements in F2m and their respective polynomials:
A( x ) = am−1 x m−1 + am−2 x m−2 +⋅⋅⋅+ a1 x 1 + a0 ; A( x ) ∈ F2m x
B ( x ) = bm−1 x m−1 + bm−2 x m−2 +⋅⋅⋅ + b1 x 1 + b0 ; B ( x ) ∈ F2m x
C ( x ) = cm−1 x m−1 + cm−2 x m−2 +⋅⋅⋅ + c1 x 1 + c0; C ( x ) ∈ F2m x
● Addition: A( x ) + B ( x ) = C ( x ), where ci = (ai + bi ) mod 2 = ai ⊕ bi.
● Subtraction: A( x ) − B ( x ) = C ( x ) , where ci = (ai + bi ) mod 2 = ai ⊕ bi . Subtraction is the same as addition over F2.
● Multiplication: A( x ) ∗ B ( x ) = R( x ) = rm−1 x m−1 + rm−2 x m−2 + …+ r1 x 1 + r0; R( x ) is the remainder of the polynomial
product A( x ) ∗ B ( x ) divided by the reduction polynomial f ( x ).
● Multiplicative inverse: if a ∈ F2m (a is a nonzero element), then the multiplicative inverse of a is denoted a−1, such that:
A( x ) * A−1 ( x ) ≡ 1 mod f ( x ), where A−1 ( x ) = dm−1 x m−1 + dm−2 x m−2 +⋅⋅⋅+ d1 x 1 + d0 is a polynomial in F2m x .
Definition 3.43 Field generator or primitive element: given a field F2m and a primitive polynomial f ( x ) of degree m,
an element g ∈ F2m is called generator (or primitive element) of F2m if and only if g is a root of f ( x ) in F2m and every nonzero
element of F2m can be uniquely written as a power of g.
Lemma 3.7 Property of primitive polynomial in F2m: if f ( x ) is a primitive polynomial of degree m, with coefficients in
m
F2, and a root in F2m , then f ( x ) divides x 2 −1 + 1.
The two theorems above are very useful to quickly calculate multiplicative inverses and exponentiation with large
exponents.
3.2 Basic Algebraic Structures 77
Theorem 3.23 Number of generators of F2m field: The number of primitive elements (or generators) of field F2m is
ϕ(2m − 1).
Theorem 3.24 Given a positive integer m, if 2m − 1 is prime, then any element of F2m, with the exception of elements
0 and 1, is a generator of F2m.
m−1
Corollary 3.4 By Theorems 3.22 and 3.24, if 2m − 1 is prime, then the square root of any element x ∈ F2m is x = x 2 .
Example 3.36 The eight elements of the binary field F23 over F2 are as follows in polynomial and binary representations:
Example 3.37 The 16 elements of the binary field F24 over F2 are as follows in polynomial and binary representations:
0 (0000) x2 +1 (0101) x3 + x (1010)
1 (0001) 2
x +x (0110) 3
x + x +1 (1011)
x (0010) 2
x + x +1 (0111) x3 + x2 (1100)
x +1 (0011) x3 (1000) x3 + x2 + 1 (1101)
x2 (0100) x3 + 1 (1001) x3 + x2 + x (1110)
x3 + x2 + x + 1 (1111)
78 3 Mathematical Basics and Computation Algorithms for Cryptography
By Theorem 3.1, ϕ (16 − 1) = ϕ (5) * ϕ (3) = 4 * 2 = 8. By theorem 3.23, F24 has ϕ(16 − 1) = 8 generators.
Let f ( x ) = x 4 + x + 1, which is an irreducible polynomial over F2, be the reduction polynomial for field F24 .
● Example of addition: (1101) + (1000) = (0101)
In polynomial form over F24 : ( x 3 + x 2 + 1) + ( x 3 ) = 2 x 3 + x 2 + 1 = x 2 + 1.
● Example of multiplication over F24 : (1110) * (1000) = (1001) explained as follows:
( x 3 + x 2 + x )*( x 3 ) mod f ( x ) = ( x 6 + x 5 + x 4 ) mod ( x 4 + x + 1) = ( x 3 + 1).
● One of the generators of F24 is the element 2, which can be checked as follows (element 2 is represented by polynomial x):
x 0 mod f ( x ) 1 0001 1
1
x mod f ( x ) x 0010 2
x 2 mod f ( x ) x2 0100 4
x 3 mod f ( x ) x 3
1000 8
x 4 mod f ( x ) x +1 0011 3
x 5 mod f ( x ) x +x2
0110 6
x 6 mod f ( x ) x3 + x2 1100 12
x 7 mod f ( x ) 3
x + x +1 1011 11
x 8 mod f ( x ) x2 +1 0101 5
x 9 mod f ( x ) x +x3
1010 10
x 10 mod f ( x ) x2 + x +1 0111 7
x 11 mod f ( x ) 3
x +x +x 2
1110 14
x 12 mod f ( x ) x3 + x2 + x +1 1111 15
x 13 mod f ( x ) 3
x + x +12
1101 13
x 14 mod f ( x ) x3 +1 1001 9
x 15 mod f ( x ) 1 0001 1
the element 3. Using the properties of a root α, compute the following over F32 :
1) 3−1
2) 37
3) 37k (k integer greater than 1)
4) 6 * 7
Exercise 3.18 Let x 4 + x + 1 be a polynomial irreducible over F2 associated with the field F24 . Assuming that 2 is a gener-
ator, do the following operations over F24 :
1) 9 * 6
2) 9−1 (hint: use Theorem 3.21)
3) (9 + 1)357 (hint: do not compute usual addition and use 2 as generator)
Exercise 3.19 The 256 elements of field F28 are represented as polynomials F28 x mod f ( x ), where
f ( x ) = x 8 + x 4 + x 3 + x + 1.
1) Calculate the sum of 01010011 and 11001010.
2) Calculate the product of 01010011 and 11001010.
3) Find the multiplicative inverse of 00000010.
Problem 3.10 Let g be a generator of Z *p. Prove that g −1 also is a generator of Z *p.
Problem 3.11 Prove the correctness of Lemma 3.6 by counterexamples:
1) Show that a root α of the irreducible polynomial f ( x ) = x 2 + 1 cannot generate all nonzero elements of the field F32 .
80 3 Mathematical Basics and Computation Algorithms for Cryptography
2) Show that a root α of the irreducible polynomial f ( x ) = x 3 + 2 x + 2 cannot generate all nonzero elements of field F33 .
Problem 3.12
1) Let g1 , g2 , …, gm be the generators of Z *p, with p > 3. Prove that
∏ii= k
=1 gi ≡ 1 mod p.
2) Let Fp be a prime field. Prove that ∑ u∈F u ≡ 0 mod p .
p
The previous sections presented theorems and lemmas, which are of paramount importance to cryptographic algorithms.
Often, computations are needed to find elements (e.g. multiplicative inverses, square roots, etc.). Such computations are
time consuming in particular when large numbers are of concern. Many algorithms exist in literature aiming to optimize
computations in general and in cryptosystems in particular. This section presents the most commonly used algorithms to
speed up computations in cryptographic algorithms. They include Extended Euclidean algorithm to find the greatest
common divider and multiplicative inverse, Square-and-multiply method to perform modular exponentiation, Montgomery
multiplication to compute modular multiplication, Gauss’s algorithm to solve congruence systems, Tonelli-Shanks
algorithm to find modular square roots, and Rabin’s algorithm to test irreducibility of polynomials.
function Euclidean_Algorithm_GCD(a, b)
# a and b are integers such that a ≥ b
while b ≠ 0 do
t = b; b = a mod b; a = t
return a
Theorem 3.25 Bezout’s theorem (also called Bezout’s identity): for every pair of two non-negative integers a and
b, there exist two integers x and y, such that GCD(a, b) = ax + by .
In addition to the GCD computation, the Extended Euclidean algorithm computes two coefficients (called Bezout’s identity
coefficients) x and y, such that ax + by = GCD (a, b). The pseudocode of the extended Euclidean algorithm is as follows:
Example 3.38
*
– Compute modular inverse of 2 in Z11
By Theorem 3.1, p = 11 is prime ⇒ ϕ (11) = 102−1 ≡ 211−2 mod 9 = (24 ) * (25 ) mod 11 = 6
Check: 2 * 2−1 mod 11 = 2 * 6 mod 11 = 1
*
– Compute modular inverse of 2 in Z23
By Theorem 3.1, p = 23 is prime ⇒ ϕ (23) = 22
2−1 ≡ 223−2 mod 9 = 12
Check: 2 * 2−1 mod 9 = 2 * 12 mod 23 = 1
( )
Thus, α * α−1 − k * n = n * (−k ) + α * α−1 = 1 = GCD(n, α ).
( )
Hence, given α and n, applying the Extended Euclidean algorithm to n * (−k ) + α * α−1 = 1 returns −k and α−1. In other
words, we substitute n to a, α to b, −k to x, and α −1
to y in the equality ax + by = GCD(a, b) and keep the returned value for y.
In the congruence am mod n , a is called the base, m the exponent, and n the modulus. To compute am mod n , the right-
to-left binary exponentiation method is based on the reuse of powers of 2 of a. Let us see an example to show computation
principle of the method:
82 3 Mathematical Basics and Computation Algorithms for Cryptography
511 mod 14 ≡ ?
511 = 54 *2+2+1 (11, the power of 5, is expressed as a sum of powers of 2.)
4
( ) ( )
511 mod 14 ≡ 52 ∗ 52 ∗ 5 mod 14 .
By the modular arithmetic rules recalled above:
4
( ) ( )
511 mod 14 ≡ 52 mod 14 * 52 mod 14 * (5 mod 14) mod 14 .
2
Replace 5 mod 14 ≡ 11 and 5 mod 14 ≡ 5 in the previous equation:
4
(
511 mod 14 ≡ (11) * (11) * (5) mod 14 ≡ 115 * 5 mod 14 )
2
( ) 2
115 mod 14 ≡ 112 mod 14 * 11 mod 14 ≡ (9) * 11 mod 14 ≡ 9 .
Thus, 511 mod 14 ≡ 9 * 5 mod 14 ≡ 3.
The right-to-left binary exponentiation method computes ak mod n ≡ b as follows:
1) Convert k in binary notation k = kL−1kL−2 ⋅⋅⋅ k0 , ki ∈ {0,1}, (0 ≤ i ≤ L − 1).
i= L−1 i
2) Thus, k = ∑ i 2 * ki .
=0
(∑ i= L−1
*2i * ki ) = ∏i= L−1 2i
k
3) a is considered as a product of powers of 2 : ak = a
2i
i= 0
i=0 (a ) .
ki
function Right_to_Left_Binary_Exponentiation
input a: base; n: modulus; k: exponent
output res
res = 1; a = a mod n
while k > 0 do
return res
Definition 3.44 Montgomery reduction: let n and R be two integers such that R > n and GCD(n,R) = 1. For any
integer T, such that 0 ≤ T < n * R , the Montgomery reduction of T, denoted REDC (T ) modulo n w.r.t. R is defined by:
REDC (T ) = T * R−1 mod n.
Montgomery reduction function described below enables to quickly compute T * R−1 mod N from T :
function REDC
input T : integer such that 0 ≤ T < R * n
n, n′, R: integers
output t
1. m = (T mod R ) * n′ mod R
T +m*n
2. t =
R
3. if t ≤ n then t = t − n
4. return t (# t = T * R−1 mod n)
Next, the Montgomery reduction function REDC is used to compute the modular multiplication a ∗ b mod N as follows:
Example 3.39 We make use of the Montgomery reduction to find a ∗ b mod n with a = 43, b = 56, and n = 97.
n = 97 is less than 27 , we can pick R = 128 = 27.
n−1 mod R = 97−1 mod 27 = 33, −n−1 = 95 .
Montgomery conversion of arguments a and b:
a ≡ 43 * 27 mod 97 = 72, b ≡ 56 * 27 mod 97 = 87
= REDC (6264) = 55
c ′ ≡ REDC (a ∗ b)
c ≡ REDC (c ′) = 80, which is equal to 43 ∗ 56 mod 97.
Why does Montgomery’s method speed up the modulation multiplication?
1) First, in cryptosystems that use Montgomery multiplication, R, R−1, n−1, and n′ are computed once and used in several
modular multiplications. Therefore, their computation time has a negligible impact on the cryptosystem performance.
For example, in RSA the modulus n is computed from two large primes, then the public and private keys are computed
and the same pair (public and private keys) is used to encrypt and decrypt messages for a long time (maybe in months).
84 3 Mathematical Basics and Computation Algorithms for Cryptography
2) Second, when R is a power of 2, multiplication and division by R are efficiently performed with left and right bit-shift-
ing, which are very fast operations in hardware. Therefore, t in line 2 of DECR is computed with a w-right-shift.
3) Third, in line 1 of DECR function, mod R is used instead of mod n. Since R is a power of 2, mod R can be efficiently
computed with shifting operations as follows: for any integer x, x ≡ z mod R ≡ z mod 2 w . By definition of modulo
x x
z = x − w * 2 w . Therefore, z is computed by a w-right-shift (i.e. q = w ), a w-left-shift (i.e. p = q * 2 w ), and a subtrac-
2 2
tion (i.e. z = x − p).
X = ∑ li−1 w i l−1 i
=0 x i ∗ (2 ) = ∑ i=0 x i ∗ B , (0 ≤ x i < B, i = 0, …, l − 1)
function MultiprecisionAddition
input X , Y : two large integers X = ( x 0 ,…, x l−1 ) and Y = ( y 0 ,…, y l−1 )
# Integer with less than l words is left-padded with zero-words
B : base (in cryptography, B is a power of 2)
output S # sum represented in base B as S = ( s0 ,…, sl )
1. c = 0 # c is the carry digit. It is 0 or 1.
2. for i = 0 to l −1 do
si = ( x i + y i + c ) mod B
if ( x i + y i + c ) < B then c = 0 else c = 1
3. sl = c
4. return (S )
function MultiprecisionSubtraction
input X , Y : two large integers X = ( x 0 ,…, x l−1 ) and Y = ( y 0 ,…, y l−1 )
# Integer with less than l words is left-padded with zero-words
# To simplify the function, assume X ≥ Y
B: base (in cryptography, B is a power of 2)
output D # difference represented in base B as D = (d0 ,…, dl−1 )
1. c = 0 # c is the carry digit. It is 0 or -1
2. for i=0 to l −1 do
di = ( x i − y i + c ) mod B
if ( x i − y i + c ) ≥ 0 then c = 0 else c = −1
4. return (D )
function MultiprecisionMultilpication
input X , Y : two large integers X = ( x 0 ,…, x l−1 ) and Y = ( y 0 ,…, y k −1 )
# k ≤ l (arguments are ordered to reduce operations)
B : base (in cryptography, B is a power of 2)
3.3 Computation Algorithms 85
When computing modular multiplication X ∗ Y mod n over large integers, the Montgomery multiplication is valuable to
speed up computations. The modulus n and arguments and X and Y are represented as l words in base B:
l −1 i i, i.
n = ∑ i=0 ni ∗ ( B ) , X = ∑
l −1 l −1
i=0
x i ∗ ( B ) Y = ∑ i=0 yi ∗ ( B )
function MultiprecisionMontgomeryMultiplication
input n, X , Y : l-word integers; n is an odd integer
n': one-word integer
B: base (in cryptography, B is a power of 2)
l: word-length of arguments n, X , Y, R
# Condition:R = B l, R > n and GCD (R, n) = 1
output X ∗ Y ∗ R−1 mod n
1. A = 0 # A = (al−1 , al−2 ,…, a0 ), where a’s are words in base B.
2. for i=0 to l −1 do
A = A + x i ∗ Y ; q = A ∗ n′ mod B; A = ( A + n ∗ q ) / B
3. if A ≥ n then A = A − n
4. return A
The multi-precision Montgomery multiplication computes X ∗ Y ∗ R−1 mod n. Therefore, to find the modular multiplica-
tion, the returned result is multiplied by R.
Note. The multi-precision Montgomery multiplication makes use of multi-precision addition, subtraction, and multipli-
cation. In addition, division by n′ and mod B operations are performed using shift operations.
Example 3.40 n = 50021 (n is a prime), X = 15063, Y = 37551, Base B = 100
X is three 2-decimal-digit-words: X = (01, 50, 63).
We choose R = 100 4, which meets the conditions R > n and GCD( R, n) = 1.
R = 100 4 = 100l ⇒ l = 4
Compute n′ = − n−1 mod B
n′ = −50021−1 mod 100 = −81 mod 100 = 19.
Below are the computations in multi-precision Montgomery multiplication:
i xi A + xi ∗ Y q = A ∗ n′ mod B A = ( A + n ∗ q) / B
0 63 2365713 47 47167
1 50 1924717 23 30752
2 01 68303 57 29195
3 00 29195 5 2793
86 3 Mathematical Basics and Computation Algorithms for Cryptography
The multi-precision Montgomery multiplication returns 2793, which represents X * * R−1 mod n. Multiplying by R yields
( X * Y * R−1 ) * R mod n ≡ X * Y mod n.
Thus, 2793 ∗ 100 4 mod 50021 = 15063 ∗ 37551 mod 50021 ≡ 43266.
Theorem 3.26 Chinese remainder theorem: if k integer numbers ni , i = 1, …, k, are pairwise coprime and greater than
1, and if k numbers a1 , …, ak are such that 0 ≤ ai < ni for every i, then there is one and only one integer x such that:
i=k
0 ≤ x <∏i=1 ni and x ≡ ai modni , f or every i ∈ [1, k ].
Example 3.41
x ≡ 1 mod 5
x ≡ 2 mod 7
x ≡ 3 mod 9
x ≡ 4 mod 11
In the equation system above, n1 = 5, n2 = 7, n3 = 9, n4 = 11, a1 = 1, a2 = 2, a3 = 3, and a4 = 4. All ni’s are pairwise coprime
and 0 ≤ ai < ni for every i. x = 1731 is a solution, since:
i) 1731 < 5 ∗ 7 ∗ 9 ∗ 11 = 3465
ii) 1731 ≡ 1 mod 5 1731 ≡ 2 mod 7 1731 ≡ 3 mod 9 1731 ≡ 4 mod 11
Gauss’s algorithm
The Chinese remainder theorem says that there is a unique solution when some conditions are met, but it does not say how
to find it. This is usually done using Gauss’s algorithm.
Given a system of k congruence equations that fulfill the conditions of application of Chinese remainder theorem,
Gauss’s algorithm finds the solution to the congruence equation system as follows:
i =k
1) Compute the common modulus N = ∏i =1 ni
N
2) Let Ni = , for 1 ≤ i ≤ k
ni
3) Compute Ni−1 the modular inverse of Ni mod ni , for 1 ≤ i ≤ k
i.e. Ni ∗ Ni−1 ≡ 1mod ni, for 1 ≤ i ≤ k
4) The solution to the congruence equation system is
k
x = ∑ ai ∗ Ni ∗ Ni−1 mod N
( )
i =1
Example 3.42 Find x for the following congruence equation system using Gauss’s algorithm.
x ≡ 1 mod 5
x ≡ 2 mod 7
x ≡ 3 mod 9
x ≡ 4 mod 11
function Tonelli_Shanks
input p, a: prime p and integer a, with 0 < a < p
output r : r ∈ Z*p such that r 2 ≡ a mod p
1. # Use Euler’s criterion to check that a square root exists and stop,
# if it does not exist.
2. # Find q and s such that: p = 2s q + 1 and q is odd.
3. # In Z*p, select14 a quadratic nonresidue u.
4. # Variable initialization q +1
m = s ; c = u q mod p ; t = aq mod p ; R = a 2 mod p.
5. loop
5.1. if t = 1, then return r = R
5.2. else
i. k = 0
(2k
)
while not t ≡ 1mod p do: k = k +1
k
# the loop above is to find the least k , such that t 2 ≡ 1mod p.
ii. # Variable update
(m−k −1)
b = c2 mod p; m = k; c = b2 mod p
2
t = t ∗ b mod p; R = R ∗ b mod p
Such a naïve method is easy to understand and implement. Unfortunately, it suffers two weaknesses: 1) it does not scale
(remember that in cryptography very large numbers are used) and 2) a polynomial may be reducible even if it has no roots.
For example, in field F3 , x 4 + 2 x 2 + 1 can be written as a product ( x 2 + 1) ( x 2 + 1). Therefore, it is reducible, but it has no
roots in Z3, because ( x 2 + 1) has no roots in F3 .
Theorem 3.27. Rabin test’s of irreducibility: let f ( x ) be a polynomial of degree m over Fp. Then, f ( x ) is irreducible
over Fp if and only if: m
n
function Rabin_Irreducibilility_Test
input f ( x ): polynomial of degree m over a field Fq
m1, m2, …, mk are all distinct prime dividers of m
output “Reducible” or “Irreducible”
1. for j=1 to k do p j = m / m j
2. for j=1 to k dop
2.1 h ( x ) = x q − x mod f ( x )
j
Example 3.45
– Check of irreducibility of f ( x ) = x 4 + x 2 + x + 1 over F2
m = 4, so the prime divider of m is 2.
4
p1 = = 2
2
Iteration #1 (test of prime divider 2, i.e. p1 = 2):
x 2 = x 4 ≡ x 2 + x + 1 mod f ( x )
2
h( x ) = x 2 + x + 1 − x mod f ( x ) = x 2 + 1
g ( x ) = GCD( f ( x ), h( x )) = x + 1
g ( x ) ≠ 1; thus, f ( x ) is irreducible over F2 as it was checked by the naïve method (see Example 3.44). Stop the algorithm.
– Check of irreducibility of x 3 + x + 1 over F2
3.3 Computation Algorithms 91
Thus, f ( x ) is irreducible.
Exercise 3.20 Use the Euclidean algorithm to compute the GCD of:
1) 726 and 1144
2) 2184 and 16170
3) 113 and 13
Exercise 3.21 Use the Extended Euclidean algorithm to find GCD(654, 123) and to find integers u and v such that
654u + 123v = GCD(654, 123).
Exercise 3.22 Find the multiplication inverse of the following using the Extended Euclidean algorithm
1) 13−1 mod 31
2) 111−1 mod 4111
Exercise 3.23
1) Compute 147165 mod 23 with the right-to-left binary exponentiation method.
2) Use Fermat’s little theorem to reduce the number of iterations in the right-to-left binary exponentiation method.
Exercise 3.24
Compute X ∗ Y mod n , using the Montgomery multiplication with:
n = 50021 (50021 is a prime), X = 15063, Y = 37551, Base = 16 .
Exercise 3.25 Find x for the following congruence equation system using Gauss’s algorithm:
x ≡ 3 mod 5
S = x ≡ 1 mod 7
x ≡ 6 mod 8
Exercise 3.26 Use Gauss’s algorithm and Lemma 3.1 to compute 11372 000 000 000 013 mod 105 .
Exercise 3.27 Use the Tonelli-Shanks algorithm to find the square roots of:
1) 37 mod 43
2) 36 mod 43
3) 53 mod 97
Exercise 3.28 Find the solution(s) to y 2 ≡ 3 mod 143.
Exercise 3.29 Find the solution(s) to y 2 ≡ 421 mod 693 .
Exercise 3.30 Check the irreducibility of f ( x ) = x 10 + x 3 + 1 over F2 using Rabin’s test of irreducibility.
Exercise 3.31 Check that f ( x ) = x 5 + x 4 + x 3 + x 2 + x − 1 is irreducible over F3 using Rabin’s test of irreducibility.
Problem 3.16
1) Compute 147155 mod 23 using Fermat’s little theorem.
2) How many iterations are needed to compute 147155 mod 23 with the right-to-left binary exponentiation? What do you
conclude?
92 3 Mathematical Basics and Computation Algorithms for Cryptography
Problem 3.17
1) Prove the correctness of the Montgomery reduction function REDC, i.e. prove that t = T * R−1 mod n .
2) Prove the correctness of the Montgomery multiplication algorithm based on REDC.
First of all, it is worth noticing that Birthday paradox is used to find the complexity of some attacks against cryptographic
algorithms that will be discussed in next chapters.
Birthday paradox, also referred to as Birthday problem, is relating to the probability that, in a set of n randomly chosen
people, a pair of them will have the same birthday. In a group of 23 people, the probability of a same birthday exceeds 50%,
while a group of 70 has a 99.9% chance of a same birthday. Birthday problem is a paradox, because it first appears counter-
intuitive that with 23 people, there is 50% chance that two people share the same birthday.
Proof:
It is assumed that all 365 birthdays have the same probability of occurrence.
Let P (n) represent the probability that at least a pair among the n people have the same birthday.
P (n) = 1 − P (n) represents the probability that no pair among the n people have the same birthday. It is obvious to deduce
that P (n) = 0, if n ≥ 365.
Let us consider n < 365:
Without loss of generality, assume that persons are numbered from 1 to n.
P (n) = p (1) ∗ p (2) ∗ p (3) ∗…∗ p (n − 1)
p(1) is the probability that person 2 does share birthday with person 1 and p (k ) is the probability that person k + 1 does
share birthday with the other k persons.
365 − 1 365 − 2 365 − 3 365 − (n − 1)
P (n) = * * * … * .
365 365 365 365
After some arrangements,
365 !
P (n ) = .
365n (365 − n)!
□
365 !
Thus, P (n) = 1 −
365n (365 − n)!
Using the approximation below, to have 50% chance that at least a pair of persons have the same birth-
1
day, n ≈ 2 * 365 * ≈ 20 and n ≈ 2 * 365 * ln(2) ≈ 23 for the first and second approximations, respectively.
2
If P (n) = 0.5, the first approximation results in n ≈ M and the second in n ≈ 2 * M * ln(2) ≈ 1.18 M .
In [12] and other references in literature, the following bounds have been proven to delimit the collision proba-
bility P (n, M ). The first upper bound is as follows:
n (n − 1)
P (n, M ) ≤
2M
If is large, may n is large, n2 − n may be approximated by n2. Thus, a second upper bound is used:
n2
P (n, M ) ≤
.
2M
The upper bound to probability of no collision P (n, M ) is
q(q−1)
−
P (n, M ) ≤ e 2N
.
Thus, the lower bound to P (n, M ) becomes
q(q−1)
−
1− e 2N
≤ P (n, M ).
The following property holds for any real number x ∈ 0,1:
(1 − e−1 ) * x ≤ 1 − e− x ≤ x .
Finally, using the property above, the lower bound to P (n, M ) can be approximated as:
q (q − 1)
0.316 * ≤ P (n, M ).
N
Exercise 3.1
Pro perties of Euler’s totient function are given by Theorem 3.1.
1) N = 17 is a prime. Hence, all the 16 integers in range 1,16 are coprime to 17.17 is prime ⇒ ϕ (17) = 17 − 1 = 16.
2) N = 42:
12 integers, which are coprime to 42, are: 1, 5, 11, 13, 17, 19, 23, 25, 29, 31, 37, 41.
42 = 7 ∗ 3 ∗ 2 ⇒ ϕ (42) = (7 − 1)(3 − 1)(2 − 1) = 12.
3) N = 25:
20 integers, which are coprime to 25, are: 1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24
25 = 52 ⇒ ϕ (25) = (52 − 5) = 20 .
Exercise 3.2
1) More generally, a′ is the additive inverse of a modulo p if a′ + a ≡ 0 mod p and a−1 is the multiplicative inverse of a
modulo p if a ∗ a−1 ≡ 1 mod p. The additive inverse of 27 is 73, because if 27 + 73 ≡ 0 mod 100 and its multiplicative
inverse is 63, because if 27 ∗ 63 = 1701 ≡ 1 mod 100.
2) By properties of Euler’s phi function (Theorem 3.1):
● 101 is prime. Thus, ϕ (101) = 100
● 102 = 2 ∗ 3 ∗ 17. Thus, ϕ (102) = ϕ (2) ∗ ϕ (3) ∗ ϕ (17) = 1 ∗ 2 ∗ 16 = 32
● 500 = 22 ∗ 53. Thus, ϕ (500) = (22 − 21 )(53 − 52 ) = 200 .
94 3 Mathematical Basics and Computation Algorithms for Cryptography
Exercise 3.3
1) Find x such that 3 x ≡ 13 mod 17: we can use a trial-and-error method and find x = 4.
34 = 81 = 4 * 17 + 13 ⇒ 34 13 mod 17
2) If x ≤ 5, there is no solution to 4 x ≡ 5 mod 31, because 41 , 42 , 43 , 4 4 , and 45 are not congruent to 5 mod 31. In particular,
45 ≡1 mod 31.
If x is greater than 5, it can be written as x = 5k + x ′, for some positive integer k and x ′ , an integer less than 5. Thus,
k
4 x mod 31 ≡ (45 ) (4) mod 31 ≡ (1) (4) mod 31 ≡ 4 x ′ mod 31.
x′ k x′
/ 5 mod 31. Therefore, there does not exist x such that 4 x ≡ 5 mod 31.
Since x ′ is less than 5, 4 x ′ ≡
3) In general, the modular exponentiation is an invertible function. It is what is called Discrete Logarithm Problem.
Exercise 3.4
By definition of multiplicative inverse, a has an inverse modulo n, if and only if GCD(a, n) = 1. Thus, Z9* has only six ele-
ments; Z9* = {1, 2, 4, 5, 7, 8}.
Euler’s theorem (Theorem 3.4 states that if a ∈ Zn* , then a ( ) ≡ 1 mod n, which can be written as a * a ( ) ≡ 1 mod n. Using
ϕ n ϕ n −1
By definition of Euler’s totient (Theorem 3.1), ϕ (9) = (33 − 3) = 6 . Therefore, using Euler’s theorem, the inverses are
computed and checked as follows:
1−1 ≡ 15 mod 9 ≡ 1. Check: 1 * 1 ≡ 1 mod 9
2−1 ≡ 25 mod 9 ≡ 5. Check: 2 * 5 = 10 ≡ 1 mod 9
4−1 ≡ 45 mod 9 ≡ 7. Check: 4 * 7 = 28 ≡ 1 mod 9
5−1 ≡ 55 mod 9 ≡ 2. Check: 5 * 2 = 10 ≡ 1 mod 9
7−1 ≡ 75 mod 9 ≡ 4. Check: 7 * 4 = 28 ≡ 1 mod 9
8−1 ≡ 85 mod 9 ≡ 8. Check: 8 * 8 = 64 ≡ 1 mod 9.
Let us try to find 3−1 using Euler’s theorem:
3−1 ≡ 35 mod 9 ≡ 0, which is incongruous, since 0 is not the inverse of any other integer. Therefore, Euler’s theorem is
applicable only if a and n are coprime.
Exercise 3.5
If n is prime and n and a are coprime, then Fermat’s little theorem states that an−1 ≡ 1 mod n, which can be rewritten as
a * an−2 ≡ 1 mod n . Using the definition of inverse, we deduce that an−2 is the inverse of a.Euler’s theorem states that if
a ∈ Zn* , then a ( ) ≡ 1 mod n, which can be written as a * a ( ) ≡ 1 mod n. Using the definition of inverse, we deduce that
ϕ n ϕ n −1
a ( ) is the inverse of a.
ϕ n −1
1) a = 6, n = 7:
7 is prime and coprime to 6. Thus, Fermat’s little theorem is applicable.
6−1 ≡ 65 mod 7 ≡ 6 . Check: 6 * 6 ≡ 1 mod 7.
2) a = 7, n = 15 :
15 is not prime. Thus, Fermat’s little theorem is not applicable. We use Euler’s theorem.
By Theorem 3.1, ϕ (15) = (5 − 1)(3 − 1) = 8
7−1 ≡ 78−1 mod 15 ≡ 13.
Check: 7 * 13 mod 15 ≡ 1
3) a = 19, n = 101:
101 is prime and coprime to 19. Thus, Fermat’s little theorem is applicable.
19−1 ≡ 1999 mod 101
19−1 ≡ (193* 25 )(1919 )(195 ) mod 101 ≡ 1 ∗ 5 ∗ 84 mod 101 ≡ 16 .
Check: 19 ∗ 16 mod 101 ≡ 1
4) a = 97, n = 100:
100 is not prime. Thus, Fermat’s little theorem is not applicable. We use Euler’s theorem.
By theorem 3.1, ϕ (100) = (25 − 5)(4 − 2) = 40
97−1 ≡ 9739 mod 100 ≡ (9720 ∗ 9719 ) mod 100 ≡ 33.
Check: 97 ∗ 33 mod 100 ≡ 1
3.5 Solutions to Exercises and Problems 95
Exercise 3.6
1) x ≡ 4100 mod 17
42 ≡ − 1 mod 17
50
Thus, 4100 ≡ mod 17 ≡ 42 *50 mod 17 ≡ (−1) mod 17 ≡ 1.
Therefore, x = 1.
2) 9 x ≡ 13 mod 17
92 ≡ 13 mod 17. Therefore, x = 2
3) 5 x ≡ 13 mod 17
52 ≡ 8 mod 17
(52 ) ∗ (52 ) ≡ 8 ∗ 8 mod 17 = 13. Therefore, x = 4
4) 7 x ≡ 11 mod 13
(72 ) ∗ (72 ) ∗ (71 ) ≡ 10 ∗ 10 ∗ 7 mod 13 = 9 ∗ 7 mod 13 = 11.
Therefore, x = 5.
Exercise 3.7
By definition, the order of a group is the number of the group elements.
1) Z7*: 7 is prime. Thus, Z7* = 7 .
* *
2) Z101 : 101 is prime. Thus, Z101 = 101.
* *
3) Z18 : 18 is not prime. Thus, we need to identify the invertible elements that belong to Z18 . In general, an integer a ∈ Zn* ,
if and only if GCD(a, n) = 1.Thus, Z18 = {1, 5, 7, 11, 13, 17} and Z18 = 6.
* *
Exercise 3.8
By definition, the order of an element a ∈ Zn* is the smallest integer k such that
1) ak ≡ 1 mod n.
2) 212 ≡ 1 mod 13. Thus, ord (2) = 12.
3) 54 ≡ 1 mod 13. Thus, ord (5) = 4 .
4) 33 ≡ 1 mod 13. Thus, ord (3) = 3.
Exercise 3.9
2
1) Calculate in Z8*
5
2
= 2 * 5−1
5
5 * 5 ≡ 1 mod 8; hence, 5−1 = 5
2
Hence, = 2 * 5 = 2 in Z8*.
5
2) Is Z6* a cyclic group?
Recall that an integer b has a multiplicative inverse mod p if and only if GCD(b, p) = 1. Thus, Z6* = {1, 5}.
Recall that a cyclic group is a finite group that is generated by a single element g, called generator.
50 ≡ 1 mod 6 , 51 ≡ 5 mod 6 .
Hence, 5 is a generator for Z6*. Therefore, Z6* is a cyclic group.
3) Is Z8* a cyclic group?
Z8* = {1, 3, 5, 7}
30 ≡ 1 mod 8, 31 ≡ 3 mod 8 32 ≡ 1 mod 8 33 ≡ 3 mod 8 …
2 3
50 ≡ 1 mod 8, 51 ≡ 5 mod 8 5 ≡ 1 mod 8 5 ≡ 5 mod 8 …
2 3
7 0 ≡ 1 mod 8, 7 ≡ 7 mod 8 7 ≡ 1 mod 8 7 ≡ 7 mod 8 …
1
* * *
No element in Z8 can generate Z8. Therefore, Z8 is not a cyclic group.
Exercise 3.10
707 411
99707 mod 100 = (100 − 1)
411
mod 100 .
m
By Lemma 3.1, for integers a, m, and n, a mod n = (a mod n) mod n .
m
411 411
Thus, 99707 mod 100 = (−1)707 mod 100.
The exponent 707 411 is odd. Thus, there exists k such that 707 411 = 2k + 1.
2k
99707 mod 100 = (−1) * (−1) mod 100 = 99.
411
96 3 Mathematical Basics and Computation Algorithms for Cryptography
Exercise 3.11
More generally (by Theorem 3.9), if p is a prime number, then Z p* has ϕ (ϕ ( p)) generators (also called primitive roots), where
ϕ() is the Euler’s totient function. By Theorem 3.1, since 29 is prime, φ (29) = 28. Integers between 1 and 28, which are coprime
with 28, are {1, 3, 5, 9, 11, 13, 15, 17, 19, 23, 25, 27}. Thus, φ (28) = 12. Therefore, by Theorem 3.9, Z29
*
has 12 generators.
Exercise 3.12
In general, to build the multiplication table of a finite field Fpm with an irreducible polynomial f ( x ):
i) associate with each element i ∈ Fpm a polynomial Pi ( x ) of degree m and with coefficients in Fp.
ii) compute Ri, j ( x ) ≡ ( Pi ( x ) * Pj ( x )) mod f ( x ) for all pairs of elements i and j in Fpm .
m −1
iii) Let MulTab be the multiplication table of 8 rows by 8 columns. MulTab [i, j] = ∑ k =0 (2k * ri, j ,k ), ∀ i ∈ [0, m − 1],
∀ j ∈ [0, m − 1], where ri, j , k , k = 0, …, m − 1, are the binary coefficients of the polynomial Ri, j ( x ).
Now, build the multiplication table of field F23 with the irreducible polynomial f ( x ) = x 3 + x 2 + 1:
F23 = {0, 1, 2, 3, 4, 5, 6, 7}.
* 0 1 2 3 4 5 6 7
0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7
2 0 2 4 6 5 7 1 3
3 0 3 6 5 1 2 7 4
4 0 4 5 1 7 3 2 6
5 0 5 7 2 3 6 4 1
6 0 6 1 7 2 4 3 5
7 0 7 3 4 6 1 5 2
Notice that all the nonzero elements of F23 appear seven times in the table.
Exercise 3.13
Elements of field F32 are {0, 1, 2, 3, 4, 5, 6, 7, 8}.
f ( x ) = x 2 + 2 x + 2 is irreducible over field F3 .
Note that in F3 : −1 ≡ 2 mod 3 and − 2 ≡ 1 mod 3.
Also note that coefficients in polynomial representation of elements of F32 are in {0, 1, 2}. Polynomial representation of the
elements of field F32 :
P0 ( x ) = 0 P1 ( x ) = 1 P2 ( x ) = 2
P3 ( x ) = x P4 ( x ) = x + 1 P5 ( x ) = x + 2
P6 ( x ) = 2 x P7 ( x ) = 2 x + 1 P8 ( x ) = 2 x + 2
Pi ( x ) denotes the polynomial associated with element i of field F32 .
1) 4+5:
( x + 1) + ( x + 2) = 2 x + 3 = 2 x + x = 3 x = 0. Therefore, 4 + 5 = 0.
2) 3 * 2 :
( x ) * (2) mod f ( x ) ≡ 2 x . Therefore, 3 ∗ 2 = 6.
3) 4 * 5:
( x + 1) * ( x + 2) = x 2 + 3 x + 2 = x 2 + 2
x 2 + 2 mod ( x 2 + 2 x + 2 ) ≡ −2 x = x . Therefore, 4 ∗ 5 = 3.
4) 82:
(2 x + 2) * (2 x + 2) = 4 x 2 + 8 x + 4 = x 2 + 2 x + 1 mod f(x)
x 2 + 2 x + 1 mod f ( x ) ≡ − 1 ≡ 2. Therefore, 82 = 2.
Exercise 3.14
Recall that adding/subtracting twice the same element with coefficients in F2 is equivalent to adding/subtracting 0, which
has no effect.
Let f ( x ) = x 4 + x + 1 be the irreducible polynomial used in multiplication over F24 .
1) Compute x −1 and x −3
( x ) * ( x + 1)) mod ( x + x + 1) ≡ 1 ⇒ x = x + 1
3 4 −1 3
(( x ) * ( x + x + x + 1)) mod ( x + x + 1) ≡ 1 ⇒ x
3 3 2 4 −3
−1
= x 3 + x 2 + x + 1.
2) Compute ( x 2 ) / ( x 3 + x 2 + 1) = ( x 2 ) * ( x 3 + x 2 + 1)
First, compute the inverse of ( x 3 + x 2 + 1) mod ( x 4 + x + 1)
(x 3
+ x 2 + 1) * x 2 = x 5 + x 4 + x 2 = x 5 + x 4 + x 2 + ( x − x ) + (1 − 1)
= x ( x 4 + x + 1) + ( x 4 + x + 1) + 1
(x 3
+ x 2 + 1) * x 2 mod ( x 4 + x + 1) ≡ 1.
−1
Thus, ( x 3 + x 2 + 1) mod ( x 4 + x + 1) ≡ x 2 .
98 3 Mathematical Basics and Computation Algorithms for Cryptography
Therefore, ( x ) / ( x + x + 1) = x + 1.
2 3 2
(x 2
+ x + 1) * ( x 2 + x ) = x 4 + x 3 + x 2 + x 3 + x 2 + x = x 4 + x
(x 2
+ x + 1) * ( x 2 + x ) mod ( x 4 + x + 1) ≡ 1.
−1
Thus, ( x 2 + x + 1) mod ( x 4 + x + 1) ≡ ( x 2 + x ) .
Second, compute ( x 3 + x 2 + x ) * ( x 2 + x ) mod ( x 4 + x + 1)
(x 3
+ x2 + x) * (x2 + x) = (x5 + x2 )
(x 5
+ x 2 ) mod ( x 4 + x + 1) ≡ x .
Therefore, ( x 3 + x 2 + x ) / ( x 2 + x + 1) = x .
14
In numeric form, = 2.
7
4) All the previous computations make use of multiplication in a finite field, which—by design—is based on a computa-
tion modulo f ( x ). Therefore, if f ( x ) changes, the computation results change.
Exercise 3.15
Check of polynomial reducibility in field F2 . Recall that adding twice the same polynomial with coefficients in F2 is
equivalent to adding 0.
( )
1) f1 ( x ) = x 6 + x 4 + x 2 = x 2 x 4 + x 2 + 1 . Hence, f1 ( x ) is reducible in F2 .
2) f2 ( x ) = x + 1 = x + (2 x ) + 1 = ( x + 1)( x 2 + x + 1) . Hence, f2 ( x ) is reducible in F2 .
3 3 2
Exercise 3.16
Let us consider the extension field F32 under polynomial f ( x ) = x 2 + x + 2 irreducible over F3 . α is a root of f ( x ) .
Thus, α 2 + α + 2 = 0 ⇒ α 2 = −α − 2 = 2α + 1.
The powers, till 32 − 2 , of α give:
α 0 = 1 α1 = α
α 2 = 2α + 1 α3 = α (2α + 1) = 2α + 2
α 4 = α (2α + 2) = 2 α5 = α (2) = 2α
α 6 = α (2α ) = α + 2 α 7 = α (α + 2) = α + 1.
Thus, α can generate all nonzero elements of F32 . The latter can be written in three forms:
F32 = { 0, 1, 2, 3, 4, 5, 6, 7, 8}
= 0, { 0
α , α , 4 1
α, α , 7
α , 6
α , 5
α , 2
α3 }
= { 0, 1, 2, α, α + 1, α + 2, 2α, 2α + 1, 2α + 2}.
Exercise 3.17
α = 3 is a root of f ( x ) = x 2 + x + 2 over F32 .
3.5 Solutions to Exercises and Problems 99
1) Compute 3−1
f (α ) = α 2 + α + 2 = α (α + 1) + 2 = 0 ⇒ α (α + 1) = −2 = 1 .
(
Thus, (α + 1) is the inverse of α . Therefore, 3−1 = 4 over F32 / x 2 + x + 2 . )
2) Compute 37
Since α is a root of f ( x ) , f (α ) = α 2 + α + 2 . Thus, α 2 = −α − 2 = 2α + 1
(α)
7
( 2
)
= α 2 * α 2 * α 2 * α = (2α + 1) * (2α + 1) * α
(( ) )
= α + α + 1 (2α + 1) * α = ((2)(2α + 1)) * α
2
= (α + 2) * α = α + 2α = 2α + 1 = 1
2
Thus, 37 = 1 .
3) Compute 37k
k
(3)
7k
= 37( ) = (1) = 1
k
4) Compute 6 * 7
6 = 2α , 7 = 2α + 1
2α * (2α + 1) = 4α 2 + 2α = α 2 + 2α = 2α + 1 + 2α = α + 1 .
Thus, 6 * 7 = 4 .
Exercise 3.18
Let x 4 + x + 1 be a polynomial irreducible over F2 associated with the field F24 .
Do the following operations over F24 :
1) 9 * 6 =?
9 is represented by polynomial x 3 + 1 and 6 by x 2 + x .
( x 3 + 1)( x 2 + x ) mod ( x 4 + x + 1) = x + 1.
Thus, 9 * 6 = 3 over field F24 .
2) 9−1 = ?
x i ≡ x 3 + 1 mod (x 4 + x + 1) ⇒ i = 14.
9 is represented by polynomial x 3 + 1 and 2 by x .
Hence, 9−1 = 2 .
357
3) (9 + 1) = ?
9 is represented by polynomial x 3 + 1 and 1 by constant polynomial 1. Thus, the addition over F24 , is ( x 3 + 1) + (1) = x 3.
4
2 is chosen as generator, which is represented by polynomial x . By Theorem 3.22, x 2 −1 = x 15 ≡ 1 mod f ( x ).
(9 + 1)357 is represented by polynomial x 3∗357 = x (15∗71)+6 .
3*357
Thus, x ≡ (171 )( x 6 ) mod f ( x ) = x 3 + x 2.
Hence, (9 + 1)357 = 12 .
Exercise 3.19
1) Addition in field binary F28 is an XOR operation.
01010011 + 11001010 = 10011001.
2) Find the product of 01010011*11001010 over F28 with reduction polynomial f ( x ) = x 8 + x 4 + x 3 + x + 1.
Represent bit strings as polynomials, then find the mod f ( x ):
01010011 → A( x ) = x 6 + x 4 + x + 1
11001010 → B ( x ) = x 7 + x 6 + x 3 + x
01010011*11001010 = C | C( x ) = A( x ) * B ( x ) mod f ( x )
A( x ) * B ( x ) = x 13 + x 12 + x 11 + x 10 + x 9 + x 8 + x 6 + x 5 + x 4 + x 3 + x 2 + x
A( x ) * B ( x ) mod f ( x ) = 1.
Thus, 01010011*11001010 = 00000001.
3) Find the multiplicative inverse of 00000010, in field F28 with reduction polynomial f ( x ) = x 8 + x 4 + x 3 + x + 1.
a = 00000010 is represented by polynomial A( x ) = x .
100 3 Mathematical Basics and Computation Algorithms for Cryptography
2) Steps of computation of GCD(16170, 2184) are shown in Figure 3.2. The remainder of the 3rd step, i.e. 42, is the GCD of
16170 and 2184 .
3) Steps of computation of GCD(113, 13) are shown in Figure 3.3. The remainder of the 3rd step, i.e. 1, is the GCD of 113
and 13 .
Exercise 3.21
The steps of computation of GCD(654, 123) are as follows:
1st step: 654 = 123 ∗ 5 + 39
2nd step: 123 = 39 ∗ 3 + 6
3rd step: 39 = 6 * 6 + 3 4th step: 6 = 3 * 2 + 0
Thus, GCD(654, 123) = 3.
To find u and v such that 654u + 123v = GCD(654, 123), do backward calculations starting from the result of the 3rd step:
3 = 39 − 6 * 6
= (654 − 123 * 5) − 6 * (123 − 39 * 3)
= (654 − 123 * 5) − 6 * 123 + (39 * 18)
= (654 − 123 * 5) − 6 * 123 + 18 * (654 − 123 * 5)
= 654 * 19 + 123 * (−5 − 6 − 90)
= 654 * 19 + 123 * (−101)
Exercise 3.23
1) 147165 mod 23 ≡ ?
165 = 128 + 32 + 4 + 1 = 27 + 25 + 22 + 20
L = 8, k7 = 1, k6 = 0, k5 = 1, k4 = 0, k3 = 0, k2 = 1, k1 = 0, k0 = 1
20
( )
b0 ≡ 1471
1
mod 23 ≡ 147 mod 23 ≡ 9
2
b1 ≡ (147 0 ) mod 23 ≡ 1
2
2
b2 ≡ (1471 )
4
mod 23 ≡ 147 4 mod 23 ≡ (147 mod 23) mod 23 ≡ 6
3
2
b3 ≡ (147 0 ) mod 23 ≡ 1
4
2
b4 ≡ (147 0 ) mod 23 ≡ 1
5
2
b5 ≡ (1471 )
32
mod 23 ≡ 14732 mod 23 ≡ (147 mod 23) mod 23 ≡ 18
6
2
b6 ≡ (147 0 ) mod 23 ≡ 1
7
2
b7 ≡ (1471 )
32 * 4
mod 23 ≡ 137128 mod 23 ≡ (147 mod 23) mod 23 ≡ 4
165
147 mod 23 ≡ 9 ∗ 1 ∗ 6 ∗ 1 ∗ 1 ∗ 18 ∗ 1 ∗ 4 mod 23 ≡ 3888 mod 23 ≡ 1 .
2) Fermat’s little theorem states that if p is prime and a is an integer not divisible by p, then a p−1 ≡ 1 mod p .
By Fermat’s little theorem, 14722 mod 23 ≡ 1, because 147 is not divisible by 23.
Also, 14722*7 mod 23 ≡ 1.
( )( )
Thus, 147165 mod 23 ≡ 14722∗7 147165−22∗7 mod 23 ≡ 17 ∗ 14711 mod 23.
11
Then, solve 147 mod 23 using the right-to-left binary exponentiation method.
11 = 8 + 2 + 1 = 23 + 2 + 1
L = 4, k3 = 1, k2 = 0, k1 = 1, k0 = 1
20
( )
b0 ≡ 1471
1
mod 23 ≡ 147 mod 23 ≡ 9
2
b1 ≡ (1471 )
2
mod 23 ≡ (9) mod 23 ≡ 12
2
2
b2 ≡ (147 0 ) mod 23 ≡ 1 mod 23
3
2
b3 ≡ (1471 )
4
mod 23 ≡ (12) mod 23 ≡ 13
147165 mod 23 ≡ 9 ∗ 12 ∗ 1 ∗ 13 mod 23 ≡ 1.
Therefore, using Fermat’s little theorem before applying the binary exponentiation algorithm reduces significantly the
number of squaring and multiplication operations.
Exercise 3.24
n = 50021 , X = 15063 , Y = 37551, Base B = 16.
Hexadecimal representation of arguments:
n = 5002110 = C 36516
X = 1506310 = 3 AD716 , Y = 3755110 = 92 AF16
X is four 16-bit words: X = (3, 10, 13, 7) . Words are in decimal representation to make the computations by hand easy.
We keep R = 164 , which meets the conditions R > n and GCD ( R, n) = 1 .
R = 164 = 16l ⇒ l = 4 .
Compute n′ = − n−1 mod B : n′ = −50021−1 mod 16 = −13 mod 16 = 3 .
Below are the computations in multi-precision Montgomery multiplication:
3.5 Solutions to Exercises and Problems 103
i xi A + xi * Y q = A * n′ mod B A = ( A + n * q) / B
0 7 262857 11 50818
1 13 538981 15 80581
2 10 456091 1 31632
3 3 144285 7 30902
−1
The multi-precision Montgomery multiplication returns 30902, which represents X * Y * R mod n. Multiplying by R
( −1
)
yields X * Y * R * R mod n ≡ X * Y mod n.
Thus, 30902 ∗ 164 mod 50021 = 15063 ∗ 37551 mod 50021 ≡ 43266.
Exercise 3.25
Let us consider the following congruence system:
x ≡ 3 mod 5
S = x ≡ 1 mod 7
x ≡ 6 mod 8
( (
x = ∑3i=1 ai * N i * N i−1 mod N ))
= ((3 * 56 * 1) + (1 * 40 * 3) + (6 * 35 * 3)) mod 280
= 918 mod 280 = 78.
Check: 78 ≡ 3 mod 5, 78 ≡ 1 mod 7, 78 ≡ 6 mod 8
Exercise 3.26
105 = 3 * 5 * 7
● 113 ≡ 2 mod 3
By Lemma 3.1:
72 000 000 000 013
10372 000 000 000 013 ≡ (2) mod 3
72 000 000 000 012
( )( )
≡ 21 * 22 2 mod 3
72 000 000 000 012
≡ 2 * (1) 2 mod 3 = 2 (because 22 ≡ 1 mod 3 )
● 113 ≡ 3 mod 5
By Lemma 3.1:
72 000 000 000 013
11372 000 000 000 013 mod 5 ≡ (3) mod 5
72 000 000 000 012
( )( )
≡ 31 * 34 4 mod 5
72 000 000 000 012
≡ 3 * (1) 4 mod 5 = 3 (because 34 ≡ 1 mod 5)
104 3 Mathematical Basics and Computation Algorithms for Cryptography
● 113 ≡ 1 mod 7 .
By Lemma 3.1:
72 000 000 000 013
11372 000 000 000 013 mod 7 ≡ (1) mod 7 = 1.
● Thus, we have the following congruences:
11372 000 000 000 013 ≡ 2 mod 3
11372 000 000 000 013 ≡ 3 mod 5
11372 000 000 000 013 ≡ 1 mod 7.
There exist two positive integers k and x < 105, such that 11372 000 000 000 013 = k * 105 + x . Thus, from the congruences
above, we derive the following congruence equation system:
x ≡ 2 mod 3
S = x ≡ 3 mod 5
x ≡ 1 mod 7
The constant of the congruence system above are: n1 = 3, n2 = 5 , n3 = 7 , a1 = 2 , a2 = 3 , and a3 = 1 . All moduli are pair-
wise coprime and ai < ni , for i = 1, 2, 3. Therefore, the conditions to use the Chinese remainder theorem are met. Hence,
according to the CRT there exists a unique value of x mod 3 ∗ 5 ∗ 7 that satisfies the three congruences. The solution to
the congruence equation system is as follows:
N ≡ 3 ∗ 5 ∗ 7 = 105
N1 = 5 ∗ 7 = 35 N 2 = 3 * 7 = 21 N 3 = 3 * 5 = 15
Exercise 3.27
1) First, use the Euler’s criterion (Theorem 3.7) to test if 37 mod 43 has a solution.
( )
43−1 /2
37 ≡ 42 mod 43 = −1. Therefore, no solution exists.
2) First, use the Euler’s criterion to test if 36 mod 43 has a solution.
( )
43−1 /2
36 ≡ 1 mod 43 . Thus, two solutions exist.
The steps of Tonelli-Shanks algorithm are as follows:
43 = 21 * 21 + 1 . Thus, s = 1 and q = 21.
Find a square nonresidue modulo 43. u = 2 is a square nonresidue.
Initialization: m = 1; c = 221 mod 43 = 42; t = 3621 mod 43 = 1
(21+1)/2
R = 36 mod 43 = 6.
Loop: the algorithm stops at the first iteration, because t = 1, and returns r = 6.
2
Check: (±6) ≡ 36 mod 43 .
3) First, use the Euler’s criterion to test if 53 mod 97 has a solution.
(97−1)/2
53 ≡ 1 mod 97. Thus, two solutions exist.
The steps of Tonelli-Shanks algorithm are as follows:
97 = 25 * 3 + 1 . Thus, s = 5 and q = 3.
Find a square nonresidue modulo 97 : u = 5 is a square nonresidue.
Initialization: m = 5; c = 53 mod 97 = 28; t = 533 mod 97 = 79
(3+1)/2
R = 53 mod 97 = 93.
Loop:
3.5 Solutions to Exercises and Problems 105
x ≡ 5 mod 11 x ≡ 5 mod 11
S1 = S2 =
x ≡ 4 mod 13 x ≡ 9 mod 13
x ≡ 6 mod 11 x ≡ 6 mod 11
S3 = S4 = .
x ≡ 4 mod 13 x ≡ 9 mod 3
Use Gauss’s algorithm to find the solutions to each of the four congruence systems. Below, only the calculations to solve
S1 are included.
The constants of congruence equation system S1 are: n1 = 11 , n2 = 13, a1 = 5 , a2 = 4 .
Common modulus is N = 11 * 13 = 143 .
N1 = 1111*13 = 13 , N 2 = 1113*13 = 11.
Now, check that the four values are square roots of 3 mod 143
x = 82 : 822 = 6724 ≡ 3 mod 143
x = 126 : 1262 = 15876 ≡ 3 mod 143
x = 17 : 172 = 289 ≡ 3 mod 143
x = 61 : 612 = 2304 ≡ 3 mod 143.
Thus, 3 mod 143 has four square roots.
Exercise 3.29
Find the solution(s) to y 2 ≡ 421 mod 693.
Since 693 = 7 * 9 * 11 is a product of three primes, there should exist 23 square roots. Procedure to find the square roots in
case of multiple primes is composed of two steps:
Step 1: Find the square roots of prime factors.
By Lemma 3.2:
x ≡ 421 mod 7 ⇒ x ≡ 1 mod 7
x ≡ 421 mod 693 x ≡ 421 mod 9 ⇒ x ≡ 7 mod 9
x ≡ 421 mod 11 ⇒ x ≡ 3 mod 11
Find square roots for each of the three congruences above:
1 mod 7 has two square roots: r1 = 1 and −r1 = 6.
7 mod 9 has two square roots: r2 = 4 and −r2 = 5.
3 mod 11 has two square roots: r3 = 5 and −r3 = 6.
Step 2: Find solutions to congruence systems.
From the squares roots of the primes factoring 693, eight congruence systems are derived:
x ≡ 1 mod 7 x ≡ 1 mod 7
S1 = x ≡ 4 mod 9 S2 = x ≡ 4 mod 9
x ≡ 5 mod 11 x ≡ 6 mod 11
x ≡ 6 mod 7 x ≡ 6 mod 7
S7 = x ≡ 5 mod 9 S8 = x ≡ 5 mod 9
x ≡ 5 mod 11 x ≡ 6 mod 11
Gauss’s algorithm is used to find solutions to the eight congruence systems. Below are calculations to solve S1 system:
The constants of the congruence equation system are n1 = 7, n2 = 9, n3 = 11, a1 = 1, a2 = 4, a2 = 5 .
Common modulus is N = 7 * 9 * 11
7 * 9 * 11 7 * 9 * 11 7 * 9 * 11
N1 = = 99, N 2 = = 77, N 3 = = 63.
7 9 11
Multiplicative inverses:
N1−1 * N1 ≡ 1 mod 7 ⇒ N1−1 = 1
Applying the SRT to the eight congruence systems yields the following:
x = 148 is a solution to S1 x = 589 is a solution to S2
x = 302 is a solution to S3 x = 50 is a solution to S4
x = 643 is a solution to S5 x = 391 is a solution to S6
x = 104 is a solution to S7 x = 545 is a solution to S8 .
Check if the eight solutions to the congruence systems are square roots of
421 mod 693 :
x = 148 : 1482 = 21904 ≡ 421 mod 693
x = 589 : 5892 = 346921 ≡ 421 mod 693
x = 302 : 3022 = 91204 ≡ 421 mod 693
x = 50 : 502 = 2500 ≡ 421 mod 693
x = 643 : 6432 = 413449 ≡ 421 mod 693
x = 391 : 3912 = 152881 ≡ 421 mod 693
x = 104 : 1042 = 10816 ≡ 421 mod 693
x = 545 : 5452 = 297025 ≡ 421 mod 693.
Finally, notice that
−148 mod 693 = 545 −545 mod 693 = 148
−589 mod 693 = 104 −104 mod 693 = 589
−302 mod 693 = 391 −391 mod 693 = 302
−50 mod 693 = 643 −643 mod 693 = 50 .
Thus, 421 mod 693 has exactly eight square roots: four roots and their negatives.
Exercise 3.30
Note that to do computations with large numbers, a tool implementing the polynomial extended Euclidean algorithm is
required.
In the following, −ax mod p is replaced by ( p − a) x mod p .
Check the irreducibility of f ( x ) = x 10 + x 3 + 1 over F2 .
Degree of f ( x ) is m = 10. The prime dividers of 10 are 5 and 2.
10 10
p1 = = 2 , p2 = = 5 .
5 2
Iteration #1 (test of prime divider 5, i.e. p1 = 2 ):
2
x 2 ≡ x 4 mod f ( x )
h( x ) = x 4 − x mod f ( x ) = x 4 + x
g ( x ) = GCD( f ( x ), h( x )) = 1 g ( x ) = 1; hence, the algorithm continues.
( )
5
x 2 ≡ x 8 + x 5 + x 4 + x 2 + x mod f ( x )
h( x ) = x + x + x + x + x − x mod f ( x ) = x 8 + x 5 + x 4 + x 2
8 5 4 2
g ( x ) = GCD( f ( x ), h( x )) = 1
Exercise 3.31
Note that to do computations with large numbers, a tool implementing the polynomial extended Euclidean algorithm is
required.
108 3 Mathematical Basics and Computation Algorithms for Cryptography
( )( )
Indeed, x 5 + x 4 + x 3 + x 2 + x + 2 = x 2 + 2 x + 2 x 3 + 2 x 2 + x + 1 .
□
k
Then, a * a * a mod n ≡ (a mod n) mod n , which may be generalized to ak mod n ≡ (a mod n) mod n for any integer k > 2.
□
By definition, ϕ (n) is the number of elements of Zn , which are coprime with n. By Theorem 3.3, all the ϕ (n) elements have
multiplicative inverse mod n . Therefore, they are elements of Zn* . Hence, Zn* = ϕ (n) .
Problem 3.4
1) By definition of multiplicative inverse, given two elements x and x ′ of Z *p , if x ′ is a multiplicative inverse of x , then
x * x ′ ≡ 1 mod p.
Let a be an even integer less than p. There exists a positive integer m such that a = 2m . a′ , the multiplicative inverse
of a, does not exist because the condition a * a′ ≡ 1 mod p cannot be satisfied, if p is even, which is proven as follows:
If a′ was the multiplicative inverse of a, then:
a * a′ ≡ 1 mod p ⇒ ∃k | 2m * a′ = k * p + 1. (a)
3.5 Solutions to Exercises and Problems 109
Statement (b) cannot hold because the left side of equality is even while the right one is odd. Thus, no even integer is
an element of Z *p if p is even.
2) Z2* m means Z *p with p = 2m . Since p is even, Z *p does not include any even elements, because their multiplicative inverses
do not exist in Z2* m . Thus, Z2* m includes only odd elements. Hence, its cardinality can be at most 22 = 2m−1.
m
Problem 3.5
*
Z11 = {1, 2, 3, 4, 5, 6, 7, 8, 9,10}
p−1
p = 11 ⇒ 2
= 5 and −1 = 10 mod 11.
Check by Euler’s criterion (Theorem 3.7):
15 ≡ 1 mod 11, 35 ≡ 1 mod 7, 45 ≡ 1 mod 11, 55 ≡ 1 mod 11, 95 ≡ 1 mod 11
25 ≡ −1 mod 11, 65 ≡ −1 mod 11, 75 ≡ −1 mod 11, 85 ≡ −1 mod 11, 105 ≡ −1 mod 11.
*
Thus, five (i.e. 112−1 ) of elements in Z11 are square residues and five elements are square nonresidues.
{
Z *p = {1, 2, …, p − 1} = 1, 2, …,
p−1 p +1
2
, 2 , }
…, p − 2, p − 1 .
distinct squares. It is easy to prove that if a and b are two distinct elements in Z *p , with b ≠ −a , then a2 mod p and b2 mod p
are two distinct elements. By definition, an element a ∈ Z *p is a quadratic residue if there exists y ∈ Z *p such that
p−1
y 2 ≡ a mod p . Since there are exactly p−1
distinct squares in Z *p , the number of square residues is . Hence, the remain-
□
2 2
p−1
ing elements are square nonresidues.
2
□
p +1 p−1
r2 = a 2 =a*a 2 ⇒ r 2 ≡ a * (1)mod p = a .
110 3 Mathematical Basics and Computation Algorithms for Cryptography
Problem 3.8
By definition, Z *p = {a ∈ Z p | GCD(a, p) = 1} .
Let u be any element of Z *p .
(p−1)/2 (p−1)
● a=u ⇒ a2 = u .
(p−1)
By Fermat’s little theorem (Theorem 3.5), u ≡ 1 mod p .
2
Thus, a ≡ 1 mod p . Hence, a is a square root of 1.
(p−1)/2 (p−1)/2
● From answer to question 1, we know that u is a square root of 1 mod p. Thus, u is 1 or −1 in modulo p.
Problem 3.9
Prove that: given two distinct primes p and q :
( ) ( )
q q−1 mod p + p p−1 mod q = pq + 1.
Let N = q (q−1 mod p) + p( p−1 mod q). (a)
( )
p p−1 mod q ≡ 1 mod q ⇒ ∃k ∈ N | p ∗ p−1 = k ∗ q + 1 (b)
( )
N = q q−1 mod p + k ∗ q + 1 ⇒ N ≡ 1 mod q (c)
N ≡ 1 mod p * q (d)
( )
All integers p, p−1 , q, q−1 in (a) are greater than 1, so:
N ≥2 . (e)
By definition of modulo:
( )
p−1 mod q ≤ q − 1 ⇒ p p−1 mod q < p ∗ q (f)
( )
q−1 mod p ≤ p − 1 ⇒ q q−1 mod q < q ∗ p. (f’)
From (a), (e), (f), and (f’):
2 ≤ N < 2 * p * q. (g)
The unique value of N , which fulfills (d) and (g), is p * q +1.
( ) ( )
Therefore, q q−1 mod p + p p−1 mod q = 1 + p ∗ q.
Problem 3.10
Let q be the order of Z *p and 1 its neutral element.
If g is a generator of Z *p , then elements of Z *p can be expressed as powers of g :
{
Z *p = 1, g , g 2 ,…, g q−1 .}
Since g is a generator of Z *p and Z *p = q , g q ≡ 1 mod p .
By definition of multiplicative inverse: g * g −1 = 1.
3.5 Solutions to Exercises and Problems 111
q q q q
(
Then, g * g −1 ) ( )
= 1 ⇒ g q * g −1 ( )
= 1 ⇒ 1 * g −1 ( )
= 1 ⇒ g −1 = 1.
Since the order of g −1
is q , g −1
is a generator of Z *p .
Problem 3.11 (Proof of Lemma 3.6)
To prove that Lemma 3.6 is correct, we need to prove that the statement “any irreducible polynomial of degree m can gen-
erate all the elements of field Fpm ” is false. The two following scenarios are counterexamples to the statement above.
1) Let f ( x ) = x 2 + 1 and α its root over field F32 .
Since α is a root of f ( x ) , then α 2 + 1 = 0 ⇒ α 2 = −1 = 2 .
Let us see how powers of α generate elements of field F32 :
α 0 = 1 α 1 = α
( )
α 2 = 2 α3 = α α 2 = 2α
α = α (2α ) = 2 α = 1
4 2
1 1 α +2 5
α0 α9
α1 α 3 α10 α 2 + 2α 15
α2 α2 9 α11 2α 2 + α + 1 22
α3 α +1 4 α12 α2 + 1 10
α4 α2 + α 12 α13 1 1
α5 α2 + α + 1 13 α14 α 3
α6 α 2 + 2α + 1 16 α15 α2 9
α7 2α 2 + 2α + 1 25 α16 α +1 4
α8 2α 2 + 2 20 ⋅⋅⋅ ⋅⋅⋅ ⋅⋅⋅
Root α can generate only 12 nonzero elements among the 26 nonzero elements of F33 .
□
Both examples above prove (by counterexamples) that not all polynomials of degree m and irreducible over field Fp
have a root α that can generate all elements of a field Fpm .
Problem 3.12
1) If gi is a generator, then its multiplicative inverse gi−1 also is a generator.
By definition of multiplicative inverse: gi * gi−1 ≡ 1 mod p .
Let q be the number of generators of Z *p and G the set of Z *p generators denoted { g1 , g2 , …, gq }. Each element in G has
its multiplicative inverse in G. Without loss of generality, assume that, if q is even, the set G is organized into two halves
q
such that gk , 1 ≤ k ≤ , is the inverse of gq−k +1 , i.e. G = g1 , g2 , …, g q , g −q 1 , ..., g2−1 , g1−1 .
2
2 2
i=k
The product ∏i=1 gi = g1 ∗ g2 ∗⋅⋅⋅∗ gq may be rewritten as
∏ii= k
(
=1 gi = g1 ∗ g1
−1
)( )
∗ g2 ∗ g2−1 ∗…∗ g q ∗ g −q 1 .
2 2
Thus, ∏ii= k
=1 gi ≡ 1 ∗ 1 ∗…∗ 1 ≡ 1 mod p
.
112 3 Mathematical Basics and Computation Algorithms for Cryptography
−1 −1 −1
If q is odd, G is organized as g1 , g2 , …, g q−1 , g q+1 , g q−1 , g2 , g1 . Since, the elements in the subset of G on the right of
2 2 2
−1 i=k
g q+1 and the elements on its left are pairwise inverses, g q+1 = g q+1 . Hence, ∏i=1 gi ≡ 1 * …1… * 1 ≡ 1 mod p.
2 2 2
2) Let Fp be a prime field. Thus, Fp = {0, 12,…, p − 1}. Each element u ∈ Fp has one and only one additive inverse u′ ∈ Fp ,
such that u + u′ = 0 . The elements of Fp can be organized as follows: 0, 1,−1, 2,−2, …, { p−1
2 ( )}. Therefore,
p−1
,− 2
∑ u∈F u ≡ (0) + (1 − 1) + (2 − 2) +…+
p
( p−1
2
p−1
− 2 ) mod p = 0.
Problem 3.13
Z 4 = {0, 1, 2, 3} is not a field, because 0 and 2 have no multiplicative inverse in Z 4 .
Problem 3.14
Consider field F25 with reduction polynomial f ( x ) = x 5 + x 2 + 1. Show that g = x is a generator of F25 .
The set of elements of F25 is {0, 1, 2, …, 30, 31}.
By definition, if g is a generator of a field F2m , then every nonzero element of F2m can be uniquely written is a power of g .
{
That is: F2*m = F2m − {0} = 2m , 0 ≤ i ≤ 2m − 2 . }
g = x is it a generator of F25 ?
In this problem 2m = 32 . Thus, we have to check the powers of x from 0 to 30.
( )
= x ∗ x 2 + 1 mod f ( x ) = x 3 + x = (01010) = 10
(( )(
x 7 mod f ( x ) = x 2 mod f ( x ) ∗ x 5 mod f ( x ) mod ( fx ) ))
( )
= x 2 ∗ x 2 + 1 mod f ( x ) = x 4 + x 2 = (10100) = 20
(( )(
x mod f ( x ) = x 3 mod f ( x ) ∗ x 5 mod f ( x ) mod ( fx )
8
))
3
( 2
)
= x ∗ x + 1 mod f ( x ) = x + x + 1 = (01101) = 13 3 2
((
x mod f ( x ) = x 1 mod f ( x ) ∗ x 8 mod f ( x )
9
)( ))
( 3
)
= x ∗ x + x + 1 = x + x + x = (11010) = 26
2 4 3
= x ∗ ( x 4 + x 3 + x ) mod f ( x ) = x 4 + 1 = (10001) = 17
= x * ( x 4 + 1) mod f ( x ) = x 2 + x + 1 = (00111) = 7
= x ∗ ( x 2 + x + 1) mod f ( x ) = x 3 + x 2 + x = (001110) = 14
3.5 Solutions to Exercises and Problems 113
(( )( ))
x 13 mod f ( x ) = x 1 mod f ( x ) ∗ x 12 mod f ( x ) = (11100) = 28
x 14
mod f ( x ) = (( x 1
mod f ( x )) ∗ ( x mod f ( x ))) = (11101) = 29
13
x 15 mod f ( x ) = (( x 1
mod f ( x )) ∗ ( x 14 mod f ( x ))) = (11111) = 31
x 16 mod f ( x ) = (( x 8
mod f ( x )) ∗ ( x 8 mod f ( x ))) mod ( fx ) = (11011) = 27
x 30 mod f ( x ) = (( x 16
)( ))
mod f ( x ) ∗ x 14 mod f ( x ) mod f ( x )
2
( )( )
= x 4 + x 3 + x + 1 * x 4 + x 2 mod f ( x ) = x 4 + x = (10010) = 18.
Problem 3.15
Let f ( x ) = x 4 + x + 1 be an irreducible polynomial over F2 . f ( x ) is used for computations over field F24 . Solve the follow-
ing linear equations:
1) 3 y = 4
y = 4 * 3−1 .
Operations are done using polynomial representation.
( ) ( )
3−1 : ( x + 1) x 3 + x 2 + x mod x 4 + x + 1 = 1 ⇒ 3−1 = 14
4 * 3−1 : ( x 2 )( x 3 + x 2 + x ) mod ( x 4 + x + 1) = x 3 + x 2 + 1.
Hence, y = 13
2) 9 y + 3 = 2
y = (2 − 3) * 9−1 .
Operations are done with polynomial representation.
2 − 3 : x − x − 1 = −1 = 15
( ) ( )
9−1 : x 3 + 1 ( x ) mod x 4 + x + 1 = 1 ⇒ 9−1 = 2
(2 − 3) * 9−1 : 15 x mod ( x 4 + x + 1) = 15 x = −x
Hence, y = −2 = 14 .
Problem 3.16
147155 mod 23 ≡ ?
1) Fermat’s little theorem states that given two positive integers m and p, such that p is prime and m is not divisible by p,
then m p−1 ≡ 1 mod p .
In this problem m = 147 and p = 23. m and p are coprime. Thus, Fermat’s little theorem is applicable. Thus,
14722 ≡ 1 mod 23 is used to reduce the computations as follows:
114 3 Mathematical Basics and Computation Algorithms for Cryptography
7
147155 mod 23 ≡ 1477∗22+1 mod 23 ≡ 14722 ( ) ∗ (147) mod 23
7
≡ (1) ∗ (147) mod 23 ≡ 9.
To use the right-to-left binary exponentiation method, we need to represent the exponent as a sum of powers of 2:
155 = 128 + 16 + 8 + 2 + 1 = 27 + 24 + 23 + 21 + 20 .
The number of iterations of the right-to-left binary exponentiation method depends on the rank of the leftmost
significant bit of the exponent. If the exponent is 155 , the number of iterations of the algorithm is 8 (i.e. 7+1). Conse-
quently, when applicable, Fermat’s little theorem is a very fast method to perform modular exponentiation.
Problem 3.17
1) We need to prove that t * R = T mod n, 0 ≤ t < n (because a residue is less than the modulus), and t is an integer.
t * R = T mod n ? (a)
In line 2, t = (T + m * n) / R). Multiplying both sides by R yields t * R = (T + m * n)) ≡ T mod n, because adding m * n
does not change the residue. Therefore, condition (a) holds.
0 ≤ t < n? (b)
From line 3, the returned result is either t < n or t = t − n. Therefore, we need to prove that t < 2n. From definition in
line 1, 0 ≤ m < R. Thus, 0 ≤ n * m < n * R. By definition 3.44, 0 ≤ T < n * R. Thus, 0 ≤ T + n * m < 2 * n * R. Dividing the
inequality by R yields 0 ≤ (T + n * m) / R < 2 * n. Thus, condition (b) holds.
t is it an integer? (c)
( )
□
Multiplying both sides in line 1 by n yields n * m = n * T * n′ = T * −n * n−1 = −T mod R. Therefore, there exists some
integer k such that n * m = k * R − T and hence t = T +Rm *n = k R* R is an integer.
2) We need to prove that c ≡ a * b mod n , where c denotes the result of the Montgomery multiplication. We proceed by
substitution starting from the definition of c :
(
c ≡ REDC (c ′) ≡ c ′ * R−1 mod n ≡ REDC (a * b) * R−1 mod n )
( )
≡ (a * b) * R−1 * R−1 mod n
Proof:
∏ii= k
=1 ni
By construction, N i = , for 1 ≤ i ≤ k. Thus,
ni
i) Since the ni ’s are pairwise coprime and N i does not have a factor equal to ni , GCD( N i , ni ) = 1. Thus, the multiplicative
inverse of N i mod ni , for every i in [1, k ], exists.
ii) For every j in (1,k ), N j ≡ 0 mod ni for every i in [1, k ] and j ≠ i , because ni is a factor of N j .
( ( ))
⇒ ∑ ik=1 ai ∗ N i ∗ N i−1 mod ni = ai mod ni , ∀i ∈ [1, k ].
( ( ))
By construction: x = ∑ ik=1 ai ∗ N i ∗ N i−1 mod N . Hence, there exists a positive integer m such that
( )
x = ∑ ik=1 ai ∗ N i ∗ N i−1 − m ∗ N
( ( )
⇒ x mod ni = ∑ ik=1 ai ∗ N i ∗ N i−1 − m ∗ N mod ni .)
Since N is a multiple of ni ,
( ( ))
x mod ni = ∑ ik=1 ai ∗ N i ∗ N i−1 mod ni = ai mod ni , ∀i ∈ [1, k ]. □
Notes
1 See Problem 3.1 for proof of Lemma 3.1.
2 See Problem 3.2 for proof of Lemma 3.2.
3 In the sequel, multiplicative inverse or simply inverse is used instead of modular multiplicative inverse, because we only
consider calculations in modular arithmetic.
4 See Problem 3.3 for proof of Lemma 3.3.
6 It is easy to prove that if p is a prime and greater than 2, then p ≢ 0 mod 4 and p ≢ 2 mod 4.
5 See Problem 3.6 for proof of Lemma 3.4.
References
1 McEliece, R.J. (2011). Finite Fields for Computer Scientists and Engineers. Kluwer Academic Publishers.
2 Hachenberger, D. and Jungnickel, D. (2020). Topics in Galois Fields. Springer.
3 Mullen, G.L. and Panario, D. (2013). Handbook of Finite Fields. CRC Press.
4 Stein, W. (2009). Elementary Number Theory: Primes, Congruences, and Secrets: A Computational Approach. Springer.
5 Rosen, K.H. (1984). Elementary Number Theory and Its Applications. Addison Wesley.
6 Tattersall, J.J. (2005). Elementary Number Theory in Nine Chapters. Cambridge University Press.
7 Blake-Wilson, S., Bolyard, N., Gupta, V. et al. (2006). Elliptic Curve Cryptography (ECC) Cipher Suites for Transport Layer
Security (TLS) - RFC 4492. Internet Engineering Task Force (IETF).
8 ANSI. (2020). Financial Services - Public Key Cryptography for the Financial Services Industry: The Elliptic Curve Digital
Signature Algorithm - ECDSA - ANSI X9.142. American National Standard Institute.
9 Montgomery, P.L. (1985). Modular multiplication without trial division. Mathematics of Computation 44 (170): 519–521.
10 Shanks, D. (1972). Five number-theoretic algorithms. In Second Manitoba Conference on Numerical Mathematics.
Winnipeg, MB, Canada: American Mathematical Association, 51–70.
11 Rabin, M.O. (1980). Probabilistic algorithms in finite fields. SIAM (Society for Industrial Applied Mathematics) Journal of
Computing 9 (2): 273–280.
12 Katz, J. and Lindell, Y. (2007). Introduction to Modern Cryptography. CRC Press.
117
Symmetric Ciphering
Historical Ciphers
Shift and substitution ciphers have been used for written text transmission and dominated the art of secret writing for at
least two millenniums (and maybe more). The most known historical ciphers in this category, include Caesar’s, Vigenere’s,
affine, OTP, and Enigma ciphers. With the advent of computers, shift and substitution ciphering were abandoned, because
it has become easy to break them. However, it is important to learn them since they had inspired the modern cryptography.
The material below is mostly collected from [1–5].
4.1 Definitions
Definition 4.1 Alphabet: it is a set of elements, which may be letters, words, or any other form of bit strings that are used to
generate plaintexts and ciphertexts.
In the sequel, the alphabet elements are either Latin letters or bits.
Definition 4.2 Substitution cipher: it is a cipher in which an alphabet element is replaced by another alphabet element to
yield a ciphertext.
Definition 4.3 Shift cipher: it is a special type of substitution cipher in which a letter is replaced by another letter located a
few positions away.
Definition 4.4 Monoalphabetic cipher: it is a cipher in which the letters of the plaintext are mapped to ciphertext letters
based on a single substitution key and each letter is always replaced by the same letter. The transformation is bijective.
Definition 4.5 Polyalphabetic cipher: it is a cipher, which makes use of multiple alphabets and a letter may be replaced
by many other letters depending on its position in the plaintext. It makes use of multiple keys. The transformation is not
bijective.
Definition 4.6 Information-theoretic secure cipher: a cipher is information-theoretic secure if it cannot be broken even if
the adversary has unlimited computation resources.
One of the most known shift ciphers is Caesar’s cipher used in the Roman Empire to encrypt messages exchanged between
Roma (i.e. the emperor and his attorneys) and roman armies around the world. At ancient Rome, the romans had an intel-
ligence system comparable to the one in today’s USA.
A message to encrypt is a string of letters over an alphabet A of m letters. Each letter has an index in interval [0, m − 1].
Let Ind ( y ) be a function that returns the index of a letter y in the alphabet A and Let (c ), a function that returns the letter
of index c. Caesar’s cipher may be formulated as follows:1
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
118 4 Symmetric Ciphering
Encryption: given a key k (k N, k < m) and l a letter to encrypt, the encryption is a shift right to yield the encrypted letter l ′.
Formally:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
X Y Z A B C D E F G I H J K L M N O P Q R S T U V W
In affine ciphers, each letter is encrypted using an affine substitution based on indices of letters in the alphabet. Formally:
Encryption: Enc ( x ) = a * x + b mod m = y.
Decryption: Dec ( y ) = a−1 ∗ ( y − b) mod m = x .
4.3 Affine Ciphers 119
where:
pair (a, b) denotes the key of substitution
m denotes the number of letters in alphabet
a−1 is the multiplicative inverse of a mod m
l denotes the letter in plaintext and x, its index in alphabet; i.e. x = Ind(l)
l′ denotes the letter in ciphertext and y, its index in alphabet; i.e. l ′ = Let ( y ).
The intercept b can be any value in the interval [0, m − 1]. The decryption operation makes use of multiplicative inverse a−1.
Therefore, not all values in [1, m − 1] can be used for slope a. Indeed, a must be an element of Zm
* . Recall that an element a
Note. Shift ciphers, including Caesar’s cipher, are affine ciphers with a = 0.
{ }
* = 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25 .
Z26
Therefore, the slope a can take distinct 12 values. For each element of Z26
* there exists a multiplicative inverse in Z * as
26
shown in the following table:
a 1 3 5 7 9 11 15 17 19 21 23 25
a−1 1 9 21 15 3 19 7 23 11 5 17 25
l1 = Let (2) = C .
Second letter:
l2 = Let (0) = A.
Third letter:
* . For example, with Latin alphabet, the number of keys is 12 26 = 312 . Even if an affine cipher provides
of the group Zm *
more keys than Caesar’s cipher, it has the same flaws when computers are used in attacks.
120 4 Symmetric Ciphering
To make attacks based on frequency analysis harder, polyalphabetic ciphers have been invented in the 16th century. One
of the most famous polyalphabetic ciphers is the one invented by Blaise de Vigenere.
Vigenere’s cipher was proposed in the middle of the 16th century and it resisted all attempts to break it for three cen-
turies. Vigenere’s cipher is an improvement of Caesar’s cipher. It makes use of several Caesar’s ciphers in sequence with
different shift values. A table T, called Vigenere’s table, is defined as follows (see Figure 4.1): the first row is composed of
the 26 letters of the Latin alphabet, the second row is one-position circular left shifting of the first row, …, the 26th row is
one-position left circular shifting of the 25th row. Letters and table columns and rows are numbered from 0 to 25 .
Encryption:
1) Before any encryption operation, the sender and receiver of message M must agree on a secret key word k.
2) Key expansion K: the key word k is repeated until the size of the expanded key equals the size of the message M to
encrypt.
3) For each letter M j ( j = 0, ..., len( M ) − 1) of message M, Vigenere’s table T is used for substitution as follows:
Let Ind( M j ) be the index of letter M j and Ind( K j ), the index of the jth letter of the expanded key. Then, the encryption is
Decryption:
For each letter M ′j ( j = 0, ..., len( M ′ ) − 1) of the received message M ′ , the decryption is performed as follows:
Go to raw K j of Vigenere’s table, locate the column of letter M ′j on raw K j , say c j . Then, use the letter T (0, c j ).
Formally, Dec ( M j′ ) = M j = T (0, Col( K j , M j′ )) where Col(i, l) is a function that returns the column of letter l in raw i of
table T.
The original version of Vigenere’s ciphering is based on a table (see Figure 4.1), because encryption and decryption were
carried out by hand. With computers, the implementation of both operations does no more require the table. Indeed,
Vigenere’s ciphering may be described without using a table as follows:
– Letters are ordered from 0 ( A) to 25 ( Z ) .
– Encryption of jth letter of message M, denoted M j, is:
M ′j = ( M j + K j ) mod 26 (K j is the jth letter of the expanded key).
– Decryption of the jth letter encrypted message M ′ , denoted M ′j , is:
M j = ( M ′j − K j ) mod 26 .
The second description of Vigenere’s cipher makes it an extension of Caesar’s cipher.
4.4 Vigenere’s Cipher 121
Example 4.3 Let HORSE and LEAVEHOUSE be the shared secret and the plaintext, respectively.
Key expansion yields HORSEHORSE, which is of the same length as the plaintext. Then, the indices of expanded key letters
are
Ind( K 0 ) = 7 Ind( K1 ) = 14 Ind( K 2 ) = 17 Ind( K3 ) = 18 Ind( K 4 ) = 4
Ind( K5 ) = 7 Ind( K 6 ) = 14 Ind( K 7 ) = 17 Ind( K 8 ) = 18 Ind( K 9 ) = 4.
– Encryption and decryption using Vigenere’s table
Encryption
Γ
the number of keys to test is ∑ i=1 26i . If the upper bound of key length is unknown to the adversary, the number of keys
max( len ( M ))
to test is ∑ i=1 26i , where max(len( M )) denotes the maximum message length.
With a key length of 3, there exist 1.75 * 10 4 keys; and 9.5 * 1016 keys, with a length of 12. That is why Vigenere’s cipher
was unbreakable by brute-force attack until the era of computers.
The first modern cyphering machine, which had been widely used, is with no doubt the Enigma machine. Many modern
ciphering algorithms were inspired by Enigma machine design, whose internal structure looks like a symmetric ciphering
algorithm.
A German engineer (Arthur Scherbius) at the end of World War I invented enigma machine; it had been used commercially
from the early 1920, and was adopted by Nazi Germany before and during World War II (WW2). Enigma has played a significant
role in 3rd Reich domination. However, when the ciphering technique of Enigma has been broken by the British (with the
support of the mathematician Alan Turing), the fall of Nazi army started. Most of secret messages transmitted by Nazi com-
mandment were disclosed by the English and allies secrecy agencies. For more detail on the story of Enigma, refer to [6].
Enigma machine is an electromechanical design of a polyalphabetic substitution cipher. It consists of multiple elements,
among which six are of prime importance to understand how encryption and decryption are performed (see Figure 4.22):
● Batteries for power supply of bulbs.
● Keyboard for keying plaintext and ciphertext.
● Lamp panel in which the letter resulting from the encryption or decryption of a keyed letter is illuminated.
positions of the wiring relative to the turnover-point and start position. With three rotors selected out of five, there
exist 5 * 4 * 3 = 60 permutations to fit the rotors.
The reflector receives a signal coming from the keyboard and propagates it toward the lamp board to illuminate the
appropriate bulb.
When a letter is pressed on the keyboard, a bulb lights up and the rightmost wheel makes a single step (one-contact move
position). Each rotor has a notch3 on its left side at a specific location (from 1 to 26). When the rightmost rotor makes a full
turn (after 26 pressed keys), its notch triggers the stepping motion, by engaging a pawl, of the rotor to the left, which makes
a single step, and so on until the leftmost rotor makes a single step. Therefore, 263 keystrokes are needed to the Enigma
machine to return to its start position (see Problem 4.7).
Figure 4.5 Example of a piece of Enigma codebook. Tag: day in month (the first day of month is located on bottom of the sheet, because
the operators are required to cut off and destroy expired settings), UKW: model of reflector—Walzenlage: roller position (rotor numbers
and order). Ringstellung: rotor settings—Steckerverbindungen: connections on the plug board. Kenngruppen: Identification groups.
A start position is a string of three or four letters each associated with one and only rotor. For example, in case of three
rotors, the start position WXZ means the leftmost rotor should be placed on letter W, the middle rotor on letter X, and the
rightmost on letter Z.
Enigma encryption
1) If not yet done, install the Enigma machine according to the settings of the day.
2) Let M be the message content to encrypt.
3) Select randomly a start position, say WXZ, and a message key, say XTS, and write both values on paper.
4) Turn the rotors to the start position WXZ and encrypt the message key XTS and write the encrypted message key, say
ASV, on paper.
5) Change the start position to the message key XTS.
6) Encrypt message content and write the resulting letters on paper. Let M ′ be the encrypted message content.
7) Form a key identification as follows: select two random letters, say FE and select one of the strings in the identification
groups from the settings of the day, say CGY.
8) Write on paper an encrypted message M of four parts: key identification (FECGY), start position (WXZ), encrypted mes-
sage key (ASV), and the encrypted message content (M ′ ).
9) Deliver the encrypted message M to the radio operator for transmission.
Enigma decryption
1) If not yet done, install the Enigma machine according to the settings of the day.
2) Let M be the encrypted message, which is received by the radio operator. The latter delivers the encrypted message to
Enigma operator. M is composed of four fields: identification group (in clear), say FECGY, start position (in clear), say
WXZ, encrypted message key, say ASV, and encrypted message content.
3) The first task of the operator is to check message freshness. If the message has been encrypted in the current day, identification
group (in our example, CGY) in the message header appears in the identification groups of the current day (in the codebook).
Otherwise, the message had been received within a delay exceeding one day and the operator must inspect the codebook to
find the day associated with the received identification group and then select and reinstall the rotors accordingly.
4) Set rotors in start position WXZ and decrypts ASV (the encrypted message key) to yield the message key XTS.
5) Set rotors in start position XTS and decrypts M ′ (the encrypted message content) to yield the message content M. Write
on paper, one by one, the illuminated letters.
6) Deliver the plaintext M to whom it may concern.
Example 4.4 Figure 4.5 shows a piece of codebook of Enigma settings for five days.
Assume that the current day is 29. The operator selects reflector C, and rotors IV, I, and V. Then, Rotor IV is set on position
01, rotor I on position 12, and rotor V on position 21. Reflector and rotors are inserted in the machine. Next, letters are
interconnected on the plug board: A↔R, B↔Y, C↔I, D↔X, E↔N, F↔V, G↔W, H↔O, J↔Q, K↔T. If a message is received
with identification group in {QGL, IXI, VIT, SGU} the message is decrypted with the settings of the current day.
126 4 Symmetric Ciphering
If a message is received with identification group equal to SYI, the operator must reconfigure the machine according to
the settings of day 27 to decrypt.
( (( ( ))))
x ′ = Enc ( x , s x ) = P −1 L−1 M −1 R−1 U L M ( R ( P ( x )))
(4.1)
where:
x ′ is the encryption output, i.e. the illuminated letter on the lamp board.
t x denotes the time when letter x is pressed.
s x denotes the state of the Enigma configuration at time t x :
s x = (u, p, r (t x ), m(t x ), l(t x )), where u denotes the reflector model, p, the matrix of connections on plug board, and r (t x ),
m(t x ), and l(t x ), the positions of rightmost, middle, and leftmost rotor at time t x , respectively.
R( z ), M ( z ), and L( z ) denote the substitutions yielded by rightmost, middle, and leftmost rotors, respectively, if the input
from the right rotor side is z and the state of Enigma machine is s x . For example, in Figure 4.6, letter I is connected to
letter G of the rightmost rotor whose output is letter V . Thus, R( I ) = V .
R ( z ), M −1 ( z ), and L−1 ( z ) denote the substitutions yielded by rightmost, middle, and leftmost rotors, respectively, if the
−1
input from the left rotor side is z and the state of Enigma machine is s x . For example, in Figure 4.7, letter J of leftmost
rotor is connected to letter F of the middle rotor whose output is letter N . Thus, M −1 ( J ) = N .
P ( z ) denotes the swapping of pressed letter z to enter the ciphering components. For example, P ( Z ) = I .
P −1 ( z ) denotes the swapping of letter z to exit the ciphering components (toward the lamp board or keyboard). For
example, P −1 ( I ) = Z .
U ( z ) denotes the substitution yielded by the reflector.
Decryption
The decryption is correct if and only if the encryption of an encrypted letter yields the initial letter, i.e. Enc ( Enc ( x , s x ),
sx ) = x, for any letter x in the plaintext. Let x ′ = Enc ( x , s x ′ ) and t x ′ , the time when letter x ′ is pressed. x ′′ denotes the illu-
minated letter resulting from x ′ encryption. To decrypt, operators on both sides are required to use same Enigma state (i.e.
same deflector, same connections on plug board, and same rotor positions). Thus, s x ′ = s x . By definition of Enigma
encryption:
( (( (
x ′′ = Enc ( x , s x ) = P −1 R−1 M −1 L−1 U L M ( R ( P ( x ′)))))))
(4.2)
P (.), P −1 (.), and U (.) depend only the initial machine settings. Thus, U (U ( z )) = z and P −1 ( P ( z )) = z, for any letter z.
During the encryption of a letter, the state of the Enigma machine remains unchanged. It changes at the end of
encryption process. Therefore, inverting the result of a rotor transformation is equivalent to not transforming the input.
That is, F −1 ( F ( z )) = z, for F ∈ {R, M , L}. Below are the substitutions of (4.1) in (4.2), starting from the innermost
function,
( (( (
P ( x ′) = R−1 M −1 L−1 U L M ( R ( P ( x )))
))))
( (( (
R( P ( x ′)) = M −1 L−1 U L M ( R ( P ( x ))) ))))
( ((
M ( R ( P ( x ′))) = L−1 U L M ( R ( P ( x ))) )))
( ) (
L M ( R ( P ( x ′))) = U L( M ( R ( P ( x ))) )
(( )) (
U L M ( R ( P ( x ))) = L M ( R ( P ( x ))) )
( (( ))) = M (R(P ( x )))
L−1 U L M ( R ( P ( x ′)))
M ( L (U ( L ( M ( R ( P ( x ))))))) = R ( P ( x ))
−1 −1
( (((
R−1 M −1 L−1 U L M ( R ( P ( x )))
)))) = P ( x )
M ( L (U ( L( M ( R ( P ( x ))))))) = x = x ′′.
P −1 R−1 −1 −1
Hence, encrypting twice a letter results in the same letter. Therefore, Enigma decryption is correct.
Finally, the operator selects one of the reflectors. Therefore, the number of distinct settings that an Enigma machine may
R! 26 !
have as a whole is 2 * .
(R − r )! * (26 − 2c )! * c ! * 2c
Table 4.1 shows the number of settings depending on the strength level of security to guarantee. Strength levels 2 and 3
were the most deployed by Nazi army from 1940 onward, which had an equivalent of security strength of 68 and 77 bits of
modern digital ciphers. In WW2, breaking a 77-bits code was very difficult though Turing did it.
4.5.8.1 Weaknesses, Practices, and Other Features that had been Exploited
To reduce the search space, cryptanalysts tried to discover weaknesses in the Enigma design, message contents, practices
of Enigma operators, and German language.
● The plug board connections are reciprocal. Therefore, for example, if T is connected to F on the plug board, then pressing
TFTFFTTTFF… results in an output where T and F are never present.
Figure 4.8 Example of tests of matching between ciphertext and crib. Letters in black boxes denote non-compliance with Enigma
encryption. Letters in gray denote letters that are not yet checked.
connected to letter H, which is already connected to J. Such a situation is called contradiction. Therefore, the previous
decisions were wrong and the work must restart from the first letter of the ciphertext fragment.
Second attempt:
1) Start with the first letter of the ciphertext, which is A, and decide to not connect letter A. Then, press letter A and iden-
tify, on Bombe machine, on which letter the signal from the rightmost rotor returns to the plug board, say J. From letter
J on plug board, the signal has to travel to letter H on the lamp board. Therefore, keep connection J↔H.
2) Continue with the 2nd letter of the ciphertext, which is J. Letter J is already connected to H. Then, press J and identify
on which letter the signal from the rightmost rotor returns to the plug board, say L. If the previous decisions were
correct, L must be connected to the 2nd letter of the crib, i.e. O. Therefore, keep connection L↔O.
3) Continue with the 3rd letter of the ciphertext, which is U, and decide to not connect letter U. Then, press U and identify
on which letter the signal from the rightmost rotor returns to the plug board, say J. Since letter J is already connected
to H, no new connection is guessed.
4) Continue with the 4th letter of the ciphertext, which is Y, and decide to not connect letter Y. Then, press Y and identify
on which letter the signal from the rightmost rotor returns to the plug board, say S. If the previous decisions were right,
S must be connected to the 4th letter of the crib, i.e. E. Therefore, keep connection E↔S.
5) Continue with the 5th letter of the ciphertext, which is S that is already connected to E. Then, press S and identify on
which letter the signal from the rightmost rotor returns to the plug board, say F. If the previous decisions were right, F
must be connected to the 5th letter of the crib, i.e. T. Then, keep connection F↔T.
6) Continue with the 6th letter of the ciphertext, which is X, and decide to not connect letter X. Then, press X and identify
on which letter the signal from the rightmost rotor returns to the plug board, say S. Therefore, no new connections are
guessed.
7) Continue with the 7th letter of the ciphertext, which is P, and decide to connect P to Q. Then, press P and identify on
which letter the signal from the rightmost rotor returns to the plug board, say I. If the previous decisions were right, I
must be connected to letter of the crib, i.e. M. Therefore, keep connection P↔Q and I↔M.
8) At this stage, six connections have been guessed. The remaining letters of the ciphertext fragment do not raise contra-
dictions and no connections are added: when G is pressed, the signal returns via Q and then goes to P; when L is pressed,
the signal returns via S and then goes to E; when V is pressed, the signal returns to R; when I is pressed, the signal
returns to A; when K is pressed, the signal returns via F and then goes to T; when the second K is pressed, the signal
returns to U; when U is pressed, the signal returns to R.
Guessing the right connections requires a huge number of attempts before success. If a contradiction occurs while
addressing the ith letter of ciphertext fragment, take another decision (not connect the ith letter or connect it to a not-yet
tested letter). If all decisions regarding the ith letter lead to a contradiction, return to i-1th letter and take another decision.
If all the decisions regarding the first letter of the chosen ciphertext fragment lead to contradictions, then select another
ciphertext fragment in the list of candidates and retry. If all the fragments lead to contradictions, change the rotor settings
(the position of rightmost rotor is changed first). If all the settings of rotors lead to contradictions, then change the crib
and retry.
Exercise 4.1
OTP is known to be unconditionally secure. However, it is uncommon in modern ciphering systems. Discuss some of the
reasons, which make OTP impracticable.
134 4 Symmetric Ciphering
Exercise 4.2
Explain why brute-force attack cannot succeed in breaking an OTP-based security system even if infinite computational
resources are available to the adversary.
Exercise 4.3
If the most repeated letter in a long ciphertext encrypted by an affine cipher y = ax + b is S, what are the most likely values
for a and b such that 0 < a < 4 and b ≤ 10? Assume an English plaintext.
Exercise 4.4
An affine cipher with modulus 31 encrypts 3 as 22 and 7 as 11. Determine the secret key.
Exercise 4.5
An adversary intercepted a text encrypted with an affine cipher. The ciphertext starts with LSRB; and the adversary knows
that the plaintext starts with DEAR. Assume that only lowercase Latin letters and space are in the text and space has index
0, A, index 1, ..., and Z, index 26.
1) Determine the encryption key.
2) Use the recovered key to decrypt the ciphertext.
Problem 4.1
1) How many attempts are required to brute-force attack to disclose a message encrypted with Caesar’s cipher?
2) Assume a sender that encrypts people’s names using Caesar’s cipher with k = 3. Also, assume that hundreds of cipher-
texts are known to an adversary, who also knows the frequency of letters in names as shown by the table below. Explain
how the adversary could try to recover the name contained in the encrypted message PDUWLQ.
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
9 2 4 6 10 3 0 4 5 6 2 6 5 6 5 4 1 4 6 5 1 1 1 0 1 0
Problem 4.2
* . Using Euler’s theorem (Theorem 3.4) show that a−1 used in
Consider an affine cipher y = (ax + b) mod 26, where a ∈ Z26
−1 11
decryption (see Section 4.3) is derived as a ≡ a mod 2.
Problem 4.3
Assume that an affine cipher is used and brute-force attack is done by hand. Show that widening an alphabet may jeopar-
dize its resistance to brute-force attack. In other words, larger alphabets are not always more brute-force-attack-resistant
than smaller alphabets.
Problem 4.4
An adversary knows that a sender encrypted a plaintext with a Vigenere’s cipher using the plaintext as a key. Can the plain-
text be recovered?
Problem 4.5
Assume that the following ciphertext has been produced by an affine cipher and it includes a message written in English.
KAR KRPYREFKNER DH ADXA. KAR FMFHJF IRFE MRUK KAR IMNR PVNSKFDS F TRRJ FXV FSO PVQRO
KV KAR EDQRE. DK UDHARH HFMPVS.
Make use of frequency analysis to recover the plaintext. The table of letter frequency used in English is given in Table 2.2.
Problem 4.6
How many pairs of letters (plaintext and ciphertext) are required to recover the key of the following ciphers?
1) Caesar’s cipher
2) Affine cipher
3) Vigenere’s cipher, assuming a key length of L
Problem 4.7
What is the period of Enigma alphabet?
Hint: a rotor may have one or two notches to trigger its step-rotation.
Problem 4.8
It is recommended to never use the same OTP key to encrypt two distinct messages. However, by mistake a user can encrypt
more than one plaintext with the same key. Such a mistake has been reported in cryptography literature. Show how an
adversary can break the code if two ASCII-coded English texts, with space character, are encrypted with the same key.
4.7 Exercises and Problems 135
Problem 4.9
1) Show that OTP suffers malleability vulnerability, i.e. an adversary can change the content of the original plaintext, thus
impacting its integrity. Notice that malleability attack is applicable in man-in-the-middle context.
2) Assume that Eve knows the format of Bob’s plaintext and she knows that the plaintext includes an amount of $1000,
located at position p in the plaintext, which indicates a penalty that Eve should pay to Alice. Show how Eve can lower
her penalty to $10.
Exercise 4.1
OTP is known to be unconditionally secure. However, OTP is not used in practice for many reasons among which:
● The size of the encryption key is the same as (or even greater than) that of the data to encrypt. It would be infeasible in
practice to generate OTP keys, store, and send them to the receivers, when large amounts of data are of concern. For
example, secure transfer of multiple-terabyte database or secure periodic remote data sensing based on OTP would be
impracticable.
● Even if one can generate very large OTP keys, their secure exchange would be difficult in almost all commonly used
applications and services over digital networks. For example, spies, diplomatic staff, and armies in the field receive the
keys in hand via diplomatic bag or dedicated persons. Such key exchange protocols would jeopardize the performance of
any modern cryptosystem.
● OTP key generation requires secure random generators with capacity of generating long keystreams without periodicity.
If not enough secure, the algorithm used to generate the OTP keys would be a vulnerability of the security system.
Exercise 4.2
An OTP key is random and with the same length as (or even longer than that of) the plaintext and each message is
encrypted with a distinct randomly generated key. Therefore, there is no information in the ciphertext (such as letter fre-
quency) that the adversary could use to recover the plaintext/key. Also, even if enough resources are available to the adver-
sary to apply a brute-force attack, where the adversary decrypts the ciphertext with all possible keys, the adversary would
have no way in knowing which plaintext is the original plaintext. This is because a brute-force attack would produce many
potential plaintexts that make sense to the adversary.
Exercise 4.3
The most common letter in English texts is E. Therefore, letter E is likely to be replaced by S in the ciphertext under
consideration.
In Latin alphabet, letters A, E, and S have indices 0, 4, and 18, respectively. Substitution in equation y ≡ ax + b mod 26
yields 18 ≡ a * 4 + b mod 26.
There exist two solutions a = 2, b = 10 and a = 3, b = 6.
Exercise 4.4
By definition of an affine cipher, a plaintext P is encrypted as C = a * P + b, where (a, b) is the key. Two plaintexts and their
ciphertexts are known. Therefore, we have two equations:
22 = a * 3 + b mod 31
11 = a * 7 + b mod 31
1) Key recovery:
Since the adversary knows that the plaintext starts with DEAR, we get the following congruences
Idx ( L) = 12 ≡ a * Idx ( D) + b mod 27 = a * 4 + b mod 27
Idx ( S ) = 19 ≡ a * Idx ( E ) + b mod 27 = a * 5 + b mod 27
Idx ( R) = 18 ≡ a * Idx ( A) + b mod 27 = a * 1 + b mod 27
Idx ( B ) = 2 ≡ a * Idx ( R) + b mod 27 = a * 18 + b mod 27
Take the following congruences:
12 ≡ a * 4 + b mod 27
19 ≡ a * 5 + b mod 27
Subtracting the first congruence from the second yields a = 7, then b = 11.
2) Decryption with the recovered key:
Make substitution in the formula y = ax + b mod N :
y ≡ 7 x + 11 mod 27
−7 x ≡ − y + 11 mod 27
x ≡ ( y − 11) * 7−1 mod 27
x = 4 y + 10 mod 27
Now, decrypt:
y = 12 ⇒ x = 4 * 12 + 10 mod 27 = 4 ⇒ letter is D
y = 19 ⇒ x = 4 * 19 + 10 mod 27 = 5 ⇒ letter is E
y = 18 ⇒ x = 4 * 18 + 10 mod 27 = 1 ⇒ letter is A
y = 2 ⇒ x = 4 * 2 + 10 mod 27 = 18 ⇒ letter is R
Problem 4.1
1) The key used to shift letters in Caesar’s cipher is a value in the interval 1, 25 . Therefore, the adversary should try
each of the 25 keys to retrieve the plaintext. Given a ciphertext, 25 distinct texts are found, but only one matches the
original plaintext.
2) Since the letter substitution is bijective when Caesar’s cipher is used, the adversary builds a similar frequency table for
ciphertext letters as follows:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 0 9 2 4 6 10 3 0 4 5 6 2 6 5 6 5 4 1 4 6 5 1 1 1
When likelihood is high, the adversary makes association between plaintext letters and ciphertext letters as follows:
Ciphertext Plaintext
H E, A
D E, A
G, M, O, Q, V D, J, L, N, S
… …
Assume the adversary receives the ciphertext PDUWLQ. The letter with the highest frequency is D. Now, the adversary
assumes that D results from either E or A and the key is either 25 or 3, respectively.
First, try key = 25:
l1 = A(( Ind( P ) − 25) mod 26) = O
4.7 Exercises and Problems 137
Guessed name is OETVKP, which does not sound as a name. Therefore, the adversary tries the second key = 3:
The second guessed name is MARTIN, which is widespread name. Therefore, the adversary may stop searching or try other
alternatives starting with Q, which may result from D, J, L, N, or S.
Problem 4.2
Euler’s theorem states that if a ∈ Zn* , then aϕ(n ) ≡ 1 mod n, which can be written as a * aϕ (n )−1 ≡ 1 mod n. Using the defini-
tion of multiplicative inverse, we can derive that aϕ(n )−1 is the inverse of a.
By definition of Euler’s totient (Theorem 3.1), φ(26) = (13 − 1)(2 − 1) = 12.
Therefore, using Euler’s theorem (Theorem 3.4), a−1 ≡ a12−1 mod 26 ≡ a11 mod 26.
Problem 4.3
Recall that in affine ciphers, letters are mapped to integers, which represent letter indices in the alphabet. In order to
* , where m denotes the number of letters in alphabet. An
decrypt, affine ciphers do calculations over multiplicative group Zm
affine function is defined by: y = ax + b; the slope a ∈ Zm
* and the intercept b ∈ {0, 1, ..., m − 1}. A key is a pair (a, b).
Therefore, the number of distinct keys is Zm *
* m.
Assume that we start with an alphabet of 13 letters. Hence, m = 13. Since 13 is prime, the cardinality of Z13 * is of 12.
Therefore, the slope a can take any of the 12 values of Z13, i.e. a ∈ {1, 2, 3, ..., 12}. The intercept b is any value in {0,1, 2, 3, ..., 12}.
*
With the second alphabet, the slope a can take any of the six values of Z18 * , while the intercept b can take any value in
{0,1, 2, 3, ..., 17}. Hence, the number of combinations of the key is 6 * 18 = 108.
Therefore, the number of attempts, in a brute-force attack, is larger with a smaller alphabet.
Problem 4.4
Let M j and K j denote the jth letter of the plaintext and the jth letter of expanded key, respectively.
If the plaintext is used as a key in Vigenere’s ciphering, then K j = M j , for 0 ≤ j ≤ length( M ) . Vigenere’s encryption for
letter M j is
M ′j = ( M j + K j ) mod 26 = (2 M j ) mod 26
Therefore, M j = 2−1 ∗ M ′j mod 26 is used as decryption function by the adversary to recover the plaintext.
In general, it is recommended not to use English texts as keys when encrypting with Vigenere’s cipher.
138 4 Symmetric Ciphering
Problem 4.5
Let the ciphertext be
KAR KRPYREFKNER DH ADXA. KAR FMFHJF IRFE MRUK KAR IMNR PVNSKFDS F TRRJ FXV FSO PVQRO KV
KAR EDQRE. DK UDHARH HFMPVS.
Frequencies of letters in ciphertext are:
R 15/92 M, P, S 4/92
F, K 10/92 N 3/92
A 7/92 I, J, O, Q, U, X 2/92
D 6/92 T, Y 1/92
E, H, V 5/92 B, C, G, L, W, Z 0/92
Using the frequency of letters in English texts, the search should start with the highest-frequency letters, that is:
e 12.02 i 7.31
t 9.10 n 6.95
a 8.12 s 6.28
o 7.68 r 6.02
In the ciphertext, the guessed letters are in lower cases. Since there is lot of attempts before disclosing the plaintext, we only
show the guesses that lead to recover the plaintext:
● e, t, or a could be R, F, or K.
Associations R↔e and K↔t lead to
“tAe tePYeEFtNEe DH ADXA. tAe FMFHJF IeFE MeUt tAe IMNe PVNStFDS F TeeJ FXV FSO PVQeO
tV tAe EDQeE. Dt UDHAeH HFMPVS”.
● Since two sentences start with tAe, there is a high probability that A is associated with h. F is alone; it is likely to be asso-
ciated with article a. Associations A↔h and F↔a lead to
“the tePYeEatNEe DH hDXh. the aMaHJa IeaE MeUt the IMNe PVNStaDS a TeeJ aXV aSO
PVQeO tV the EDQeE. Dt UDHheH HaMPVS”.
● Next high-frequency letter is o. It may be associated with D, E, H, or V. Association V↔o leads to
“the tePYeEatNEe DH ADXh. the aMaHJa IeaE MeUt the IMNe PoNStaDS a TeeJ aXo aSO
PoQeO to the EDQeE. Dt UDHheH HaMPoS”.
● Next high-frequency letter is i. It may be associated with D, because Dt at the beginning of a sentence is likely to be it.
Association D↔i leads to
“the tePYeEatNEe iH hiXh. the aMaHJa IeaE MeUt the IMNe PoNStaiS a TeeJ aXo aSO
PoQeO to the EiQeE. it UiHheH HaMPoS”.
● The next high frequency letters are n, s, and r; they may be associated with E, H, M, P, and S. Associations E↔r, H↔s,
and S↔n lead to
“the tePYeratNre is hiXh. the aMasJa Iear MeUt the IMNe PoNntain a TeeJ aXo anO
PoQeO to the riQer. it Uishes saMPon”.
● It is likely that aXo is ago and anO is and. Associations X↔g and O↔d lead to
“the tePYeratNre is high. the aMasJa Iear MeUt the IMNe PoNntain a TeeJ ago and
PoQed to the riQer. it Uishes saMPon”.
4.7 Exercises and Problems 139
● From “the tePYeratNre is high” it is likely that P is m, Y is p, and N is u. Associations P↔m, Y↔p, and N↔u lead to
“the temperature is high. the aMasJa Iear MeUt the IMue mountain a TeeJ ago and
moQed to the riQer. it Uishes saMmon”.
● The remaining letters have low frequency; hence, many attempts are to do before recovering the plaintext.
If “Uishes” is “fishes”, then “saMmon” is “salmon.” Associations U↔f and M↔l lead to
“the temperature is high. the alasJa Iear left the Ilue mountain a TeeJ ago and moQed
to the riQer. it fishes salmon”. “moQed to the riQer” is likely to be “moved to the river”,
Associations Q↔v leads to
“the temperature is high. the alasJa Iear left the Ilue mountain a TeeJ ago and moved
to the river. it fishes salmon”.
From the words river, fishes, and salmon, we can guess Alaska and week by associations J↔k and T↔w. The
last words to guess are bear and blue.
Therefore, the plaintext was: ”the temperature is high. the alaska bear left the blue mountain
a weeJ ago and moved to the river. it fishes salmon”., which has been encrypted with an affine cipher
y = 3 x + 5.
Problem 4.6
1) In Caesar’s cipher, any letter x is replaced by a letter y using formula y = x + k mod 26. Therefore, a single letter x1 and
its encrypted letter y1 are enough to recover Caesar’s cipher key k. That is, k = y1 − x1 mod 26.
2) In affine cipher, any letter x is replaced by a letter y using formula y = x + k mod 26, where a ∈ Z26
* and b ∈ Z . Therefore,
26
two distinct letters x1 and x 2 and their encrypted letters y1 and y2 are enough to recover an affine cipher key (a, b). That
is, given two equations y1 = ax1 + b mod 26 and y2 = ax 2 + b mod 26 , a and b are unique.
3) In Vigenere’s cipher, any letter M j of message M is encrypted using letter K j of the expanded key, as
M ′j = ( M j + K j ) mod 26, 0 ≤ j < len( M ) . Thus, M ′j − M j = K j mod 26. Therefore, L distinct pairs of letters and their
encryptions are enough to recover a Vigenere’s cipher key of length L.
Problem 4.7
Let n be the number of rotors installed in an Enigma machine, where n = {3, 4}. Let rn and r1 denote the leftmost and right-
most rotors, respectively.
If all rotors have a single notch, then each rotor ri+1 makes a step when rotor ri finishes a full revolution. Therefore,
Enigma returns to its start position after pressing 26n keys.
As mentioned previously, some rotors may have two (or even more) notches. If a rotor ri has two notches, then in a full
revolution, it triggers two steps of rotor ri+1. Thus, rotor ri+1 makes a full revolution after 13 full revolutions of rotor ri.
26n
Therefore, the period of ciphering alphabet of Enigma with n rotors is n−1 , where ci ∈ {1, 2} denotes the number of
∏ ci i=1
notches of rotor ri. Therefore, doubling the notches on rotors reduces the security strength of ciphering.
Problem 4.8
Let ( M1 , C1 ) and ( M 2 , C2 ) be two pairs of plaintext–ciphertext. The same OTP key k is used to encrypt both plaintexts.
Hence, C1 = M1 ⊕ k and C2 = M 2 ⊕ k . C1 and C2 are known to the adversary. Thus, the latter can compute:
C1 ⊕ C2 = ( M1 ⊕ k ) ⊕ ( M 2 ⊕ k )
= ( M 1 ⊕ M 2 ) ⊕(k ⊕ k ) = M 1 ⊕ M 2
Notice that to recover both plaintexts, the latter must be of the same bit-length.
Let M1,i and M 2,i denote letter i in plaintexts M1 and M 2, respectively. Also, let left 3(l) denote the three leftmost bits of a
7-bit ASCII letter l.
Without loss of generality, we only focus on uppercase letters and space. Recall the ASCII codes (in Hexadecimal):
space → 2016 , A → 4116 , B → 4216 , O → 4 F16, → 5016 , …, → Y 5916 , Z → 5 A16. The ASCII code has some characteristics
that can serve the adversary to speed up the attack (i.e. recover plaintexts):
140 4 Symmetric Ciphering
● If M1,i ⊕ M 2,i = 00 , then M1,i = M 2,i . Therefore, recovering a letter in one ciphertext results in recovering the same letter
in the other ciphertext.
● Space code is 2016 , having a single 1-bit, and the codes of uppercase letters are greater than 4116 . If M1,i and M 2,i are two
letters, then M1,i ⊕ M 2,i < 1 A16. If M1,i ⊕ M 2,i > 2016 , then either M1,i or M 2,i is a space. Hence, ( M1,i ⊕ M 2,i ) ⊕ 2016 is a letter
included in one plaintext; and the other plaintext has a space at the same position. Example, 5 A16 ⊕ 2016 = 3 A16 > 2016.
Therefore, one plaintext has a letter Z and the other has a space. Such a property is very useful to speed up the attack,
since spaces are very frequent in English text (nearly 19% of characters are spaces). In addition, spaces are unlikely
to occur at the same positions in distinct plaintexts, which results in more letters recovered in both ciphertexts.
● Codes of letters A to O start with 100, while codes of letters P to Z start with 101. If left 3( M1,i ⊕ M 2,i ) = 000, then both
letters M1,i and M 2,i are in the same half of alphabet, i.e. either in A, O or in P, Z . If left 3( M1,i ⊕ M 2,i ) = 001, then
letters M1,i and M 2,i are not in the same half of alphabet. Such property is useful while testing different letters.
The adversary takes advantage of the ASCII characteristics to automatically recover some letters. Then, he/she applies a
crib dragging technique, i.e. guess some words likely to be in the original plaintexts, XOR them with the ciphertexts and
derive a part of the key, which, in turn, serves to recover a word in the other ciphertext. Repeat the guess until both plain-
texts are recovered.
Problem 4.9
1) Indeed, OTP suffers malleability vulnerability under the man-in-the-middle attack, which can be shown as follows:
Bob sends a ciphertext C1 = M1 ⊕ k to Alice.
Eve, the adversary, intercepts ciphertext C1 and computes C ′ = C1 ⊕ M ′, where M ′ is either a random or a specific
plaintext chosen by Eve.
When Alice receives the ciphertext C ′ , she obtains, after decryption, a plaintext M 2 :
M 2 = C ′ ⊕ k = C1 ⊕ M ′ ⊕ k = M1 ⊕ k ⊕ M ′ ⊕ k = M1 ⊕ M ′
M 2 is distinct from M1 . Therefore, integrity is no more assured to Alice.
2) In the ciphertext C intercepted by Eve, a value of 100010 = 0011111010002 is included starting from bit-position p. Eve
forges a ciphertext as follows:
Copy the ciphertext: C ′ = C
Change bits at locations p to p + 11:
N = (0011111010002 ) ⊕ (0000 000010102 ) = (00111110 00102 )
M 2,3 = C ′ p + 12, len(C ) ⊕ k p + 12, len(C ) = M1 p + 12, len(C )
Notes
1 Congruence was discovered in the 18th century and Caesar’s ciphering made use of tables. Congruence is used in this chapter
to formalize the idea of Caesar’s cipher.
2 Genuine pictures of ENIGMA are available from several national army museums and websites including Wikipedia and
Cryptomuseum.com.
3 Rotors numbered VI, VII, and VIII have two, or even more, turnover notches; thus, they trigger two (or more) steps for the
rotor on their left after a full revolution. It has been shown that it was not a good idea from security point of view, because
double stepping of the rotor on the left reduces the substitution alphabet period.
4 “Six” is the number of rotors arrangements in the earliest versions of Enigma machine.
1
5 “Randomly selected” means that any key K has a probability of to be selected.
K
6 In the information theory, the entropy of a random variable X , denoted H ( X ), is the average level of uncertainty inherent in
the variable possible outcomes (see Chapter 16).
7 In the information theory, the conditional entropy, denoted H ( M | C ), quantifies the amount of information needed to
describe the outcome of a random variable M given that the value of another random variable C is known.
References
This chapter introduces three aspects of cryptography, namely hash functions, Message Authentication Codes, and Digital
signature. All of them are of paramount importance for providing integrity and authentication guarantees. Hash functions
produce digital fingerprints, also called Message Authentication Codes (MAC), which are used to meet multiple needs:
● Verifying integrity of messages and files: a hash works like a fingerprint, which uniquely represents data. Thus, any change
in an email, a file, a software, an image, and so on, results in a hash, which does not match the hash generated by the sender.
● Generating and verifying digital signatures,1 which enable to verify the authenticity of a message. If the encrypted hash
is altered, the verification fails and if the message is altered, the hash computed by the recipient does not match the mes-
sage. In both cases, the message is rejected.
● Facilitating secure password storage and verification: instead of storing and exchanging passwords, hashes of passwords
are stored and used to control local and remote logins.
● Since hashes look like random values, hash functions may be used as pseudorandom bit generators.
It is worth noticing that MAC algorithms provide stronger assurance of data integrity than a checksum or an error detect-
ing code. The verification of a checksum or an error detecting code is designed to detect only accidental modifications of
data, while MAC is designed to detect intentional, unauthorized modifications of data, as well as accidental modifications.
MACs can be generated either by hash functions alone or by block ciphers. The first category of MACs is addressed in
this chapter, while block cipher modes of operation that generate MACs are addressed in Chapter 9.
Formally, a hash function H() is defined by: H : {0,1} N → {0,1}n, where {0,1} N is the set of input space and {0,1}n the set of
output space. N and n are the bit-lengths of spaces. H ( x ) is the hash or digest of input x. In practice n is between 160
and 512, while N may be very large.3
Since the input space is much larger than the output space, two distinct inputs x and x ′ may result in the same output,
which is a circumstance called collision. The larger the number of possible hashes, the smaller the chance that two values
will create the same hash. In existing hash functions, collisions are unavoidable, but the probability of collision occurrence
should be minimized.
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
5.1 Hash Functions 143
Preimage resistance
This property means given a hash value z, it should be computationally infeasible to find an input value x that hashes to
z. Formally:
n N
∀ z ∈ {0, 1} , Pr ( Finding x | x ∈ {0, 1} , H ( x ) = z ) ≅ 0
Pr() denotes probability. Preimage resistance property of hash function protects against an attacker who has a hash and
wants to find the associated data. For example, the attack would be the recovery of a password from the hash of the
password.
Second preimage resistance (also referred to as weak collision resistance)
This property means given an input x1, it is computationally infeasible to find an input x 2 distinct from x1 with the same
hash. Formally:
N
(
∀ x1 ∈ {0,1} , Pr Finding x 2 | x 2 ∈ {0,1} ,
N
x1 ≠ x 2 , )
H ( x1 ) = H ( x 2 ) ≅ 0
Second preimage resistance property of hash function protects against an attacker who has an input value and its hash and
wants to substitute a forged value to the original input value. In other words, pre-image resistance preserves data
integrity.
Collision resistance
This property means it should be computationally infeasible to find any two inputs that result in the same hash. Formally:
( N
)
Pr Finding x1 , x 2 | x1 , x 2 ∈ {0,1} , H ( x1 ) = H ( x 2 ) ≅ 0
Notice that if a hash function is collision-resistant, then it is second preimage resistant (see Problem 5.7). Collision resis-
tance prevents from creating two distinct data or messages with the same hash. For example, in password management
systems, hashes are associated with passwords. Passwords are supplied to users when they register and hashes are stored
in the password file in the authentication system. When a user tries to log in the system, he/she provides his/her password,
then the verification system computes the hash of the password entered by the user and compares it to the one stored in
the password hash file. Consequently, distinct hashes should be associated to distinct passwords; otherwise, a user may be
admitted to access a service granted to another user.
Even the hash functions, which have been considered secure for a long time, may have collisions. For example, Figure 5.1
shows a collision attack against MD5, a hash function widely used in the past. Two documents, File1.ps and File2.ps, with
distinct contents have the same MD5 hash.
The output of hash functions used in operational cryptosystems looks like4 a random string and any small change (of one
bit or one byte) results in entirely different hash. Below are three examples of hashes produced by SHA256 algorithm asso-
ciated with two strings “Hello” and “hello” which have major differences:
SHA256(“Hello”) = 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969
SHA256(“hello”) = 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Alice Falbala fulfilled all the requirements of the Roman Empire Alice Falbala is given full access to all confidential and secret
intern position. She was excellent at translating roman into her gaul information about GAUL.
native language, learned very rapidly, and worked with considerable
independence and confidence.
Her basic work habits such as punctuality, interpersonal deportment, Sincerely,
communication skills, and completing assigned and self-determined
goals were all excellent. Julius Caesar
I recommend Alice for challenging positions in which creativity.
reliability, and language skills are required.
Sincerely,
Julius Caesar
Figure 5.1 Example of collision attack against MD5. MD5(File1.ps) = a25f7f0b29ee0b3968c860738533a4b9. MD5(File2.ps) =
a25f7f0b29ee0b3968c860738533a4b9. From: http://web.archive.org/web/20071226014140 /http://www.cits.rub.de/MD5Collisions.
5.1 Hash Functions 145
continuation of blocks of string key || M || P and the resulting hash H( Ӻ) matches the hash H (key M P || Ӻ) that would be
produced by a normal hash function.
Proof of correctness
Let P ′ be the padding string to append to fake data Ӻ, such that len( Ӻ || P′) is a multiple of the block size L and K, the
number of blocks of the string Ӻ || P ′.
Let M ′ be the bit string M || P || Ӻ that the recipient receives.
Let 𝕙 ( B, v ) denote a one-block hash function, which hashes one block B using an initialization vector v and returns a
hash.
( ) ( )
Let B1 , B 2 , ..., Bm be the sequence of blocks representing the string key M P and Bm+1 , Bm+2 , ..., Bm+ K be the block
sequence representing the string Ӻ || P ′.
By design of Merkle-Damgård construction–based hash functions, given a bit-string X of N blocks B1 , B 2 , ..., B N , the
hash function H() is defined by:
H ( X , IV ) = H N , such that:
( )
Hk= 𝕙 B k , H k−1 , 1 < k ≤ N
H = 𝕙 ( B , IV ), where IV
1 1
denotes the initialization vector.
Upon reception of padded message M ′, the legitimate verifier computes the following hash:
(( ) )
H ((Key || M || P || Ӻ || P ′), IV ) = H B1 , B 2 ,…, Bm , Bm+1 , Bm+2 , ..., Bm+ K , IV
(( ) (( ) ))
= H Bm+1 , Bm+2 , ..., Bm+ K , H B1 , B 2 , ..., Bm , IV
= H ( Ӻ || P ′, H ((key || M || P ), IV ))
The adversary knows the hash v computed by the legitimate sender, v = H (key || M || P, IV ). He/she modifies the hash
□
function to use a chosen initialization vector and computes H( Ӻ || P ′, v ). Thus, the hash computed by the adversary is the
same as the one computed by the verifier; and the received message M ′ is validated.
SHA algorithm family is the most used hashing algorithms in current cryptosystems and it is very likely to dominate in the next
decade(s). SHA family is a set of NIST standards named SHA-0, SHA-1, SHA-2, and SHA-3. The most popular algorithm is SHA-
1. SHA-0 was published in 1993, SHA-1 in 1995, SHA-2 in 2002, and SHA-3 in 2015. SHA-0 was replaced by SHA-1, which in turn
was attacked with success, but still used. Current and future cryptosystems are either using or moving to SHA-2 or SHA-3.
Each subfamily may have more than one variant. SHA variants differ in terms of maximum message size, hash size,
block size, and number of rounds (see Table 5.1). SHA-1 and SHA-2 are similar in design, while SHA-3 relies on different
design principles. SHA-1 and SHA-2 make use of Merkle-Damgård hash construction model [1, 2], while SHA-3 makes use
of sponge construction model [3, 4].
SHA-2 and SHA-3 offer the same set of hash lengths and the same security strengths levels. Main characteristics of SHA
variants are summarized in Table 5.1. It is worth noticing that the most important characteristic, when security is of con-
cern, is the message digest size.
● Data representation
–Hashing algorithms manipulate words of either 32 or 64 bits. An integer between 0 and 232 − 1 (or 264 − 1 ) is repre-
sented by a word of 32 or 64 bits, respectively. The least significant bits of an integer are rightmost bits of the word.
–Message to hash is split into blocks with a fixed size of either 512 or 1024 bits.
–Blocks of the message to hash are labeled B1 , …, Bm , where m is the number of blocks of the message including pad-
ding bits.
–To be processed, each block B i is stored in 16 words labeled B0i , B1i , …, B15i
.
● Message padding
The purpose of padding is to ensure that the bit-length of the padded message is a multiple of block size. Padding bits are
appended to the end of the initial message in a format known to both parties. Let l denote the bit-length of the message
M to hash. Two distinct padding methods are used:
Padding in SHA-1, SHA-224, and SHA-256 is done as follows: append a bit “1” at the end of message M, followed by k
zero bits, where k is the smallest positive integer such that l + 1 + k ≡ 448 mod 512, then append the binary value of l
represented on 64 bits.
Padding in SHA-384, SHA-512, SHA-512/224, and SHA-512/256 is done as follows: append a bit “1” at the end of
message M, followed by k zero bits, where k is the smallest positive integer such that l + 1 + k ≡ 896 mod 1024, then
append the binary value of l represented on 128 bits.
Bitwise operations used by SHA-x are: ∧ (and), ∨ (or), ⊕ exclusive or, and ¬ (complement).
● Bit operations used by SHA-x
K i = 5a827999 if 0 ≤ i ≤ 19 K i = 6ed9eba1 if 20 ≤ i ≤ 39
K i = 8f 1bbcdc if 40 ≤ i ≤ 59 K i = ca62c1d6 if 60 ≤ i ≤ 79
148 5 Hash Functions, Message Authentication Codes, and Digital Signature
SHA-1 uses a sequence of functions f0 , f1 , ..., f79 . Each function fi operates on three 32-bit words and produces a 32-bit
word as output. The computation of logical functions depends on their index as follows:
fi ( x , y, z ) = Ch( x , y, z ) =( x ∧ y ) ⊕ (¬x ∧ z ) if 0 ≤ i ≤ 19
fi ( x , y, z ) = Parity ( x , y, z ) = x ⊕ y ⊕ z if 20 ≤ i ≤39
fi ( x , y, z ) = Maj( x , y, z ) = ( x ∧ y ) ⊕( x ∧ z )⊕( y ∧ z ) if 40 ≤ i ≤ 59
fi ( x , y, z ) = Parity ( x , y, z ) = x ⊕ y ⊕ z if 60 ≤ k ≤ 79
● SHA-1 initialization
3) Process 80 rounds:
for t = 0 to 79 do
5) After processing block Bm, H0m || H1m || H2m || H3m || H 4m is the 160-bit string representing the hash of the entire message.
Ch( x , y, z ) =( x ∧ y ) ⊕ (¬x ∧ z )
Maj( x , y, z ) = ( x ∧ y ) ⊕ ( x ∧ z )⊕( y ∧ z )
{256}
∑ 0 ( x ) = ROTR2 ( x ) ⊕ ROTR13 ( x ) ⊕ ROTR22 ( x )
{256}
∑1 ( x ) = ROTR6 ( x ) ⊕ ROTR11 ( x ) ⊕ ROTR25 ( x )
σ0{ } ( x ) = ROTR7 ( x ) ⊕ ROTR18 ( x ) ⊕ SHR3 ( x )
256
SHA-224 and SHA-256 use the same sequence of 64 constant 32-bit words, K 0{ } , ..., K 63
{256}
256
, defined as follows, from the left
to the right:
● SHA-256 Initialization
Bti 0 ≤ t ≤ 15
Wt = {256} {256}
σ
1 (Wt −2 ) + Wt −7 + σ0 (Wt −15 ) + Wt −16 16 ≤ t ≤ 63
2) Initialize the five working words:
3) Process 64 rounds:
for t = 0 to 63 do
{256} {256}
Tmp1 = h + ∑ 1 (e ) + Ch(e, f , g ) + K t + Wt
{256}
Tmp2 = ∑ 0 (a) + Maj(a
a, b, c )
h = g; g = f ; f = e
e = d + Tmp1; d = c; c = b; b = a; a = Tmp1 + Tmp2
5) After processing block Bm , H0m || H1m || H2m || H3m || H 4m || H5m || H6m || H7m is the 256-bit string representing the hash of
the entire message.
150 5 Hash Functions, Message Authentication Codes, and Digital Signature
● The message hash is obtained by keeping only 7 words of the final block hash, i.e. H0m || H1m || H2m || H3m || H 4m || H6m.
Ch( x , y, z ) =( x ∧ y )⊕(¬x ∧ z )
Maj( x , y, z ) = ( x ∧ y )⊕( x ∧ z )⊕ ( y ∧ z )
{512}
∑ 0 ( x ) = ROTR28 ( x ) ⊕ ROTR34 ( x ) ⊕ ROTR39 ( x )
{512}
∑1 ( x ) = ROTR14 ( x ) ⊕ ROTR18 ( x ) ⊕ ROTR41 ( x )
σ1{ } ( x ) = ROTR1 ( x ) ⊕ ROTR8 ( x ) ⊕ SHR7 ( x )
512
{512} {512}
SHA-384, SHA-512, SHA12/224, and SHA-512/256 use the same sequence of 80 constant 64-bit words, K 0 , ..., K 79 ,
defined as follows, from left to right:
● SHA-512 initialization
Bti 0 ≤ t ≤ 15
Wt = {512} {512}
σ
1 (Wt −2 ) + Wt −7 + σ0 (Wt −15 ) + Wt −16 16 ≤ t ≤ 63
2) Initialize the five working words:
3) Process 80 rounds:
for t = 0 to 79 do
{512} {512}
Tmp1 = h + ∑ 1 (e ) + Ch(e, f , g ) + K t + Wt
{512}
Tmp2 = ∑ 0 (a) + Maj(a
a, b, c )
h = g ; g = f ; f = e; e = d + Tmp1; d = c; c = b; b = a
a = Tmp1 + Tmp2
5) After processing block Bm , H0m || H1m || H2m || H3m || H 4m || H5m || H6m || H7m is the 256-bit string representing the hash of
the entire message.
– SHA-512/224 initialization
– SHA-384 keeps six 64-bit words, H0m || H1m || H2m || H3m || H 4m || H5m
– SHA-512/224 keeps three 64-bit words and the left half of the fourth 64-bit word, H0m || H1m || H2m || left_half H3m ( )
– SHA-512/256 keeps four 64-bit words, H0m || H1m || H2m || H3m
associated with a bit string of a bit-length of b is composed as follows: five planes, five sheets, and w slices. Two quantities,
labeled w and l, are associated with each bit string length b (see Table 5.2). They are used in transformation specification.
Rules for conversion
1) A string S of size b, whose bits are labeled S 0 , S 1 , ..., S b − 1 is converted into a state array A as follows:
For all triples ( x , y, z ) such that 0 ≤ x < 5, 0 ≤ y < 5, 0 ≤ z < w do:
A x , y, z = S w (5 y + x ) + z
2) A state array A is converted into a bit string S of size b, whose bits are as follows:
where:
Plane ( j) = Lane (0, j) || Lane (1, j) || Lane (2, j) || Lane (3, j) || Lane ( 4, j), 0 ≤ j < 5
Lane (i, j) = A i, j, 0 || A i, j,1 || A i, j, 2 || … || A i, j, w − 1 , 0 ≤ i < 5 and 0 ≤ j < 5
154 5 Hash Functions, Message Authentication Codes, and Digital Signature
Example 5.1
Let b = 100.
Any string of 100 bits is organized into four slices of 25 bits each. Figure 5.4 shows the location of each bit on the four
slices.
C x , z = A x , 0, z ⊕ A x ,1, z ⊕ A x , 2, z ⊕ A x , 3, z ⊕ A x , 4, z
– For all triples ( x , y, z ) such that 0 ≤ x < 5, 0 ≤ y < 5, and 0 ≤ z < w do:
A′ x , y, z = A x , y, z ⊕ D x , z
Step mapping ρ
The effect of ρ is to rotate the bits of each lane by a length, called offset, which depends on x and y coordinates of the lane.
More formally, mapping ρ is specified as follows:
– For all z such that 0 ≤ z ≤ w do: A′ 0, 0, z = A 0, 0, z
– ( x , y ) = (1, 0)
– For t = 0 to 23 do:
i) For z such that 0 ≤ z < w do: A ′ x , y, z = A x , y, ( z − (t + 1)(t + 2) / 2) mod w
ii) ( x , y ) = ( y, (2 x + 3 y ) mod 5)
Step mapping π
The effect of π is to rearrange the positions of the lanes. More formally, mapping π is specified as follows:
For all triples ( x , y, z ) such that 0 ≤ x < 5 , 0 ≤ y < 5 , and 0 ≤ z < w do:
5.2 Secure Hash Algorithms (SHA) 155
Step mapping χ
The effect of χ is to XOR each bit with a nonlinear function. More formally, mapping χ is specified as follows:
For all triples ( x , y, z ) such that 0 ≤ x < 5, 0 ≤ y < 5, and 0 ≤ z < w do:
Step mapping τ
The effect of τ is to modify some of the bits of Lane(0, 0) in a manner depending on the index of the round. The input of
τ is a pair ( A, ir ), where A is a state array and ir a round index; its output is a state array A′ . More formally, mapping τ
is specified as follows:
– For all triples ( x , y, z ) such that 0 ≤ x < 5, 0 ≤ y < 5, and 0 ≤ z < w do: A′ x , y, z = A x , y, z
– RC = 0 w ( RC is a string of w 0-bits)
– l = log2 (b / 25)
– For j = 0 to l do: RC 2 j − 1 = rc ( j + 7ir )
– For all z such that 0 ≤ z < w do: A′ 0, 0, z = A′ 0, 0, z ⊕ RC z
Function rc (t ) is specified as follows:
– If t mod 255 = 0, then return 1
– R = 10000000 (R is an array of eight bits)
– For i = 1 to 255 do:
Bit string N is concatenated with the padding bits produced by Padding function to yield a sequence of bit strings
P0 , P1 , P0 , ..., Pn−1 . Each bit string Pi ,0 ≤ i ≤ n − 1, has a fixed length of r bits. n, the number of strings, is equal to bit-length
( )
of padded input by r, i.e. n = len( N ) + len ( Padding (r , len( N ))) / r . Notice that bit strings P0 , P1 , P0 , ..., Pn−1 are equivalent to
blocks B1, B 2 … in SHA-1 and SHA-2.
Sponge function is composed of two stages: absorbing and squeezing. In absorbing stage, the transformation of each bit
string Pi , 1 ≤ i ≤ n − 1, is yielded by function f whose input is Pi and the result of transformation of bit string Pi−1. The bit
string S yielded by the absorbing stage is used as input to the squeezing stage in which function f is applied L times and
in each iteration, the r most-left bits of the result of function f are appended to a bit string Z initialized to empty string.
d
The number of iterations of squeezing stage is L = .
r
The algorithm of Sponge f , Padding, r ( N , d) is specified as follows:
1. P = N || Padding (r , len( N ))
2. n = len (P ) / r (by construction, len( P ) is a multiple of r )
3. Let P0 , P1 , P0 , … , Pn−1 be a sequence of strings of length r such that P = P0 || P1 || … Pn−1
4. c = b − r (r is always less than b)
5. S = 0b (S is a sequence of b 0-bits)
6. ( (
for i = 0 to n −1 do S = f S ⊕ Pi || 0c ))
7. Let Z be the empty string
8. Z = Z || Truncr ( S ) (keep the r most-left bits of string S )
9. if d ≤ len( Z ), then return Truncd ( Z ); else continue
10. S = f (S )
11. go to step 8
5.3 Message Authentication Codes 157
b, the length of bit string size manipulated by Keccak_ p permutation, is greater than d, the hash size. c = b − r is called the
capacity of the sponge function.
SHA-3 standard made the following choices:
● b = 1600: the size of state arrays manipulated by mapping steps of Keccak-p permutation is 1600. The rationale of choice
is that all SHA-3 variants have the same implementation support and 1600 is a multiple of 64 and 32;
hence, Keccak_ p 1600,. favors 64-bit CPUs and remains efficient on 32-bit CPUs.
● c = 2d : with such a capacity, there are no generic attacks with expected complexity below 2d.
● r = 1600 − 2d : since by design b = r + c , r = 1600 − 2d .
● N r = 24: 24 rounds are estimated sufficient to provide resistance against potential attacks.
● SHA-3 Padding function is labeled " pad10 * 1". It returns a string equal to "1 || 0 j || 1", where j = ((−len( N ) − 2) mod r
and 0 j is a sequence of j 0-bits. pad10 * 1 is easy to specify and implement, while providing compliance regarding the
randomness of padding bits.
Concrete sponge function model used to specify SHA-3 functions is labeled Keccak c , where c is the capacity of the
sponge function:
Keccak c def Sponge Keccak_ p 1600, 24 , pad 10 * 1, 1600 − c
Given an input bit string N and an output length d, Keccak[c]( N , d) produces a bit string of length d, which is a hash of N.
SHA-3 standard specified four hash functions based on sponge function whose capacity is the double of the hash
bit-length:
● SHA3-224 ( M ) = Keccak 448 ( M || 01, 224)
● SHA3-256 ( M ) = Keccak 512 ( M || 01, 256)
● SHA3-384 ( M ) = Keccak 768 ( M || 01, 384)
● SHA3-512 ( M ) = Keccak 1024 ( M || 01, 512)
Notice the two additional paddings bits are appended to message M before launching the sponge function.
This chapter focuses on the second component, i.e. generation of tags. The other components depend on the underlying
cryptosystems either symmetric or asymmetric. In symmetric systems, the shared secret is used to encrypt and to sign. In
public key cryptosystems, specific methods are used to generate private and public key and to generate signatures using
hash functions and verifying them (see Chapters 12 and 13).
MAC Properties:
1) P1: MAC systems should adapt to a large number of applications. Thus, they should accept arbitrary length of message,
while producing a fixed length output.
2) P2: preserve the integrity of message.
3) P3: authenticate the message sender.
P1 and P2 properties are fulfilled by hash functions, while P3 is provided by using a shared secret key. It is worth noticing that
MACs do not provide the property of non-repudiation assured by signatures, because any user who share the secret key can verify
and generate MACs. In contrast to MAC, a digital signature is generated using the private key of a user. Since this private key is
only accessible to its holder, a digital signature proves that a message was signed by none other than that private keyholder.
There exist two main standard categories of MACs:
1) Hash function-based MACs, which are addressed in this chapter.
2) Block cipher-based MACs, which are addressed in Chapter 9.
5.3.2.1 HMAC
HMAC is the acronym for either keyed-hash message authentication code or hash-based message authentication code. HMAC
was originally proposed by Bellare, Canetti, and Krawczyk [9] and then adopted by the IETF in 1997 [10]. HMAC is widely used
in particular jointly with SHA-1 or SHA-2. Before being broken, MD5 also was widely used in HMAC implementations.
HMAC is a MAC family parameterized with the underlying hash function. HMAC instances are denoted HMAC-H, where
H may be any hash function including SHA-1, MD5, SHA-256, SHA3-512, etc. HMAC takes two parameters M, the message,
and k, the secrete key, and generates a digest HMAC ( M , k ) of a length of n bits, which is the same as the hash function output
bit-length. HMAC can be used with any secret key length. However, secret keys with length less than the length of block size
processed by the hash function are strongly discouraged, because they would decrease the security strength of the HMAC as a
whole. Figure 5.7 illustrates the diagram of HMAC. HMAC is a double hashing method to provide resistant MACs.
ik ′ denotes the block yielded after XORing the expanded keyy k ′ with i Pad block.
ok ′ denotes the block yielded after XORing the expanded keyy k ′ with o Pad block.
h(i ) denotes the inner hash and P (h(i ) ), the block yielded after padding h(i ) .
Given a message M and a secret key k, the yielded MAC is expressed as:
Security of HMAC
The security of HMAC depends on the security strength of the underlying hash function H, which in turn depends on the
size of hash function output. HMAC is resistant to common attacks against MAC, including recovering the private key or
altering the message content. In HMAC, the inner hash (i.e. h(i ) ) would be vulnerable to length-extension attack, while the
outer hash (i.e. HMAC ( M , k )) is not (see Problem 5.19).
5.3.2.2 KMAC
KMAC is the acronym for Keccak Message Authentication Code. It is based on Keccak function of SHA-3 [11]. Two variants
exist, KMAC-128 and KMAC-256. Notice that 128 and 256 in KMAC variants refer to the capacity of the sponge function
(see Section 5.2.2.3). KMAC functions take the following parameters:
● K, a key of a variable bit-length, which depends on the required security strength, but len ( K ) is at most 22040 .
● M, a message of a variable bit-length.
● L, the requested bit-length of the output (i.e. the tag length), with L < 22040 .
● S, an optional customization bit-string, which may be empty, of length len (S ) < 22040.
Let KMAC〈m〉 denote either KMAC128 or KMAC256. KMAC〈m〉 is defined by:
function KMAC〈m〉( K , M , L, S )
1. if m = 128, then R = 168 else R = 136
2. X ′ = BytePad (EncodeString( K ), R ) || M || RightEncode( L )
3. T = BytePad (EncodeString(" KMAC ") || EncodeString( S ), R )
4. Res = Keccak[2 * m]( T || X ′ ||00, L )
5. return Res
function EncodeString(Y )
1. Y ′ = LeftEncode ( len(Y )) || Y
2. return Y ′
function RightEncode( x ) :
# encode integer x as byte-string ending with the byte-length of x:
1. n is the smallest positive integer such that 28n > x
n
(
2. Let x1 x2 …x n be the representation of x in base 256, i.e. x = ∑ i =1 x i * 28( n−i ) )
3. for i = 1 to n do Oi = enc8( x i ) (13)
4. On+1 = enc8( n )
5. return (O1 || O2 || … || On+1 )
function LeftEncode( x ) :
# encode integer x as byte-string starting with the byte-length of x:
1. n is the smallest positive integer such that 28n > x
2. Let x1 x2 …x n be the representation of x in base 256
3. for i = 1 to n do Oi = enc8( x i )
4. O0 = enc8(n)
5. return (O0 || O1 || O2 || … || On )
function BytePad (Y , w ) :
# Prepend an encoding of w to the input-string bit- string Y,
# then pad it with zeros until the new bit-string is multiple of w
1. z = LeftEncode(w ) || Y
5.4 Digital Signature 161
● Signature with appendix14: given a message M, the signer generates a signature S from the hash of message and sends a
pair ( S, M ) . The verifier decrypts the signature S to yield a hash H ′ , computes H, the hash of the received message, then
compares both hashes (see Figure 5.8).
● Signature with message recovery: given a message M, all or some of message M is embedded in the signature S. When the
message is entirely embedded, the verification procedure requires only the signature S and recovers M from the
signature.
In symmetric cryptosystems, the same key, which is shared by both parties, is used for generating and verifying signature.
In asymmetric cryptosystems, the signer makes use of his/her private key to generate the signature, while the verifier
makes use of the public key of the signer to verify the signature.
Digital signature algorithms include:
● RSASSA (RSA Signature Scheme with Appendix), presented in Section 12.2.6.
● DSA (Digital Signature Algorithm), presented in Section 12.4.
● ElGamal signature algorithm, presented in Section 12.3.4.2.
● ECDSA (Elliptic Curve Digital Signature Algorithm) and EdDSA (Edwards Elliptic Curve Digital Signature Algorithm),
presented in Sections 13.5.5–13.5.6.
All those algorithms make use of hash functions. They are addressed in detail in Chapters 12–14 when the foundations
of the underlying public key are introduced. Then, attacks against digital signatures produced by public key algorithms are
discussed.
Digital signature and MACs are used for guaranteeing message integrity and authentication. MAC algorithms do not pro-
vide non-repudiation service because the secret used to produce MACs may be shared by more than two users; and even
with two users, both can produce MACs. Whereas with digital signatures, each key is private to each user; hence, there is
non-repudiation as only the private keyholder can sign with his/her key.
It is worth noticing that message authentication and user authentication are distinct services. Message authentication,
also called message origin authentication, enables the receiver to check that the MAC accompanying a message has been
generated by a user sharing a key with him/her. Whereas user authentication (also called entity authentication) enables
the recipient to check if the message sender engaged in the current session is really the person who is pretending to be. Let
us take the following two scenarios to show the difference between both authentications.
Alice, Bob, and Eve share a secret. Bob computes the MAC of a message, then sends the message and its MAC to Alice.
Alice forwards the message and the MAC to Eve, who can verify that the message was originated by a holder of the shared
secret. However, Eve is not communicating with Bob; thus, she cannot authenticate him.
Alice and Eve know the public key of Bob. Bob signs a message and sends the message and its signature to Alice. Alice
forwards the message and signature to Eve, who can verify that the message was signed by Bob. However, Eve is not com-
municating with Bob; thus, she cannot authenticate him. Thus, used alone, neither MACs nor signatures provide entity
authentication. Other mechanisms are required to provide user authentication (see Chapter 15).
5.6 Problems
Problem 5.1
Fundamental security properties include confidentiality, integrity, authenticity, and non-repudiation.
1) Which of the above properties are provided by digital signature?
2) Which of the above properties are provided by MACs?
Problem 5.2
Hashing and encryption are two cryptographic functions, which manipulate inputs to produce a kind of random output.
What is the fundamental difference between those functions from a security point of view?
Problem 5.3
Discuss why the following functions cannot be used as hash functions regarding preimage and collision resistance properties:
1) H1 ( x ) is a function that returns the parity bit of x .
2) H2 ( x ) is defined by H2 ( M ) = P ( M ) mod g ( x )
where P ( M ) is a polynomial associated with M such that P ( M ) = mi . x i + mi−1 . x i−1 + m1 . x 1 + m0, where mi, …, m0 are
bits of M and g ( x ) is a given polynomial of degree k.
Problem 5.4
Discuss the hash function properties of the following function for generating MACs.
Let X be a bit-string; X = X 1 || X 2 || … || X m, where X i=1,…,m are 128-bit blocks.
Given a 128-bit key K, the MAC is generated as follows:
MAC ( X , k ) = Cm + K mod 2128
where: C0 = 99 and Ci = Ci−1 ⊕ X i, i = 1, ..., m
164 5 Hash Functions, Message Authentication Codes, and Digital Signature
Problem 5.5
Discuss why CRC (Cyclic Redundancy Check), used to protect against transmission errors, is not appropriate for use as
hash functions? Which hash function properties are not fulfilled with CRCs?
Problem 5.6
Why collision-free hash functions do not exist?
Problem 5.7
Prove that a collision-resistant hash function also is second-preimage resistant.
Problem 5.8
2m m
Let H1: {0, 1} → {0, 1} be a collision-resistant hash function.
4m m
Define H2: {0, 1} → {0, 1} as follows:
H2 ( x1 || x 2 ) = H1 ( H1 ( x1 ) || H1 ( x 2 )), where x1 ∈ {0,1}2m and x 2 ∈ {0,1}2m
Prove that H2 also is collision-resistant.
Problem 5.9
Let H1 () be a collision-resistant hash function. Do the following constructions provide collision-resistant hash functions?
1) H2 ( x ) = H1 ( x ) || x
2) H3 ( x ) = H1 ( x ⊕ 1)
3) H 4 ( x ) = H1 ( x ⊕ c ) , c is a constant integer less than max ( x ) .
Problem 5.10
One of the applications of hash functions is the protection of passwords in authentication systems. Instead of storing the pass-
words in clear, only password hashes are stored. To authenticate a user, his/her password is hashed and the resulting hash is
compared to that stored on the authentication system. Therefore, even if the password file is stolen, the passwords are very
hard to recover. Assume that the hash function used by an attacked authentication system is known to the adversary.
1) Is it secure to use a hash bit-length of 10 to protect 500 passwords?
2) Assume that an adversary has access to 1000 hashes of 8-byte passwords. Is it difficult, from the computational feasi-
bility point of view, for the adversary to gain access to the system as a legitimate user with a brute-force attack?
3) Assume that each of 1000 passwords is concatenated to a random input called salt so that the appended password has a
bit-length of 512. The authentication system stores the 128-bit hashes of passwords in a file and the salts in another file.
Consider an adversary who has access to the hash file but not the salt file. Can the adversary gain access to the system?
Problem 5.11
Assume that the hash function used by Alice manipulates blocks with a length of 512 bits and the maximum size of data to
hash is 1 G bytes. Alice has an album of 1000 pictures each of 1 M bytes. She has two alternatives to send her album to Bob:
either hash and send each picture separately or zip the album, then hash and send the hashed zipped file.
1) What is the most attack-resistant alternative?
2) Assume that the second preimage is feasible but at a high cost for the adversary. Which alternative is preferred if integ-
rity is of interest?
Problem 5.12
Deterministic generic attacks are attacks that break hash resistance whatever is the hash function. What is the maximum
number of steps required for a generic deterministic attack to succeed in finding a preimage, a second preimage or a
collision? Assume that no dictionary is built in advance.
Problem 5.13
Prove that the number of steps required to preimage brute-force-attack to succeed (at a probability close to 1) is approxi-
mately 2n, where n is the hash bit-length. Use Taylor’s approximation of e x , which states that: e x ≈ 1 + x , when | x | 1.
Problem 5.14
1) Prove that the number of steps required for a collision birthday attack to succeed at a 50% probability is approxi-
mately 2n /2 , where n is the hash bit-length. Birthday paradox is presented in Section 3.4.
2) Infer that the number of steps required to collision birthday attack to succeed at a probability close to 1 is approxi-
mately 2n/2.
5.6 Problems 165
Problem 5.15
Why key length is required in length extension attack?
Problem 5.16
Length extension attack is introduced in Section 5.1.3.2.
1) Explain why SHA-512/224 and SHA-512/256 are not vulnerable to length extension attack.
2) Explain why SHA-3 is not vulnerable to length extension attack.
Problem 5.17
Imagine that a journalist and an editor use a MAC algorithm for message authentication. Then the editor posts a content
sent by the journalist who claims he/she never authored the posted content. In case of legal dispute, who is the winner? In
security terms, do MACs provide non-repudiation service?
Problem 5.18
In length extension attack (see Section 5.1.3.2), the adversary takes advantage of the internal operation of Merkle-Damgård
construction, to append fake data at the end of the original and to generate a MAC without knowledge of the secret key.
1) Show that secret prefix MAC is vulnerable to length extension attack.
2) Assume that the MAC algorithm includes the length of message in the hash computation, i.e.
MAC ( M , k ) = H (key || len( Message ) || Message ). Does the length extension attack still work against secret prefix MAC,
designed with such a hash function, under the assumption the key length is known to adversary?
3) Show that secret suffix MAC is not vulnerable to length extension attack.
Problem 5.19
Explain why HMAC inner hash is vulnerable to length extension attack, while the outer hash is not vulnerable.
Problem 5.1
Fundamental security properties include confidentiality, integrity, authenticity, and non-repudiation.
1) Digital signature provides guarantees regarding integrity, authenticity, and non-repudiation. However, if the plaintext
is not encrypted, the digital signature cannot provide confidentiality.
2) MACs provide integrity and message authenticity guarantees. They do not guarantee confidentiality, if the message is
not encrypted. They do not provide non-repudiation guarantees, as well.
Problem 5.2
Hashing and encryption are two distinct cryptographic functions. Encryption is something used to convert plaintext (read-
able) into ciphertext (indecipherable). Decryption is done either with the same ciphering key, which is a secret, in symmetric
systems or with a key mathematically related to the encryption key in asymmetric systems. In asymmetric systems, mes-
sages are encrypted with public keys and then decrypted with private keys. Hashing is a technique used to produce a fin-
gerprint to characterize uniquely a data, while it does not hide data. In hashing, nothing is secret. Encryption is for ensuring
confidentiality, while hashing is for ensuring integrity.
Problem 5.3
1) H1 ( x ) is a function that returns the parity bit of x.
Given a value of parity bit (i.e. 0 or 1), the half of the input space matches the chosen value. Thus, H1 is not preimage
resistant.
The probability of collision is 50%. Thus, H1 is not collision-resistant.
2) H2 ( x ) is defined by H2 ( M ) = P ( M ) mod g ( x ).
Let k denote the degree of polynomial g ( x ), L denote the degree of polynomial P ( M ), and Q ( x ) a polynomial of
degree L − k.
Given a hash z, any message M such that P ( M ) = g ( x ) * Q ( x ) + P ( z ) matches the chosen hash z. P ( z ) denotes the
polynomial associated with the bit string representing z . Thus, H2 is not preimage-resistant.
All message M ′ such that P ( M ′) = g ( x ) * Q( x ) + r ( x ) , where r ( x ) is a polynomial of degree less than k, have the same
hash, which is r ( x ). Thus, H2 is not collision-resistant.
166 5 Hash Functions, Message Authentication Codes, and Digital Signature
Problem 5.4
With the given function, the MAC is computed as: MAC ( X , K ) = Cm + K mod 2128
The function defined above does not match any hash function property.
No collision resistance: it is easy to find collisions. For example, all permutations of three blocks have the same MAC. That
is:
No preimage resistance: given a MAC h, it is easy to find a preimage. For example, a preimage with a single block X 1 can
be easily found, if C0 and K are known, by the congruence relationship: h = (C0 ⊕ X 1 ) + K mod 2128
No second preimage resistance: given a bit string X and its MAC h, it is easy to find another bit string X ′ with the same
MAC. For example, we can replace blocks X 1 and X 2 in X to obtain X ′ with the same MAC:
( )
CRC ( x ) ≡ S ( x ) * x n mod G ( x ).
(( ) ) ( )
CRC ( x ) ≡ x 4 + x 2 + x + 1 * x 3 mod x 3 + x + 1 = x + 1.
Problem 5.6
Collisions are intrinsic to all existing hash functions. Collison-free hash functions do not exist for, at least, the following
reasons:
In practice, the input space is much larger than the input space. Thus, the same output value is an image for multiple input
values. In mathematics, the pigeonhole principle states that if N items are put into m containers, with N > m then at
least one container must contain more than one item.
Even if the output space size is equal or greater than the input space size, the probability of collision in all existing hash
functions is not zero. In addition, increasing the size of the hash function output results in more consumption or storage
and communication resources.
5.6 Problems 167
Problem 5.7
Recall that attack-resistance of hash functions qualifies the difficulty, from the computational point of view, of finding col-
lisions or preimage and not the property that collisions do not exist or that preimage can never be found. The statement to
prove is: a collision-resistant hash function also is second-preimage resistant. The suggested proof is by contradiction.
Assume that a hash function H is collision-resistant but not second-preimage resistant. If H is not second-preimage resis-
tant, then, given an input x, one can find an input x ′ such that x ≠ x ′ and H ( x ) = H ( x ′) . However, if one can find two
distinct inputs with the same hash, he/she can prove that H is not collision-resistant, which is a contradiction with the
hypothesis that H is collision-resistant.
Problem 5.8
Let H1: {0, 1}2m → {0, 1}m be a collision-resistant hash function.
Let H2: {0, 1} 4m → {0, 1}m be a hash function defined by:
H2 ( x1 || x 2 ) = H1 ( H1 ( x1 ) || H1 ( x2 )) .
H1 ( H1 ( x1 ) || H1 ( x 2 )) = H1 ( H1 ( x1′ ) || H1 ( x 2′ )).
Since H1 is collision-resistant, it is computationally infeasible to find two bit strings H1 ( x1 ) || H1 ( x 2 ) and H1 ( x1′ ) || H1 ( x 2′ )
that have the same hash. In consequence, H2 also is collision-resistant.
Problem 5.9
Let H1 () be a collision-resistant hash function.
1) H2 ( x ) = H1 ( x ) || x
If H2 is not collision-resistant, then one can find x1 ≠ x 2 such that
H2 ( x1 ) = H2 ( x 2 ).
H1 ( x1 ) || x1 = H1 ( x2 ) || x2
x1 = z || 0 and x 2 = z || 1
x1 ⊕ 1 = ( z || 0) ⊕ 1 = z || 0
x 2 ⊕ 1 = ( z || 1) ⊕ 1 = z || 0
By construction of H3:
H3 ( x1 ) = H1 ( x1 ⊕ 1) = H1 ( z || 0)
H3 ( x2 ) = H1 ( x 2 ⊕ 1) = H1 ( z || 0)
Let x1 and x 2 be two bit strings that differ at least by one bit at position i such that 0 ≤ i ≤ k − 1 : x1 = z || 0 || y and
x 2 = z || 1 || y
If ci = 1 , then x1 ⊕ c = x 2 ⊕ c = z || 0 || y .
By construction of H 4:
H 4 ( x1 ) = H1 ( x1 ⊕ c ) = H1 ( z || 0 || y)
H 4 ( x 2 ) = H1 ( x 2 ⊕ c ) = H1 ( z || 0 || y)
1 − P(N )
N
n 1
ln e 2 ≈ ln
1 − P ( N )
1
N ≈ 2n * ln
1 − P ( N )
1
In the previous formula, P ( N ) = 1 cannot be used. Thus, the probability of success is 1− ε. N ≈ 2n * ln . At ε = 0.01,
ε
1 1
ln = 3.0 and at ε = 10 , ln = 6.79. Thus, when n is large, 2n is a good approximation of N .
− 20
ε ε
Problem 5.14
1) In the basic birthday paradox, the problem is to find the minimum number of people such that at least a pair among
them share the same birthday. When collision attack is of concern, the birthday problem may be reformulated as: find
the number of input elements so that two elements have the same hash. In case of collision birthday attack, input ele-
ments are selected randomly and hashes are associated with them. The hash is the equivalent of the birthday in the
basic paradox. Hence, the input space is the hash space. The attack terminates when two hashes are equal. In Section
3.4, three approximations of the number of elements to use for finding two elements with the same value are presented.
In the general case, two formulas may be used to approximate the required number of elements: N ≈ 2S * P ( N )
or N ≈ 2S * ln(1 / (1 − P ( N )) where S denotes the cardinality of the input space and P ( N ) the probability of finding
two equal elements among N randomly selected elements. In case of collision birthday attack, S is the cardinality of
the input hash space function of 2n, where n is the hash bit-length. By substitution with P ( N ) = 0.5:
First approximation yields: N ≈ 2 * 2n * 0.5 = 2n = 2n / 2
Second approximation yields: N ≈ S * 2 * ln(2) = 2n /2 * 1.77 < 2(
n +1)/2
.
2) “always succeed” means finding a collision with a probability of 1. Approximation N ≈ 2S * P ( N ) may be used with
P ( N ) = 100% and results in N ≈ 21/2 * 2n /2, which may be approximated by 2n/2 when n is large.
Approximation 2S * ln(1 / (1 − P ( N )) cannot be used with P ( N ) = 100%, but with P ( N ) = 1 − ε, where ε is a positive
1 1
integer very close to 0 . Thus, the approximation becomes: N ≈ S * 2 * ln = 2n /2 * 2 * ln .
ε ε
170 5 Hash Functions, Message Authentication Codes, and Digital Signature
1 1
At ε = 0.01, 2 * ln = 3.0 and at ε = 10−10 , 2 * ln = 6.7 . Thus, when n is large, 2n/2 is a good approximation of
ε ε
N.
Problem 5.15
Given a message M, the adversary easily computes the length of padding string for M. However, the sender computes the
padding string for string key || M to generate H (key || M ). Without knowing the length of key, the adversary is unable to
compute the length for padding string key || M . Therefore, he/she cannot run the length extension attack.
Problem 5.16
1) In SHA-384, SHA-512/224, and SHA-512/256, the initialization hash H 0 and the block hashes H i , i = 1, ..., N , are rep-
resented as eight words of 64 bits. But, the message hash is produced by truncation of H N , the hash of the last block.
From the later, SHA-384 keeps six 64-bit words, SHA-512/224 keeps three 64-bit words and the left half of the fourth
64-bit word, and SHA-512/256 keeps four 64-bit words. Message hash and initialization hash H 0 have different lengths.
Consequently, the message hash cannot be used as H 0 to enable the adversary extend the original message. In other
words, hash obtained by truncation prevents the hash function from length extension attack.
2) In SHA-3, the hash function output length d is the half of Keccak-p permutation capacity c. Inside the sponge function,
Keccak-p permutation takes an input of b bits, called state array, with b > c. In squeezing step, the message hash is
produced by truncation. Consequently, the message hash intercepted by the adversary cannot be substituted to the
initial state array to realize a length extension attack.
Problem 5.17
Recall that non-repudiation is the assurance that a message originator cannot deny having sent the message (e.g. denying
having sent a newspaper article). First, since MACs do not address confidentiality, messages with MACs can be checked by
more than one receiver and any user who share the secret with the sender(s) can produce valid MACs. For example, a pool
of journalists shares the same secret with their editor. Second, in case the sender is malicious (e.g. a malicious editor), he/
she can generate a MAC and then claims he/she received it from a journalist. Consequently, if the sender and receiver get
involved in a dispute over message origination, MACs cannot provide a proof that a message was indeed sent by the
designated sender.
Problem 5.18
Length extension means appending a bit string F to the end of the original message. Without loss of generality, assume
that the length of string F is a multiple of the block length of the targeted hash function.
1) In secret prefix MAC, MAC ( M , key ) = H (key || M ) .
( )
The input bit string key || M || P are structured into a sequence B1 , B 2 , ..., B n of blocks of fixed size L, which is a param-
eter of the hash function. P denotes the padding bits added so that the length of key || M || P is a multiple of the block
length of the hash function.
(
MAC ( M , key ) = H (key || M || P ) = H B1 || B 2 ||…|| B n )
In Merkle-Damgård construction, block B1 and initialization vector, which also is referred to as H 0 , are used as inputs
of the hash function to produce H 1, then H 1 and block B 2 are used to produce H 2 , etc. and finally, H n represents
H (key || M || P ). Length extension attack takes advantage of the design of Merkle-Damgård construction to adapt the
hash function H, such that H 0 is not a constant vector, rather it takes the value of H (key || M || P ). Hashing block(s)
of fake data F with H 0 = H (key || M || P ) looks like a continuation of blocks of the string key || M || P , and the result-
ing hash H (key || M || P || F ) is a MAC that would be produced by a legitimate party. Consequently, secret prefix
MACs are vulnerable to length extension attack.
2) The hash available to the adversary is H (key || len( M ) || M || P ).
( )
Let B be the sequence of blocks B1 , B 2 , ..., B n such that
B1 || B 2 || … || B n = key || len ( M ) || M || P
Let F be the bit string appended by the adversary. Upon reception of the forged message, the verifier computes the
hash as H (key || (len( M ) + len( F )) || M || F || P ′), where P ′ is the padding bits for the string key || (len( M ) + len( F )) || M || F .
( )
Let A be the sequence of blocks A1 , A2 , ..., An , ..., An+d such that
References 171
Notes
References
1 Merkle, R. (1989). One way hash functions and DES. 9th Annual International Cryptology Conference, Advances in Cryptology -
CRYPTO’89, 428–446. Santa Barbara, California: Springer, LNCS 435.
2 Damgard, I. (1989). A design principle for hash functions. 9th Annual International Cryptology Conference, Advances in
Cryptology - CRYPTO’89, 416–427. Santa Barbara, California: Springer, LNCS 435.
172 5 Hash Functions, Message Authentication Codes, and Digital Signature
3 Bertoni, G., Daemen, J., Peeters, P. et al. (2007). Sponge functions. ECRYPT Hash Functions Workshop, 1–22. Barcelona,
Spain.
4 Bertoni, G., Daemen, J., Peeters, P. et al. (2008). On the indifferentiability of the sponge construction. 27th Annual
International Conference on the Theory and Applications of Cryptographic Techniques, Advances in Cryptology, 181–197.
Istanbul, Turkey: Springer, LNCS 4965.
5 NIST. (1995). Secure hash standard - FIPS PUB 180-1. National Institute of Standards and Technology.
6 NIST. (2015). Secure hash standard - FIPS PUB 180-4. National Institute of Standards and Technology.
7 Leurent, G. and Peyrin, T. (2020). SHA-1 is a shambles: first chosen-prefix collision on SHA-1 and application to the PGP
web of trust. 29th USENIX Security Symposium, 1839–1856. Boston, US: Unix Association.
8 NIST. (2015). SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions - FIPS PUB 202. National
Institute of Standards and Technology.
9 Bellare, M., Canetti, R., and Krawczyk, H. (1996). Keying hash functions and message authentication. Annual International
Cryptology Conference, Advances in Cryptology - Crypto’96, 1–15. Santa Barbara, California: Springer, LNCS 1109.
10 Krawczyk, H., Bellare, M., and Canetti, R. (1997). HMAC: Keyed-Hashing for Message Authentication - RFC 2104. Internet
Engineering Task Force.
11 Kelsey, J., Chang, S., and Perlner, R. (2016). SHA-3 Derived Functions: cSHAKE, KMAC, TupleHash and ParalleHash, Special
Publication 800-185. National Institute for Standards and Technology (NIST).
173
Stream Ciphers
Stream ciphers are symmetric ciphers that encrypt and decrypt bits individually. They are used to secure communications
in wireless and cellular networks. Stream ciphers are well-suited to hardware implementation and they are generally faster
than block ciphers. They also are well-suited to encrypt and decrypt continuous data (e.g. phone communication) at high
rate and when devices have limited memory to store long messages. That is why, stream ciphers are often used in telecom-
munication networks, such as 3G, 4G, and 5G.
ChaCha20 stream cipher is an Internet standard; it is recommended as a cipher in TLS protocol to secure communica-
tions between clients and web servers [1]. Most common stream ciphers are built around linear feedback shift registers,
which makes them easy to implement in hardware.
This chapter aims at presenting the principles and standard algorithms related to stream ciphers.
Definition 6.2 Initialization vector (IV): it is a bit string computed for each plaintext (or for a set of plaintexts) and used
jointly with the secret key to generate the keystream.
There are two main reasons to use and frequently change initialization vectors: 1) long sequences of keystream require
periodic synchronization of encryption and decryption processes (because of transmission errors) and 2) encrypting dis-
tinct plaintexts with the same key is insecure. Therefore, initialization vectors is a solution to generate different pseudo-
random sequences without necessarily changing the secret key.
Definition 6.3 Key-Scheduling Algorithm (KSA): it is the operation of mixing the secret key and the Initialization vector to
yield a key, which is then used to encrypt/decrypt a single plaintext.
As shown in Figure 6.1, the main building block of cipher stream is the keystream generator. The latter is a PRNG (pseudo
random number generator), which generates a stream of bits given a secret key and an initialization vector.
Stream ciphers were inspired by One-time pad cipher (see Section 4.6). Unlike OTP cipher, in which the key stream is at
least as long as the data to encrypt, stream ciphers make use of periodic PRNGs.
The secret key is shared by both parties. Therefore, the keystream generators on both sides generate the same sequence
of keystream bits. Encryption and decryption operations are very simple. Let ai and s j be the current plaintext and key-
stream bits, respectively. Formally,
Encryption is: ci = ai ⊕ s j mod 2
Decryption is: ai = ci ⊕ s j mod 2
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
174 6 Stream Ciphers
( )
ci ⊕ s j mod 2 = ai ⊕ s j mod 2 ⊕ s j mod 2 = ai ⊕ s j ⊕ s j mod 2 = ai
Example 6.1
Encryption
Plaintext 110 01101010 01110
Keystream ⊕ 10 0 0 0111110 01011
Ciphertext 010 0101010 0 0 0101
Encryption
Ciphertext 010 0101010 0 0 0101
Keystream ⊕ 10 0 0 0111110 01011
Plaintext 110 01101010 01110
Definition 6.4 Synchronous stream cipher: it is a cipher in which the keystream is generated independently of the plaintext
and of the ciphertext.
Definition 6.5 Self-clocking stream cipher: it is a cipher in which the keystream is generated from a key function and a
fixed number of previous ciphertext bits.
6.1 Stream Ciphers 175
Synchronous stream ciphers have at least two advantages and one drawback.
Advantages: i) If a bit is modified but not deleted, the process of decryption continues to correctly decrypt the remaining
bits. Therefore, synchronous stream ciphers are not error-propagation sensitive. ii) If some bits are inserted, by an adver-
sary, the receiver will lose synchronization and the forged bits as well as the remaining bits are very likely to be discarded.
Therefore, synchronous stream ciphers are more prone to support the detection of some attacks.
Drawback: if a bit is lost (because of transmission error), the receiver is desynchronized and the decryption may fail
starting from the missing bits if no re-synchronization mechanism is used.
Therefore, synchronous stream ciphers are very useful to encrypt streaming media (voice, audio, and video) where the
speed of data-traffic is more important than the integrity of the data (e.g. loss of a few pixels or images in video streaming
is not damaging).
It is worth noticing that synchronous stream ciphers are the most common in practice. To alleviate the drawback above,
the common approach, is to reinitialize the keystream generator each limited-length message.
Example 6.2
– Bit loss
Assume that l, the length of synchronization window, is 5 and a transmission error occurs on bit i. The table below shows
the synchronization window bits at each cycle on both sides. At, cycle i, both parties have the same bit set, but the receiver
cannot decrypt the errored bit. Therefore, it includes the undefined value O in its set. Next, from cycle i +1 to cycle i + 5,
the receiver has a distinct synchronization window set and consequently, it cannot not decrypt correctly. Next, staring from
cycle i + 6, both parties have the same set and the decryption resumes correctly.
i (ci−5 , ci−4 , ci−3 , ci−2 , ci−1 ) (ci−5 , ci−4 , ci−3 , ci−2 , ci−1 ) Yes
i +1 (ci−4 , ci−3 , ci−2 , ci−1 , ci ) (ci−4 , ci−3 , ci−2 , ci−1 , O ) ) No
i+2 (ci−3 , ci−2 , ci−1 , ci , ci+1 ) (ci−3 , ci−2 , ci−1 , O, ci+1 ) No
i +3 (ci−2 , ci−1 , ci , ci+1 , ci+2 ) (ci−2 , ci−1 , O, ci+1 , ci+2 ) No
i+4 ( ci−1 , ci , ci+1 , ci+2 , ci+3 ) ( ci−1 ,O, ci+1 , ci+2 , ci+3 ) No
i +5 (ci , ci+1 , ci+2 , ci+3 , ci+4 ) (O, ci+1 , ci+2 , ci+3 , ci+4 ) No
i+6 (ci+1 , ci+2 , ci+3 , ci+4 , ci+5 ) (ci+1 , ci+2 , ci+3 , ci+4 , ci+5 ) Yes
6.1 Stream Ciphers 177
– Bit insertion
Assume that l, the length of synchronization window, is 4 and a bit i has been altered by an adversary. Let ci′ denote the
received ciphertext bit. The table below shows the synchronization window bits at each cycle on both sides. At cycle i, both
parties have the same bit set, but the receiver decrypts an altered bit and updates its synchronization set with ci′ . Next, from
cycle i + 1 to cycle i + 4, the parties have two distinct synchronization sets. Therefore, their keystream bits are distinct result-
ing in bits of plaintext that are different from the decrypted bits. Starting from cycle i + 5, both parties have the same set and
the decryption resumes correctly. Notice that the receiver has no means, at this stage, to know that a bit had been altered.
output is st = 0. Then, at next clock impulse, the register elements are one-position right-shifted and the second register
output st+1 = 1. At the m −1th clock impulse, the register output is st +m−1 = 1. Then, the register output does not change (i.e.
all register elements are zeros).
If a non-feedback register has enough bits, it can be used to deliver the key in one-time pad cipher. Unfortunately, since
the secret key is at least as long as the message and messages may have a long length, non-feedback shift registers are not
appropriate to implement OTP ciphers in hardware.
Shift registers, used in hardware implementation of stream ciphers, are characterized by feedback; that is why they are
called Feedback Shift Registers. That is, the output of some or all flip-flop elements are used to generate an input to the first
element. Not all the elements are required to generate feedback. Thus, binary coefficients, denoted cm, cm−1 , …, and c1 , indi-
cate if the output of flip-flop elements are used or not. In Figure 6.4, the operation ⊗ denotes binary multiplication (i.e. the
output of FFi participates in the feedback only if ci = 1). The flip-flops that impact the feedback are called taps or feedback
coefficients. The feedback is yielded by a linear function; that is why LFSRs are called linear. There exist other LFSRs that
are not linear. The operation of an LFSR can be described as follows:
f = (∑ m
i =1
(ci * FFi )) mod 2
Register right-shift: FFj = FFj−1 ∀j = m, ..., 2
Input the feedback: FF1 = f
Deliver the register output: ρ= FFm
The state of an LFSR at time t, denoted σ(t ) , is the product of the states of its flip-flop elements. That is,
σ(t ) = ( FFm (t ), FFm−1 (t ), ..., FF1 (t )), where FFi (t ) denotes the state of flip-flop i at time t. In bit representation, the state of
LFSR is a bit string ranging from 000…001 to 111…111.
At each clock impulse, the LFSR delivers a bit and register elements are right-shifted. Therefore, the register output is a
bit stream that starts with string st +m−1 , st +m−2 , ..., st +1 , st . The first bit produced by the LFSR is st . The next bits of the key-
stream are computed as follows:
m−1
st +m = st +m−1 c1 ⊕ st +m−2 c2 ⊕ … ⊕ st +1 cm−1 ⊕ st cm = ∑ st + j cm− j mod 2
j=0
m−1
st +m+1 = st +m c1 ⊕ st +m−1 c2 ⊕ … ⊕ st +2cm−1 ⊕ st +1cm = ∑ st + j +1cm− j mod 2
j =0
…
m−1
st +m+i = st +m+i−1c1 ⊕ st +m+i−2 c2 ⊕ … ⊕ st +i+1 cm−1 ⊕ st +icm = ∑ st + j +icm− j mod 2 (6.1)
j=0
Lemma 6.15
An LFSR with m flip-flop elements can generate N distinct states such that N ≤ 2m − 1. N is called cycle (or period) of
LFSR.
Properties of LFSRs
i) The output of LFSR, which has N distinct states, is a bit string, which repeats every N bits. Therefore, the state of
flip-flop i at time t + kN , with k a positive integer, is the same as at time t.
ii) An LFSR with n flip-flops is said to be maximal-length LFSR, if it has exactly 2n − 1 distinct states.
iii) An LFSR, which reaches a state where all flip-flop states are 0s, has a constant6 output equal to 0.
Example 6.3
Figure 6.5 shows an example of LFSR with four FF elements. To simplify the LFSR structure, an equivalent representation
is used; if ci = 1, then the output of element FFi is connected to the XOR feedback line; and there is no connection
otherwise.
The initial state of the LFSR is 1100. t denotes clock impulses. It is worth noticing that the first LFSR has only 6 distinct
states, while the second has 15 distinct states. The second LFSR is maximal-length. Table 6.1 shows the state changes of the
considered LFSR.
0 1100 0 1100
1 1110 1 1110
2 0111 2 1111
3 0011 3 0111
4 0001 4 1011
5 1000 5 0101
6 1100 6 1010
7 1110 7 1101
8 0111 8 0110
9 0011 9 0011
10 0001 10 1001
11 1000 11 0100
12 1100 12 0010
13 1110 13 0001
14 0111 14 1000
15 0011 15 1100
16 0001 16 1110
In Example 6.1, F ( x ) = x 4 + x 3 + x + 1; in Figure 6.5a and F ( x ) = x 4 + x + 1 in Figure 6.5b. Polynomial and diagram rep-
resentations are equivalent. That is, from a feedback polynomial, the structure of LFSR can be drawn; and from a structure
of an LFSR, the feedback polynomial can be derived. Polynomial representation is used when mathematical analysis is of
concern.
Lemma 6.2
Given a m -bit linear-feedback shift register R represented with a feedback polynomial F ( x ) and initialized with a non-
zero binary vector, if F ( x ) is a primitive polynomial, then R is a maximal-length LFSR (i.e. with a period of 2m − 1).
A proof of Lemma 6.2 is given in [2]. Recall that a primitive polynomial p( x ), of degree m, is a polynomial irreducible in Z2
that can generate all elements of a field F2m (see Section 3.2.4). For any integer m ≥ 2, there exists at least one primitive poly-
nomial of degree m to generate a field F2m . The number of distinct primitive polynomials of degree m grows quasi-exponen-
tially with m. Therefore, there exist multiple combinations of tags to build LFSRs with a cycle of 2m − 1. To reduce the
hardware implementation of LFSRs (i.e. reduce the number of connections and XOR circuits due to tags), sparse primitive
polynomials of degree m, i.e. with the least number of monomials, are preferred.
Table 6.2 [3] provides a list of examples of feedback polynomials with minimal cost (i.e. with minimum electronic cir-
cuits) to build LFSRs with 2 to 32 bits.
6.1 Stream Ciphers 181
2 3 x2 + x +1
3 7 x3 + x2 +1 x3 + x +1
4 3
4 15 x + x +1 x4 + x +1
5 31 x5 + x3 +1 x5 + x2 +1
6 5
6 63 x + x +1 x6 + x +1
7 127 x7 + x6 +1 x7 + x +1
8 6 5 4
8 255 x + x + x + x +1 x8 + x6 + x5 + x +1
9 511 x9 + x5 +1 x9 + x4 +1
10 7
10 1 023 x + x +1 x 10 + x 3 + 1
11 2 047 x 11 + x 9 + 1 x 11 + x 2 + 1
12 5
12 4 095 x + x +1 x 12 + x 3 + 1
13 8 191 x 13 + x 12 + x 11 + x 8 + 1 x 13 + x 4 + x 3 + x + 1
14 11 6
14 16 383 x + x + x + x +1 x 14 + x 8 + x 6 + x + 1
15 32 767 x 15 + x 4 + 1 x 15 + x + 1
16 12 7 2
16 65 535 x + x + x + x +1 x 16 + x 12 + x 3 + x + 1
17 131 071 x 17 + x 6 + 1 x 17 + x 3 + 1
18 11
18 262 143 x + x +1 x 18 + x 7 + 1
19 524 287 x 19 + x 18 + x 17 + x 14 + 1 x 19 + x 6 + x 5 + x + 1
20 17
20 1 048 575 x + x +1 x 20 + x 3 + 1
32 4 294 967 295 x 32 + x 22 + x 2 + x + 1
Several stream ciphers have been proposed and some of them have been standardized and widely used in operational net-
works. Recall that standardization organizations involved in networks and telecommunications are mainly IEEE,7 3GPP,8
ETSI,9 IETF,10 and ISO,11
Standard stream ciphers include A5/1, E0, SNOW 3G, ZUC, Chacha20, and RC4, which are presented in the sequel.
Note. In the sequel, the presentation of keystream generators preserves the notations of standards. Therefore, different
notations for numbering cells and states will be used depending on the standard.
F1 ( x ) = x 19 + x 18 + x 17 + x 14 + 1 F2 ( x ) = x 22 + x 21 + 1
F3 ( x ) = x 23 + x 22 + x 21 + x 8 + 1
Therefore, in total, 19 + 22 + 23 bits are used to deliver a key stream. The registers are initialized using a key of 64 bits stored
on the mobile phone.
A5/1 output is an XOR of the output of the three registers. In each register, a specific bit, called clocking bit, is used to
know when the shift operation is to perform. In Figure 6.9, bit 8 is the bit clocking of the first and second registers and bit
10 is the bit clocking of the third register. At each cycle, the clocking bits of the three registers are examined. A register is
clocked (i.e. a clock signal is delivered to the register; thus, it shifts its cells to the right) if the current state of its clocking
bit agrees with the majority of clocking bits. Therefore, at each cycle, two or three register shifts are performed. The state
of register of which the clocking bit differs from the clocking bits of the other registers does not change.
The irregularity of register clocking was a countermeasure against plaintext attacks against LFSR (see attack against
LFSR, Problem 6.7). Unfortunately, even with irregular clocking of registers, several attacks succeeded and showed that
A5/1 was not secure. From then on, A5/1 was no longer a solution for cellular networks.
Another countermeasure was proposed in A5/2 cipher, with four registers, but it is no more recommended, because of
reported attacks.
F1 ( x ) = x 25 + x 20 + x 12 + x 8 + 1 F2 ( x ) = x 31 + x 24 + x 16 + x 12 + 1
F3 ( x ) = x 33 + x 28 + x 24 + x 4 + 1 F4 ( x ) = x 39 + x 36 + x 28 + x 4 + 1
Therefore, in total 128 (= 25 + 31 + 33 + 39) bits are used to deliver a key stream. The output of LFSRs is combined with a
state machine called summation combiner (see Figure 6.10).
In addition to the four registers, E0 cipher makes use of two internal 2-bit-words denoted ct −1 and ct initialized to 00. The
main steps of E0 cipher are Generation of key stream and Initialization.
Generation of key stream bits
Let the start time be t = 0.
Let x tk denote the output of register k (k = 1, 2, 3, 4) at time t.
1
Let ct−1 and ct1 denote the left bit of words ct−1 and ct , at time t, respectively.
Let ct−1 and ct0 denote the right bit of words ct−1 and ct , at time t, respectively.
0
( )
Let wt0 , wt1 denote the two bits of a 2-bit-word w.
The output of the key stream generator is performed as:
1) Compute the sum over integers:
yt = x t1 + x t2 + x t3 + x t4 . Thus, 0 ≤ yt ≤ 4.
zt = x t1 ⊕ x t2 ⊕ x t3 ⊕ x t4 ⊕ ct0
( )
ct +1 = ct1+1 , ct0+1 = st +1 ⊕ T1 ct ⊕T2 ct −1
y + ct
( )
st +1 = st1+1 , st0+1 = t
2
.
T1 . and T2 . are two linear functions defined by:
( ) (
T1 : ct1 , ct0 ct1 , ct0 ;) ( ) ( )
T2 : ct1−1 , ct0−1 ct0−1 , ct1−1 ct0−1 .
F ( x ) = α x 16 ⊕ x 14 ⊕ α−1 x 5 + 1 ∈ F232 [ x ]
t +1
s15 = α−1 * s11
t
⊕ s2t ⊕ α * s0t
where:
sit denotes the state, at cycle t, of stage i (i = 0, 1, ..., 15),
186 6 Stream Ciphers
( ) ( )
R1t = R2t−1 + R3t−1 ⊕ s5t−1 ; R2t = S1 R1t−1 ; R3t = S2 R2t−1 ( )
where S1 and S2 are two 32-bit to 32-bit substitution boxes. S1 and S2 s-boxes make use of two small 8-bit s-boxes SR and SQ . SR
is the well-known s-box used in AES cipher (see Section 7.3).
After the initialization step, the output of the SNOW 3G keystream generator, at cycle t, is z t = z t ⊕ s0t .
ts ts
Before starting the generation of the first bit of the keystream in cycle t s , the value of s15 is s15 = α −1 *
ts −1 ts −1 ts −1 ts −1
s11 ⊕ s2 ⊕ α * s0 ⊕ F .
⊕: addition modulo2
R j : register R j ( j = 1, 2, 3) of the FSM
: addition modulo 232
SNOW 3G makes uses of four functions:
1) MULx function: maps eight bits to eight bits as follows:
(V 8 1) ⊕ c if the most significant bit of V = 1
MULx (V , c ) =
(V 8 1) otherwise
For example, MULx (0 x 2 A, 0 x12) = 0 x54; MULx (0 xA2, 0 x12) = 56.
2. MULxPOW function: recursively maps eight bits to eight bits as follows:
V if i=0
MULxPOW (V , i, c ) = .
MULx ( MULxPOW (V , i − 1, c ), c ) otherwise
3. MULα function: maps eight bits to 32 bits as follows:
r0 = MULx (SR (W0 ), 0 x1B) ⊕ SR (W1 ) ⊕ SR (W2 ) ⊕ MULx (SR (W3 ), 0 x1B) ⊕ SR (W3 )
r1 = MULx (SR (W0 ), 0 x1B) ⊕ SR (W0 ) ⊕ MULx (SR (W1 ), 0 x1B) ⊕ SR (W2 ) ⊕ SR (W3 )
r2 = SR (W0 ) ⊕ MULx (SR (W1 ), 0 x1B) ⊕ SR (W1 ) ⊕ MULx (SR (W2 ), 0 x1B) ⊕ SR (W3 )
r3 = SR (W0 ) ⊕ SR (W1 ) ⊕ MULx (SR (W2 ), 0 x1B) ⊕ SR (W2 ) ⊕ MULx (SR (W3 ), 0 x1B)
where SR, which is called Rijndael’s s-box, is a table of 256 8-bit-constants that, given u = i * 16 + j (i and j are row and
column numbers of a cell in Rijndael’s table), returns a 8-bit constant. For example, SR (17) = SR (0 x11) = 0 x 63,
SR (127) = SR (0 x 7 F ) = 0 xD2 , SR (255) = SR (0 xFF ) = 0 x16.
Given a word W, S-box S2 returns a result S2 (W ) = r0 r1 r2 r3 defined as follows:
r0 = MULx (SQ (W0 ), 0 x 69) ⊕ SQ (W1 ) ⊕ SQ (W2 ) ⊕ MULx (SQ (W3 ), 0 x 69) ⊕ SQ (W3 )
r1 = MULx (SQ (W0 ), 0 x 69) ⊕ SQ (W0 ) ⊕ MULx (SQ (W1 ), 0 x 69) ⊕ SQ (W2 ) ⊕ SQ (W3 )
r2 = SQ (W0 ) ⊕ MULx (SQ (W1 ), 0 x 69) ⊕ SQ (W1 ) ⊕ MULx (SQ (W2 ), 0 x 69) ⊕ SQ (W3 )
r3 = SQ (W0 ) ⊕ SQ (W1 ) ⊕ MULx (SQ (W2 ), 0 x 69) ⊕ SQ (W2 ) ⊕ MULx (SQ (W3 ), 0 x 69)
where SQ is a second table of 256 8-bit-constants used in the same way as table SR, but with distinct arrangements of constants
inside the tables. For example, SQ (17) = SQ (0 x11) = 0 x 25, SQ (127) = SQ (0 x 7 F ) = 0 x5 A, SQ (255) = SQ (0 xFF ) = 0 x 86 .
The FSM registers R1, R2 , and R3 are all set to 0. Then, the following two steps are repeated 32 times:
1) FSM is clocked to produce a 32-bit word F.
2) LFSR is clocked according to initialization mode using word F.
Generation of keystream
First, the FSM is clocked once and its output is discarded. Then, the LFSR is clocked according to the keystream mode.
After that, keystream 32-bit words are produced by repeating the following steps as long as keystream bits are needed to
encrypt/decrypt messages:
1) FSM is clocked to produce a 32-bit word F.
2) The next keystream word is produced as zt = F ⊕ s0.
3) LFSR is clocked according to the keystream mode.
Note. For interested readers, some issues regarding the resynchronization mechanism of SNOW 3G are discussed in [7].
( ( ))
F ( x ) = x 16 − 215 x 15 + 217 x 13 + 221 x 10 + 220 x 4 + 1 + 28 .
Notes
– In ZUC, addition and multiplication of LFSR stages are over prime field F231 −1.
t +1
– If s15 = 0 , then s15
t +1
is replaced by 231 − 1 (because in Fp , p and 0 are equivalent).
30
– Any element a ∈ F231 −1 can be written as a = ∑ i=0 ai 2i , ai=0,…,30 ∈{0,1}. Then, ∀ x ∈ F231 −1 , k < 31, 2k * x := x 31 k . This
makes implementation of ZUC quite efficient. x 31 k denotes a left circular shift of 31-bit element by k positions.
6.2 Examples of Standard Keystream Generators 189
( )
v = 215 s15 + 217 s13 + 221 s10 + 220 s4 + 1 + 28 s0 mod 231 − 1 ( )
(
T = (u + v ) mod 231 − 1 )
If T = 0, then T = 231 − 1
(s1 , s2 , ..., s14 , s15 ,T ) → (s0 , s1 , ..., s14 , s15 ) (i.e. shift stages).
2) LFSR work mode
In LFSR initialization mode, ZUC performs the following:
( )
T = 215 s15 + 217 s13 + 221 s10 + 220 s4 + 1 + 28 s0 mod 231 − 1 ( )
If T = 0, then T = 231 − 1
190 6 Stream Ciphers
where siL and siH denote the leftmost and rightmost 16 bits of stage i, respectively.
F ( X 0 , X1 , X 2 ) :
{W = ( X 0 ⊕ R1 ) R2 ; W1 = R1 X 1 ; W2 = R2 ⊕ X 2 ;
function QRound
input a, b, c , d # four 32-bit words
output a, b, c , d
# n m denotes m-bit left-rotation of a 32-bit integer n
1. a = a + b mod 232 ; d = d ⊕ a ; d = d 16
2. c = c + d mod 232; b = b ⊕ c; b = b 12
3. a = a + b mod 232 ; d = d ⊕ a ; d = d 8
4. c = c + d mod 232; b = b ⊕ c; b = b 7
5. return (a, b, c , d )
Figure 6.15 Order in which state words are used to form one 8-quarter-round series.
function KeyStreamBlock_Generation
input K: 256-bit key; Ctr: 32-bit counter; Nonce: 96-bit nonce
output Kstr : 64-byte keystream
1. Constants = 0x61707865 0x3320646e 0x79622d32 0x6b206574
2. InitState = Constants K Ctr Nonce
3. S = InitState
4. for i=1 to 10 do
# perform four column quarter-rounds
Qround (S 0 , S 4 , S 8 , S 12); Qround (S 1 , S 5 , S 9 , S 13 )
Qround (S 2 , S 6 , S 10 , S 14 ); Qround (S 3 , S 7 , S 11 , S 15)
# perform four “diagonal” quarter-rounds
Qround (S 0 , S 5 , S 10 , S 15); Qround ( S 1 , S 6 , S 11 , S 12)
Qround (S 2 , S 7 , S 8 , S 13); Qround (S 3 , S 4 , S 9 , S 14 )
# After 80 quarter-rounds
5. Kstr = null
# add the initial state to the current
6. for i=0 to 15 do
S[i] = S[i] + InitState[i] # (addition mod 232)
Kstr = Kstr || LittleEndianEncode (S[i])
7. return Kstr # Bit-length of Kstr is of 512 bits
function ChaCha20_Encryption
input K : 256-bit key; C: 32-bit counter; Nonce: 96-bit nonce
P: variable-length plaintext
output Ciphertext: bit-string
1. Ciphertext = null
2. m = Blen( P ) / 64 − 1 # m + 1 is the number of full 64-byte blocks
6.2 Examples of Standard Keystream Generators 193
3. for j = 0 to m do
Kstr = KeyStreamBlock_Generation (K, C+j, nonce)
Ciphertext= Ciphertext ( P [ j * 64 : j * 64 + 63] ⊕ Kstr )
4. if ( Byte Len( P ) mod 64 ≠ 0 ) then
j = ByteLen( P ) / 64 ; r = Blen( P ) − j * 64
Kstr = KeyStreamBlock_Generation(K, C + j, nonce)
Blk = P ⌊ j*64: Blen(P)-1⌋
Ciphertext = Ciphertext || (Blk ⊕ Kstr[0: r – 1])
5. return Ciphertext
K i denotes byte i of key K, with i = 0,1, ..., len ( K ) and len ( K ) denotes the byte-length of key K. Swap(S[i], S[j]) is a function
to swap the contents of elements S[i] and S[j].
If the length of key K is 256, key K is used once. Otherwise, it is used many times.
i, j = 0
while (GeneratingOutput) do
i = (i + 1) mod 256
j = (j + S[i]) mod 256
Swap(S[i], S[j])
Z = S[(S[i] + S[j]) mod 256]
output Z
i) Keystream generation
Trivium interval state is composed of 288 register bits, denoted s1 , s2 , ..., s288, among which 15 bits are iteratively used to
generate N keystream bits, N ≤ 264 , as follows:
for i = 1 to N do
1. # Compute one bit of the keystream
t1 = s66 ⊕ s93 ; t2 = s162 ⊕ s177; t3 = s243 ⊕ s288; zi = t1 ⊕ t2 ⊕ t3
2. # Update the internal state
t1 = t1 ⊕ (s91∧s92) ⊕ s171; t2 = t2 ⊕ (s175∧s176) ⊕ s264
t3 = t3 ⊕ (s286∧s287) ⊕ s69
(s1, s2, …, s93)← (t3, s1, s2, …, s92)
(s94, s95, …, s177)← (t1, s94, s2, …, s176)
(s178, s179, …, s288)←(t3, s178, s179, …, s287)
ii) Initialization
The internal state of Trivium is initialized using 80-bit key K and 80-bit IV as follows:
Z
(t )
( ( ) ) = a( )
= Output S
t
1
t
Function ρ
It takes four elements of buffer b, numbered 2, 7, 16, and 29, to update the a-state bytes as follows:
(t ) (t ) (t ) (t )
u0 = a0 ⊕ S b2 u1 = a1 ⊕ S b7 ( v0 , v1 ) = L (u0 , u1 )
(t +1) (t ) (t +1) (t )
a0 = v0 ⊕ S b16 a1 = v1 ⊕ S b29
where L is a linear transformation over finite field F28 , defined by:
v0
= L v , v = 1 1 u0 , where d = 0 x 02
v ( 0 1 ) 1 d u
1 1
S is a substitution box, which maps eight bits to eight bits to provide nonlinearity to operation of the KSG.
Function λ
It rotates buffer b and then updates three bits of the buffer as follows:
(t +1) (t )
bi = bi−1 , i ≠ 0, 3, 8,17 ( partial shifting of registter)
(t +1) (t ) (t ) (t +1) (t ) (t )
b0 = b31 ⊕ a0 b3 = b2 ⊕ b6
(t +1) (t ) (t ) (t +1) (t ) (t )
b8 = b7 ⊕ b15 b17 = b16 ⊕ b28
Initialization
For each encryption, a distinct pair (Key, IV) is selected. The Init function takes a 128-bit key K and a 64-bit initialization
vector IV and performs the following:
(−96)
bi = K i , 0 ≤ i ≤16
(−96)
bi+16 = IVi , 0 ≤ i < 8
(−96) (−96)
b24 = 0 x666 b25 = 0 xe 9
(−96) (−96)
b26 = 0 x 4b b27 = 0 x 4d
(−96) (−96)
b28 = 0 xef b29 = 0 x8a
(−96) (−96)
b30 = 0 x 2c b31 = 0 x3b
(−96) (−96)
a0 = 0 x 88 a1 = 0 x 4c
After initialization of the state (i.e. a and b) using the key, the initialization vector, and constants, the state is updated with
96 iterations of two functions (namely, XORing the iteration counter and register element b31 followed by Next function).
The iteration counter is initialized by 0 x 01 and incremented by the multiplication by 0 x 02 over the extension field F28 ,
under the primitive polynomial ϕ8 ( x ). Then, the KSG delivers the first byte of the keystream, which is used to encrypt or
decrypt one byte.
Exercise 6.1
Let R be an LFSR defined with the following parameters:
Seed: FF1 = 0, FF2 = 0, FF3 = 1
Feedback coefficients: c1 = 1, c2 = 0, c3 = 1
Show the states of R in the eight first clock impulses. What is the cycle of the register?
Exercise 6.2
Show the table of states of the following LFSRs for nine clock impulses:
1) First LFSR: feedback polynomial F1 ( x ) = x 3 + 1 and seed = (0, 1, 0)
Second LFSR: feedback polynomial F2 ( x ) = x 3 + x 2 + 1 and seed = (0, 1, 0)
2) Why the second LFSR has more states?
Exercise 6.3
1) What is the maximum byte-length of plaintexts that can be encrypted with ChaCha20?
2) What is the maximum amount of data that can be encrypted with the same ChaCha20 key?
Problem 6.1
1) Consider a self-synchronizing stream cipher (S3C) with a large synchronization window. Discuss why synchronous
stream ciphers (S2Cs) are less impacted by transmission errors than S3Cs.
2) Consider a self-synchronizing stream cipher (S3C) with a short synchronization window. Discuss why it is more diffi-
cult to detect bit deletion or insertion with S3Cs than with S2C.
Problem 6.2
1) Show that it is easy to recover the parameters A and B of a linear congruential generator if three outputs and the mod-
ulus m, which is a prime, are known.
2) Assume that three LCG values are known: z1 = 13, z2 = 6, and z3 = 5 and the modulus m is 20. Find parameters of LCG.
3) Assume that three LCG values are known: z1 = 6, z2 = 5 , and z3 = 2 and the modulus m is 20. Find parameters of LCG.
4) What do you conclude?
Problem 6.3
1) Show that it is easy to recover the secret key ( A, B ) of a stream cipher based on a linear congruential generator if 3n bits
of plaintext and their cipher bits and the modulus m of the LCG are known. Assume that m = 2n − 1 is a prime. Assume
that the known bits are the first bits of a message. Hint: use the result of Problem 6.2.
2) Find the secret key ( A, B ), if n = 3 and the known plaintext is a = 101010101 and the ciphertext c = 000100111.
198 6 Stream Ciphers
Problem 6.4
Let R be an LFSR defined by feedback polynomial F ( x ) = x 4 + x + 1. Show that the output sequence of R is defined by the
initial entries and the recursion s4+i = s3+i + si .
Problem 6.5
In the feedback of SNOW 3G, there are two multiplications one by α and one by α−1. α is an element of extension field F232
and α−1 is its multiplicative inverse. The field F232 is generated by α, which is a root of F232 [ x ] polynomial
P 4( x ) = x 4 + β x 23 x 3 + β 245 x 2 + β 48 x + β 239. β ∈ F28 [ x ] is a root of F2 [ x ] polynomial P 8( x ) = x 8 + x 7 + x 5 + x 3 +. How x −1
can be expressed using β?
Hint: check with parameters of DIVα function.
Problem 6.6
Prove Lemma 6.1.
Problem 6.7
Assume that the adversary knows 2m bits of plaintext (for example, he/she knows the header of a message) and their
ciphertext. He/she also knows that the sender is using a stream cipher based on an LFSR with m bits. Assume that known
bits of plaintext are located at the beginning of a message. Show that LFSR-based ciphers are vulnerable to plaintext attack.
Problem 6.8
A plaintext M = 1001 0010 0110 1101 1001 0010 0110 is encrypted with an LFSR-based stream cipher and the ciphertext is
C = 1011 1100 0011 0001 0010 1011 0001. Assume that the pair ( M , M ′) is given and the period of the keystream generator
is less than 15.
1) What is the period of the keystream generator used to encrypt M?
2) What is its degree, initialization value, and feedback polynomial?
Problem 6.9
Consider a keystream generator with a period of L bits. The adversary can intercept all the traffic. All the encrypted mes-
sages start with a content (e.g. an application protocol header) of k bits known to adversary. No other characteristics of the
code are known.
What is the potential vulnerability of the considered encryption system (i.e. under which conditions the code can be
broken)?
Problem 6.10
Consider a user who has a series of documents to encrypt with a stream cipher and then store them. All documents are
English texts including only uppercase letters and space in 7-bit ASCII code. Given the large size of the documents, the user
decides to restart (with the same initial value) the keystream generator to encrypt each document. Show that if the number
of documents is enough large, an adversary, who has copies of the encrypted documents, can recover partially or entirely
all the documents.
Problem 6.11
Imagine a text-source sending a text in natural language. In such a case, some portions of plaintext are likely to be the same.
The adversary can take advantage of plaintext redundancy to derive relations between keystream bits, which contribute to
recover the key. Consider a simple stream cipher composed of an LFSR with feedback polynomial x 3 + x + 1 and a key
K = ( K 0 , K1 , K 2 ) = (0, 0,1) , as illustrated by Figure 6.19. Show how an adversary who knows the positions, denoted i and j,
of two portions of plaintext of L-bit length, L ≥ 3, can recover the key.
Exercise 6.1
Seed: FF1 = 0, FF2 = 0, FF3 = 1. Feedback coefficients: c1 = 1, c2 = 0, c3 = 1.
Below are the states of LFSR R in the 9 first clock impulses.
0 0 0 1
1 1 0 0
2 1 1 0
3 1 1 1
4 0 1 1
5 1 0 1
6 0 1 0
7 0 0 1
8 1 0 0
From the table above, we see that the register has a cycle of 7. Another way to find the register cycle is to inspect the
feedback polynomial, which is equal to x 3 + x + 1. Such a polynomial of degree 3 is a primitive polynomial (see Table 6.2).
Therefore, the register is maximal-length, with a cycle of 23 − 1.
Exercise 6.2
1) Below are the state tables for both LFSRs.
F1 ( x ) = x 3 + 1 F2 ( x ) = x 3 + x 2 + 1
0 0 1 0 0 0 1 0
1 0 0 1 1 1 0 1
2 1 0 0 2 1 1 0
3 0 1 0 3 1 1 1
4 0 0 1 4 0 1 1
5 1 0 0 5 0 0 1
6 0 1 0 6 1 0 0
7 0 0 1 7 0 1 0
8 1 0 0 8 1 0 1
9 0 1 0 9 1 1 0
2) F2 ( x ) is a primitive polynomial. By Lemma 6.2, the LFSR is a maximal-length LFSR; it has a cycle of 23 − 1. The polyno-
mial F1 ( x ) is reducible in F2. That is, x 3 + 1 = ( x + 1)( x 2 + x + 1). F1 ( x ) cannot be a primitive polynomial; thus, the first
LFSR has a cycle less than 23 − 1.
Exercise 6.3
1) The same ChaCha20 key and nonce are used to encrypt each plaintext. Up to 232 counter values can be used with the
same nonce to generate a maximum of 232 keystream blocks. Each keystream block is used to encrypt a 64-byte plaintext
block. Therefore, the maximum byte-length of any plaintext is of 238 bytes (i.e. 256 Gb).
2) The same ChaCha20 key can be used with up to 296 nonces; and each nonce can be used with up to 232 counter values
to generate a maximum of 296 * 232 keystream blocks. Each keystream block is used to encrypt a 64-byte plaintext block.
Therefore, the maximum amount of data that can be encrypted with the same ChaCha20 key is of 2134 bytes.
200 6 Stream Ciphers
Problem 6.1
Let n be the number of bits in the synchronization window of a self-synchronized (S3C).
1) Assume that n is large and a transmission error occurs when transmitting bit i. With a synchronous stream cipher (S2C),
the receiver just discards the bit i. With an S3C, the receiver cannot correctly decrypt n bits, starting with bit i. For
example, if the continuous flow being transmitted is composed of pixels represented with eight bits, with an S2C, a
single pixel is discarded, while n / 8 pixels are discarded with an S3C.
2) Assume that n is low and a few bits have been inserted or deleted by an adversary. In the S2C, the receiver loses syn-
chronization and the forged bits as well as the remaining bits are very likely to be discarded. This helps in detecting
attacks because of inconsistency between the message content before and after the alteration. In S3C, only bits altered
in synchronization window may be discarded, which reduces the chance to detect attacks. For example, imagine that
the adversary changes an amount 10 to 1000 in a text. On the receiver side, in S2C, it is very likely that the part of the
message starting from the altered amount will be entirely different from the original one and the receiver has chance to
detect the attack. In the S3C, only the amount and may be a few other characters in encrypted message will be different
from the characters in decrypted message. Therefore, the receiver has less chance to detect the attack.
Problem 6.2
1) Assume that three successive outputs, denoted z1, z2 , and z3 , of a linear congruential generator are known as well as the
modulus m.
* (i.e. the set of invertible elements of Z ). By definition of LCG, the following
In the following, computations are over Zm m
equalities hold:
z2 = A * z1 + B mod m
z3 = A * z2 + B mod m
Thus,
B = z2 − A * z1 mod m
B = z3 − A * z2 mod m
z2 − A * z1 mod m = z3 − A * z2 mod m
⇒ A = ( z2 − z3 )( z1 − z2 ) mod m
−1
= (7)−1 mod 20 = 3
Since 4 and 20 are not coprime, 4−1 mod 20 does not exist. Thus, A and B cannot be recovered.
4) From the previous example, we conclude that if the modulus m is not a prime, some elements of Zm do not belong to Zm* .
−1
In particular, ( z1 − z2 ) may not exist in Zm
* and consequently, the 3-known-value attack may fail to recover A and B.
Problem 6.3
1) Let the known bits be a3n , a3n−1, ..., a2 , a1 and their corresponding cipher bits be c3n , c3n−1 , ..., c2 , c1 . The modulus 2n − 1
of the linear congruential generator (LCG) also is known. Each LCG output is of a length of n bits. Thus, LCG output k
(k = 1, 2, 3) can be written as zk = ( zk ,n , zk ,n−1 , ..., zk ,1 ).
Assume that the known bits are the first bits of a message. Therefore, the keystream bits used to encrypt them form the
first three outputs of LCG, i.e. z1, z2 , and z3 . From the plaintext and ciphertext, keystream bits can be derived as follows:
Then, once the three values z1, z2 , and z3 are computed, it easy to recover the key ( A, B ) as in Problem 6.2.
2) Find the secret key ( A, B ), if the modulus is m = 7 and the known plaintext is a = 101010101 and the ciphertext
c = 000100111. From the known elements, keystream bits are derived as:
z1,1 = 1 ⊕1 = 0 z1,2 = 0 ⊕ 1 = 1 z1,3 = 1 ⊕ 1 = 0
z2,1 = 0 ⊕ 0 = 0 z 2, 2 = 1 ⊕ 0 = 1 z2,3 = 0 ⊕ 1 = 1
z3,1 = 1 ⊕ 0 = 1 z3,2 = 0 ⊕ 0 = 0 z3,3 = 1 ⊕ 0 = 1
Thus, z1 = 2, z2 = 6, and z3 = 5
By design of LCG:
6 = A * 2 + B mod 7
5 = A * 6 + B mod 7
Hence,
1 = −A * 4 mod 7
Problem 6.4
R is an LFSR defined by feedback polynomial F (−1) = x 4 + x + 1. Hence, its feedback coefficients are c1 = 1, c2 = 0, c3 = 0,
c4 = 1. The property of the output sequence of R is proven by induction.
Therefore, the output sequence of LFSR R is defined by the recurrence s4+i = s3+i + si for any positive integer i.
Problem 6.5
Since α ∈F232 [ x ] is a root of F28 [ x ] polynomial P 4( x ) = x 4 + β 23 x 3 + β 245 x 2 + β 48 x + β 239, the field F232 is equivalent to the
set {0, 1, α1 , α 2 , ..., α32−2 }. Any element of F232 can be represented by a polynomial of degree less than 32 with coefficients
in {0,1} or as a polynomial of degree less than 4 with coefficients in F28 .
By definition of a field F2m generated with a primitive polynomial P ( x ), multiplication of two elements a and b, repre-
sented by their polynomials a( x ) * b( x ) and b( x ), is the element c, such that c ( x ) is the remainder of the Euclidean division
of a( x ) * b( x ) by p( x ) .
Since x −1 ∈ F232 [ x ], x (−1) ( x ) is represented by a polynomial c3 x 3 + c2 x 2 + c1 x + c0, with ci=0,1,2,3 ∈ F28 .
( )
By definition of multiplicative inverse, ∀ a ∈ F232 , aa−1 = 1. Thus, x * x −1 = 1 = x c3 x 3 + c2 x 2 + c1 x + c0 mod P 4( x )
( )
The Euclidean division of c3 x 4 + c2 x 3 + c1 x 2 + c0 x by x 4 + β 23 x 3 + β 245 x 2 + β 48 x + β 239 returns a remainder equal to
202 6 Stream Ciphers
□
The same repeats after kN iterations (k is a positive integer). Thus, the output of LFSR follows a cyclic pattern of bits with
a period of N.
Problem 6.7
Assume that the adversary knows 2m bits of plaintext (for example, he/she knows the header of a message) and their
ciphertext. He/she also knows that the sender is using a stream cipher based on an LFSR with m bits.
Without loss of generality, assume that known bits of plaintext are located at the beginning of a message and denoted
a2m−1 , a2m−2 , ..., a1 , a0 . The ciphertext bits are denoted a2′ m−1 , a2′ m−2 , ..., a1′ , a0′ . By definition of a stream cipher, given a
plaintext and its ciphertext, it is easy to compute the key bit string ( s2m−1 , s2m−2 , ..., s1 , s0 ). That is,
s2m−1 = a2′ m−1 ⊕ a2m−1
sm−1 = am
′ −1 ⊕ am−1
…
s0 = a0′ ⊕ a0
m−1
s = a′ ⊕ a = mod 2
∑ j m− j
s c
m m m
j=0
m−1
s
m+1 = am ′ +1 ⊕ am+1 = ∑ s j +1cm− j mod 2
j=0
...
m−1
s = a ′ m−1 ⊕ a2m−1 = ∑ s j +m−1cm− j mod 2
2 m −1 2
j=0
Feedback coefficients cm, cm−1, …, c1 are given by solving the linear equation system above.
6.3 Exercises and Problems 203
Example:
The LFSR output is given by the rightmost bit. As shown on Figure 6.5b, the first eight outputs of LFSR R defined by poly-
nomial x 4 + x + 1 are (1, 0, 1, 1, 1, 1, 0, 0); they represent the key bit string of the stream cipher. Hence, s7 = 1, s6 = 0, s5 = 1,
s4 = 1, s3 = 1, s2 = 1, s2 = 1, and s0 = 0.
Let a = (1, 1, 0, 1, 1, 1, 0, 0) be the plaintext. The ciphertext yielded by a stream cipher relying on LFSR R is a′ = (0, 1, 1, 0, 0, 0, 0, 0) .
Given the plaintext and ciphertext, the adversary derives the keystream bits as follows:
a0′ = 0 = s0 ⊕ a0 ∧ a0 = 0 ⇒ s0 = 0
a1′ = 0 = s1 ⊕ a1 ∧ a1 = 0 ⇒ s1 = 0
a2′ = 0 = s2 ⊕ a2 ∧ a2 = 1 ⇒ s2 = 1
a3′ = 0 = s3 ⊕ a3 ∧ a3 = 1 ⇒ s3 = 1
a4′ = 0 = s4 ⊕ a4 ∧ a4 = 1 ⇒ s4 = 1
a5′ = 1 = s5 ⊕ a5 ∧ a5 = 0 ⇒ s5 = 1
a6′ = 1 = s6 ⊕ a6 ∧ a4 = 1 ⇒ s6 = 0
a7′ = 0 = s7 ⊕ a7 ∧ a5 = 1 ⇒ s7 = 1
By definition of LFSR with m = 4, si+4 is yielded by feedback polynomial using si+3 , si+2 , si+1 , si. Hence, we can build the
following linear equation system:
s4 = s3c1 ⊕ s2c2 ⊕ s1c3 ⊕ s0c4 = c1 ⊕ c2 = 1
s5 = s4c1 ⊕ s3c2 ⊕ s2c3 ⊕ s1c4 = c1 ⊕ c2 ⊕ c3 = 1
s6 = s5c1 ⊕ s4 c2 ⊕ s3c3 ⊕ s2c4 = c1 ⊕ c2 ⊕ c3 ⊕ c4 = 0
s7 = s6c1 ⊕ s5c2 ⊕ s4c3 ⊕ s3c4 = c2 ⊕ c3 ⊕ c4 = 1
The previous linear equation system can be easily solved with Gaussian elimination, which yields the solution: c1 = 1,
c2 = 0, c3 = 0, c4 = 1.
Problem 6.8
(s0 = 0, s1 = 0, s2 = 1, s3 = 0, s4 = 1, s5 = 1, s6 = 1)
Under the assumption that the degree is m = 3. The initialization vector is 100, because the m first bits (i.e. s0, s1, and s2)
delivered by a keystream generator are equal to the initialization vector. Then, the coefficients of the LFSR result from the
following equations:
s3 = ( s2 c1 ) ⊕ ( s1c2 ) ⊕ ( s0 c3 ) = (1 ⋅ c1 ) ⊕ (0 ⋅ c2 ) ⊕ (0 ⋅ c3 ) = 0 ⇒ c1 = 0
204 6 Stream Ciphers
Therefore, the feedback polynomial is F ( x ) = x 3 + x 2 + 1, which is a primitive polynomial; that is why the period of the
LFSR is 23 − 1 = 7 (by Lemma 6.2). The internal structure is shown in Figure 6.20 . Now, we are able to confirm that degree
.
is m = 3.
Problem 6.9
Assuming that all the encrypted messages start with a known header of k bits, an adversary can break a code based on a
keystream generator with a period of L bits if the adversary can collect a set of ciphertexts such that he/she can rebuilt an
entire period of the keystream generator as follows:
Let m1, m2, …, mt be the intercepted messages and I (mi ) denote the index of the first bit used in the keystream period to
encrypt message mi. For example, L = 127 and five intercepted messages of the following lengths:
( ) ( )
I mi ≤ I mi ≤…≤ I mi .
1 2
( ) t
( ) ( ) ( )
If mi = 0 , I m j +1 ≤ I m j + k, ∀ j, i1 ≤ j < it , and I mi + k ≥ L, then the adversary can recover all the keystream generator
1 t
output in an entire period. Therefore, the code is vulnerable.
Problem 6.10
Let C1 , C2 , ..., Cn be the n known encrypted documents. Each document is composed of uppercase letters and space in 7-bit
ASCII code. Let Ci,k denote the k th character of ciphertext i.
Recall ASCII codes (in Hexa): space → 2016 , A → 4116 , B → 4216, O → 4 F16 , P → 5016 , …, Y → 5916, Z → 5 A16.
The attacker exploits two advantages: i) space character is frequent in English texts (nearly 19% characters are spaces in English
texts) and ii) XORing any letter with space character returns a value greater than 2016 and XORing two letters returns a value
( )
less than 2016 . Attacker exploits all pairs of ciphertexts, and for each pair Ci , C j , 1 ≤ i, j ≤ n , i ≠ j , performs the following:
K is the keystream generator output, which is the same for all ciphertexts.
(
Let s = min len (Ci ), len C j . ( ))
Reduce both bit string Ci and C j to the same bit-length s, i.e. the longer document is truncated.
XOR the ciphertexts:
( )
Ci ⊕ C j = ( Di ⊕ K ) ⊕ D j ⊕ K = Di ⊕ D j
Di ⊕ D j = ( Di,1 , Di,2 , ..., Di, s ) ⊕ ( D j,1 , D j,2 , ..., D j, s )
Di ⊕ D j represents the XOR of two original documents.
Notes 205
( )
Ci+b ⊕ C j +b = ( Pi+b ⊕ si+b ) ⊕ Pj +b ⊕ s j +b = si+b ⊕ s j +b, for b = 0, ..., L − 1.
Encryption step
Consider a plaintext P = 11011001 11011001 composed of two identical bytes. The keystream, denoted S, used to encrypt P
is composed of bits of two LFSR periods plus two bits, i.e. S = 01 0111001 0111001.
Thus, C = P ⊕ S = 10000101 01100000. Let Pi, Ci , and Si , i = 0, ..., 15, denote bits of plaintext, ciphertext, and keystream,
respectively. The first bit has index 0. After 16 clock impulses, the bits of the keystream are computed as follows:
S0 = S7 = S14 = K 2 = 1 S1 = S8 = S15 = K1 = 0 S2 = S9 = K 0 = 0
S3 = S10 = K 0 ⊕ K 2 = 1 S4 = S11 = ( K 0 + K 2 + K1 ) = 1
S5 = S12 = ( K 2 + K1 ) = 1 S6 = S13 = ( K 0 + K1 ) = 0
Attack step
The adversary builds an equation system as follows:
C0 ⊕ C8 = 1 = S0 ⊕ S8 = K 2 ⊕ K1
C1 ⊕ C9 = 0 = S1 ⊕ S9 = K1 ⊕ K 0
C2 ⊕ C10 = 1 = S2 ⊕ S10 = K 0 ⊕ ( K 0 ⊕ K 2 ) = K 2
Therefore, K 2 = 1, K1 = 0, and K 0 = 0 .
Notes
1 Recall that 0 ⊕ 0 = 0, 1 ⊕ 0 = 1, 0 ⊕ 1 = 1, 1 ⊕ 1 = 0.
2 “Transmission error” means that at the physical layer, the signal received cannot be sampled as 1 or 0.
3 Bit insertion means either modification or appending of bits in the original message.
4 Flip-flops are the basic building blocks of digital systems. Broadly speaking, a flip-flop circuit can be modeled as a black
box, which has two stable states, 0 or 1. A flip-flop stores one bit. When it receives a clock impulse, it changes its state to
the state of its input. Then, the output is the state of the flip-flop until the next clock impulse.
5 For proof of Lemma 6.1, see Problem 6.6.
6 It should be noticed that LFSRs using only XOR operation may remain in 0-state. There also exist LFSRs, which use jointly
XOR and XNOR (i.e. exclusive NOR), that do not stay in 0-state.
7 IEEE: Institute of Electrical and Electronics Engineers.
8 3GPP: 3rd Generation Partnership Project.
9 ETSI: European Telecommunications Standards Institute.
10 IETF: Internet Engineering Task Force.
11 ISO: International Organization for Standardization.
12 Addition (+) and multiplication (* ) are done over finite field F232 , while XOR operation (⊕) is over F2 . See Chapter 3 for
more on operations over finite fields.
13 ZUC acronym comes from Zu Chongzhi, a Chinese mathematician and scientist (5th century).
14 FSM registers are of 32 bits; hence, they are adapted to computations over extended fieldF232 .
15 ChaCha20 is an instance of ChaCha algorithm, with 20 rounds. ChaCha20 is a variant of another stream cipher, called
Salsa20; both algorithms are proposed by the same author.
206 6 Stream Ciphers
References
1 Rescorla, E. (2018). The transport layer security (TLS) protocol version 1.3, RFC 8446. Internet Engineering Task Force
(IETF).
2 Fredricksen, H. (1982). A survey of full length nonlinear shift register cycle algorithms. SIAM (Society for Industrial and
Applied Mathematics) Review 24 (2): 195–221.
3 Web1. Primitive polynomial list. [Online]. [Cited 2023 April]. https://www.partow.net/programming/polynomials.
4 BLE. (2021). Bluetooth core specification, Revision v5.3. Bluetooth SIG, Inc.
5 ETSI. (2006). Specification of the 3GPP confidentiality and integrity algorithms UEA2 & UIA2, document 2 – SNOW 3G
specification. European Telecommunications Standards Institute.
6 ISO/IEC. (2011). Information technology security techniques – encryption algorithms – part 4: stream ciphers – ISO/IEC
18033-4. International Organization for Standardization/International Electrotechnical Commission.
7 Biryukov, A., Schmid, D.P., and Zhang, B. (2010). Analysis of SNOW 3G Resynchronization Mechanism. In International
Conference on Security and Cryptography, 327–333. Athens, Greece: IEEE Xplore.
8 Mukherjee, C.S., Dibyendu, R., and Maitra, S. (2021). Design and Cryptanalysis of ZUC: A Stream Cipher in Mobile
Telephony. Springer.
9 ETSI. (2011). Specification of the 3GPP confidentiality and integrity algorithms 128-EEA3 & 128-EIA3, document 2 – ZUC
specification. European Telecommunications Standards Institute.
10 Bernstein, D. (2008). ChaCha, a Variant of Salsa20. [Online]. [Cited 2023 April]. http://cr.yp.to/chacha/chacha-20080128.
pdf.
11 Nir, Y. and Langley, A. (2018). ChaCha20 and Poly1305 for IETF Protocols, RFC 8439. Internet Engineering Task Force
(IETF).
12 Fluhrer, S., Mantin, I., and Shamir, A. (2001). Weaknesses in the key scheduling algorithm of RC4. In: 8th Annual
International Workshop on Selected Areas in Cryptography, 1–24. Toronto, Canada: Springer, LNCS 2259.
13 Schneier, B. (1996). Applied Cryptography: Protocols, Algorithms and Code in C. Wiley.
14 ISO/IEC. (2012). Information technology – security techniques – lightweight cryptography – part 3: stream ciphers. ISO/
IEC 29192-3. International Organization for Standardization/International Electrotechnical Commission.
15 DeCanniere, C. (2006). Trivium: a stream cipher construction inspired by block cipher design principles. In: 9th
International Conference ISC, 171–186. Samos Island, Greece: Springer, LNCS 4176.
16 DeCanniere, C. and Preneel, B. (2006). Trivium specifications. [Online]. [Cited 2023 April]. https://www.ecrypt.eu.org/
stream/p3ciphers/trivium/trivium_p3.pdf.
17 Hitachi. (2010). Pseudorandom number generator Enocoro, Specification Ver. 2.0. Hitachi Corporation.
207
This chapter focuses on block ciphers, which are the most commonly used algorithms to encrypt confidential data. In
addition to ciphering, block ciphers can be used as stream ciphers and pseudorandom number generators or used to build
hash functions and MACs (Message Authentication Codes). Therefore, block ciphers are of prime importance to build
cryptosystems.
A huge number of block ciphers are published in literature; but a very small number of them are standards used in oper-
ational cryptosystems. This chapter aims at introducing the basics of construction of block ciphers and present in detail the
standard block ciphers, currently in use, namely TDEA (Triple Data Encryption Algorithm) and AES (Advanced Encryption
Standard). Both ciphers are NIST (National Institute of Standards and Technology, US) standards. It is worth noticing that,
because of some reported attacks (even if they are theoretical) against TDEA, AES would be the dominating block cipher
in the near future and for a long time.
Definition 7.1 Block cipher: it is an encryption–decryption scheme where a block of plaintext is treated as a single block and
is used to obtain a block of ciphertext with the same size.
Modern ciphering was inspired by mechanical ciphering machines such as Enigma, presented in Section 4.5. The most
commonly used cyphers, called block ciphers, operate as follows (see Figure 7.1):
● The plaintext is divided into a series of fixed-length blocks (P1, P2 , …, Pm ). In the standards currently in use, the block bit-
length is of either 64 or 128.
● An encryption key K (with a known length of 56, 128, 192, or 256 bits).
● Encrypted blocks (C1 , C2, …, Cm) are of a fixed length, which is the same than that of plaintext blocks.
● Decryption is the inverse operation.
A block cipher is composed of two algorithms: encryption and decryption algorithms, which make use of the same secret
key K. The algorithms are denoted E K () and DK (), which operate on input of fixed-length and produce output with the
same length. Formally:
k n n
E : {0,1} × {0,1} → {0,1}
k n n
D : {0,1} × {0,1} → {0,1}
where n is the block bit-length and k, the key bit-length.
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
208 7 Block Ciphers: Basics, TDEA, and AES
Definition 7.3 Diffusion: it is a cipher operation where when a single bit is changed in the plaintext, several bits in the cipher-
text should change. Similarly, when a single bit changes in the ciphertext, several bits in the plaintext should change.
Definition 7.4 Avalanche effect: changing a few bits in the plaintext (resp. in ciphertext) results in a lot of changes in the
ciphertext (resp. in plaintext), which is known as avalanche effect; i.e. a small change in either the key or the plaintext should
cause a drastic change in the ciphertext.
Affine and Caesar ciphers, presented in Sections 4.2–4.3, do not make use of diffusion and confusion methods. Therefore,
they are very easy to break. In block ciphers, the common techniques to achieve confusion and diffusion are: substitution
boxes, permutations, and key expansion.
7.1.1.2 Permutation
n n
Definition 7.5 Permutation: a function E : {0,1} → {0,1} is a permutation if there exists an inverse function E −1 such
n
that E −1 ( E ( x )) = x , for any x ∈ {0,1} .
rounds, each round has its own key called round key. The result is that the ciphers make use of r keys, where r is the
number of rounds. The key expansion function, also called key schedule function, is the component of block ciphers
that generates the round keys from the initial key (also called cipher key). In general, key expansion function makes use
of permutations and s-boxes (see Figure 7.3).
Encryption
input B: plaintext
output C: ciphertext
1. ( LE0 , RE0 ) = B # B is the plaintext divided into two equal-length halves,
LE0 and RE0 . Abbreviations: L (Left), R (Right), E (encryption).
2. for i = 1 to n do
LEi = REi−1; REi = LEi−1 ⊕ F ( REi−1 , Ki )
3. C = REn || LEn; return C
Note. The halves computed in the last round are concatenated in this order REn followed by LEn to form the ciphertext
block.
Decryption2 is the same as the encryption with one difference: the round keys used in encryption are used in the reverse
order.
210 7 Block Ciphers: Basics, TDEA, and AES
Figure 7.4 Feistel structure (encryption on the left and decryption on the right). Halves are indexed by the round number; and
E and D denote encryption and decryption.
Decryption
input C: ciphertext
output B: plaintext
1. ( LD0 , RD0 ) = C # Divide C into two equal-length halves, with
# abbreviations: L (Left), R (Right), D (Decryption)
# Thus, LD0 = REn and RD0 = LEn .
2. for i = 1 to n do
LDi = RDi−1; RDi = LDi−1 ⊕ F ( RDi−1 , K n−i +1 )
3. B = RDn || LDn; return B
Note. The halves computed in the last round are concatenated in this order RDn followed by LDn to form the plaintext
block.
7.2 Triple Data Encryption Algorithm (TDEA) 211
The first version of TDEA was approved by the NIST in 2004; and the most recent revision of TDEA was published in
2017 [2]. Till now, TDEA is considered as a secure block cipher. It applies the DEA (Data Encryption Algorithm) cipher
three times to each data block. To understand how TDEA works one must first understand the basics of DEA.
As shown in the encryption and decryption algorithms above and in Figure 7.6, DEA makes use of specific internal
components: initial permutation and its inverse, key schedule function KS, and function f ; all these components are
described below.
7.2 Triple Data Encryption Algorithm (TDEA) 213
Note. DEA permutation and substitution tables are two-dimension arrays. In the sequel, both rows and columns indices
start with 0; T 0, 0 denotes the first element of any table.
7.2.1.3 Function f
Function f is the core of DEA, as it makes use of selection functions to scramble a 32-bit round input using a round key,
an expansion operation Exp, and a permutation P (see Figure 7.7). The pseudocode of the function f is as follows:
function f
input R, k : 32-bit string and round key
output R ′ # 32-bit string
1. Rxp = Exp( R ) # expand R to 48 bits
2. Z = k ⊕ Rxp
3. Let Z 1 : 48 be the bit-vector representation of Z
4. Z i = Z 6 * ( i − 1) + 1, 6 * i , i = 1, … , 8 # Split vector Z into 8 sub-vectors
5. for i = 1 to 8 do
Yi = SFi ( Z i ) # selection function SFi compacts Z i to four bits
6. Y = Y1 || Y2 || Y3 || Y4 || Y5 || Y6 || Y7 || Y8 # Concatenate the eight values
7. R′ = P (Y ) # Permute the 32 bits of Y
8. return R′
58 50 42 34 26 18 10 2
60 52 44 36 28 20 12 4
62 54 46 38 30 22 14 6
64 56 48 40 32 24 16 8
57 49 41 33 25 17 9 1
59 51 43 35 27 19 11 3
61 53 45 37 29 21 13 5
63 55 47 39 31 23 15 7
214 7 Block Ciphers: Basics, TDEA, and AES
40 8 48 16 56 24 64 32
39 7 47 15 55 23 63 31
38 6 46 14 54 22 62 30
37 5 45 13 53 21 61 29
36 4 44 12 52 20 60 28
35 3 43 11 51 19 59 27
34 2 42 10 50 18 58 26
33 1 41 9 49 17 57 25
32 1 2 3 4 5
4 5 6 7 8 9
8 9 10 11 12 13
12 13 14 15 16 17
16 17 18 19 20 21
20 21 22 23 24 25
24 25 26 27 28 29
28 29 30 31 32 1
Selection functions
Selection functions also are called substitution boxes (or S-boxes). They are nonlinear (see Exercise 7.4), which pro-
vide some level of security to DEA. DEA makes use of eight selection functions, denoted SF j , j = 1, ..., 8 , which
operate like compression functions. Each selection function SF j has a table S j associated with it (Table 7.4). Tables
of selection functions are represented as 4 rows by 16 columns matrices. Given a 6-bit value v, each selection function
SF j , j = 1, ..., 8, yields a 4-bit value w j = SF j ( v ). SF j ( v ) returns the table element S j ( vr , vc ) such that vr , the row number,
is a 2-bit value formed by the first and the last bits of v; and vc , the column number, is a 4-bit value formed by the
2nd, 3rd, 4th, and 5th bits of v.
For example, let v = 27 = 0110112. Then, vr = 012 and vc = 11012. Hence, the reductions of v = 27 are:
SF1 (27) → S1 (1,13) = 5 SF2 (27) → S2 (1,13) = 9 SF3 (27)→ S3 (1, 13) = 11
SF4 (27) → S4 (1,13) = 10 SF5 (27) → S5 (1,13) = 9 SF6 (27) → S6 (1,13) = 11
SF7 (27) → S7 (1,13) = 15 SF8 (27) → S8 (1,13) = 14
S1 14 4 13 1 2 15 11 8 3 10 6 12 5 9 0 7
0 15 17 4 14 2 13 1 10 6 12 11 9 5 3 8
4 1 14 8 13 6 2 11 15 12 9 7 3 10 5 0
15 12 8 2 4 9 1 7 5 11 3 14 10 0 6 13
S2 15 1 8 14 6 11 3 4 9 7 2 13 12 0 5 10
3 13 4 7 15 2 8 14 12 0 1 10 6 9 11 5
0 4 7 11 10 4 13 1 5 8 12 6 9 3 2 15
13 8 10 1 3 15 4 2 11 6 7 12 0 5 14 9
S3 10 0 9 14 6 3 15 5 1 13 12 7 11 4 2 8
13 7 0 9 3 4 6 10 2 8 5 14 12 11 15 1
13 6 4 9 8 15 3 0 11 1 2 12 5 10 14 7
1 10 13 0 6 9 8 7 4 15 14 3 11 5 2 12
S4 7 13 14 3 0 6 9 10 1 2 8 5 11 12 4 15
13 8 11 5 6 15 0 3 4 7 2 12 1 10 14 9
10 6 9 0 12 11 7 13 15 1 3 14 5 2 8 4
3 15 0 6 10 1 13 8 9 4 5 11 12 7 2 14
(Continued)
216 7 Block Ciphers: Basics, TDEA, and AES
S5 2 12 4 1 7 10 11 6 8 5 3 15 13 0 14 9
14 11 2 12 4 7 13 1 5 0 15 10 3 9 8 6
4 2 1 11 10 13 7 8 15 9 12 5 6 3 0 14
11 8 12 7 1 14 2 13 6 15 0 9 10 4 5 3
S6 12 1 10 15 9 2 6 8 0 13 3 4 14 7 5 11
10 15 4 2 7 12 9 5 6 1 13 14 0 11 3 8
9 14 15 5 2 8 12 3 7 0 4 10 1 13 11 6
4 3 2 12 9 5 15 10 11 14 1 7 6 0 8 13
S7 4 11 2 14 15 0 8 13 3 12 9 7 5 10 6 1
13 0 11 7 4 9 1 10 14 3 5 12 2 15 8 6
1 4 11 13 12 3 7 14 10 15 6 8 0 5 9 2
6 11 13 8 1 4 10 7 9 5 0 15 14 2 3 12
S8 13 2 8 4 6 15 11 1 10 9 3 14 5 0 12 7
1 15 13 8 10 3 7 4 12 5 6 11 0 14 9 2
7 11 4 1 9 12 14 2 0 6 10 13 15 3 5 8
2 1 14 7 4 10 8 13 15 12 9 0 3 5 6 11
Permutation P
It takes a 32-bit string and yields a bit string of the same length, using table P (Table 7.5). Table P is an 8-row by 4-colum
matrix. Given a 32-bit value Y , the permuted bit-string Y ′ = P (Y ) is defined by:
Y ′ i = Y P ir , ic , for i = 1, ..., 32, where ir = i / 4 − 1 and ic = i − 4 * ir − 1
Example:
Y ′ 1 = Y P 0, 0 = Y 16 Y ′ 4 = Y P 0, 3 = Y 21
16 7 20 21
29 12 28 17
1 15 23 26
5 18 31 10
2 8 24 14
32 27 3 9
19 13 30 6
22 11 4 25
7.2 Triple Data Encryption Algorithm (TDEA) 217
A TDEA key, called bundle key, consists of three DEA keys, denoted Key1, Key2, and Key3 ; i.e. BundleKey = ( Key1 , Key2 , Key3 ).
Two options are permitted:
1) The three keys are all distinct (i.e. Keyi ≠ Key j , ∀i ≠ j, i, j ∈ {1, 2, 3}); in such a case, the block cipher is called three-key
TDEA (and denoted 3TDEA). It is the recommended option.
2) Two keys are identical and are distinct from the third one, which is an option for legacy use only. The selection of keys
shall fulfill the following condition: Key1 ≠ Key2 , Key2 ≠ Key3 , and Key1 = Key3; in such a case, the block cipher is called
two-key TDEA (and denoted 2TDEA5).
When a DEA key is used, it has a length of 56 bits. However, when DEA keys are generated, distributed, or stored, they are
represented as a 64-bit strings, where eight extra bits are odd parity bits (i.e. one odd parity bit is added on the right of every
seven bits in the initial key), which may be used for error detection. Odd parity bits are dropped by the key schedule
function; they have no impact on security.
Weak keys and semi-weak keys
A key Key is said to be weak, if all the round keys generated from it are identical. The bad property of a weak key is that
encrypting twice a plaintext M yields M and decrypting twice a ciphertext C yields C. Formally,
( ) (
Weak ( K ) ⇒ E K ( E K ( M )) = M , ∀M ∈ {0,1}64 ∧ DK ( DK (C )) = C , ∀C ∈ {0,1}64 )
The following keys are considered weak, when used in DEA engine, and should be avoided:
01010101 0101010116 FEFEFEFE FEFEFEFE16
E0E0E0E0 F1F1F1F116 1F1F1F1F 0E0E0E0E16
A key Key is said to be semi-weak, if only two distinct round keys can be generated from it. If two keys key1 and key2 are
semi-weak keys and have the same round keys, they form a pair of semi-weak keys. In other words, encryption with one of
the keys in the pair is equivalent to decryption with the other (and vice versa). The bad property of a pair of weak keys is
that encrypting a plaintext M with both keys in cascade yields M. Formally,
( )
WeakPair ( Key1 , Key2 ) ⇒ E Key E Key ( M ) = M , ∀M ∈ {0, 1}64
1 2
The following six pairs are pairs of semi-weak keys and should be avoided:
011F 011F 010E010E16 and 1F 011F 010E010E0116
01E001E001F101F116 and E001E001F101F10116
01FE01FE01FE01FE16 and FE01FE01FE01FE0116
1FE01FE00EF10EF116 and E01FE01FF10EF10E16
1FFE1FFE0EFE0EFE16 and 1FFE1FFE0EFE0EFE16
E0FEE0FEF1FEF1FE16 and FEE0FEE0FEF1FEF116
Finally, there is a list of 48 keys that produce only four distinct round keys when the key schedule is applied and when it
should be avoided (see NIST recommendation [2]).
Problems 7.6 and 7.7 discuss examples of weak and semi-weak keys.
E((Key
TDEA )
3 , Key , Key )
2 1 3
( 2
(
( P ) = E Key DKey E Key ( P ) = C
1
))
TDEA decryption of a 64-bit ciphertext C is defined by:
D((Key
TDEA )
3 , Key , Key )
2 1 1
( 2
(
(C ) = DKey EKey DKey (C ) = P
3
))
Figure 7.8 shows an overview of how DEA is used to perform TDEA encryption and decryption. Notice that a TDEA bundle
key bit-length is 3 * 64 when it is stored or distributed, while its bit-length from the cryptographic perspective is 3 * 56.
218 7 Block Ciphers: Basics, TDEA, and AES
Permuted choice function is used once; it takes a 64-bit key KEY and makes use of permutation PC1 to compress and per-
mute KEY to yield two 28-bits blocks C0 and D0 defined by:
C0 [i] = KEY PC1 ir , ic , for i = 1, ..., 28 , where ir = i / 7 − 1 and ic = i − 7 * ir − 1.
D0 [i] = KEY PC1 ir , ic , for i = 1, ..., 28, where ir = (i + 28) / 7 − 1 and ic = (i + 28) − 7 * ir − 1.
Example:
C0 [1] = KEY PC1[0, 0] = KEY [57] C0 [2] = KEY PC1[0,1] = KEY [49]
C0 [28] = KEY PC1[3, 6] = KEY [36] D0 [1] = KEY PC1[4, 0] = KEY [63]
D0 [2] = KEY PC1[4,1] = KEY [55] D0 [28] = KEY PC1[7, 6] = KEY [4]
Compression permutation is used for each iteration i, i = 1, ..., 16; it takes two 28-bits blocks Ci and Di and makes use of com-
pression permutation PC2 to yield the round key K i . Each 28-bit block Ci (resp. Di) is yielded from Ci−1 (resp. Di−1) using a
left rotation by one or two positions. The number of rotation positions for each iteration is given by the vector NLR (Table
7.8). Pseudocode of the key scheduling function KS is as follows:
57 49 41 33 25 17 9
1 58 50 42 34 26 18
10 2 59 51 43 35 27
19 11 3 60 52 44 36
63 55 47 39 31 23 15
7 62 54 46 38 30 22
14 6 61 53 45 37 29
21 13 5 28 20 12 4
14 17 11 24 1 5
3 28 15 6 21 10
23 19 12 4 26 8
16 7 27 20 13 2
41 52 31 37 47 55
30 40 51 45 33 48
44 49 39 56 34 53
46 42 50 36 29 32
220 7 Block Ciphers: Basics, TDEA, and AES
Iteration number 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# of left rotations 1 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1
Decryption: D((Key
2 DE )
, Key )
( P ) = DKey ( DKey (C )) = P
2 1 1 2
where P is the plaintext, C the ciphertext, and Key1 and Key2 , the keys.
At a first glance, one may think that the brute-force attack against 2DES has a complexity of 22*56 = 2112. Therefore, dou-
bling the key length would result in a secure cipher. Unfortunately, 2DES is insecure; therefore, it is not recommended.
2DES is insecure under the meet-in-the-middle attack, which is presented below. Its effective key length is 257.
In a similar way to 2DES, the meet-in-the-middle attack reduces the complexity of TDEA, with three distinct keys, to 2112.
Therefore, tripling the key length of DES does not result in a security of 2168 as naïvely expected. However, TDEA, with three
distinct keys, has an effective key length of 112. Therefore, an attack of a complexity of 2112 is computationally infeasible with
current technologies, which makes TDEA a secure cipher.
Assume that an adversary knew a plaintext–ciphertext pair ( P, C ) and has the capacities to compute and store the cipher-
texts associated with the plaintext P encrypted with all the 256 DES keys. The MITM attack takes advantage of the following
observation:
( X = E Key ( P )) ∧ (C = E Key ( E Key ( P ))) ⇒ DKey (C ) = X
1 2 1 2
The principle of MITM attack is to perform encryptions of the known plaintext with all values of Key1 and perform decryp-
tions of the known ciphertext with all the values of Key2 and join both computations to find key pair candidates ( K1 , K 2 ) ,
such that: E K ( P ) = DK (C ). Hence, the notion of meet in the middle.
1 2
In the attack complexity analysis, it is assumed that only encryption and decryption operations, which are the most
time-consuming, are of interest. The MITM attack algorithm is as follows:
In the attack above, the worst case of the number of encryptions is 256 and that of decryptions is 256 . Therefore, the attack
complexity is of 257 . However, only one of the key pair candidates is the real pair ( Key2 , Key1 ). In Problem 7.9, we address
the probability of success of the MITM attack.
In the pseudocode above, the table T is a vector, where T i contains the ciphertext of plaintext P encrypted with key i.
However, when a decrypted value Z = D( K 2 , C ) is searched in table T, the search time would be very high, because one
needs, in average, to test half of the table. One optimization of the MITM attack algorithm is to use a table with two col-
umns T 0 : 256 − 1, 1 : 2 , where T i,1 = E (i, P ) and T i,2 = i . Then, sort the table on the first column. Then, a dichotomic
search may be applied to reduce the computation time of the attack.
E((Key
TDEA )
, Key , Key )
( P ) = E Key ( DKey ( EKey ( P ))) = C
3 2 1 3 2 1
Like Double DES, TDEA is defined by a repetitive use of the same cipher. Therefore, it is vulnerable to MITM attack. The
principle of MITM attack against TDEA is very similar to the attack against double DES. It takes advantage of the following
observation:
The Advanced Encryption Standard (AES), also known by its original name Rijndael,6 was proposed by Daemen and
Rijmen in the late 1990s. Rijndael algorithm was one of the finalists to the public call issued by the NIST in 1997 to replace
DES, because of the discovered weaknesses. Rijndael algorithm was the winner and it was confirmed by the NIST as a stan-
dard in 2001, but under the name AES [6]. The only difference between Rijndael and AES is the range of supported values
of block length and key length.
AES is by now the most widely used cipher in cryptosystems and it is expected to dominate for long time. In 2003, the
NSA (National Security Agency) allowed AES for protection of classified data up to Top secret with keys of 192 or 256 bits.
Let A be an input, an output, or a round key of 16 bytes. A is represented in one of the following forms:
1) byte representation: A = A0 A1 … A16
2) word representation: A = W0W1W2W3, where W0−3 are 32-bit words
3) bit representation: A = b0b1 … b127 .
Bit indices of a 128-bit block are represented by Figure 7.11.
State notion
AES transformations are performed on two-dimensional arrays of bytes called states. A state has four rows each of four
bytes (i.e. 4 * 4 bytes = 128 bits). Notice that in the current version of AES, the block length is of 128 bits; it might change
in the future. Therefore, the number of bytes per row should change.
Each byte within a state S is denoted Sr ,c , where r, 0 ≤ r ≤ 3, denotes the row number and c, 0 ≤ c ≤ 3, the column
number. The mapping from the cipher input to the state and from the state to the cipher output is illustrated by Figure 7.12.
The four bytes in each column of a state form a 32-bit word. Therefore, a state S can be considered as an array of four
words W0, W1 , W2, and W3 , defined as follows:
W0 = S0,0 , S1,0 , S2,0 , S3,0 W1 = S0,1 , S1,1 , S2,1 , S3,1
W2 = S0,2 , S1,2 , S2,2 , S3,2 W3 = S0,3 , S1,3 , S2,3 , S3,3
Figure 7.12 Mapping between the cipher input, output bytes, and the state bytes.
224 7 Block Ciphers: Basics, TDEA, and AES
CopyCipherInputToStateArray and CopyStateToCipherOutput are conversion functions to convert a bit-string (i.e. plaintext
or ciphertext block) to a state array and vice versa.
Note. Unlike DEA, which makes use of random S-boxes, the AES s-boxes have an algebraic structure (see Section 7.3.6.2).
Example 7.1
SubBytes and InvSubBytes make use of tables S-box and InvS-box, respectively. Byte 3c 16 is replaced
by S_Box (3, 12) = eb . Byte eb 16 is replaced by InvS_Box (14, 11) = 3c 16 .
16
Byte 75 16 is replaced by S_Box (7, 5) = 9d 16. Byte 9d 16 is replaced by InvS_Box (9, 13) = 75 .
16
Figure 7.13 Overall structure of AES.
0 1 2 3 4 5 6 7 8 9 a b c d e f
x 0 63 7c 77 7b f2 6b 6f c5 30 01 67 2b fe d7 ab 76
1 ca 82 c9 7d fa 59 47 f0 ad d4 a2 af 9c a4 72 c0
2 b7 fd 93 26 36 3f f7 cc 34 a5 e5 f1 71 d8 31 15
3 04 c7 23 c3 18 96 05 9a 07 12 80 e2 eb 27 b2 75
4 09 83 2c 1a 1b 6e 5a a0 52 3b d6 b3 29 e3 2f 84
5 53 d1 00 ed 20 fc b1 5b 6a cb be 39 4a 4c 58 cf
6 d0 ef aa fb 43 4d 33 85 45 f9 02 7f 50 3c 9f a8
7 51 a3 40 8f 92 9d 38 f5 bc b6 da 21 10 ff f3 d2
8 cd 0c 13 ec 5f 97 44 17 c4 a7 7e 3d 64 5d 19 73
9 60 81 4f dc 22 2a 90 88 46 ee b8 14 de 5e 0b db
a e0 32 3a 0a 49 06 24 5c c2 d3 ac 62 91 95 e4 79
b e7 c8 37 6d 8d d5 4e a9 6c 56 f4 ea 65 7a ae 08
c ba 78 25 2e 1c a6 b4 c6 e8 dd 74 1f 4b bd 8b 8a
d 70 3e b5 66 48 03 f6 0e 61 35 57 b9 86 c1 1d 9e
e e1 f8 98 11 69 d9 8e 94 9b 1e 87 e9 ce 55 28 df
f 8c a1 89 0d bf e6 42 68 41 99 2d 0f b0 54 bb 16
226 7 Block Ciphers: Basics, TDEA, and AES
0 1 2 3 4 5 6 7 8 9 a b c d e f
x 0 52 09 6a d5 30 36 a5 38 bf 40 a3 9e 81 f3 d7 fb
1 7c e3 39 82 9b 2f ff 87 34 8e 43 44 c4 de e9 cb
2 54 7b 94 32 a6 c2 23 3d ee 4c 95 0b 42 fa c3 4e
3 08 2e a1 66 28 d9 24 b2 76 5b a2 49 6d 8b d1 25
4 72 f8 f6 64 86 68 98 16 d4 a4 5c cc 5d 65 b6 92
5 6c 70 48 50 fd ed b9 da 5e 15 46 57 a7 8d 9d 84
6 90 d8 ab 00 8c bc d3 0a f7 e4 58 05 b8 b3 45 06
7 d0 2c 1e 8f ca 3f 0f 02 c1 af bd 03 01 13 8a 6b
8 3a 91 11 41 4f 67 dc ea 97 f2 cf ce f0 b4 e6 73
9 96 ac 74 22 e7 ad 35 85 e2 f9 37 e8 1c 75 df 6e
a 47 f1 1a 71 1d 29 c5 89 6f b7 62 0e aa 18 be 1b
b fc 56 3e 4b c6 d2 79 20 9a db c0 fe 78 cd 5a f4
c 1f dd a8 33 88 07 c7 31 b1 12 10 59 27 80 ec 5f
d 60 51 7f a9 19 b5 4a 0d 2d e5 7a 9f 93 c9 9c ef
e a0 e0 3b 4d ae 2a f5 b0 c8 eb bb 3c 83 53 99 61
f 17 2b 04 7e ba 77 d6 26 e1 69 14 63 55 21 0c 7d
where LRotate (r , Nb) operation rotates r with Nb positions to the left. Recall that when the block bit-length is 128, Nb, the
number of state columns, is 4.
Note that ShiftRows transformation ensures that the four bits of one column are spread out to four different
columns.
InvShiftRows transformation (see Figure 7.15) inverses the ShiftRows output. The row 0 of the input state S
remains unchanged and each of the other three rows, r = 1, 2, 3, are rotated by r byte(s) to the right. Formally, InvShiftRows
transformation is defined by:
S ′ , S ′ , S ′ , S ′ = S , S , S , S ⊕ KW
0,c 1,c 2,c 3,c 0,c 1,c 2,c 3,c rnd * 4 +c , for 0 ≤ c < 4
In the encryption (resp. decryption) operation, the initial input state is added to the key words KW0 to KW3 (resp. KWNr *4
to KWNr * 4+3 ) before performing the first encryption (resp. decryption) round.
Table 7.11 Values of the leftmost byte of the constant vector Rcon.
Round number 1 2 3 4 5 6 7 8 9 10
Rcon 0116 0216 0416 0816 1016 2016 4016 8016 1b16 3616
function KeyExpansion
input Nk : key length in 32-bit words; K : key array of Nk 32-words
output W : array of the round keys; W is of 4 * ( Nr + 1) words
1. for i= 0 to Nk do
# Copy the cipher key K Nk + 1 times in the array W
# K j denotes the jth byte of key K ; 0 ≤ j ≤ len(K )-1
W i = K 4 * i , K 4 * i + 1 , K 4 * i + 2 , 4 * i + 3]]
2. for i=Nk to 4 * ( Nr + 1) -1 do
tmp = W i − 1
if (i mod Nk = 0)
then tmp = SubWord(RotWord(tmp)) ⊕ Rcon[i/Nk ]
else if (Nk > 6 and i mod Nk = 4)
then tmp = SubWord(tmp)
W i = W i − Nk ⊕ tmp
3. return W
7.3 Advanced Encryption System (AES) 229
SubWord(Z) is a function that takes a 4-byte input word Z and applies the S-Box to each of the four bytes to yield an
output word Z ′. RotWord(Z) is a function that takes a 4-byte input word Z = Z0 , Z1 , Z2 , Z3 and outputs the permuted
word Z ' = Z1 , Z2 , Z3 , Z0 . Rcon(i) is a constant array.
Example 7.2
Let a = 11011011 and b = 111000112 be two bytes in binary representation. In polynomial representation, we have:
a( x ) = x 7 + x 6 + x 4 + x 3 + x + 1 and b( x ) = x 7 + x 6 + x 5 + x + 1
In extension field F28 , the coefficients in the polynomials are binaries. Hence, c = a + b is yielded by:
c ( x ) = a( x ) + b ( x ) = x 5 + x 4 + x 3
With the bitwise XOR operation:
a ⊕ b = (110110112 ) ⊕ (111000112 ) = 001110002
Byte multiplication
Byte multiplication, denoted •, is performed with the irreducible polynomial m( x ) = x 8 + x 4 + x 3 + x + 1. Notice that since
the irreducible polynomial m( x ) is of degree 8, any multiplication of two bytes results in a value represented by a byte. Any
element b and its inverse b−1 are both elements of F28 . The irreducible polynomial used in AES has a useful property, which
makes it easy to implement the operations especially in hardware.
Example 7.3
Let a = 110110112 and b = 000000112 be two bytes in binary representation.
c = a i b is computed as follows:
(
c ( x ) = a ( x ) * b ( x ) mod x 8 + x 4 + x 3 + x + 1 )
(
= ( x 8 + x 6 + x 5 + x 3 + x 2 + 1) mod x 8 + x 4 + x 3 + x + 1 )
6 5 4 2
=x +x +x +x +x
c = 110110112 i 000000112 = 011101102
Let a′ = 100001112 and b′ = 010101102 be two bytes in binary representation.
c ′ = a′ i b′ is computed as follows:
(
c ′ ( x ) = a ′ ( x ) * b ′ ( x ) mod x 8 + x 4 + x 3 + x + 1 )
( )
= ( x 13 + x 11 + x 9 + x 7 + x 5 + x ) mod x 8 + x 4 + x 3 + x + 1 = 1
230 7 Block Ciphers: Basics, TDEA, and AES
Word addition
The addition of two words A = A0 , A1 , A2 , A3 and B = B0 , B1 , B2 , B3 is yielded by the bitwise XOR of their coefficients.
More precisely, C = A + B is yielded as follows:
C = A0 ⊕ B0 , A1 ⊕ B1 , A2 ⊕ B2 , A3 ⊕ B3
( )(
C ( x ) = A ( x ) i B ( x ) = A3 x 3 + A2 x 2 + A1 x + A0 * B3 x 3 + B2 x 2 + B1 x + B0 )
= ( A3 i B3 ) x 6
+ (( A3 i B2 ) ⊕ ( A2 i B3 )) x 5
+ (( A3 i B1 ) ⊕ ( A2 i B2 ) ⊕ ( A1 i B3 )) x 4
+ (( A3 i B0 ) ⊕ ( A2 i B1 ) ⊕ ( A1 i B2 ) ⊕ ( A0 i B3 )) x 3
+ (( A2 i B0 ) ⊕ ( A1 i B1 ) ⊕ ( A0 i B2 )) x 2
+ (( A1 i B0 ) ⊕ ( A0 i B1 )) x
+ ( A0 i B0 )
D( x ) = A( x ) ⊗ B ( x ) = C ( x ) mod ( x 4 + 1) = D3 x 3 + D2 x 2 + D1 x + D0
Thus, D( x ) is of degree 3 and its coefficients are computed as follows:
D ( x ) = (( A3 i B0 ) ⊕ ( A2 i B1 ) ⊕ ( A1 i B2 ) ⊕ ( A0 i B3 )) x 3
+ (( A2 i B0 ) ⊕ ( A1 i B1 ) ⊕ ( A0 i B2 ) ⊕( A3 i B3 )) x 2
+ (( A1 i B0 ) ⊕ ( A0 i B1 ) ⊕ ( A3 i B2 ) ⊕ ( A2 i B3 ) x
+ ( A0 i B0 )⊕ ( A3 i B1 ) ⊕ ( A2 i B2 ) ⊕ ( A1 i B3 )
D0 A0 A3 A2 A1 B0
D A A0 A3 A2 B
1 = 1 1
D A A1 A0 A3 B
2 2 2
D A A2 A1 A0 B
3 3 3
7.3 Advanced Encryption System (AES) 231
Notes
1) The polynomial x 4 + 1 is not an irreducible polynomial, because it has 1 as a root. Thus, the multiplicative inverse does
not exist for some elements mod x 4 + 1. However, it is not important, because AES makes use of only two polynomials
that both have inverses:
– Polynomial A( x ) = 03 16 x 3 + 01 16 x 2 + 01 16 x + 02 16 is used in MixColumns; and its inverse is
A( x )−1 = 0 b 16 x 3 + 0d 16 x 2 + 09 16 x + 0e 16. One can easily check that A( x ) * A( x )−1 = 1 mod ( x 4 + 1).
– Polynomial A( x ) = x 3 is used in key expansion; and its inverse is A( x )−1 = x , because x 3 * x mod ( x 4 + 1) = 1.
2) AES selected the polynomial x 4 + 1, due to its simplicity of reduction. Indeed, it provides the following
i mod 4
reduction: x i mod ( x 4 + 1) = x .
Example 7.4
– Let W (1) and W (2) be two 32-bit words such that:
W (1) = fe 16 , 11 16 , 03 16 , ab 16 and W (2) = aa 16 , c1 16 , 10 16 , d0 16
Adding W (1) to W (2) yields W (1+2), computed as:
W
(1+2)
( x ) = (ab16 ⊕ d016 ) x 3 + (0316 ⊕ 1016 ) x 2 + (1116 ⊕ c116 ) x + (fe16 ⊕ aa 16 )
= 7 b 16 x 3 + d0 16 x 2 + 13 16 x + 54 16
C
(1*2)
( x ) = (1116 x 3 ) * (5516 x 3 + 2216 x 2 + cd16 )
( ) ( ) (
= 11 16 i 55 16 x 6 + 11 16 i 22 16 x 5 + 11 16 i cd 16 x 3 )
Compute 11 16 i 55 16 :
( x 4 + 1)( x 6 + x 4 + x 2 + 1) mod x 8 + x 4 + x 3 + x + 1
= x6 + x5 + x 4 + x
( x 4 + 1)( x 5 + x ) mod x 8 + x 4 + x 3 + x + 1 = x 5 + x 4 + x 2
( x 4 + 1)( x 7 + x 6 + x 3 + x 2 + 1) mod x 8 + x 4 + x 3 + x + 1
= x7 + x5 + x3 +1
Example 7.5
– S_Box (0, 0) = 63 16, because:
⚪ The inverse of a = 00 is b = 00 (by AES design)
b7′ = 0 ⊕ 0 ⊕ 1 ⊕ 0 ⊕ 1 ⊕ 0 = 0 b3′ = 0 ⊕ 0 ⊕ 0 ⊕ 1 ⊕ 1 ⊕ 0 = 0
b6′ = 1 ⊕ 1 ⊕ 0 ⊕ 1 ⊕ 0 ⊕ 1 = 0 b2′ = 1 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 1 ⊕ 0 = 1
b5′ = 0 ⊕ 1 ⊕ 1 ⊕ 0 ⊕ 1 ⊕ 1 = 0 b1′ = 1 ⊕ 0 ⊕ 1 ⊕ 0 ⊕ 0 ⊕ 1 = 1
b4′ = 1 ⊕ 0 ⊕ 1 ⊕ 1 ⊕ 0 ⊕ 0 = 1 b0′ = 0 ⊕ 1 ⊕ 0 ⊕ 1 ⊕ 0 ⊕ 1 = 1
In the matrix form, the affine transformation (7.1) can be specified as follows (with addition modulo 2):
b0′ 1 0 0 0 1 1 1 1 b0 1
b ′ 1 1 0 0 0 1 1 1 b1 1
1
b ′ 1 1 1 0 0 0 1 1 b2 0
2
b ′ 1 1 1 1 0 0 0 1 b3 0
3
= ⊕ (7.2)
b4′ 1 1 1 1 1 0 0 0 b4 0
b5′ 0 1 1 1 1 1 0 0 b5 1
b6′ 0 0 1 1 1 1 1 0 b6 1
b ′ 0 0 0 1 1 1 1 1 b7 0
7
Construction of InvS-Box
The InvS-Box is constructed in the inverse order of that of the S-Box; it is obtained by the inverse of the affine transforma-
tion used to construct the S-Box and then, by computing the multiplicative inverse.
7.3 Advanced Encryption System (AES) 233
Let α denote the concatenation of the row and column indexes of an InvS-Box cell. β ′ , the content of the InvS-Box cell
indexed by α, is computed in two steps as follows:
1) Apply the following affine transformation to the element α, for 0 ≤ i < 8, to yield
αi′ = α(i+2) mod 8 ⊕ α(i+5) mod 8 ⊕ α (i+7 ) mod 8 ⊕ di , (7.3)
where d is a constant with a value of 0516 = 000001012.
2) Take β ′, the multiplicative inverse of α ′ in the extension field F28 ; that is, β ′ = α ′−1.
In the matrix form, the affine transformation (7.3) can be specified as follows (with addition modulo 2):
b0′ 0 0 1 0 0 1 0 1 b0 1
b 1 0 0 1 0 0 1 0 b 0
1 1
b′ 0 1 0 0 1 0 0 1 b 1
2 2
b′ 1 0 1 0 0 1 0 0 b 0
3 3
= ⊕ (7.4)
b4′ 0 1 0 1 0 0 1 0 b4 0
b5′ 0 0 1 0 1 0 0 1 b5 0
b6′ 1 0 0 1 0 1 0 0 b6 0
b′ 0 1 0 0 1 0 1 0 b 0
7 7
Note. The elements of the S-Box and their inverses are constants; thus, they are computed one time and stored in two
tables.
( ) ( )
S1′,c = S0,c ⊕ 02 16 i S1,c ⊕ 03 16 i S2,c ⊕ S3,c , for 0 ≤ c < 4
( )( )
S2′,c = S0,c ⊕ S1,c ⊕ 02 16 i S2,c 03 16 i S3,c , for 0 ≤ c < 4
( ) (
S3′,c = 03 16 i S0,c ⊕ S1,c ⊕ S2,c ⊕ 02 16 i S3,c , for 0 ≤ c < 4 )
From the four equalities above, we observe that each byte in a column c of the input state S is replaced by twice that byte,
plus three times the next byte, plus the byte that comes next, and plus the byte that follows in the column.
Example 7.6
Assume that the first column of the state S is 10 16 , 00 16 , 00 16 , 01 16 . We compute the new column yielded by
MixColumns. The polynomial associated with the first column is: S* ,0 ( x ) = 01 16 x 3 + 10 16 .
Compute the modular product: S*,0 ( x ) ⊗ a( x ).
234 7 Block Ciphers: Basics, TDEA, and AES
( )( ) ( )
S*,0 ( x ) ⊗ a ( x )= 01 16 x 3 + 10 16 * 03 16 x 3 + 01 16 x 2 + 01 16 x + 02 16 mod x 4 + 1
( ) ( ) ( )
= 03 16 i 01 16 x 6 + 01 16 i 01 16 x 5 + 01 16 i 01 16 x 4
( ) ( )
+ 02 16 i 01 16 ⊕ 03 16 i 10 16 x 3 + 01 16 i 10 16 x 2
( ) ( ) (
+ 01 16 i 10 16 x + 02 16 i 10 16 mod x 4 + 1 )
( ) ( )
= 02 16 i 01 16 ⊕ 03 16 i 10 16 x 3 + 01 16 i 10 16 ⊕ 03 16 i 01 16 x 2
( ) ( )
+ 01 16 i 10 16 ⊕ 01 16 i 01 16 x + 02 16 i 10 16 ⊕ 01 16 i 01 16
( ) ( )
= 02 16 ⊕ 03 16 i 10 16 x 3 + 10 16 ⊕ 03 16 x 2
( ) (
+ 10 16 ⊕ 01 16 x + 02 16 i 10 16 ⊕ 01 16 )
= 31 16 x 3 + 13 16 x 2 + 11 16 x + 21 16
(
S0′,c = 0e 16 i S0,c ) ⊕(0 b16 i S1,c )⊕(0d16 i S2,c )⊕(0916 i S3,c ), for 0 ≤ c < 4
(
S1′,c = 09 16 i S0,c ) ⊕ (0e16 i S1,c ) ⊕ (0 b16 i S2,c ) ⊕ (0d16 i S3,c ), for 0 ≤ c < 4
(
S2′,c = 0d 16 i S0,c ) ⊕ (0916 i S1,c ) ⊕ (0e16 i S2,c )⊕ (0 b16 i S3,c ), for 0 ≤ c < 4
(
S3′,c = 0 b 16 i S0,c )⊕(0d16 i S1,c ) ⊕ (0916 i S2,c )⊕(0e16 i S3,c ), for 0 ≤ c < 4
7.3.6.5 AddRoundKey Transformation
AddRoundKey is an XOR operation between a state and the round key; it is its inverse.
Exercise 7.1
Consider the first round of the Feistel cipher encryption. Which part of the plaintext is encrypted at the end of the round?
Exercise 7.2
Select randomly six bits in a 64-bit block B and check that the permutation IP −1 (defined by Table 7.2) is the inverse of the
initial permutation IP (defined by Table 7.1).
Exercise 7.3
What is the probability that DES encryption maps a plaintext x to a ciphertext y for a given key? For all keys?
Exercise 7.4
One property of DEA that makes TDEA secure is that the selection functions SFi , i∈ 1, 8 , are nonlinear. Use the following
three pairs of inputs and show that SF2 ( x1 ) ⊕ SF2 ( x 2 ) ≠ SF2 ( x1 ⊕ x2 ) ; i.e. show that SF2 is nonlinear.
– x1 = 1111112 and x 2 = 0000002
– x1 = 1101102 and x 2 = 0010012
– x1 = 1110002 and x 2 = 0001112
Exercise 7.5
1) What is the output of the first round of DEA when the plaintext and the key are both all zeros?
2) What is the output of the first round of DEA when the plaintext and the key are both all ones?
Exercise 7.6
What do you get if you left-rotate by one position the last two 28-bits blocks, i.e. C16 and D16 , in the key schedule function?
Exercise 7.7
Show that SubBytes and ShiftRows transformations of AES can be applied in either order with the same result.
Exercise 7.8
What is the output of the first round of AES when the plaintext block and the cipher key are both of a value of 1(128) ; i.e. all
bits are 1s?
Problem 7.1
Recall that, in a round i of Feistel network, the input is a pair of halves Li−1 and Ri−1 and a round key K i ; and the output is
a pair of halves Li and Ri , defined by Li = Ri−1 and Ri = Li−1 ⊕ F ( Ri−1 , K i ). Prove that no matter what the function F is, the
round transformation is one-to-one, i.e. we can recover the old state ( Li−1 , Ri−1 ) from the new state ( Li , Ri ) and the round-
key K i .
Problem 7.2
Prove the correctness of Feistel encryption and decryption assuming that the number of rounds is 1 or 2.
Problem 7.3
Prove the correctness of Feistel cipher for an arbitrary number of rounds.
Problem 7.4
Prove the correctness of TDEA, i.e. the decryption a ciphertext block yields the original plaintext block.
Problem 7.5
1) Prove the following property called complementation property of DES:
C = E(K, M ) ⇒ C = E(K, M )
where x is the bit-by-bit complementation of bit-string x.
236 7 Block Ciphers: Basics, TDEA, and AES
2) Explain how the complementation property of DES can be used to reduce the computation time of a brute-force attack
against a DES key by about a factor of 2, if the adversary knew two plaintext–ciphertext pairs, ( M1 , C1 ) and ( M 2 , C2 ),
such that M 2 = M1 , C2 = C1 , C1 = E ( K , M1 ), C2 = E ( K , M 2 ). Assume that only encryption and decryption operations
are time-consuming.
Problem 7.6
1) Show that if all the round keys of DEA are identical, encrypting twice a plaintext B results in the plaintext B;
i.e. E ( K , E ( K , B )) = B.
2) Discuss why the following DEA keys are weak and should be avoided Key1 = 0101 0101 0101 0101 16 and
Key2 = FEFE FEFE FEFE FEFE16.
Problem 7.7
Let Key1 = 011F 011F 010E010E16 and Key2 = 1F 011F 010E010E0116 be a pair of DEA keys.
1) How many distinct round keys are generated for both keys?
2) Show that ( Key1 , Key2 ) is a pair of semi-weak keys, i.e. for any plaintext M, E ( Key1 , E ( Key2 , M )) = M .
Problem 7.8
In the DEA key scheduling function, after dropping odd parity bits, 56 bits are used to generate 48-bit round keys. Thus, at
each iteration, eight bits of the key are not used. Identify which key bits are not used to generate the first round key.
Problem 7.9
In this problem, we discuss the success probability of the meet-in-the-middle attack against double-DES described in
Section 7.2.3.3.
1) What is the probability of false alarm with a single known plaintext–ciphertext pair ( P1 , C1 )?
2) To increase the success probability of the attack, consider the following strategy: i) The first plaintext–ciphertext
pair ( P1 , C1 ) yields a set of key pair candidates, denoted S.
ii) A second plaintext–ciphertext pair ( P2 , C2 ) also is known and it is tested, but only the key pair candidates in S are used.
What is the false alarm probability with two known plaintext–ciphertext pairs?
3) What is the false alarm probability with three known plaintext–ciphertext pairs?
Problem 7.10
Using the matrix forms of construction of S-Box and InvS-Box, prove that InvSubBytes(SubBytes(S))= S, for any
state S.
Problem 7.11
1) Prove that 0 b 16 x 3 + 0d 16 x 2 + 09 16 x + 0e 16 is the inverse of 03 16 x 3 + 01 16 x 2 + 01 16 x + 02 16 mod ( x 4 + 1), with
coefficients in F28 .
2) Using the matrix form, prove that InvMixColumns is the inverse of MixColumns.
Exercise 7.1
Operations performed in the first round are LE1 = RE0 and RE1 = LE0 ⊕ F ( RE0 , K1 ) .
The right half is used in the round function F , but it does not change and it is directly copied in the left part of the input
to the second round.
The left half is XORed with the output of the round function F and the transformation result is copied in the right part
of the input to the second round. Therefore, only the left part of the plaintext is encrypted in the first round.
Exercise 7.2
Let B, B ′ , and B ′′ be 64-bit blocks presented as vectors of bits B 1 : 64 , B ′ 1 : 64 , and B ′′ 1 : 64 . Let B ′ = IP ( B ) and
B ′′ = IP −1 ( B ′). We need to check that B ′′ = B.
Consider six bits randomly selected: B 1, B 5 , B 21, B 49 , B 52 , B 63 .
Computation of B ′ = IP ( B ) yields:
B ′ 1 = B 58 B ′ 5 = B 26 B ′ 21 = B 30
7.4 Exercises and Problems 237
= 110110001101100011011011101111002
Therefore, the output of round 1 is:
L1 = R0
R1 = L0 ⊕ f (0, 0) = 110110001101100011011011101111002
= D8 D8 DBBC16
2) Let B = 1(64 ) and K = 1(54 ) be a plaintext and a key; both are all 1-bit strings.
Applying the initial permutation to B yields a 1(64 ) bit string. Therefore, the input of the first round is the same than B;
i.e. L0 = 1(32) and R0 = 1(32).
If the DEA key is 1(54 ) , then the key scheduling function yields 16 identical round keys, which are all equal to 1( 48) .
Application of the function F with R0 = 1(32) and a round key K1 = 1( 48): first the expansion key yields a 1( 48) bit-string;
second, Exp( R0 ⊕ K1 ) = 0 ( 48); thus, the input of all the selection functions is 1(6); thus, all of them yield the first element
of their tables: SF1 (0) = 14, SF2 (0) = 15, SF3 (0) = 10, SF4 (0) = 7, SF5 (0) = 2 SF6 (0) = 12, SF7 (0) = 4, SF8 (0) = 13. Notice
that f (1(32) ,1( 48) ) is the same than f (0 (32) , 0 ( 48) ).
238 7 Block Ciphers: Basics, TDEA, and AES
Therefore, the output of round 1 is: L1 = 1(32) and R1 = 1(32) ⊕ f (1(32) , 1( 48) ) = 00100111001001110010 0100010000112
= 2727244316 .
Exercise 7.6
All blocks Ci and Di, i = 1, ..., 16, used in the key schedule function are 28-bit blocks. NLR (Table 7.8) vector determines the
number of positions to rotate both Ci and Di for each round i. At 16th round, the value of C16 (resp. D16 ) is the initial value
C0 (resp. D0 ), which has been left-rotated by a total number of positions equal to the sum of elements of vector NLR (i.e.
4 * 1 + 12 * 2 = 28). Thus, if you left-rotate C16 (resp. D16 ) by one position, you get C1 (resp. D1). Notice that C0 = C16 and
D0 = D16.
Exercise 7.7
Let Sb( Sr ,c ) denote the substitution of byte Sr ,c (i.e. the byte of state S at row r and column c) using the S-Box. The result of
ShiftRows (SubBytes (S)) is given on the left of Figure 7.17 and that of SubBytes(ShiftRows(S)) on the right.
The results are the same. Thus, SubBytes and ShiftRows can be applied in either order in the AES encryption.
Exercise 7.8
1) The plaintext and cipher key are both of a value of 1(128) ; therefore, the key expansion function yields the following two
first round keys:
Key of initialization, K 0 = (W [0], W [1], W [2], W [3]), where W [0] = W [1] = W [2] = W [3] = [FF , FF , FF , FF ]
Key of the first round, K1 = (W [4], W [5], W [6], W [7]) computed as follows:
W [4] = W [0] ⊕ g (W [3]) , where g (W [3]) is yielded by three operations:
Therefore, we can recover Li−1 and Ri−1 if we know Li, Ri , and K i , for any function F .
Problem 7.2
Feistel cipher is correct, if Dec ( Enc ( B )) = B , where B denotes a plaintext block.
1) Number of rounds n = 1
B = ( LE0 , RE0 ) ; B is the plaintext, which is divided into two equal-size halves, LE0 and RE0.
Encryption
Round 1:
LE1 = RE0; RE1 = LE0 ⊕ F ( RE0 , K1 )
The ciphertext is C = RE1 || LE1
Decryption
C = ( LE0 ⊕ F ( RE0 , K1 )) || ( RE0 ) is the ciphertext
Divide C into two equal-size halves: C = (( LE0 ⊕ F ( RE0 , K1 )), ( RE0 ))
LD1 = RD0 = RE0
RD1 = LD0 ⊕ F ( RD0 , K1 ) = LE0 ⊕ F ( RE0 , K1 ) F ( RE0 , K1 ) = LE0
RD1 || LD1 = B. Therefore, the decryption produces the original plaintext block.
2) Number of rounds n = 2
B = ( LE0 , RE0 ) ; B is the plaintext divided into two equal-size halves.
240 7 Block Ciphers: Basics, TDEA, and AES
Encryption
Round 1:
LE1 = RE0 ; RE1 = LE0 ⊕ F ( RE0 , K1 )
Round 2:
LE2 = RE1 = LE0 ⊕ F ( RE0 , K1 )
RE2 = LE1 ⊕ F ( RE1 , K 2 ) = RE0 ⊕ F ( LE0 ⊕ F ( RE0 , K1 ), K 2 )
The result of the last decryption round is ( RE0 , LE0 ). Then, swapping the two halves yields ( LE0 , RE0 ), which is the original
plaintext. □
Problem 7.4
First, we address the correctness of DEA. Recall that DEA encryption and decryption are based on a Feistel network of 16
rounds. Let the 16-round Feistel network be modeled as a function F that takes a 64-bit block and a set of 16 round keys;
and it yields an output of the same bit-length. DEA encryption and decryption can be written using the function F as
follows:
Encryption: E ( K , p) = c = IP −1 (F (KE , IP ( p))) (a)
−1
Decryption: D( K , c ) = p = IP (F (KD , IP (c ))) (b)
where KE = { K1 , K 2 , ..., K16 } is the set of the round keys yielded by the key schedule function, using the key K; and KD is
the reverse set of KE ; KD = { K16 , K15 , ..., K1 }.
F is proven to be correct (see the solution to Problem 7.3). Therefore, if KE is a set of 16 round keys and KD is its reverse,
then:
64 64
F (KE , x ) = y ⇒ F (KD , y ) = x , for any ( x , y ) ∈ {0,1} ×{0,1} (c)
Making substitution of (a) in (b) and using (c):
( ( ( (
D ( K , c ) = IP −1 F KD , IP IP −1 F (KE , IP ( p)) ))))
( ( ))
= IP −1 F KD , F (KE , IP ( p)) = IP −1 ( IP ( p)) = p
By TDEA construction:
ETDEA (( Key1 , Key2 , Key3 ), p) = E ( Key3 , D( Key2 , E ( Key1 , p)))
DTDEA (( Key1 , Key2 , Key3 ), c ) = D( Key1 , E ( Key2 , D( Key3 , c )))
(
D Key1 , E ( Key2 , D ( Key3 , c )) )
( (
= D Key1 , E Key2 , D ( Key3 , E ( Key3 , c2 )) ))
(
= D ( Key1 , E ( Key2 , c2 )) = Key1 , E ( Key2 , D ( Key2 , c1 )) )
= D ( Key1 , c1 ) = D ( Key1 , E ( Key1 , p)) = p
Problem 7.5
1) Proof of the complementarity property of DES
We need the following lemma.
Lemma: for any pair of n-bit strings, x and y, the following holds:
x ⊕ y = x ⊕ y and x ⊕ y = x ⊕ y .
Proof: let 1(n ) denote a bit string with n 1-bits.
By definition of the bit-by-bit complementation (denoted 1-complement):
x ⊕1(n ) = x and x ⊕1(n ) = x .
x ⊕ y = x ⊕ y ⊕ (1(n ) ⊕ 1(n ) ) = (( x ⊕ 1(n ) ) ⊕ y ) ⊕ 1(n )
□
= ( x ⊕ y ) ⊕1(n ) = x ⊕ y
x ⊕ y = x ⊕ y ⊕ (1(n ) ⊕ 1(n ) ) = ( x ⊕1(n ) ) ⊕ ( y ⊕ 1(n ) ) = x ⊕ y .
242 7 Block Ciphers: Basics, TDEA, and AES
After the final permutation, the output of E ( K , M ) is ( R16 , L16 ) , which is the 1-complement of E ( K , M ) = ( R16 , L16 ). There-
fore, we can conclude that:
C = E ( K , M ) ⇒ C = E ( K , M ) □
2) In general, when the naïve brute-force attack is applied against DES, the adversary, who knew a plaintext–ciphertext
pair ( M , C ), needs to test each of the 256 keys to find a key, which matches the known pair. In this problem, we assume
that the adversary knew two plaintext–ciphertext pairs, ( M1 , C1 ) and ( M 2 , C2 ), such that M 2 = M1 and C2 = C1 ; i.e.
C2 = E ( K , M 2 ) = E ( K , M1 ) = C1 = E ( K , M1 ).
By the complementation property, which states that C = E ( K , M ) ⇒ C = E ( K , M ),
C2 = E ( K , M 2 ) = E ( K , M 2 ) = E ( K , M1 ) (a)
Let’s see the attack that takes advantage of the complementation property. The adversary tries all the 255 keys whose left-
most bit is 0 (notice that the other 255 keys are 1-complement of the tried keys). Let K ′ be one of the tried keys. The adversary
makes an encryption, C = E ( K ', M1 ). If C1 = C , then K ′ is likely to be the real key K. Otherwise, if C2 = C , then, by the
double equality (a), K ′ is likely to be the 1-complement of the real key K, i.e. K ′ = K, because C2 = E ( K , M1 ) = E ( K ′, M1 ).
If neither K ′ nor K ′ can be the real key K, another key is picked and tested as above. We mentioned “likely to be the real
key,” because false alarm may occur. Indeed, because the DES key space is of 256 and the ciphertext space is of 264, the
same ciphertext may be yielded by more than one key. In particular, we may have C = E ( K ′, M1 ) = E ( K ′′, M1 ), while K ′
and K ′′ are two distinct keys. To reduce the probability of false alarm, more than two plaintext–ciphertext pairs should
be used. In conclusion, the complementation property of DES reduces the maximum number of encryptions to 255 .
Problem 7.6
1) The algorithms of DEA encryption and decryption are the same with the exception of the use of the round keys. In the
encryption, the rounds keys are used from k1 to k16 , while they are used in the inverse order, from k16 to k1, in the decryption.
If all the round keys are identical, the order does matter. Therefore, encrypting E ( K , B ) is equivalent to a decryption. Hence,
E ( K , E ( K , B )) = B. Notice that decrypting twice a ciphertext C results in the ciphertext C, i.e. D( K , D( K , C )) = C.
2) Take key1 = 0101 0101 0101 010116 and drop the odd11 parity bits. The resulting 56-bit key is Key1(56) = 00 0000 0000 000016.
Since all the bits of the input are 0 s in key schedule function, all the generated round keys are also 0 s. Permutation, rotation,
and compression of s yield only 0 s.
Take Key2 = FEFE FEFE FEFE FEFE16 and remove the odd parity bits. The resulting 56-bit key is and
Key2(56) = FF FFFF FFFF FFFF16. Since all the bits of the input are s, in key schedule function, all the generated round
keys are also 1 s. Permutation, rotation, and compression of 1 s yield only 1 s. Taking into account the answer to the
first question, both keys are weak and should be avoided, because an attacker can try all weak keys to decrypt twice an
intercepted ciphertext and recover the key if the result is the same after two decryptions.
7.4 Exercises and Problems 243
Problem 7.7
1) In the first step of the key schedule function, applying permutation PC-1 to Key1 = 011F 011F 010E010E16 yields two
28-bits blocksC0Key1 = 000000016and D0Key1 = AAAAAAA16; and applying permutation PC1to Key2 = 1F 011F 010E010E0116
yields two 28-bits blocks and D0Key2 = 555555516.
First, after left rotation of C0Key1 and C0Key2 both remain unchanged, because both are equal to a 28 0-bit string.
Second, since A16 = 10102 and 516 = 0101, left-rotating D0Key1 or D0Key2 yields either AAAAAAA16 or 555555516:
LeftRotate(555555516 ,1) = AAAAAAA16
LeftRotate( AAAAAAA16 ,1) = 555555516
LeftRotate(555555516 , 2) = 555555516
LeftRotate( AAAAAAA16 , 2) = AAAAAAA16
In the last step of the key schedule function, only two distinct round keys can be generated, i.e.
K (1) = PC 2(0000000555555516) or K (2) = PC 2(0000000 AAAAAAA16 ).
Using the number of rotation positions given in vector (Table 7.8), the 32 round keys derived from Key1 and Key2 are:
RoundKeys ( Key1 ) = ( K (1) , K (2) , K (2) , K (2) , K (2) , K (2) , K (2) , K (2) ,
K (1 ) , K (1 ) , K (1 ) , K (1 ) , K (1 ) , K (1 ) , K (1 ) , K ( 2 ) )
RoundKeys ( Key2 ) = ( K (2) , K (1) , K (1) , K (1) , K (1) , K (1) , K (1) , K (1) ,
K ( 2 ) , K ( 2 ) , K ( 2 ) , K ( 2 ) , K ( 2 ) , K ( 2 ) , K ( 2 ) , K (1 ) )
2) Recall that the algorithms of DEA encryption and decryption differ only in the order in which the round keys are used.
Let K i , i = 1, ..., 16 be the round keys generated by the key schedule function from a key Key. The encryption algorithm
makes use of K1 in the 1st round, …, and K16 in the 16th round, while the decryption algorithm makes use of K16 in the
1st round, …, and K1 in the 16th round. In the answer to question 1, the list of round keys generated from Key1 is the
reverse of that generated from Key2 . Therefore, encrypting C = E ( Key2 , M ) using Key1 is equivalent to decrypting C with
Key2 ; i.e. E ( Key1 , E ( Key2 , M )) = D( Key2 , E ( Key2 , M )) = M , for any plaintext M.
Problem 7.8
Using Table PC1, we build the first two 28-bit blocks, C0 and D0 , used to generate the round keys. Let K j denote the bit
j, j = 1, ..., 64 of the key K (“64”, because the key scheduling function starts with a 64-bit key and then drops odd parity bits).
C0 = K 57 K 49 K 41 K 33 K 25 K 17 K 9 K 1 K 58 K 50 K 42 K 34 K 26 K 18
K 10 K 2 K 59 K 51 K 43 K 35 K 27 K 19 K 11 K 3 K 60 K 52 K 44 K 36
D0 = K 63 K 55 K 47 K 39 K 31 K 23 K 15 K 7 K 62 K 54 K 46 K 38 K 30 K 22
K 14 K 6 K 61 K 53 K 45 K 37 K 29 K 21 K 13 K 5 K 28 K 20 K 12 K 4
C0 and D0 are concatenated to form a 56-bit block. The inspection of Table PC2 shows that at any round i, i = 1, ..., 16, the
following bits are not used to generate the round key K i : bits 9, 18, 22, and 25, located in C0; and bits 35, 38, 43, and 54,
located in D0 (because all those eight numbers are not included in Table PC2).
The first round key, K1, is computed as follows: C0 and D0 are one-bit-left-rotated to yield C1 and D1, which are concatenated
and used in the compression permutation. Therefore, the key bits that are not used to generate K1 are: K 50, K 43, K 11,
K 52, K 7 , K 46, K 6 , and K 12 .
Problem 7.9
1) With a key bit-length of 56, there exist 256 * 256 pairs of keys ( K i , K j ); i, j ∈ 0, 256 − 1 . Each pair is used to double-encrypt.
64
We can do 2112 double encryptions, but the final ciphertext is an element in {0,1} . Thus, in average, each element of
2112
the ciphertext space can be yielded by 64 = 248 pairs. The probability to pick the real key pair is 1 / 248. Therefore, the
2
probability of false alarm is 1 − 1 / 248, which is a very high probability.
244 7 Block Ciphers: Basics, TDEA, and AES
2) With a space of key pairs of 248 pairs, a maximum of 248 ciphertexts may be yielded. Thus, in average, the number key
248
pairs, selected in the previous step, that encrypt the same plaintext to the same ciphertext is 64 = 2−16; this probability
2
is also the probability of false alarm. In other words, with two known plaintext-ciphertext pairs, the probability to find
the real key pair is 1 − 2−16 ≈ 1.
3) With three known plaintext-ciphertext pairs, the probability that three ciphertexts are yielded by the same key pair
2−16
is 64 = 2−80. The latter is the probability of false alarm. In conclusion, three known plaintext-ciphertext pairs are
2
enough to break double DES.
Problem 7.10
In SubBytes and SubBytes transformations, byte substitution is performed byte-by-byte, independently from each
other. Therefore, to prove that InvSubBytes is the inverse of SubBytes, we need to prove that InvS_Box ( S_Box (b)) = b
for any byte b. We use the matrix forms of substitution; i.e. (7.2) and (7.4):
b ′ = S_Box (b) ⇒ b ′ = A ∗ b ⊕ c , where c = [63]16
x = InvS_Box (b ′) ⇒ x = B ∗ b ′ ⊕ d , where d = [05]16
Then, by substitution: x = B ∗ ( A ∗ b ⊕ c ) ⊕ d = (( B ∗ A) ∗ b) ⊕ ( B ∗ c ) ⊕ d
It is easy to check that B ∗ A is the identity matrix.
Then, by substitution: x = b ⊕ ( B ∗ c ) ⊕ d
As shown below, ( B ∗ c ) ⊕ d = 0. Therefore, x = b, which confirms that InvS_Box ( InvS_Box (b)) for any byte b.
B c B∗c d B∗c⊕d
0 0 1 0 0 1 0 1 1 1 1 0
1 0 0 1 0 0 1 0 1 0 0 0
0 1 0 0 1 0 0 1 0 1 1 0
1 0 1 0 0 1 0 0 0 0 0 0
= ⊕ =
0 1 0 1 0 0 1 0 0
0
0
0
0 0 1 0 1 0 0 1 1 0 0 0
1 0 0 1 0 1 0 0 1 0 0 0
0 1 0 0 1 0 1 0 0 0 0 0
Problem 7.11
( )( ) ( )
1) 0 b 16 x 3 + 0d 16 x 2 + 09 16 x + 0e 16 * 03 16 x 3 + 01 16 x 2 + 01 16 x + 02 16 mod x 4 + 1
( )
= ( 0 b 16 i 03 16 ) x 6 + 0 b 16 i 01 16 ⊕ 0d 16 i 03 16 x 5
( )
+ 0 b 16 i 01 16 ⊕ 0d 16 i 01 16 ⊕ 09 16 i 03 16 x 4
( )
+ 0 b 16 i 02 16 ⊕ 0d 16 i 01 16 ⊕ 09 16 i 01 16 ⊕ 0e 16 i 03 16 x 3
( )
+ 0d 16 i 02 16 ⊕ 09 16 i 01 16 ⊕ 0e 16 i 01 16 x 2
(
+ 09 16 i 02 16 ⊕ 0e 16 i 01 16 x)
( )(
+ 0e 16 i 02 16 mod x 4 + 1 )
( )
= 0 b 16 i 02 16 0d 16 i 01 16 09 16 i 01 16 0e 16 i 03 16 x 3
( )
+ 0d 16 i 02 16 ⊕ 09 16 i 01 16 ⊕ 0e 16 i 01 16 ⊕ 0b 16 i 03 16 x 2
( )
+ 09 16 i 02 16 ⊕ 0e 16 i 01 16 ⊕ 0 b 16 i 01 16 ⊕ 0d 16 i 03 16 x
( )
+ 0e 16 i 02 16 ⊕ 0 b 16 i 01 16 ⊕ 0d 16 i 01 16 ⊕ 09 16 i 03 16
( ) ( )
= 16 16 ⊕ 0d 16 ⊕ 09 16 ⊕ 12 16 x 3 + 1a 16 ⊕ 09 16 ⊕ 0e 16 ⊕ 1d 16 x 2
( )
+ 12 16 ⊕ 0e 16 ⊕ 0 b 16 ⊕ 17 16 x
( )
+ 1c 16 ⊕ 0 b 16 ⊕ 0d 16 ⊕ 1b 16
= (0) x + (0) x + (0) x + 1 = 1 mod ( x 4 + 1)
3 2
Notes 245
4
Therefore, 0 b 16 x 3 + 0d 16 x 2 + 09 16 x + 0e 16 is the inverse of 03 16 x 3 + 01 16 x 2 + 01 16 x + 02 16 mod ( x + 1)
with computations in the extension field F28 .
2) Let A and B be the matrices defined by (7.5) and (7.6). Using the matrix form of the MixColumns transformation, for any
4-byte column c, c ′ = MixColumns (c ) can be written as c ′ = A ∗ c and d = InvMixColumns(c ′) can be written as d = B ∗ c ′.
Hence, d = ( B ∗ A) ∗ c. Let D be the product of matrices B by A.
0e 0b 0d 09 02 03 01 01
09 0e 0b 0d 01 02 03 01
D = B * A =
0d 09 0e 0b 01
01 02 03
0b 0d 09 0e 03 01 01 02
Hence, B *A is the identity matrix and therefore, d = B * A * c = c , which confirms that InvMixColumns is the inverse
of MixColumns.
Notes
1 Feistel structure notion was proposed in 1973 by Horst Feistel and Don Coppersmith and implemented in Lucifer cipher.
2 In literature, there exist other equivalent descriptions of Feistel decryption, which perform computations in the inverse
order, i.e. from i = n to i = 0 and start with round key K 0.
3 DEA is also referred to as the algorithmic design of DES.
4 US patent n° 3962539, which describes DES, was assigned to IBM Corporation in 1976. This patent expired in 1993.
5 Do not confuse 2TDEA with 2DES. The latter uses only two encryptions (or decryptions) in sequence.
6 Rijndael is a contraction of Rijmen and Daemen, the authors of Rijndael algorithm.
7 Nk denotes the number of 32-bit words of the key. That is, Nk = 4, 6, and 8 to denote keys of 128, 192, and 256 bits,
respectively.
8 In the matrix forms discussed in the chapter, the usual addition is replaced by the XOR operation.
9 SubBytes and its inverse are the only non-linear transformation in AES.
10 “Indexed by a” means “a is split into two 4-bit halves to yield the indexes of a cell in the S-Box.”
11 Odd parity works as follows: for a given set of bits, if the count of bits with a value of 1 is even, the parity bit value is set to 1
making the total count of s in the entire set (including the parity bit) an odd number. If the count of bits with a value of 1 is
odd, the count is already odd; hence, the parity bit value is 0.
246 7 Block Ciphers: Basics, TDEA, and AES
References
1 Shannon, C. (1949). Communication theory of secrecy systems. Bell System Technical Journal 28: 656–715.
2 Barker, E. and Mouha, N. (2017). Recommendation for the Triple Data Encryption Algorithm (TDEA) Block Cipher - Special
publication 800-67 (Rev. 2). NIST.
3 NIST. (1999). Data Encryption Standard (DES) - FIPS publication 46-3. National Institute for Standards and Technology.
4 Biham, E. and Shamir, A. (1991). Differential cryptanalysis of DES-like cryptosystems. Journal of Cryptology 4 (1): 3–72.
5 Matsui, M. (1993). Linear cryptanalysis method for DES cipher. International Workshop on the Theory and Application of
Cryptographic Techniques, Advances in Cryptology, 386–397. Lofthus, Norway: Springer, LNCS 765.
6 NIST. (2001). Advanced Encryption Standard (AES) - FIPS PUB 197. National Institute for Standards and Technology.
7 Deamen, J. and Rijmen, V. (2002). The Design of Rijndael: AES – The Advanced Encryption Standard. Springer.
8 Ashokkumar, C., Giri, R., and Menezes, B. (2016). Highly efficient algorithms for AES key retrieval in cache access attacks.
IEEE European Symposium on Security and Privacy, 261–275. Saarbrucken, Germany: IEEE Xplore.
247
In the previous chapter, two standard block ciphers, namely TDEA and AES, have been presented. A block cipher takes a
fixed-size plaintext block and returns a ciphertext block of the same size. However, in many applications, a plaintext (for
example an image) is composed of thousands of blocks or even more. It is not desirable to use a block cipher in such a way
that the encryption of the individual plaintext blocks leaks some features about the whole plaintext. In addition, in many
applications, the recipient of a message may need to authenticate the message sender.
Data protection refers to confidentiality of data in transit (i.e. data exchanged via a communication network) and data on
storage devices (such as CD-ROMs and USB flash drives). Like messages that may be intercepted, while being transmitted
form sender to recipient, storage devices may be stolen or copied, which would result in disclosing confidential data. In
addition, the advent of storage area networks has made storage devices, which are directly connected to servers, vulnerable
to attacks. Therefore, protecting storage devices is (often) required. Such a protection is commonly achieved using block
ciphers. Overall, encryption of data on storage devices aims at providing: data confidentiality, fast data storage and retrieval,
and optimization of storage space.
It should be noticed that the protection of data in transit (i.e. messages) and that of data on storage devices differ, which
results in important implications for encryption, even though the core encryption algorithms are the same:
● Latency: message transmission is ephemeral, while data storage is often used for a long time. In networks, the recipient
follows a protocol for key establishment and authentication before encrypting/decrypting messages. Attacks against
messages need that the attacker is present when messages are transmitted, while attacks against storage devices do not.
● Key management: in networks, the encryption key changes from a message to another. Even the public key used for sig-
nature is renewed periodically. If a key is lost, the participants run a protocol to agree on a new key. In case of storage, if
the encryption key is lost, the entire encrypted data is lost.
With the exception of one mode (XTS-AES), the modes of operation presented in this chapter can be used directly to protect
messages or, with some adaptions, to protect data on storage devices. This chapter addresses the standard approaches to
use block ciphers to encrypt and decrypt plaintexts, while considering plaintexts of a size longer than that of a single block.
It is worth noticing that encryption alone provides confidentiality guarantees but not data integrity guarantees. Indeed,
in the event an adversary alters a message or the storage device content, the decryption operation cannot detect any alter-
ation. Therefore, message authentication codes or other techniques are required to preserve data integrity. Modes of oper-
ation that provide data authenticity are addressed in the next chapter
8.1 Introduction
8.1.1 Definitions
Definition 8.1 Mode of operation of block cipher: it describes how to repeatedly apply a single-block cipher to provide
confidentiality or authenticity. Alternatively, modes of operation are ways of using block ciphers for encrypting and decrypting
multiple-block data or for providing authentication service.
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
248 8 Block Cipher Modes of Operation for Confidentiality
Definition 8.2 Deterministic encryption: given a key, an encryption is said to be deterministic if plaintext blocks with the
same content are mapped to a same ciphertext block.
Definition 8.3 Probabilistic encryption: given a key, an encryption is said to be probabilistic if any two plaintext blocks are
(very likely) mapped to distinct ciphertext blocks [1].
Figure 8.1 Block cipher modes of operations. (*) Poly1305-AES is not yet approved as a block cipher mode of operation. (**)
ChaCha20 is a stream cipher, not a block cipher.
8.2 ECB Mode of Operation 249
x :the least integer that is not less than the real number x.
x : the greatest integer that is not greater than the real number x.
X || Y : concatenation of bit strings X andY .
X ⊕ Y : bitwise exclusive-OR of bit strings X andY of the same length.
x : binary representation of integer x in s bits, where 0 ≤ x < 2 s .
s
0 s : bit string of s “0” bits.
MSBd ( X ) : bit string consisting of the d leftmost bits of the bit string X (i.e. most significant d bits).
In the Electronic Codebook2 (ECB) mode, the encryption and decryption operations are applied independently to each
block (see Figure 8.2). ECB mode is the simplest mode of operation.
250 8 Block Cipher Modes of Operation for Confidentiality
C1 = Enc K ( Bi ⊕ IV )
Ci = Enc K ( Bi ⊕ Ci−1 ), ∀ i, 2 ≤i ≤m
B1 = Dec K (C1 ) ⊕ IV
Bi = Dec K (Ci ) ⊕ Ci−1 , ∀ i, 2 ≤i ≤m
Unlike ECB, in CBC and in other modes of operation, blocks with the same content are encrypted with distinct ciphertexts.
In CBC, the encryption cannot be performed in parallel, but decryption can be. Indeed, when all ciphertext blocks are
received, the recipient can perform parallel computations on them to recover the plaintext blocks.
CBC is not fully error-propagation free, because the decryption of ciphertext block i makes use of two ciphertext blocks i
and i −1. In case some bits of ciphertext block i are altered, plaintext blocks i and i +1 cannot be recovered, but plaintext
blocks with index greater than i +1 can be recovered correctly. CBC mode requires an initialization vector known to sender
and recipient. In addition, the IV value should be unpredictable.
8.3 CBC Modes of Operation 251
blocks are complete ones. With the ciphertext stealing technique, the ciphertext and the plaintext are of the same bit-
length. The encryption and decryption of complete blocks ( B1 , …, Bm−2 ) and (C1 , …, Cm−2 ) are the same as in the basic
CBC. CS variants differ only in how they order and process the two last ciphertext blocks Cm−1 and Cm. Ciphertext steal-
ing has no impact on security and block ordering is only used for implementation convenience. If len ( B ) is a multiple of
the block length b, then all three variants are equivalent to the basic CBC.
Note. In line 3 (of decryption), b − d bits are taken from the decryption of Cm to rebuild Cm−1. Hence, the idea of ciphertext
stealing.
If len (Cm−
*
1 ) < b , then C = C1 || C2 || … || Cm || Cm−1 .
*
8.5 CTR Mode of Operation 253
OFB, CTR, and CFB modes of operation function like stream ciphers. Therefore, all of them use the same function to
encrypt and decrypt. They do not directly encrypt the plaintext using the key. Instead, they compute a bit string, which is
XORed with the plaintext block. The first plaintext block is XORed with the encrypted IV. Then, the latter is encrypted to
produce a bit string, which is XORed with the second plaintext block, etc. (see Figure 8.5). OFB mode requires that the IV
is a nonce.
OFB mode does not require padding. Indeed, if the last plaintext block is of bit-length u less than b (the block length),
only the most significant u bits of the last ciphertext block are XORed with the plaintext block and the least significant b − u
bits are discarded. The same applies to decrypt if the last ciphertext block is of a length less than b. Such an operation is
identical to that of a stream cipher.
Formally, the OFB mode is defined with the following equations:
Encryption: Decryption:
I1 = IV I1 = IV
I j = O j−1 , ∀ j, 2 ≤ j ≤ m I j = O j−1 , ∀ j, 2 ≤ j ≤ m
O j = Enck ( I j ), ∀ j, 2 ≤ j ≤ m O j = Enck ( I j ), ∀ j, 2 ≤ j ≤ m
C j = Bj ⊕ Oj, ∀j, 2 ≤ j ≤m −1 Bj = C j ⊕ Oj, ∀j, 2 ≤ j ≤m −1
Cm = Bm ⊕ MSBu (Om ), u = len ( Bm ) Bm = Cm ⊕ MSBu (Om ), u = len (Cm )
With the exception of the first plaintext block, the encryption of a plaintext block depends on the encryption of the previous
plaintext block. The same applies to decryption. Therefore, neither encryption nor decryption of blocks can be performed
in parallel.
Like EBC, OFB mode is error-propagation free, because one ciphertext block is used to recover one plaintext block and
ciphertext blocks are not recalculated at recipient. Only the plaintext block associated with the altered ciphertext block
cannot be recovered.
CTR mode is similar to OFB mode with the exception that a counter is used instead of an initialization vector (see Figure
8.6). In CTR, it is required that each plaintext block is encrypted with a distinct counter.
One advantage of CTR over OFB is that encryption and decryption of distinct blocks can be performed in parallel.
Formally, the OFB mode is defined by the following equations, where Cnt1 , Cnt2 , …, Cntm denote the values of the counter:
254 8 Block Cipher Modes of Operation for Confidentiality
Encryption: Decryption:
O j = Enck (Cnt j ), ∀j, 1≤ j ≤ m O j = Enck (Cnt j ), ∀j, 1≤ j ≤ m
C j = Bj ⊕ Oj, ∀j, 1≤ j ≤ m −1 Bj = C j ⊕ Oj, ∀j, 1≤ j ≤ m −1
Cm = Bm ⊕ MSBu (Om ), u = len ( Bm ) Bm = Cm ⊕ MSBu (Om ), u = len (Cm )
Counter values can be generated by any function that returns a distinct value for each call. In addition, it is required that
all counter values must be distinct for all messages encrypted with the same key. To fulfill the uniqueness of counter values
used with a specific key, there exist several methods, including:
● Sequential assignment of counter values, which is defined as follows:
– Cnt11 = random()
– Cntij = Cntij−1 + 1 mod 2b , for i = 2, …, m j , j = 1, …, L
– Cnt1j = Cntmj−1 + 1 for j = 2, …, L
j−1
where Cnt11 denotes the first randomly selected counter value to use with a new key, Cnt1j the first counter value to use
for message j, Cntij , the counter value to use for block i of message j, m j the number of blocks of message j, and L the
number of messages, respectively.
● Hybrid sequential assignment of counter values, which is defined as follows:
– Divide the counter bits into two parts of r and b − r bits, where r < b.
– Assign to each message j, a nonce nc j in the interval 0, 2r − 1 .
– Assign to each block i of message j a counter block Cntij as follows:
v1j = random() in 0, 2b−r − 1 , j = 1, …, L
vij = vij−1 + 1 mod 2b−r , for i = 2, …, m j, j = 1, …, L
8.6 CFB Mode of Operation 255
Like OFB, Cipher Feedback (CFB) mode operates as a stream cipher and makes use of an initialization vector and the
same algorithm for encryption and decryption. In CFB mode, a feedback between successive plaintext blocks is used as
in CBC mode, but in a different way (see Figure 8.7). CFB mode uses an initialization vector and a parameter s, which is
an integer less than (or equal to) the block length b. The IV used in CFB must be unpredictable. Often, the name of CFB
mode starts with the value of parameter s, such that 1 ≤ s ≤ b. For example, CFB-8 and CFB-64 denote CFB with s = 8 and
s = 64, respectively. CFB mode is said to be full-CFB if s = b (i.e. a block contains one and only one segment).
CFB operates on plaintext/ciphertext segments of length s and not on blocks of length b. To distinguish segments from
blocks, segments are upper-indexed with “#”. CFB does not directly encrypt (with operation Enc K ) the plaintext. Instead,
it uses a bitstring (which results from either the encryption of IV or a previous ciphertext) and XORes it with the plaintext
to get a ciphertext. Formally, CFB mode is defined by the following equations, where m_s denotes the number of segments
of the plaintext, LSBd ( x ) and MSBd ( x ) denote the d least and most significant bits of integer x, respectively:
Encryption: Decryption:
I1 = IV I1 = IV
I j = LSBb−s ( I j−1 ) || C #j−1, ∀j, 2 ≤ j ≤ m_s I j = LSBb−s ( I j−1 ) || C #j−1, ∀j, 2 ≤ j ≤ m_s
O j = Enc K ( I j ), ∀j, 1≤ j ≤ m_s O j = Enc K ( I j ) , ∀j, 1≤ j ≤ m_s
C #j = B #j ⊕ MSBs (O j ), ∀j, 1≤ j ≤ m_s B #j = C #j ⊕ MSBs (O j ) ∀j, 1≤ j ≤ m_s
,
256 8 Block Cipher Modes of Operation for Confidentiality
With the exception of the first block, in CFB mode, the encryption of a block depends on the previous one. Therefore, dis-
tinct blocks cannot be encrypted in parallel. However, once all the ciphertext blocks are received, the recipient can com-
pute the input blocks (I2 , I3 , …, Im_ s ) and then perform in parallel the decryption of ciphertext blocks.
Like CBC, CFB mode is not fully error-propagation free. In case a ciphertext block i is altered, plaintext blocks i and i + 1
cannot be recovered, but plaintext blocks with index greater than i +1 can be recovered correctly. It should be noticed that
CFB mode is the slowest mode because it processes a small portion of the data to encrypt/decrypt at each step. The number
of operations depends on segment size s.
Figure 8.8 FPE encryption vs other modes of encryption (e.g. AES or TDEA).
names are in clear) and an application needs to check the expiry date of client John Taylor. Since the encryption of distinct
fields are chained, it is required to decrypt a large portion of the file to retrieve the expiry date of interest, in most modes of
operations. That may take a long time to decrypt. With FPE modes, applications can easily locate ciphertext portions of
interest and decrypt only the required fields of data.
Currently, FF1 and FF3-1 modes are approved to be used only with AES block cipher with block length of 128 bits and
key lengths of 128, 192, or 256 bits.
Data representation. FPE modes are designed to be adapted for any type of data. The number of symbols (also called
characters) of an alphabet is called the base; it is denoted radix. The set of symbols7 of a base radix is {0, 1, 2, …, radix − 1}.
A numeral is a nonnegative integer less than the base and a numeral string is a finite ordered sequence of numerals of the
given base.
Example 8.1
– If radix = 8, then the set of characters is {0, 1, 2, 3, 4, 5, 6, 7} in decimal representation and {000, 001, 010, 011, 100,
101, 110, 111} in binary representation.
– If radix = 16, then the set of characters is {0, 1, 2, …, 14, 15} in decimal representation and {0, 1, 2, …, E, F } in hexadec-
imal representation.
– With radix = 16, X = 12 13 5 7 2 is a string of five numerals (i.e. 12, 13, 5, 7, and 2) in decimal representation.
– With radix = 210, X = 125 978 2 is a string of three numerals (i.e. 125, 978, and 2) in decimal representation.
For simplicity, in the sequel, we focus only on numeral data represented with decimal characters. Texts and special char-
acters should be converted into decimal symbols before applying FPE modes. For example, lower-case Latin letters may be
represented with numbers 1 to 26, upper-case letters with numbers 27 to 52, etc. Another representation would be the
well-known ASCII code.
The input data of FF1 and FF3-1 modes are numeral strings. If the base is greater than 10, then numerals of a string are
separated by space character. FF1 and FF3-1 use different conventions for interpreting numeral strings as numbers. For
FF1, numbers are represented by strings of numerals with decreasing order of significance (i.e. in big-endian); for FF3-1,
numbers are represented by strings of numerals in the reverse order, i.e. with increasing order of significance (i.e. in little-
endian). For example, “0125” is a string of decimal digits that represents the number “one hundred twenty-five” for FF1
and the number “five thousand two hundred ten” for FF3-1.
Tweak. To encrypt data, FPE modes make use of a secret key and a tweak. The latter does not need to be secret and intends
the same as an initialization vector in other modes. In CBC, OFB, and CFB modes, the IV is used to encrypt and decrypt the
first block. In FPE modes, the tweak8 is used inside a Feistel structure jointly with a key and can be regarded as a changeable
part of a cipher key. Block ciphers that make use of tweaks are referred to as tweakable block ciphers [6]. One application of
tweakable block ciphers is disk encryption, where each disc portion has an index, which is used as a tweak.
Encryption and decryption of FPE modes are based on Feistel structure presented in Section 7.1.2, with some adapta-
tions. Specifically, instead of XOR operations in basic Feistel structure, in FPE modes, the operations are addition and
subtraction modulo a power of the chosen base and the round function FK takes a key, the bit-length of the plaintext, the
tweak, and the round number.
258 8 Block Cipher Modes of Operation for Confidentiality
As shown in Figure 8.9, the encryption and decryption are transformations in three steps: 1) the input is split into two
parts A (left) and B (right) of lengths denoted u and v, respectively; 2) a keyed function is applied to one part of the input;
and 3) the two parts are swapped and used as input of the next round.
If the length of the plaintext is even, then u = v = len( B ) / 2. Otherwise, one half has one symbol more than the other.
u = (len( B ) − 1) / 2 and v = (len( B ) +1) / 2. The bit-lengths u and v are taken into account when swapping a half with the
other.
The number of rounds, denoted r, is of 10 for FF1 and of 8 for FF3-1. Inputs of round i (i = 0, …, r − 1) are denoted Ai and Bi .
Figure 8.9 Feistel structure for building FF1 and FF3-1 modes.
8.7 Format-Preserving Encryption Modes of Operation 259
● Numradix(x):integer that a numeral string x represents in base radix when numerals are in decreasing order of signifi-
cance. For example, Num8 (0100001) = 1 * 85 + 1 = 32769.
m
● Strradix (x): given a positive integer x less than radix m , this function returns a string of numerals in base radix. For example,
str164 (1957) = 07105, because 0 * 163 + 7 * 162 + 10 * 161 + 5 * 160 = 1957.
Figure 8.10 depicts the computations performed in each round of FF1 mode. The encryption algorithm of FF1 mode is as
follows:
Figure 8.10 Round computations in FF1 mode. FBd ( S ) denotes the first d bytes of string S.
260 8 Block Cipher Modes of Operation for Confidentiality
function FF1_Encryption
input K : key; T : tweak of length t bytes; t ∈ 0 .. maxTLen
X : plaintext, a string of n numerals in base radix
# n ∈ minLen .. maxLen
output Y : ciphertext of the same length than that of input X
1. # The input numeral string X issplitintotwohalvesA (left ) andB (right).
# If length of X is odd, then the right half has one numeral more than
# the left. A andB are strings of numerals
u = n / 2; v = n − u ; A = X 1: u ; B = X u + 1: n
2. # b and d are byte-lengths.
2.1. # b is the number of bytes to represent numeral string B in binary
b = v * log2 ( radix ) / 8
2.2. # d: it ensures that the output of the Feistel round function is at
# least four bytes longer than b, which minimizes any bias in the
# modular reduction in Step 4.3.
d = 4 b / 4 + 4
3. # P is a static-value 128-bit block used for invocation of PRF function.
3
P = [1]1|| [2]1|| [1]1 || radix || [10]1 || [u mod 256]1 || [n]4 || [t]4
4. for i = 0 to 9 do # FF1 has ten rounds
4.1. # Encode in bytes: tweak T, substring Z, round number i, and
# numeral string B. Z is a 0-byte string added so that the byte length
# of Q is a multiple of 16 bytes (i.e. 128 bits, which is the AES block length.
Z = [0](−t −b−1) mod 16;
b
Q = T || Z || [i ]1 || Numradix ( B )
4.2. # PRF function is applied to P || Q string to produce a 128-bit block R
R = PRF ( P || Q )
# R is truncated or expanded to a string S of a length of d bytes.
# If d ≤ 16, then S is composed of the first d bytes of R. Otherwise,
# block R is expanded (with iterative encryption of R and a constant)
# to produce d bytes. FBd ( S ) denotes the first d bytes of string S .
# S corresponds to the output of round function FK
16 16
EncK ( R ⊕ [1] ) || EncK ( R ⊕ [2] ) || …
S = FBd R ||
16
EncK ( R ⊕ d / 16 − 1 )
y = Num( S )
4.3. # To take into account the parity of X length, the computation of the
# next value of half B is performed with modulo radix u if the round
# number is even, and with modulo radix v otherwise,
if i is even, then m = u, else m = v
c = (Numradix ( A ) + y ) mod radix m
# C is a sum converted into a string of m numerals in base radix
C = strradix m
(c )
4.4. # Swap of halves:
A = B ; B = C
5. Y = A || B; return Y
Notes
– Why R is padded with random string in step 4.2? S, the output of round function, is obtained from R by padding with
16 16 16
random blocks (Enc K ( R ⊕ 1 , Enc K ( R ⊕ 2 , …, Enc K R ⊕ d / 16 − 1 ) instead of padding with a constant bit
sequence, which would be a potential security risk. Therefore, the round function produces a fully random output.
8.7 Format-Preserving Encryption Modes of Operation 261
– Why d is greater than b by 4 at least? Given a substring A of length b, the round function must return a scrambled
string of at least b bytes. In step 4.3, the sum c = Numradix ( A) + y mod radix m is composed of two parts Numradix ( A)
and y. Numradix ( A) is less than radix m, because substring A has u or v symbols in base radix; and m = u or m = v . To
scramble A with y, without bias we need a value of y in which all bits are random. Therefore, for y to be a fully
randomized number, it must be at least equal to radix m . With a bit-string S of length d, with d = 4 b / 4 + 4 , we can
represent integers greater than radix m . Indeed, radix m = 2log2 (radix )*m 28* b < 28* d.
Algorithm of FF1 decryption is similar to that of encryption. Both algorithms differ only in lines 4.1, 4.3, and 4.4. That is,
the encryption algorithm makes use of half B to produce the bit string Q and it uses the half A and modular addition to yield
C, which is copied in half B, while the decryption algorithm makes use of half A to produce the bit string Q and it uses the
half B and modular subtraction to produce C, which is copied in half A.
function FF1_Decryption
input K : key; T : tweak of length t bytes; t ∈ 0 .. maxTLen
X: ciphertext, a string of n numerals in base radix
# n ∈ minLen .. maxLen
output Y : plaintext of the same length than that of X
1. # Input numeral string X is split into two halves A (left) and B (right)
u = n / 2 ; v = n − u ; A = X 1: u ; B = X u + 1: n
2. # b and d are byte-lengths.
b = v * log2 ( radix ) / 8 ; d = 4 b / 4 + 4
1 1 1 3 1 1 4 4
3. P = [1] || [2] || [1] || radix || [10] || [u mod 256] || [n] || [t ]
4. for i = 0 to 9 do
1 b
4.1. Z = [0](
−t −b−1) mod 16
; Q = T || Z || i || Numradix ( A )
4.2. R = PRF ( P || Q )
Enc ( R ⊕ [1]16 ) || Enc ( R ⊕ [2]16 ) || …
K K
S = FBdR || 16
EncK ( R ⊕ d / 16 − 1 )
y = Num( S )
4.3. if i is even, then m = u, else m = v
c = (Numradix ( B ) − y ) mod radix m
C = strradix m
(c )
4.4. # Swap of halves:
B = A ; A = C
5. Y = A || B; return Y
Example 8.2
Below is a simple example to show how FF1 performs the encryption and decryption. To perform FF1 operations by hand,
we need two simplifications: the number of rounds is limited to two and the PRF( X ) function returns six 0-bytes followed
by the two rightmost bytes of inputX followed by eight 0-bytes.
Let the plaintext be X = 28750457, a string of eight characters in base 10. Let the tweak be T = 67 , a string of one byte.
Therefore, t = 1.
Encryption
8
– Split the input: u = v = = 4; A = 2875; B = 0457
2
– b = 4 * log2 (10) / 8 = 2 . Two bytes are required to represent in binary each of 2875 and 0457 values.
– d = 4 2 / 4 + 4 = 8
– P = [1]1 || [2]1 || [1]1 || [10]3 || [10]1 || [4]1 || [8]4 || [1]4
Round 0
– Z = [0](−1−2−1) mod 16 = [0]12
– Q = [67] || [0]12 || [0]1 || [0457]2 . len(Q) is 16 bytes.
262 8 Block Cipher Modes of Operation for Confidentiality
– R = PRF ( P || Q ). PRF receives two 128-bit blocks and returns a 128-bit block R, which depends on the key and AES
encryption of the bit string P || Q.
To simply, we assume that the returned value is
R = [0][0][0][0][0][0][0457]2 [0][0][0][0][0][0][0][0]
● FF3-1 is not flexible regarding the tweak length. In FF1, the tweak is an arbitrary string, which may be empty, while it
must be of exactly 56 bits in FF3-1.
● FF1 runs 10 rounds, while FF3-1 runs eight rounds.
● If the length of the input string is odd, the length of the right half is one byte longer than the left half in FF1 mode and
the inverse in FF3-1.
● FF1 makes use of big-endian representation, while little-endian is used in FF3-1. Therefore, FF3-1 makes use of two
functions to inverse strings before performing arithmetic operations:
– REV ( X ): given a character string X , REV ( X ) returns X in the reverse order. For example, REV (1957) = 7591.
– REVB ( B ): given a byte string B, REVB ( B ) returns B in the reverse byte order. For example,
( )
REVB [1]1 || [9]1 || [5]1 || [7]1 = [7]1 || [5]1 || [9]1 || [1]1 .
Figure 8.11 depicts computations performed in each round of FF3-1 encryption; conversion from symbols to integers and
vice versa is not shown on the figure.
function FF3_1_Encryption
input K : key; T : tweak of length of 56 bits
X : plaintext, a string of n numerals in base radix
# n ∈ minLen .. maxLen
output Y : ciphertext of the same length than that of input X
1. # The input numeral string X issplitintotwohalvesA (left )andB (right).
# If length of X is odd, then the left half has one numeral more than the
# right. A andB are strings of numerals
u = n / 2 ; v = n − u ; A = X [1: u ]; B = X [u + 1: n]
2. # The tweak T is partitioned into two parts, left (TL) and right (TR ), each
# of 32 bits (28 bits from T and four 0-bits):
TL = T [0 : 27] || 04; TR = T [32: 55] || T [28: 31] || 04
3. for i = 0 to 7 # FF3-1 has eight rounds
3.1. if i is even, then m = u; W = TR else m = v ; W = TL
3.2. # Half B is reversed and combined with the round number and a
# tweak half to produce a 128-bit block.
# Reverse operations (in FF3-1) are performed byte per byte.
12
P = W ⊕ [i ] || Numradix (REV ( B ))
4
3.3. # The byte-string P and the key K are reversed before encryption
# and then the produced ciphertext is reversed
S = REVB (EncREVB( K ) (REVB( P )))
3.4. y = Num( S )
3.5. c = (Numradix (REV ( A )) + y ) mod radix m
3.6. # Before swapping, a reverse operation is performed
C = REV strradix ( m
)
(c )
3.7. # Half swapping:
A = B ; B = C ;
4. Y = A || B; return Y
Algorithm of FF3-1 decryption is similar to that of encryption. Both algorithms differ only in lines 3.2 and 3.5. That is, the
encryption algorithm makes use of half B to produce the bit string P and it uses the half A and modular addition to produce
C, which is copied in half B, while the decryption algorithm makes use of half A to produce the bit string P and it uses the
half B and modular subtraction to produce C, which is copied in half A.
function FF3_1_Decryption
input K: key; T : tweak of length of 56 bits
X : ciphertext, a string of n numerals in base radix
# n ∈ minLen..maxLen
264 8 Block Cipher Modes of Operation for Confidentiality
XTS stands for XEX (Xor-Encrypt-Xor) Tweakable block cipher with ciphertext Stealing. XTS-AES mode also is referred to
as IEEE standard 1619. It is supported by many operating systems and platforms.
XTS-AES is a format-preserving encryption mode of operation. Hence, the length and the format of plaintext and cipher-
text are the same (i.e. no disk space waste). Therefore, applications do not need to change data format to encrypt or decrypt.
In addition, XTS-AES encrypts individual data units resulting in independent ciphertexts. Therefore, applications are not
required to decrypt all ciphertexts to retrieve a specific item of data. Rather, XTS-AES provides support to fast data random
access.
XTS-AES operates with keys of bit-length of either 256 or 512. If the XTS-AES key consists of 256 bits, the encrypt/
decryption procedures use 128-bit AES; if the XTS-AES key consists of 512 bits, the procedures use 256-bit AES, which dif-
fer in term of number of rounds (see Section 7.3.3).
Definition 8.4 Key scope: it defines the stream of data encrypted by a particular key. The key scope is represented by three
integers: tweak value corresponding the first data unit, the bit-length of data unit, and the number of units to be encrypted/
decrypted under the control of this key.
Definition 8.5 Data unit:10 it is a fixed-length bit-string within a key scope. The data unit length should be at least 128 bits.
Each data unit is divided into 128-bit blocks.
The total number11 of 128-bit blocks of the entire data shall not exceed 264 and the maximum number12 of 128-bit blocks in
a data unit shall not exceed 220. Usually the length of data unit equals the sector length of storage devices, e.g. 512 or 4k
bytes.
Definition 8.6 XTS-AES Tweak value: it is a 128-bit value representing the logical position of the data being encrypted or
decrypted. Each data unit is assigned a tweak value.
Tweak values are assigned consecutively, starting from an arbitrary value. An easy way to assign tweak values is to start
with a random value T1 and then increment it for each subsequent data unit; i.e. Ti = Ti−1 + 1 for i>1. Figure 8.12 illustrates
the main items of XTS-AES mode of operation.
Modular multiplication: input and output of XTS-AES encryption and decryption operations are bit-string of a length of 128
bits. Such operations perform multiplication, denoted ⊗, over an extension field F2128 (as below) with a reduction polynomial
f ( x ) = x 128 + x 7 + x 2 + x + 1 and a primitive element α, which corresponds to polynomial x (i.e. 0000…00102 = 000210 ). For
more on extension fields, see Section 3.2.3.
function XTS_AES_Block_Encryption
input K : key with a length of 256 or 512 bytes
Px : 128-bit plaintext block; T : tweak value (a 128-bit block)
j : sequential number for each 128-bit block inside the data unit
output C x : 128-bit ciphertext block
1. # The key is split into two equal length subkeys
Let K = K1 || K2
2. # Ciphertext block computation
A = AES _EncK2 (T ) ⊗ a j ; B = AES _EncK1 (Px ⊕ A); C x = B ⊕ A
3. return C x
function XTS_AES_Data_unit_Encryption
input K : key with a length of 256 or 512 bytes
P: plaintext composed of one or more 128-bit blocks
T : tweak value (a 128-bit block) assigned to the data unit
266 8 Block Cipher Modes of Operation for Confidentiality
function XTS_AES_Block_Decryption
input K : key with a length of 256 or 512 bytes
C x : 128-bit ciphertext block; T : tweak value (a 128-bit block)
j: sequential number for each 128-bit block inside the data unit
output Px : 128-bit plaintext block
1. # The key is split into two equal length subkeys
Let K = K1 || K2
2. # Plaintext block computation
A = AES _EncK2 (T ) ⊕ a j ; B = AES _DecK1 (C x ⊕ A); Px = B ⊕ A
3. return Px
function XTS_AES_Data-unit_Decryption
input K : key with a length of 256 or 512 bytes
C: ciphertext composed of one or more 128-bit blocks
T : tweak value (a 128-bit block) assigned to the data unit
output P: plaintext of the same bit-length than C
1. # Key is partitioned into m +1 blocks, where is m is the largest
# integer such that m * 128 < len(C ).
# Blocks C0 , … , C m−1 have the same bit length, 128.
# The last block C m is of bit-length between 0 and 127.
Let C = C0 || C1 … || C m
2. # Ciphertext decryption
2.1 for i = 0 to m−2 do
Pi = XTS _AES _Block_Decryption( K , Ci ,T , i )
2.2 b = len (C m )
2.3. if b = 0, then
Pm−1 = XTS _AES _Block_Decryption (K , C m−1 ,T , m − 1)
Pm = Empty
2.4 else
PP = XTS _AES _Block_Decryption (K , C m−1 ,T , m)
Pm = MSBb ( PP ); CP = LSB128−b ( PP ); CC = C m || CP
Pm−1 = XTS _AES _Block_Decryption( K , CC ,T , m − 1)
3. P = (P0 || P1 … || Pm ); return P
XTS-AES is more performant than CBC, when decrypting ciphertexts. In CBC, to access a specific field (or portion) in
data on storage device, the decryption of the entire data is often required. With XTS-AES, only the searched field (or por-
tion) requires decryption. Since XTS-AES is a format-preserving encryption only, it cannot provide support for data integ-
rity. Indeed, because there is no hash or MAC (message authentication code) in the produced ciphertext, any alteration
(modification, deletion or insertion), in the ciphertext, is decrypted as some (random) plaintext. There exist three main
categories of potential attacks against XTS-AES:
● Randomizing a sector: an adversary with write access to the encrypted storage device can change a sector to an arbitrary
value, which results in invalid data used by legitimate applications.
● Selective replay attack: an adversary with write access to the encrypted storage device can set the value of a sector to a
specific value observed in past in order to corrupt some write operations. For example, consider a malicious store
employee who has write access to a stock status file and who knows the index of a block, say C xcurrent, associated with the
number of articles A, of interest to him/her, in stock and he/she also knows that different versions of the file are encrypted
with the same tweak, and finally, he/she has access to an older version of the same file. Under such conditions, the
employee can replace block C xcurrent by an older block C xold. Since C xcurrent and C xold ciphertext blocks have been encrypted
by the same parameters (tweak, key, and bock index), the decryption of the modified block yields the stock status of
interest to the malicious employee.
● Traffic analysis: if an adversary can observe the communication between the encrypting device and the storage device,
he/she can infer when some sectors are modified over time and then use such a knowledge to design an attack.
Table 8.1 aims at summarizing some fundamental design features to compare block cipher modes of operation. The fea-
tures of interest are the following:
● Encryption determinism: is the same plaintext block always mapped to the same ciphertext block under the same
key?
● Padding is the plaintext length required to be a multiple of block length?
● Initialization vector: is IV required? If Yes, should the IV be a nonce or unpredictable?
● Parallelization: can the encryption or decryption of blocks be performed in parallel?
● Ciphertext error-propagation: does a bit error in a ciphertext block prevent13 the recovery of the remaining plaintext
blocks? “No” means only the plaintext block associated with the altered ciphertext block is unlikely to be recovered cor-
rectly; “Yes” means the plaintext block associated with the altered ciphertext block and the plaintext block that follows
are unlikely to be recovered correctly.
● IV and counter error-propagation: in case the IV or counter is sent14 to recipient, does bit alteration in the IV or counter
impact the decryption?
● Diffusion property: does a modification of a bit in a plaintext block propagate in the whole ciphertext?
● Block cipher (BC) decryption use:15 does the mode of operation make use of the decryption operation of the underlying
block cipher to decrypt?
● Stream cipher16 construction: can the mode of operation be used as a stream cipher?
When a block cipher is used for confidentiality protection, the security goal is to prevent an eavesdropper with limited
computational power to learn any information about the plaintext (except for maybe its length). This eavesdropper can
apply the following attacks: known-plaintext attacks, chosen-plaintext attacks, and chosen-ciphertext attacks that should
be prevented by the underlying cipher.
270 8 Block Cipher Modes of Operation for Confidentiality
CBC-SC
ECB Basic CBC variants OFB CTR CFB FF1FF3-1 XTS-AES
Determinism Yes No No No No No No No
Padding Yes Yes No No No No No No
IV/counter No Unpr. Unpr. Nonce Ctr(a) Unpr. Twk(b) Twk(c)
(d) (d)
Encryption parallelization Yes No No Yes Yes No No Yes(e)
Decryption parallelization Yes Yes Yes(f) Yes(g) Yes(g) Yes(h) No Yes(i)
(j) (k) (l)
Error propagation No Yes Yes No No Yes Yes No(m)
IV/counter error propagation n.a No(n) No(o) Yes(p) Yes(q) Yes(r) Yes(s) Yes(s)
Diffusion No Yes Yes No No Yes Yes No
BC decrypt. algorithm use Yes Yes Yes No No No No Yes
Stream cipher No No No Yes Yes Yes No No
Notes:
(a) A unique counter block for each plaintext block that is ever encrypted under a given key, across all messages, i.e. the block counter should
be a nonce.
(b) A distinct tweak is used for each plaintext.
(c) A distinct tweak is used for each data unit.
(d) Under the condition that the blocks O1 , …, Om are precomputed.
(e) With the exception of the two last blocks.
(f) With the exception of the two last blocks, which cannot be treated in parallel.
(g) Under the condition that the blocks O1 , …, Om are precomputed.
(h) Under the condition that the blocks I1 , …, Im are precomputed, upon reception of the ciphertext blocks.
(i) With the exception of the two last blocks.
(j) In CBC variants, the decryption of the last but one block steals some bits from the last ciphertext block. Therefore, if the last cipher block is
altered, then the two last blocks are unlikely to be recovered correctly.
(k) If segment Ci# is altered, then segments Ci# , Ci+1
#
, …, to Ci#+ b / s are unlikely to be recovered correctly.
(l) Because of the Feistel structure of FF1 and FF3-3 modes, if a ciphertext block is altered, it is very unlikely that any plaintext block could be
recovered correctly.
(m) With the exception of the last but one block, because the last ciphertext block steals some bits from the block before it.
(n) Only the decryption of the first ciphertext block makes use of the IV. Therefore, only the first plaintext block is unlikely to be recovered
correctly.
(o) As in basic CBC and in addition, if the ciphertext is composed of two blocks only, both blocks are unlikely to be recovered correctly.
(p) If an error occurs in the IV, then it is very unlikely that any plaintext block could be recovered correctly.
(q) If the initial counter is altered, then it is very unlikely that any plaintext block could be recovered correctly.
(r) If segment Ci# is lost, then segments Ci+1#
, …, to Ci#+ b / s are unlikely to decrypt to correct plaintext segments.
(s) If the tweak is altered in transit, then it is very unlikely that any plaintext block could be recovered correctly.
Before encrypting plaintext blocks, FF1 and FF3-1 modes append to the plaintext other strings (tweak, plaintext length,
round number, and constants), then a Feistel structure is applied, and bits are scrambled in each round. In the output of
FF1 and FF3-1, applying Ci1 ⊕ Ci2 does not help to derive Bi1 ⊕ Bi2 .
In XTS-AES mode, the encryption of two plaintexts M1 and M 2, with the same tweak, results in the following decryption,
for i = 1, …, min (len ( M1 ), len ( M 2 )):
1
( 2
)
Ci1 = Enc K Bi1 ⊕ Enc K (T ) ⊗ α i ⊕ Enc( K ) (T ) ⊗ α i ,
2
1
( 2
)
Ci2 = Enc K Bi2 ⊕ Enc K (T ) ⊗ α i ⊕ Enc( K ) (T ) ⊗ α i
2
Applying Ci1 ⊕ Ci2 does not help to derive Bi1 ⊕ Bi2 . Therefore, FF1, FF3-1, and XTS-AES modes are not vulnerable to attacks
based on reuse of tweak value.
Let S = 0117 || 10000000000 be the bit-string representing the integer 1024 on 128 bits.
The original plaintext block is recovered by the recipient as B4 = C4 ⊕ Enck (Cnt4 ).
Since the original amount v is less than 100, the bit-string B4′ represents the integer 1024 + v.
ECB mode is not vulnerable to bit-flipping, because each ciphertext block is decrypted only with the decryption operation
of the underlying block cipher, which is a pseudorandom permutation.
Given the scrambling performed in FF1 and FF3-1 rounds when encrypting or decrypting, the adversary has no control
on which bits will flip in the recovered plaintext, if some bits are flipped in the ciphertext.
In the XTS-AES mode, block decryption is performed with AES-encryption followed by AES-decryption. Therefore,
the adversary has no control on which bits will flip in the recovered plaintext, if some bits are flipped in the
ciphertext.
8.11 Exercises and Problems 273
Exercise 8.1
Consider a block cipher E , defined by the pseudorandom permutation given by the table below. Each letter is a block.
Then, consider ECB and CBC as modes of operation of the block cipher E . As the XOR operation (i.e. ⊕) is not defined on
the set { A, B, …, Z }, the following adaptations are used:
To encrypt a block Bi , the ciphertext Ci−1 (or the IV) is added modulo 26 to Bi (e.g. B ⊕ C = D , K ⊕ I = S ).
1) Decrypt the ciphertext OXBBJ, which was encrypted using ECB mode.
2) Decrypt the ciphertext DOLYV, which was encrypted using CBC mode with IV=K.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
P A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
E(K , P) Q E R Z X G N O P I C B V S J F W D H M T A Y K U L
Exercise 8.2
Discuss which of ECB, CBC, CTR, and FF1 modes could provide integrity guarantees.
Exercise 8.3
How many distinct counter blocks are required to encrypt a hard disk of 16 T bytes with AES-CTR?
Exercise 8.4
Let s denote the segment length parameter of CFB mode and b the block bit-length. Show that CFB mode is the same as
OFB mode if s = b.
Exercise 8.5
Show that ECB leaks information regarding plaintext-block repetition while CBC does not.
Problem 8.1
Consider a list of N names each of a length of 16 bytes. The name list is encrypted with four modes (ECB, CBC, OFB, and
CTR) of operation of AES.
1) On transit, a ciphertext block of index i (1 ≤ i ≤ N ) is altered because of transmission errors changing some 0-bits to
1-bits and vice versa. What is the number of names that cannot be correctly recovered by the recipient for each mode of
operation?
2) On transit, a ciphertext block of index i (1 ≤ i ≤ N ) is lost. What are the names that are missing in the recipient list and
those that are not correctly recovered in each mode of operation?
Problem 8.2
Consider a plaintext, composed of N segments, encrypted with CFB mode.
1) On transit, a ciphertext segment of index i (1 ≤ i ≤ N ) is altered because of transmission errors changing some 0-bits to
1-bits and vice versa. What is the number of segments that cannot be correctly recovered by the recipient?
2) On transit, a ciphertext segment of index i (1 ≤ i ≤ N ) is lost. What are the plaintext segments that are missing in the
recipient plaintext and those not correctly recovered? Without loss of generality, assume that the block length is a mul-
tiple of the segment length.
Problem 8.3
Show how CTR and OFB modes can be attacked if two plaintexts M1 and M 2 are encrypted with the same initial counter
or IV, respectively.
Problem 8.4
Assume that a plaintext–ciphertext pair is known. Show that keeping the IV secret in OFB mode does not make an exhaus-
tive key search more complex, if the number of plaintext blocks is at least 2.
Problem 8.5
Consider the following scenario: in a company, a group of engineers collaborate on a project including several tasks. Some
engineers are task managers and they declare, on a weekly basis, the number of hours of participation of each engineer
274 8 Block Cipher Modes of Operation for Confidentiality
(including themselves) in the tasks assigned to them. Participation declarations are first securely sent to a server 1 by each
task manager, and then server 1 encrypts, with ECB mode, a message for each engineer participation and sends the cipher-
text to a server 2, which centralizes the engineers’ participation in the project. The key shared by servers is not known to
engineers. The format of the messages between both servers is composed of three fields each represented on one block:
Manager identifier, participating engineer identifier, and the number of hours of participation. One malicious task man-
ager who participates in multiple tasks and who knows the format of ECB-encrypted messages and who can intercept and
modify ciphertexts between servers, wants to increase his/her amount of participation hours. He/she observed that the task
managers used to send participation declarations on Friday before 6:00 p.m., but the server 1 accepts declarations up to
Friday midnight. How may the malicious engineer design the attack?
Problem 8.6
Prove the correctness of CBC-CS1 mode of operation.
Problem 8.7
Prove the correctness of XTS-AES block encryption.
Problem 8.8
Consider the following context: Alice and Bob agree to use CBC mode to protect their communications. Eve has the capacity
to ask Alice to encrypt messages for her (i.e. Eve is able to mount chosen-plaintext attacks) and she is able to predict the IV
that will be used by Alice to encrypt her next message. Bob asks Alice to do something and she has to reply just by “Yes” or
“No” in one block. Alice encrypts her response PAlice = ‘Yes’, using IV IV0 , and sends a ciphertext CtoBob to Bob. Eve intercepts
IV0 and CtoBob and she wants to know Alice’s response without any knowledge about the key. Show how Eve can discover
Alice’s response.
Exercise 8.1
Let Ci be the ciphertext of plaintext block Bi . Let D denote the decryption operation of block cipher E .
1) Decryption of ciphertext OXBBJ using ECB mode
The decryption using ECB mode is defined by: Bi = D (Ci ).
The plaintext associated with ciphertext OXBBJ is HELLO, because:
D(O) = H , D( X ) = E, D( B ) = L, D( B ) = L, D( J ) = O
2) Decryption of the ciphertext DOLYV, which was encrypted using CBC mode with IV=K
The decryption using CBC mode is defined by: Bi = D (Ci ) ⊕ Ci−1 , with C0 = IV
Since ⊕ is not defined on the letters, the decryption is transformed as follows:
(
Bi = Letter Ind ( D (Ci )) − Ind (Ci−1 ) mod 26 )
Hence,
B1 = Letter ( Ind ( D( D)) − Ind( K ) mod 26) = Letter (17 − 10 mod 26) = H
B3 = Letter ( Ind ( D( L)) − Ind(O ) mod 26) = Letter (25 − 14 mod 26) = L
B4 = Letter ( Ind ( D(Y )) − Ind( L) mod 26) = Letter (22 − 11 mod 26) = L
B5 = Letter ( Ind ( D(V )) − Ind(Y ) mod 26) = Letter (12 − 24 mod 26) = O
Exercise 8.2
ECB, CBC, CTR, and FF1 are algorithms aiming to provide confidentiality guarantees. As they do not make use of tags, no
integrity guarantees could be provided. Any altered ciphertext is decrypted to a plaintext, which is very likely to be distinct
from the original plaintext and the recipient has no means to check the integrity.
8.11 Exercises and Problems 275
Exercise 8.3
We consider a disk of 16 T bytes encrypted with AES-CTR. 16 tera bytes are split into m 128-bit blocks, where
24 * 240 * 23
m= = 240 . Each plaintext block requires a distinct counter block; hence, the number of distinct counter blocks
27
is 240.
Exercise 8.4
If the segment length s is equal to the block length b, then:
– The number of segments m_s is equal to the number of blocks m.
– For any i, 1 ≤ i ≤ m, segments Bi# and Ci# are equal to blocks Bi and Ci , respectively.
– LSBb−s ( X ) = null and MSBs ( X ) = X , for a bit-string of bit-length not greater than b.
With the limitations above, the CFB encryption formulas become:
I1 = IV
( )
I j = LSBb−s I j−1 || C #j−1 = null || C #j−1 = C j−1 , ∀j, 2 ≤ j ≤ m_s
( ) ( )
O j = Enc K I j = Enc K C j , ∀j, 1 ≤ j ≤ m_s
( )
C #j = B #j ⊕ MSBs O j = B j ⊕ O j, ∀j, 1 ≤ j ≤ m_s −1
The formulas above are the same as those of OFB encryption. The same apply to decryption. Therefore, CFB mode is iden-
tical to OFB mode if the segment length is the same as that of the block.
Exercise 8.5
Let A and B be two blocks and P = A || B || B || B , a plaintext with three repetitions of block B. If ECB or CBC is used, then
the ciphertext is C = C1 || C2 || C3 || C4 .
If ECB is used, then C1 = Enc K ( A), C2 = C3 = C4 = Enc K ( B ).
If CBC is used, then C1 = Enc K ( A ⊕ IV ) , C2 = Enc K ( B ⊕ C1 ), C3 = Enc K ( B ⊕ C2 ), C4 = Enc K ( B ⊕ C3 ).
We can see that the same ciphertext block Enc K ( B ) repeats three times in C. Therefore, ECB leaks information regarding
plaintext repetition, while CBC does not.
Problem 8.1
1) Error-propagation resistance
– In ECB, OFB, and CTR modes, the decryption of a block is independent of that of other blocks. Therefore, if ciphertext
block i is errored, only the name with index i is unlikely to be correctly recovered.
– In CBC mode, the decryption of ciphertext block k depends on ciphertext blocks k and k −1. Therefore, if ciphertext
block i is errored, there exist two cases: a) if i = N , only the last name in the list is unlikely to be correctly recovered
and b) if i < N , the names with indices i and i +1 are is unlikely to be correctly recovered.
2) Loss-propagation resistance
– In ECB mode, the decryption of a block is independent of that of other blocks. Therefore, if ciphertext block Ci is lost,
only the name with index i is missing in the recipient list.
– In CTR mode, the encryption counter block Ctn j is used as a keystream string to encrypt the plaintext block B j , for
j = 1, …, N . In OFB and CFB modes, the encrypted block I j is used as a keystream string to encrypt the plaintext block
B j , for j = 1, …, N . In all these three modes, if the ciphertext block Ci is lost, then the recipient makes use of block Cnti
(for CTR) or Ii (for OFB and CFB) to decrypt ciphertext Ci+1 for i = 1, …, N − 1. Therefore, the name with index i is
missing in the recipient list and all the subsequent names are very likely to be incorrectly recovered, if CTR, OFB, and
CFB modes are used. Those three modes operate like stream ciphers where any loss in the keystream string results in
a loss of synchronization.
– In CBC mode, the encryption ciphertext block C j−1 is used to encrypt plaintext block C j , j = 2, …, N . If ciphertext
block Ci is lost, then the decryption of the subsequent ciphertext blocks is performed as: Bi = Dec K (Ci+1 ) ⊕ Ci−1,
Bi+1 = Dec K (Ci+2 ) ⊕ Ci+1, …, BN −1 = Dec K (C N ) ⊕ C N −1. Because of a jump in ciphertexts, Bi = Dec K (Ci+1 ) ⊕ Ci−1 is
very likely to be an incorrect name. Therefore, the name with index i is missing in the recipient list and the names of
index greater than i are unlikely to be correctly recovered, if CBC mode is used.
276 8 Block Cipher Modes of Operation for Confidentiality
Problem 8.2
Recall that CFB mode processes segments of a bit-length s, which is not greater than that of a block denoted b. CFB mode
operates like a stream cipher in which the leftmost s bits of keystream block I j are XORed with plaintext segment B #j to
produce the ciphertext segment B #j . Assuming that b is a multiple of s, let q = b / s . Keystream blocks are computed as
follows:
I1 = IV = IV1 || IV2 || … || IVq, where IVi=1,…,q are s-bits segments of IV.
…
1) Error-propagation resistance
In CFB mode, if the ciphertext segment Ci# is altered, then the plaintext segment Bi# is unlikely to be correctly recovered.
The keystream block Ii+1, used to decrypt the subsequent ciphertext segment Ci+1#
is computed as: Ii+1 = LSBb−s ( Ii ) || Ci#,
which differs from the one used at encryption step. The segment decryptions are unlikely to produce the original plaintext
segments as long as the errored ciphertext segment Ci# is present inside keystream blocks subsequent to Ii . Now, let us see
how the segment Ci# is left-shifted in the subsequent keystream blocks Ii+2 , Ii+3, … until it disappears. Instead of string
concatenation, integer representation of block is used for convenience.
Ii+1 = LSBb−s ( Ii ) * 2 s + Ci#
( )
Ii+2 = LSBb−s ( Ii+1 ) * 2 s + Ci#+1 = LSBb−s LSBb−s ( Ii ) * 2 s + Ci# * 2 s + Ci#+1
( ( ) )
Ii+3 = LSBb−s ( Ii+2 ) * 2 s + Ci#+2 = LSBb−s LSBb−s LSBb−s ( Ii ) * 2 s + Ci# * 2 s + Ci#+1 * 2 s + Ci#+2
In block Ii+3, the errored segment Ci# is left-shifted with 2s positions. The shifting process continues until the segment
Ci# exits on the left. Let q = b / s . After left-shifting with q * s positions, the ciphertext segment Ci# is eliminated and the
synchronization resumes. Therefore, all the ciphertext segments, from Ci# to Ci#+q , are unlikely to be correctly decrypted.
2) Loss-propagation resistance
After decrypting ciphertext segment Ci−1 #
, the recipient computes keystream block Ii as Ii = LSBb−s ( Ii−1 ) * 2 s + Ci#−1. If the
ciphertext segment Ci is lost, then the plaintext segment Bi# is missing in the plaintext recovered by recipient. Then, the
#
#
recipient receives ciphertext segment Ci+1 , while it was waiting for segment Ci#. Thus, it is unlikely to recover plaintext seg-
( )
ment Bi+1 . Then, keystream block Ii+1 is computed as: Ii+1 = LSBb−s LSBb−s ( Ii−1 ) * 2 s + Ci#−1 * 2 s + Ci#+1, in which Ci# is
#
missing (i.e. there is gap in the sequence of ciphertext segments present in the stream block); thus, it is unlikely to produce
plaintext segment Bi# or Bi+1 #
. After q = b / s − 1 incorrect decryptions, there is no ciphertext segment gap in subsequent
keystream blocks and thus the resynchronization resumes on recipient side, ciphertext segment Ci# is not treated (because
#
it has not been received), ciphertext segments Ci+1 to Ci#+q are unlikely to decrypt to correct plaintext segments, and the
decryption is one-segment behind the encryption, i.e. Ci#+q + j is decrypted as it if was Bi#+ q + j −1.
Problem 8.3
Let M 1j , j = 1, …, n1, and M 2j , j = 1, …, n2 , denote blocks of plaintexts M1 and M 2, respectively. Let C 1j , j = 1, …, n1 , and C 2j ,
j = 1, …, n2 , denote blocks of ciphertexts C 1 and C 2 , respectively; where n1 and n2 denote the numbers of blocks of M1 and M 2,
respectively. Without loss of generality, assume that both plaintexts are of a length multiple of that of a block.
Recall that given a plaintext of m blocks, the ciphertext blocks are computed as follows:
( )
If CTR is used, C j = B j ⊕ O j, O j = Enc K Cnt j , ∀ j, 1 ≤ j ≤m.
If OFB is used, C j = B j ⊕ O j , O j = Enc K ( I j ), ∀ j, 1 ≤ j ≤m, I1 = IV , I j = O j−1.
8.11 Exercises and Problems 277
Therefore, the ciphertext blocks in both modes are computed as C j = B j ⊕ O j, ∀ j, 1 ≤ j ≤m. Both modes differ only in how
keystream blocks O j=1,…,m are computed.
If two plaintexts M1 and M 2 are encrypted with the same counter or the same IV, then:
C 1j = B1j ⊕ O j, j = 1, …, n1
C 2j = B 2j ⊕ O j , j = 1, …, n2.
( )
Let m = min n1 , n2 . XORing both plaintexts yields:
C 1j ⊕ C 2j ( ) ( )
= B1j ⊕ O j ⊕ B 2j ⊕ O j = B1j ⊕ B 2j , j = 1, …, m
Therefore, if CTR or OFB modes are used to encrypt two plaintexts with the same counter or the same IV, the adversary can
derive the XOR of both plaintexts, which is particularly damaging, if plaintexts are messages in natural language.
Problem 8.4
In this problem, we consider a brute-force attack against OFB mode to disclose the key. The adversary is given a plaintext–
ciphertext pair of at least two plaintext blocks.
By design of OFB, C1 = B1 ⊕ Enc K ( IV ), C2 = B2 ⊕ Enc K ( Enc K ( IV )), …, where Bi=1,2,… are plaintext blocks and Ci=1,2,…, the
corresponding ciphertext blocks.
a) Case 1: IV is known to the adversary
From the first ciphertext block and its ciphertext, the following is inferred:
C1 = B1 ⊕ Enc K ( IV )
C1 ⊕ B1 = Enc K ( IV ) (a)
Since the IV is known, the adversary has to find a key such that the encryption of the IV yields C1 ⊕ B1, which is known.
With a brute-force attack, a maximum of 2n keys may be tested, where n denotes the bit-length of the key.
b) Case 2: IV is unknown to the adversary
Using the second ciphertext block and its ciphertext, the following is inferred:
Next, the adversary has to find a key such that the decryption of the C2 ⊕ B2 yields C1 ⊕ B1, which are known. With a brute-
force attack, a maximum of 2n keys may be tested.
Consequently, making the IV secret does not result in a more complex brute-force attack to disclose the key in OFB mode.
Problem 8.5
The malicious task manager knows that the format of the ciphertext is composed of three blocks C1 , C2, and C3 , where C1
is the encryption of the task manager ID, C2 is the encryption of the participating engineer’s ID, and C3 is the encryption of
the number of hours. Since ECB mode is used, the encryption of any engineer’s ID produces the same ciphertext block in
all the encrypted participation declarations. Let C2_mal be the ciphertext of the malicious engineer’s ID. Such a ciphertext
bock appear in all the encrypted messages related to the malicious engineer. With C2_ mal known, the malicious engineer
has just to intercept ciphertexts, between servers, and replace the second ciphertext block of the intercepted ciphertexts
by C2_mal and the number of hours will count for him/her.
To discover the ciphertext associated with his/her ID, the malicious engineer knows that task managers used to send
participation declarations on Friday before 6:00 p.m., but the server 1 accepts declarations up to Friday midnight. To exploit
such a knowledge, he/she sends (for some weeks) his/her declarations late, say on Friday 11:00 p.m., and intercepts the
ciphertexts between the servers. After some ciphertext interceptions, he/she can infer, at a high probability, the encryption
of his/her ID, which is located in the first block of the ciphertexts. Then, he/she can change the second ciphertext blocks
in some messages between servers.
278 8 Block Cipher Modes of Operation for Confidentiality
Problem 8.6
Consider the encryption, using CBC-CS1 mode, of a plaintext B of m blocks, where the last block Bm* is of a bit-length d less
(n−d)
than the block length n. Block Bm is padded with 0 ; then, CBC encryption is applied to m complete blocks to yield
ciphertext blocks C1 , …, Cm.
Write Cm−1 as Cm−1 = Cm* −1 || Cm**−1, where Cm−1
* **
is of a bit-length of d and Cm−1 of a bit-length of n − b .
By design of CBC encryption,
(
Cm = Enc K ( Bm ⊕ Cm−1 ) = Enc K Bm* || 0
(n−d)
)
⊕ Cm−1
(
= Enc K Bm* ⊕ Cm* −1 || 0
(n−d)
⊕ Cm**−1 ) = Enc ((B
K
*
m
**
⊕ Cm* −1 || Cm− ))
1 .
In case of non-alteration of the ciphertext, the decryption of the last block using CBC-CS1 is as follows:
( ((
Dec K (Cm ) = Dec K Enc K Bm* ⊕ Cm* −1 || Cm**−1 ) )) = (Bm* ⊕ Cm* −1 || Cm**−1 )
Thus, Z * = Bm* ⊕ Cm* −1 and Z ** = Cm**−1.
Then, by addition, Z * ⊕ Cm* −1 = Bm* ⊕ Cm* −1 ⊕ Cm* −1 = Bm* . Therefore, the last (incomplete) block is recovered correctly. □
( )
Problem 8.7
We need to prove the correctness of XTS-AES at two levels: block and data unit encryption levels.
1) Correctness of XTS-AES block encryption
In the encryption procedure, the ciphertext is produced as follows:
C = AES_Enc ( K1 , P ⊕ A) ⊕ A, where A = AES_Enc ( K 2 , T )×α j
Assuming no alteration of the ciphertext block and given that T and j are the same on both sides, A = AES_Enc ( K 2 ,T ) ⊗ α j
is the same on both sides.
Let P ' denote the result of the block decryption procedure. By substitution,
P ' = AES_Dec ( K1 , C ⊕ A) ⊕ A
(
= AES_Dec K1 , ( AES_Enc ( K1 , P ⊕ A) ⊕ A) ⊕ A ⊕ A )
= AES_Dec ( K1 , AES_Enc ( K1 , P ⊕ A)) ⊕ A = ( P ⊕ A) ⊕ A = P
( (
Cm−1 = B_Enc K , Pm || RMB128−b ( B_Enc ( K , Pm−1 , T , m − 1)) , T , m ) )
Data unit decryption procedure performs the following computations:
Pm′ = LMBb ( B_Dec ( K , Cm−1 , T , m)) (a)
( ( )
Pm′ −1 = B_Dec K , Cm || RMB128−b ( B_Dec ( K , Cm−1 , T , m)) , T , m − 1 ) (b)
Notes 279
(
= LMBb Pm || RMB128−b ( B_Enc ( K , Pm−1 , T , m − 1)) = Pm )
By substitution, (b) becomes:
LMB B_Enc K , P ,T , m − 1
b( ( m−1 ))
Pm′ −1 = B_Dec K ,
,T , m − 1
|| RMB
128−b
(
( (
B_Dec K , B_Enc K , Pm || RMB128−b ( B_Enc ( K , Pm−1 ,T , m − 1)) ,T , m ,T , m
) ) )
= B_Dec K ,
( LMB (B_Enc(K , P
b m−1 , T , m − 1 )) || RMB128−b ( (Pm || RMB128−b ( B_Enc ( K , Pm−1 ,T ,m − 1))) )),T ,m − 1
( )
= B_Dec K , ( B_Enc ( K , Pm−1 , T , m − 1)), T , m − 1 = Pm−1 .
Notes
1 Seed is the initialization parameter of a PRNG. Pseudorandom number generation is addressed in Chapter 16.
2 In cryptography, a codebook is a lookup table for coding and decoding; each word has one string, which replaces it. Like a
codebook, ECB mode associates a ciphertext to each plaintext block.
3 Block alteration means presence of bit transformations (e.g. “0” becomes “1” or “1” becomes “0”).
4 Capacities required to save ciphertexts on storage devices or to transmit them.
5 Padding is used only to perform ciphertext computation and it does not impact the bit-length of the produced ciphertext.
6 FF2 has not been approved by NIST, because of its vulnerability. FF3-1 is a revision of FF3 mode.
7 It’s important to distinguish between symbols and their representation. The same symbol has several representations,
depending on the chosen base.
8 The IV value is used once to encrypt/decrypt a set of blocks of the plaintext/ciphertext, while a (different) tweak value is
used in each block encryption/decryption. That is a reason to use distinct terms.
9 When the chosen base is greater than 10, a space character is used to separate numerals.
10 “Data unit” as defined above is specific to XTS-AES mode. A data unit does not necessarily correspond to a physical or
logical block on a storage device. The mapping between data units and data on storage device is implementation-dependent
and is out of the scope of XTS-AES mode.
11 264 limit is for thwarting birthday attack.
12 220 limit is for interoperability of XTS-AES implementations.
13 For any mode of operation, if there are any bit errors in a ciphertext block, then the decryption of that ciphertext block is
very unlikely to be correct.
14 Sending IVs or counters results in a vulnerability in the mode of operation.
15 Some modes of operation make use only of the encryption operation of the underlying block cipher to encrypt plaintexts
and to decrypt ciphertexts.
16 Modes of operation, which generate a bit string that is XORed with the plaintext (respectively the ciphertext) to produce the
ciphertext (respectively the plaintext), provide techniques (in addition to those presented in Chapter 6) to build stream ciphers.
280 8 Block Cipher Modes of Operation for Confidentiality
References
1 Goldwasser, S. and Micali, S. (1984). Probabilistic encryption. Journal of Computer and System Sciences 28: 270–299.
2 Dworkin, M. (2001). Recommendation for block cipher modes of operation methods and techniques, special publication
800-38A. NIST. National Institute for Standards and Technology.
3 Dworkin, M. (2019). Recommendation for block cipher modes of operation: methods for format-preserving encryption,
special publication 800-38G. NIST. National Institute for Standards and Technology.
4 Dworkin, M. (2010). Recommendation for block cipher modes of operation: three variants of ciphertext stealing for CBC
mode, addendum to NIST special publication 800-38A. NIST. National Institute of Standards and Technology.
5 IEEE. (2018). IEEE standard for cryptographic protection of data on block-oriented storage devices, IEEE Std 1619™-2018.
Institute of Electrical and Electronics Engineers. IEEE.
6 Liskov, M., Rivest, R., and Wagner, D. (2002). Tweakable block ciphers. Journal of Cryptology 24: 588–613.
281
In the previous chapter, we presented the modes of operation of block ciphers to provide confidentiality guarantees.
Another security property of prime importance is integrity. Indeed, in the event an adversary alters a message or a storage
device content, the decryption operation cannot detect any alteration. Therefore, message authentication codes or other
techniques are required to preserve data integrity. To provide confidentiality and integrity guarantees based on block
ciphers, the NIST approved a set of modes of operation for block ciphers, which are discussed in this chapter. They include
(see Figure 9.1):
● Five modes of operation for confidentiality and authenticity guarantees: CCM, GCM, KW, KWP, and TKW.
● Two modes of operation for authenticity guarantees only: CMAC and GMAC.
All these modes provide capabilities to generate and verify message tags. In addition to approved modes of operation of
block ciphers, two other algorithms are useful to authenticate messages:
● AES-GCM-SIV [1] is an extension of GCM, which is resistant to IV misuse.
● ChaCha20-Poly1305 is a scheme recommended to build authenticated encryption for TLS implementation.
Notice that authentication, addressed in this chapter, means message authenticity and not the authentication of the
entity sending a message. Entity authentication is addressed in Chapter 15.
9.1 Introduction
Definition 9.1 Data authenticity: it is a property to indicate that the data originated from its purported source.
Definition 9.2 Authenticated encryption: it is a cryptography scheme that provides guarantees to data confidentiality and
authenticity verification.
Definition 9.3 Associated data (also called additional authentication data): it may be any bit string (including a MAC
address, an IP addresses, a port numbers, a user name, an application name or a protocol title), which is used in data authen-
ticity verification.
Definition 9.4 Authenticated encryption/decryption with associatedencryption/decryption with associated
data”1 data (AEAD): it is an authenticated encryption/decryption in which additional data is used to authenticity
verification.
Definition 9.5 Nonce misuse-resistant AEAD: it is an authenticated-encryption scheme in which encrypting different
plaintexts with the same nonce will reveal nothing to adversary.
Notations: the same notations are used in Chapters 8 and 9.
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
282 9 Block Cipher Modes of Operation for Authentication and Confidentiality
Standard algorithms for authenticated encryption (such as CMAC, CCM, and GCM), which are presented in the sequel,
are Encrypt-then-MAC algorithms. In order to thwart attacks, it is recommended to always compute the MACs on the
ciphertext and to use two distinct keys, one key for encryption and another for MAC generation.
● Another recommendation to prevent attacks is to limit the number of MACs generated with the same key, because in case a
large number of tags are generated with the same key, collisions may be observed and their exploitation may be catastrophic.
The maximum number of MACs per key depends on each authenticated-encryption algorithm, as discussed in the sequel.
function CMAC_Subkey_Generation
input b: block cipher bit-length (b = 64 for TDEA and b = 128 for AES)
K : key (with a bit-length complying with either AES or TDEA)
output K1, K2: subkeys
1. # R is a binary constant, which only depends on the bit-length block of
# the underlying block cipher. R starts with sequence of “0” bits of a
# bit-length of either 59 (for TDEA) or 120 (for AES).
if b = 64, then R = 0(59 )11011 else R = 0(120 )10000111
2. # L is a block that consists of b “0” bits encrypted with key K
( )
L = EncK 0( b )
3. if MSB1 ( L ) = 0 then K1 = L 1
else K1 = ( L 1) ⊕ R
4. if MSB1 (K1 ) = 0 then K2 = K1 1
else K2 = (K1 1) ⊕ R
5. return (K1 , K2 )
function CMAC_MAC_Generation
input b: block cipher bit-length (b = 64 for TDEA and b = 128 for AES)
K : key (with a bit-length complying with either AES or TDEA)
Tlen: MAC bit-length; P: plaintext of bit-length Plen
output T : tag of bit-length Tlen
1. # Generate subkeys
(K1 , K2 ) = CMAC _Subkey _Generation( K , b )
2. # n is the number of blocks to process
len( P )
if len( P ) = 0 then n = 1 else n =
b
3. # Split the plaintext into n blocks P1,…, Pn−1, Pn* all the blocks but one
# have the same length of b bits.
( )
# i.e. len (Pi ) = b,1 ≤ i < n and 0 < len Pn* ≤ b
Let P = P1 || P2 || … || Pn−1 || Pn*
( )
4. if len Pn* = b then Pn = K1 ⊕ Pn*
(
else j = n * b − Plen − 1; Pn = K2 ⊕ Pn* || 1 || 0 j )
5. C0 = 0b
6. for i = 1 to n do Ci = EncK (Ci−1 ⊕ Pi )
7. T = MSBTlen (C n )
8. return T
9.2 Block Cipher Modes of Operation for Confidentiality and Authentication 285
function CMAC_MAC_Verification
input b: block cipher bit-length (b = 64 for TDE and b = 128 for AES)
K : key (with a bit-length complying with either AES or TDEA)
Tlen: MAC bit- length; p: plaintext; T : tag of bit-length Tlen
output V : Decision (“Valid” or “Invalid”)
1. # Compute the tag of plaintext P
T ′ = CMAC _MAC _Generation( b, K ,Tlen, P )
2. # Check if both tags are identical or not
if T = T ′ then return “Valid” else return “Invalid”
4) The MAC T is XORed with Enc K (Ctr0 ), so that only the recipient holding the secret key can recover the tag.
The MAC generation and encryption algorithm of CCM is given below and depicted in Figure 9.4.
function CCM_MAC_GenenerationAndEncryption
input K : key (with a bit-length complying with a 128-bit block cipher)
Tlen: MAC bit-length; N : nonce; P: payload of bit-length Plen
A: associated data of bit-length Alen, which may be empty.
output C , Tag: ciphertext and an encrypted tag
1. # Represent the input (N , A, P ) as r 128-bit blocks
(B0,…, Br ) = InformationFormatting( N , A, P )
2. # Tag computation: encryption of nonce, associated data, and payload
Y0 = EncK (B0 )
for i = 1 to r do Yi = EncK (Bi ⊕ Yi−1 )
T = MSBTlen (Yr ) # T is the tag in clear
3. # Ciphertext computation
3.1 # Compute m + 1 formatted counter values (m is the number of
# blocks in the payload)
(Ctr0 , … , Ctrm ) = CounterFormatting( m, N )
3.2 for j = 0 to m do S j = EncK (Ctrj )
3.3 S = S1 || S2 || … || S m
3.4 CC = P ⊕ MSBlen( P ) ( S ) # Encryption of payload
4. # Encryption of the tag
Tag = T ⊕ MSBTlen (S 0 )
5. return (CC , Tag )
function CCM_MAC_VerificationAndDecryption
input K : key (with a bit-length complying with a 128-bit block cipher)
Tlen: MAC bit-length; N : nonce of bit-length Nlen
C: ciphertext of bit-length Clen; A: associated data of bit-length Alen
output V : Decision (“Valid” or “Invalid”)
P: plaintext of bit-length Plen
1. # Check the length of the ciphertext
if Clen ≤ Tlen , then return “Invalid”
2. # Payload recovery
2.1 # Compute m +1 formatted counter values
m = (Clen − Tlen ) / 128
(Ctr0 , … , Ctrm ) = CounterFormatting( m, N )
2.2 for j = 0 to m do S j = EncK (Ctrj )
2.3 S = S1 || S2 || … || S m
2.4 P = MSBClen−Tlen (C ) ⊕ MSBClen−Tlen ( S )
3. # Recover the tag included in ciphertext
T = LSBTlen (C ) ⊕ MSBTlen (S 0 )
4. # Apply the information formatting function to produce r
# and encrypt them to produce a tag T ′ of the received payload
4.1 (B0,…, Br ) = InformationFormatting( N , A, P )
4.2 Y0 = EncK (B0 )
4.3 for i = 1 to r do Yi = EncK (Bi ⊕ Yi−1 )
4.4 T ′ = MSBTlen (Yr )
5. # Tag check
if T ′ = T, then return (“Valid”, P)
else return “Invalid”
Notice that since q −1 is represented on three bits, q cannot be greater than 8. Therefore, the maximum byte-length of
payload is p < 28* q < 28*8.
The remaining 15 bytes of block B0 are used to represent the nonce and the payload length. The nonce value is repre-
sented on 15 − q bytes. Notice that the parameter q bounds the nonce space, i.e. the number of distinct nonces
8*(15−q)
is 28*n < 2 .
Formatting the associated data
The second bit of the first byte of block B0 indicates whether associated data is present or not. If a > 0, then the associated
data and its length are represented on u blocks B1, …, Bu. The associated-data byte-length a is represented according to three
cases:
1) If 0 < a < 216 − 28 , then a is represented as [a]16 , i.e. on two bytes.
2) If 216 − 28 ≤ a < 232 , then a is represented as 0 xff || 0 xfe || [a]32 , i.e. on six bytes.
3) If 232 ≤ a < 264 , then a is represented as 0 xff || 0 xff || [a]64 , i.e. on ten bytes.
Then, a is followed by the associated data. If bytes used to represent the associated data and its length are not a multiple of
128 bits, then a string of 0-bits is appended to fill the last block Bu.
Formatting the payload
The payload is represented as blocks denoted Bu+1 , …, Br , where r = u + p /16 .
function GCTR
input K: Key (with a bit-length complying with a 128-bit block cipher)
P: plaintext, a bit string; ICB: initial counter block (128 bits)
output C: ciphertext
1. # m is the number of blocks in bit string P . Pm* , the last block, may be incomplete
m = len( X ) / 128; Let P = P1 || P2 || … || Pm−1 || Pm*
2. # Compute the counter blocks
Cnt1 = ICB
for i = 2 to m do Cnt i = Inc32 (Cnt i−1 )
290 9 Block Cipher Modes of Operation for Authentication and Confidentiality
(
GHashH ( D) = D1 ⊗ H m ) ⊕ ( D2 ⊗ H m−1 ) ⊕…⊕ ( Dm−1 ⊗ H 2 ) ⊕ (Dm ⊗ H )
where H denotes the hash key; and ⊗ is the multiplication operation, defined over extension field F2128 , with the irreducible
polynomial f ( x ) = x 128 + x 7 + x 2 + x + 1. (For more on multiplication over extension fields see Section 3.2.3).
D = D1 || D2 || … || Dm where D1 , D2 , …, Dm are 128-bit blocks and m = len( D) /128.
GCM standard provides an efficient method to implement the multiplication over the chosen finite field and its irreduc-
ible polynomial. As chosen below the multiplication algorithm only makes use of XOR and shift operations, which are very
useful to speed the multiplication. The convention for interpreting strings as polynomials is little endian; i.e. the
block U = u0u1 …u127 corresponds to the polynomial P (U ) = u127 x 127 + u126 x 126 +…+ u1 x + u0.
function GCM_Block_Multiplication
input P , Q : two 128-bit blocks
output Z : product
1. Let p0 p1 p2 ...p127 be the bit sequence of block P
2. Z 0 = 0128 # Z 0 is set to a string of 128 “0” bits
V0 = Q ; R = 11100001 || 0120
3. for i = 0 to 127 do
if pi = 0 then Z i +1 = Z i else Z i ⊕ Vi
if LSB1 (Vi ) = 0 then Vi +1 = Vi 1 else Vi +1 = (Vi 1) ⊕ R
4. return Z128
● IV : an initialization vector, which is a unique value (i.e. a nonce) associated with each plaintext; its bit-length is
denoted IVlen. The latter may take a value of 64, 96, 128, or 160. The total number of invocations of the authenticated-
encryption algorithm shall not exceed 232 , including all IV lengths, with the same key.
The algorithm of encryption and Tag generation of GCM is given below and also depicted in Figure 9.8.
function GCM_Authenticated_Encryption
input K : key (with a bit-length complying with a 128-bit block cipher)
P: plaintext; A: associated authentication data
IV : initialization vector; Tlen: tag bit-length (≤ 128)
output C: ciphertext (of same length than that of plaintext)
T : tag (of Tlen bits)
(
1. H = EncK 0128 )
2. J0 is computed to serve as the initial value of the counter in CTR mode
if len(IV ) = 96, then J0 = IV || 031 || 1
if len(IV ) ≠ 96, then
s = 128 * len(IV ) / 128 − len(IV )
( )
J0 = GHashH IV || 0 s+64 || len (IV )
64
3. # Compute the ciphertext C
C = GCTRK (Inc32 ( J0 ), P )
4. # u and v denote the lengths of the incomplete ciphertext block and
# associated data if applicable, respectively
u = 128 * len(C ) / 128 − len(C ); v = 128 * len( A ) / 128 − len( A )
5. # Compute and encrypt the tag
( )
S = GHashH A || 0v || C || 0u || len( A )64 || len(C ) 64
T = MSBTlen (GCTRK ( J0 , S ))
6. return (C , T )
function GCM_Authenticated-Decryption
input K : key (with a bit-length complying with a 128-bit block cipher)
C: ciphertext; T : tag (of Tlen bits); Tlen: tag bit-length (≤ 128)
A: associated authentication data; IV : initialization vector
output V : Decision (“Valid” or “Invalid”)
P: plaintext (of the same length than that of ciphertext)
(
1. H = EncK 0128 )
2. # J0 is computed to serve as the initial value of the counter
if len(IV ) = 96, then J0 = IV || 031 || 1
if len(IV ) ≠ 96, then
s = 128 * len(IV ) / 128 − len(IV )
( )
J0 = GHashH IV || 0 s+64 || len(IV )64
3. # Compute the plaintext P
P = GCTRK (Inc32 ( J0 ), C )
4. # u and v denote the length of the incomplete ciphertext block and
# associated data if applicable, respectively
u = 128 * len(C ) / 128 − len(C ); v = 128 * len( A ) / 128 − len( A )
5. # Compute and encrypt the tag
( 64 )
S = GHashH A || 0v || C || 0u || len( A ) || len(C )
64
T ′ = MSBTlen (GCTRK ( J0 , S ))
6. if T ′ = T, then return (“Valid”,P) else return “Invalid”
292 9 Block Cipher Modes of Operation for Authentication and Confidentiality
( )
T (1) = GCTRK J 0 , S (1) = S (1) ⊕ Enc K ( J 0 )
( )
T (2) = GCTRK J 0 , S (2) = S (2) ⊕ Enc K ( J 0 )
where:
J 0 is the initial counter derived from the IV
( ) (
C (1) = GCTRK J 0 + 1, M (1) and C (2) = GCTRK J 0 + 1, M (2) are the ciphertexts. )
(
S (1) = GHashH C (1) || 0u || len ( A) || len C (1)
64 64
( ) )
S (2) = GHashH (C (2)
|| 0u || len ( A′) ||
64 ( )
len C (2)
64 )
S (1) and S (2) are the tags, in cleartext. Assuming that plaintexts M (1) and M (2) are one-block each and no associated data is
used:
( )
S (1) = GHashH C (1) || [0]64 || [1]64 = GHashH C (1) || [1]128 ( )
( )
S (2) = GHashH C (2) || [0]64 || [1]64 = GHashH C (2) || [1]128 ( )
For both tags, the input of function GHashH is a two-block string.
Tags S (1) and S (2) are computed with the GHashH function as follows:
( ) ( ) (
S (1 ) = C (1 ) ⊗ H 2 ⊕ 1 ⊗ H 1 = C (1 ) ⊗ H 2 ⊕ H ) (9.1)
( ) ( ) (
S (2) = C (2) ⊗ H 2 ⊕ 1 ⊗ H 1 = C (2) ⊗ H 2 ⊕ H ) (9.2)
The encrypted tags and ciphertexts are known to the adversary and both plaintexts are encrypted with the same IV. Thus,
( ) (
T (1) ⊕ T (2) = S (1) ⊕ Enc K ( J 0 ) ⊕ S (2) ⊕ Enc K ( J 0 ) = S (1) ⊕ S (2)) (9.3)
( )
T (1 ) ⊕ T ( 2 ) = C (1 ) ⊕ C ( 2 ) ⊗ H 2 (9.4)
Since the function GHashH is defined over the extension field F2128 with the irreducible polynomial f ( x ) = x 128 + x 7 + x 2 + x + 1,
(9.4) can be rewritten as:
−1
( )(
H 2 = T (1 ) ⊕ T ( 2 ) * C (1 ) ⊕ C ( 2 ) ) mod f ( x ) (9.5)
−1
(C (1) ⊕ C (2) ) and (T (1) ⊕ T (2) ) are constants; and H is the unknown. Finding the square root of (T (1) ⊕ T (2) )* (C (1) ⊕ C (2) )
over F2128 yields the value of H. Notice that in the binary field, H and −H are the same.
294 9 Block Cipher Modes of Operation for Authentication and Confidentiality
m−1
In general, the square root of an element x ∈ F2m is defined by: x = x 2 , if 2m−1 is a prime (see Corollary 3.4). Finally,
H is given by the following:
127
−1
( )(
H = T (1) ⊕ T (2) * C (1) ⊕ C (2)
)
mod f ( x ) (9.6)
It is worth noticing that in general, GHashH function yields a polynomial of degree m, which depends on the number of
blocks in the plaintext and the associated data. In consequence, the number of roots of the polynomial inferred
from S (1) ⊕ S (2) may be high, if messages are longer than one block and/or associated data is used; and the adversary may
decide which root (i.e. which authentication key H to keep) among a large set to forge tags. To increase the chance of suc-
cess in choosing the correct authentication key, the adversary may need to collect many pairs of messages encrypted with
the same IV, each pair providing a set of roots. Then, combining the roots yielded by all pairs helps to find a single root (i.e.
the valid authentication key) that matches all the pairs. Therefore, the forbidden attack against AES-GCM is likely to suc-
ceed only if the sender either encrypts plaintexts with small sizes or frequently makes use of the same IV to generate tags.
function AES_GCM_SIV_KeyDerivation
Input K : key (of a bit-length of 128 or 256)
N : nonce (96 bits)
output K _hash : authentication key (128 bits)
K _msg: encryption key (128 or 256 bits)
1. if len( K ) = 128 then Nb_iter = 4 else Nb_iter = 6
2. for i = 0 to Nb_iter −1 do
# integers are in little-endian encoding
Ti = MSB64 ( AES _EncK _msg ([i ]32 || N ))
3. K _hash = T0 || T1
4. if len( K ) = 128 then K _msg = T2 || T3
else K _msg = T2 || T3 || T4 || T5
5. return (K_hash , K_msg )
where H denotes the hash key and ⊗ is the multiplication operation defined over extension field F2128 with the irreducible polyno-
mial f ( x ) = x 128 + x 127 + x 126 + x 121 + 1, and D = D1 || D2 || … || Dm . D1 , D2 , …, Dm are 128-bit blocks and m = len( D) /128.
Notice that x −128 can also be written as x 127 + x 124 + x 121 + x 114 + 1 in F2128 with f ( x ) = x 128 + x 127 + x 126 + x 121 + 1.
Differences between PolyvalH andGHashH functions:
Both functions are defined over extension field F2128 , but with different irreducible polynomials:
f ( x ) = x 128 + x 127 + x 126 + x 121 + 1 for PolyvalH and f ( x ) = x 128 + x 7 + x 2 + x + 1 for GHashH . The little-endian represen-
tation of the first polynomial is 10 (120 )10000111 and that of the second polynomial is 111000010 (120 )1 . Therefore, those
irreducible polynomials are the “reverse”, in little-endian representation, of each other. Both functions use little-endian
encoding; but they make use of different mappings to/from 128-bit strings and extension field elements. Let
U = U 0U1U 2U 3U 4U 5U 6U 7U 8U 9U10U11U12U13U14U15 be a 16-byte string. Let U 0 = b0b1b2b3b4b5b6b7, …, U15 = b120b121b122b123b124
b125b126b127 , where bis are bits.
PolyvalH takes the least significant bit (i.e. b7) to most significant bit (i.e. b0 ) of byte U 0 to be the coefficients of x 0 to x 7 ,
while GHashH takes them to be the coefficients of x 7 to x 0 . The same mapping continues until the last byte U15 where
PolyvalH takes the least significant bit b127 to most significant bit b120 of byte U15 to be the coefficients of x 120 to x 127, while
GHashH takes them to be the coefficients of x 127 to x 120.
Example 9.2
Consider the polynomial Q( x ) = x 127 + x 124 + x 121 + x 114 + 1. Q ( x ) is represented as 0100000000000000000000000000 0492
in AES-GCM-SIV and as 80 000000000000000000000000000020 49 in AES-GCM.
1) Key derivation: from the master key K and the nonce N , two keys are derived: K _hash of 128-bit length and K _msg of
128 or 256-bit length.
2) Hash generation: the PolyvalK _Hash hash function takes the hash key K _hash , the padded associated data, the padded
plaintext, and the data lengths len( A) and len( P ) and returns a hash. The generated hash is encrypted with the encryp-
tion key K _msg.
3) Plaintext encryption: it is performed with a CTR encryption taking the key K _msg and the encrypted tag as the initial
counter value. The CTR mode used in AES-GCM-SIV is very similar to that used in AES-GCM; the minor difference is
in counter incrementing due to integer encoding.
The authenticated encryption of AES-GCM-SIV algorithm is given below and is illustrated by Figure 9.10.
function AES_GCM_SIV_CTR
input K _msg: encryption key (of 128 or 256 bits)
P : plaintext, a bit string no longer than 236 bits
InitialCtr: initial counter block (128 bits)
output C : ciphertext (of the same bit-length than the plaintext)
1. # m is the number of blocks in bit string P . Pm* , the last block can be incomplete.
m = len( X ) / 128; Let P = P1 || P2 || … || Pm−1 || Pm*
2. # Compute the counter blocks: the initial counter block is the tag
# with the most significant bit of the last byte set to 1. Then, the
# counter advances by incrementing the first 32 bits.
Cnt1 = InitialCtr
for i = 2 to m do
# Convert the first four bytes of Cnt i−1 from little-endian encoding
function AES_GCM_SIV_AuthenticatedEncryption
input K : master key (of 128 or 256 bits)
P : plaintext, a bit string no longer than 236 bits
A : associated data, a bit string no longer than 236 bits
N: nonce (of 96 bits)
output C : ciphertext (of the same bit length than the plaintext)
Tag : encrypted tag (of a length of 128 bits)
1. # Key derivation
( K _hash, K _msg ) = AES _GCM_SIV _KeyDerivation( K , N )
2. # Tag computation (note: integers are in little-endian encoding)
2.1 L = len( A ) || len( P )
64 64
2.2 # pad the plaintext and associated data to multiple of 128 bits
P _Pad = Right _pad ( P ); A_Pad = Right _pad ( A )
2.3 h = PolyvalK _ hash ( A_Pad || P_Pad || L) # h is the tag in clear
2.4 # XOR the first twelve bytes of h with the nonce
for i = 0 to 11 h[i ] = h[i ] ⊕ N [i ]
# Clear the most significant bit of the last byte of h.
h 15 = h 15 & 0X7F # “&” denotes the bitwise AND operator
2.5 # Tag encryption. Notice that AES-GCM-SIV encrypts
# directly the tag with the AES encryption operation, while
# the AES-GCM mode encrypts the tag using the CTR mode
.Tag = AES _EncK _msg ( h )
3. # Plaintext encryption
3.1 # The initial counter block is the encrypted tag with the most
# significant bit of the last byte set to 1.
# “|” denotes the bitwise OR
InitialCtr = Tag ; InitialCtr [15] = InitialCtr [15] | 0x80
3.2 C = AES _GCM_SIV _CTR( K _msg, InitialCtr , P )
4. return (C , Tag )
function AES_GCM_SIV_AuthenticatedDecryption
input K : master key (of 128 or 256 bits)
C: ciphertext, a bit string no longer than 236 bits
Tag: tag, a bit string of 128 bits
A: associated data, a bit string no longer than 236 bits
N : nonce, a bit string of 96 bits
output P: plaintext (of the same bit-length than the ciphertext)
V : Decision (“Valid” or “Invalid”)
1. # Key derivation
298 9 Block Cipher Modes of Operation for Authentication and Confidentiality
9.2.6 Poly1305
Poly1305 is a fast algorithm to generate message tags. Initially Poly1305 was proposed under the name Poly1305-AES to be
used jointly with AES [5]. Poly1305 is not yet approved by the NIST as a mode of operation of AES. However, it is recom-
mended as one of the schemes to build AEAD algorithms used in TLS [6]. In TLS, the Poly1305 is used jointly with the
stream cipher ChaCha20 (see Section 6.2.5); and their combination is referred to as ChaCha20-Poly1305 AEAD.
9.2.6.1 Poly1305-AES
To generate a tag, Poly1305-AES makes use of:
● One-time5 key of 32 bytes divided into two equal-size keys
● an AES-128 key, denoted s, and an additional 128-bit key, denoted r; r[0], r[1], …, r[15] denote the bytes of the additional
key
● a 128-bit nonce, n
● a message m of variable byte-length
Additional key r
The additional key r is not used to encrypt or decrypt. It is an integer in little-endian encoding,
i.e. r = r[0] + 28 r[1] + 216 r[2] +…+ 2120 r[15]. r must be a positive integer with the following restrictions:
● The four most-significant bits of bytes r[3], r[7], r[11], and r[15] must be zeros; i.e. r[3], r[7], r[11], and r[15] take values
smaller than 16.
● The two least-significant bits of bytes r[4], r[8], and r[12] must be zeros; i.e. r[4], r[8], and r[12] take values divisible by 4.
r can be obtained by picking a random integer z in interval [0, 2128 ( and applying the “and” operation (denoted ∧) to z in
big-endian, using a mask as follows:
r = z ∧ 0f ff ff fc 0f ff ff fc 0f ff ff fc 0f ff ff ff 16
function ConvertPadMessage
input m: message of l bytes
output c: converted message
1. q = Blen( m ) / 16 # q: number of segments in message m
# Only the last segment can be incomplete
# Message segments are interpreted as integers in little-endian
# encoding. Appending a complete segment with a byte of value 1
# is equivalent to adding 2128 to integer representing the segment.
2. for i = 1 to Blen( m ) / 16 # Blen( m ) means the byte-length of m
# map each 16-byte of message m to a 17-byte segment in c
2.1 for j = 16 to 1 do: c[i ] = c[i ] + m 16 * i − j * 28(16− j )
2.2 c[i ] = c[i ] + 2128
3. if (Blen( m ) mod 16) ≠ 0, then
3.1 z = Blen( m ) − 16 * q ; c[q ] = 28* z
3.2 for j = 16 to z do: c[q] = c[q ] + m 16 * i − j * 28(16− j )
4. return c
Tag generation
Given a one-time key (r , k ) , a nonce n, and a message m, which is transformed to a message c, the tag computation is
defined by:
mod 2130 − 5 + Enc (n) mod 2128
(
Poly1305 AES (m,(r , s ), n) = ∑ ci * r ( q−i+1) ) ( ) s
i=1,…,q
Security of Poly1305-AES L
Poly1305-AES scheme is designed to ensure that a forged message is rejected with a probability of 1 − 14 * 2−106 for a L-byte
16
message, even after having observed 264 legitimate authenticated messages; thus, it is resistant against tag forgery attacks [5].
9.2.6.2.1 Poly1305-mac
To generate a tag for a plaintext m, Poly1305-mac takes the following inputs:
● 32-byte master key K, the key used to encrypt
● 96-bit nonce n
● Message m of arbitrary byte-length
Tag generation follows three steps:
1) One-time key generation: the master key K, the nonce n, and a counter with value 0 are used as input of ChaCha20 to
produce a 64-byte keystream block Y . Only the leftmost 32 bytes of the block Y are used: r = Y [0 : 15] and s = Y [16 : 31].
Then, r is clamped to set to 0 some bits of bytes r[3], r[4], r[7], r[8], r[11], r[12], and r[15], exactly as in Poly1305-AES.
2) Message m is converted and mapped as in Poly1305-AES to yield a padded plaintext c.
3) Tag is computed according the following formula:
( ) ( )
t = ∑ ci * r (−i+1) mod 2130 − 5 + s ) mod 2128
i=1, …, q
Note. Poly1305mac does not encrypt the nonce n, while Poly1305-AES does. Poly1305mac makes use of the nonce to gen-
erate a one-time key (r , s ) , while Poly1305-AES assumes that the one-time key is given as input. In Poly1305mac, the
component s of the one-time key is the half of a keystream block generated by ChaCha20; therefore, the encryption of the
nonce in Poly1305-AES is equivalent to s in Poly1305mac.
300 9 Block Cipher Modes of Operation for Authentication and Confidentiality
function Poly1305mac
input K : 32-byte key; n: 96-bit nonce
m: message of arbitrary byte-length
output t: tag of 128 bits
1. z = ChaCha20( K , 0, n ) # generate a 64-byte keystream string
2. r = z[0 : 15]; s = z[15: 31]
3. r = r ∧ 0ffffffc 0ffffffc 0ffffffc 0fffffff 16# Clamp r
4. c = ConvertPadMessage( m )
( ) ( )
5. t = ∑ ci * r ( q−i +1) mod 2130 − 5 + s mod 2128
i =1, …, q
6. return t
9.2.6.2.2 AEAD-ChaCha20-Poly1305
ChaCha20 and Poly1305mac can be combined to build an AEAD, called AEAD-ChaCha20-Poly1305. To encrypt and gen-
erate a tag for a plaintext P, AEAD-ChaCha20-Poly1305 takes the following inputs:
● 256-bit encryption key K.
● 96-bit nonce n.
● Plaintext P of arbitrary byte-length of at most (nearly) 256 G bytes.
● Optional additional data A of at most 264 − 1 bytes.
It performs the following operations:
1) Generate a one-time key (r , s ) , using the encryption key K and the nonce n.
2) Plaintext P is encrypted by ChaCha20, using key K; the ciphertext is denoted C.
3) A tag t is produced by Poly1305mac, using a byte string MacData composed as follows: MacData = A ||
Append16( A) || C || Append16(C ) || LenA || LenC where Append16(Y ) is a 0-string, such that the length of
Y || Append16(Y ) is multiple of 16; LenA is the byte-length of the additional data A, and LenC , that of the plaintext P.
LenA and LenC are represented on 64 bits, each.
Figure 9.11 illustrates the structure of AEAD-ChaCha20-Poly1305 encryption; and its pseudocode is as follows:
function AEAD_ChaCha20_Poly1305Encrypt
input K : 256-bit key; n: 96-bit nonce
P: message of arbitrary byte-length
A: additional data (optional)
output C , t : ciphertext and 128-bit tag
1. C = ChaCha20( K , 1, n, P ) # encrypt the plaintext
2. MacData = A || Pad16( A ) || C || Pad16(C ) || Blen( A )64 || Blen(C )64
3. t = Poly 1305mac( MacData, K , n )
4. return (C , t )
Definition 9.6 Key wrapping: it is a symmetric cryptographic scheme, which provides confidentiality and integrity guar-
antees for cryptographic keys when exchanged between parties; i.e. it is a method of encrypting and decrypting keys using
symmetric-key cryptography.
Key wrapping modes differ from the other authenticated-encryption modes presented in previous subsections:
● They do not generate a tag. Rather, they append (on the left of the plaintext) a constant-bit string, which is encrypted
together with the plaintext, and then the decryption succeeds only if the constant-bit string is recovered at the beginning
of the decryption output.
● They do not provide capacity to use associated data.
● They do not provide capacity to generate signatures. Recall that tags are required to generate signatures.
One may think about key wrapping as a mode of operation where the encryption of each bit of input is dependent on every
other bits of input in all the blocks in a non-trivial way. In other words, key wrapping modes are based on the input
diffusion.
The three key wrapping modes are called KW (AES Key Wrap), KWP (KW with Padding), and TKW (Triple DEA Key
Wrap) [7]. For KW and KWP, the underlying block cipher is AES with the key length of 128, 192, or 256 bits. For TKW, the
underlying block cipher is TDEA with the key length of 56 bits.
function KW_Authenticated_Encryption
input K: key (with approved bit-length)
P : plaintext, a string of n semiblocks (2 ≤ n ≤ 254 − 1)
output C : ciphertext
1. S = 0xA6 A6 A6 A6 A6 A6 A6 A6 || P
2. C = W ( S )
3. return C
function KW_Authenticated_Decryption
input K : key (with approved bit-length)
C: ciphertext, a string of n semiblocks (3 ≤ n ≤ 254 )
output P: plaintext; V : “Valid” or “Invalid”
1. S = W −1 (C )
2. # Check
2.1 if MSB64 ( S ) ≠ 0xA6 A6 A6 A6 A6 A6 A6 A6, then return “Invalid”
2.2 else P = LSB64 *(len(C )−1)( S )
2.3 return ( P, “Valid ”)
function KWP_Authenticated_Encryption
input K : key (with approved bit-length)
P: plaintext, a byte-string of length in [1..232 − 1] bytes
output C: ciphertext
1. # Pad the plaintext, so that the byte-string to encrypt is of a
# length multiple of semiblock byte-length.
len ( P ) len ( P )
lenPAD = 8 * −
64 8
len ( P )
2. S =0xA65959 A6 || || P || 0(8∗ lenPAD )
8 32
3. if len( P ) ≤ 64, then C = EncK ( S ) else C = W ( S )
4. return C
function KWP_Authenticated_Decryption
input K : key (with approved bit-length)
C: ciphertext, a byte-string of a length in 2..229 semiblocks.
output P: plaintext of the same length than that of input C
V : “Valid” or “Invalid”
1. n = len(C ) / 64 # n is the number of semiblocks in C
2. if n = 2, then S = DecK (C ), else S = W −1 (C )
3. if MBS32 ( S ) ≠ 0xA65959 A6 , then return “Invalid”
4. if MBS32 ( S ) = 0xA65959 A6 , then
4.1 Plen = int ( LSB32 (MBS64 ( S ))
4.2 lenPAD = 8 * ( n − 1) − Plen
4.3 if lenPAD < 0 or lenPAD > 7, then return “Invalid”
4.4 if LBS8*lenPAD ( S ) ≠ 08*lenPAD , then return “Invalid”
4.5 P = MSB8*Plen (LSB64 *( n−1) ( S ))
4.6 return (“Valid”, P )
Wrapping function W takes a string S and splits it into n semiblocks. It makes use of internal variables At and Rit with
t = 1, …, s , s = 6(n − 1), i = 1, …, n. Wrapping function W runs s steps and in each step t (t = 1, …, s ), it performs an AES
9.2 Block Cipher Modes of Operation for Confidentiality and Authentication 303
encryption and it updates variables At and Rnt. The variables Rkt, with 2 ≤ k < n, are updated using the values of the previous
iteration as follows: Rkt = Rkt−+11.
The complete algorithm is given below. Notice that: 1) the encryption starts with A0 , which is equal to the constant
value 0 xA6 A6 A6 A6 A6 A6 A6 A6 , then the encryption output is propagated to the subsequent iterations, 2) the constant
value is the only way to check the authenticity and its encryption is embedded in all the ciphertext bits. Therefore, no tag
is generated. Figure 9.12 depicts the operations of wrapping function W for encrypting four semiblocks S1 , S2 , S3 , S4 . Figure
9.13 illustrates a wired representation of wrapping function W with four semiblocks. The wired representation is a struc-
ture composed of 6( 4 − 1) = 18 rectangles connected each other. Each rectangle represents an encryption operation: the
two wires on the left represent two semiblocks to encrypt and the wires on the right represent two (intermediate) ciphertext
semiblocks. The wires on the top convey the most significant 64 bits and the wires on the bottom the least significant 64
bits of the input or the output of the AES encryption.
function W
input K: key (with approved bit-length)
S : plaintext, a string of n semiblocks (n ≥ 3)
output C: ciphertext of the same length than that of input S
1. # Variable initialization
1.1. s = 6 * ( n − 1)
1.2. Let S = S1 || S2 || … || S n # S i =1,…,n are semiblocks of S
1.3. A0 = S1
1.4. for i = 2 to n do Ri0 = .S i.
2. # Compute intermediate ciphertexts
for t = 1 to s do
( (
2.1. At = MSB64 EncK At −1 || R2t −1 ⊕ [t ]64 ))
2.2. for i = 2 to n −1 do Rit = Rit+−11
(
2.3. Rnt = LSB64 EncK A ( t −1
))
|| R2t −1
3. # Function output
3.1. C1 = A s
3.2. for i = 2 to n do Ci = Ris
3.3. C = C1 || C2 || … || C n; return C
The unwrapping function W −1 decrypts a ciphertext using the inverse operations of wrapping function W. Its algorithm is
given below.
function W −1
input K : key (with approved bit-length)
C: ciphertext, a string of n semiblocks (n ≥ 3)
output P: plaintext of the same length than that of input C
1. # Initialize the variables
1.1. s = 6 * ( n − 1)
1.2. Let C = C1 || C2 || … || C n # Ci =1,…, n are semiblocks of C
1.3. A s = C1
1.4. for i = 2 to n do Ris = Ci
2. # Compute intermediate plaintext values
for t = s to 1 do
( ((
2.1. At −1 = MSB64 DecK At ⊕ [t ]64 || Rnt ) ))
2.2. R2t −1 = LSB64 (Dec (( A ⊕ [t ] ) || R ))
K
t
64
t
n
function TKW_Authenticated_Encryption
input K: key (with approved bit-length)
P: plaintext, a string of n semiblocks (2 ≤ n ≤ 228 − 1)
output C : ciphertext of the same the bit-length than input P
1. S = 0xA6 A6 A6 A6 || P
2. C = TW ( S ); return C
function TKW_Authenticated_Decryption
input K : key (with approved bit-length)
(
C: ciphertext, a string of n semiblocks 3 ≤ n ≤ 228 )
output P: plaintext of the same the bit-length than input C
V : “Valid ” or “InValid”
1. S = TW −1 (C )
2. if MSB32 ( S ) ≠ 0 xA6A6A6A6, then return “Invalid”
else P = LSB32*( len(C ) −1 ( S ); return (“ Valid ”, P)
The wrapping function TW and unwrapping function TW − 1 are the same as the functions W and W −1 where the used
semiblock length is 32 instead of 64 and the encryption/decryption primitives are those of TDEA. To build functions TW
and TW −1, substitute, in the algorithms described in 9.2.7.1, MSB32 to MSB64 , LSB32 to LSB64 , and [t ]32 to [t ]64.
by the attacker, and the recipient tag verification process validates all the (re)sent messages. However, since the plaintext
is sent in clear, detection of plaintext repetitions does not matter in CMAC.
CCM, GCM, and AES-GCM-SIV are based on CTR and CBC mode with a nonce. Therefore, replay attacks can be easily
detected. Since all those three modes make use of a nonce, they hide plaintext repetitions.
Exercise 9.1
Consider a user who encrypts and generates tags for files of 1 G bytes using CCM. How many files can he/she process
before changing the key? Hint: observe the information formatting function.
Problem 9.1
CMAC is known to be an improvement of CBC-MAC7 algorithm. Both algorithms perform exactly the same operations
until the last plaintext block Pn. In CBC-MAC, the last block Pn is directly encrypted, while in CMAC, it is XORed with a
subkey before being encrypted in step 4 of tag generation algorithm. CBC-MAC does not make use of subkeys K1 and K 2.
Assume that the tag bit-length is the same as that of a block and the plaintext length is a multiple of block length (i.e. we
consider a tag generator without truncation of the final ciphertext and without padding the last plaintext block). Show that
CBC-MAC is vulnerable to the following MAC forgery attack, while CMAC is not: given two plaintexts and their tags, the
adversary can generate a forged plaintext with a valid tag without knowing the key.
9.3 Exercises and Problems 307
Problem 9.2
In order to generate 128-bit tags for plaintexts of a bit-length multiple of 128, Bob modifies the standard CMAC by substi-
tuting addition mod 997 to XOR operations, i.e. instead of computing A ⊕ B , as in the original CMAC, he computes
( A + B ) mod 997. Bob tries three MAC schemes:
1) Scheme 1: Bob sends an encrypted 3-block message to the bank including an amount of money to transfer to Eve and
the amount is encoded in the second block. Eve intercepts a message containing an amount of $25. How can Eve
increase the amount she will receive, while the final tag does not change?
2) Scheme 2: Bob sends an encrypted 3-block message to the bank including an amount of money to transfer to Eve and
the amount is encoded in the third block (i.e. the last block). Eve intercepts a message containing an amount of $25.
How can Eve increase the amount she will receive, while the final tag does not change?
3) Scheme 3: Bob sends an encrypted 3-block message to the bank including an amount of money to transfer to Eve and
the amount is encoded in an incomplete third block (i.e. only the five first bits of the third block are used in the plain-
text). Eve intercepts a message containing an amount of $25. How can Eve increase the amount she will receive, while
the final tag does not change?
Problem 9.3
Consider the following variant of CMAC intended to generate tags for messages of arbitrary lengths, which are multiples
of the block length. The construction uses a block cipher E : {0,1}k × {0,1}n → {0,1}n, which is assumed to be secure, and
computes a tag T for message M as T = MAC ( M , K ) = CBC K ( M || l), where l is the bit-length of M represented on n bits.
Show that the construction is insecure under chosen-plaintext attack; i.e. an adversary who can get tags of some plaintexts
can forge a tag.
Problem 9.4
Consider the following variant of CMAC intended to generate tags for messages of arbitrary lengths, which are multiples
of the block length. The construction uses a block cipher E : {0,1}k × {0,1}n → {0,1}n, which is assumed to be secure. The
secret key is a pair ( K , K ′). The construction takes a message M and computes a tag T as follows:
T = MAC ( M ,( K , K ′)) = CBC K ( M ) ⊕ K ′ . K ′ is of a block bit-length n, while K is of a bit-length of k, the cipher key bit-
length. CBC is used with an IV of a fixed value 0. Show that the construction is insecure under the chosen-plaintext attack;
i.e. an adversary who can get the tags of some plaintexts can forge a tag.
Problem 9.5
This problem addresses vulnerabilities of CMAC when a set of messages is processed with the same key assuming that the
tag bit-length is the same as that of a block and the plaintext length is a multiple of block length (i.e. we consider a CMAC
without performing truncation of the final ciphertext and without padding the last plaintext block).
1) How many messages are required to have a collision (i.e. two distinct messages with the same tag) following the birth-
day paradox?
2) Given two messages M and M ′, which have the same tag T = CMAC K ( M ) = CMAC K ( M ′), how to build more collisions
of the form M || X and M ′ || X ? Such an attack is called length extension.
3) Use answers to questions 1 and 2 to show how an adversary can forge a pair (message and tag) with an uncontrolled
appended content.
Problem 9.6
This problem addresses message number limits in CMAC to prevent collision attacks. Hint: use birthday paradox.
1) In page 13, the CMAC standard [2] recommends the following “the default recommendation is to limit the key to no
more than 248 messages when the block size of the underlying block cipher is 128 bits, as with the AES algorithm, and
221 messages when the block size is 64 bits, as with TDEA. Within these limits, the probability of a collision is expected
to be less than one in a billion for the AES algorithm, and less than one in a million for TDEA.” How the recommended
limits (i.e. 248 and 221) can be substantiated?
2) In most real-world systems, it is recommended that the adversary’s advantage should not be greater than 2−32 . In
particular, the number of tags generated with the same key is such that the probability of tag collision should not be
greater than 2−32 . What is the limit on message number to tag with AES-CMAC and TDEA-CMAC, both using the same
key, such that collision risk does not exceed 2−32 ?
308 9 Block Cipher Modes of Operation for Authentication and Confidentiality
Problem 9.7
Show that ChaCha20-Poly1305 AEAD does not assure confidentiality protection, if the nonce is reused for two distinct
messages.
Problem 9.8
In this problem, we want to show that Poly1305-AES is secure against forgery attacks, even if one-time key (r , s ) and nonce
n are both reused to compute tags for two distinct plaintexts m and m′, both of the same byte-length of 16. To simplify the
problem, assume that m′ is no less than m. Discuss why forging a plaintext f using m, m′, and their tags cannot succeed.
For example, try to find a tag for f = m′ − m, assuming that one-time key (r , s ) and nonce n are unknown to the
adversary.
Exercise 9.1
Payload length is 1 G bytes. 1 G = 230 ; thus, q the byte-length of the payload length is 4. In formatting function, the nonce
is represented on bytes 1 to 15 − q of the block B0. If q = 4, then the byte-length of the nonce is 11. Hence, the maximum
distinct values of nonces is 211*8. Since each file requires a distinct nonce, the maximum number of files to encrypt and
authenticate with the same key is 288.
Problem 9.1
With the given assumptions, CBC-MAC may be defined by:
Pn = Pn* # No subkeys are used in CBC-MAC
C0 = 0 b
for i = 1 to n do: Ci = Enc K (Ci−1 ⊕ Pi )
T = MSBb (Cn ) = Cn, because the tag and block are of the same bit-length
Let ( P,T ) and ( P ′, T ′) be two known plaintexts and their tags. Let n and n′ denote the number of blocks of plaintexts
P and P ′ respectively. Let P1′ , P2′ , … Pn′ ′ denote the blocks of plaintext P ′.
( )
1) Under CBC-MAC, the adversary can forge, by concatenation, a plaintext P′′ as follows: P ′′ = P || P1′ ⊕ T || P1′ ||…|| Pn′ ′ .
Let C j , j = 1, …, n denote the encryptions of blocks of P′′.
( ) ( )
C1 = Enc K C0 ⊕ P1′′ = Enc K (C0 ⊕ P1 ) = Enc K P1′′ = Enc K ( P1 ) = T
( )
Cn = Enc K Cn−1 ⊕ Pn′′ = Enc K (Cn−1 ⊕ Pn ) = T
( ) ( ( ))
Cn+1 = Enc K T ⊕ Pn′′+1 = Enc K T ⊕ P1′ ⊕ T = Enc K P1′ ⊕ 0 ( )
Hence, the encryption of blocks of plaintext P is cancelled. Next, the encryption of plaintext P′′ continues exactly as
that of plaintext P′ and the final tag is T′. Then, the adversary sends ( P ′′,T ′), which will be validated by the recipient.
2) Now consider CMAC algorithm. The tag of plaintext P is computed as T = Enc K (Cn−1 ⊕ ( K1 ⊕ Pn )).
Since the last block of plaintext P is not the last block of message P′′, the tag of P′′ is computed as:
( )
Cn = Enc K Cn−1 ⊕ Pn′′ = Enc K (Cn−1 ⊕ Pn ) = T1 , which is distinct from T = Enc K (Cn−1 ⊕ ( K1 ⊕ Pn )). Then,
Cn+1 = (
Enc K T1 ⊕ Pn′′+1 ) = EncK (T1 ⊕ (P1′ ⊕ T )) = EncK (P1′ ⊕ T1 ⊕ T ), ( )
which is distinct from Enc K P1′ . Hence, the
encryption of plaintext P′′ does not continue as that of P′. The tag of plaintext P′′ would be T′′, which is distinct from T′.
Therefore, the forgery attack cannot succeed under CMAC.
Problem 9.2
(
1) Scheme 1: the CMAC scheme designed by Bob to generate a 128-bit tag for each 3-block message P = P1 || P2 || P3* is as )
follows:
Bob_MAC_Generation( K , P ) :
( K1 , K 2 ) = CMAC_Subkey_Generation( K , 128)
9.3 Exercises and Problems 309
( K1 , K 2 ) = CMAC_Subkey_Generation( K , 128).
Let Amt denote the amount included in the third block of P.
Let P3 = ( K1 + Amt ) mod 997
C0 = 0 ( b )
For i = 1 to 3 do : Ci = Enck ((Ci−1 + Pi ) mod 997)
Return (C3 )
Assume that Bob has generated a tag T for a message P that has the value 25 in its third block, i.e. P3 = 25.
T = Bob_MAC_Generation( K , P ) = Enck ((C2 + P3 ) mod 997) = Enc K ((C2 + Amt + K1 ) mod 997)
If Eve increases the amount Amt by 997, the third block becomes P3 = 1122; and the tag does not change. Therefore, Eve
succeeds in increasing the amount.
3) Scheme 3: the amount of money is included in the third block and encoded, so that it contains only the amount; i.e. the last
block of the plaintext is incomplete. That is, Bob’s MAC scheme becomes:
Bob_MAC_Generation( K , P ):
( K1 , K 2 ) = CMAC_Subkey_Generation( K , 128)
Let Amt denote the amount included in the third block of P denoted P3* .
j = 128 − len P3* ( )
(
P3 = K 2 ⊕ P3* || 1 || 0 j )
C0 = 0 b
for i = 1 to 3 do : Ci = Enc K ((Ci−1 + Pi ) mod 997)
Return (C3 )
The tag generated by Bob is:
(( (
T = Enc K C2 + K 2 + [25]5 || 1 || 0122 ) ) mod 997).
If Eve increases the amount by x, then:
Let L denote the bit-length of integer x + 25. Hence, the tag of the forged message is:
(( (
T ′ = Enc K C2 + K 2 + [ x + 25]L || 1 || 0128−L−1 ) ) mod 997).
Eve can find a value x, such that the following holds, and then change the amount:
310 9 Block Cipher Modes of Operation for Authentication and Confidentiality
( (
T2 = E K E K EK ( EK ([0]n ) ⊕ [1]n ) ⊕ T0 ⊕ 3 ) )
= EK (E ( T
K 0 ⊕ T0
n
) ⊕ 3) = E ( EK K ([0]n ) ⊕ 3)
– Forge a message M forge = [1]n || [1]n || T1 with tag T2 , which matches the forged message, because:
( (
MAC ([1]n || [1]n || T1 , K ) = E K EK EK ( EK ([1]n ) ⊕ [1]n ) ⊕ T1 ⊕ 3 ) )
( (
= E K E K T1 ⊕ T1 n ) ⊕ 3) = E (E K K ([0]n ) ⊕ 3) = T2
We can apply the previous steps for any pair of blocks M 0 and M1, and forge a tag.
Problem 9.4
The tag forgery attack may be designed as follows:
i) The adversary gets two tags:
T1 = CBC K 0 ( ( )) ⊕ K ′ and T = CBC (0( ) || T ) ⊕ K ′
n
2 K
n
1
T1 = CBC K 0 ( ( )) ⊕ K ′ = E (0( )) ⊕ K ′
n
k
n
(n)
ii) The adversary can forge T2 , as a valid tag of a message 0 || T1 || T2, because:
CBC K 0( ( ) || T || T ) ⊕ K ′
n
1 2
(
= Ek Ek ( K ′) ⊕ ( Ek ( K ′) ⊕ K ′) ⊕ K ′ = T2 )
Problem 9.5
1) With a tag bit-length of b, the number of distinct tags is 2b . From the birthday paradox (in Section 3.4), we can deduce
that if the number of messages (for which the tags have been produced with the same key K) known to the adversary is
close to 2b/2, then there exists a high probability that two distinct messages M and M ′ have the same tag; i.e.
CMAC K ( M ) = CMAC K ( M ′) = T .
2) Assume that two messages M and M ′ are known and they have the same tag under the key in use; i.e.
T = CMAC K ( M ) = CMAC K ( M ′). Let n and n′ denote the number of blocks of messages M and M ′, respectively. Let Ci ,
i = 1, …, n, and C ′j , j = 1, …, n′ , denote the ciphertext blocks computed for messages M and M ′, respectively. Since any
plaintext block is of length b, only the subkey K1 is used. The tag of both messages is computed as follows:
9.3 Exercises and Problems 311
(
T = Enc K (Cn−1 ⊕ K1 ⊕ M n ) = Enc K Cn′ ′−1 ⊕ K1 ⊕ M n′ ′ )
Thus, Cn−1 ⊕ K1 ⊕ M n = Cn′ ′−1 ⊕ K1 ⊕ M n′ ′
( )
Cn1 = Enc K Cn1−1 ⊕ M n1 = Enc K (Cn−1 ⊕ M n ) (b)
(( ) ( ) )
t = c1 * r 1 mod 2130 − 5 + Encs (n) mod 2128
Assume that the plaintext that could be forged, using the same one-time key and nonce, is f = m′ − m. The padded segment
yielded from f is c f = (m′ − m) + 2128 . The tag of f , computed by the legitimate sender, is the following:
(( ) ( ) )
t f = c f * r 1 mod 2130 − 5 + Encs (n) mod 2128
Since r, s, and n are unknown to the adversary, he/she cannot compute the second component of right part of the last
equality. Therefore, Poly1305-AES is secure against the suggested forgery attack.
Notes
1 In literature, the acronym AEAD is expanded as either “Authenticated Encryption with Associated Data” or “Authenticated
Encryption with Additional Data,” which are the same notion.
2 It is worth noticing that in this chapter, authentication refers to data authenticity and not to user authentication (e.g. with a
password or biometrics), which is another aspect of security.
3 Notice that to be standard-complying, applications should not use the same key and nonce to process distinct messages.
4 AES-GCM means GCM mode of operation of AES bock cipher.
5 For each tag to compute, a distinct 32-byte key is used. So, the sender and recipient of tagged messages must agree on a
procedure (e.g. a key derivation function) to generate one-time keys from a session key.
6 A semiblock is the half of a block, i.e. a 64-bit substring, if AES is used and a 32-bit substring, if TDEA is used.
7 CBC-MAC has not been approved as standard because of its vulnerabilities.
References 313
References
1 Gueron, S. and Lindell, Y. (2017). Better bounds for block cipher modes of operation via nonce-based key derivation - report
2017/702. Cryptology ePrint Archive. Cryptology ePrint Archive.
2 Dworkin, M. (2016). Recommendation for block cipher modes of operation: the CMAC mode for authentication, special
publication 800-38B. NIST. National Institute for Standards and Technology.
3 Dworkin, M. (2007). Recommendation for block cipher modes of operation: the CCM mode for authentication and
confidentiality, special publication 800-38C. NIST. National Institute for Standards and Technology.
4 Dworkin, M. (2007). Recommendation for block cipher modes of operation: Galois/counter mode (GCM) and GMAC, special
publication 800-38D. NIST. National Institute for Standards and Technology.
5 Bernstein, D. (2005). The poly1305-AES message-authentication code. 12th International Workshop on Fast Software
Encryption, 32–49. Paris: Springer. LNCS 3357.
6 Rescorla, E. (2018). The transport layer security (TLS) protocol version 1.3, RFC 8446. Internet Engineering Task Force
(IETF). Internet Engineering Task Force.
7 Dworkin, M. (2012). Recommendation for block cipher modes of operation: methods for key wrapping, special publication
800-38F. NIST. National Institute for Standards and Technology.
314
10
Modern cryptography security relies on the computational difficulty1 to break ciphers rather than on the theoretical impos-
sibility to break them. If adversaries have enough resources and time, they can break any cipher. The security analysis of
block ciphers and their modes of operation is a wide field in cryptography. One approach to address the security of ciphers
is to show how it is hard for adversaries to break ciphers given the resources they can use. The adversaries have access to
black boxes (called oracles) associated with the ciphers to attack and they try to guess some information through the exploi-
tation of chosen plaintexts and ciphertexts. Consequently, information inference is probabilistic. The information inferred
through querying a black-box is measured in terms of adversary advantage. Secure ciphers are those ciphers for which the
advantage of adversaries is negligible if their resources and time remain below some limits. The analysis of different sce-
narios of attacks is an approach to assess the security of ciphers from a probabilistic point of view. In particular, security
analysis aims to define bounds beyond which the use of some ciphers may become insecure.
Security analysis is based on oracles, in particular oracles modeling the encryption, decryption, MAC generation, and
MAC verification operations. The cipher to analyze is put in the worst conditions; i.e. the adversaries can choose any plain-
texts to encrypt or ciphertexts to decrypt or the adversaries choose MACs and then ask the oracle to verify their validity.
Therefore, the interception of true plaintexts and ciphertexts is not an issue.
In general, block cipher analysis is defined using two parameters relating to the following questions:
● What is the goal of the adversary: decrypt a ciphertext, learn something about the plaintext from the ciphertext or recover
the key?
● What is the amount of resources available to the adversary? The resources are described in terms of computation time
and known plaintexts, ciphertexts, and plaintext–ciphertext pairs. In addition, the memory required to store data may be
a critical issue.
Security analysis of modes of operation of block ciphers addresses two issues:
● Privacy: it should be computationally infeasible for an adversary to derive any information from the ciphertexts unless
the key is known. Such a property is called perfect secrecy [1].
● Authenticity: it should be computationally infeasible for an adversary to forge a valid pair ciphertext–tag unless the key
is known.
As mentioned in other chapters, cryptographic standards specify limits for the number of plaintexts to encrypt to not
compromise the security. This chapter aims at introducing some security bounds, which link the plaintext limit and the
expected security in terms of privacy and authenticity preserving. It is worth noticing that this chapter is far from covering
the field of probabilistic security analysis.
Pseudorandom functions (PRFs) and pseudorandom permutations (PRPs) are basic tools in cryptography. One of the pri-
mary motivations of PRFs and PRPs is to enable the security analysis of block ciphers and their modes of operation [2–4].
This section presents basic definitions relevant to PRFs and PRPs.
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
10.1 Pseudorandom Functions and Permutations 315
Definition 10.1 Function: a function f : M → R from a set M, called function domain, to a set R , called function range or
codomain, assigns to each element of M one element of R .
Definition 10.2 Permutation: a permutation π: M → M from a set M, called permutation domain, to the set M, is a bijec-
tive function that uniquely assigns to each element of M one element of M.
Definition 10.3 Function family: a function family F is a map F : K × M → R , where K denotes the key space, M the domain
of F , and R its range, which also is called co-domain of F .
When functions are used in cryptographic algorithm analysis, the elements (or points) of K, M, and R are bit strings. That
is, K = {0,1}k, M = {0,1}n, and R = {0,1} L, where k denotes the key bit-length; n and L denote the bit-length of function
input and output, respectively.
Definition 10.4 Instance of a function family: given a key K ∈ K, an instance of a function family F , denoted FK , is a map
from each point x ∈ M to a point y ∈R such that FK ( x ) → y .
Definition 10.5 Permutation family: a permutation family P is a collection of permutations with the same domain and
range; i.e. P: K × M → M.
Definition 10.6 Instance of a permutation family: given a key K ∈ K, an instance of a permutation family P, denoted PK , is
a map from each point x ∈ M to a unique point y ∈ M such that y = PK ( x ) and PK ( x ) ≠ PK ( x ′) if x ≠ x ′, ∀ x , x ′ ∈ M.
A function family F: K × M → R is a collection of functions F1 , F2, …, F2k , each with a key in the key space; and a permuta-
tion family P: K × M → M is a collection of permutations P1, P2 , …, P2k , each with a key in the key space K.
The collection of all functions of M to R is denoted Func (M, R ) ; and the collection of all permutations of M to M is
denoted Perm(M) .
Notice the massive difference in size between F and Func (M, R ) sets and between P and Perm(M) sets (see Problem 10.1):
n
● | F | = | K| = 2k and | Func (M, R )| = |R ||M| = 2 L*2
● | P | = | K| = 2k and | Perm (M)| = | M| ! = 2n !
Example 10.1
AES-128 block cipher is a family of permutations that make use of 128-bit keys and 128-bit plaintext to produce 128-bit
ciphertext blocks. Therefore, it is a family of permutations with K = {0,1}128 and M = {0,1}128 .
AES-128-CMAC is a function family of algorithms that produce tags (i.e. message authentication codes) of Tlen-bit length
for messages of arbitrary bit-length. Therefore, it is a function family with K = {0,1}128, M = {0,1}* , and R = {0,1}Tlen .
Definition 10.7 Random function: given an element x of a domain M, a random function ϕ: M → R is a black-box, which
returns a random element y in codomain R . If the same input x is given to a random function ϕ, at multiple times, the same
output y is returned. Given any distinct inputs x1 and x 2, the output y1 = ϕ ( x1 ) and y2 = ϕ ( x 2 ) are independent.
Definition 10.8 Random permutation: given an element x of a domain M, a random permutation π: M → M is a black-
box, which returns a random element y of M. If an input x is given to a random permutation π, for the first time, the re-
turned output is distinct from all previously returned outputs. If the same input x is given to a random permutation π, at
multiple times, the same output y is returned. Given any distinct inputs x1 and x 2, the outputs y1 =π ( x1 ) and y2 =π ( x 2 ) are
independent and distinct.
Definition 10.9 Pseudorandom function (PRF): a PRF F: K × M → R a is family of functions whose any instance is com-
putationally indistinguishable from a random function of the function family Func (M, R ).
Definition 10.10 Pseudorandom permutation (PRP): a PRP F: K × M → M is a family of permutations whose any in-
stance is computationally indistinguishable from a random instance of the permutation family Perm (M ). A PRP P is required
to be bijective, and to have an efficient inversion function P −1; i.e. ∀ K ∈ K, P −1 (K, P ( K , x ))= x .
316 10 Introduction to Security Analysis of Block Ciphers
A pseudorandom function family F (resp. PRP P) is computationally indistinguishable from a random function (resp.
permutation), if an adversary that has practical computational resources and given access to an instance of the PRF F (resp.
PRP P) and to a random function (resp. permutation), with the same domain and codomain; he/she cannot distinguish
between the outputs of the PRF (resp. PRP) and those of the random function (resp. permutation).
Definition 10.11 Oracle: an oracle of a function f is a (theoretical) black box that responds to every unique query with a
(truly) random response chosen uniformly from the output domain of the function.
The most commonly used approach to evaluate the security (i.e. indistinguishability) of PRFs (and also PRPs) is based on
a probabilistic analysis and referred to as Real-Or-Random (ROR), which works as a game between a distinguisher A (called
hereafter adversary) of a PRF F and a challenger (see Figure 10.1).
Adversary A is given an interface to access two oracles and it submits one or more queries and receives answers. Before
processing the first query, the game challenger, whose strategy is unknown to the adversary, uniformly selects at random
a key K from the key space K and a random binary b. For each submitted query, if b = 1, then the query is processed with
the instance function FK (i.e. processed with the oracle of F ); and if b = 0, then the query is processed with a random
function φ selected function from the family Func (M, R ) . Upon reception of an answer, the adversary tries to guess which
oracle processed its query, i.e. which value was chosen for b. The adversary outputs 1, if it thinks that the query was pro-
cessed by an instance of PRF F (i.e. the received bit string is a valid ciphertext); and 0 otherwise (i.e. the received bit string
is random).
Each adversary query and guess is called experiment. For each experiment, a quantity called PRF-advantage is computed
to measure how the adversary is able to distinguish between the PRF and a random function:
def R R
ADVFprf ( A) Pr K ← K; A FK ⇒ 1 − Pr ϕ ← Func (M,R ); Aϕ ⇒ 1
where:
R
K ←K: it denotes the uniform selection at random of a key K from key space K.
R
ϕ ← Func (M, R ): it denotes the selection of a random function φ from all the random functions in Func (M,R ).
A FK : adversary A is given access to FK , an instance of the function family F.
Aϕ: adversary A is given access to ϕ, a random function from Func (M,R ).
Pr[ A FK ⇒ 1] is the probability that the adversary outputs b = 1, given that the query was effectively processed by FK ;
i.e. it is the probability of a correct guess.
Pr[ Aϕ ⇒ 1] is the probability that the adversary outputs b = 1, given the query was processed by a random function
ϕ ∈ Func (M, R ) ; it is the probability of a wrong guess.
Note. For a testing session, the adversary queries the interface one or more times depending on the amount of computa-
tion time the adversary can use. The challenger randomly selects the parameter b, b ∈ {0,1}, one time per session before
the adversary starts submitting its queries and b remains unchanged during all the testing session. If b = 1, then the chal-
lenger uniformly selects a random key K from the key space K. Therefore, all the queries of a session are processed either
by the same instance of function family, denoted FK , or by a random function, denoted ϕ.
Different adversaries may have different PRF-advantages depending on their number of queries and computation time and
how each adversary exploits the received outputs. The security of a function as PRF is measured as:
def
ADVFprf (t , q) ( )
max ADVFprf ( A)
A
where q is the maximum number of queries that any adversary can ask; and t is the maximum testing computation time.
Definition 10.12 Secure PRF: a PRF F: K × M → R is (t , q, ε)-secure if the PRF-advantage over all adversaries is negligible
i.e. ADVFprf (t , q) ≤ ε, where ε 1 is a context-dependent bound; q and t denote the maximum number of queries and compu-
tation time for any adversary, respectively.
Example 10.2
Let K = {0,1}n and M = {0,1}n. Consider the function family Φ: K × M× M defined by Φ( K , x ) = K ⊕ x . Let us show that Φ
is not a secure function family. An adversary A queries with two distinct elements x1 and x 2 and receives two elements
y1 = f ( x1 ) and y2 = f ( x 2 ), where f is either an instance of Φ or a random function from Func(M, M). If f is an instance of
Φ, then y1 ⊕ y2 = ( K ⊕ x1 ) ⊕ ( K ⊕ x 2 ) = x1 ⊕ x 2. The strategy of the adversary A would be to output 1 if y1 ⊕ y2 = x1 ⊕ x 2,
and 0 otherwise. The probability that the adversary outputs 1 if the pair (x1 , x 2 ) was processed by an instance of Φ is equal
1
to 1. The probability that the adversary outputs 1 if the pair (x1 , x 2 ) was processed by a random function is n , because there
exists a single element v ∈ M such that v = y1 ⊕ y2 = x1 ⊕ x 2 . The adversary advantage is: 2
R R 1
ADVΦprf ( A) = Pr K ← K; AΦK ⇒ 1 − Pr ϕ ← Func (M ,R ); Aϕ ⇒ 1 = 1 − n
2
1
1 − n is far from negligible. Therefore, the function family Φ is not secure.
2
In addition, it is easy to recover the key used by the function family Φ. The adversary submits x = 0 (n ) and receives
y = K ⊕ 0 (n ) . Then, the key is recovered as K = y .
where:
R
K ←K: it denotes the uniform selection at random of a key K from key space K.
R
π← Perm(M) : it denotes the selection of a random permutation π from all the random permutations in Perm(M) .
PK
A : adversary A is given access to PK , an instance of permutation family P.
A π: adversary A is given access to π, a random permutation in Perm(M) .
Pr[ A PK ⇒ 1] is the probability that the adversary outputs b = 1, given that the query was effectively processed by PK . It
is the probability of a correct guess.
Pr[ Aπ ⇒ 1] is the probability that the adversary outputs b = 1, given that the query was processed by a random permu-
tation π. It is the probability of a wrong guess.
In a similar way as for PRF, the PRP-advantage over all adversaries asking a maximum of q queries requiring a total com-
putation time no more than t is defined by:
def
ADVPprp−cpa (t , q) (
max ADVPprp−cpa ( A)
A
)
Definition 10.13 Secure PRP under CPA: a PRP P : K × M → M is said to be (t , q, ε)-secure under CPA if the PRP-advantage
over all adversaries is negligible, i.e. ADVPprp−cpa (t , q) ≤ ε, where ε 1 is a context-dependent bound; q and t denote the
maximum number of queries and computation time for any adversary, respectively.
def R −1 R
Pr K ← K; APK , PK ⇒ 1 − Pr π ← Perm (M); Aπ,π ⇒ 1
−1
ADVPprp−cca ( A)
where:
R
K ←K: it denotes the uniform selection at random of a key K from key space K.
−1 R
π π; ← Perm (M): it denotes the selection, form Perm(M) , of a random permutation π and its inverse π−1.
PK , PK−1
A : adversary A is given access to the oracles of permutation instances Pk and PK−1 of permutation family P with the
key K.
A ; π : adversary A is given access to both random permutation instances π and π−1 of permutation family Perm ( M )
π−1
PK , PK−1
Pr[ A ⇒ 1] is the probability of a correct guess.
−1
Pr[ APK , PK ⇒ 1] is the probability of a wrong guess.
In a similar way as for PRF, the PRP-advantage under CCA over all adversaries asking a maximum of q queries requiring
a total computation time no more than t is defined by:
( )
def
ADVPprp−cca (t , q) = max ADVPprp−cca ( A)
A
Definition 10.14 Secure PRP under CCA: a PRP P: K × M → M is said to be (t , q,ε)-secure under CCA if the PRP-
advantage over all adversaries is negligible, i.e. ADVPprp−cca (t , q) ≤ ε, where ε 1 is a context-dependent bound; q and t denote
the maximum number of queries and computation time for any adversary, respectively.
10.1 Pseudorandom Functions and Permutations 319
Definition 10.15 Strong PRP: PRP P : K × M → M is said to be a strong PRP if it is CPA-secure and CCA-secure.
Example 10.3
Consider a block cipher E: {0, 1}3 × {0, 1}2 → {0, 1}2 defined by the following matrix of permutations:
Key 0 1 2 3
0 0 1 2 3
1 3 0 1 2
2 2 3 0 1
3 1 2 3 0
4 0 3 2 1
5 1 0 3 2
6 2 1 0 3
7 3 2 1 0
− Two queries: the adversary submits two inputs x1 = 0 and x 2 = 1. There exist 4 !/ 2 ! pairs ( y1 , y2) among which eight can
Therefore, the PRP-CPA advantage is ADVEprp−cpa (t ,1) = 1 − 1 = 0.
be generated by a permutation EK . If the adversary receives one of the pairs (0,1), (3, 0) , (2, 3), (1, 2) , (0, 3), (1, 0), (2,1) ,
8
(3, 2), it outputs 1. The probability that a random permutation returns one of the same eight pairs is . Thus, the
8 ( 4 !/ 2 !)
PRP-CPA advantage is ADVE prp−cpa
(t, 2) = 1 − 12 = 1 / 3.
− Four queries: the adversary submits four inputs x1 = 0, x 2 = 1, x3 = 2, x 4 = 3. There exist 4! results ( y1 , y2 , y3 , y4 ) among
which eight can be generated by a permutation E K . If the adversary receives one of the quadruplets (0,1, 2, 3) , (3, 0,1, 2) ,
(2, 3, 0,1), (1, 2, 3, 0), (0, 3, 2,1), (1, 0, 3, 2), (2,1, 0, 3), (3, 2,1, 0) , it outputs 1. The probability that a random permutation returns
8 8
one of the same eight quadruplets is . Hence, the PRP-CPA advantage is ADVEprp−cpa (t , 4) = 1 − = 2 / 3
( 4 !) 24
Lemma 10.1 states that the difference between the probability for the adversary to output 1, if it is given access to a random
q(q − 1)
function or to a random permutation is bounded by . Therefore, given n and q, the acceptability of the bound
q(q − 1) 2n+1
should be confirmed before interpreting a PRP as PRF in the analysis of block cipher-based algorithms. For
2n+1 q(q − 1) 1
example, if q = 2n /2, then n+1 ≈ , which is far from being a negligible probability difference.
2 2
320 10 Introduction to Security Analysis of Block Ciphers
q(q − 1) q2 q2
If q is large, may be approximated by = 0.5 *
. Therefore, a permutation family may have a PRF-advantage
2n+1 2n+1 2n q2
advantage that exceeds its PRP-advantage, but not by more than 0.5 * n .
2
It is commonly admitted in the cryptography field that a block cipher E : {0, 1}k × {0, 1}n → {0, 1}n , where k and n are the bit-
lengths of the key and the block, respectively, is a permutation family E . For example, AES128: {0, 1}128 × {0, 1}128 → {0, 1}128
and AES256: {0, 1}256 × {0, 1}128 → {0, 1}128 are two permutation families. The inverse to the block cipher E is a permutation
family E −1 with the same domain. In this book, the instances of permutations families E and E −1 are denoted Enc K (for
encryption) and Dec K (for decryption). In the cryptography field, a PRP isreferred to as block cipher and vice versa.
Therefore, the security of a block cipher E can be quantified as the maximum advantage that an adversary A can obtain
when trying to distinguish between an instance of a permutation family E and a random permutation with the same
domain as seen in Section 10.1.2.1.
The security analysis should address multiple objectives of adversaries. A block cipher is secure, if it prevents CPA, CCA,
and key recovery attacks. As far as we know, standard block ciphers have not been proven to be fully secure. The usual
method to evaluate the security of a block cipher works as follows: any adversary is given access to a block box, which runs
either the block cipher with a randomly selected key or a random permutation. The adversary asks the black box and
receives answers; then, it tries to guess in which context its queries are handled. For each addressed attack, a bound on the
adversary advantage may be calculated.
The bounds proposed in literature are mainly dependent on the number of queries and computation time available to the
adversary. Block ciphers remain secure as long as the bounds are not exceeded. It is worth noticing that many bounds have
been proposed and improved over time. This section aims to give some examples of security bounds; however, it is far from
covering the topic. Following the same notations as in previous sections, the advantage that an adversary A may have against
a block cipher E , by modeling the block cipher either as a permutation family or as a function family, is defined as follows:
def R R
ADVEprf ( A) Pr K ← K; A EK ⇒ 1 − Pr ϕ ← Fact (M, M); Aϕ ⇒ 1
def R R
ADVEprp ( A) Pr K ← K; A EK ⇒ 1 − Pr π ← Perm (M); Aπ ⇒ 1
In [5], the authors proved that given a block cipher E , the difference between maximum advantages over all adversaries
that run in time t and submit q queries, depending whether E is interpreted as a PRF or a PRP is bounded as follows:
q (q − 1)
ADVEprf (t , q) ≤ ADVEprp (t , q) +
2n+1
If the adversary is given access to both E (to make a chosen-plaintext attack) and E −1 (to make a chosen-ciphertext attack),
its advantage is defined by:
def R −1 R
ADVE± prp ( A) = Pr K ← K; A EK , EK ⇒ 1 − Pr π ← Perm (M); Aπ,π ⇒ 1
−1
When AES and DES are attacked by an adversary, which runs in at most t and submits q queries, the following bounds are
proposed in literature as conjectures [2, 4]:
t / TDES q2 t / TAES q2
prf
ADVDES (t, q) ≤ c1 * + prf
and ADVAES (t, q) ≤ c1 * +
255 264 2128 2128
TDES (resp. TAES) denotes the time to do one DES (resp. AES) computation on the RAM (Random Access Machine) model2
of adversary; and c1 is a constant depending upon the adversary RAM model.
In [6], the following adversary advantage bound is proven for TDES:
q2 q 2/3 12
prp
ADVTDES (t, q) ≤ 12(2n + k ) + 10.7 k +n /2 + k
23k 2 2
10.2 Security of TDEA and AES 321
Definition 10.16 Secure block cipher under key recovery attack: a block cipher E : K × M → M is said to be (t , q,)-secure
under key-recovery attack, if the kr-advantage over all adversaries is negligible, i.e. ADVEkr (t , q) ≤ε, where ε 1 is a context-
dependent bound; q and t denote the maximum number of queries and computation time for any adversary.
In [4], Rogaway proved the following bounds regarding the key-recovery attack when the block cipher is modeled as a PRF
or as a PRP:
1
ADVFkr (t , q) ≤ ADVFprf (t , q) + (10.2)
2n
1
ADVFkr (t , q) ≤ ADVFprp−cpa (t , q) + n
(10.3)
2 −q
Bounds (10.2) and (10.3) mean that if a family of functions is a secure PRF or PRP, then it is also secure against key-
recovery attacks. Therefore, if a block cipher is modeled as a PRF or PRP, it is implicitly assumed to be secure against
key-recovery attacks.
Lemma 10.2
Let E : {0,1}k × {0,1}n → {0,1}n be a block cipher and q a number of queries such that 1 ≤ q ≤ 2(n+1)/2. Then, the advantage
q(q − 1)
of any adversary making q queries within a computation time not exceeding q * n is ADVEprf (t , q) ≥ 0.316* .
2n
Notations
{0,1}*: any bit string
K = {0, 1}k : set of all bit-strings of length k; k is the key bit-length
{0,1}n: set of all bit-strings of length n; n is the block bit-length
({0,1}n )+: one or more n-bit blocks
({0,1} s )+: one or more s-bit segments, with s ≤ n (applicable to CFB only)
Modes of operation of block ciphers, which are presented in detail in Chapter 8, aim to protect data. Therefore, the security
analysis of such modes focuses on privacy.
In ECB mode, identical plaintext blocks yield identical ciphertext blocks. Therefore, ECB mode leaks the repetitions in
plaintexts; and in consequence, it is not regarded as an interesting mode of operation. In literature, ECB security is mainly
addressed from the information leakage point of view. For example, the analysis would infer statistical results such as
10.3 Security Analysis Modes of Operation of BC for Confidentiality 323
similarity between two ciphertexts, frequency of repetition in the same ciphertexts, locations of repetitions, etc. Since there
are no dependencies between ciphertext blocks corresponding to the same plaintext, ECB mode looks like a repetitive use
of a block cipher. Therefore, its security regarding CPA, CCA, and key recovery is similar to that of a block cipher alone.
With the exception of ECB mode, a mode of operation is modeled as permutation family and its inverse:
ε: K × V ×P → C
D : K×V ×C → P
where: K denotes the key space, V the space of IV or of counter, P and C the plaintext and ciphertext spaces, respectively.
The IV may be a random value, a nonce, or a tweak, depending on the analyzed mode.
Let εKv ( P ) = C denote the encryption of plaintext P∈P using a key K ∈K and a parameter v∈V; and DKv (C ) = P denote
the decryption of plaintext C∈C using a key K ∈K and a parameter v∈V. Modes of operation of block ciphers are modeled
as permutation families:
( ) → ({0,1} )
+ +
k n n
ECB: {0, 1} × {0, 1}
k n * *
OFB: {0, 1} ×{0, 1} ×{0, 1} → {0, 1}
( ) ({0,1} )
+ +
k n s s
CFB: {0, 1} × {0, 1} × {0, 1} →
k n * *
CTR: {0, 1} ×{0, 1} ×{0, 1} → {0, 1}
2k 128 * *
XTS : {0, 1} ×{0, 1} ×{0, 1} → {0, 1} . XTS makes use of keys of a bit-length 2k = 256 or 2k = 512 and a 128-bit
tweak.
Question assuming the underlying block cipher E is secure at an advantage of ADVEprf (t ′, q′) or ADVEprp (t ′, q′) , depending on
whether the block cipher is modeled as a PRF or a PRP, what are the values parameters t (the computation time), qe (the
number of encryption queries), qd (the number of decryption queries), µe (the total of plaintext bits), and µd (the total ciphertext
bits) such that the adversary advantage in attacking a symmetric cipher remains small?
Different ways to address the analysis of the security of modes of operation of block ciphers have been proposed in litera-
ture, including Real-or-Random indistinguishability (see Section 10.1.2), Left-or-Right, Find-then-Guess, and Semantic
security [2]. In this book, we only focus on the Left-or-Right approach, which is, as far as we know, the most used to derive
concrete bounds on indistinguishability of modes of operation for confidentiality.
In other words, the adversary advantage is measured in terms of the difference between the probabilities to guess which
plaintexts have been encrypted, the left or the right ones. Then, the maximal advantage over all CPA adversaries that can
run in at most time t and submit a maximum of qe encryption queries totaling4 at most µe bits is defined by:
(
ADVεlor −cpa (t , qe , µe ) = max ADVεlor −cpa ( ACPA )
ACPA
)
324 10 Introduction to Security Analysis of Block Ciphers
In a CCA security analysis session, in addition to qe encryption queries, the adversary submits qd decryption queries each
of the form of a bit-string yi , i = 1 , …, qd, under the assumption that yi has not been previously returned by the encryption
oracle εK . Otherwise, the adversary will obviously win the game. Then, if yi is a valid ciphertext, the decryption oracle
returns a plaintext mi = DK ( yi ). Otherwise, it returns a null symbol ⊥. Using the chosen ciphertexts and received plain-
texts, the adversary has to guess which value is used for parameter b.
The advantage that a CCA adversary can get is defined as that of CPA; and the maximal advantage over all CCA adver-
saries that can run in a time t and submit a maximum of qe encryption queries totaling at most µe bits and qd decryption
queries totaling at most µd bits is defined by:
( ) (
ADVεlor −cca t , qe , µ e , qd , µd = max ADVεlor −cca ( ACCA )
ACCA
)
A mode of operation ε is said to be LOR-CPA secure if ADVεlor −cpa (t , qe , µe ) ≤ βcpa and LOR-CCA secure if
ADVεlor −cca (t , qe , µ e ) ≤ βcca, where βcpa and βcca are negligible bounds.
Inequalities (10.4) and (10.5) state that the adversary advantage attacking the CBC or CTR modes, under CPA, is at most
the advantage when attacking the underlying block cipher E , if it is modeled as a PRF, plus a quantity that depends on the
10.3 Security Analysis Modes of Operation of BC for Confidentiality 325
number of encrypted blocks. Notice that CTR mode has a better security bound. If the underlying block cipher is secure
and the number of encrypted blocks is low, then both CBC and CTR modes are secure.
Example 10.4
Using the TDES security bound (10.1), given the maximum number of blocks to encrypt under CBC over TDES, the CBC-
adversary advantage β can be yielded as follows:
q2
TDES (t , qe , µe ) ≤ ADVTDES (t , q) +
lor −cpa prf
β = ADVCBC
2n
By PRF/PRP switching lemma,
q2 q (q − 1)
TDES (t , qe , µe ) ≤ ADVTDES (t , q) +
lor −cpa prp
β = ADVCBC n
+
2 2n+1
In TDES, n = 64 and k = 56. Thus, by substitutions:
2
q2 q 3 12 q2 q (q − 1)
β ≤ 212(2 * 64 + 56) 168 + 10.7 88 + 56 + 64 + 64+1
2 2 2 2 2
4416 q2 21.4 q2/3 24 q2 q (q − 1)
= * + * + 56 + 64 +
2168 288*2/3 2 2 265
If q = 230 (i.e. a total of 16 G bytes are encrypted with the same key), then
4416 230 *2 21.4 230 *2/3 24 230 *2 230 230 − 1 1
β = * * + 56 + 64 +
( )
+ ≈ 4 , which is a high bound.
2168 288*2/3 2 2 265 2
If q = 220 (i.e. a total of 16 M bytes are encrypted with the same key), then
C = (C L || c | | CR ) = B ⊕ Enc K (V )
(CL || c || CR )⊕ EncK (V ) = B = ( BL || b || BR )
C ′ ⊕ Enc K (V ) = (C L || c || CR ) ⊕ Enc K (V ) = ( BL || b || BR ) = B ′.
The probability that the random permutation oracle returns a bit string that differs from B by a single bit at a known posi-
tion is 1/2n . Thus, CCA-adversary advantage is close to 1.
326 10 Introduction to Security Analysis of Block Ciphers
2) Recall that CBC encryption of one block B is defined by C = Enc K ( B ⊕ IV ) and the decryption defined by B = Dec K (C ) ⊕ IV .
Let (V , C ) denote a ciphertext block C and V the IV value obtained with a query to CBC encryption oracle. Flip a bit in
V and get V ′; i.e. V = VL || v || VR and V ′ = VL || v || VR (VL and VR are the left and right bits of V , respectively; and v is
the flipped bit). Next, query CBC decryption oracle with (V ′, C ) and receive an n-bit string B ′ . If B ′ differs from B by one
bit (the one flipped in the IV), then the adversary infers that it was given access to CBC decryption oracle, because:
Authenticity-only schemes, which include CMAC, GMAC, and HMAC, aim to generate and verify MACs. Therefore, the
security analysis of such schemes focuses on authenticity. Authenticity modes of operation, which include CMAC and
GMAC standards, are presented in Chapter 9. HMAC is another way to provide authenticity guarantees by using hash
functions and not block ciphers; it is presented in Section 5.3.2.1.
verification queries, denoted qver . The probability of attack success depends on the number of queries; the higher the
number of queries, the higher the probability of success. The computation time t required to perform encryptions (Enc K ),
decryptions (Dec K ), and tag verifications to answer all the queries is of paramount importance, because it indicates if the
attack is computationally feasible or not under the expected probability.
ADVFmac (t , qgen + qver , µ) denotes the probability of tag forgery over all adversaries that ask at most t calls7 to the under-
lying block cipher, qgen queries to the MAC generation component, and qver queries to the MAC-verification component
with a maximum of µ bits per query. Formally,
def
ADVFmac (t , q, µ) = max ADVFmac (A )
A
def R
ADVFmac (A ) = Pr K ← K; A FK ⇒ 1
R
R
where K ←K denotes a uniform selection at random of a key K; Pr K ← K; A FK ⇒ 1 means the probability that the adver-
sary A receives 1 (i.e. it succeeds in forging a tag T ′ and a message M ′ such that T ′ = FK ( M ′)).
A MAC mode is said to be secure if ADVFmac (t , q, µ) is below an acceptable probability, which depends on applications.
(
ADVFprf (A ) = Pr K ← K; A FK ⇒ 1 − Pr ϕ ← Func M, {0,1}
Tlen
)
; A ϕ ⇒ 1
The maximum advantage over all adversaries with computation time at most t and submitting at most q plaintexts with a
total of µ bits is defined by:
def
ADVFprf (t , q, µ) = max ADVFprf (A )
A
It is commonly accepted that if function family F is secure as a PRF (i.e. F is indistinguishable from a random function), it
is secure as a MAC (i.e. attacker cannot forge tags, which are validated by MAC F ). That fact is formalized by the following
relationship proven in [5]:
1
ADVFmac (t , q, µ) ≤ ADVFprf (t ′, q) + Tlen
(10.7)
2
328 10 Introduction to Security Analysis of Block Ciphers
where:
q is the number of queries; t and t ′ denote the computation times of adversary attacking F as a MAC or as a PRF, respec-
1
tively. t ′ exceeds t with an amount in order of Tlen + d, where d is the bit-length of plaintext. Notice that Tlen is added
1 2
in (10.7), because even a perfect PRF (i.e. ADVFprf (…) = 0 ), there is a probability of Tlen that the adversary can randomly
2
choose a valid tag and submit a query, and then receives 1 (i.e. the tag is valid) from the tag verifier.
The maximum adversary advantage to forge a tag is called the maximum forgery probability.
Example 10.5
In AES-CMAC standard, it is recommended to limit the key to no more than 248 messages for general-purpose applications
and to no more than 248 blocks if a higher confidence in security is required. The ADVEprp (t ′, q′) is negligible, if the number
4 σ q
of blocks q′ is at most 248. The third bound of forgery probability may be reduced to * n * , because the second factor is
2
− If each of 2 messages is 1 G bytes in length, then
very small.
48
230
q = 248, σ = * 248 = 274.
16
5 * 274 * 248 5
The best advantage bound is ADVCMAC prf
(t, q, σ ) ≤ = , which is a weak security.
16
q = 248, σ = * 248 = 248.
16
5 248 248 5
The best advantage bound is ADVCMAC prf
(t, q, σ ) ≤ * 128* = 32 , which is a strong security.
− If each of 232 messages is 1 G bytes in length, then
2 2
230
q = 232 , σ = * 232 = 258 .
16
5 258 232 5
The best advantage bound is ADVCMAC prf
(t, q, σ ) ≤ * 128* = 38 , which is a very strong security.
2 2
10.4.2.2 Security Bounds for HMAC
Hash functions and HMAC are presented in Section 3.5.2.1. HMAC is a family of MAC schemes parameterized with a cryp-
tographic hash function. HMAC instances are denoted HMAC_H, where H may be any hash function including SHA-1,
SHA-256, SHA3-512, etc. HMAC does not make use of any block cipher; its security relies on the underlying hash function.
A MAC of a messageM is computed as follows:
HMAC_H ( K , M ) = H (( K ′ ⊕ oPad) || ( H ( K ′ ⊕ iPad || M )) (10.8)
10.5 Generic Models for Security Analysis of Authenticated-Encryption Modes 329
where H is the underlying hash function, K ′ an expanded key derived from a master key K, and oPad and iPad are constant
bit strings.
H function takes any bit string (with length multiple of 8) and returns a bit string (called digest) of fixed length Hlen.
Function H splits up a message into blocks of a fixed length b, which is a parameter of H (e.g. b = 512 for SHA-1 and
b = 1024 for SHA-512) and iterates8 over them with a compression function h. A compression function h is basic hash
function that takes a single b-bit block and a chaining parameter (which may be an IV or the tag of the previous block) and
returns a Hlen-bit tag; i.e. h is a map: h: {0, 1} Hlen × {0, 1}b → {0, 1} Hlen . Any HMAC variant is a function, i.e.
HMAC_H : {0,1}k × {0,1}* → {0,1} Hlen
where k denotes the key bit-length and Hlen the tag bit-length (e.g. Hlen = 160 if H = SHA-1, Hlen = 256 if H is SHA-256,
and Hlen = 512 if H is SHA3-512).
HMAC security relies on i) the security of the key derivation key (KDF), which computes K ′ from K and ii) on the secu-
rity of the underlying hash function H. The KDF used in standard HMAC is a PRG (pseudorandom generator). Therefore,
the first condition is omitted when analyzing the security of standard HMAC.
In [11], Bellare proved that HMAC is a PRF under the sole assumption that the compression function of the underlying
hash function is a PRF. Standard hash families SHA-1 and SHA-2 (including SHA-224, SHA-256, SHA-384, SHA-512, SHA-
512/224, and SHA-512/256) are iterated hash functions and are considered as secure PRFs. SHA-3 is a based on the Keccak
permutation and it also is considered as a secure hash function.
Under the assumption that the underlying compression function is a PRF, Bellare proposed the following bound:
q q (q − 1)
prf
ADVHMAC (A ) ≤ ADVhprf (A1 ) + (q − 1)σ − * ADVhprf (A2 ) + Hlen+1
2 2
A is any adversary that attacks HMAC. A makes at most q queries with a total of σ blocks (each of b bits); σ = n1 + n2 +…+ nq,
where ni is the number of blocks of query i. A1 is any adversary that attacks the compression function h used in HMAC. A1
submits q queries (totalizing σ blocks). A2 is any adversary, which submits at most two queries (totalizing at most 2m
blocks) to attack the compression function h. A and A1 run at most in t, while A2 runs at most in O(m * th ), where
m = max i (ni ) and th is the time for one computation of h.
It is worth noticing that the bound mentioned above is a simplified one of a more accurate bound proposed in [6], which
adds an advantage of any adversary that attacks the dual function of compression h. h is a dual function of h is defined by
h ( x , y ) = h ( y, x ) .
The maximum privacy advantage and authenticity advantage of any adversary attacking an authenticated-encryption F ,
which run in at most t and submit q queries with a total9 of plaintext not exceeding µ are defined by:
def
E (t , q, µ ) = max ADVF
ADVFpriv (A )
priv
A
def
E (t , q, µ ) = max ADVF
ADVFauth (A )
mac
A
where: qE and qD are the numbers of encryption and decryption (i.e. forgery attempt) queries, respectively; lE and lD are total
numbers of block cipher calls needed to respond to all encryption and decryption queries, respectively. Each encryption/
decryption enquiry is composed of plaintext, associated data, and padding (for detail on CCM format, see Section 9.2.3).
l l 1 l 1 [13]
p
q + 2q IV + 1 n−1 + + 1 Tlen
n
n 2 n 2
lp 2
+ 2q
n
auth
ADVGMAC
( prp
)
E t , q,(lp , l) ≤ ADVE (t ′, q′ ) +
2n+1
+
l l 1 l 1 [13]
p
q + 2q + 1 IV + 1 n−1 + + 1 Tlen
n n 2 n 2
lp 2
+ q + 1
n E
priv
ADVGMAC
(
E t ,(qE , qD ),(lp , l) ≤ ) 2n+1
[14]
l l
32 * qE * p + qE IV + 1
n n
+
2n
lp 2
+ q + q + 1
n E D
auth
ADVGMAC
(
E t ,(qE , qD ),(lp , l) ≤ ) 2n+1
+
[14]
l l l
32(qE + qD ) p + qE + 1 IV + 1 qD + 1
n
n n
+
2n 2Tlen
10.5 Generic Models for Security Analysis of Authenticated-Encryption Modes 331
where:
q denotes the number of queries (either MAC generation or verification queries);
qE and qD are the numbers of encryption and decryption queries, respectively;
lp is total number of plaintext bits;
lIV is the maximum bit-length of the IV; l is the maximum number of input bits (of ciphertext and associated data) for any
query;
t and t ′ are computation times of GMAC and PRP E adversaries, respectively;
q′ is the total number of blocks processed by the block cipher E .
2
∑ i =1 (QEi )
N
N Q Ei 2m 3N N * Bmax 2
296 2129 2126−m
N : maximum number of different nonces; QEi : number of messages encrypted with nonce i;
Bmax: maximum number of blocks encrypted or decrypted with the same nonce.
( )
QEi = max i=1,…, N N Ei for the same row; 2m: maximum message length (in blocks);
332 10 Introduction to Security Analysis of Block Ciphers
nonce are equal (i.e. N Ei = N Di , i = 1, ..., Q). In gray, are some parameter combinations that do not fulfill the NIST recom-
mendation, which states that the adversary’s advantage should not be greater than 2−32 .
Problem 10.1
Prove the following cardinalities:
1) | F |= K = 2k and | P |=| K | = 2k , where k is the key bit-length.
n
2) | Func (M, R ) | = |R ||M| = 2 L*2 , where |R | = L and | M| = n.
3) | Perm(M)| = | M| ! = 2n !.
Problem 10.2
Let E : {0,1}k × {0,1}n → {0,1}n be a block cipher such that: E K ( x ) = x , ∀ K ∈ {0, 1}k , ∀ x ∈ {0, 1}n. Show that E is very secure
against key-recovery attack, but it is very insecure against chosen-plaintext attacks. Use the Real-or-Random security anal-
ysis model.
Problem 10.3
Let E: {0,1}k × {0,1}n → {0,1}n be a secure PRP. Consider the permutation family E ′: {0,1}k × {0,1}2n → {0,1}2n defined by:
∀ x ∈ {0,1}n , ∀ x ′ ∈ {0,1}n , E K′ ( x || x ′) = E K ( x ) || Ek ( x ⊕ x ′). Show that E ′ is not a secure PRP. Use the Real-or-Random
security analysis model.
Problem 10.4
Let E: {0, 1}k × {0, 1}n → {0, 1}n be a block cipher. The twofold cascade of E is the block cipher E (2) : {0, 1}2k × {0, 1}n → {0, 1}n
defined by E K(2)||K ( x ) = E K ( E K ( x )), for all K1 , K 2 ∈ {0, 1}k and all x ∈ {0,1}n. Prove that if E is a secure PRP, E (2) is too. Use
1 2 1 2
Problem 10.9
This problem aims to show that AES-GCM-SIV outperforms AES-GCM in terms of the amount of data that can be
encrypted. Consider a user encrypting a collection of data with length multiple of 128 bits, while guaranteeing an adver-
sary’s advantage bound no greater than 2−32 . What is the maximum byte-length of data that can be encrypted with the same
key in the following scenarios? Use Gueron and Lindell’s bound (see Section 10.5.2.3).
1) A single IV is used to encrypt with the AES-GCM mode.
2) 232 distinct IVs are used to encrypt with the AES-GCM mode. Notice that for AES-GCM standard compliance, the
maximum number of IV values used under the same key with AES-GCM should not exceed 232 .
3) A single nonce is used to encrypt with the AES-GCM-SIV mode, assuming that data are fragmented into messages of 230
128-bit blocks.
4) 232 distinct nonces are used to encrypt with the AES-GCM-SIV mode, assuming that data are fragmented into messages
of 230 128-bit blocks.
5) 262 distinct nonces are used to encrypt with the AES-GCM-SIV mode, assuming that data are fragmented into messages
of 28 128-bit blocks and the maximum nonce repetition is 28 for all nonces.
Problem 10.1
1) Since the bit-length of the key is k, there exist 2k distinct keys. Therefore, there exist 2k distinct instances of the function
family F and the same applies to permutation family P. Hence, | F | = | P | = | K | = 2k .
2) Let M = { x1 , x 2 , …, x 2n } and R = { y1 , y2 , …, x 2L } be the domain and codomain of function collection Func (M, R ). If
f is a function from M to R , then each element x i of M can be mapped to any of the 2 L elements of R . By the multipli-
n
cation principle of counting,10 the total number of functions from M to R is 2 L * 2 L * … * 2 L = (2 L )2 . For example,
2
n = 2 and L = 2. There exist 22 mappings for each of the 22 input elements. Thus, there are 22*2 mappings in total; and
therefore, | Func (2, 2) |= 256. For, n = 3 and L = 2. There exist 22 mappings for each of the 23 input elements. Hence, there
3
are 22*2 in total; and therefore, | Func (3, 2)| = 65536.
3) Let permutation domain be M = { x1 , x2 , …, x2n }, i ≠ j ⇒ x i ≠ x j . Assume that the first permutation π1 is defined
by π1 ( x1 ) = x1′, π1 ( x 2 ) = x 2′ , …, π1 ( x 2n ′) , where M = { x1′ , x 2′ , …, x 2′ n } = { x1 , x 2 , …, x2n }, then the second permutation π2 is
defined by π2 ( x1 ′) = x1 ″, π2 ( x 2 ′) = x 2 ″, ..., π2 ( x 2n ′) = x 2 ″, etc. π1 → π2 → π3 … The number of distinct elements to per-
mute is 2n. In general, the number of permutations of a set of N distinct elements is N !. Therefore, the number of per-
mutations of Perm(M) is (2n )!
Problem 10.2
When the adversary queries the oracle of E with a value x, the challenger selects a random key, which is not used to com-
pute y = E K ( x ). Therefore, upon reception of y, the adversary has no information in y to help it find the used key. Even
though the number of queries is large, no useful information will be inferred by the adversary from the returned results.
1 1
Therefore, the probability that the adversary guesses the key is n ; i.e. ADVEkr (.) = n . Hence, the block cipher is very
2 2
secure against key-recovery attacks. However, with a single query, because the adversary knows that E K ( x ) = x , upon
1
reception of y, if y = x , the adversary strategy is to output 1 with a probability of 1. With a probability of n , the adversary
2
outputs 1 while a random function is used and the returned value is such that y = x . Therefore, ADVE prf −cpa
(q, t ) = 1 − 1n ,
which means that the block cipher E is insecure against chosen-plaintext attacks. 2
Problem 10.3
The adversary asks the oracle of E ' with a pair ( x1 , 0) and receives y. If an instance E K′ of E ′ is used, then
y = E K′ ( x || 0) = E K ( x ) || Ek ( x ⊕ 0) = E K (x ) || EK ( x ). Therefore, the strategy of the adversary would be to output 1, if the
1
two halves of y are identical. If the adversary has access to a random permutation, then there is a probability of n that
1 2
y = y1 || y1, y1 ∈ {0,1}n has been picked at random. Hence, ADVEprp '
−cpa
(q, t ) = 1 − n , which is very high. Therefore, E ' is
an insecure PRP. 2
Problem 10.4
Twofold cascade of E is also called double-encryption of E . There are two cases to address: K1 = K 2 and K1 ≠ K 2.
334 10 Introduction to Security Analysis of Block Ciphers
Case: K1 = K 2 = K
The adversary asks the oracle with any point x ∈{0,1}n and gets a point y ∈{0,1}n . Since E is a secure PRP, the adversary
cannot distinguish between an instance Ek and a random permutation π. Then, y is submitted to the oracle and the
adversary gets a point y ′ ∈ {0,1}n. Once again, since E is a secure PRP, the adversary cannot distinguish between an in-
stance E K and a random permutation π. Hence, after two queries, the adversary cannot distinguish between π (π ( x ))
and E K ( E K ( x )). Therefore, E (2) is a secure PRP.
Case: K1 ≠ K 2
In this case, the test runs in two sessions, each with a (distinct) key. The adversary asks the oracle with any point
x ∈{0,1}n and gets a point y ∈{0,1}n . Since E is a secure PRP, the adversary cannot distinguish between an instance E K
2
and a random permutation π2. Then, y is submitted to the oracle and the adversary gets a point y ′ ∈ {0,1}n. Since E is a
secure PRP, the adversary cannot distinguish between an instance E K and a random permutation π1. Hence, after two
1
queries, the adversary cannot distinguish between π1 (π2 ( x )) and E K ( E K ( x )). Therefore, E (2) is a secure PRP.
1 2
Problem 10.5
1) Consider a block cipher E : {0,1}128 × {0,1}128 → {0,1}128 such that E K ( x ) = K ⊕ x .
First, consider an adaptive adversary, which chooses M1 = 1 and queries the oracle and gets y. Then, it asks the oracle
with M 2 = y and gets z. If the adaptive adversary has access to the oracle of E , then:
z = E K ( y ) = K ⊕ y = K ⊕ E K (1) = K ⊕ K ⊕ 1 = 1
Therefore, if z = 1, then the adversary outputs 1 with a probability of 1. The probability that z = 1 is returned by a
1 1
random permutation, for the second query, is 128 . Hence, ADVEprp−cpa (t , 2) = 1 − 128 ; and the block cipher E is insecure
2 2
against an adaptive adversary.
Second, consider a non-adaptive adversary, which selects a large set of q (e.g. q = 220 ) random integers from {0,1}128
and then queries the oracle. It gets q integers: yi = E K (x i ) or yi = ( x i ), for any i ∈[1, q], where π is a random permutation.
If the adversary is given access to the permutation family E , then for any pair i, j ∈ [1, q], i ≠ j ,
yi ⊕ y j = E K ( x i ) ⊕ E K ( x j ) = ( K ⊕ x i ) ⊕ ( K ⊕ x j ) = x i ⊕ x j
Therefore, if yi ⊕ y j = x i ⊕ x j, ∀i, ∀j ∈ [1, q], i ≠ j, the adversary outputs 1 with a probability of 1. The probability that a
random permutation returns values that match the previous condition is very low. Therefore, the block cipher is inse-
cure, even for a non-adaptive adversary.
2) Consider a block cipher E : {0,1}128 × {0,1}128 → {0,1}128 defined by E K ( x ) = K ⊕ Rotate ( x , K mod 128).
First, consider an adaptive adversary, which chooses two plaintexts M1 = 0 and M 2 = 1(128); i.e. 128 1-bits. It queries the
oracle and gets y1 = f (0) and y2 = f (1(128) ). If the adversary is given access to the oracle of E K , then:
y2 = K ⊕ Rotate 1 (( 128)
)
, K mod 128 = K ⊕1
(128)
(128) (128)
y1 ⊕ y2 = K ⊕ K ⊕ 1 =1
Therefore, if y1 ⊕ y2 = 1(128), the adversary outputs 1 with a probability of 1. The probability that a random permutation
returns two images y1 and y2, such that y1 ⊕ y2 = 1(128), is of 1/2128. Therefore, the adversary advantage is close to 1, which
makes the block cipher insecure.
Second, consider a non-adaptive adversary, which selects a large set of q random integers from {0,1}128 and then
queries the oracle. It gets q integers: yi = E K (x i ) or yi = ( x i ), for all i ∈[1, q], where π is a random permutation. If the
adversary is given access to the permutation family E , then for any pair i, j ∈ [1, q], i ≠ j,
( )
yi ⊕ y j = E K ( x i ) ⊕ E K x j
(
= K ⊕ Rotate ( x i , K mod 128) ⊕ K ⊕ Rotate x j , K mod 128 )
(
= Rotate ( x i , K mod 128) ⊕ Rotate x j , K mod 128 )
Then, the adversary takes any pair ( x i , x j ) and checks if yi ⊕ y j = Rotate ( x i , r ) ⊕ Rotate ( x j , r ), for r = 0, …, 127. If the
test is positive, then the adversary outputs 1 with a probability of 1. The probability that a random permutation returns a
pair of values, which matches the previous condition, is very low. Therefore, the adversary advantage is close to 1, which
makes the block cipher insecure even for a non-adaptive adversary.
10.6 Problems and Solutions 335
Problem 10.6
The security analysis model to use in this problem is the Right-or-Left model.
After querying with a pair of plaintexts ( M 0 , M1 ) , the adversary receives a two-block-ciphertext, C = C1 || C2.
If b = 0, then C1 = Enc K ([0]n ) and C2 = Enc K ([0]n ); i.e. M 0 is encrypted by the oracle.
If b = 1, then C1 = Enc K ([0]n ) and C2 = Enc K ([1]n ); i.e. M1 is encrypted by the oracle.
Thus, after receiving the ciphertext C, if C1 ≠ C2, the adversary outputs 1 at a probability of 1; and if it receives C2 such that
C1 = C2, it outputs 0 at a probability of 1. Since the underlying block cipher is a pseudorandom permutation, the proba-
bility that C1 = Enc K (0) = C2 = Enc K (1) is 0. Hence, the probability that the adversary outputs 1, while the left (i.e. b = 0)
oracle was accessed, is 0. Therefore, the ECB-CPA-adversary advantage is 1 − 0 = 1, which means that EBC is insecure.
Problem 10.7
( M 01 = 0, M11 = 0) and ( M 02 = 0, M12 = 1),
The security analysis model to use in this problem is the Right-or-Left model.
Assume that the adversary can predict that the IV to encrypt the first message is IV1 = 0 and that to encrypt the second is
IV2 = 1. In the first query, the adversary submits a pair (0, 0) and receives (C1 , IV1 ), where C1 = Enc K (0 ⊕ IV1 ) = Enc K (0),
because M 01 = M11 = 0 (whatever the encrypted block, the result is the same). Then, in the second query, it submits a pair
(0, 1) and receives (C2 , IV2 ) .
If b = 0, then C2 = Enc K ( M 02 ⊕ IV2 ) = Enc K (0 ⊕ IV2 ) = Enc K (1).
2
If b = 1, then C2 = Enc K ( M1 ⊕ IV2 ) = Enc K (1 ⊕1) = Enc K (0) = C1 . Thus, after the second query, if the adversary receives C2
such that C1 = C2, it outputs 1 at a probability of 1; and if the adversary receives C2 such that C1 ≠ C2, it outputs 0 at a proba-
bility of 1. Since the underlying block cipher is a pseudorandom permutation, the probability that C1 = Enc K (0) = C2 = Enc K (1)
is 0. Thus, the probability that the adversary outputs 1, while the left (i.e. b = 0) oracle was accessed, is 0. Therefore, the
CBC-CPA-adversary advantage is 1 − 0 = 1, which means that CBC is insecure, if the IV can be predicted.
2
( )
N
Problem 10.8 i
3 N N * Bmax 2 ∑i=1 QE
Recall that the adversary’s bound provided by Gueron and Lindell’s bound is Adv = 96 + + (see
Section 10.5.2.3). 2 2129 2126−m
A single nonce is used to encrypt and decrypt 248 messages. So,
N = 1, QE1 = 248, QD1 = 0, and Bmax = (248 + 0) * 216.
2 2
Therefore, Adv =
3
+
( )
1 * 264 1
+
(248 )
1
=
3 1
+ + 14 , which is dominated by . Thus, encryption of 248 * 216 blocks,
96 129 2 2 126−16 96 2
2 2 2 2
with the same nonce under AES-GCM-SIV algorithm, is insecure. By the birthday paradox, the adversary can succeed in
breaking the ciphering code.
Problem 10.9
1) With one IV, GCTR of AES-GCM mode can generate 232 distinct counter blocks. Hence, in total, 232 blocks (i.e. 236 bytes)
can be encrypted.
2) With 232 distinct IVs, used in the AES-GCM mode, a total of 232 * 232 blocks (i.e. 268) bytes can be encrypted.
3) Using Gueron and Lindell’s bound (see Section 10.5.2.3), to provide an adversary’s advantage bound no greater than 2−32,
2
( )
N i
3 * N N * Bmax 2 ∑i=1 QE
the inequality 96 + 129
+ 126−m
≤ 2−32 must hold. If only encryptions are considered, then the inequality
becomes: 2 2 2
2
( ) + ∑ (Q ) ≤ 2
2
3* N N * max i=1,…, N QEi * 2m( ) N
i=1
i
E −32
+ .
296 2129 2126−m
5) With N = 262, QEi = 28 for all nonces, and a message length of 28 , the inequality becomes:
3 * 262 262 * (28 )2 * (28 )2 262 * (28 )2 3 1 1
96
+ 129
+ 126−8
= 34 + 35 + 40 ≤ 2−32. Therefore, the total data that can be encrypted is
2 2 2 2 2 2
3 * 264 3 * 263 1
262 * 28 * 28 blocks ≈ 282 bytes. Notice that if N = 264 or N = 263, the inequality cannot hold, because 96 > 96 > 32 .
2 2 2
Notes
1 The computational difficulty refers to the fact that given practical resources that adversaries can use, the time for an attack
to succeed is too long (in centuries or more) to attempt the attack.
2 A random-access machine model is an abstract CPU model used to do some computations.
3 Each key check requires more than 103 (which is very optimistic) processor operations. The fastest computer in 2022 has a
speed of 442 * 1015 operations per second.
4 Notice that the total amount of encrypted bits is µe /2, because each query takes two equal-length plaintexts and only one of
them is encrypted.
5 q shall not exceed 2n blocks encrypted with the same key; otherwise, a collision occurs. Indeed, attack, after encrypting 2n
blocks with the same key, the adversary can collect twice a ciphertext, which is known as collision.
6 It is assumed that the adversary does not query the oracle twice with the same value either for tag generation or for tag
verification, because querying twice with the same input does not provide new knowledge to the adversary.
7 Notice that the computation time t is specified in terms of encryption and decryption operations of the underlying block
cipher, because those operations are the most time-consuming.
8 A hash function, which makes use of a compression function that is iterated on each block, is referred to iterated hash
function.
9 Some proposed bounds include the total length of associated data in μ.
10 According to the Multiplication counting principle, if one event can occur in u ways and a second event can occur in v ways
after the first event has occurred, then the two events can occur in u * v ways. In the considered problem, each point of M
may have up to 2 L images in R independently of the other points.
References
1 Shannon, C.E. (1949). Communication theory of secrecy systems. Bell System Technical Journal 28: 656–715.
2 Bellare, M., Piertrzak, K., and Rogaway, P. (2005). Improved security analyses for CBC MACs. In: Advances in Cryptology –
CRYPTO 2005 (ed. V. Shoup), 527–545. Santa Barbara, California: Springer. LNCS 3621.
3 Bellare, M. and Rogaway, P. (2005). Introduction to modern cryptography, course notes. University of California at San Diego
(US).
4 Rogaway, P. (2011). Evaluation of some block cipher modes of operation, research report. Davis University, California (US).
5 Bellare, M., Kilian, J., and Rogaway, P. (2000). The security of the cipher block chaining message authentication code.
Journal of Computer and System Sciences 61: 362–399.
6 Bellare, M. and Rogaway, P. (2006). Code-based game-playing proofs and the security of triple encryption. In: 25th
International Conference on the Theory and Applications of Cryptographic Techniques, Advances in Cryptology. 409–426.
Petersburg, Russia: Springer. LNCS 4004.
7 Bellare, M., Desai, A., Jokipii, E. et al. (1997). A concrete security treatment of symmetric encryption. In: 38th Annual
Symposium on Foundations of Computer Science. 394–403. Florida, US: IEEE Press.
8 Liskov, M. and Minematsu, K. (2008). Comments on XTS-AES. [Online]. (Cited 2023 April). Available from: https://csrc.nist.
gov/csrc/media/projects/block-cipher-techniques/documents/bcm/comments/xts/xts_comments-liskov_minematsu.pdf.
9 Iwata, T. and Kurosawa, K. (2003). Stronger security bounds for OMAC, TMAC, and XCBC. In: 4th International Conference
on Cryptography in India. 402–515. New Delhi, India: Springer. LNCS 2904.
10 Nandi, M. (2009). Improved security analysis for OMAC as a pseudorandom function. Journal of Mathematical Cryptology
3: 133–148.
References 337
11 Bellare, M. (2006). New proofs for NMAC and HMAC: security without collision-resistance. In: 26th International
Conference on the Theory and Applications of Cryptographic Techniques, Advances in Cryptology – CRYPTO 2006. 602–619.
Santa Barbara, California: Springer. LNCS 4117.
12 Jonsson, J. (2002). On the security of CTR + CBC-MAC. In: 9th Annual International Workshop on Selected Areas in
Cryptography. 76–93. Newfoundland, Canada: Springer. LNCS 2595.
13 McGrew, D.A. and Viega, J. (2004). The security and performance of the galois/counter mode of operation. Report 2004/193.
Cryptology ePrint Archive.
14 Iwata, T., Ohashi, K., and Minematsu, K. (2012). Breaking and repairing GCM security proofs. In: 32rd Annual Cryptology
Conference, Advances in Cryptology - CRYPTO 2012. 31–49. Santa Barbara, California: Springer. LNCS 7417.
15 Gueron, S. and Lindell, Y. (2017). Better bounds for block cipher modes of operation via nonce-based key derivation - report
2017/702. Cryptology ePrint Archive.
338
11
Cryptanalysis is the science and techniques of analyzing and breaking cryptographic algorithms and protocols. There exist
hundreds of cryptanalysis attack variants. Cryptanalysis is a very exciting field; and improvements of existing attacks are
proposed every year. Cryptanalysis attacks can be categorized according to various criteria, such as:
● Nongeneric vs generic attacks: in the first category, attackers take advantage of vulnerabilities of internal components of
attacked ciphers, while they do not in the second category. In general, nongeneric attacks are more efficient than generic
ones, as attackers know the internal vulnerabilities of attacked ciphers.
● Statistical vs deterministic attacks: in the first category, the attackers derive some properties of attacked ciphers that can
hold with some probabilities and exploit such statistical knowledge to partially or entirely recover keys. In the second
category, attackers design models of ciphers in form of equations. Models are used to reduce the search space of keys.
Linear and differential cryptanalyses are examples of statistical attacks, while algebraic attacks are deterministic. Linear
cryptanalysis together with differential cryptanalysis are the most widely used attacks against block ciphers.
● Known vs chosen information: there exist four main types (or models) of attacks: ciphertext-only, known-plaintext,
chosen-plaintext, and chosen-ciphertext attacks.
In Section 2.4.2, a general categorization of cryptanalysis methods is provided to show the main categories of attacks. This
chapter aims at introducing some common methods used to attack symmetric ciphers, namely:
● Memory-time trade-off attacks, including Hellman’s tables and rainbow chains
● Linear cryptanalysis
● Differential cryptanalysis
● Algebraic cryptanalysis
● Cube attacks
● Divide-and-conquer attacks
● Correlation attacks
This chapter introduces only the basic version of each mentioned attacks. All the basic attacks have been improved and
specialized (to address specific ciphers) in literature and many variants exist for each attack. The chapter is not a compre-
hensive survey.
Examples are used to show how a key can be partially or entirely recovered. It is worth noticing that only simple ciphers
(or toy ciphers) are used in examples below. The parameters of our toy-ciphers are such that the reader could check the
attacks “by hand.” Recovering key bits of real ciphers requires a lot of formulas and time-consuming experimentations.
Three metrics are commonly used to assess the complexities of attacks: computation time, memory to store data (plain-
texts, ciphertexts, and others), and the number of known/chosen plaintexts and/or ciphertexts. Those metrics are briefly
discussed in this chapter, because huge parameters are often required to describe attack complexities. It is worth noticing
that almost all cryptanalysis attacks are academic and cannot be performed, in practice, by normal attackers against real
ciphers, because of the huge amount of required resources. However, some security and intelligence agencies could have
resources to perform them.
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
11.1 Memory-Time Trade-off Attacks 339
In general, we can regard Memory-Time Trade-Off (MTTO) attacks as methods searching for a preimage of a one-way
function by utilizing a significant memory prepared in a precomputation phase to reduce the time complexity. The latter is
decreased by increasing the memory complexity and vice versa. Common MTTO attacks rely on Hellman’s and Rainbow
tables and their extensions. MTTO attacks may be used under known plaintext, chosen plaintext, or ciphertext-only
assumptions.
1. for i = 1 to m do
1.1 x i ,0 = SPi
1.2 for j = 1 to t do
x i , j = f ( x i , j−1 ) = R Enc xi , j−1 (P0 )
1.3 Let Pi = f t (SPi ) = x i ,t (EPi : endpoint of the i th chain)
2.1 Discard all intermediate points (to save memory)
2.2 Build a table HT : {SPi , EPi }, 1 ≤ i ≤ m, sorted on endpoints
Therefore, chain i contains t encryption keys. With the exception of the start point, a key xi,k is the result of two operations,
encryption using key xi,k −1, followed by a reduction.
Collisions and false alarms
It may happen that two distinct chains i and j collide, i.e. they yield the same key α located at position k1 in chain i and at
position k2 in chain j , with 0 < k1 ≤ t and 0 < k2 ≤ t . That is,
340 11 Introduction to Cryptanalysis Attacks on Symmetric Ciphers
Figure 11.1 (a) Matrix of images under f and (b) Hellman table.
{
Xi , the set of keys of chain i , is xi ,0 , xi ,1 , …, xi ,(k1 −1) , α, …, xi ,t −1 , xi ,t and }
X , the set of keys of chain j , is { x
j j ,0 , x j ,1 , …, x j ,(k2 −1) , α, …, x j ,t −1 , x j ,t }
Since a single reduction function R is used, the keys in both chains overlap starting with the position of α . In such a case,
the chains merge. For example, if chains i and j collide at positions k1 = 5 and k2 = 7 , with t = 20 , the chains have 14
common keys.
If two chains i and j merge at their endpoints, i.e. EPi = x i,t = EPj = x j,t = y , but x i,t −1 and x j,t −1. are distinct, then the
same value y has two inverse images, f −1 ( y ) = x i,t −1 and f −1 ( y ) = x j,t −1. Such a case is referred to as false alarm. A false
alarm means that when online key search is performed, both chains may be inspected and only one chain will (probably)
contribute to find the secret key and the other chain is a wrong track. Notice that false alarms may concern more than two
chains.
K = xi,t −1 . Check if the guessed key is correct: if Encx ( P0 ) ≠ C0 , then try another row, until a correct key is found or all
i ,t −1
guessed key is not correct, then try another row until a correct key is found or all rows are tested.
● Iteratively, until all the columns are tried or the correct key is found, try columns t − 3, t − 4 , …, 1.
The pseudocode for key HT-based search is as follows:
because the intermediate computations have been discarded after the precomputation phase. Since endpoints
are computed as reduced ciphertexts, the attacker has to check if the guessed key x i ,t −1 is correct or not. The
attack succeeds, if and only if Enc xi ,t−1 (P0 ) = C0. There is a non-null probability that the guessed key is not correct.
If the x i ,t −1 is not the correct key, then continue as in case 2.
● Case 1.2: If there is a false alarm (i.e. y = EP , but Enc
1 i x (P0 ) ≠ C0 ), proceed as in case 2.
i ,t −1
11.1 Memory-Time Trade-off Attacks 341
Example 11.1 The following is a simple example to show how Hellman’s table-based attack works. Let the key space size
be N = 64 . Choose a simple encryption, say Enck ( P ) = P * k mod 2 N . Plaintexts and ciphertexts are of 7-bit length.
Assume that the known plaintext is P0 = 57 .
1) Building of Hellman’s tables
According to Hellman’s recommendation (i.e. m = t = N 1/ 3), let m = t = 4 . Four reduction functions are needed to build
four HTs. Let the reduction functions be:
z z
R1 ( z ) =
2 R2 ( z ) = ( z mod 16) * 16 + mod N
16
342 11 Introduction to Cryptanalysis Attacks on Symmetric Ciphers
z z
R3 ( z ) = 3 z − 11 mod N R4 ( z ) : −
2 7
Let the random start points be:
{15, 32, 17, 36, 24, 11, 48, 61, 57, 10, 4, 42, 63, 19, 54, 26 }.
The HT matrices are shown in Table 11.1.
Notice that there exist collisions in HTs 1, 2, and 4 (e.g. chains 3 and 4 in HT 1 have three common values). All endpoints
are distinct in all HTs, which makes higher the probability of key search success.
2) Key search in HTs
Three scenarios are considered.
i) Scenario 1: plaintext encrypted with K = 36
Hence, C0 = 57 * 36 mod 128 = 4
⚪ Table 1 exploration
y1 = R1 (C0 ) = R1 (4) = 2 . 2 is the endpoint in chain 2 in table 1. x 21,3 = 36 is the correct key.
ii) Scenario 2: plaintext encrypted with K = 17
Hence, C0 = 57 ∗ 17 mod 128 = 73
⚪ Table 1 exploration
SPib and EPib denote start and end points of Hellman’s table b (b = 1, …, 4).
11.1 Memory-Time Trade-off Attacks 343
Distinguished points
Rivest suggested an improvement of the original Hellman’s tables, cited in [2]. Rivest observed that the number of table
lookups (and consequently the attack time) is drastically reduced if the endpoints have some property; for example, end-
points beginning with a fixed number of 0s. Such endpoints are called distinguished points. Therefore, instead of performing
exactly t computations for each start point, computations continue until an endpoint with the appropriate property is
found for each start point. Then, the improved table is used in the online key search as in the original Hellman’s algorithm.
M start points are randomly selected in key space. Let SP1 , SP2 , …, SPM be the selected start points. Then, the keys of
rainbow chain i (1 ≤ i ≤ M ) are computed as follows:
Figures 11.2 and 11.3 show the construction of a rainbow table and the difference between t HTs and one rainbow table.
fd
The notation x → y means y = Rd ( Encd−1 ( P0 )). As in Hellman’s tables, only start and end points of rainbow chains are
saved in memory.
Key search in rainbow table
It is worth noticing that lookup in a rainbow table is a little bit more complex than that in Hellman’s table, because t reduction
functions are used in every rainbow chain, while the same reduction function is used in all the chains of the same HT.
Given a ciphertext C0 associated with plaintext P0 , the secret key search is performed column by column starting with
column t −1 and ending with column 0 . Below are the conditions for the secret key K to be in column d, 0 ≤ d < t , of
chain i:
● Key K is in column t −1:
If K = x i,t −1 , then x i,t = Rt Enc x ( P0 ) = Rt Enc K ( P0 ) = Rt C0 .
i ,t −1
Figure 11.3 (a) Three 3*3 Hellman’s tables and (b) one 9*3 Rainbow table.
11.1 Memory-Time Trade-off Attacks 345
● Key K is in column t − 2:
If K = x i,t −2 , then x i,t −1 = Rt −1 Enc x ( P0 ) = Rt −1 Enc K ( P0 ) = Rt −1 C0 and x i,t = Rt Enc x ( P0 ) = Rt EncR C ( P0 )
i ,t −2 i ,t −1 t −1 0
= ft ( Rt −1 C0 ) = EPi
● Key is in column t −3:
If K = x i,t −3 , then x i,t −2 = Rt −2 Enc x ( P0 ) = Rt −2 Enc K ( P0 ) = Rt −2 C0 ,
i ,t −3
x i,t −1 = Rt −1 Enc x ( P0 ) = Rt −1 EncR C ( P0 ) = ft −1 ( Rt −2 C0 )
i ,t −2 t −2 0
(
x i,t = ft ft −1 ( Rt −2 C0 ) = EPi )
● Iteratively, the condition for key K to be in column d, 0 ≤ d < t − 3 , is:
(
If K = x i,d , then x i,t = ft ft −1 …. fd+1 ( Rd C0 )… = EPi )
y = f ( f ( f …( f ( R C )))).
t t t −1 t −2 2 1 0
From the previous conditions, the iterative search in the rainbow table is constructed according to the following pseudocode:
Attack success probability
When two rainbow chains i and j collide at points k1 and k2 , they merge only if k1 = k2 . Therefore, the probability for two
1
chains of length t to merge is . Hence, the probability of attack success, given in [3], is:
t
t
M
P r ( M , t ) ≥ 1 − ∏1 − i
i=1
N
M
− k
where M1 = M and M k +1 = N 1 − e N .
If M = m ∗ t and t distinct reductions functions are used in both table types, then the success probability of a rainbow table
of size M ∗ t is equivalent to that of t HTs of size m ∗ t .
346 11 Introduction to Cryptanalysis Attacks on Symmetric Ciphers
( ( (
which requires one encryption-reduction operation. To test if it is in column 0 , yt = ft ft −1 ft −2 … f2 ( R1 C0 ) ))) is calcu-
t (t − 1)
lated, which requires t −1 encryption-reduction operations. To compute each yd , d = 1, …, t , encryption-reduction
2
operations are required, which is the half of that needed for Hellman’s tables.
In addition to encryption-reduction operations, t table lookup operations are needed to check if each yi is an endpoint;
and t chain reconstruction operations to check if each yi is the correct key. Since encryption-reduction operation dominate
t (t − 1)
in computation, the complexity of rainbow-table-based attack, with t = N 1/3 , is * N 1 /3 .
2
Example 11.2 The following is a simple example to show how a rainbow chain-based attack works. Let the key space size
be N = 64. Choose a simple encryption, say Enck ( P ) = P * k mod 2 N . Plaintexts and ciphertexts are of 7-bit length.
Assume that the known plaintext is P0 = 57 .
1) Building of rainbow table
According to Hellman’s recommendation (i.e. m = t = N 2/3 ), let m = t = 4 .
Four reduction functions are needed to build the rainbow table. The reduction functions and start points are the same as
those used in Example 11.2:
z z
R1 ( z ) = R2 ( z ) = ( z mod 16) * 16 + mod N
2 16
z z
R3 ( z ) = 3 z − 11 mod N R4 ( z ) = −
2 7
The start point set is {10, 63, 54, 19, 4, 32, 48, 57, 15, 42, 24, 61,17, 36, 26, 11}.
The rainbow table is shown in Table 11.2:
j 1 2 3 4
0
i ( R1) ( R2 ) ( R3 ) ( R4 )
1 10 29 23 18 1
2 63 3 50 27 1
3 54 3 50 27 1
4 19 29 23 18 1
5 4 50 34 43 7
6 32 16 1 32 12
7 48 24 5 12 16
8 57 24 5 12 16
9 15 43 49 48 18
10 42 45 16 37 22
11 24 44 4 33 32
12 61 10 35 22 37
13 17 36 0 11 41
14 36 2 39 2 41
15 26 37 19 38 43
16 11 57 19 38 43
11.2 Linear Cryptanalysis 347
Merges and false alarms are highlighted in gray. For example, chains 2 and 3 merge, because a collision occurred in posi-
tion j = 1 for both chains, while chains 15 and 16 merge, because a collision occurred in position j = 2 for both chains.
Endpoint 1 has four inverse images, while endpoints 16, 41, and 43 all have two inverse images. Merges and false alarms
are frequent when the key space is small, which is the case of this example (N = 64).
2) Key search in rainbow table
Three scenarios are considered.
i) Scenario 1: plaintext encrypted with K = 27
C0 = 57 * 27 mod 128 = 3.
3 3
y1 = R4 (C0 ) = − = 1. 1 is the endpoint of chains 1, 2, 3, and 4 . Key is x 2,3 = x3,3 = 27 , which is the correct key.
2 7
Testing keys x1,3 and x 4,3 (both equal to 18 ) results in incorrect key.
ii) Scenario 2: plaintext encrypted with K = 5
Hence, C0 = 57 ∗ 5 mod 128 = 29.
29 29
y1 = R4 (C0 ) = − = 10 , which is not an endpoint.
2 7
y2 = f4 ( R3 C0 ) = f4 ( (3 ∗ 29 − 11) )
mod 64 = f4 (12) = R4 ( Enc12 ( P0 )) = 16, which is the endpoint of chains 7 and 8.
x 7,2 = x 8,2 = 5 , which is the correct key.
iii) Scenario 3: plaintext encrypted with K = 6
C0 = 57 ∗ 6 mod 128 = 86 .
86 86
y1 = R4 (C0 ) = − = 31, which is not an endpoint.
2 7
y2 = f4 ( R3 C0 ) = f4 ( (3 ∗ 86 − 11) mod 64) = f4 (55) = R4 (Enc55 (P0 )) = R4 (63) = 22, which is the endpoint of chain 10;
but it is a false alarm.
( ) ( )
y3 = f4 f3 ( R2 (C0 )) = f4 ( f3 (37)) = f4 R3 ( Enc37 (57)) = f4 ( R3 (61)) = f4 (44) = R4 ( Enc44 (57)) = 28 , which is not an
endpoint.
( ( )) ( )
y4 = f4 f3 f2 ( R1 (C0 )) = f4 f3 ( f2 (43)) = f4 ( f3 (49)) = f4 (48) = 18 ,
which is the endpoint of chain 9; but it is a false alarm.
Stop the search.
Conclusion: no correct key is recovered in scenario 3. If one visually inspects the rainbow table, no element equal to 6
is present. Therefore, there is no chance that the correct key can be found in the table.
Linear cryptanalysis technique was first introduced by Mitsuru Matsui, who applied it to DES cipher [4]. Using CPU tech-
nology of the 1990s, 12-round DES was broken in 50 hours using 233 known plaintexts; and 16-round DES was broken,
using 247 known plaintexts.
Linear cryptanalysis is applied to key-alternating block ciphers to either disclose some plaintexts or to recover the cipher
key [5]. It may be used in known-plaintext attacks or only-ciphertext attacks. In the following, we only focus on known-
plaintext attacks. The probability of attack success depends on the number of known plaintext‒ciphertext pairs; in general,
this number is large. The basic ideas of linear cryptanalysis are:
● Find relationships, in form of linear approximations, between bits of plaintext, ciphertext, and key.
● Use each linear approximation as distinguisher to predict one bit of information about an unknown plaintext, the cipher
key or the last-round key.
Linear cryptanalysis is suitable against key-alternating block ciphers (such as DES and AES) where the key of round i is
XORed with the round input to yield the round output, using a transformation function (as shown on Figure 11.4). The
348 11 Introduction to Cryptanalysis Attacks on Symmetric Ciphers
relationships are associated with one round, some rounds, or the full cipher. Specifically, linear cryptanalysis tries to
linearly approximate the nonlinear components of a block cipher. Recall that s-boxes are the main nonlinear functions
used in block ciphers.
Let X 1 , X 2 , …, X m be m independent random binary variables whose values are 0 with probability pi or 1 with probabil-
1 m
ity 1− pi. Then, the probability that X 1 ⊕ X 2 ⊕ … ⊕ X m is equal to 0 is : + 2m−1 ∏ ( pi − 1 / 2).
2 i=1
In particular, ε1,2 , the bias of two random binary variables, X 1 and X 2 , is ε1,2 = 2ε1ε2 .
1
Notice that if any of variables X i , i = 1, ..., m, is unbiased (i.e. εi = 0), then Pr ( X 1 ⊕ X 2 ⊕… ⊕ X m = 0) = . There exists
2
a linear relationship between m variables X i=1,…,m , only if the bias ε1,…,m is not zero.
The second linear expression form, which is used in the sequel, is specified as:
(α ⋅ P ) ⊕ (β ⋅ C ) ⊕ (κ ⋅ K ) = 0
(11.7)
= ⊕ (αi ⋅ Pi ) ⊕ ⊕ (βi ⋅ Ci ) ⊕ ⊕ (κi ⋅ K i ) = 0
i=1,…,b i=1,…,b i=1,…,b
where α , β , and κ are called masks of plaintext, ciphertext, and key, respectively, such that: α = ∑ a i , i ,…, i 2b−a ,
{ 1 2 p}
β = ∑ a j , j ,…, j 2b−a, and Κ = ∑ a{k ,k ,...,k } 2b−a .
{ 1 2 q} 1 2 u
αi=1,…,b , βi=1,…,b , and κi=1,…,b are all binary constants. “.” denotes the bit product operation (i.e. AND operation) and
⊕ denotes the XOR operation of b binary variables.
i=1,…,b
Example 11.4 Consider an s-box, which takes four bits and outputs four bits, according to the table in Figure 11.5. As you
may see the s-box is not a linear function.
Three linear expressions are tried: X 1 ⊕ X 4 = Y4 , X 2 ⊕ X 3 = Y4 , and X 2 ⊕ X 3 = Y1 ⊕ Y2 .
In Table 11.3, incorrect approximations are highlighted in gray.
12 1 1
Pr ( X 1 ⊕ X 4 = Y4 ) = Pr ( X 1 ⊕ X 4 ⊕ Y4 = 0) = 12 / 16 . The bias is − = .
16 2 4
350 11 Introduction to Cryptanalysis Attacks on Symmetric Ciphers
Y4 = Y4 = Y1 ⊕ Y2 =
X1 X2 X3 X4 Y1 Y2 Y3 Y4 X 1 ⊕ X 4 X 2 ⊕ X 3 X 2 ⊕ X 3
Pr ( X 2 ⊕ X 3 = Y4 ) = Pr ( X 2 ⊕ X 3 ⊕ Y4 = 0) = 1 / 2 . The bias is 0 .
12 1 1
Pr ( X 2 ⊕ X 3 = Y1 ⊕ Y2 ) = Pr ( X 2 ⊕ X 3 ⊕ Y1 ⊕ Y2 = 0) = 12 / 16 . The bias is − = .
16 2 4
The first and third linear approximations of the s-box are more likely to be correct than the second one. They are good
linear approximations; they are written as follows:
Example 11.5 Table 11.4 is the LAT corresponding to the s-box specified in Figure 11.5.
β
α 0 1 2 3 4 5 6 7 8 9 a b c d e f
0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 –4 0 –4 0 0 0 0 0 –4 0 4
2 0 0 2 2 –2 –2 0 0 2 –2 0 4 0 4 –2 2
3 0 0 2 2 2 –2 –4 0 –2 2 –4 0 0 0 –2 –2
4 0 0 –2 2 –2 –2 0 4 –2 –2 0 –4 0 0 –2 2
5 0 0 –2 2 –2 2 0 0 2 2 –4 0 4 0 2 2
6 0 0 0 –4 0 0 –4 0 0 –4 0 0 4 0 0 0
7 0 0 0 4 4 0 0 0 0 –4 0 0 0 0 4 0
8 0 0 2 –2 0 0 –2 2 –2 2 0 0 –2 2 4 4
9 0 4 –2 –2 0 0 2 –2 –2 –2 –4 0 –2 2 0 0
a 0 0 4 0 2 2 2 –2 0 0 0 –4 2 2 –2 2
b 0 –4 0 0 –2 –2 2 –2 –4 0 0 0 2 2 2 –2
c 0 0 0 0 –2 –2 –2 –2 4 0 0 –4 –2 2 2 –2
d 0 4 4 0 –2 –2 2 2 0 0 0 0 2 –2 2 –2
e 0 0 2 2 –4 4 –2 –2 –2 –2 0 0 –2 –2 0 0
f 0 4 –2 2 0 0 –2 –2 –2 2 4 0 2 2 0 0
352 11 Introduction to Cryptanalysis Attacks on Symmetric Ciphers
(α ⋅(P ⊕ K )) ⊕ (β ⋅ C ) = 0
The form above is equivalent to (α ⋅ P ) ⊕ (β ⋅ C ) = α ⋅ K , meaning that if some
information is known about some bits of the plaintext and ciphertext, then some
information could be deduced about some bits of the key. For example, if
(0110 ⋅ P) ⊕ (0 0 01 ⋅ C ) = 0 = (0 011 ⋅ K ), then K3 ⊕ K 4 = 0 . Therefore, the 3rd and
4th bits of the key are both equal either to 1 or to 0.
Figure 11.6 Example of a toy-cipher
with one round. 11.2.2.4 Finding Linear Expressions Associated with Two s-boxes and a Key
Consider the toy-cipher, illustrated by Figure 11.7, which makes use of two
s-boxes. The cipher has two rounds. Let K r denote the key of round r and kir=1…,4 ,
the four bits of k r . We can express linear expressions of the form:
( )
α ⋅ P ⊕ K 1 = β1 ⋅Y 1 (11.9)
β 1 ⋅ (Y 1 ⊕ K 2 ) = β 2 ⋅ C (11.10)
where, Y r , β r , and K r denote the output, the output mask, and the key of round
r , respectively. Combining equations (11.9) and (11.10) yields:
Example 11.6 Consider the cipher illustrated by Figure 11.7. We can use the following two expressions to express a linear
approximations to infer some information about the 1st bit of the second key round from the approximation of the 1st and
4th bits of the first round key and the plaintext (as shown by the masks):
( ( )) (
L1 := 1001· P ⊕ K 1 = 0001·Y 1 )
L := ( 0001·(Y
2 1
⊕ K 2 )) = ( 0101·Y 2 )
1
For the second linear approximation: LAT (1, 5) = −4 = 24 * ε2 ⇒ ε2 = − . Hence, the second expression holds with a
4
1 1 1
probability of P2 = − = .
2 4 4
For the third linear approximation, we use Piling-up lemma applied to two random binary variables in L1 and L2 :
1 1 1 3
ε1,2 = 2 * ε1 * ε2 = − . Hence, the third expression holds with a probability of P3 = − = .
8 2 8 8
Example 11.7
Notations
b : bit-length of plaintext, ciphertext, and key
Pi , i = 1,…, b : plaintext bits; Ci , i = 1,…, b : ciphertext bits
R: number of rounds
d: number of s-boxes per round; m: number of input (or output) bits per s-box
K r : key of round r , r = 1,…, R ; K ir , i = 1,…, b : bits of K r
Y r : output of round r ; Yir , i = 1,…, b : bits of Y r
U lr, j , l = 1,…, d, j = 1,…, m : input bits of s-box Slr
Vlr, j , l = 1,…, d, j = 1,…, m : output bits of s-box Slr
LAT l (i, j ): value of the LAT of s-box l at row i and column j.
Consider the cipher illustrated by Figure 11.8, where b = 16, R = 5 , and d = m = 4. In each round r , with the exception of
the first and last rounds, the output of round r −1 is permuted and then XORed with the key of round r to feed s-boxes of
round r . A single permutation is used in the entire cipher, with the following mapping:
(( ) ( ) (
L1 := P2 ⊕ K 21 ⊕ P3 ⊕ K31 ⊕ P4 ⊕ K 41 )) ⊕ Y31 ⊕ Y41 = 0
where Y31 = V11,3 and Y41 = V11,4 . So,
( (
L1 := ( P2 ⊕ P3 ⊕ P4 ) ⊕ K 21 ⊕ K31 ⊕ K 41 )) ⊕ Y31 ⊕ Y41 = 0
Let ΩP = P2 ⊕ P3 ⊕ P4 and ΩK 1 = K 21 ⊕ K31 ⊕ K 41. So,
(
L1 := ΩP ⊕ Ω K 1 ⊕ Y31 ⊕ Y41 = 0 )
Let ε1 denote the bias of linear approximation L1. Since only s-box S11 is used,
LAT 1 (7, 3) 4 1
ε1 = = = .
16 16 4
354 11 Introduction to Cryptanalysis Attacks on Symmetric Ciphers
Figure 11.8 Cipher with four rounds, four s-boxes per round, and a permutation.
( ) ( )
L2 := U 42,2 ⊕ U 42,3 ⊕ Y132 ⊕ Y142 = 0
((
L2 := Y41 ⊕ K14
2
) (
⊕ Y31 ⊕ K15
2
)) ⊕ (Y132 ⊕ Y142 ) = 0
2 2
Let ΩK 2 = K14 ⊕ K15. Thus,
(
L2 : = ΩP ⊕ ΩK 1 ⊕ ΩK 2 ⊕ Y132 ⊕ Y142 = 0 )
Let ε2 denote the bias of linear approximation L2 . Since two s-boxes are used, by Piling-up lemma, ε2 = 2 *
LAT 1 (7, 3) LAT 4 (6, 12) 4 4 1
* =2* * = .
16 16 16 16 8
11.2 Linear Cryptanalysis 355
( ) (
L3 := U 23,2 ⊕ U 33,3 ⊕ Y63 ⊕ Y73 ⊕ Y83 ⊕ Y113 ⊕ Y123 = 0 )
where Y63 = V23,2 , Y73 = V23,3 , Y83 = V23,4 , Y113 = V33,3 , Y123 = V33,4 . So,
(( ) (
L3 := Y142 ⊕ K 63 ⊕ Y132 ⊕ K11
3
)) ⊕ (Y63 ⊕ Y73 ⊕ Y83 ⊕ Y113 ⊕ Y123 ) = 0
Let ΩK 3 = K 63 ⊕ K11
3
. Thus,
(
L3 := ΩP ⊕ ΩK 1 ⊕ ΩK 2 ⊕ ΩK 3 ⊕ Y63 ⊕ Y73 ⊕ Y83 ⊕ Y113 ⊕ Y123 = 0 )
Let ε3 denote the bias of linear approximation L3 . Four s-boxes are used; by Piling-up lemma,
( ) (
L4 := U14,1 ⊕ U14,3 ⊕ U14,4 ⊕ U 24,1 ⊕ U 24,3 ⊕ Y44 ⊕ Y54 ⊕ Y74 ⊕ Y84 = 0 )
where Y14 = C4 ⊕ K 45 , Y54 = C5 ⊕ K55 , Y74 = C7 ⊕ K 75 , Y84 = C8 ⊕ K 85 . So,
(( ) (
L4 := Y63 ⊕ K14 ⊕ Y123 ⊕ K34 ) ⊕ (Y83 ) ( ) (
⊕ K 44 ⊕ Y113 ⊕ K54 ⊕ Y73 ⊕ K 74 ))
(( ) ( ) ( ) (
⊕ C4 ⊕ K 45 ⊕ C5 ⊕ K55 ⊕ C7 ⊕ K 75 ⊕ C8 ⊕ K 85 = 0 ))
Let ΩK 4 = K14 ⊕ K34 ⊕ K 44 ⊕ K55 ⊕ K 74 and ΩK 5 = K 45 ⊕ K55 ⊕ K 75 ⊕ K 85.
Let ΩK = ΩP ⊕ ΩK 1 ⊕ ΩK 2 ⊕ ΩK 3 ⊕ ΩK 4 ⊕ ΩK 5
Finally, L4 becomes
L4 : = ( P2 ⊕ P3 ⊕ P4 )⊕ (C4 ⊕ C5 ⊕ C7 ⊕ C8 )⊕ ΩK
Let ε 4 denote the bias of linear approximation L4 . Six s-boxes are used; by Piling-up lemma,
4 4 4 2 −4 −4 1
= 25 * * * * * * = .
16 16 16 16 16 16 256
Linear equation L4 is a full-cipher linear approximation. Since the bias ε 4 is positive, linear equation L4 holds with a
1 1 129
probability of + = . Using mask notation, L4 can be rewritten as:
2 256 256
L4 := 0111 0000 0000 0000·P ⊕ 0001 1011 0000 0000·C = ΩK ,
356 11 Introduction to Cryptanalysis Attacks on Symmetric Ciphers
Matsui-Algorithm 1
( )
Let P i , C i , i = 1,…, N , be N known plaintext–ciphertext pairs. All plaintexts are encrypted with the same key.
Linear full-cipher approximation is (π·P ) ⊕ (σ·C ) ⊕ (κ·K ) = 0
Let ε be the bias of the linear full-cipher approximation
T =0
( ) ( )
for i = 1 to N do if π·P i ⊕ σ·C i = 0 , then T = T +1
if T > N / 2, then if ε > 0, then guess κ·K = 0 else guess κ·K = 1
else if ε > 0, then guess κ·K = 1 else guess κ·K = 0
Example 11.8 Consider the toy-cipher illustrated by Figure 11.9. All arguments are of a bit-length of 4. The cipher runs
in two rounds, which make use of the same s-box. The linear approximation table of the used s-box is identical to that given
in Table 11.4. The key of the first round is the cipher key; and that of the second round is yielded by a permutation of the
first key. The encryption of all plaintexts using all keys is shown in Table 11.5.
Assume that the following plaintext–ciphertext pairs are known:
(1, 12), (2, 8), (4, 9), (5, 13), (8, 10), (12, 11), (15, 14).
11.2 Linear Cryptanalysis 357
(((P ⊕ K ) ⊕ (P ⊕ K )) ⊕ K
1
1
1 3
1
3
1 1
3 ⊕ K4 )
⊕ K11 ⊕ C4 = 0
1 1 1
which can be rewritten as 10·P ⊕ 1·C = K 41 ; it has a bias of 2− − = Figure 11.9 Example of a toy-cipher with
4 4 8
two s-boxes and a key permutation.
We apply Matsui’s algorithm 1, with N , the number of known plaintexts, of 7:
● Computation of V ( P, C ) = 10 ⋅ P ⊕ 1 ⋅ C , for known plaintexts
V (1, 12) = 0 V (2, 8) = 1 V (4, 9) = 1 V (5, 13) = 1
V (8, 10) = 1 V (12, 11) = 0 V (15, 14) = 0
● The bias is positive and the count T is equal to 3, which is less than 7 / 2 . Hence, we guess that K 41 = 1 .
K 0 1 2 3 4 5 6 7 8 9 a b c d e f
P
0 4 d 1 5 7 a a b 6 7 a b 5 c 4 7
1 0 1 b 4 9 2 5 9 2 c 5 9 6 b 2 1
2 a e 9 2 1 8 0 1 1 8 f 0 9 0 e 3
3 8 9 7 a e 4 4 d e 4 d 3 d a f 8
4 e 6 6 d 3 b f 0 0 9 3 e a e 6 d
5 c 8 0 c 5 f d 3 a d 8 f 8 9 0 c
6 f 2 5 f 6 7 c 8 c 5 7 4 f 2 1 5
7 7 3 3 b 2 c e 6 b 6 1 2 7 3 b 4
8 b 4 d 6 c 5 7 4 7 a 2 c 4 d d 6
9 1 5 c 0 b 6 1 2 9 2 6 7 0 1 c 0
a 2 f 8 9 0 9 3 e d 3 0 1 2 f 9 2
b 3 7 a e a d 8 f f 0 4 d 3 7 7 a
c 9 0 e 3 d 3 b a 3 b b a e 6 8 9
d d a f 8 f 0 9 5 5 f 9 5 c 8 a e
e 5 c 4 7 8 1 2 c 8 1 c 8 b 4 5 f
f 6 b 2 1 4 e 6 7 4 e e 6 1 5 3 b
358 11 Introduction to Cryptanalysis Attacks on Symmetric Ciphers
From the LAT of chosen s-box, we select LAT (15, 7). Therefore, the linear approximation for the first round
( (
is 15· P ⊕ K 1 )) ⊕ (7·Y ), which has a bias of −1 / 8. In bit representation, linear approximation for the first round is:
(P1 ⊕ K11 ) ⊕ (P2 ⊕ K21 ) ⊕ (P3 ⊕ K31 ) ⊕ (P4 ⊕ K 41 ) ⊕ Y2 ⊕ Y3 ⊕ Y4 = 0
For the second round, we use LAT (7, 3). Hence, the linear approximation for the second round is 7 ⋅ Y ⊕ K 2 ( ( )) ⊕ (3 ⋅ C ),
which corresponds to a bias of 1 / 4 .
In bit representation, linear approximation for the second round is:
Using key permutation, where K12 = K31 , K 22 = K 21 , K32 = K 41 , and K 42 = K11 , the linear approximation becomes:
1 1 1
P1 ⊕ P3 ⊕ P4 ⊕ C2 ⊕ C4 = K11 ⊕ K 21; and its bias is of 2 = .
8 4 16
We apply Matsui’s algorithm 1, with N , the number of known plaintexts, of 7:
With three full-cipher linear approximations, we know that K11 ⊕ K 21 = 1, K31 = 0, and K 41 = 1. Therefore, the cipher key
is either 5 or 9. The latter is the correct key.
11.2 Linear Cryptanalysis 359
( ) ( ) (
π ⋅ P ⊕ σ ⋅ U R−1 = π1 ⋅ K 1 ⊕ π 2 ⋅ K 2 ⊕…⊕ π R−1 ⋅ K R−1 = κ ⋅ K) (11.12)
where U R−1 and σ denote the input of s-boxes of round R −1 and their corresponding mask; and π i , i = 2, ..., R − 1
denotes the mask of the key of round i. Masks π and π1 are identical, because the first-round key and plaintext are
XORed (without permutation) to feed s-boxes in the first round. Y R−1 , the output of s-boxes of round R −1, is referred
to as intermediate ciphertext, because Y R−1 = C ⊕ K R .
( ) ( ) ( )
Once the cipher key is fixed, the sum Ω = π1 ⋅ K 1 ⊕ π 2 ⋅ K 2 ⊕…⊕ π R−1 ⋅ K R−1 is a fix value, either 0 or 1, depending
1 1
on the cipher key. Therefore, linear expression (11.12) holds with a probability of + ε , if Ω = 0 or − ε, if Ω = 1.
2 2
2) Recovery of bits of the last-round key
In the cipher structure under consideration, the output of round R −1 is XORed with the key of round R to produce the
ciphertext. Hence, the basic idea of Algorithm 2 is to find a last-round key candidate, such that the partial decryption of
known ciphertexts most likely yields the inputs of s-boxes of round R −1. Notice that last-round key candidates refer to
varying bits corresponding to active s-boxes in round R −1. Pseudocode of Algorithm 2 is as follows:
Matsui-Algorithm 2
( )
1) Let P i , C i , i = 1,…, N , be N known plaintext–ciphertext pairs.
All the plaintexts are encrypted with the same key.
2) Let R be the number of rounds.
3) Let ε be the bias of selected linear partial-cipher approximation.
4) Let π , σ , and κ denote masks of plaintext, input of s-boxes of round R −1 , and cipher key, in the selected partial-
cipher linear-approximation.
5) Let ReverseSboxes denote a function that, given the output of s-boxes in round R −1 , returns the input of those
s-boxes.
6) Let f denote the number of active s-boxes in round R −1 .
7) Let KC R be the list of key candidates obtained by varying from 0 to 2m − 1 bits at the positions corresponding to
each of the f active s-boxes; and the bits corresponding to inactive s-boxes are set to 0.
m denotes the bit-length of s-box input (and output).
With f active s-boxes, there exist m f key candidates.
Let KC(Rj ) , j = 1, 2,…, m f denote the j th last-round key candidate.
8) for j = 1 to m f do T j = 0
9) for i = 1 to N do
Y R−1 = C i ⊕ K(Rj ) # partial decryption
( )
U R−1 = ReverseSboxes Y R−1 # use backward the s-boxes
( i
if π·P ⊕ σ·U ) ( R−1
) = 0 , then Tj = Tj + 1
(Continued)
360 11 Introduction to Cryptanalysis Attacks on Symmetric Ciphers
(Continued)
Example 11.9 Reuse the 3rd linear approximation selected in Example 11.7.
(
L3 := ΩP ⊕ ΩK 1 ⊕ ΩK 2 ⊕ ΩK 3 ⊕ Y63 ⊕ Y73 ⊕ Y83 ⊕ Y113 ⊕ Y123 = 0. )
where: ΩP = P2 ⊕ P3 ⊕ P4 ; ΩK 1 = K 21 ⊕ K31 ⊕ K 41 ; 2
ΩK 2 = K14 2
⊕ K15 ; ΩK 3 = K 63 ⊕ K11
3
By construction of the cipher structure under consideration, the following equations hold:
The set of last-round key candidates is composed of 256 keys, by varying the eight leftmost bits from 0 x 00 to 0xff and the
eight rightmost bits are 0 x 00 .
Notes
— Linear cryptanalysis attack, as described in this section, is a known-plaintext attack. The randomness of known pairs
has an impact on the attack success probability.
— Collected plaintext-ciphertext pairs should be associated with the same key. Otherwise, the linear approximations are
likely to be wrong. Collecting plaintexts encrypted with two or more keys, leads to an unsuccessful attack.
— Linear cryptanalysis is a nongeneric attack. Therefore, linear approximations depend on the structure of attacked
cipher, i.e. how its components (s-boxes, permutations, and other linear or nonlinear functions) are combined to pro-
duce ciphertexts.
In the beginning of the 1990s, Biham and Shamir applied differential cryptanalysis to successfully break DES [6]. Using the
technology of the early 1990s, DES with six rounds was broken in less than 0.3 seconds, DES with eight rounds in two min-
utes, and DES with 15 rounds in less time than that of an exhaustive search. Attacks against 15 and 16 rounds required 247
chosen plaintexts.
Like linear cryptanalysis, differential cryptanalysis focuses on key-iterating ciphers, in which output bits of s-boxes of
round r −1 are permuted and then XORed with the r th round key to form the input of s-boxes of round r , as illustrated by
Figure 11.8 [5].
11.3 Differential Cryptanalysis 361
Differential cryptography attack is a chosen-plaintext attack that takes advantage of the effect, with high probability, of
differences in plaintexts on the differences in the last round input. In this model, the attacker can request a cryptosystem
to encrypt plaintexts of his/her choice using the target key (which is not known to the attacker). By analyzing the returned
ciphertexts, the attacker can guess the key being used. The best characteristics (represented as differences between inputs
and between outputs of each s-box) of individual s-boxes are combined to yield an overall characteristic of the cipher,
which in turn enables to recover some bits of the last-round key; and the remaining bits may be recovered by a brute-force
attack. The first step of a differential attack is the construction of difference distribution tables associated with s-boxes.
( )( )
∆Z = Z − Z * = Z ⊕ Z * = Z1 ⊕ Z1* , Z2 ⊕ Z2* , …, Zn ⊕ Zn*
( ) .
( )
Let C = Enc ( P ) = 10001111 and C * = Enc P * = 01001001 .
Then, ∆C = C ⊕ ∆C * = 1100 0110 .
Definition 11.1 Difference set of α (denoted ∆α): it is a set of ordered pairs of elements, which have a difference of α .
Formally, ∆α = {( X1, X 2 ) ∈ F2n × F2n | X1 ⊕ X 2 = α}. Alternatively, ∆α can be defined by ∆α = {( X , X ⊕ α) | X ∈ F2n }.
Definition 11.2 Difference set of s-box S with respect to α and β (denoted ∆αS ,β ): it is a set of ordered pairs of elements,
which have a difference in s-box input of α and a difference in s-box output of β . Formally,
∆αS ,β = {( X1, X 2 ) ∈ F2n × F2n | ( X1 ⊕ X 2 = α) ∧ (S ( X1 ) ⊕ S ( X 2 )) = β}. Alternatively, it can be defined by:
Example 11.11 Consider elements of finite field F24 . Let α = 9. The difference set when α = 9 is denoted ∆9 ; and it
contains the following pairs (in binary representation):
{(0, 9), (1, 8), (2, 11), (3, 10), (4, 13), (5, 12),(6, 15), (7,14), (8, 1), (9, 0), (10, 3), (11, 2), (12, 5), (13, 4), (14, 7), (15, 6)}.
Table 11.6 shows the differences in s-box output, when the difference in input is α = 9. The s-box is the same than that
of Figure 11.5 and the numbers are in hexadecimal representation. Difference sets of chosen s-box S, with respect to α = 9
and β ∈ {2, 4, 6, 8,e} are the following:
∆9S,2 = {(0, 9), (9, 0)} ∆9S,4 = {(3, a ), (5, c), (a, 3), (c, 5)} ∆9S,6 = {(1, 8), (8, 1)}
∆9S,8 = {(6, f ), (f , 6)} ∆9S,c = {(7, e), (e, 7)} ∆9S,e = {(2, b), (4, d), ( b, 2), (d, 4)}
Definition 11.3 Difference distribution table of an s-box S (denoted DS ): it is an n-by-m matrix, where the entry indexed
by α and β corresponds to the number of pairs which have a difference in s-box input of α and a difference in s-box output of
β . Formally, DαS ,β = ∆αS ,β , for (α, β ) ∈ F2n × F2m , where . denotes the cardinality of a set.
362 11 Introduction to Cryptanalysis Attacks on Symmetric Ciphers
X X ⊕9 S (X ) S ( X ⊕ 9) S ( X ⊕ 9) ⊕ S ( X )
0 9 c e 2
1 8 5 3 6
2 b 6 8 e
3 a b f 4
4 d 9 7 e
5 c 0 4 4
6 f a 2 8
7 e d 1 c
8 1 3 5 6
9 0 e c 2
a 3 f b 4
b 2 8 6 e
c 5 4 0 4
d 4 7 9 e
e 7 1 d c
f 6 2 a 8
DaS,b = 0 means that it never happens that when the input difference is a, the output difference is b . Table 11.7 shows an
example of DDT, where the largest value is 4.
β
0 1 2 3 4 5 6 7 8 9 a b c d e f
α
0 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 4 0 0 0 4 0 4 0 0 0 4 0 0
2 0 0 0 2 0 4 2 0 0 0 2 0 2 2 2 0
3 0 2 0 2 2 0 4 2 0 0 2 2 0 0 0 0
4 0 0 0 0 0 4 2 2 0 2 2 0 2 0 2 0
5 0 2 0 0 2 0 0 0 0 2 2 2 4 2 0 0
6 0 0 2 0 0 0 2 0 2 0 0 4 2 0 0 4
7 0 4 2 0 0 0 2 0 2 0 0 0 2 0 0 4
8 0 0 0 2 0 0 0 2 0 2 0 4 0 2 0 4
9 0 0 2 0 4 0 2 0 2 0 0 0 2 0 4 0
a 0 0 2 2 0 4 0 0 2 0 2 0 0 2 2 0
b 0 2 0 0 2 0 0 0 4 2 2 2 0 2 0 0
c 0 0 2 0 0 4 0 2 2 2 2 0 0 0 2 0
d 0 2 4 2 2 0 0 2 0 0 2 2 0 0 0 0
e 0 0 2 2 0 0 2 2 2 2 0 0 2 2 0 0
f 0 4 0 0 4 0 0 0 0 0 0 0 0 0 4 4
11.3 Differential Cryptanalysis 363
Properties of DDT
i) A DDT contains 2n * 2m elements, which are all positive even integers.
ii) Element4 D0S,0 is 2n ; it is called trivial differential; and it is not used in differential cryptanalysis.
m
iii) The sum of any matrix row α is ∑ DαS ,β = 2n (see Problem 11.7).
β =1
Definition 11.4 Difference uniformity of an s-box S: it is the highest value (except the value in the first cell) of the s-box
DDT; i.e. it is equal to max ∆αS ,β .
α ≠0 ∧β ≠0
High values of the differential uniformity are better for attackers, while low values are better for cipher designers. An s-box with
a differential uniformity of η is referred to as η –uniform s-box.
Definition 11.5 Difference-propagation probability of an s-box S with respect to α and β: it is the probability that,
∆αS ,β
given an s-box input with a difference of α , the difference of output will be of β Formally, Pr S (α, β ) = n .
4 2
In Table 11.7, the highest difference-propagation probability is of .
16
Notes
— DEA (or DES) s-boxes are 6 * 4 matrices. In [6], the largest value of DES s-box DDT is of 14, with an associated proba-
14
bility of ≈ 0.22. Therefore, DEA/DES is vulnerable to differential cryptanalysis attacks.
64
— AES s-box is a 8 * 8 matrix. DDT building codes available on the internet showed that the largest AES entry is of 4, with
4
a difference-propagation probability of ≈ 0.016 . Therefore, AES is resistant to differential cryptanalysis.
256
( ) ( )
X ⊕ X * = Y r −1 ⊕ K r ⊕ Z r −1 ⊕ K r = Y r −1 ⊕ Z r −1 = α.
Therefore, the difference is the same, with or without the round key. In other words, the values of Y r−1 and Z r−1 will change as
they proceed through the XOR with the key, but their relationship (i.e. their difference) to each other will not. Therefore, since the
key bits have no effect on the difference in the s-box input, the key is ignored in the overall difference computation process.
technique (such as mixed integer linear programming). Assume that the attacker
has selected one or more s-boxes in each round, such that overall-cipher
characteristic is the highest. Selected s-boxes are referred to as active s-boxes.
As illustrated by Figure 11.10, the overall differential is denoted
(α,ω), where α = 10 010 0110 0 0 0 is the difference in plaintext and
ω = 10 010 0 0 0 0 0 01, the difference in the input of the last-but-one round.
Notice that the computation of the overall differential depends on the struc-
ture of the attacked cipher. Therefore, the description below is valid only for
ciphers with a structure similar to that shown in Figure 11.11.
The overall-cipher difference-propagation probability, denoted P is the
product of all intermediate DPPs of involved active s-boxes. Formally,
difference in plaintexts is α = 0000 01110000 0000 , then the difference in the input of the fourth round
1
is ω = 0000 0000 00110001 , with a probability of .
64
Example 11.12
Notations
b : bit-length of plaintext, ciphertext, and key
Pi , i = 1,…, b: plaintext bits; Ci , i = 1,…, b : ciphertext bits
R: number of rounds
d: number of s-boxes per round
m: number of input (or output) bits per s-box
K r : key of round r , r = 1,…, R; K ir , i = 1,…, b : bits of K r
U r : input difference of s-boxes of round r ; U ir , i = 1,…, b : bits of U r
Y r : output difference of s-boxes of round r ; Yir , i = 1,…, b : bits of Y r
Consider the cipher illustrated by Figure 11.11, where b = 16, R = 5 , and d = m = 4. In each round r , with the exception of
the first and last rounds, the output of round r −1 is permuted and then XORed with the key of round r to feed s-boxes of
round r . The first and last rounds do not make use of permutation. A single permutation is used in all rounds, with the
following mappings:
where i → (l, j ) denotes connection of bit i of permutation input to input bit j of s-box l.
In Figure 11.11, thick lines highlight how bit differences are used to combine difference-propagation probabilities.
Notice that in linear cryptanalysis example (in Figure 11.8), thick lines highlight s-box inputs, while in Figure 11.11, they
mark the difference in s-box inputs.
To simplify, assume that all s-boxes are identical to the one whose DDT is shown in Table 11.7. A good combination of s-box
differentials that we choose is constructed as follows:
1 1
● Round 1: s-box S21 is selected. One of its best differentials is ∆7S,21, with a probability of 4 / 16. ∆7S,21 means that a difference
of 7 in input of s-box S21 is likely to result in a difference of 1 in its output. Thus, the rightmost bit of the output s-box S21
is used. Therefore,
⚪ Difference in plaintext is ∆P = 0000 01110000 0000 .
⚪ Difference in input of first-round boxes is ∆U = 0000 01110000 0000 .
1
⚪ Difference in output of first-round boxes is ∆Y = 0000 00010000 0000 .
1
● Round 2: the rightmost bit of s-box S21 is connected to 4th bit of s-box S12 . Thus, S12 is selected. One of the best differentials
2
of S12 is ∆1S,13, with a probability of 4 / 16 . Therefore,
⚪ Difference in input of second-round boxes is ∆U = 00010000 0000 0000 .
2
⚪ Difference in output of second-round boxes is ∆Y = 00110000 0000 0000 .
2
● Round 3: the two rightmost bits of s-box S12 are connected to the 2nd and 3rd bits of S43 . Thus, s-box S43 is selected; one of
3
its best differential is ∆6S,b4 , with a probability of 4 / 16 . Therefore,
⚪ Difference in input of third-round boxes is ∆U = 0000 0000 0000 0110 .
3
⚪ Difference in output of third-round boxes is ∆Y = 0000 0000 00001011 .
3
● Round 4: the three selected bits of s-box S43 are connected to the 3rd and 4th bits of s-box S34 and to the 4th bit of s-box S44 .
Therefore,
⚪ Difference in input of fourth-round box is ∆U = 0000 0000 00110001 .
4
Finally, if the difference in plaintext is ∆P = 0000 01110000 0000 , then the difference in the input of s-boxes in round 4
would be ∆U 4 = 0000 0000 00110001 . That is, the overall differential is
s0 = (k0, , k1 , …, kn−1 )
bi = f ( si ), for i ≥ 0
11.4 Algebraic Cryptanalysis 367
st and bt denote the current state of LFSR and the last output bit of the cipher, respectively. Keystream bits are computed
as follows:
b = f (k , k , …, k )
0 0, 1 n−1
1 b (= f L ( 0, 1 kn−1 )
k , k , …, )
…
t(
b = f Lt (k , k , …, k )
0, 1 n−1)
When m bits of keystream, at positions i1 , i2 , …, im , are known to the adversary, he/she constructs the following equation
system:
i1 (
b = Li1 (k , k , …, k )
0, 1 n−1 )
S = i2
(
b = f L (k0, , k1 , …, kn−1 )
i2
)
…
(
bim = f L (k0, , k1 , …, kn−1 )
im
)
The degrees of polynomials yielded by function f depend on the known positions i1 , i2 , …, and im . Therefore, solving the
equation system becomes an issue. Under some assumptions regarding nonlinear function f [8], proposed a method to
significantly reduce the degrees of polynomials and then break the stream cipher.
The larger number of equations included in system S , the larger the computation time of nonlinear equation system
solver. Therefore, the attacker may need to select a subset of the equations that (hopefully) uniquely determines the key.
In addition, there is a non-null probability of failure to recover a unique key, in a reasonable time, if the number of known
keystream bits is small.
Example 11.13 Below is a simplified version of algebraic cryptanalysis. Consider the keystream generator shown in Figure
11.12. It is composed of a 4-bit LFSR and a filter function f defined6 by: f ( R0 , R1 , R2 , R3 ) = ( R0 ∧ ¬ R2 ) ∨ ( R1 ∧ ¬ R3 ) .
1) Encryption step
Let the key be k = (0, 0,1,1). The party, which encrypts a plaintext P = 10110 needs to compute the following keystream bits:
b0 = f (0, 0,1,1) = 0 b1 = f ((0 ⊕ 1), 0, 0,1) = 1
b2 = f ((1 ⊕ 1),1, 0, 0) = 1 b3 = f ((0 ⊕ 0), 0,1, 0) = 0
b4 = f ((0 ⊕ 0), 0, 0,1) = 0
Equality (a) holds, if both(k0 ∧ ¬k2 ) and (k1 ∧ ¬k3 ) are 0. Therefore, condition c1 must hold:
L(k0 , k1 , k2 , k3 ) = ((k0 ⊕ k3 ), k0 , k1 , k2 )
Equality (b) holds, if ((k0 ⊕ k3 ) ∧ ¬k1 ) = 1 or (k0 ∧ ¬k2 ) = 1 . Therefore, condition c2 must hold:
P (k1 , k2 , k3 , v1 , v2 , v3 ) =
k1k2k3 ⊕ k1k2 v1 ⊕ k1k2 v2 ⊕ k1k2 v3 ⊕ k1k3 v1 ⊕ k1k3 v2 ⊕ k1k3 v3 ⊕ k2k3 v1 ⊕
k2k3 v2 ⊕ k2k3 v3 ⊕ k1v1v2 ⊕ k1v1v3 ⊕ k1v2 v3 ⊕ k2 v1v2 ⊕ k2 v1v3 ⊕ k2 v2 v3 ⊕
k3 v1v2 ⊕ k3 v1v3 ⊕ k3 v2 v3 ⊕ v1v2 v3
⊕ k1k2 ⊕ k1k3 ⊕ k2k3 ⊕ k1v1 ⊕ k1v2 ⊕ k1v3 ⊕ k2 v1 ⊕ k2 v2 ⊕ k2 v3 ⊕ k3 v1
⊕ k3 v2 + k3 v3 ⊕ v1v2 ⊕ v1v3 ⊕ v2 v3
⊕ k1 ⊕ k2 ⊕ k3 ⊕ v1 ⊕ v2 ⊕ v3 ⊕ 1
Let VI denote a term of polynomial P , such that VI is the product of IV variables with indices in index subset I ⊆ {1, …, m}.
That is, VI = v j * v j *… v j . For example, if m = 4, then V{1,3} = v1v3 and V{1,2,3,4} = v1v2 v3 v4 .
1 1 I
Definition 11.6 Superpoly: Given a polynomial P (k1 , k2 , …, kn , v1 , v2 , …, vm ) and an index subset I ⊆ {1, …, m}, polyno-
mial PS( I ) is referred to as superpoly of subset I in P if:
a) P (k1 , k2 , …, kn , v1 , v2 , …, vm ) = VI ·P + Q (k1 , k2 , …, kn , v1 , v2 , …, vm )
S( I )
b) VI = ∏ v
∀i ∈ I i
c) No term in polynomial Q divides the product VI
d) PS( I ) and VI have no common variables
Definition 11.7 Maxterm: A maxterm of polynomial P is a term VI , such that the superpoly of I in P is of degree 1, i.e. PS( I )
is a linear polynomial, which is not a constant.
Each index subset I of size j ( j ≤ m) defines a j-dimensional binary cube, denoted C I , of 2 j vectors obtained by varying9 IV
variables included in index subset I , and leaving all other variables undetermined. Each vector w ∈ C I defines a new derived
polynomial, denoted Pw , with n + m − j variables. The variables in index subset I are called cube variables. Summing all
derived polynomials in C I , yields a new polynomial PI = ⊕ Pw , which matches the following property, proven in [9]:
w∈CI
Dinur and Shamir proved that the summation of 2 j polynomials derived from a master polynomial P by varying values of
the j IV variables included in index subset I , eliminates terms except those contained in the superpoly of I in P . Hence,
the degree of the master polynomial is reduced. In particular, the following theorem is proven in [9]:
If VI is a maxterm of polynomial P , then PI yields a linear equation in the remaining variables.
— Methods to select master polynomials are provided in [9]. The proposed methods are too long to be described in this
introductory presentation. If the selected master polynomial does not meet some conditions regarding the randomness
in its terms, the attack may fail.
— Finding the optimal degree of master polynomial for a given cipher is a hard issue, even if the internal structure of the
targeted cipher is known.
To simplify the description of the cube attack, assume that the master polynomial P has enough maxterms and correctly
represents the targeted cipher. Each maxterm may be used to yield a linear expression. Let be the number of index sets
to use in the attack. A list L of linear expressions is built as follows:
1) h = 1; L = []
2) while h < :
● Let V
I h be a maxterm not yet considered.
● Find the superpoly P corresponding to index set I h . Since VI is a maxterm, PS( I ) is a linear expression in vari-
S( I h ) h h
ables not included in I h , with a possible addition of the constant 1.
●
( )
Append pair I h , PS( I ) to list L .
h
However, it should be noticed that in practice, it is unlikely to find a master polynomial that correctly characterizes a
stream cipher, without information about its internals, to recover the correct key. The authors of the cube attack suggested
an offline test-based approach to check the validity of chosen superpoly associated with each index set. The suggested
procedure may be described as follows:
1) Choose an index set I and its superpoly PS( I ) , which is a linear expression.
2) In superpoly PS( I ) , set to either 0 or 1 all IV variables not included in PS( I ) .
I
3) Build a list VC of 2 IVs, by varying the bits corresponding to variables included in index set I , and fixing the remaining
bits as in step 2.
4) Randomly select a large number of key values. Then, for each chosen key k :
● Evaluate P , and obtain a binary value πk .
S( I )
●For each IVi in list VC , query the oracle, with k and IVi , and receive an output ρi = F (k, IVi )
● If π ≡ ∑
k / ρ mod 2, then the chosen superpoly is not valid and the test procedure stops. Otherwise, go to
i=1,…, VC i
step 4 and continue the test.
5) If the selected superpoly passes all the tests, it can be used to mount the attack.
Example 11.15 Below is a cube attack against a toy-cipher, which is composed of a 6-bit LFSR initialized with three key-
bits and IV-bits. The output function of the cipher is defined by the following polynomial of degree 6 (unknown to the
attacker):
F (k1 , k2 , k3 , v1 , v2 , v3 ) = k1k2k3 v1v2 v3 ⊕ k1k3 v1v2 v3 ⊕ k2k3 v1v2 v3 ⊕ k1k2 v3 ⊕ k1k3 v1 ⊕ k1v1v2 ⊕ k2 v1v2 ⊕ k2 v2 v3 ⊕ k1v1v3
⊕ k2 v1v3 ⊕ k3 v1v3 ⊕ k3 v2 v3 ⊕ v1v2 v3 ⊕ v1v2 ⊕ v1v3 ⊕ v2 v3
Phase 1
All the terms of any polynomial of degree 3 in 3 + 3 variables are shown in Example 11.14. We select11 a master polyno-
mial of degree 3 as follows:
We select three index sets that result in maxterms and we fix to 0 all IV variables used in superpolys.
Pv v
1 2 =00 (…) = Q1 (k1 , k2 , k3 , 0, 0, v3 )
Pv v
1 2 =10 (…) = Q1 (k1 , k2 , k3 , 1, 0, v3 )
Pv v
1 2 =01 (…) = Q1 (k1 , k2 , k3 , 0, 1, v3 )
Pv v
1 2 =11 (…) = (k1 ⊕ k2 ⊕ v3 ⊕ 1) + Q1 (k1 , k2 , k3 , 1, 1, v3 )
By property (11.15),
P{1,2} = ∑ P (…) ≡ (k1 + k2 ⊕ v3 ⊕ 1) mod 2
v1 v2∈ {00,…,11} v1 v2
By setting v3 to 0 , PS {1,2} = k1 ⊕ k2 ⊕ 1 .
( )
2) Let index set I = {1, 3}. Hence, VI = v1v3 ; VI is a maxterm.
Master polynomial P can be rewritten as a summation: P (k1 , k2 , k3 , v1 , v2 , v3 ) = v1v3 (k1 ⊕ k2 ⊕ k3 ⊕ v2 ⊕ 1)
⊕ Q2 (k1 , k2 , k3 , v1 , v2 , v3 )
The superpoly PS({1,3}) is k1 ⊕ k2 ⊕ k3 ⊕ v2 ⊕ 1 .
By property (11.15), P{1,3} ≡ (k1 ⊕ k2 ⊕ k3 ⊕ v2 ⊕ 1) mod 2
By fixing v2 = 0 ,PS({1,3}) = k1 ⊕ k2 ⊕ k3 ⊕ 1 .
3) Let index set I = {2, 3}. Hence, VI = v2 v3 ; VI is a maxterm.
Master polynomial P can be rewritten as a summation: P (k1 , k2 , k3 , v1 , v2 , v3 ) = v2 v3 (k2 ⊕ k3 ⊕ v1 ⊕ 1)
⊕ Q3 (k1 , k2 , k3 , v1 , v2 , v3 )
The superpoly PS({2,3}) is k2 ⊕ k3 ⊕ v1 ⊕ 1.
By property (11.15), P{2,3} ≡ (k2 ⊕ k3 ⊕ v1 ⊕ 1)mod 2
By setting v1 to 0, PS {2,3} = k2 ⊕ k3 ⊕ 1.
( )
The three superpolys were tested using all the eight keys.
Phase 2
We used a program to simulate the black box F ( K , IV ), where K is fix and IV is chosen by the attacker.
Use of the first set index I = {1, 2}
Query by varying variables v1 and v2 and fixing v3 to 0.
F ( K,000) = 0 F ( K,100) = 0
F ( K,010) = 0 F ( K,110) = 1
372 11 Introduction to Cryptanalysis Attacks on Symmetric Ciphers
The solution to the equation system above is k1 = 1, k2 = 1, and k3 = 0 , which corresponds to the key we fixed.
Example 11.16 Consider a single-LFSR-based stream cipher, illustrated by Figure 11.13. Let us see how a divide-and-
conquer attack can contribute to recover cipher key. The vulnerability of the stream cipher considered in this example is
that the filter function makes use only of the odd bits of LFSR.
1) An LFSR with 12 bits, denoted R0 , …, R11 , is used jointly with a filter function f ( R3 , R5 , R7 , R9 ) , which produces the
keystream …. s7 s6 s5 s4 s3 s2 s1s0 .
Initial values of LFSR bits are Ri = ki , for i = 0, …, 11, where k denotes the key.
2) Keystream bits produced in four cycles (without interference of the register feedback) are as follows:
Cycle 1: s0 = f (k3 , k5 , k7 , k9 ), then LFSR shifts.
Cycle 2: s1 = f (k2 , k4 , k6 , k8 ), then LFSR shifts.
Cycle 3: s2 = f (k1 , k3 , k5 , k7 ), then LFSR shifts.
Cycle 4: s3 = f (k0, k2, k4, k6), then LFSR shifts.
We notice that only odd bits of key (i.e. k1 , k3 , k5 , k7 , k9 ) are used to compute the even bits of the keystream (i.e. s0 , s2 )
and only even bits of key (i.e. k0 , k2 , k4 , k6 , k8 ) are used to compute odd bits of the keystream (i.e. s1 , s3 ).
Function f (.) is known to the adversary as well as a plaintext‒ciphertext pair. Instead of testing 212 distinct keys, the
adversary divides the search space into three subspaces: one subspace, to find the first five even bits of the key, a second
subspace, to find the first five odd bits, and a third subspace, to find the last two bits. Therefore, in total, the adversary
( )
tries 2 * 25 * 22 alternatives; and time complexity is reduced from 212 to 28 .
a significant influence on the output si . If no bit has an influence greater than 50%, the attack is unlikely to succeed.
4) Use each of the influencing bits to guess the key, bit per bit. The attacker can recover the key partially or entirely. At this
step an appropriate (maybe sophisticated) statistical analysis method may be used.
Example 11.17 Recall that the efficiency of correlation attacks depends on the vulnerability of the filtering function and
l, the number of known keystream bits. The stronger the bias, the more information is deduced, when analyzing the rela-
tionships between inputs and outputs of the filtering function. Let us see how the correlation attack may contribute to
recover the key of a simple cipher based on a vulnerable filtering function.
Assume a keystream generator composed of two 6-bit LFSRs R1 and R2 initialized with key bits k0 , k1 , k2 , …, k11 , as illus-
trated by Figure 11.14. Filter function f produces keystream bits as follows:
( ) (( ) ( ))
f R31 , R41 , R32 , R42 = R31 ∧ R41 ∨ R31 ∧ R32 ⊕ R42
R31 R41 R32 R42 output R31 R41 R32 R42 output
0 0 0 0 0 1 0 0 0 0
0 0 0 1 1 1 0 0 1 1
0 0 1 0 0 1 0 1 0 1
0 0 1 1 1 1 0 1 1 0
0 1 0 0 0 1 1 0 0 1
0 1 0 1 1 1 1 0 1 0
0 1 1 0 0 1 1 1 0 1
0 1 1 1 1 1 1 1 1 0
From filter function output table, one can see that bit R42 has a significant influence on the output of filter function. In 10
inputs, the output is identical to bit R42 . Therefore, under randomly chosen inputs, in average 10 / 16 of outputs are the
same as bit R42 ; and therefore, the second register has more influence on the keystream generator output than the first one.
Now, assume that the secret key is 011010 011010 . Then, assume that the adversary has derived (for example, using the
message header) the first three bits of the keystream. Let s0 = 0 , s1 = 1 , and s2 = 0 . Both LFSRs shift at each cycle.
Use of keystream bit s0 = 0 :
s0 = 0 = f (k2 , k3 , k8 , k9 )
s1 = 1 = f (k1 , k2 , k7 , k8 )
s2 = 0 = f (k0 , k1 , k6 , k7 )
At this stage, six key bits (i.e. k3 , k4 , k5 , k6 , k10 , and k11) are still unrecovered. To recover those bits, we need to test 26
candidate keys, instead of 212 , required in case of a brute-force attack.
Problem 11.2
Consider a rainbow table with m rows and t +1 columns.
1) What is the maximum probability of search success of an n-bit key, if the table has no collisions?
2) What is the memory size required to recover a 128-bit key with a probability of 1/8, assuming no collisions in the table
and a maximum computation time of 240 c? c denotes the computation time to perform an encryption-and-reduction
operation and a table lookup.
3) What do you conclude from the answer to question 2?
Problem 11.3
Given t + 1, the number of columns in a rainbow table and their associated reduction functions, prove that if the key, used
to encrypt a plaintext P0 to a ciphertext C0 , is present in the table (in one or more columns with indices less than t ), then
that key is found by the key search procedure.
1) t = 1 (i.e. a single reduction function is used)
2) t = 2 (i.e. two reduction functions are used)
Problem 11.4
Consider a linear approximation table (TAL) with random binary variables of an arbitrary bit-length b .
1) Prove that TAL(0, 0) = 2b−1 .
2) Prove that the sum of all elements of a TAL is 0.
Problem 11.5
Prove that TAL (α, β )0 = 2b * (α, β ) , where b denotes the bit-length of random binary variables, α and β are masks
of variable, and ε (α, β ), the bias depending on α and β .
Problem 11.6
1) Consider a non-well designed s-box, defined by a linear transformation Y = λ ⋅ X ⊕ µ, where λ and µ are two b -bit
constants; and X and Y are random b -bit variables. What is the bias of any linear approximation of the s-box? What
can you conclude?
2) Assume that the best bias of any s-box used in a 16-round block cipher is 1 4 . What is the best bias of a linear approxima-
tion involving one s-box in each round?
Problem 11.7
Consider the difference distribution table (DDT) of an s-box with an input and output bit-length of n; the latter is an arbi-
trary integer greater than 1.
1) Prove that every DDT element is even.
2) Prove that the sum of any row of s-box DDT is 2n .
Problem 11.8
Consider the stream cipher illustrated by Figure 11.15. It has a feedback polynomial F ( x ) = x 3 + x + 1, which is primitive.
Then, assume that the attacker intercepted a ciphertext of 703 bits and he/she knows the three last bits of the plaintext.
Show how the attacker can recover the key.
1) P0 = 57 and C0 = 114 .
114 114
y1 = R4 (C0 ) = − = 41, which is an endpoint of chains 13 and 14.
2 7
x14,4−1 = 2 , which is the correct key. Figure 11.15 Example of
stream cipher.
376 11 Introduction to Cryptanalysis Attacks on Symmetric Ciphers
2) P0 = 57 and C0 = 73 .
73 73
y1 = R4 (C0 ) = − = 26, which is not an endpoint.
2 7
( (3 * 73 − 11) mod 64) = f4 (16) = R4 ( Enc16 (P0 )) = R4 (16) = 6, which is not an endpoint.
y2 = f4 ( R3 C0 ) = f4
y3 = f4 ( f3 ( R2 (C0 ))) = f4 ( f3 (20)) = f4 ( R3 ( Enc20 (57))) = f4 ( R3 (116)) = f4 (17) = R4 ( Enc17 (57)) = 26, which is not an
endpoint.
( ( )) ( )
y4 = f4 f3 f2 ( R1 (C0 )) = f4 f3 ( f2 (36)) = f4 ( f3 (0)) = f4 (11) = 41, which is the endpoint of chains 13 and 14.
x13,0 = 17 , which is the correct key.
Problem 11.2
Recall that last column of a rainbow table contains endpoints, which are not keys.
Each test of a key in rainbow chains requires an encryption, a reduction, and a table lookup, which together take a compu-
tation time of c.
1) The number of keys is 2n . If the table has no collision, the maximum number of keys that can be found in the table
(m ∗ t )
is m ∗ t . Therefore, the maximum probability of key search success is P = .
2n
2) In this problem, t = 240 . If c is one millisecond, then the total computation time is 1 billion seconds (i.e. nearly 34 years).
1 1 (m ∗ t )
The maximum success probability is . Thus, = 128 ⇒ m = 2−3 * 2128 * 2−40 = 285. Each rainbow table entry has two
8 8 2
values (start and end points), which represent keys. Therefore, the rainbow table entry size is of 2*128 bits (i.e. 25 bytes).
Therefore, the required memory space is 285+5 bytes, which is overmuch large!
3) 128 is the block bit-length of AES. We conclude that MTTO attack against AES is computationally infeasible, because it
requires 290 bytes.
Problem 11.3
Let t + 1 denote the number of columns in a rainbow table, and R1, R2 , …, Rt , the reduction functions. Let m denote the
number of rows in the table.
Let P0 , C0 , and K be the plaintext, the ciphertext, and the key, respectively.
Let x i,0 , for i = 1, …, m, denote the random start points.
1) Scenario with t = 1. Endpoints are defined by x i,1 = R1 Enc x ( i ,0
(P0 )) , for i = 1, …, m.
If key K, such that x i,1 = R1 Enc x ( i ,0
(P0 )) , is present in the table, then there exists an endpoint x j,1 such that
(
x j,1 = R1 Enc x
i ,0
(P0 )) = R1 (C0 ). Therefore, the first test in the key search procedure returns key K .
2) Scenario with t = 2
There exist two cases: key K arises in the column 1 or in column 0.
Case 1: key K arises in column 1, i.e. K = x j,1 for some j, (1 ≤ j ≤ m)
Hence, x j,2 = R2 Enc x ( j ,1
(P0 )) = R2 ( EncK (P0 )) = R2 (C0 ).
Therefore, the first test in the key search procedure returns key K .
Case 2: key K arises in column 0, i.e. K = x j,0 for some j, (1 ≤ j ≤ m)
Hence, x j,1 = R1 Enc x ( j ,0
(P0 )) = R1 ( Enc x (P0 )) = R1 (C0 ). Then,
K
(
x j,2 = R2 EncR (C ) ( P0 )
1 0
)
Since K is not in column t −1, the search procedure makes the following computation:
( )
y2 = f2 ( R1 (C0 )) = R2 EncR (C ) ( P0 ) , which is an endpoint. Therefore, the second test in the key search procedure
1 0
returns key K .
11.7 Problems and Solutions 377
Problem 11.4
{
m = X , Y ∈ F2b | 0 ⋅ X ⊕ 0 ⋅ Y = 0 } = 2b
1
Therefore, Pr (0 ⋅ X ⊕ 0 ⋅ Y = 0) = 1 and ε (0, 0) = .
2
Thus, LAT (0, 0) = 2b * ε (0, 0) = 2b−1
2) Prove that the sum of all elements of a TAL is equal to 0.
2b−1 2b−1 2b−1 2b−1
S = ∑∑ LAT (α, β ) = 2b ∑∑ε (α, β )
α =0 β =0 α =0 β =0
1 n(α,β ) 1
For any pair (α, β ), the bias is: ε (α, β ) = Pr (α ⋅ X ⊕ β ⋅ Y = 0) − = b −
2 2 2
where n(α,β ) denotes the number of matchings (i.e. α ⋅ x ⊕ β ⋅ y = 0 , where x and y are values of random variables X
and Y ). By substitution,
2b−1 2b−1
2b−1 2b−1 ∑ ∑ n 1 2b
α =0 β =0 (α ,β )
∑∑ε(α, β ) = 2 b
− * 2
2
α =0 β =0
When we consider all combinations of values of X , Y , α , and β , there exist 23b expressions of the form α ⋅ X ⊕ β ⋅ Y .
One half of expressions are equal to 0 and the others to 1. That is,
2b−1 2b−1
23b
∑∑n(α,β) = 2
α =0 β =0
By substitution,
2b−1 2b−1
1 23b 1 2b
∑∑ε(α, β ) = 2b − * 2 = 0
2 2
α =0 β =0
Problem 11.5
By definition, TAL(α, β ) is the number of correct matchings (i.e. α ⋅ X = β ⋅ Y ) of the linear expression, using α and β
values, minus 2b−1 . m, the number of correct matchings for a fixed pair (α, β ), is defined by:
{
m = X , Y ∈ F2b | α· X ⊕ β ⋅ Y = 0 }
With a bit-length of b , there exist 2b linear equations. Therefore, the probability Pr (α ⋅ X + β ⋅ Y = 0) is m / 2b and the bias
m 1
ε (α, β ) is b − . Then, by substitutions:
2 2
□
m 1
2 * ε (α, β ) = 2b b − = m − 2b−1 = LAT (α, β )
b
2 2
Problem 11.6
1) If the s-box is defined by Y = λ ⋅ X ⊕ µ, then the linear approximation of the s-box, for any mask pair (α, β ) is
α ⋅ X ⊕ β ⋅ Y = α ⋅ X ⊕ β ⋅ (λ ⋅ X ⊕ µ) = (α ⊕ β ⋅ λ )⋅ X ⊕ β ⋅ λ
In binary representation,
Once α , β , λ, and µ are fixed, (⊕i=1,…,b (βiµi )) is a constant c0 , either 0 or 1; αiβi is a constant denoted ai , either 0 or 1,
for i = 1, …, b. The relationship can be rewritten as (⊕i=1,…,b (ai ⋅ X i )) ⊕ c0 . Since the sum of b bits (for all bit combina-
tions) is equally either even or odd,
1
( ) (
Pr (⊕i=1,…b (ai ⋅ X i )) = 0 = Pr (⊕i=1,…b (ai ⋅ X i )) = 1 = ) 2
1
(
Pr (⊕i=1,…b (ai ⋅ X i )) ⊕ c0 = 0 = ) 2
Therefore, the bias of linear expression (a) is 0. By Piling-up lemma, if a random binary variable Z has a bias of 0, the
bias of any variable combination including Z also is 0. We can conclude that linear cryptanalysis cannot be applied to
break ciphers using linear s-boxes.
1 16
2) By Piling-up lemma, the bias of a linear expression involving 16 s-boxes, all with a bias of ¼, is 215 * = 2−17 .
4
Problem 11.7
S
Recall that DDT D*,* of an n-by-m s-box S has 2n rows and 2m columns. When n = m , D*,*
S
is a square matrix. By definition
S S
of Dα,β = ∆α,β , such that:
( ) ( )
α , 0 ≤ α ≤ 2n − 1 , and β , 0 ≤ β ≤ 2m − 1 , are indices of rows and columns of DDT, respectively.
1) Consider any differential (α, β ) . For any s-box input X , if ( X , X ⊕ α ) is such that S ( X ) ⊕ S ( X ⊕ α ) = β , then
also S ( X ⊕ α ) ⊕ S ( X ) = β . Therefore, if ( X , X ⊕ α ) is included in set ∆αS ,β , then ( X ⊕ α, X ) also is included. Thus, the
cardinality of the set ∆αS ,β , in equation (a), is even. In other words, the elements of each DDT are even positive
integers.
2) Consider any row α in DDT. The bit-length of variable X and of α is of n. Therefore, we can build 2n ordered pairs
( X , X ⊕ α). A difference S ( X ) ⊕ ( X ⊕ α) is associated with each pair ( X , X ⊕ α). Therefore, the number of s-box output
differences associated with row α is 2n . Therefore, the element sum of each DDT row is 2n .
Problem 11.8
First step: compute the bits of the keystream until the last intercepted bit. Since the considered LFSR has a primitive
feedback polynomial, it has seven distinct states. Assume that the initial state is s0 = (k0, , k1 , k2 ) = (1,1, 0). Then,
s1 = L(1, 1, 0) = (1,1,1) s2 = L(1, 1, 1) = (0,1,1)
s3 = L(0, 1, 1) = (1, 0,1) s4 = L(1, 0, 1) = (0,1, 0)
s5 = L(0, 1, 0) = (0, 0,1) s6 = L(0, 0, 1) = (1, 0, 0)
The LFSR has a period of 7. Since the filter function is memory-less, the keystream bits are computed as follows (where d
is any positive integer):
b0+7 d = f (1,1, 0) = (1 ∧ ¬0) ∨ (1 ∧ 1) = 1
b1+7 d = f (1,1,1) = (1 ∧ ¬1) ∨ (1 ∧ 1) = 1
b2+7 d = f (0,1,1) = (0 ∧ ¬1) ∨ (0 ∧ 1) = 0
b3+7 d = f (1, 0,1) = (1 ∧ ¬1) ∨ (1 ∧ 0) = 0
b4+7 d = f (0,1, 0) = (0 ∧ ¬0) ∨ (0 ∧ 1) = 0
b5+7 d = f (0, 0,1) = (0 ∧ ¬1) ∨ (0 ∧ 0) = 0
b6+7 d = f (1, 0, 0) = (1 ∧ ¬0) ∨ (1 ∧ 0) = 1
Second step: the three known plaintext bits are located at positions 700, 701, and 702 (the first position is 0) in the cipher-
text; thus, they are encrypted with b0+700 = 1, b1+700 = 1 , and b2+700 = 0 , respectively. Then, adversary constructs the fol-
lowing equation system:
Notes 379
b0 = 1 = f (k0 , k1 , k2 )
S = b1 = 1 = f ( L(k0 , k1 , k2 ))
2
(
b = 0 = f L2 (k0 , k1 , k2 ) )
Use of the first equation:
At the first clock cycle: ( R0 , R1 , R2 ) = (k0 , k1 , k2 )
Equality (a) holds if (k0 ∧ ¬ k2 ) or (k0 ∧ k1 ) is 1 or both are equal to 1. Therefore, condition c1 must hold:
L(k0 , k1 , k2 ) = ((k0 ⊕ k2 ), k0 , k1 )
Equality (b) holds if ((k0 ⊕ k2 ) ∧ ¬k1 ) = 1 or ((k0 ⊕ k2 ) ∧ k0 ) = 1 . Therefore, condition c2 must hold:
Equality (c) holds if both ((k0 ⊕ k2 ⊕ k1 ) ∧ ¬k0 ) and ((k0 ⊕ k2 ⊕ k1 ) ∧ (k0 ⊕ k2 ) ) are equal to 0. Therefore, condition c3
must hold:
Finally, the unique solution that satisfies conditions c1, c2, and c3 is
Notes
1 If such an assumption holds, only one chain is tested for each column. If the assumption does not hold, i.e. some endpoints
have more than a reverse image, multiple chains may be tested for each column, which makes the time complexity analysis
harder.
2 At this step, mixed integer linear programming can be used to find the best linear approximations.
3 Partial-cipher means only some consecutive rounds of the cipher are considered.
4 It is obvious that if there is no change in plaintext difference (i.e. α = 0 ), there is no change in the ciphertext difference (i.e.
β = 0 ), for all the 2n plaintext pair ( P, P ⊕ 0).
5 A connection function is the function that updates the state of LFSR bits at each clock cycle. It makes use of the feedback
polynomial of LFSR.
6 ∧ , ∨ , and ¬ denote AND, OR, and NOT bit operators, respectively.
7 Trivium stream cipher is described in Section 6.2.7.1. The full initialization of Trivium performs 4 * 288 = 1152 rounds.
380 11 Introduction to Cryptanalysis Attacks on Symmetric Ciphers
8 The polynomial is assumed to be in algebraic normal form (ANF); i.e. it is a summation of binary variable products.
9 Each IV variable in index set I , of size j , takes 0 and 1 values. So, 2 j polynomials are derived from the master polynomial.
Each derived polynomial is considered as a vector and the set of vectors form a j -dimensional cube. This geometric
representation was the origin of the name of the attack.
10 Terms that are not maxterms can also be used in a cube attack, but more processing is needed to yield linear equations.
11 Notice that most terms in the master polynomial P() are identical to the ones in polynomial F () , unknown to attacker.
Many tests were performed before finding P() that correctly represents F () .
References
1 Hellman, M.E. (1980). A cryptanalytic time-memory trade-off. IEEE Transactions on Information Theory 26 (4): 401–406.
2 Denning, D.E. (1982). Cryptography and Data security. Addison-Wesley.
3 Oechslin, P. (2003). Making a faster cryptanalytic time-memory trade-off. 23rd Annual International Cryptology Conference
- Advances in Cryptology. Santa Barbara, California: Springer, LNCS 2729, 617–630.
4 Matsui, M. (1993). Linear cryptanalysis method for DES cipher. In: International Workshop on the Theory and Application of
Cryptographic Techniques, Advances in Cryptology (ed. T. Helleseth), 386–397. Lofthus, Norway: Springer. LNCS 765.
5 Heys, H.M. (2001). A Tutorial on Linear and Differential Cryptanalysis. Canada: University of Waterloo.
6 Biham, E. and Shamir, A. (1991). Differential cryptanalysis of DES-like cryptosystems. Journal of Cryptology 4 (1): 3–72.
7 Bard, G.V. (2009). Algebraic Cryptanalysis. Springer.
8 Courtois, N.T. and Meier, W. (2003). Algebraic attacks on stream ciphers with linear feedback. Annual International
Conference on the Theory and Applications of Cryptographic Techniques. Warsaw, Poland: Springer, LNCS 2656, 345–349.
9 Dinur, I. and Shamir, A. (2009). Cube attacks on tweakable black box polynomials. 28th Annual International Conference on
the Theory and Applications of Cryptographic Techniques. Cologne, Germany: Springer, LNCS 5479, 278–299.
381
12
Public-Key Cryptosystems
RSA and Finite Field Cryptography-based Schemes
In symmetric cryptosystems, the message sender and recipient must share a common secret (i.e. a ciphering key) before
encrypting and decrypting messages. The big question is: how to agree on the secret key in first place, particularly if sender
and receiver never met? It looks like the “The chicken or egg” dilemma. Trust is required before exchanging the secret key
in a secure way. Therefore, symmetric cryptosystems are limited to use in cases where both parties know and trust each
other.
The turning point in modern cryptography occurred in 1976‒1977, when Diffie and Hellman [1] on one side and Rivest,
Shamir, and Adleman [2], on the other, proposed original schemes to secure systems without requiring a unique cipher
shared by both parties. The proposed schemes were and are still used to design public-key cryptosystems. The latter pro-
vide support to secure communications worldwide between people who do not a priori know each other. The first and still
most widely used public-key cryptosystem is with no doubt is the RSA.
Modern cryptography is founded on the idea that the key used to encrypt messages can be made public, while the key
used to decrypt messages must be kept private. As such, these systems are known as public-key cryptographic systems (also
called asymmetric cryptosystems) and are based on operations easy to process in one direction, but difficult to invert.
Public-key algorithms provide support for confidentiality through message encryption and authentication through mes-
sage signature (see Figure 12.1). Public-key encryption is founded on the idea that the key used to encrypt messages is
made public, while the key used to decrypt is kept private. Public-key signature is based on the idea that the key used to
sign messages is private, while the key used to verify signature is made public.
There exist hundreds (or even more) algorithms in the symmetric cryptography world, while there exist only three fam-
ilies of public key algorithms, namely RSA, discrete logarithm-based, and elliptic curve schemes. The first generation of
public-key cryptosystems, including RSA, Diffie-Hellman key exchange, Menezes-Qu-Vanstone, and ElGamal cryptosys-
tems are addressed in this chapter. The security of those cryptosystems is based on either integer factorization problem
(addressed in Section 12.2.4) or discrete logarithm problem (DLP) in cyclic groups Z *p (addressed in Section 12.3.1). Those
problems are known to be computationally infeasible for large numbers. The second generation of public-key cryptosys-
tems is based on elliptic curve theory. They are more powerful than the first generation and are on the way to dominate in
the future. The security of elliptic curve cryptosystems is based on discrete logarithm problem in finite fields Fp (addressed
in Section 3.2.2).
Public-key cryptography is fundamentally based on the theory of numbers and not on a shared secret without worrying
about adversaries listening in the exchanged messages via an insecure network. The strong idea behind the public-key
cryptography is a challenge to attackers, which may be phrased as follows: you, the potential attackers, know the key used to
encrypt the messages sent to me, but you cannot decrypt them unless you have algorithms to solve factoring or DLP problems.
Public-key cryptography makes use of one-way functions, also called trapdoor functions. A one-way function is a function
easy to compute if the input is given, but it is computationally infeasible to find the input if the output is given (i.e. given
the function image). For example, RSA is based on integer factoring. Computing the product n = p * q given p and q is
easy. However, finding p and q given n is computationally infeasible when n is a product of two large random primes.
In summary public-key cryptography is divided into two classes: IFC (Integer Factorization Cryptography) and DLC
(Discrete Logarithm Cryptography). The latter is divided into two subclasses: Finite Field Cryptography (FFC) and Elliptic
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
382 12 Public-Key Cryptosystems
Algorithm family
DHKE: Diffie-Hellman Key Exchange, DSA: Digital Signature Algorithm, ECDH: Elliptic
Curve Diffie-Hellman key agreement protocol, ECIES: Elliptic Curve Integrated Encryption
Scheme, MQV: Menezes-Qu-Vanstone, ECMQV: Elliptic Curve MQV, ECDSA: Elliptic Curve
Digital Signature, EdDSA: Edwards-curve DSA.
Curve Cryptography (ECC). DSA is an example of FFC algorithms; ECDSA is an example of ECC algorithms. Other exam-
ples of DLC algorithms are the Diffie-Hellman and MQV key agreement algorithms, which have both FFC and ECC forms.
The difference between those three classes is the underlying used math. IFC and FFC algorithms are discussed in this
chapter and the ECC algorithms in the next one.
Table 12.1 summarizes the services provided by public-key algorithms:
● Encryption service is for guaranteeing confidentiality. In general, public-key cryptosystems are not recommended to
encrypt large amounts of data.
● Signature service is for authentication of message origin.
● Key exchange service is the way to use public keys to generate a shared secret between parties. Then, the shared secret is
used to derive a symmetric key; and then, parties make use of a symmetric cipher, such as AES, to encrypt and decrypt
their messages.
Note. RSA and DLP-based schemes rely on cyclic groups. To address those cryptographic schemes the fundamentals of
modular arithmetic and cyclic groups are reminded with examples in Chapter 3.
hidden part of those cryptosystems. Identified vulnerabilities have been taken into account to provide a high level of secu-
rity in the current public-key cryptosystems.
Public-key cryptosystems are considered safe at multiple levels of security strength depending on the length (in bits) of
the keys. Public-key standards provide useful guides to select parameter values for each cryptographic algorithm. As dis-
cussed in the sequel, when public-key algorithms are used correctly, they are secure enough to prevent all known attacks.
However, if a cryptosystem is not complying with standards, it becomes a target for attackers, which, in particular, can
easily lead to recovering the private key. Even a brute-force attack, which is inefficient in general, can succeed if the
algorithm is not parameterized correctly. The potential attacks depend on the mathematical foundations of each algorithm.
In the next sections, some well-known attacks are discussed.
The seminal asymmetric ciphering was patented1 by Rivest, Shamir, and Adleman in 1977 and published in [2]. Named
after its coauthors, RSA was the first radically different approach in which the sender and receiver do not need to share a
secret key. RSA is based on two keys: a private key known only to its owner and a public key, as the name suggests, known
384 12 Public-Key Cryptosystems
to all. In the last four decades, vulnerabilities of RSA have been intensively addressed and the proposed countermeasures
were included in operational RSA cryptosystems. Most of clients and servers in the today’s Internet make use of RSA to
secure their communications.
Let us consider a scenario in which Bob needs to receive messages from Alice and both partners agree to use the RSA
cryptosystem to make their messages confidential. To do so, the steps to follow are:
1) Bob computes two keys (public and private keys).
2) Bob sends his public key to Alice.
3) When Alice has a message to send, she encrypts the message using Bob’s public key.
4) When Bob receives the encrypted message, he uses his private key to retrieve the plaintext.
To provide secure systems, RSA must address fundamental questions:
● How Bob can compute public and private keys?
● How Bob can share his public key with Alice?
● A more challenging question: how to make it computationally infeasible to derive the private key from the public key
(assuming a known key computation algorithm)?
Answers to the first and third questions take their roots in the modular arithmetic (a sub-branch of arithmetic), which is
the basis of RSA. However, RSA by itself does not address the second question. It only assumes that the network is reliable,
but insecure. Public-key distribution is provided by public-key infrastructures (PKIs), which are addressed in Section 15.2.
First, RSA operations (i.e. key generation and distribution, encryption, and decryption) are described, then security and
correctness proof are addressed.
Bob Alice
Key generation
● Select two distinct large prime numbers p and q.
● Compute n = p ∗ q and φ(n) = ( p − 1) ∗ (q − 1)
● Public key is sent to Alice via a reliable channel, which is not required to be
Notes
― Not any integer e can be used as public key. e must be prime with φ (n). The private key d, which is the multiplicative
inverse of e mod φ (n), exists only if GCD (e,φ (n)) = 1.
― Since p −1 and q −1 are even (because p and q are primes), e = 2 cannot be used.
― One may be tempted to use e = 3, to reduce the encryption time. However, there are risks in using small values for
public key exponent. Some attacks succeed when e is small (see Problem 12.1).
Example 12.1
k
k1 (q−1) 2 +dq k * k2 dq dq
M ≡ C d mod q ≡ C mod q ≡ (1) 1 C mod q ≡ C mod q
Therefore, the exponents may be significantly reduced. Exponent dp is bounded by p −1 and dq , by q −1.
● The congruence equation system is:
M ≡ C dp mod p
M ≡ C dq mod q
dp
M ≡ (Cp ) mod p, where Cp ≡ C mod p
dq
M ≡ (Cq ) mod q, where Cq ≡ C mod q
d d
Let C p mod p ≡ M p , such that M p < p , and C q mod q ≡ M q , such that M q < q .
● By virtue of the Chinese remainder theorem, there exists a unique integer M < p * q such that both congruence equations
are fulfilled. By Gauss’s algorithm (see Section 3.3.4), M is computed as:
(( ( )) (
M ≡ M p * q * q−1 mod p + M q * p * p−1 mod q ( ))) mod pq
The pseudocode of the CRT-based decryption is as follows:
function CRT_RSA_Decryption
input C: Ciphertext; p, q : RSA prime parameters
d : private key
output M : plaintext
1. # Reduction of bases of C in Z p and Zq
C p = C mod p ; Cq = C mod q
2. # Reduction of the exponent d in Z p−1 and Zq−1
d p = d mod (p − 1); dq = d mod (q − 1)
3. # Exponentiation in Z p and Zq
d d
M p = C p p mod p ; Mq = Cq q mod q
4. # CRT-based solution to decryption
( −1
( −1
M = M p * q * q mod p + Mq * p * p mod q mod pq ) ( ))
5. return M
(( ( )) (
M = 5 ∗ 89 ∗ 89−1 mod 37 + 64 ∗ 37 ∗ 37−1 mod 89 ( ))) mod 37 ∗ 89
M = ((5 ∗ 89 ∗ 5) + (64 ∗ 37 ∗ 77)) mod 3293 ≡ 153
Therefore, the plaintext is 153.
q
By the modular arithmetic rule (Lemma 3.1), which states: aq mod p ≡ (a mod p) mod n, in which a is replaced by
M e mod n , (a) is rewritten as:
Below is the method most used in literature to prove (b); it is based on Fermat’s little theorem.
By definition: e * d ≡ 1 mod ( p − 1)(q − 1). Therefore, there exists an integer k such that:
e * d = 1 + k ( p − 1)(q − 1)
By substitution:
1+k( p−1)(q−1)
M e * d mod n ≡ M mod n
(p−1) ( ) (q−1) ( )
k q−1 k p−1
≡M* M ( ) mod n ≡ M * M ( ) mod n
(p−1) ( )
k q−1
M e * d mod p ≡ M * M ( ) mod p
k(q−1)
≡ M * (1) mod q ≡ M mod p
The integer M e * d − M is a multiple of p and q. Since p and q are primes, there exists a positive integer f such that
M e * d − M = f * p * q . It results that M e * d − M also is a multiple of n = p ∗ q. Consequently, M e * d mod n ≡ M mod n .
2) Case 2: M is coprime with p and not with q .
Since q is a prime number, M is either 0 or a multiple of q (i.e. M ≡ 0 mod q ). By the modular arithmetic exponentia-
tion rule, we have:
e *d
M e * d mod q ≡ (0) mod q ≡ 0 mod q ≡ M mod q
(p−1) ( )
k q−1
M e * d mod p ≡ M * M ( ) k(q−1)
mod p ≡ M * (1) mod p
□
The integer M ed − M is a multiple of p and q . Since p and q are primes and n = p * q , M ed − M also is a multiple
of M ed − M . Consequently, M ed ≡ M mod n .
bi ∈ ℕ*, i = 1, …, k.
Integer factorization problem: given an integer N , find prime factors n1 , n2 , …, nk such that N = ∏ik=1 ( ni )bi , where
In case of RSA, the number of integers, which are coprime with n is ( p − 1)(q − 1) , which is derived from Euler’s totient
theorem (Theorem 3.1).
Given n, finding p and q may be solved by naïvely checking all pairs p′ and q′ in the range 3 .. (n − 1) to find the pair
whose product is equal to n. Thus, the number of tries (in case of brute-force attack) is very high when large primes are
used. Another approach is to pick randomly an integer and test if it is a factor of n. Given that there exist φ (n) integers that
φ (n)
are coprime with n, the probability to pick an integer that divides n is 1− ; with large prime numbers p and q , such
n
probability is almost zero.
As far as we know and under the current known attacks, RSA security relies on the difficulty to factorize the modulus.
No algorithm has been published that can factorize all integers in polynomial time. The general number field sieve (GNFS)
is the most efficient algorithm for factoring (very) large integer; its correctness is considered in [3]. The GNFS has a time
complexity of:
64 3
1
1 2
exp + o (1)(ln n) (ln ln n)
3 3
9
Such a complexity makes the factorization computationally infeasible for very large numbers. That is the reason why the
RSA requires the selection of large prime numbers p and q to generate the keys. If both p and q are not large enough, there
exists an efficient algorithm, called Lenstra’s elliptic-curve factorization method, which makes use of elliptic curves (dis-
cussed in Chapter 13), with a time complexity of exp ( )
log ( p) * log (log ( p)) , where p is the smallest factor of the number to
factorize. To thwart attacks based on Lenstra’s algorithm, it is recommended to use both RSA primes of a bit-length in
magnitude of 1000 or more.
For readers interested in prime numbers, the list of 10 000 first prime numbers and the top ten prime numbers are avail-
able at: https://tk5.org.
Just for curiosity, the largest prime number was discovered in 2018; it is 282 589 933 − 1 (it has 24 862 048 decimal digits).
When the value of the modulus n is not large, some RSA-S5 had been cracked: RSA-576 cracked in 2003, RSA-640 in
2005, and RSA-768 in 2009. However, it should be noticed that much computation resources were monopolized to crack
RSA. Cryptanalysts used either special multiprocessors or clusters interconnected via Internet. For example, RSA-640 was
cracked with the equivalent of almost 200 years of computing on a single core 2.2 GHz and RSA-768 with the equivalent of
almost 2000 years of computing on a single core 2.2 GHz.
No RSA-S with S > 768 has been cracked yet. RSA-2048 is recommended and currently widely used. In conclusion, RSA
is considered secure when used with large primes (made of 1024 or more bits). Therefore, users may continue using RA for
years before the RSA-2048 would be broken.
Note. It is not yet formally proven that the only way to disclose RSA-encrypted message is by factoring the modulus n.
RSA-OAEP encoding
● Let k denote the length (in bytes) of the modulus n and mLen denote the length of the message M to encrypt. Message
length mLen is bounded: mLen ≤ k − 2 * hLen − 2 (because padding bytes and hashes are concatenated with the original
message before encryption).
● Select a string label L associated with the message M. In the version PKCS #1 v2.2, L is the empty string.
● Generate a padding string PS formed by k − mLen − 2 * hLen − 2 zero-bytes. The length of string PS may be zero.
● Make concatenation: EM = 0 x 00 maskedSeed maskedPM . The length of the encoded message EM is k (i.e. the mod-
⚪ Let EM .maskedSeed and EM .maskedPM denote the values of the fields maskedSeed and maskedPM, respectively, in
● OAEP decoding (assuming no error in the coding step)
⚪ 6 is the minimum length to form an OAEP message with one data byte, one padding byte, two one-byte hashes, and
– RSA modulus and key selection
two constant bytes (see Figure 12.3). Therefore, the length of the RSA-OAEP modulus n should be of six bytes at least.
12.2 RSA Cryptosystem 391
⚪ p = 32 452843 and q = 1000 003 are two primes such that n = p * q = 32 452940358529 has a length of six bytes.
⚪ Public key exponent selection: e = 5
⚪ Private key selection: d = 6 490581381137
⚪ To make the computations easy to check without a specialized library, let H() be the identity function and G() the one-
– Hash and mask generation functions and padding string
⚪ PM = H ( L) || PS || 0 x 01 || M = 65 || 00 || 01 || 00.
EM . maskedSeed is 84
EM .markedPM is 65 00 20 10
⚪ seed = EM .maskedSeed ⊕ G ( EM .maskedPM , hLen)
= (84) ⊕ G ( EM .maskedPM , 1) = (84) ⊕ (65) = 21
⚪ PM = EM .maskedPM ⊕ G ( seed, k − hLen − 1)
= (65 00 20 10) ⊕ (00 00 21 00) = 65 00 01 10
⚪ Extract M from the most-right byte of PM . Thus, M = 10.
⚪ PHsalt = (00 00 00 00 00 00 00 00 ) mHash salt . PHsalt is a byte string with length of 8 + hLen + sLen bytes.
● Make concatenations and hashing:
⚪ Hash = H ( PHsalt )
⚪ Generate a string PS consisting of k − sLen − hLen −2 zero bytes. PS may be the empty string.
⚪ H (10 ) = 10
⚪ PHsalt = 10 || 77
⚪ Hash = H ( PHsalt ) = 10 || 77
⚪ Psalt = 01 || 77
⚪ Thus, salt = 77
= (76 || 71) ⊕ (77 || 10) = 01 || 77
Discrete logarithm problem (DLP): given a cyclic multiplicative group Z*p, a generator g of the group Z*p, and an element
h of Z*p, find k such that: g k = h mod p.
k is called discrete logarithm.
Recall that in classic mathematics, given two real numbers a and b , logb (a) , the logarithm of a to base b , is a real number
c such that: b c = a . log ( x ) is the inverse function of e x . Analogously, in any cyclic group Z *p with generator g , powers g k
can be defined for all integers k , and log g (h), the discrete algorithm of an element h ∈ Z *p , is an integer k such that:
g k ≡ h mod p .
Example 12.5 *
Let us consider Z11 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
*
Element 2 is a generator of Z11 , since:
20 = 1 21 = 2 22 = 4 23 = 8
4 5 6
2 = 16 ≡ 5 mod 11 2 = 32 ≡ 10 mod 11 2 = 64 ≡ 9 mod 11
27 = 128 ≡ 7 mod 11 28 = 256 ≡ 3 mod 11 29 = 512 ≡ 6 mod 11
k
Find k such that 2 ≡ 3 mod 11. It is easy to find k when the powers of 2 calculated a priori; k = 8.
The most recent record on solving DLP in cyclic groups Z *p was announced in late 2019. Researchers computed the dis-
crete logarithm modulo for 795 bits. The computation took approximately 3100 core-years, using Intel Xeon Gold 6130
CPUs (2.1GHz). Another record on solving DLP in extension fields GF (2m ) was announced in late 2019. Researchers
computed the discrete logarithm modulo for GF (230750 ) using 25 481 219 core hours on clusters based on Intel Xeon
architecture.
In the sequel, the most known finite field-based cryptographic algorithms (namely, DHKE, ElGamal, and MQV), are
presented.
Example 12.6 Alice and Bob decide to compute a shared secret using DHKE protocol with p = 227, which is prime,
and g = 2 .
Alice chooses her private key to be PrA = 175 . Then, she computes her public key: Pu A = 2175 mod 227 = 23* 44+43
( )
mod 227 = 1713 * 199 mod 227 = 201.
Bob chooses his private key to be PrB = 44 . Then, he computes his public key: PuB = 244 mod 227 = 171 .
Then, public keys are exchanged between Alice and Bob.
The shared secret computed by Alice is:
35
B mod 227 = (171)
S = Pu175
175
mod 227 = 1715 ( ) mod 227
7
( )
= 1885 mod 227 = (129)
5 +2 2
mod 227 = (132) * (129) mod 227 = 160
Bob Alice
Alice and Bob agree on two public parameters: g (a subgroup generator) and prime p , the modulus of the Z *p group.
● Pick a private key, PrB, an integer such that: 1 ≤ PrB < p − 1 (8) ● Pick a private key, PrA , an integer such that: 1 ≤ PrA < p − 1
Pr
● Compute the public key PuB: PuB = g PrB mod p ● Compute the public key Pu A: Pu A = g A mod p
● Send PuB to Alice ● Send Pu A to Bob
Public keys are exchanged via an insecure network.
● Receive Alice’s public key ● Receive Bob’s public key
PrB PrA
● Compute a shared secret S: S = SB = ( Pu A ) mod p ● Compute a shared secret S: S = S A = ( PuB ) mod p
Alice and Bob have generated the same secret S, which can be used, entirely or in part, as a session key of a symmetric cipher to
encrypt and decrypt messages.
Resistance to attacks
Given the public parameters ( g , p, PuB , and Pu A ), breaking the Diffie-Hellman key exchange scheme means revealing the
session key S, which requires solving a problem known as Diffie-Hellman problem.
Diffie-Hellman problem (DHP): given a cyclic multiplicative group Z*p, a generator g of the group Z*p, and two values
g x mod p and g y mod p, x and y are two random values, find g x * y mod p .
Since the session key S is derived from a couple of public and private keys, from either ( PuB , PrA ) or ( Pu A , PrB ), the adver-
sary should9 reveal one of private keys (PrB or PrA ). Unfortunately, for the adversary, revealing a private key, which is
defined by a modular exponentiation, requires the adversary to solve the DLP problem, which is known to be computation-
ally infeasible. In such a case, the DHP is equivalent to the DLP. Therefore, solving the Diffie-Hellman problem (DHP) also
is computationally infeasible for large values of cyclic group size.
(
≡ M * g PrB * k mod p * g ) −( PrB * k )
mod p
0
≡ M . g mod p = M □
12.3 Finite Field-based Cryptography 397
Bob Alice
Alice and Bob agree on three public parameters: prime p, g (a subgroup generator) and q, the order of the subgroup.
● Pick a static private key, PrB, an integer such that: 1 ≤ PrB < p − 1 ● Pick a static private key, PrA , an integer such that:
●
Pr
Compute the static public key PuB: PuB = g B mod p 1 ≤ PrA < p − 1
● Compute the static public key Pu A: Pu A = g PrA mod p
● Send PuB to Alice
Send Pu A to Bob
Pick an ephemeral private key, PrBe , an integer such that:
●
●
● Pick an ephemeral private key, PrAe , an integer such that:
1 ≤ PrBe < p − 1 e 1 ≤ PrAe < p − 1
● Compute the ephemeral public key PuBe: PuBe = g PrB mod p Pr e
Compute the ephemeral public key Pu eA: Pu eA = g A mod p
Send PuBe to Alice
●
●
e
● Send Pu A to Bob
Public keys are exchanged via an insecure network.
● Receive Alice’s public keys ● Receive Bob’s public keys
● Compute a shared secret Z: ● Compute a shared secret Z:
1
1 w = log2 (q)
w = log2 (q) 2
2
( )
TB = PuBe mod 2 w + 2 w ( )
TA = Pu eA mod 2 w + 2 w
( TA
Z = Pu eA * ( Pu A )
SB
) mod p ( T
Z = PuBe * ( PuB ) B ) mod p
Alice and Bob have generated the same secret Z , which can be used, entirely or in part, as a session key of a symmetric cipher to
encrypt and decrypt messages.
Bob Alice
● Select two group parameters: g (a subgroup generator) and prime p, the modulus of Z *p
group.
● Pick a private key, PrB, an integer such that: 2 ≤ PrB ≤ p − 2
● Compute the public key10 PuB: PuB = g PrB mod p
● Send (p, g , PuB) to Alice
● Receive ( p, g , PuB )
● Pick an integer k11 such that: 0 ≤ k ≤ p − 2
● Compute public key Pu A: Pu A = g k mod p
k
● Compute the session key S: S = ( PuB ) mod p
● Encrypt the message: C = M * S mod p
● Send ( Pu A , C ) to Bob
● Receive ( Pu A , C ′) Pr
● Compute a shared secret S: S = ( Pu A ) B mod p
−1
● Decrypt the ciphertext: M ′ = C ′.S mod p
Notes
― The sender should not use the same per-message secret k to encrypt more than one message. If the same value k0 is
used to encrypt two messages M1 and M 2, the adversary would be able to discover the content of M 2 , �
assuming he/she
had previously intercepted the content, in clear, of message M1, as follows:
k0 k0 C1 M1
C1 = M1 * ( PuB ) mod p; C2 = M 2 * ( PuB ) mod p; = mod p
C2 M 2
398 12 Public-Key Cryptosystems
From the public information (C1, C2 , p ) and the intercepted message M1, the adversary can easily discover M 2:
M 2 = M1 * C2 * C1−1 mod p.
In general, if the sender does not change the private key, the adversary has just to capture the plaintext of any message
to learn the content of all messages of a session.
― The consequence of encrypting a single message by each private key value is that when the sender transmits, at differ-
ent times, the same data (for example a password or PIN code), the ciphertexts are different and the adversary will not
be able to detect that the same data is sent multiple times.
Example 12.7 Use case: Bob sends a message to Alice who verifies the signature.
Bob operations:
*
– Use Z19 and g = 10
– Pick a private key PrB = 16
– Compute the public key PuB = 1016 mod 19 = 4
– Send domain parameters ( p = 19, g = 10, PuB = 4) to Alice
– Choose a message M = 14
– Pick a per-message-signature key K B = 5 / * GCD (5, 19 − 1) = 1 * /
– Generate signature of M :
r = 105 mod 19 = 3
( )
s = (14 − 16 * 3) 5−1 mod 18 = (2) * (11) mod 18 = 4
– Send (14, (3, 4))
Alice’s operations
– Receive ( p = 19, g = 10, PuB = 4)
– Receive ( M = 14, (r = 3, s = 4))
( )
– Verify signature:v = 43 * 34 mod 19 = (7) * (5) mod 19 = 16
M 14
Bob Alice
● Select two group parameters: g (a subgroup generator) and prime p, the modulus of the Z *p
group.
● Pick a private key PrB, an integer such that: 2 ≤ PrB ≤ p − 2
Pr
● Compute the public key PuB: PuB = g B mod p
● Send (p, g , PuB ) to Alice
● Receive (p, g , PuB )
● M : message to sign (M ≤ p −2)
● Pick an integer12 K B such that: 2 ≤ K B ≤ p − 2 and GCD ( K B , p − 1) = 1 (13)
● Generation of signature, a couple (r , s ): r = g K B mod p
s = ( M − PrB * r ) K B−1 mod ( p − 1)
● Send ( M , (r , s )) to Alice
k mod ( p−1)
Lemma 12.1 " mod p ↔mod p−1": for any positive integers a, p, and k, the following holds: ak mod p ≡ a mod p
Lemma proof: For any integers k and p, there exists an integer k1 , such that:
k = k1 * ( p − 1) + (k mod ( p − 1))
Therefore, for any integer a, by substitution, we can write:
k *( p−1)+(k mod ( p−1))
ak = a 1
k *( p−1)+(k mod ( p−1))
⇒ ak mod p ≡ a 1 mod p
k1 (
p−1)
(k mod (p−1))
k
a mod p ≡ a ( ) *a mod p
Using Little Fermat theorem (i.e. a p−1 ≡ 1 mod p ), the last equality becomes:
(k mod (p−1)) k mod ( p−1)
ak mod p ≡ 1 * a mod p ≡ a mod p □
Second, make substitutions in the formula used by the recipient to verify the signature:
(
v ≡ PuBr * r s mod p )
r s
≡ g PrB *r + K B * s mod p
PrB * r + K B *(( M −PrB * r )* K B−1mod( p−1))
≡g mod p # substitute s
PrB * r +(( M −PrB * r )mod( p−1))
≡g mod p
mod( p−1)
≡g mod p
M mod ( p−1)
g mod p ≡ g M mod p.
□
Therefore, the signature associated with the received message is valid and the result of the signature verification in
correct.
The original digital signature scheme of ElGamal results in signatures composed of two items (r and s ), each of which has
a size of p bits. Consequently, the size of the digital signature is twice the message size. Thus, signing long size messages
(such as pictures, scanned documents, and videos) results in significant consumption of resources (bandwidth and
memory), which are limited in some mobile and embedded devices. To alleviate such a drawback of ElGamal signature
scheme, it is recommended to sign the hash of the message and not the entire message. This recommendation led to the
DSA14 (Digital Signature Algorithm) standard, which is currently one of the three techniques mostly used to sign docu-
ments online. The main adaptions of ElGamal signature scheme to yield the DSA standard are addressed in this section.
For specific details regarding the implementations of the DSA standard (including how parameters are selected and
checked), refer to [12] and Chapter 14.
( )
r = g K mod p mod q (K is the per-message-signature key)
Z = leftmost (min ( N , outlen), HASH ( M ))
s = K −1 * ( Z + Prs * r ) mod q (Prs is the private key of the signer)
min ( N , outlen) denotes the minimum of the N (the order of the generator) and outlen (the bit length of the hash function
output).
If r = 0 or s = 0 , a new value of r shall be recalculated and tried.
hash function, and the public key of the signer Pus , before any signature verification. Upon reception of a message M ′ and
its signature (r ′, s ′), the verification is as follows:
Z = leftmost (min ( N , outlen), HASH ( M ′ ))
w = s ′−1 mod q
u1 = Z ∗ w mod q
u2 = r ′ ∗ w mod q
(( ) ( ) mod p) mod q
u2
v = g u1 * Pus
Exercise 12.1
Let p = 19 and q = 11 be two primes for RSA settings. Which of the following values are valid public keys: e1 = 11 , e2 = 4 ,
e3 = 120 , e4 = 15311 ?
ElGamal DS DSA
Exercise 12.2
Compute RSA public and private keys with p = 7 and q = 13. Then encrypt message M = 10 and decrypt the ciphertext.
Exercise 12.3
Use the Extended Euclidean algorithm to find the private key of RSA for the following scenarios:
1) p = 13, q = 11, and e = 7 (e is the public key)
2) p = 7 , q = 11, and e = 13
Exercise 12.4
Let RSA parameters be: p = 101, q = 113, and e = 6747 .
1) Find the private key d using the Extended Euclidean algorithm to compute the multiplicative inverse (see Section
3.3.1.3.2).
2) Find the plaintext associated with ciphertext 5859 using the right-to-left binary exponentiation method (see Section
3.3.2).
Exercise 12.5
Given the following RSA parameters find the plaintext using the Chinese remainder theorem:
p = 37, q = 131, private key d = 3343, and ciphertext C = 1819.
Check the result assuming that public key e = 7 .
Hint: 631 mod 37 ≡ 31 and 11693 mod 131 ≡ 30.
Exercise 12.6
*
1) In example 12.5, k = 8 is given as a discrete logarithm of 3 mod 11 when the generator of Z11 is 2. Are there any other
values for k ?
* *
2) Given the cyclic group Z97 and g = 5 as a generator of Z97 , find k such that 5k = 35 mod 97.
Exercise 12.7
Consider ElGamal’s signature. Let Bob’s private key be 9 and his public key parameters be ( p = 31, g = 7, PuB = 8).
Compute and verify signatures of messages M1 = 25 and M 2 = 57 using ephemeral keys k1 = 11 and k2 = 17 ,
respectively.
Problem 12.1
1) Explain why 1 and 2 cannot be used as public-key exponent values.
2) Imagine that a user sends three times his/her credit card PIN using the same public-key exponent e = 3 with different
values of the modulus, which are pairwise coprime. For example, the public keys used are (e = 3, n = 5 * 11),
(e = 3, n = 23 * 29), and (e = 3, n = 41 * 101). Show that the PIN code can be recovered. Make use of the Chinese
remainder theorem.
Problem 12.2
Use the following statements to prove the correctness of RSA:
φ( z )
● Euler’s theorem (Theorem 3.4) states that if a and z are two coprime positive integers, then a ≡ 1 mod z , where is
φ ( z ) the Euler’s totient.16
● If z is prime, then φ ( z ) = z −1.
Problem 12.6
The attacker sends a public key to the recipient, who accepts it as a public key of a legitimate signer. Then, he/she signs
messages. How does RSA protect against this attack?
Problem 12.7
Given two messages M1 and M 2 and their RSA signatures s1 and s2 , show that the adversary cannot (within a reasonable
computation time) forge a signed message with a content of his/her choice.
Problem 12.8
Let Bob’s public key be (5,119). Show how Eve can perform an existential forgery attack to send a signed message to Alice.
Problem 12.9
Textbook RSA signature scheme is a simplified design of the RSA signature. It does not use a hash function. Notice that Textbook
RSA signature scheme is not used in practice to sign messages. Consider the following attack against a Textbook RSA signature
scheme: given a message M and its signature s , the adversary can forge a signature s' without controlling the content of a message
e
M ′, where: s ′ = 2 s and M ′ = 2 M (e is the public key exponent). Prove that the attacker can generate a valid signature.
Problem 12.10
In practice, we use low values for public keys to reduce the encryption time. In this problem, we discuss the impact of using
low-value private keys. Assume that the right-to-left binary exponentiation method (RLBEM) is used in both operations
(encryption and decryption) and the complexity time is measured in number of iterations performed by the RLBEM. Let RSA
parameters be p = 1009 and q = 1013. The following pairs of keys are given: ( x = 5, y = 816077), ( x = 13, y = 78469),
( x = 17, y = 180017), ( x = 19, y = 805339), ( x = 25, y = 775273), ( x = 29, y = 386933).
1) What do you notice if x represents the public key and y the private key and vice versa?
2) Discuss how the sum of encryption and decryption times is impacted if x is the public key and y is the private key and
vice versa.
3) Consider an adversary who suspects, when looking at the value of the public key and the modulus pq, that the sender
is using a low-value for the private key, say d < 100. Given a known pair plaintext–ciphertext, how the adversary could
discover the primes p and q ?
4) What is minimum bit-length of the private key to make brute-force attack with known plaintext infeasible to find the
private key, assuming that the adversary can perform a maximum of 2Ω square-and-multiply operations?
5) Conclude regarding the use of low-value private keys.
Problem 12.11
1) Show that the product of two RSA ciphertexts is equal to the encryption of the product of the two respective plaintexts.
In other words, show that RSA has a multiplicative property.
2) Assume that Bob, Alice, and Eve share a public key (e, n) and Bob owns the private key d. The ciphertexts are known to
the three partners. Alice and Bob exchange plaintexts that Eve should not read. To check that Bob possesses the right
private key, Eve encrypts messages, using Bob’s public key, and asks Bob to decrypt them and return the plaintext. If
Bob decrypts correctly the ciphertexts, Eve concludes that he owns the appropriate private key. Unfortunately, such a
challenge-based authentication protocol has a weakness. Design an attack based on RSA multiplicative property, which
enables Eve to disclose messages sent by Alice.
3) Numeric check: RSA parameters: p = 101, q = 103, e = 19, and d = 6979 . Assume x = 40 and Msec = 27 and their
respective ciphertexts Cx = 4019 mod 101 ∗ 103 = 8697 and Csec = 2719 mod 101 ∗ 103 = 7408. Check that Eve
recovers the content Msec = 27.
4) Why the multiplicative property-based attack, as designed above, cannot succeed in current RSA cryptosystems?
Problem 12.12
Assume that RSA encryption makes use of the right-to-left binary exponentiation method (RLBEM, presented in Section
3.3.2) to compute the modular exponentiation. To simplify, assume that i) the most time-consuming operation in the
RLBEM is the modular multiplication and ii) m2 * c is the runtime18 of a modular multiplication with m-bit operands, with
c a constant depending on the implementation of the modular multiplication and the underlying hardware, and iii) the
public key e is 216 + 1 .
1) How does the encryption time increase in the modulus increase?
2) Show the increase ratio between moduli 1024 and 4092.
404 12 Public-Key Cryptosystems
Problem 12.13
*
1) 100 000 007 is a prime number. Given the cyclic group Z100 000 007 and g its generator, what is the worst time it takes to
solve the DLP for a computer that calculates and compares every power of the generator g in 1 μs.
2) Let Z *p be a cyclic group with p of 90-bit length. What is the worst time it takes to solve the DLP for a computer that
calculates and compares a power of g in 1 μs?
Problem 12.14
Alice and Bob agree to use prime p = 101 as modulus to generate a shared secret key using the DHKE protocol. Compute
the shared secret key in the following:
1) Generator g = 13, PrA = 26, PrB = 4
2) Generator g = 13, PrA = 12, PrB = 17
3) Derive a condition that the pairs of private keys ( PrA , PrB ) must meet to generate the same secret key under the same
generator and modulus.
Problem 12.15
Why private keys used in DHKE protocol must be distinct from 1 and p −1, with p the modulus.
Problem 12.16
May it happen that the shared secret key generated with the DHKE protocol be equal to 1 assuming that private keys are
distinct from p −1?
Problem 12.17
1) Given a modulus p of 2048-bit-length and a generator g ∈ Z *p , which has an order of 2256 . What is the maximum value
that the private keys can have in DHKE protocol?
2) What is the minimum order of a generator to provide security strength of 256 bits?
3) Assume that two elements g1 = 2 and g2 = 216 + 1 have the same order mod p . Which one of the generators is more
secure when used in DHKE protocol?
Problem 12.18
1) Let g be an element of Z *p and p a prime. Prove that if g = p − 1, then the order of g is 2.
2) Why it is not secure to use a generator g = p − 1 under modulus p in DHKE protocol?
Problem 12.19
Let p be a safe prime (i.e. such that p = 2q + 1 and q is a prime).
p −1
1) Show that the order of any element of cyclic group Z *p is 1, 2, , or p −1.
2
2) Discuss the contribution of safe primes in terms of security strength when DHKE protocol is used.
Problem 12.20
Is the DHKE protocol, as defined in this chapter, vulnerable to man-in-the-middle attack?
Problem 12.21
Consider an ElGamal encryption system based on a pseudorandom generator (PRNG) π (i), which returns a random
integer to be used as a private key. The function π (i) may be complex, but it depends only on parameter i and it is public.
π (i) is used as per-message key for encrypting message i, i = 1, 2, 3, …, π (0) is the initialization value of the PRNG.
1) Discuss the vulnerability of ElGamal encryption regarding PRNG π (i).
2) Suggest a method for enforcing the security even if the adversary may know the initial value (seed) of the PRNG.
3) Conclude on the role of PRNG in ElGamal cryptosystems.
Problem 12.22
Given two messages M1 and M 2 and their ElGamal signatures (r1 , s1 ) and (r2 , s2 ) . Show that if both messages are signed
with the same per-message-signature key, i.e. r1 = r2 , the adversary can easily recover the private key of the signer.
12.5 Exercises and Problems 405
Problem 12.23
Assume that an adversary forges a legitimate ElGamal signature, without controlling the content of the generated fake
message as follows:
g (generator), p (modulus), and PuB (public key of the legitimate signer) are public parameters known to the adversary.
The adversary’s actions are:
i) Select two positive integers a and b such that:
a, b < p − 2 and DCD (b, p − 1) (thus, b−1 mod ( p − 1) exists).
ii) Calculate the signature components:
b
r = g a * ( PuB ) mod p
s = −r * b−1 mod ( p − 1)
iii) Compute the (fake) message:
M ≡ s * a mod ( p − 1)
Notice that the message generated by the adversary depends on a and b and cannot be controlled by the adversary to
include a specific content.
iv) Send ( M , (r , s ))
Prove that the recipient (Alice) verification will conclude that the signature is valid.
Problem 12.24
1) How many distinct first-components (i.e. r ) of ElGamal signature can be generated for a message x given a mod-
ulus p = 17 and generator g = 3.
2) How many distinct first-components (i.e. r ) of ElGamal signature can be generated for a message x given a mod-
ulus p = 17, a generator g = 2 .
3) How many distinct first-components (i.e. r ) of ElGamal signature can be generated for a message x given a modulus p,
which is a safe prime, and g a generator of Z *p .
4) How many distinct first-components (i.e. r ) of ElGamal signature can be generated for a message x given a modulus p,
which is a safe prime, and g an element of Z *p .
Problem 12.25
Given g a generator of a subgroup of order q in the multiplicative group Z *p , prove the following lemma:
Lemma 12.2 (property of DSA generator) states that: if q is a prime divisor of p −1 and g is a generator of DSA sub-
group in Z*p, then g q mod p ≡ 1.
Problem 12.26
Prove the correctness of the DSA scheme.
Problem 12.27
Bob is curious about cryptography and asks you why AES keys are of 128 bits, while those of RSA are of 2048 or even more.
Exercise 12.2
p = 7 , q = 13
Exercise 12.3
Recall that given two primes p and q , the RSA private key d is the multiplicative inverse of the public exponent e . Formally:
( ( ( )))
= (60 * 2 − 13 * 9) − (60 − 13 * 4) − 2 * (60 − 13 * 4) − (13 − (60 − 13 * 4))
= 60 * 5 + 13 * (−23)
Thus, d = −23. In modulo 60, d = 37.
Exercise 12.4
Let RSA parameters be p = 101,q = 113, and e = 6747.
Since RSA parameters p, q , and e are known, it is easy to find the private key d and then decrypt the ciphertext.
25
( ) mod 11413 ≡ 1
b5 ≡ 58590
6
2
b6 ≡ (58591 ) mod 11413 ≡ 708
585983 mod 11413 ≡ 5859 * 8990 * 1 * 1 * 10505 * 1 * 708 mod 11413 ≡ 9192
Check: one can easily do computations (using a program of the right-to-left binary exponentiation method) to confirm
that:
1 ≡ 9192112 mod 11413 and 5859 ≡ 919227 mod 11413
Thus, encrypting the plaintext 9192 with the public key 6747 results in
C ≡ 91926747 mod 11413 ≡ 919260 *112+27 mod 11413 = 5859 .
Exercise 12.5
Let p = 37, p = 131, d = 3343, and C = 1819.
The plaintext M is such that M ≡ 18193343 mod 37 * 131 and by Lemma 3.2,
M ≡ 18193343 mod 37 and M ≡ 18193343 mod 131.
To find the plaintext M using the CRT-based RSA decryption, we proceed as follows:
● Reduce the bases of congruences:
1819 = 37 * 49 + 6 = 131 * 13 + 116
Cp ≡ 1819 mod 37 ≡ 6
Cq ≡ 1819 mod 131 ≡ 116
● Reduce the exponents:
3343 = 92 * (37 − 1) + 31 = 25 * (131 − 1) + 93
dp = 3343 mod (37 − 1) = 31
dq = 3343 mod (131 − 1) = 93
● Exponentiation in Z37 and Z131 :
d
M p = Cp p mod p = 631 mod 37 ≡ 31
d
M q = Cq q mod q = 11693 mod 131 ≡ 30
● CRT-based solution to decryption
131−1 mod 37 ≡ 13 37−1 mod 131 ≡ 85
(( ( )) (
M = 31 * 131 * 131−1 mod 37 + 30 * 37 * 37−1 mod 131 ( ))) mod 37 * 131
M ≡ ((31 * 131 * 13) + (30 * 37 * 85)) mod 4847 ≡ 1733
Exercise 12.6
1) Let us consider the group Z11*
with generator 2. 8 is one of the discrete logarithms of 3, since 28 ≡ 3 mod 11. 18 also is a
discrete logarithm of 3, since
(( )( )(
218 mod 11 ≡ 28 mod 11 * 28 mod 11 * 22 mod 11 mod 11 ))
≡ (3) * (3) * (4) mod 11 = 3
By Fermat’s little theorem (Theorem 3.5), any m = 8 + 10k is a discrete logarithm of 3 mod 11, because:
(
28+10 k mod 11 = 28 mod 11 * 2
k
)
(11−1)k
(
mod 11 mod 11
)
= (3) * (1) mod 11 = 3 mod 11.
* *
However, since 8 + 10k ∉ Z11 , for k > 0 , only 8 is a valid solution in Z11 .
12.5 Exercises and Problems 409
Exercise 12.7
Bob’s public key parameters are ( p = 31, g = 7, PuB = 8) and his private key is PrB = 9 .
Compute signatures of messages M1 = 25 and M 2 = 57 using ephemeral keys k1 = 11 and k2 = 17
r1 = 711 mod 31 = 20
s1 = (25 − 9 * 20) * 11−1 mod 30 = (−155) * 11 mod 30 = 5
r2 = 717 mod 31 = 18
s2 = (57 − 9 * 18) * 17−1 mod 30 = (57 − 9 * 18) * 23 mod 30 = 15
Verification of M1 = 25 and its signature (20, 5) :
( )
v = PuBr * r s mod p = 820 * 205 mod 31 = 25
M 25
g mod p = 7 mod 31 = 25
v = g M mod p is satisfied; thus, the signature is valid.
Verification of M 2 = 57 and its signature (18, 15) :
( )
v = PuBr * r s mod p = 818 * 1815 mod 31 = 16
Problem 12.1
1) If e = 1, then the encryption becomes C ≡ M 1 mod n = M . Thus, with e = 1, the plaintext and ciphertext are identical;
no confidentiality is assured.
If e = 2, then d * e ≡ 1 mod φ (n) becomes 2 * d ≡ 1 mod φ (n). Since p and q are primes, φ (n) is divisible by 2 and con-
sequently, there is no d such that 2 * d and φ (n) are coprime. In other words, GCD (2, φ (n)) ≠ 1 . Therefore, the
multiplicative inverse of 2 mod φ (n) does not exist.
2) Let M be a message, which is encrypted three times with the same public-key exponent e = 3 and with three distinct
moduli, which are pairwise coprime. For example, the public keys are (e = 3, n1 = 5 * 11), (e = 3, n2 = 23 * 29), and
(e = 3, n3 = 41 * 101). The ciphertexts are as follows:
C1 ≡ M 3 mod n1 C2 ≡ M 3 mod n2 C3 ≡ M 3 mod n3
Let x be M 3 . By substitution:
x ≡ C1 mod n1 x ≡ C2 mod n2 x ≡ C3 mod n3
Then, by transformation (with k1 , k2 , and k3 positive integers):
x = C1 + k1 * n1 x = C2 + k2 * n2 x = C3 + k3 * n3
Let us take an example with M = 13 and the suggested public keys. The ciphertexts are:
C1 ≡ 133 mod (5 * 11) = 52 C2 ≡ 133 mod (23 * 29) = 196
C3 ≡ 13 mod (41 * 101) = 2197
3
Since the moduli n1 , n2 , and n3 are pairwise coprime, and any ciphertext is less than the modulus (i.e. Ci < ni , i = 1, 2, 3) ,
by the Chinese remainder theorem, there exists one and only one value of x to fulfill the equation system.
There exist multiple methods to solve linear equation systems. The solution to the problem is k1 = 39 , k2 = 3, k3 = 0 .
Consequently, x = 2197 and 3 2197 = 13 . Thus, the message can be recovered from the known ciphertexts and public
keys.
Problem 12.2
Let e , d, and n be the RSA public and private key and modulus, respectively.
RSA is correct if the decryption of a ciphertext C = M e mod n returns the original plaintext M . Formally, the following
must hold:
d
( M e mod n) ≡ M mod n = M , ∀M ≤ n − 1 (a)
Problem 12.3
Let e , d, and n be the RSA public and private key and modulus, respectively.
RSA is correct if the decryption of a ciphertext C = M e mod n returns the original plaintext M . Formally, the following
must hold:
d
( M e mod n) ≡ M mod n = M , ∀M ≤ n − 1 (a)
By definition of RSA keys: e * d ≡ 1 mod ( p − 1)(q − 1). Thus, there exists an integer k such that: e * d = 1 + k ( p − 1)(q − 1)
1+k( p−1)(q−1)
By substitution: M e * d mod n ≡ M mod n
k(q−1)
(q−1) ( )
k p−1
≡ M * (M ( )) p−1
mod n ≡ M * M ( ) mod n
e *d
We need to prove that: M mod n ≡ M mod n
Since M < n and n is a product of two primes p and q , M can have common dividers with p or with q , but not with both.
Hence, three cases are to consider:
Case 1: M is coprime with p and with q .
Case 2: M is coprime with p but not with q .
12.5 Exercises and Problems 411
Multiplying by M both congruences above yield the following congruence equation system:
M ≡ M e * d mod p
S =
M ≡ M e * d mod q
The Chinese theorem states that: if k integer numbers ni , i = 1, …, k are pairwise coprime and greater than 1, and if k
numbers a1 , …, ak such that 0 ≤ ai < ni for every i, there exists a unique integer 0 ≤ x < ∏ii= k
=1 ni
such that x ≡ ai mod ni
for every i in (1, …, k ). By Gauss’s algorithm (see Section 3.3.4),
k
(
x ≡ ∑ ai * N i * N i−1
i=1
) mod N (d)
( ( ) (
M ≡ M e * d * q * q−1 mod p + p * p−1 mod q mod pq )) (e)
To fulfill congruence equation (e), the following must hold:
( ( ) (
1 ≡ q * q−1 mod p + p * p−1 mod q mod pq )) (f)
Congruence (f) is true by the lemma provided in this problem. Therefore,
M ≡ M e * d mod pq , which proves the correctness of RSA decryption.
2) Case 2: M is coprime with p but not with q
Since q is a prime number, M is either 0 or a multiple of q (i.e. M ≡ 0 mod q). By the modular arithmetic exponentia-
tion rule, we have:
e *d
M e * d mod q ≡ (0) mod q ≡ 0 mod q ≡ M mod q
(p−1) ( )
k q−1
M e * d mod p ≡ M * M ( ) mod p ≡ M * (1)
k(q−1)
mod p = M
The integer M ed − M is a multiple of p and q . Since p and q are primes and n = p * q , M ed − M also is a multiple of n.
Therefore, M ed ≡ M mod n , which proves the correctness of RSA decryption.
Problem 12.4
1) The ciphertext 75 was obtained using n = 437 and e = 3. Since the plaintext is supposed to be a value between 3 and 10, we
have to check a maximum of eight alternatives:
If the valid plaintext is 3, then 33 mod 437 ≡ 27.
If the valid plaintext is 4 , then 43 mod 437 ≡ 64.
If the valid plaintext is 5, then 53 mod 437 ≡ 125.
412 12 Public-Key Cryptosystems
(
M 3 = M 3 mod n + 0 * n)
( )
Given C ≡ M 3 mod N , there is a unique solution to M , if M 3 = M 3 mod n + 0 * n , which is 3 C .
3
For example, n = 41 * 101 and M = 5 yield C = 5 = 125 = 125 + 0 * n .
Therefore, 3 125 = 5 .
Problem 12.6
RSA signature scheme does not protect against stolen public keys. It assumes that a higher level mechanism (i.e. authenti-
cation) is used jointly with RSA signature.
Problem 12.7
Recall that RSA signature is the modular exponentiation of the hash of the message to sign. Given two messages M1 and
M 2 and their signatures s1 and s2 , the adversary may start with the following computations:
(s1 * s2 ) mod n ≡ ( H ( M1 ) )
d d
* H ( M 2 ) mod n (d is the private key)
d
(s1 * s2 ) mod n ≡ ( H ( M1 ) * H ( M2 )) mod n
(s1 * s2 ) could be the forged signature. To do so, the adversary must find a message M ′ , such that H ( M ′) = H ( M1 ) * H ( M2 ).
However, he/she has to find the message associated with the given hash. Such an attack is referred to as preimage attack,
which is known to be computationally infeasible, because hash functions are one-way functions.
Problem 12.8
Recall that an existential forgery attack means the adversary can generate a pair composed by a message and its signature
without controlling the message content.
Suppose that Bob signed two messages M1 = 25 and M 2 = 57 and produced two signatures: s1 ≡ 25d mod 119 and
s1 ≡ 57 d mod 119 .
Then, (25, s1 ) and (57, s2 ) are sent to Alice.
Eve intercepts (25, s1 ) and (57, s2 ) and she knows Bob’s public key (5, 119) . Then, an existential attack may consist in
sending (25 * 57, s1 * s2 ) to Alice. Notice that Eve just multiplies the values she received.
Upon reception of (25 * 57 s1 * s2 ) , Alice verifies signature as follows:
e
(s1 * s1 )
e
(
mod 119 ≡ (25 * 57)
d
) mod 119 ≡ 25 * 57
Therefore, the received forged signed message is accepted by Alice. However, notice that Eve cannot control the content of
the forged message.
12.5 Exercises and Problems 413
Problem 12.9
In case of Textbook RSA signature scheme, no hash function is used and the signature of message M is computed as
follows:
s ≡ M d mod n (d is the private key)
d d
( )
s ′ ≡ 2e M mod n mod n ≡ 2e M ( ) mod n ≡ 2e * d M d mod n
d
2e * d mod n ≡ 2e ( ) mod n = 2 and M d mod n ≡ s
Hence, s ′ ≡ 2 * s mod n.
Therefore, the adversary succeeds in forging an attack against the Textbook RSA signature.
Problem 12.10
1) x is a (very) low value compared to y. If the public key has a low value, its corresponding private key has a high value
and vice versa.
2) Let M and C denote the plaintext and ciphertext respectively. Let tenc denote the number of iterations of the encryption
operation and tdec that of the decryption operation. Recall that the right-to-left binary exponentiation method com-
putes ak mod b within log2k square-and-multiply iterations.
If x is the public key and y the private key, then
tenc = log2 x and tdec = log2 y .
If y is the public key and x the private key, then
tenc = log2 y and tdec = log2 x .
Therefore, the sum of tenc + tdec is the same, if the public and private keys are swapped.
There is no gain in terms of the sum of RSA operation times, if we choose low values as private keys.
3) If the adversary knows the public key e and the modulus n and suspects that the private key d is less than 100 , he/she
tries decryption with, at most, 98 candidate private keys and produces 98 candidate plaintexts among which the known
plaintext is used to validate the private key recovery. Keys 1 and 2 are not tested, because key 1 is the identity and 2 is
not coprime with ϕ ( pq), which is even. Let D be the recovered private key. The adversary finds a candidate value
matching ϕ ( pq) and then checks it regarding RSA parameters as follows:
Starting from λ = n − 1, because ϕ ( pq) is not far from n, and until p and q are recovered, check decreasing values of λ:
● If GCD (e * D, λ ) ≠ 1, try the next value of λ.
● If GCD(e * D, λ ) = 1, suppose that λ = ϕ ( pq). Then check:
n = pq and λ = ( p − 1)(q − 1) = pq − p − q + 1 = n − p − q + 1
n n
⇒ p = = n− λ −q +1 ⇒ + q = n− λ +1
q q
⇒ q2 − q (n − λ + 1) + n = 0
" n − λ + 1" is a constant. If the solutions to the second-degree equation above are integers, a pair ( p, q) is found. Then,
check if all RSA parameters are consistent (i.e. e * D ≡ 1 mod ϕ ( pq)). If not consistent, then try the next value of λ.
Example (just the final attempts of attack are given): assume the private key d = 13 has been recovered using a known
pair of plaintext–ciphertext. The modulus, n = 1009 * 1013 , and public key, e = 78469, are known to the adversary.
After some attempts, λ = 1020096 , which meets 78469 * 13 ≡ 1 mod 1020096 , is found.
Make substitutions in the second degree equation above:
q2 − q (1009 * 1013 − 102096 + 1) + 1009 * 1013
= q2 − 2022q + 1022117
The solutions to equation are q = 1009 and q = 1013, which means that the primes are recovered.
414 12 Public-Key Cryptosystems
4) Let m be the bit-length of the private key. Given a pair of plaintext–ciphertext, each tested private key k ∈ 3, 2m − 1
m
2m −1
m
requires log2 k RLBEM iterations. To test all the private keys in range 3, 2 − 1 , ∑ i=3 log2 i = ∑ k =3 k * 2 k −1
( )
−(m − 1) + 3 = 2m (m − 1) − m. RLBEM iterations are needed (the proof of the formula is addressed below). Therefore, to
make infeasible a plaintext brute-force attack with a capacity of 2Ω iterations, 2m (m − 1) − m ≥ 2Ω , i.e approxi-
mately m log2 m ≥ Ω .
5) As a conclusion, the use of low-value RSA private keys is insecure. Therefore, they are prohibited in RSA
cryptosystems.
( )
m
2 −1 m
Proof: ∑ i=3 log2 i = ∑ k =3 k ∗ 2k−1 − (m − 1) + 3 = 2m (m − 1) − m
( )
m
2 −1 m
i) Proof by recurrence that ∑ i=3 log2 i = ∑ k =3 k ∗ 2k−1 − (m − 1) + 3:
8−1
m=3: ∑ i=3 log2 i = 2 + 2 + 3 + 3 + 3 = 13
∑ k=3(k ∗ 2k−1 ) − (3 − 1) + 3 = 3 ∗ 23−1 − (3 − 1) + 3 = 13
3
16−1
m=4: ∑ i=3 log2 i = 2 ∗ (2) + 4 ∗ (3) + 7 ∗ (4) = 44
∑ k=3(k ∗ 2k−1 ) − (4 − 1) + 3 = 3 ∗ 23−1 + 4 ∗ 24−1 − (4 − 1) + 3 = 44
4
Now, assume that the equality holds for m = n (n > 3 ) and prove that the property holds for m = n +1:
n +1
∑(k * 2 ) − ((n + 1) − 1) + 3
k −1
k =3
n
( )
= ∑ k * 2k−1 + (n + 1) 2n − ((n + 1) − 1) + 3 ( )
k =3
n
( )
= ∑ k * 2k−1 − (n − 1) + 3 + (n + 1) 2n − 1 ( )
k =3
2n+1 −1
log i = ∑ 2 −1 log i + ∑ 2 n−1 log i
n n+1
∑ i=3 2 i=3 2 i =2 2
2n+1 −1
In the sum ∑ i=2 +1 log2 i ,
n i takes 2n − 1 values ranging from 2n + 1 to 2n+1 − 1 and log2 i = n + 1.
( )
n+1
2 −1
Hence, ∑ i=2n +1 log2 i = (n + 1) 2n − 1 and equation (a) becomes
= (∑ (k ∗ 2 ) −((n + 1) − 1)) + 3
n +1 k −1
k =3
Therefore, ∑ i=3
2m −1
2 k =3 (
log i = ∑ m k * 2k−1 − (m − 1) + 3 )
m
ii) Proof by recurrence that ∑ k * 2k−1 = 2m (m − 1) − 4 ( )
k =2
∑ k=3(k * 2k−1 ) = 3 * 22 = 23 (3 − 1) − 4 = 12
3
m = 3:
12.5 Exercises and Problems 415
∑ (k * 2 k − ) = 3 * 2 + 4 * 23 = 24 (4 − 1) − 4 = 44
1 2
m = 4:
k =3
Now, assume that the equality holds for m = n (n > 3 ) and and equation (a) becomes m = n +1:
( ) ( )
= 2n (n − 1) − 4 + (n + 1)2n = 2n (2n) − 4 = 2n+1 (n) − 4
Therefore,
2m −1
∑ i =2 2 (
k =2 )
log i = ∑ m k * 2k−1 = 2m (m − 1) − 4.
□
m
2 −1
Finally, ∑ i=3 log2i = 2m (m − 1) − m .
Problem 12.11
e e
1) Let C1 ≡ ( M1 ) mod n and C2 ≡ ( M 2 ) mod n be two ciphertexts.
(( )(
C1 * C2 mod n ≡ M1e mod n * M 2e mod n mod n ))
e
≡ M1e * M 2e mod n ≡ ( M1 * M 2 ) mod n
Therefore, the product of two RSA ciphertexts is equal to the encryption of the product of the two respective
plaintexts.
e
2) Assume that Eve has intercepted a ciphertext sent by Alice. Let be C ≡ M sec mod n be the ciphertext known to Eve. M sec
is the plaintext to recover by Eve. The attack may be designed as follows:
● Eve chooses an arbitrary plaintext x ∈ Zn* , then computes Carb ≡ x e * C mod n
● Eve sends the ciphertext Carb to Bob as a pretext to check if he owns the private key associated with the public key (e, n).
● Bob decrypts the ciphertext and obtains an arbitrary plaintext M arb :
d
d
M arb ≡ Carb ( )
mod n ≡ x e * C mod n
≡ ( x * C ) mod n ≡ ( x e * d mod n) * (C d mod n) mod n
e *d d
≡ x * M sec mod n
● Bob returns the plaintext M arb to Eve.
●Eve knows x and M arb ; thus, she can compute M sec ≡ x −1 * M arb mod n
3) Numeric check:
● Eve computes: C
19
arb ≡ 40 * 7408 mod 10403 ≡ 1597
● Eve sends ciphertext 1597
4) The Optimal Asymmetric Encryption Padding (see Section 12.2.5) prevents the attack based on multiplicative property
of RSA. Indeed, OAEP encodes each message, using padding bits, before its encryption.
Let P ( M ) denote the OAEP-encoding of message M . Given two plaintexts M1 and M 2 , RSA with OAEP, encrypts M1
e e e
as C1 = ( P ( M1 )) mod n , M 2 as C2 = ( P ( M 2 )) mod n , and M1 * M 2 as C3 = ( P ( M1 * M 2 )) mod n . So,
e e e
C1 * C2 mod n ≡ ( P ( M1 )) * ( P ( M 2 )) mod n ≡ ( P ( M1 * M 2 )) mod n. Therefore, the attack cannot succeed.
Problem 12.12
1) In general, the right-to-left binary exponentiation method (RLBEM) requires log2 k iterations to find x such that
x ≡ ak mod n , given a, k , and n. RLBEM iteration is composed of a test, two modular multiplications, and a
one-bit-shift.
416 12 Public-Key Cryptosystems
If only the modular multiplication matters, the encryption time is 2 * log2 e * m2 * c, where m denotes the bit-length
modulus n. c is a constant that depends on the underlying implementation and hardware.
If the bit-length of the modulus n multiplied by a factor of δ, the encryption time is increased by a factor of
(
)
2 * log2 216 + 1 * (δ * m) * c 17 * (δ * m)2
2
= = δ2.
(
)
2 * log2 216 + 1 * m2 * c 17 * m2
2) Modulus 4092 is 4 * 1024 . With δ = 4, by substitution in the formula above, the ratio of the encryption time increase is
δ 2 = 16 . It is worth noticing that increasing the security level of an RSA cryptosystem comes with a significant compu-
tation time increase.
Problem 12.13
* 8
1) 100 000 007 is prime. Thus, Z100 000 007 has 100 000 006 elements, which is close to 10 . Therefore, in case of a brute-force
attack, approximately 108 powers of the generator should be computed and tested. Consequently, the worst computa-
tion time is 1 * 108 μs (i.e. 100 seconds), which is not deterrent for attackers.
2) If the length of p is 90 bits and p is prime, then Z *p has approximately 290 elements. Consequently, the worst computa-
9
( )
tion time is 1 * 290 µs = 210 µs = 10249 µs ≈ 1027 seconds!
Problem 12.14
Recall that the shared secret key is computed in DHKE protocol as follows:
PrB PrA
( )
K AB ≡ g PrA mod p ≡ g PrB ( ) mod p
where PrA , PrB , g , and p denote party private keys, the generator, and the modulus, respectively.
1) With p = 101, g = 13, PrA = 26, PrB = 4
4
K AB ≡ 1326( ) mod 101 ≡ (13104 ) mod 101
≡ (13100 ) * 134 mod 101
By Fermat’s little theorem, K AB ≡ 1100 * 134 mod 101 ≡ 79
2) With p = 101, g = 13, PrA = 12, PrB = 17
17
K AB ≡ 1312( ) mod 101 ≡ (13204 ) mod 101
≡ (13100 *2 ) * 134 mod 101
By Fermat’s little theorem, K AB ≡ 1200 * 134 mod 101 ≡ 79
3) Let ( PrA , PrB ) and ( PrA′ , PrB′ ) be two distinct private key pairs. Both pairs generate the same shared secret key
K AB ≡ g α mod p , with α a positive integer less than p −1, if there exist two positive integers k and k ′ such that
PrA * PrB = k * ( p − 1) + α and PrA′ * PrB′ = k ′ * ( p − 1) + α, because, by Fermat’s little theorem:
k
g PrA * PrB mod p ≡ g ( ) g α mod p ≡ g α mod p
k *( p−1)+α
mod p ≡ g p−1
k′
mod p ≡ ( g p−1 ) * g α mod p ≡ g α mod p.
k ′ *( p−1)+α
g Pr * Pr mod p ≡ g
A
′ B
′
Problem 12.15
● A private key used in DHKE protocol must be distinct from 1, because of the following:
If one side, say Bob, picks 1 as his private key, then his public key is PuB ≡ g 1 mod p ≡ g .
The other side, say Alice, picks a private key PrA distinct from 1, then her public key is Pu A ≡ g PrA mod p .
PrA
Next, the shared secret key is computed as K AB ≡ g 1 ( )
≡ g PrA mod p. Therefore, the shared secret key is the same
as Alice’s public key, which is insecure.
● A private key used in DHKE protocol must be distinct from p −1, because of the following:
If Bob picks p −1 as his private key, then his public key is PuB ≡ g p−1 mod p ≡ 1 (by Fermat’s little theorem). Alice
picks a private key PrA distinct from p −1, then her public key is Pu A ≡ g PrA mod p .
p−1
Next, the shared secret key computed by Bob is K BA ≡ ( Pu A )
PrA
p−1
( )
mod p ≡ g PrA mod p ≡ 1; the shared secret key
computed by Alice is K AB ≡ (1) mod p ≡ 1.
Hence, if a participant uses p −1 as private key, then both sides would generate a shared secret key equal to 1, which
is equivalent to not using any cipher.
Problem 12.16
The shared secret key generated by the DHKE protocol is defined by:
PrB
( )
K AB ≡ g PrA mod p ≡ g PrA * PrB mod p, where PrA , PrB , g , and p denote party private keys, the generator, and the mod-
ulus, respectively.
If the private keys are chosen such that PrA * PrB = k * ( p − 1), with k a positive integer, then
k
K AB ≡ g PrA * PrB
( )
mod p ≡ g p−1 mod p.
k
Since g is coprime to p, by Fermat’s little theorem, K AB ≡ (1) mod p = 1.
For example, if p = 47 , PrA = 23, and PrB = 2 , then K AB ≡ g 23*2 mod 47 ≡ 1.
Problem 12.17
1) Given a group Z *p , by definition of element order (see Section 3.2.1)), if an element g has an order of Ω( g ) , then
Ω( g ) k *Ω( g )+α
g mod p ≡ 1. Hence, for any positive integers k and α , with α < Ω( g ), g mod p ≡ g α mod p .
In DHKE protocol, the computation of the shared secret key K AB from two private keys PrA and PrB is as follows:
K AB = g PrA * PrB mod p .
If PrA = k * Ω( g ) + α and PrB = k ′ * Ω( g ) + α ′, with k and k ′ , two positive integers, and α and α ′ , two positive integers
less than Ω( g ) , then K AB = g α *α mod p .
′
Increasing a private key value by a multiple of Ω( g ) does not change the resulting shared secret key. Therefore, if a
generator g has an order of 2256 , then the maximum value that private keys can have is 2256 − 1 .
2) In DHKE, the security strength depends on the private key value range, which in turn is limited by the order of the gen-
erator. Therefore, to provide a security strength of 256 bits to DHKE protocol, the generator should have an order of at
least 2256 .
First, the generator used in DHKE protocol is public, thus known to the adversary. Second, to recover a private key K ,
one has to solve a discrete logarithm problem either “find K such that 2 K ≡ h mod p ” or “find K such that
K
(216 + 1) ≡ h mod p”, with known p and h. Therefore, from the security point of view, the value of the generator
(excluding 1 and p −1) does not matter. Therefore, it is customary to select a generator g , which makes public and
shared key computations easier, usually g = 2 or g = 3.
Problem 12.18
k
1) If g = p −1, then ( p − 1) mod p is either 1 or p −1 for any positive integer k :
0
(p − 1) ≡ 1 mod p
1
(p − 1) ≡ p − 1 mod p
2
(p − 1) = p2 − 2p + 1 ≡ 1 mod p
For any k > 2, there exist k1 ≥ 1 and k2 ∈ {0,1} such that k = 2k1 + k2
418 12 Public-Key Cryptosystems
k1
k
(
Hence, ( p − 1) ≡ ( p − 1)
2
) k k k
* ( p − 1) 2 ≡ (1) 1 * ( p − 1) 2 mod p .
Therefore, g = p −1 generates only two elements; its order is 2.
k
2) Let g = p −1 be the generator used in HDKE protocol. The answer to question 1, shows that ( p − 1) is either 1 orp −1.
Therefore, the shared secret key generated by DHKE is either 1 or p −1 whatever are the chosen private keys. Therefore,
the shared secret key is easy to recover from observing the public parameters p and g .
Problem 12.19
1) Lagrange’s theorem states that if G is a group and H is a subgroup of G, then H divides G . In addition, any element
a ∈ G, with order denoted Ω(a) generates a subgroup of G; thus, Ω(a) divides G .
If p is a prime, then Z *p = p −1. If p is a safe prime, then p − 1 = 2q , with q prime. Hence, dividers of p −1 are
p −1
{1, 2, q, p − 1} . Therefore, any element in Z*p has an order of 1, 2, q = , or p −1.
2
Element 1 generates a subgroup of a single element, which is 1 itself, because 1k = 1 , for any positive integer k .
1
Element p −1 generates a subgroup of two elements, 1 and p −1, because ( p − 1) ≡ ( p − 1)mod p ,
2 2k 2 k +1
(p − 1) = p2 − 2 p + 1 ≡ 1 mod p, …, ( p − 1) ≡ 1 mod p and ( p − 1) ≡ p − 1 mod p , for any positive integer k . Hence,
p −1
the order of 1 is 1 and that of p −1 is 2. Therefore, any element in {3, 4, …, p − 2} has an order of either or p −1, if
2
p is a safe prime.
2) When DHKE protocol is of concern, parties agree on a generator g to compute a shared secret key. If p is a safe prime, any
p −1 p −1
element g of Z *p − {1, p − 1) has an order of either or p −1. Hence, depending on the shown generator, either −1
2 2
log2 ( p)
or p − 2 distinct private keys may be chosen. Therefore, a safe prime p provides a security strength of nearly 2 .
Problem 12.20
Yes, the basic DHKE protocol, as defined in this chapter, is vulnerable to man-in-the-middle attack. Let us show a scenario:
Alice and Bob cooperate to generate a shared secret key. Eve intercepts the messages sent by Alice and Bob. Then, instead
of the legitimate Alice’s public key, Eve makes use of her private key and sends her public key to Bob. Then, the generated
shared secret key is known to Eve. Therefore, she can recover the messages sent by Bob to Alice and then either not forward
them to Alice or modify them before sending them. To let Alice decrypt the messages, Eve sends her public key to Alice
instead of Bob’s public key. In this scenario, there are two shared secret keys, one between Bob and Eve and another bet-
ween Eve and Alice. To prevent DHKE protocol from man-in-the-middle attack, a third trusted party must be used to
authenticate the public keys used to generate a shared secret key.
Problem 12.21
1) If the initialization value π (0) used by a party B and the public key of partner A are known to adversary who can inter-
cept ciphertexts, then the adversary can easily derive the per-message keys used for encrypting the plaintexts, because
she/he knows the PRNG in use. Also, if the adversary knows the k th pair ciphertext-plaintext, he/she can use k to
obtain per-message keys used for plaintexts encrypted before and after the k th plaintext, because the PRNG in use is
deterministic.
2) The primary technique to make a known PRNG secure when used in a cryptosystem, is to make its seed (i.e. initial
value) confidential. Another technique is to randomly discard some returned results of the PRNG before using a value
as a private key. For example, use in tandem two PRNGs, one is public and another is private. The second PRNG is peri-
odically used to pick a random integer, which indicates the number of PRNG results to discard before selecting one
result as a per-message key. Since the number and the positions of discarded values of the PRNG are unknown to the
adversary, he/she cannot reconstruct the series of per-message keys from the construction of the public PRNG.
3) As conclusion, we can say that the security of ElGamal cryptosystem depends not only on the subgroup used to pick
private keys but also on the security of the PRNG used to generate random private keys.
Problem 12.22
Let (r1 , s1 ) and (r2 , s2 ) be the ElGamal signatures of two messages M1 and M 2 . The public key and private keys are denoted
by PuB and PrB , respectively. The per-message-signature key used to sign both messages is KB . By definition of component
r of signature:
r1 = r2 = r = g K B mod p
12.5 Exercises and Problems 419
Then, by subtraction:
s1 − s2 = ( M1 − M 2 ) K B−1 mod ( p − 1)
M1 − M 2
⇒ KB = mod ( p − 1)
s1 − s2
s1, s2 , r1 , r2 , M1 , M 2 , and p are public. Therefore, the per-message-signature key K B can be derived easily. Then, the adver-
sary makes use of the disclosed per-message-signature key and one of the components s1 or s2 to derive the private key PrB
of the signer:
M1 − ( s1 * K B )
PrB = mod ( p − 1).
r
Problem 12.23
Alice receives ( p, g , PuB , M , (r , s )) such that:
b
r = g a * ( PuB ) mod p
s = −r * b−1 mod ( p − 1)
M ≡ s * a mod ( p − 1)
(
v = PuBr * r s mod p )
By substitution:
r s
( ) * (g
v = g PrB a
* PuBb mod p )
s
= (g ) * (g
PrB * r a + PrB * r
) mod p
−r * b−1 mod ( p−1)
= g * (g
PrB * r a + PrB * b
) mod p
Using the lemma 12.1 “mod p ↔ mod p −1 ” (introduced in correctness proof of ElGamal signature) v becomes:
(−r ∗b )
−1
(
v = g PrB ∗r ∗ g a+ PrB ∗b ) mod p
(−a∗r ∗b−1 ) +( −PrB ∗b∗r ∗b−1 )
= g PrB ∗r ∗ g mod p
(−a∗r ∗b ) +( −PrB ∗r )
−1
= g PrB ∗r ∗ g mod p
( PrB ∗r − PrB ∗r ) (−a∗r ∗b−1 )
=g ∗ g mod p
(−a∗r ∗b ) −1
=g mod p
s ∗a
=g mod p
g s * a mod p = g s * a mod p
Therefore, the signature is considered valid.
Problem 12.24
1) According to ElGamal’s signature design, the signer must select an ephemeral key k such that 2 ≤ k ≤ p − 2
and GCD(k, p − 1) = 1. Thus, if p = 17, then ephemeral keys are selected from {3, 5, 7, 9, 11, 13, 15}. Compute the first-
component (r ) of signature for each candidate ephemeral-key, using g = 3:
r1 = 33 mod 17 = 10 r2 = 35 mod 17 = 5
r3 = 37 mod 17 = 11 r4 = 39 mod 17 = 14
r5 = 311 mod 17 = 7 r6 = 313 mod 17 = 12
r7 = 315 mod 17 = 6
Therefore, the number of distinct first-components of signature that can be associated with a message x , under the
*
given parameters, is 7. Notice that the order of element 3 is 16; thus, it is a generator of the group Z17 .
2) p = 17: as in previous case, ephemeral keys are selected from {3, 5, 7, 9, 11, 13, 15}. Compute the first-component of sig-
nature for each candidate ephemeral-key, using g = 2 :
r1 = 23 mod 17 = 211 mod 17 = 8
r2 = 25 mod 17 = 213 mod 17 = 15
r3 = 27 mod 17 = 215 mod 17 = 9
r4 = 29 mod 17 = 2
Therefore, the number of distinct first-components of signature that can be associated with a message x , under the
given parameters, is 4. Notice that the order of element 2 is 8 (because 28 mod 17 = 1). Hence, 2 is a generator of the
*
subgroup of Z17 .
3) If p is a safe prime, then the number of nonzero elements in Z *p is 2q, with p = 2q + 1 and q a prime. Any ephemeral
key in Z *p is coprime to p −1, i.e. coprime to 2q. Since q is prime, any odd element in Z *p is coprime to 2q. Therefore,
p −1
the number of elements that can be used as ephemeral keys is − 1, “−1” is to exclude element 1, which cannot be
2
used as ephemeral key. Since g is a generator of Z *p , no distinct keys k1 and k2 , with 2 < k1 < k2 < p − 1 , could result in
the same signature first-component, because g k1 ≡ g k2 mod p . Hence, the number of distinct first-components of signa-
p −1
ture that can be generated for the same message, under the given conditions, is − 1.
2
4) Let p be a safe prime and g , an element of Z *p . The order of g is denoted Ω( g ) . In the previous question, we considered
the case when g is a generator of Z *p . If g is not a generator of Z *p , then Ω( g ) < p −1. As in previous question, the
p −1
number of elements in Z *p that are coprime to p −1 and distinct from 1 is − 1. However, if g is not a generator of
2
Z *p , any pair of elements k1 and k2 such that k2 = Ω( g ) + k1 results in the same first component of signature
r ≡ g k1 mod p ≡ g k2 mod p ≡ g ( ( )) * ( g ) mod p ≡ (1) * ( g ) mod p. Hence, only odd elements of Z
Ω g k1 k1 *
p less than Ω( g )
Ω( g )+1
can result in distinct first-components. Notice that r ≡ g 1 mod p ≡ g mod p . Element 1 cannot be used as an
ephemeral key but element Ω( g ) + 1 can be used. Thus, the number of distinct first components of signature that can
Ω( g ) − 1
be generated for the same message, under the given conditions, is 2 .
12.5 Exercises and Problems 421
Problem 12.25
g is a generator of a subgroup, of order q of the multiplicative group Z *p and q is a prime divisor of p −1. Since g is an
element of Z *p of order q , by the definition of the element order (see Section 3.2.1), g q mod p ≡ 1.
The property can also be proven otherwise as follows:
If q is a prime divisor of p −1, then there exists a unique positive integer i such that: p − 1 = i * q .
p−1
i q
Generator g can be rewritten as: g ≡ h mod p ≡ h mod p , with h a positive integer less than p. Then,
q
p−1
q (1/q) (p−1) q
q
g mod p ≡ h
mod p mod p ≡ h
(
mod p mod p
)
□
q
By Little Fermat’s theorem: g q mod p ≡ (1) mod p ≡ 1.
Problem 12.26
DSA scheme is correct if the verification of a legitimate signed message accompanied with its signature results is “Valid
signature”.
Assume that the received data are p, g , Pubs , M , and (r , s ) generated by the legitimate signer. If M is the authentic mes-
sage, then the hash computed by the verifier is Z , which is the same as the one computed by the signer. To prove DSA
correctness, we make substitutions in the formulas used by the verifier as follows:
−1
(
w = s−1 mod q = K −1 ∗ ( Z + Prs * r ) ) mod q
−1
= K * ( Z + Prs ∗ r ) mod q
u1 = Z ∗ w mod q
u2 = r ∗ w mod q
(
v = g u1 ∗ Pubs u2 mod p mod q )
Z ∗ w mod q Pr r ∗ w mod q
= g
( ) ( )
∗ g s
mod p mod q
((Z + Prs ∗r )∗ w) mod q
= g mod p mod q
Substitute w in v:
( )
v = g K mod q mod p mod q = r = g K mod p mod q ( )
To do so, the following Lemma is needed:
Lemma 12.3 If p and q are two primes, such that q divides p −1, and a and b are two positive integers, such that
a mod q = b mod q , then g a mod p = g b mod p.
Since K mod q = ( K mod q) mod q, replace in lemma 12.3 a by K and b by K mod q . Then, from lemma 12.3:
Then: v = ( g K mod q mod p) mod q = r = ( g K mod p) mod q, which means that the signature verification is correct. □
Problem 12.27
In block ciphers, the key length is chosen enough long to be resistant to brute-force attack, while in RSA, the modulus and
private key have to be enough large to be resistant against factoring. Naïve brute-force attack against AES is of a complexity
of 2128 . Using the complexity bound proven in [3], the complexity of factoring RSA-2048 modulus is of
3
1
1 2
64
(
exp ln 22048
9
) (ln
3
)
ln 22048 3 ≈
2117
Both complexities result in computationally infeasible attacks. Therefore, RSA keys are much larger than AES keys.
Notes
1 The patent for the RSA algorithm (US patent n° 4405829) was issued on September 1983, exclusively licensed to RSA
Security Inc. This patent expired in 2000.
2 By definition of multiplicative inverse, d ≡ e−1mod n .
3 The value of M must be an integer between 0 and n −1 , because the encryption and the description functions are
mod ulon . In case the message to send has a value greater than n −1 , it must be fragmented into a series of segments and
each segment is encrypted separately.
4 An iteration is composed of a test, a multiplication, a division, and a squaring (see the algorithm of the right-to-left binary
exponentiation method in Section 3.3.2).
5 RSA-S denotes RSA with modulus on S bits (e.g. RSA-2048 denotes RSA with modulus n , where n < 22048 − 1).
6 The identity of a function enables to know the input and output lengths as well as the algorithm to run.
7 The US patent n° 4200770, which describes the DH agreement protocol, was assigned to Hellman, Diffie, and Merkle in
1980. This patent expired in 1997.
8 In order to make the private key unpredictable, in both parties, the generation of private keys shall use standard random
number generator, which has been approved to be attack-resistant.
9 The only known attack to reveal the session key is to derive a private key by solving the DLP. Other ways of breaking DHKE
are being investigated without publication of breaking success.
10 Unlike the public-key of the message sender, the public-key of the recipient does not need to change during the session to
receive multiple encrypted messages.
11 k also is called per-message secret number. It is used to generate a public-key of the sender, which has to change for each
message to encrypt.
12 K B also is called per-message-signature key. The public key of the message signer may be generated once for a session, but,
the key (KB ) to sign must be generated for each message.
13 GCD ( KB , p − 1) is the condition of existence of K B−1 used the signature generation in which the computation is done
mod ( p − 1).
14 The US patent n° 5231668, which describes DSA, was assigned to the US department of commerce in 1993. This patent
expired in 2011.
15 k is a prime divisor of an integer n , if k is a prime number and it divides n .
16 The Euler’s totient function φ (n) counts the number of integers k such that 1 ≤ k ≤ n and GCD (k, n) = 1.
17 This lemma is proven in Problem 3.9.
18 In literature, other time complexity models of modular multiplication exist. For example, Karatsuba proposed an algorithm
k
19 When a , n , and k are positive integers, then: ak mod n = (a mod n) mod n .
References 423
References
1 Diffie, W. and Hellman, M.E. (1976). New directions in cryptography. IEEE Transactions on Information Theory 22 (6):
644–654.
2 Rivest, R., Shamir, A., and Adleman, L. (1978). A method for obtaining digital signatures and public-key cryptosystems.
Communications of the ACM 21 (2): 120–126.
3 Crandall, R. and Pomerance, C. (2005). Prime Numbers: A Computational Perspective. Springer.
4 Bellare, M. and Rogaway, P. (1994). Optimal asymmetric encryption. In: Workshop on the Theory and Application of
Cryptographic Techniques, Advances in Cryptology, 92–111. Perugia, Italy: Springer. LNCS 950.
5 Moriarty, K., Kaliski, B., Jonsson, J. et al. (2016). PKCS #1: RSA Cryptography Specifications Version 2.2, RFC 8017. Internet
Engineering Task Force (IETF).
6 ANSI (1998). Digital Signatures Using Reversible Public Key Cryptography for the Financial Services Industry (rDSA) - ANS
X9.31. American National Standard Institute.
7 Menezes, A., van Oorschot, P., and Vanstone, S. (2001). Handbook of Applied Cryptography. CRC Press.
8 Menezes, A., Qu, M., and Vanstone, S. (1995). Key agreement and the need for authentication. In Workshop on Public Key
Solutions, Toronto, Canada.
9 Law, L., Menezes, A., Qu, M. et al. (2003). An efficient protocol for authenticated key agreement. Designs, Codes and
Cryptography 28 (2): 119–134.
10 Barker, E., Chen, L., Roginsky, A. et al. (2018). Recommendation for Pair-Wise Key-Establishment Schemes Using Discrete
Logarithm Cryptography - Special Publication 800-56A (Rev. 3). NIST.
11 ElGamal, T. (1985). A public key cryptosystem and a signature scheme based on discrete logarithms. IEEE Transactions on
Information Theory 31 (4): 469–472.
12 NIST (2013). Digital Signature Standard (DSS) - FIPS PUB 186-4. National Institute of Standards and Technology.
424
13
Public-Key Cryptosystems
Elliptic Curve Cryptography
13.1 Introduction
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Z. Mammeri.
© 2024 John Wiley & Sons Inc. Published 2024 by John Wiley & Sons Inc.
13.1 Introduction 425
80 160–223 1024
112 224–255 2048
128 256–383 3072
192 384–511 7680
256 512+ 15360
Definition 13.1: An elliptic curve over a set S (real numbers, integer numbers, etc.), denoted E ( S ), is the set of solutions
( x , y ) ∈ S 2 to the equation:1
y 2 + dxy + ey = x 3 + cx 2 + ax + b (13.1)
Figure 13.1 shows some examples of shape of elliptic curves over real numbers.
The elliptic curve cryptography uses elliptic curves over finite fields. This means that the points on the curve are limited
to integer coordinates within the field. There are two types of fields to build ECs: prime fields, denoted Fp, where p is a
prime, and extension fields, denoted F2m, where the number of elements is a prime power.
ECs over prime fields and ECs over extension fields differ in their EC equations and in their operations on curve points.
The former are not easy to grasp quickly; the latter are still a bit more complex, but they are recommended by the standards
of public key cryptosystems like ECDSA (elliptic curve digital signature algorithm).
(a) = +7 (b) = − +1
(c) = −3 +1 (d) = +4 −4
Definition 13.2: The order of an EC is the number of points on the EC including a virtual point called point to infinity.
Notations:
● An elliptic curve is denoted E ( Fp ) in case of a prime field and E ( F2m ) in case of an extension field.
● The EC order is denoted #E ( Fp ) or #E ( F2m ) depending on the field type.
The role of the point to infinity is addressed in the sequel.
Note. Elliptic curves are based on finite fields. To address easily EC-based cryptosystems, the basics of finite fields are
reminded with examples and exercises in Chapter 3 (see Section 3.2.2).
Definition 13.3 Elliptic curve:2 it is denoted E ( Fp ) and formed by the set of solutions ( x , y ) ∈ Fp 2 to the equation 13.2 under
the condition 13.3.
E : y 2 ≡ x 3 + ax + b mod p (13.2)
Note. The equation y 2 ≡ x 3 + ax + b mod p is called Weierstrass equation. Hence, the elliptic curves defined by the
equation are called Weierstrass curves.
Point to infinity
A special point called point at infinity, denoted O , is associated with any elliptic curve. It is used to tell that addition of two
points cannot lead to a third point (see vertical point addition below). Point to infinity (also called zero element) is the
neutral element of elliptic curve arithmetic. Adding point to infinity to any point P results in that other point, including
adding point to infinity to itself: P + O = P , O + O = O .
Point to infinity is an artificial point of the curve; it is introduced to fill gaps in the table for addition of points on the
curve, and it acts as the group neutral element. When two points have the same x-coordinate, their addition results in a
point to infinity
Example 13.1 The equation of the elliptic curve used in Bitcoin (denoted secp256k1) is y 2 = x 3 + 7. When we limit the
use of the EC to F17 ; i.e. the equation becomes: y 2 ≡ ( x 3 + 7) mod 17 . The points are shown on Figure 13.2.3 Notice that
condition 13.5 is fulfilled since: ( 4 ∗ 03 + 27 ∗ 72 ) mod 17 ≡ 0 mod 17.
3
– Point (3, 0) belongs to E ( F17 ) , because 3 + 7 − 0 = 34 ≡ 0 mod 17.
– Point (8, 3) belongs to E ( F17 ) , because 83 + 7 − 32 = 510 = 17 ∗ 30 ≡ 0 mod 17.
– Point (3, 3) does not belong to E ( F17 ) , because 33 + 7 − 32 = 7 ≡ 7 mod 17 .
Notes
— The shape of the curve given by y 2 ≡ x 3 + ax + b mod p over a prime field Fp differs from that of the curve y 2 ≡ x 3 + ax + b
(i.e. without specifying a field). For example, the shapes of the curves of the first EC in Figures 13.1 and 13.2 are distinct
although they have the same equation y 2 = x 3 + 7 . The reason is that when the field is finite, say Fp, the points of the initial
curve are mapped modulo p on a curve where the points have integer coordinates in a square p by p. Let ( x , y ) be the coor-
dinates of any point on the infinite elliptic curve. Rewrite x and y as y = y1 + k1p and x = x1 + k2 p , where x1 and y1 are two
positive integers less than p. Equation 13.4 may be rewritten as ( y1 + k1p)2 ≡ ( x1 + k2 p)3 + a( x1 + k2 p) + b mod ,p
13.2 Elliptic Curve Cryptography over Prime Field Fp 427
which can be simplified (using modular arithmetic rules) as y12 ≡ x13 + ax1 + b mod p. Consequently, all the points
whose coordinates differ by a multiple of the modulus p have the same image point on the EC. For example, all points
2 3
of EC defined by y = x + 7 with coordinates x = 3 + 17k (k is integer) and y = 0 are mapped to a single point with
coordinates (3, 0) on the EC ( F17 ) .
— The number of points on the elliptic curve over a finite field Fp is different from the number of elements in the field Fp .
Since points on the curve E ( Fp ) have their coordinates in a square p by p, the number of points may be larger than p.
Exercise 13.1 shows an example of EC ( F23 ) , which has 27 points plus the point to infinity.
yQ − yP
x R = λ 2 − x P − xQ yR = λ ( x P − x R ) − yP λ=
xQ − x P
R1 = P + Q; R2 = P + R1 ; R3 = P + R2
To locate point R1 on the curve; first, a line is drawn between points P and Q. The intersection of the line PQ with the curve
is the point −R1 . Then, the intersection of the vertical line including point −R1 with the curve results in the point R1. −R1
and R1 are symmetrical with respect to the x-axis.
428 13 Public-Key Cryptosystems
Point doubling
Let P = ( x P , yP ) be a point on the elliptic curve E : y 2 ≡ ( x 3 + ax + b) mod p. The point doubling results in a
point R = P + P = 2 P , such that R = ( x R , yR ) where:
3 x P2 + a
x R = λ2 − 2 x P yR = λ ( x P − x R ) − yP λ=
2 yP
As there is no second point to add when point doubling, to locate the point 2P, a tangent to the curve is drawn at point P .
Then, from the intersection between tangent and curve, draw a vertical line to locate the point 2P (see Figure 13.4).
Addition of vertical points (addition of negative point)
Equation y 2 = x 3 + ax + b yields a symmetric curve. A point with the same x-coordinate has two y-coordinates. If P = ( x , y ),
its negative is denoted −P, and defined as −P = −( x , y ) = ( x ,− y ) .4
Addition of point P and its negative results in point to infinity: P + (−P ) = O .
Using the graphical representation of the elliptic curve, one can easily observe that when two points P and Q have the
same x-coordinate, there is no other point on the line PQ that intersects with the curve, that is why their addition results
in point to infinity. For example, in Figure 13.3, R1 + (−R1 ) = O .
Point multiplication by a scalar
Let P be a point over the EC and k an integer, multiplying P by k results in a point R = k ⋅ P = P + P +⋅⋅⋅+ P . Scalar
multiplication is achieved by repeated addition. Notice that a direct multiplication does not exist for elliptic curves,
which makes the EC-based cryptography secure (see section 13.4). Figure 13.4 shows an example of multiplica-
tion R = 4 ⋅ P . Multiplying any EC point by 0 returns the point to infinity O ; and multiplying O by any positive integer
k returns O .
Note. In literature, two notations exist to denote scalar multiplication: either with a symbol “⋅” between the scalar and
the point (e.g. 8⋅ P) or without the symbol (e.g. 8P). In the sequel, the first notation is used to denote point multiplication
and “*” to denote integer multiplication.
Definition 13.4: An element G on an elliptic curve E ( Fp ) is a generator (also called primitive element) if and only if any
point on the elliptic curve is a multiple of G. Formally:
G is a generator of E ( Fp ) ⇒ ∀P ∈ E ( FP ), ∃ k ∈ N * | k ⋅ G = P .
In general, not any points on an elliptic curve can generate all the points of the EC. Rather, each point of an EC can gen-
erate a subset of points. In group theory, we say that the EC is a group, and the subset of points, a subgroup.
An elliptic curve is a group with N points. If N is prime, then there is only one subgroup that is the same than the entire
group. If N is not a prime, then to each integer d that divides N is associated a subgroup of N /d points. For example, if N
is divisible only by 2, 4, and 8, there exist subgroups with 2, 4, 8, N/8 , N/4, N/2, and N points.
By Lagrange’s theorem (Theorem 3.11), all the orders of the subgroups of a group are dividers of the order of the group.
If the group order is prime, then any element of the group, with the exception of the neutral element, are generators of the
group.
Definition 13.5: The order of a point P on an EC, denoted ord( P ), is the number of points, including the point to infinity,
which can be generated starting from point P .
Definition 13.6: The cofactor, denoted h, of a point P is the ratio between the cardinality of the elliptic curve and the order
#E ( Fp )
of point P . Formally, h = .
ord ( P )
Lemma 13.1 Let E be an elliptic curve with order N and d, a prime divider of N. Then, for any point Q on the curve E,
N
⋅ Q is either the point to infinity O or it has an order of d.
d
430 13 Public-Key Cryptosystems
In other words, Lemma 13.1 means that taking a point Q on a curve and multiplying it by the cofactor necessarily yields
a point in a subgroup of prime order d. Therefore, that Lemma is important when selecting a base point in elliptic curve
cryptography. A base point is a point that can generate all points in a subgroup of the curve. The simplified procedure to
select a base point is:
1) Select a prime p and the parameters of the elliptic curve
2) Compute the order of the elliptic curve, denoted #E ( Fp )
3) Choose n, the prime order of the curve subgroup
#E ( Fp )
4) Compute the cofactor h =
n
5) Choose a random point Q on the curve
6) If h ⋅ Q ≠ O , then Q is a basepoint (of prime order n and cofactor h). Otherwise, go to step 5 and try another point.
In cryptography, we use a base point B, which can generate a subset of n points, such that n is a prime and it divides N,
N
the order of the curve. The cofactor of B is h = .
n
If the cofactor is 1, then the used subgroup is the entire group. Any nonzero point on the curve is an elliptic curve gener-
ator and any point that satisfies the curve equation is an element of the subgroup. If the cofactor is greater than 1, then the
used subgroup of order n is strictly included in the group. A point that satisfies the curve equation belongs to some sub-
groups and does not belong to other subgroups. Therefore, EC-based cryptographic algorithms must consider this
property.
Notes
— Notice there may exist more than one generator for the same elliptic curve.
— If point P is a generator of an elliptic curve, then its cofactor is 1. EC cryptosystems with cofactor larger than 4 are more
susceptible to attacks and are undesirable when the size of the subgroups is small.
— In EC-based algorithms, a base point is used to compute the public keys. To face attacks against EC-based cryptosys-
tems, the ideal value of base-point cofactor is 1 (see Section 13.4).
Definition 13.7 Edwards curve: it is an elliptic curve over a finite field Fp , denoted E ( Fp ), with prime p, formed by the set of
solutions ( x , y ) ∈ Fp2 to the equation (13.4) under the condition (13.5).
E : y 2 + ax 2 = 1 + dx 2 y 2 mod p (13.4)
(d ≠ 0 ) ∧ (d ≠ a) (13.5)
Definition 13.8 Montgomery curve: it is an elliptic curve over a finite field Fp , denoted E ( Fp ), with prime p, formed by the
set of solutions ( x , y ) ∈ Fp2 to the equation (13.6) under the condition (13.7).
E : By 2 = x 3 + Ax 2 + x mod p (13.6)
B ( A2 − 4 ) ≠ 0 (13.7)
13.3 Elliptic Curve Cryptography over Extension Fields 431
Point addition
Let P = ( x P , yP ) and Q = ( xQ , yQ ) be two points on an Edwards elliptic curve. The addition of points P and Q results in a
point R = P + Q , such that R = ( x R , yR ) where:
x P ∗ yQ + xQ ∗ yP yP ∗ yQ − a ∗ x P ∗ yQ
xR = y =
R
1 + d ∗ x P ∗ xQ ∗ yP ∗ yQ 1 − d ∗ x P ∗ xQ ∗ yP ∗ yQ
Point doubling
Let P = ( x P , yP ) be a point on an Edwards elliptic curve. The point doubling results in a point R = P + P = 2 P , such that
R = ( x R , yR ) where:
2 x P * yP yP2 − a * yP 2
xR = yR =
1 + d * x P 2 * yP 2 1 − d * x P 2 * yP 2
Point addition
Let P = ( x P , yP ) and Q = ( xQ , yQ ) be two points, such that P ≠ ±Q , on a Montgomery elliptic curve. The addition of points
P and Q results in a point R = P + Q , such that R = ( x R , yR ) where:
yQ − yP
x R = Bλ 2 − x P − xQ − A and yR = λ( x P − x R ) − yP , where λ=
xQ − x P
Point doubling
Let P = ( x P , yP ) be a point on a Montgomery elliptic curve, such that P ≠ −P . The point doubling results in a point
R = P + P = 2 P , such that R = ( x R , yR ), where:
3 x P2 + 2 A * x P + 1
x R = Bλ 2 − 2 x P − A and yR = λ( x P − x R ) − yP , where λ =
2 B * yP
Prime power fields, of the form F2m, also are called extension fields (or extended binary fields); their basics and useful prop-
erties of are presented in Section 3.2.4.
432 13 Public-Key Cryptosystems
It is worth noticing that some cryptographic standards based on finite fields recommended the utilization of extension
fields, F2m, to make computations faster. In 2013, NIST recommended fifteen elliptic curves to support signature with
ECDSA among which ten are based on F2m fields [10].
Definition 13.9: An elliptic curve over an extension field F2m , denoted E ( F2m ), is the set of points ( x , y ), which are solutions
to equation (13.8) under condition (13.9):
E : y 2 + xy = x 3 + ax 2 + b (13.8)
Note. The elliptic curves defined by the equality (13.8) and condition (13.9) are also referred to as binary Weierstrass
curves or simply by binary curves.
Examples of elliptic curves under equation (13.8) over ℝ (real numbers) are shown in Figure 13.5. Notice that, unlike
curves over prime fields, the curves over F2m fields are not symmetrical regarding the x-axis.
Example 13.3 Let us consider the elliptic curve E : y 2 + xy = x 3 + 1 over F22 with reduction polynomial f ( x ) = x 2 + x + 1,
which is irreducible in F2 .
(c) (d)
Note. Operations on EC points, over an extension field F2m, are done modulo the irreducible polynomial selected for the
field F2m.
Point addition
Let P = ( x P , yP ) and Q = ( xQ , yQ ) be two points, with distinct x-coordinates (i.e. x P ≠ xQ ), on the elliptic curve
E : y 2 + xy = x 3 + ax 2 + b. The addition results in a point R = P + Q , such that R = ( x R , yR ) where:
yQ + yP
x R = λ 2 + λ + x P + xQ + a yR = λ ( x P + x R ) + x R + yP λ =
xQ + x P
x y y 2 + xy x3 + 1
2 2
(00) (00) (00) + (00) = (00) 03 + 1 = (01)
2
(00) (01) = g0 ( g ) + 0 = (01)
0
03 + 1 = (01)
2
(00) (10) = g1 ( g1 ) + 0 = (11) 03 + 1 = (01)
2
(00) (11) = g2 ( g 2 ) + 0 = (10) 03 + 1 = (01)
2
(01) = g0 (00) (00) + (00)(01) = (00) g 0 *3 + 1 = 1 + 1 = (00)
2 2
(01) = g0 (01) = g0 ( g ) + ( g ) = (00)
0 0
g 0 *3 + 1 = 1 + 1 = (00)
2
(01) = g0 (10) = g1 ( g1 ) + g 0 g1 = (01) g 0 *3 + 1 = 1 + 1 = (00)
2
(01) = g0 (11) = g2 ( g 2 ) + g 0 g 2 = (01 ) g 0 *3 + 1 = 1 + 1 = (00)
2
(10) = g1 (00) (00) + (00) g 1 = (00) g 1*3 + 1 = g 0 + 1 = (00)
2
(10) = g1 (01) = g0 ( g ) + g g = (11)
0 1 0
g 1*3 + 1 = g 0 + 1 = (00)
2
(10) = g1 (10) = g1 ( g1 ) + g1 g1 = (00) g 1*3 + 1 = g 0 + 1 = (00)
2
(10) = g1 (11) = g2 ( g 2 ) + g1 g 2 = (11) g 1*3 + 1 = g 0 + 1 = (00)
2
(11) = g2 (00) (00) + g 2 (00) = (00) g 2 *3 + 1 = g 0 + 1 = (00)
2
(11) = g2 (01) = g0 ( g ) + g g = (10)
0 2 0
g 2 *3 + 1 = g 0 + 1 = (00)
2
(11) = g2 (10) = g1 ( g1 ) + g 2 g1 = (10) g 2 *3 + 1 = g 0 + 1 = (00)
2
(11) = g2 (11) = g2 ( g 2 ) + g 2 g 2 = (00) g 2 *3 + 1 = g 0 + 1 = (00)
434 13 Public-Key Cryptosystems
Point doubling
Let P = ( x P , yP ) be a point on the elliptic curve E : y 2 + xy = x 3 + ax 2 + b . Point doubling results in a point R = P + P = 2 ⋅ P ,
such that R = ( x R , yR ) where:
yP
x R = λ 2 + λ + a yR = x P 2 + (+1) x R λ = x P +
xP
Example 13.4 Consider again the curve E ( F22 ) with equation y 2 + xy = x 3 + 1 (parameter a of the equation is equal to
0) over the field F22 with reduction polynomial f ( x ) = x 2 + x + 1 and generator g = x . Points of E ( F22 ) are:
E ( F22 ) = {(0,1), (1, 0), (1,1), (2, 0), (2, 2), (3, 0), (3, 3)} ∪ {O }
The order of E ( F22 ) is 8 and the four points (2, 0), (2, 2), (3, 0), and (3, 3) are generators of E ( F22 ) .
(
23 ⋅ P = P + 22 ⋅ P = P + 2(11) ⋅ P = P + 2 1 + 2(1 + 2(2 ⋅ P )) )
To calculate 23 ⋅ P , four point doublings and three point additions are required instead of one point doubling followed by
22 point additions under the naïve method. Among the proposed algorithms for fast scalar multiplication in EC cryptosys-
tems, two algorithms are presented below: left-to-right binary method for point multiplication and recursive method for point
multiplication. Many other variations of fast scalar multiplication of EC points do exist [13]. The first point multiplication
method is based on the binary representation of the scalar k; its pseudocode is as follows:
function Left_to_right_binary_point_multiplication
input k , P : positive integer and EC point
output Q : EC point
1. Let kr−1 … k1k0 be the binary representation of k , (kr−1 = 1)
2. Q = O
3. for i = r−1 down to 0 do
Q = 2 ⋅ Q
if ki = 1 then Q = Q + P
4. return Q
Theorem 13.1 Hasse’s theorem: Let E be an elliptic curve over a finite field Fq , then:
#E (Fq ) − q − 1 ≤ 2 q (13.10)
Hasse’s theorem tells us that #E ( Fq ) is in the interval q + 1 − 2 q , q + 1 + 2 q . #E ( Fq ) is roughly equal to the size of Fq .
In case of prime fields only, Theorem 13.2 gives the exact number of points of an elliptic curve over a prime field.
Theorem 13.2 Let p be a prime and E an elliptic curve over a finite field Fp, then:
x 3 + ax + b
#E (Fp ) = p + 1 + ∑ (13.11)
x ∈Fp p
x 3 + ax + b
where denotes Legendre symbol (see Section 3.1.7.1), which is equal to 1 if there exists y ∈ F such that
p p
y 2 = x 3 + ax + b mod p and −1, otherwise, with one exception, if x 3 + ax + b ≡ 0 mod p , Legendre symbol is equal to 0.
( )
The idea of Theorem 13.2 is to consider u = x 3 + ax + b mod p for each x ∈ Fp and check if u is a square residue (i.e.
there exists v ∈ Fp such that v 2 ≡ u mod p ). Therefore, Theorem 13.2 comes with a high cost to compute the number of
points.
436 13 Public-Key Cryptosystems
Breaking an EC cryptosystem is equivalent to solving the computational problem known as elliptic curve discrete loga-
rithm problem, which is stated as follows:
Elliptic curve discrete logarithm problem (ECDLP): given two points P and Q on an elliptic curve over a finite field Fq, find
an integer k, if it exists, such that Q = k ⋅ P
In regular algebra, when a product A * B is given and A is known, inferring B is easy. In EC, point Q = k ⋅ P is equal to the
addition of point (k − 1) ⋅ P to point P . Therefore, to use a point Q = k ⋅ P , point (k − 1) ⋅ P must be calculated, and so on
until 2 ⋅ P. Multiplication of an EC point by a scalar k is performed through repeated addition:
k ⋅ P = Qk | Q j = Q j−1 + P, (2 < j ≤ k ), Q1 = P
In addition, since ECs are cyclic groups, if the order of P is n, the following holds:
(d * n + k ) ⋅ P = k ⋅ P = Q, ∀d ∈ N, k ∈ N, k < n
Therefore, the attacker should not only find and exploit a single value of k , but a set of values modulo n. To deduce which
value of k matches the product k ⋅ P and recover the private key k , one needs to calculate all multiples modulo n of the
given point P .
To intuitively understand the complexity of inferring k from k ⋅ P , let us make the analogy with points on a circle. From
a point P on the circle move left or right, with a given angle, to a new point P ′, then repeat the moving on the circle until a
point Q is reached, then, from point Q, make a large number d of rotations (each rotation is a series of shifting on the
circle) over the circle and then stop. Determining the exact number of shifting, given the start point P and finish point Q,
is computationally intractable if the variation of shifting angle and the number of rotations are large.
Consequently, “inferring k given k ⋅ P ” problem becomes computationally infeasible to break operational EC cryptosys-
tems where the bit-length of the order of the chosen base point P and that of the field cardinality are of 256 or more.
At the time of writing this chapter, the last known breaking of EC cryptosystem was made by mathematicians in 2004. A
message encrypted with an elliptic curve key algorithm using a 109-bit long key was broken. The effort required 2600 com-
puters and took 17 months.
Table 13.3, from [14], illustrates the computing power needed to solve the EC discrete logarithm problem, with the most
efficient method known at the time of writing this chapter, depending on the size of the underlying finite field.
Note. To not jeopardize the security of EC cryptosystems (i.e. to make the key discovery attacks computationally infea-
sible), the cofactor of the base point G, which is used as parameter in ECC-based algorithms, should be as small as pos-
#E ( Fp )
sible, i.e. close to 1. Recall that the cofactor is h = , where #E ( Fp ) is that cardinality of the EC and ord (G ) is the
ord (G )
number of points generated starting from P . If h = 1, then the selected base point is a generator of the EC, and conse-
quently all the points of the curve may be used to generate public keys, thus making the space of search too wide, which
prevents attacks.
The elliptic curve-based algorithms used in cryptosystems are categorized as key-agreement, message signature, and mes-
sage encryption algorithms. First, the common features are presented, then how ECs is used for each category of algo-
rithms is addressed.
that: n ⋅ G = O ).
E ( Fp)
● h: the cofactor associated with the base point: h =
n
ANSI and IETF standards provide approved guidelines to select all domain parameters and to verify their validity regarding
the required level of security strength [2–4, 7, 14]. It is worth noticing that the parameters selection is of paramount impor-
tance to comply with the needed level of security strength. It is highly recommended for EC-based algorithms implemen-
ters to use the standard domain parameters.
□
Since multiplication is commutative over integers, SB = S A . Thus, both parties compute the same shared secret. Notice that
the modulus in the equations above is n (the order of base point G) and not q , the modulus of the field Fq .
438 13 Public-Key Cryptosystems
Bob Alice
Domain parameters (q, a, b, FR, G, n, and h) are sent by either Bob or Alice and are public.
● Pick a private key PrB, an integer such that Pick a private key PrA , an integer such that
1 ≤ PrB ≤ n − 1 (5) 1 ≤ PrA ≤ n − 1
● Compute a point A : A = Pr ⋅ G
● Compute a point B: B = PrB ⋅ G A
B is the public key of Bob A is the public key of Alice
● Send ( x B , y B ) , the coordinates of point B, to Alice ● Send ( x A , y A ) , the coordinates of point A, to
Bob
Coordinates of points A and B are public.
● Receive coordinates of point A ● Receive coordinates of point B
● Compute a point SB on the curve: SB = PrB ⋅ A ● Compute a point SA on the curve:
S A = PrA ⋅ B
Alice and Bob have computed the same point S = S A = SB = ( x S , yS )
Their shared secret is x S , the x-coordinate of point S.
The shared information may be used as a symmetric key to encrypt messages exchanged between Alice and Bob.
Note. The shared secret is the x-coordinate of point S. The y-coordinate ( yS ) is not a second secret, because if x S is known,
yS is calculated using the EC equation whose parameters (a and b) are public.
⚪ F
17 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
⚪ 0 is the neutral element for addition and each element in F
17 has an additive inverse in F17 : 0 + 0 ≡ 0 mod 17,
1 + 16 ≡ 0 mod 17
⚪ 2 + 15 ≡ 0 mod 17, …, 16 + 1 ≡ 0 mod 17
E ( F17 ) = {(0, 6), (0, 11), (3, 1), (3, 16), (5, 1), (5, 16), (6, 3), (6, 14), (7, 6), (7, 11), (9, 1), (9, 16),
(10, 6),(10, 11), (13, 7), (13, 10), (16, 4), (16, 13)} ∪ {O }
| E ( F17 ) | 19
ord((7, 6)) = 19 and cofactor ((7, 6)) = = = 1.
ord ((7, 6)) 19
– As the domain parameters (p, a, b, n, G ) are public, it does not matter who computes and sends them – Alice or Bob.
We assume that Bob computes and sends the domain parameters to Alice who accepts them. That is: p = 17, a = 2,
b = 2, n = 19, G = (7, 6) .
– Bob picks 9 as a private key ( KBob = 9). He computes point B = 9 ⋅ G = (9, 16) and sends it to Alice.
– Alice picks 13 as a private key (KAlice = 13). She computes point A = 13 ⋅ G = (10, 6) and sends it to Alice.
– Bob receives Alice’s point A and calculates point KBob ⋅ A = 9 ⋅ A = 9 ⋅ (10, 6) = (13, 7)
– Alice receives Bob’s point B and calculates point KAlice ⋅ B = 13 ⋅ B = 13 ⋅ (9, 16) = (13, 7)
– Alice and Bob share the same secret, 13, which is the x-coordinate of point (13, 7) .
Varying k ′ from 1 to c results in a set of points {G, 2 ⋅ G, …, (c − 1) ⋅ G} points. Thus, Alice and Bob agree on a shared point
in a tight set when c is a small value.
Example 13.6 shows how the small-subgroup attack may limit the set of shared secret values.
Example 13.6 Alice and Bob agree to use the elliptic curve E : y 2 ≡ ( x 3 + 7) over prime field F17 . The 18 points of the
used EC are:
E ( F17 ) = {(1, 5), (1, 12), (2, 7), (2, 10), (3, 0 ), (5, 8),(5, 9), (6, 6), (6, 11),
(8, 3), (8, 14), (10, 2), (10, 15), (12, 1), (12, 16), (15, 4), (15, 13), O }
Point (6, 6) is a generator of the group E ( F17 ) ; its order is n = 18 = 2 ∗ 9. Assume that selected base point G is point (6, 6) .
When Eve makes use of the small-subgroup attack, the following actions and computations are performed:
Eve intercepts A = PrA ⋅ G , the public key of Alice, and replaces it by 9 ⋅ ( A) , then sends it to Bob.
Eve intercepts B = PrB ⋅ G , the public key of Bob, and replaces it by ( PrB ∗ 9), then sends it to Alice.
Alice computes S A = PrA ⋅ (9 ⋅ B ) = ( PrA ∗ 9 ∗ PrB ) ⋅ G
Bob computes SB = PrB ⋅ (9 ⋅ A) = ( PrB ∗ 9 ∗ PrA ) ⋅ G
Let Z = 9 ∗ ( PrB ∗ PrA − 1)
440 13 Public-Key Cryptosystems
( ) (
S A = h ∗ Sig A ∗ B ′ + B ′ ⋅ B = h ∗ Sig A ∗ PrBe ⋅ G + B' ∗ PrBs ⋅ G )
= h ∗ Sig A ∗ ( Pr + B ′ ∗ Pr ) ⋅ G = h ∗ Sig
e
B
s
B A ∗ Sig B ⋅G
SB = h ∗ Sig B ∗ ( A′ + A′ ⋅ A) = h ∗ Sig ∗ ( Pr
B
e
A ⋅ G + A′ ∗ PrAs ⋅ G )
= h ∗ Sig B ∗ ( Pr + A′ ∗ Pr ) ⋅ G = h ∗ Sig
e
A
s
A B ∗ Sig A ⋅ G
Thus, S A = SB = h ∗ Sig B ∗ Sig A ⋅ G; i.e. both parties generate the same secret. □
Bob Alice
Domain parameters (q, a, b, FR, G, n, and h) are sent by either Bob or Alice and are public.
● Bob generates his static key-pair ( PrBs , PuBs ) ● Alice generates her static key-pair ( PrAs , Pu As )
● Pick a private key PrBs, an integer such that ● Pick a private key PrAs , an integer such that 1 ≤ PrAs ≤ n − 1
1 ≤ PrBs ≤ n − 1 ● Compute a point A : A = PrAs ⋅ G
● Compute a point B: B = PrBs ⋅G ● Send A to Bob
● Send B to Alice
● Bob generates his ephemeral key-pair ( PrBe , PuBe ) ● Alice generates her ephemeral key-pair ( PrAe , Pu eA )
● Pick an ephemeral private key PrBe , an integer such ● Pick an ephemeral private key PrAe , an integer such that
that1 ≤ PrBe ≤ n − 1 1 ≤ PrAe ≤ n − 1
● Compute a point B ′ : B ′ = PrBe ⋅ G ● Compute a point A′ : A′ = PrAe ⋅ G
● Send B ′ to Alice ● Send A′ to Bob
Let f denote the bit-length of the subgroup order f; i.e. f = log2 (n) . For any EC point R = ( x R , yR ),
( f / 2
the notation R means: R = x R mod 2 + 2 )
f / 2
Example 13.7 Many online tools provide services for playing with ECDSA. The domain parameters of recommended EC
are listed in [10]. As far as we know, the most used elliptic curve in EC-based digital signature systems is labeled P-256; its
equation is y 2 = x 3 − 3 x + b mod p over prime field Fp. Notice that parameter a is −3; and parameter b should be selected
prior starting signing process.
The domain parameters of the EC P-256 are as follows:
p = 15792089210356248762697446949407573530086143415290314195533631308867097853951
442 13 Public-Key Cryptosystems
n = 115792089210356248762697446949407573529996955224135760342422259061068512044369
b = 5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b
xG = 6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296
yG = 4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5
R = s−1 ( H + r ⋅ PrA ) ⋅ G = k ⋅ G
R = k ⋅ G is the same point as Q = k ⋅ G (step 1 in Signature generation). Consequently, ECDSA verification result is correct
when the received message and its signature are valid.
Condition C2
If Bob received an incorrect message, then: H ′ ≠ H .
If Bob received an incorrect signature, then: ( s, r ) ≠ (s′, r ′). There are three cases to check:
13.5 Elliptic Curve-based Algorithms 443
H ′ ≠ H ∧ ( s, r ) = (s′, r ′)
H ′ = H ∧ ( s, r ) ≠ (s′, r ′)
H ′ ≠ H ∧ ( s, r ) ≠ (s′, r ′)
We only prove the first case (then, the two others may be easily proven).
H ′ and H differ; hence, we can write: H ′ = H + δ.
Using the definition of Pu A , U1 , and U 2 , we can write:
R = U1 ⋅ G + U 2 ⋅ Pu A = U1 ⋅ G + U 2 ⋅ PrA ⋅ G
( ) (
= H ′ ∗ s−1 + r ∗ s−1 ⋅ PrA ⋅ G = ( H + δ ) ∗ s−1 + r ∗ s−1 ⋅ PrA ⋅ G )
= s−1 ( H + r ⋅ PrA ) ⋅ G + [s−1 ∗ δ ⋅ G]
As in Condition 1 proof, we can write:
k = s−1 ( H + r ∗ PrA )
□
level of security strength, there is a very negligible probability that s−1 ∗ δ ⋅ G = 0. Thus, the result of ECDSA is “Invalid”,
which is a correct decision.
3) Let (h0 , h1 , …, h2b−1 ) denote the 2b bits of the key hash H . Let H1 = (h0 , h1 , …, hb−1 ) and H2 = (hb , hb+1 , …, h2b−1 ); i.e. H1
and H2 are the first and second halves of H (k ), respectively.
4) Generate the public key Q:
b−2 = 1; hb−1 = 0. Then, set t to the modified H1 ; i.e. t = (0, 0, 0, h3 , …, hb−3 , 1, 0 )
● For Edwards25519: set h = h = h = 0 ; h
0 1 2
● For Edwards448: set h = h = 0 ; h
0 1 b−9 = 1 ; and hi = 0 , for b − 8 ≤ i ≤ b − 1 . Then, set t to the modified H1 ;
i.e. t = (0, 0, h2 , …, hb−10 , 1, 0, 0…, 0)
444 13 Public-Key Cryptosystems
● Encode t : s = BitStringToInteger (t )
● Q = s ⋅ G # multiplication of point G by a scalar s
● Encode
12
Q = Qenc = EncodePoint (Q, b)
5) Encoded public key Qenc is sent either along with the signed message or separately.
Using steps 4.1 (or 4.2) and 4.3 in key-pair generation procedure, we can see that integer s has the three (or two) least
significant bits at 0. Let us focus on the Edwards25519 curve (the same apply to the second curve). We can write s as s = s ′ * 8,
where s ′ the rightmost b − 3 bits of s . 8 is the cofactor of the Edwards2219 curve. Notice that s ′ is distinct from 0, because
it has at least a 1-bit. Then, in step 4.4, the public key is computed as Q = s ⋅ G . By substitution: Q = (8 * s ′) ⋅ G = 8 ⋅ ( s ′ ⋅ G ) . By
Lemma 13.1, Q is point of prime order n. Therefore, the legitimate signer makes use of public key with an order of n.
2) Let (h0 , h1 , …, h2b−1 ) denote the 2b bits of the key hash H . Let H1 = (h0 , h1 , …, hb−1 ) and H2 = (hb , hb+1 , …, h2b−1 ).
3) Compute the part R of the signature using H2 , the second half of the key hash:
● For Edwards25519: r = SHA512( H || M )
2
● For Edwards448: r = SHAKE 256( AppendedData || H || M , 912), where
2
AppendedData = " SigEd 448 " || octet (0) || octet (len(context )) || context ;
octet (a) denotes an octet with a value a; context 13 denotes a bit-string known to the signer and the verifier; by default,
context is the empty string.
SHAKE 256( InputData, 912) produces a hash of 456 bits.
● Compute point R′ = r ′ ⋅ G, where r ′ = BitStringToInteger (r ) . Then, encode point R′ as a b -bit-string
R = EncodePoint ( R′, b)
4) Compute the part S of the signature using H1 , the first half of the key hash
● For Edwards25519: set h0 = h1 = h2 = 0 ; hb−2 = 1; hb−1 = 0. Then, set t to the modified H1 ; i.e.
t = (0, 0, 0, h3 , …, hb−3 , 1, 0)
● For Edwards448: set h0 = h1 = 0 ; hb−9 = 1 ; and hi = 0 , for b − 8 ≤ i ≤ b − 1. Then, set t to the modified H1 ;
i.e. t = (0, 0, h2 , …, hb−10 , 1, 0, 0, …, 0)
● Encode t : s = BitStringToInteger (t ) (14)
● For Edwards25519: W = SHA512( R || Qenc || M )
● For Edwards448: W = SHAKE 256( AppendedData || R || Qenc || M , 912)
● v = (r ′ + BitStringToInteger (W ) ∗ s ) mod n
Encode v : S = IntegerToBitString ( v, b)
5) The EdDSA signature is Sig = R || S
● Decode the second half of the signature Sig to an integer v. If v < n continue the verification. Otherwise, reject the
received message.
2) Compute the hash:
● DataToHash = EncodePoint ( R ′ ) Q
enc M
● For Edwards25519: u = SHA512( DataToHash)
13.5 Elliptic Curve-based Algorithms 445
● For Edwards448: u = SHAKE 256( AppendedData || DataToHash, 912) , where AppendedData has the same
content than that in Signature generation; i.e. AppendedData = " SigEd 448 " || octet (0) || octet (len(context )) || context
● t = BitStringToInteger (u )
3) Check:
● For Edwards25519: c = log ( h) = 3 ; h = 8 is the cofactor of Edwards25519.
2
● For Edwards448: c = log ( h) = 2; h = 4 is the cofactor of Edwards448.
2
c c c
● If (2 ∗ v ) ⋅ G = 2 ⋅ R ′ + (2 ∗ t ) ⋅ Q, then accept message M, else reject it.
( )
(2c ∗ v ) ⋅ G = 2c ((r + t ∗ s )) ⋅ G = 2c ∗ r ⋅ G + 2c (t ∗ s ) ⋅ G
( ) (
= 2 ⋅ R ′ + 2 ∗ t ⋅ ( s ⋅ G ) = 2 ⋅ R ′ + 2c ∗ t ⋅ Q
c c c
)
□
The right part of the equality is the same as the left one. Therefore, if a signature is legitimate, it is validated by the
verifier.
(2 c ∗ v ) ⋅ G = 2 c ⋅ ( R ′ + U ) + (2 c ∗ t ) ⋅ Q = 2 c ⋅ R ′ + 2 c ⋅ U + (2 c ∗ t ) ⋅ Q
= 2c ⋅ R′ + (2c ∗ t ) ⋅ Q.
Therefore, the signature ( R′ + U , v) passes the batched verification. However, it should be noticed that the second part
(2c ∗ t) ⋅ Q can only be produced by the (dishonest) signer that owns the private key. Thus, this signature modification has
no impact on security, because the second part of the signature is computed by the private key owner. In the cofactor-less
verification, the check is:
v ⋅ G = ( R′ + U ) + t ⋅ Q = R′ + U + t ⋅ Q ≠ R′ + t ⋅ Q
Because multiplication by 2c eliminates the 2c -torsion component, the batch verification, can be thought of as checking
validity only in the prime-order subgroup (i.e. it checks only signatures generated by honest private-key owners), while the
cofactor-less can be thought of as checking validity in the full group and rejects signatures modified by dishonest private-
key owners. It is argued in literature that under specific implementations of the verification test, the batch verification can
speed up the verification.
function ANSI_X9.63_KDF
input Z : shared secret (i.e. the x-coordinate of an EC point)
keydatalen : size (in bytes) of the symmetric key to generate
hashlen: size (in bytes) of the hash values computed by the
selected hash function
hashmaxlen : constant, which represents the maximum size of
output of the selected hash function
13.5 Elliptic Curve-based Algorithms 447
5. return K
function ECIES_Encryption
input {q,a,b,G ,FR,n,h}: domain parameters
Pu : public key of the recipient (Pu is an EC point); M : plaintext
R R
hashlen: length (in bytes) of the output of the HASH function
keydatalen: length (in bytes) of the encryption key
mackeylen : length (in bytes) of the MAC key
output S : bit-string
( )
1. # Select an ephemeral18 EC key pair PrSe ,PuSe , with:
PrSe is a random integer in {1,…,n − 1}
PuSe = PrSe ⋅ G is an EC point, which represents public key of sender
2. # Compute the shared secret Z
Z = PrSe ⋅ PuR # (Z = ( x z ,y z ))
if Z = O, then go to step 1
3. # Derive the encryption and MAC keys
( k1 ,k2 ) = KDF ( x Z ), where:
k1 is the encryption key; and it is the keydatalen leftmost bytes of the byte string returned
by function KDF(),
k2 is the MAC key and is the mackeylen rightmost bytes of the byte string returned by function KDF(),
4. # Encrypt the message and compute the encrypted message MAC
C = ENC (M ,k ); T = MAC (C ,k )
1 2
5. S = PuSe || C || T ; return S
448 13 Public-Key Cryptosystems
ECIES decryption
function ECIES_Decryption
input {q, a, b, G, FR, n, h} : domain parameters
PrR : private key of the recipient
PuSe : ephemeral public key of the message sender
C : ciphertext; T : message tag
hashlen: length (in bytes) of the output of the HASH function
keydatalen : length (in bytes) of the encryption key
mackeylen : length (in bytes) of the MAC key
output M : bit-string
1. # Compute the shared secret Z
Z = PrR ⋅ PuSe # Z is a point; i.e. Z = ( x z , y z )
if Z = O , then Reject the received message and Stop.
2. # Derive the decryption and MAC keys
(k1 , k2 ) = KDF ( x Z ) , with the same notations as in Encryption process
3. # Compute and verify the tag
T ' = MAC (C , k2 )
if T ′ ≠ T, then Reject the message (authentication failure).
4. # Decrypt the message
M = DEC (C , k1 )
5. return (M )
( )
4) If f ( x ) = ( x 3 + ax + b) mod p is a square in Fp , then x , f ( x ) is a point on the elliptic curve E ( Fp ). Otherwise, try
another integer x until the test is positive or all the values of x in the range have been tested.
x
5) If M is embedded in x , then, M is easily retrieved from x : M = .
k
Notes
— The probabilistic mapping method may fail in finding an x value, which represents the x-coordinate of a point on the
elliptic curve.
— The x value yielded by the mapping (if it succeeds) is x = K ∗ M + c (c is an integer, 0 ≤ c < K). Since x represents the
coordinate of a point on E ( Fp ), x is less than p. Thus, the value of any message M to encrypt should be less than P .
K
— To speed the computations, K should be a power of 2. If K = 2 L (L is an integer), then x is yielded by L left-bit shifts of the
x
integer M. The plaintext L can be decoded simply by dropping the M rightmost bits of x. That is: M = L .
2
— On one hand, the value of K should be as low as possible, because it impacts the amount of data embedded in plaintexts;
the higher the value of K is, the lower the size of messages that can be mapped to EC points is. On the other hand, the
lower the value of K is, the lower probability to find an EC point is. The probability of mapping failure is 2−K . See
Problem 13.7.
0 No point
1 (30, 0)
2 (34, 10) , (37, 6) , (39, 1) , ( 40, 7)
3 (58, 9) , (60, 8)
4 (69, 5) , (72, 4)
5 (80, 2) , (81, 3)
6 No point
450 13 Public-Key Cryptosystems
Bob Alice
● (
Receive Pu ′A , C ′, K ′ )
● Retrieve the EC point: µ ′ = C ′ − PrB ⋅ Pu ′A xµ ′
● From the x-coordinate of point µ ′ extract M ′: M =
K ′
Example 13.9 ( )
Alice and Bob use the elliptic curve E : y 2 ≡ x 3 + x + 1 mod 23. Points of E ( F23 ) are the following:
{(0,1) (0, 22) (1, 7) (1, 16) (3, 10) (3, 13)
( 4, 0) (5, 4) (5, 19) (6, 4) (6,, 19) (7, 11)
(7, 12) (9, 7) (9,16) (11, 3) (11, 20) (12, 4)
(12,19) (13, 7) (13,16) (17, 3) (17, 20) (18, 3)
(18, 20) (19, 5) (19,18) O }
Any of the following points can be used as generator of the chosen EC:
{(0, 1), (0, 22), (1, 7), (1, 16), (3, 10), (3, 13), (9, 7), (9, 16), (18, 3), (18, 20), (19, 5), (19, 18)}.
Alice encrypts and Bob decrypts as follows:
– Bob’s parameter selection:
⚪ Field cardinality: p = 23.
⚪ Mapping of integer 3 onto the selected EC, with K = 4, yields point µ = (12, 4 ) # (because 4 = (12 + 12 + 1) mod 23).
2 2
⚪ Pick k ′ = 4.
□
µ′ = µ + k ′ ⋅ PuB − PrB ⋅ Pu A = µ + (k ′ ⋅ PrB ⋅ G ) − ( PrB ⋅ k ′ ⋅ G ) = µ
x
Then, from x-coordinate of point µ′, the recipient extracts the message M = µ .
k
E ( F17 ) = {(1, 5), (1, 12), (2, 7), (2, 10), (3, 0 ), (5, 8),(5, 9), (6, 6), (6, 11), (8, 3), (8, 14),
(10, 2), (10, 15), (12, 1), (12, 16), (15, 4), (15, 13), O }
1) Show that (5, 8) is not a generator of E ( F17 ).
2) Show that (6, 6) is a generator of E ( F17 ).
Exercise 13.2 Let the EC equation be y 2 = x 3 + 4 x + 20 and the prime field be F29 . E ( F29 ) has 37 points including the
point to infinity, O :
Exercise 13.3 Let E be an elliptic curve given by y 2 = x 3 + 1 over the prime field F103 .
1) Check if point with coordinate x = 2 is on the curve E ( F103 ).
2) Check if point with coordinate x = 4 is on the curve E ( F103 ).
Hint: use Euler’s criterion (Theorem 3.7).
Exercise 13.4
1) Let E be an elliptic curve given by y 2 = x 3 + x + 1 over prime field F103 . What are the y-coordinates of points with coor-
dinates x = 0, x = 11, and x = 73?
2) Let E be an elliptic curve given by y 2 = x 3 + x + 1 over prime field F101 . What are the y-coordinates of points with coor-
dinates x = 0, x = 8 , x = 100, and x = 57?
Hint: use Euler’s criterion (Theorem 3.7).
452 13 Public-Key Cryptosystems
Exercise 13.5 Let E be an elliptic curve over F23 with equation y 2 = x 3 + x + 1 mod 23.( )
1) Find all points on E .
2) Compare the number of found points with the result given by theorem 13.2.
Exercise 13.6 Consider the elliptic curve E : y 2 + xy = x 3 + 1 over the field F22 .
Points of E ( F22 ) are {(0,1), (1, 0), (1,1), (2, 0), (2, 2), (3, 0), (3, 3)} ∪ {O }.
The field F22 has a reduction polynomial f ( x ) = x 2 + x + 1 and a generator g = x .
Show that:
1) Point (1,1) is not a generator of E ( F22 ) ,
2) Points (2, 2) is a generator of E ( F22 ) .
Problem 13.2
1) What is the time complexity of the left-to-right binary method for point multiplication?
2) What is the time complexity of the recursive method for point multiplication?
Problem 13.3 Consider the elliptic curve E ( F22 ) with equation y 2 + xy = x 3 + 1 . Point set of E ( F22 ) is
{(0,1), (1, 0), (1,1), (2, 0), (2, 2), (3, 0), (3, 3)} ∪ {O }.
The field F22 has a reduction polynomial f ( x ) = x 2 + x + 1 and a generator g = x .
1) Calculate 7 ⋅ (2, 2) using the left-to-right binary point multiplication algorithm.
2) Calculate 7 ⋅ (2, 2) using the recursive point multiplication algorithm.
Problem 13.4 Consider an elliptic curve E defined by equation y 2 = x 3 + 2 x + 2 mod 17. Why all points of the elliptic of
curve E are primitive elements (i.e. they are all generators of all the other points of the curve)? Hint: use Lagrange’s the-
orem (Theorem 3.11) and its corollary.
E ( F17 ) = {(1, 5), (1, 12), (2, 7), (2, 10), (3, 0 ), (5, 8),(5, 9), (6, 6), (6, 11),
(8, 3), (8, 14), (10, 2), (10, 15), (12, 1),(12, 16), (15, 4), (15, 13), O }
1) Check that point (5, 8) is not a generator.
Let x kP denote the x-coordinate of point k ⋅ P and ykP its y-coordinate. P is point (5, 8) . The formula of point doubling
yields:
3 ∗ x12P + a 3 ∗ 52 + 0 75
λ= = = = 75 ∗ 16−1 = 7 ∗ 16 ≡ 10 mod 17
2 ∗ y1P 2∗8 16
= ⇒ P + 2 P = 3P = O (point to infinity )
y2 P − y1P 9 − 8 1
λ= =
x 2 P − x1 P 5 − 5 0
y2 P − y1P 5 − 6
λ= =
x 2 P − x1 P 1 − 6
= 5−1 = 7 (5−1 ≡ 7 mod 17).
x3 P = λ 2 − x 2 P − x1P = 72 − 6 − 1 ≡ 42 mod 17 = 8
y3 P = ( x1P − x3 P ) − y1P = 7 (6 − 8) − 6 ≡ −20 mod 17 = 14
Table 13.4 shows the results of calculations for all EC points. All the EC points are multiple of point (6, 6) ; hence, it is a
generator of the EC. The order of the generator (6, 6) is #E ( Fp ) = 18.
Exercise 13.2 Given the EC E : y 2 = x 3 + 4 x + 20 over the finite field F29 , point (8, 19) is one of the generators of E ( F29 ).
The check is as follows:
Let P denote the point (8,19). The multiples of P are:
k λ x kP y kP kP
1 – 6 6 1 ⋅ P = (6, 6)
2 9 1 5 2 ⋅ P = (1, 5)
3 7 8 14 3 ⋅ P = (8,14)
4 4 2 10 4 ⋅ P = (2,10)
5 16 10 15 5 ⋅ P = (10,15)
6 15 5 9 6 ⋅ P = (5, 9)
7 14 15 4 7 ⋅ P = (15, 4)
8 13 12 1 8 ⋅ P = (12,1)
9 2 3 0 9 ⋅ P = (3, 0)
10 2 12 16 10 ⋅ P = (12,16)
11 13 15 13 11 ⋅ P = (15,13)
12 14 5 8 12 ⋅ P = (5, 8)
13 15 10 2 13 ⋅ P = (10, 2)
14 16 2 7 14 ⋅ P = (2, 7)
15 4 8 3 15 ⋅ P = (8, 3)
16 7 1 12 16 ⋅ P = (1,12)
17 9 6 11 17 ⋅ P = (6,11)
18 ∝ 18⋅ P = O
Exercise 13.3 To be on an elliptic curve E : y 2 = x 3 + ax + b mod p , x 3 + ax + b must be a quadratic residue. Euler’s cri-
p−1
terion (Theorem 3.7) states that given integers a and p, such that p > 2 and a and p are coprime, a 2 ≡ 1 mod p , if there
p−1
exists r such that r 2 ≡ a mod p and a 2 ≡ −1 mod p, otherwise.
Exercise 13.4
1) Let E : y 2 = x 3 + x + 1 be an elliptic curve over field F103 . Given x -coordinate, to find the y-coordinate, we need to find
● x = 11 ⇒ 11 + 11 + 1 mod 103 ≡ 4 mod 103 ⇒ y = ±2 mod 103 . Hence, points are: (11, 2) and (11, 101) .
3
2 3
● x = 73 ⇒ y ≡ 73 + 73 + 1 mod 103 ≡ 60 mod 103
13.6 Exercises and Problems 455
In this case, there is no easy way to find the square roots. More work is needed. By Euler’s criterion (Theorem 3.7), 60
103−1
is a square residue, because 60 2 . Thus, a square root exists. Since 103 ≡ 3 mod 4, by Lemma 3.5,
103+1
y ≡ ±60 4 mod 103 ≡ ± 36 mod 103 . Hence, points are (73, 36) and (73, 67).
2 3
2) Let E : y = x + x + 1 be an elliptic curve over field F101 .
● x = 0 ⇒ y 2 ≡ 1 mod 101 ⇒ y = ±1. Thus, points are: (0, 1) and (0, 100) .
● x = 8 ⇒ y 2 ≡ 83 + 8 + 1 mod 101 ≡ 16 mod 101 ⇒ y = ± 4 . Hence, points are: (8, 4) and (8, 97) .
● x = 100 ⇒ y 2 ≡ 1003 + 100 + 1 mod 101
3
y 2 ≡ 1003 mod 101 ≡ (−1) mod 101 ≡ −1 mod 101 ≡ 100 mod 101
⇒ y = ±10. Hence, points are (100, 10) and (100, 91) .
● x = 57 ⇒ y 2 ≡ 17 mod 101.
In this case, there is no easy way to find the roots. More work is needed. By Euler’s criterion, 17 is a square residue,
101−1
because 17 2 ≡ 1 mod 101. Thus, a square root exists. Since 101 ≡ 1 mod 4, Tonelli-Shanks algorithm (see Section
3.3.5.1) can be used to find the square roots.
The steps of Tonelli-Shanks algorithm are as follows:
101 = 22 ∗ 25 + 1. Hence, s = 2 and q = 25.
Find a square nonresidue modulo 101 : u = 2 is a square nonresidue.
Initialization: m = 2 ; c = 225 mod 101 = 10
(25+1)/2
t = 1725 mod 101 = 100; R = 17 mod 101 = 65
Loop:
Iteration 1:
1
i) 1002 ≡ 1 mod 101. Hence, k = 1
m−k−1 0
ii) b ≡ 102 mod 101 ≡ 102 mod 101 = 10
iii) m =1
iv) c ≡ 102 mod 101 = 100
v) t ≡ 100 * 102 mod 101 = 1
vi) R ≡ 65 * 10 mod 101 = 44
Iteration 2:
vii) t ≡ 1 mod 101 . Hence, stop and return r = 44
2
Check: (±44) = 17 mod 101.
Therefore, points are: (57, 44) and (57, 57).
Exercise 13.5
1) In general, to find all points over an elliptic curve E : y 2 = x 3 + ax + b mod p , we need to check for each coordinate
x ∈ Fp , if u = x 3 + ax + b mod p is a square residue. We make use of Euler’s criterion (Theorem 3.7) to check if an
integer u is a square root mod p. Then, for each square residue, we compute the square root (i.e. y). The following table
gives the results of calculations. The number of points is 27 + 1 (+1 to count the point to infinity).
(
u = x3 + x +1 ) u
y | y2
x mod 23 23 ≡ u mod 23 Points on EC
The sum of Legendre’s symbol associated with x -coordinates in F23 is given by the sum of the values in the third col-
umn. Therefore, we checked the correctness of Theorem 13.2. For formal proof of Theorem 13.1, see Problem 13.5.
Exercise 13.6
Since E ( F22 ) has seven points plus the point to infinity, its order is ord(F22 ) = 8.
Therefore, every point P ∈ E ( F22 ) , such that 8⋅ P = O is a generator of E ( F22 ).
The elliptic curve has equation y 2 = xy + x 3 + 1; thus, a = 0 .
The field F22 has a reduction polynomial f ( x ) = x 2 + x + 1 and a generator g = x .
The elements, in binary representation, of F22 are {00, 01, 10, 11}; they are all powers of the generator g = x under the
reduction polynomial f ( x ) = x 2 + x + 1:
g 0 ≡ x 0 mod f ( x ) = (01)
g 1 ≡ x 1 mod f ( x ) = x 1 = (10)
g 2 ≡ x 2 mod f ( x ) = x 1 + 1 = (11)
Representation of elements as powers of the field generator g is very useful for point addition calculation. The coordinates
of points are represented as powers of g . Remember that addition of two elements of F22 is a bitwise XOR operation and
the multiplication is the remainder modulo the reduction polynomial f ( x ) .
As shown in Example 13.3, points of E ( F22 ) are {(0, 1), (1, 0), (1, 1), (2, 0), (2, 2), (3, 0), (3, 3)} ∪ {O }.
Let point P = ( x p , yp ) denote the point to check.
13.6 Exercises and Problems 457
( )
y3 P = (00) g 0 + g 0 + g 0 + g 0 = (00)
(00) + g 0 (00) + g 0
λ= = (division by zero).
g0 + g0 0
That is: 4 ⋅ (1, 1) = O , which means that the order of point is 4 and consequently it is not a generator of E ( F22 ) .
2) Check of point (2, 2) using the formulas of point doubling and point addition
● 2 ⋅ P = 2 ⋅ (2, 2)
g1 2
λ = g1 +
g 1
= g 2 x 2 P = g 2 ( ) + g2 + 0 = g0
2
( ) (
y2 P = g 1 + g 2 + g 0 = g 0 )
⇒ 2 ⋅ (2, 2) = (1, 1) = g 0 , g 0 ( )
● 3 ⋅ P = 3 ⋅ (2, 2) = (2, 2) + (1, 1)
g 0 + g1
λ= = 1 x3 P = 1 + 1 + g 1 + g 0 = g 2
g 0 + g1
( )
y3 P = 1 g 1 + g 2 + g 2 + g 1 = (00)
⇒ 3 ⋅ (2, 2) = (3, 0) = g 2 , 0 ( )
● 4 ⋅ P = 4 ⋅ (2, 2) = (2, 2) + (3, 0)
(00) + g 1 g1 g1 2
λ= 2
g +g 1
=
g 3
=
g 0 ( )
= g 1 x 4 P = g 1 + g 1 + g 1 + g 2 = (00)
(
y4 P = g g + (00) + (00) + g 1 = g 0
1 1
)
⇒ 4 ⋅ (2, 2) = (0, 1) = 0, g 0 ( )
● 5 ⋅ P = 5 ⋅ (2, 2) = (2, 2) + (0, 1)
458 13 Public-Key Cryptosystems
g 0 + g1 g2 2
λ=
(00) + g 1
=
g 1 ( )
= g 2 g −1 = g 1 x5 P = g 1 + g 1 + g 1 + (00) = g 2
( )
y5 P = g 1 g 1 + g 2 + g 2 + g 1 = g 2
⇒ 5 ⋅ (2, 2) = (3, 3) = g 2 , g 2 ( )
● 6 ⋅ P = 6 ⋅ (2, 2) = (2, 2) + (3, 3)
g 2 + g1 2
λ=
g +g2 1
= g 0 x 6 P = g 0 ( ) + g 0 + g1 + g 2 = g 0
( )
y6 P = g 0 g 1 + g 0 + g 0 + g 1 = (00)
(00) + g 1 g1 2
λ= 0
g +g 1
=
g 2
= g 1 g −2 = g 2 x 7 P = g 2 ( ) + g 2 + g1 + g 0 = g1
( )
y7 P = g 2 g 1 + g 1 + g 1 + g 1 = (00)
(00) + g 1 g1
λ= = (division by zero)
g1 + g1 0
Exercise 13.7
1) Find points of the elliptic curve E : y 2 = x 3 + 2 x + 2 mod 17
First, compute the quadric residues mod 17
2 2 2 2 2 2
(1) ≡ (−1) ≡ (16) ≡ 1 mod 17 (2) ≡ (−2) ≡ (15) ≡ 4 mod 17
2 2 2 2 2 2
(3) ≡ (−3) ≡ (14) ≡ 9 mod 17 (4) ≡ (−4) ≡ (13) ≡ 16 mod 17
2 2 2
(5) ≡ (−5) ≡ (12) ≡ 8 mod 17 (6)2 ≡ (−6)2 ≡ (11)2 ≡ 2 mod 17
2 2 2 2 2 2
(7) ≡ (−7) ≡ (10) ≡ 15 mod 17 (8) ≡ (−8) ≡ (9) ≡ 13 mod 17
f (0) = 2 f (1) = 5 f (2) = 14 f (3) = 1 f (4) = 6
f (5) = 1 f (6) = 9 f (7) = 2 f (8) = 3 f (9) = 1
f (10) = 2 f (11) = 12 f (12) = 3 f (13) = 15 f (14) = 3
Third, keep points such that f ( x ) is a quadratic residue mod 17. Hence, the 19 points of the elliptic curve with equation
y 2 = x 3 + 2 x + 2 mod 17 are
{(0, ± 6), (3, ± 1), (5, ± 1), (6, ± 3), (7, ± 6),(9, ± 1), (10, ± 6), (13, ± 7), (16, ± 4), O} .
13.6 Exercises and Problems 459
2) Theorem 13.1 (Hasse’s theorem) bounds the cardinality of an elliptic curve as follows:
#E ( Fq ) − q − 1 ≤ 2 q . In this exercise E ( Fq ) = 19 and q = 17 .
03 + 2 * 0 + 2 2 13 + 2 * 1 + 2 5
= = 1 = = −1
17 17 17 17
23 + 2 * 2 + 2 14 33 + 2 * 3 + 2 35 1
= = −1 = = = 1
17 17 17 17 17
43 + 2 * 4 + 2 6 53 + 2 * 5 + 2 1
= = −1 = = 1
17 17 17 17
63 + 2 * 6 + 2 9 73 + 2 * 7 + 2 2
= = 1 = = 1
17 17 17 17
83 + 2 * 8 + 2 3 93 + 2 * 9 + 2 1
= = −1 = = 1
17 17 17 17
103 + 2 * 10 + 2 2 113 + 2 * 11 + 2 12
= = 1 = = −1
17 17 17 17
123 + 2 * 12 + 2 3 133 + 2 * 13 + 2 15
= = −1 = = 1
17 17 17 17
143 + 2 * 14 + 2 3 153 + 2 * 15 + 2 7
= = −1 = = −1
17 17 17 17
163 + 2 * 16 + 2 16
= = 1
17 17
(1103 + 2 * 110 + 7) mod 179 = 22 mod 179. Thus, point (110, 2) is a mapping solution.
(1113 + 2 * 111 + 7) mod 179 = 112 mod 179. Thus, point (111, 11) is a mapping solution.
(1123 + 2 * 112 + 7) mod 179 = 32 mod 179. Thus, point (112, 3) is a mapping solution.
Problem 13.1
1) Representation of 128 in power of 2 results in: 128 ⋅ P = 2(2(2(2(2(2(2 ⋅ P )))))). Under Left-to-right point multiplication
algorithm, seven point doublings are used. More generally, when k is a power of 2 (i.e. k = 2m ), m point doublings are
used to compute k ⋅ P .
2) There are different alternatives to calculate 127 ⋅ P among which the following ones:
i) 127 ⋅ P is rewritten as 127 ⋅ P = (128 − 1) ⋅ P = 128 ⋅ P − P . Under binary representation multiplication method, seven
point doublings and one addition are used. –P is the negative of point P. –P coordinates depend on the underlying
field: −( x , y) = ( x , − y) if the field is prime and −( x , y) = ( x , x + y) if the field is an extension one (i.e. of the form F2m ).
(
ii) 127 ⋅ P = (1 + 2(63)) ⋅ P = 1 + 2(1 + 2(31)) ⋅ P )
( (
= 1 + 2 1 + 2(1 + 2(15)) ⋅ P ))
( ( (
= 1 + 2 1 + 2 1 + 2(1 + 2(7)) )))⋅ P
= (1 + 2(1 + 2(1 + 2(1 + 2(1 + 2(1 + 2)))))) ⋅ P
= ( P + 2 ⋅ ( P + 2 ⋅ ( P + 2 ⋅ ( P + 2 ⋅ ( P + 2 ⋅ ( P + 2 ⋅ P ))))))
Problem 13.2
1) In the left-to-right binary method for point multiplication, scalar k is represented as a bit string with r bits such that
k = (kr −1kr −2 … k0 ) . The number of iterations is r . Therefore, the complexity of the method is O (log2 (k )).
2) In the recursive method for point multiplication, scalar k is divided by 2 until it reaches 0 or 1. Therefore, the number
of iterations is in O (log2 (k )).
Problem 13.3 Consider the elliptic curve E ( F22 ) with equation y 2 + xy = x 3 + 1 . Points of E ( F22 ) are:
{(0, 1), (1, 0), (1, 1), (2, 0), (2, 2), (3, 0), (3, 3)} ∪ {O }.
The field F22 has a reduction polynomial f ( x ) = x 2 + x + 1 and a generator g = x .
1) Calculate R = 7 ⋅ (2, 2) using the left-to-right binary point multiplication algorithm. Below are the execution steps:
P = (2, 2)
k = 7 = 1112 ; k2 = 1, k1 = 1, k0 = 1
Q =O
i = 2:
Q=2⋅Q= O
13.6 Exercises and Problems 461
k2 = 1 ⇒ Q = Q + P = O + P = P = (2, 2)
i = 1:
i = 0:
Q = 2 ⋅ Q = 2 ∗ (3, 0) = 6 ⋅ (2, 2) = (1, 0)
k0 = 1 ⇒ Q = Q + P = (1, 0) + (2, 2) = 7⋅(2, 2) = (2, 0)
Return (2, 0).
2) Calculate 7 ⋅ (2, 2) using the recursive point multiplication (RPM) algorithm.
1st function call: RPM ((2, 2), 7)
k = 7 ⇒ k mod 2 = 1 ⇒ Return P + RPM ((2, 2), 6)
( )
2nd function call: RPM ((2, 2), 6)
k = 6 ⇒ k mod 2 = 0 ⇒ Return 2⋅ RPM ((2, 2), 3)
( )
3 function call: RPM ((2, 2), 3)
rd
Problem 13.4 Given the elliptic curve E : y 2 = x 3 + 2 x + 2 mod 17, why all points of the elliptic are generators?
Recall that the order of a point P of an elliptic curve is the smallest k such that k ⋅ P = O and a point G is a generator, if the
order of G is equal to the number of points of the curve including the point O . In general, with the exception of point O ,
which has an order of 1 (because 1 ⋅ O = O ), the elements of a group E associated with an elliptic curve have orders in
( p )
2, #E F . By Lagrange theorem and its corollary, any element of a group has an order, which divides the cardinality of
the group. Since the cardinality of the group associated with the elliptic curve y 2 = x 3 + 2 x + 2 mod 17 is equal to 19, which
is a prime, the order of all elements, distinct from O is 19. Therefore, by definition of a group generator, all points of the
elliptic curve, with the exception of O , are generators.
Problem 13.5 (Proof of Theorem 13.2) Let E : y 2 ≡ x 3 + ax + b mod p be an elliptic curve over prime field Fp . A prime
( )
field has exactly p elements. For any u ∈ Fp , if u3 + au + b mod p is a square residue, then there exists two points (u, w ) and
u3 + au + b u3 + a + b
# E ( Fp ) = 1 + ∑ 1 + = 1 + p + ∑
p p
u∈Fp u∈Fp
The “1” after sign “=” is used to include the point to infinity O . □
462 13 Public-Key Cryptosystems
Problem 13.6 Alice signed two messages M1 and M 2 . Let (r1 , s1 ) and (r2 , s2 ) be ECDSA signatures of messages M1 and
M 2 respectively.
If Alice used the same point Q = k ⋅ G to sign both messages, then r1 = r2 = xQ mod n (recall that the component r in sig-
nature is the x-coordinate of point Q). In messages M1 and M 2 , signatures (r1 , s1 ) and (r2 , s2 ) , point Q, and the hash
function are public. Therefore, the attacker can use them.
First, the attacker calculates the hashes: H1 = hash ( M1 ) and H2 = hash ( M 2 ) .
Second, using the definition of the component s of signature, the attacker can write:
s1 = k−1 ( H1 + r1 * PrA ) = k−1 ( H1 + xQ * PrA )
s1 − s2 = k−1 ( H1 − H2 )
Problem 13.7 Alice and Bob use the elliptic curve y 2 = x 3 + x + 1 mod 23. The EC points of E ( F23 ) are:
{(0, 1) (0, 22) (1, 7) (1, 16) (3, 10) (3, 13)
(4, 0) (5, 4) (5, 19) (6, 4) (6, 19) (7, 11)
(7, 12) (9, 7) (9, 16) (11, 3) (11, 20) (12, 4)
(12, 19) (13, 7) (13, 16) (17, 3) (17, 20) (18, 3)
(18, 20) (19, 5) (19, 18) O}
1) Alice and Bob should not use point (4, 0) as parameter G, because the order of point (4, 0) is 2. Point (4, 0) can only gen-
erate itself and O (because the y-coordinate is 0). With G = (4, 0), both public keys are the same and equal to (4, 0) ,
because the single value that Bob can choose as private key and that Alice can choose as ephemeral key k ′ is 1.
2) If Bob selects point (13, 7) for parameter G, he cannot use a private key higher than 6, because 7 ⋅ (13, 7) = O (the order of
point (13, 7) is 7).
3) The messages that Alice can encrypt depend only on parameters K and p. Since p = 23, the messages that can be
encrypted are in the range 0, 22 . In addition, the messages, which will be encrypted, depend on the success of the prob-
abilistic mapping method. The table below gives, for each K value, the range of message values that can be tested for
mapping, the message values for which the mapping succeeded to find EC points, the mapping success ratio, and the
ratio of the numbers l of integers less than p that can be encrypted.
Range Mapping
K of M Mapped values of M success rate Ratio l / p
As you may notice, the higher the value of K is, the higher the probability of mapping success is. Conversely, the higher
the value of K is, the lower the number of message values to map is.
References 463
Notes
1 Elliptic curves used in cryptography are a simplified form of the general equation of elliptic curves. This book is limited to
ECs for cryptography.
2 This is the definition of the traditional ECs over finite fields Fp with prime p .
3 The EC points were calculated using a few-lines python code.
4 Note that the same sign “–” is used with different meanings. “–” before a point means the inverse point within the under-
lying field (it comes from a field operation), while “–” before a y-coordinate means the inverse regarding the y-axis (it comes
from the usual interpretation of “minus”).
5 For both parties, the generation of private keys shall use standard random number generator, which has been approved to
be attack-resistant (see Chapter 16).
6 Points may be calculated with a simple program, given a and b (the coefficients of the curve equation) and p (the modulus
of the field).
7 The randomness of selection of k must be approved and k must be kept secret. The values of k have the same security
requirements as the private key. If an attacker retrieves two or more messages signed with the same value of k , he/she can
derive the private key of the signer.
8 The calculations in the signing process are made modulon . Consequently, the bit size of the hash H must not be greater
than the bit size of n (the order of the base point G ). In case, the bit size of the hash H is greater than the bit size of n , only
the leftmost log2 (n) bits of the hash are used in signing and also in verification.
9 The probability that r = 0 (or that s = 0 ) is approximately 1/n.
10 SHAKE256 is a variant of the SHA3 family. SHAKE 256( Data, 912) has an output of 912 /2 = 456 bits.
11 The randomness of selection of k must be approved and k must be kept secret.
12 Encoding an EC point is the transformation of point coordinates into a bit-string.
13 For example, use context = 1 , to sign emails, context = 2 , to sign pictures, and context = 3 , to sign videos.
14 s is the same in Key-pair generation and Signature generation.
15 In elliptic curve theory, point U is called a 2c-torsion point. There may exist several 2c-torsion points on any elliptic curve
with an order divisible by 2c .
16 The string yielded by a key derivation function is referred to as keying material.
17 Edward and Montgomery curves have parameters which differ a little from those of thetraditional curves (see Section
13.2.4).
18 To prevent attacks, an ephemeral key-pair is selected for each message to encrypt.
19 If the mapping method fails to find an EC point with the chosen K value, then try another value.
References
1 Zhu, L., Jaganathan, K., and Lauter, K. (2008). Elliptic Curve Cryptography (ECC) Support for Public Key Cryptography for
Initial Authentication in Kerberos (PKINIT), RFC 5349. Internet Engineering Task Force (IETF).
2 Adamantiadis, A., Josefsson, S., and Baushke, M. (2020). Secure Shell (SSH) Key Exchange Method Using Curve25519 and
Curve448, RFC 8731. Internet Engineering Task Force (IETF).
3 Nir, Y., Josefsson, S., and Pegourie-Gonnard, M. (2018). Elliptic Curve Cryptography (ECC) Cipher Suites for Transport Layer
Security (TLS) Versions 1.2 and Earlier - RFC 8422. Internet Engineering Task Force (IETF).
4 Housley, R. (2018). Use of the Elliptic Curve Diffie-Hellman Key Agreement Algorithm with X25519 and X448 in the
Cryptographic Message Syntax (CMS) - RFC 8418. Internet Engineering Task Force (IETF).
5 Koblitz, N. (1987). Elliptic Curve Cryptosystems. Mathematics for Computers 48 (177): 203–209.
6 Miller, V.S. (1985). Use of elliptic curves in cryptography. In: Annual International Conference on the Theory and Application
of Cryptographic Techniques - CRYPTO’85; Santa Barbara, California: Springer, LNCS 218, 417–426.
7 Langley, A., Hamburg, M., and Turner, S. (2016). Elliptic Curves for Security, RFC 7748. Internet Engineering Task Force
(IETF).
8 Chen, L., Moody, D., Regenscheid, A. et al. (2019). Recommendations for Discrete Logarithm-Based Cryptography: Elliptic
Curve Domain Parameters, (Draft) SP 800-186. NIST.
9 Josefsson, S. and Liusvaara, I. (2017). Edwards-Curve Digital Signature Algorithm (EdDSA) - RFC 8032. Internet Research
Task Force (IETF).
10 NIST. (2013). Digital Signature Standard (DSS) - FIPS PUB 186-4. National Institute of Standards and Technology.
464 13 Public-Key Cryptosystems
11 ANSI. (1998). Public Key Cryptography for the Financial Services Industry: The Elliptic Curve Digital Signature Algorithm
(ECDSA) - ANSI X9.62. American National Standard Institute.
12 Johnson, D., Menezes, A., and Vanstone, S. (2001). The Elliptic Curve Digital Signature Algorithm (ECDSA). Canada:
University of Waterloo.
13 Hankerson, D., Menezes, A., and Vanstone, S. (2004). Guide to Elliptic Curve Cryptography. Springer.
14 ANSI. (2020). Financial services - Public Key Cryptography for the Financial Services Industry: The Elliptic Curve Digital
Signature Algorithm - ECDSA - ANSI X9.142. American National Standard Institute.
15 Diffie, W. and Hellman, M.E. (1976). New directions in cryptography. IEEE Transactions on Information Theory 22 (6):
644–654.
16 ANSI. (2001). Public-Key Cryptography for the Financial Services Industry: Key Agreement and Key Transport Using Elliptic
Curve Cryptography - ANSI X9.63. American National Standard Institute.
17 Menezes, A., Qu, M., and Vanstone, S. (1995). Key agreement and the need for authentication. In: Workshop on Public Key
Solutions; Toronto, Canada.
18 Law, L., Menezes, A., Qu, M. et al. (2003). An efficient protocol for authenticated key agreement. Designs, Codes and
Cryptography 28 (2): 119–134.
19 Barker, E., Chen, L., Roginsky, A. et al. (2018). Recommendation for Pair-Wise Key-Establishment Schemes Using Discrete
Logarithm Cryptography - Special Publication 800-56A (Rev. 3). NIST.
20 IEEE. (2020). IEEE Standard Specifications for Public-Key Cryptography, IEEE Std 1363-2000. Institute of Electrical and
Electronics Engineers.
21 ISO/IEC. (2006). Information technology, Security techniques, Encryption algorithms, Part 2: Asymmetric Ciphers, Draft ISO/
IEC 18033-2. International Organization for Standardization/International Electrotechnical Commission.
22 Certicom. (2009). Standards for Efficient Cryptography, “SEC 1: Elliptic Curve Cryptography”. Certicom (Canada).
23 ElGamal, T. (1985). A public key cryptosystem and a signature scheme based on discrete logarithms. IEEE Transactions on
Information Theory 31 (4): 469–472.
465
14
Key Management
In previous chapters, we discussed how cryptographic keys might be used. More precisely, symmetric keys are mainly used
for data encryption and decryption and for message authentication code generation and verification. Private and public key
pairs are mainly used for digital signature generation and verification, for shared secret generation, and for encryption and
decryption of keys and data. In addition to those usages of keys, in this chapter, we discuss how existing keys may be used
to derive new keys.
Keys are owned and used by entities (e.g. devices, individuals or organizations) that interact with other entities to con-
duct specific operations in different fields of activities (e.g. e-commerce, e-government services, e-health, etc.). These keys
are analogous to the combination of a safe. If adversaries know the combination of a safe, the latter does not provide any
security against attacks, even it is very complex. Keys are the most valuable items in computer security; thus, their protec-
tion (i.e. confidentiality, integrity, and availability) is of paramount importance. During its lifetime, the key is either in
transit (i.e. exchanged between parties), in use (to encrypt, to decrypt, to sign, etc.), or in storage. Key protection1 shall
address all those steps in the key lifetime cycle.
Key management provides the functions for a secure management of cryptographic keys throughout their lifetime. It
mainly includes key generation, storage, distribution, recovery, suspension, and withdrawal. This chapter aims at intro-
ducing the main mechanisms and protocols for key generation, key agreement, key transport, and key distribution.
Public-key infrastructures (PKIs) are essential services for distribution of public keys. The latter are included in certifi-
cates delivered by trusted authorities enabling the recipient to have assurance regarding the holder of a public key. PKIs
maintain coherent and valid lists of public keys. PKIs are discussed in Section 15.2.
Randomness is of prime importance to generate robust keys (i.e. keys very difficult to guess with statistical analysis
methods). In Chapter 16, we introduce the recommended pseudorandom bit generators.
It is worth noticing that the protocols and functions presented in this chapter are specified in NIST recommendations
and RFCs (Request for comments) and used in current secured applications and services.
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
466 14 Key Management
Thus, keys may be categorized into several types depending on their use. More precisely, the following key types are used
to categorize keys [1]:
● Symmetric encryption and decryption keys: they are used with symmetric-key algorithms to provide confidentiality
guarantees.
● Symmetric key-wrapping keys: they are used to encrypt other keys when they are in transit.
● Symmetric master/key-derivation keys: they are used to derive other symmetric keys.
● Symmetric authentication keys: they are used with symmetric-key algorithms to provide identity authentication and integrity.
● Symmetric key-agreement keys: they are used to establish symmetric keys.
● Symmetric DRBG2 keys: they are used to generate random bits or numbers.
● Symmetric authorization keys: they are used to provide privileges to an entity using a symmetric cryptographic algorithm.
● Private signature-generation keys: they are used by public-key algorithms to generate digital signatures intended for
long-term use.
● Public signature-verification keys: they are used by public-key algorithms to verify digital signatures.
● Private authentication keys: they are used with public-key algorithms to provide evidence of the sender identity, when
establishing an authenticated session or performing some action.
● Public authentication keys: they are used with public-key algorithms to verify the identity of the sender, when establish-
ing an authenticated session or performing some action.
● Private key-transport keys: they are the private keys of asymmetric-key algorithms and are used to decrypt keys that have
been encrypted with the corresponding public key, when establishing symmetric keys.
● Public key-transport keys: they are the public keys of asymmetric-key algorithms and are used to encrypt keys when
establishing symmetric-keys.
● Private static key-agreement keys: they are the long-term private-keys of asymmetric-key algorithms and are used to estab-
lish symmetric keys.
● Public static key-agreement keys: they are long-term public keys of asymmetric-key algorithms. They are used to establish
symmetric keys.
● Private ephemeral key-agreement keys: they are the short-term private keys of asymmetric-key algorithms. They are used
only once to establish one or more symmetric keys.
● Public ephemeral key-agreement keys: they are the short-term public keys of asymmetric-key algorithms. They are used in
a single key-establishment transaction to establish one or more symmetric keys.
● Private authorization keys: they are the private keys of asymmetric-key algorithms and are used to prove the owner’s right
to privileges.
● Public authorization keys: they are the public keys of asymmetric-key algorithms and are used to verify privileges for an
entity that knows the associated private authorization-key.
Usage uniqueness
In general, each key should be used for only one purpose (e.g. confidentiality, integrity authentication, or digital signature),
because of, at least, the following two reasons:
1) The use of the same key for two distinct cryptographic applications may weaken the security provided by one or both of
the applications.
2) Limiting the use of a key limits the damage that could be done if the key is compromised.
DSA: Digital Signature Algorithm, DH: Diffie-Hellman, MQV: Menezes-Qu-Vanstone, ECC: Elliptic
Curve Cryptography, L: public-key bit-length, N: private key bit-length, K: RSA modulus bit-length,
F: key bit-length.
Table 14.2 Security strengths of common hash and hash-based functions [1].
HMAC: Hash-based Message Authentication Code, KDF: Key-Derivation Function, KMAC: Keccak-based Message
Authentication Code, DRBG: Deterministic Random Bit Generator.
Many applications require multiple cryptographic services (e.g. key establishment, confidentiality protection, integrity
protection, digital signature, etc.). A different algorithm and key could be used to provide each service or multiple services
could be provided by the same algorithm using the same or different keys. In addition, many services can be provided by
more than one algorithm (e.g. digital signature can be provided by either RSA or ECDSA). Some algorithms are inherently
efficient by design to perform some specific services, e.g. HMAC is efficient to provide data integrity protection. Therefore,
a cryptosystem designer may have to choose a variety of algorithms and their appropriate key bit-lengths. It is worth
noticing that the higher the security strength is, the higher the computation time and amount of other resources required
to perform security operations are. Therefore, a trade-off between security strength and performance is to be considered
when selecting the bit-length of keys.
14.1.1.3 Cryptoperiod
Definition 14.1 Cryptoperiod: it is the time span during which a specific key is authorized for use by legitimate entities.
The security provided by a key may be reduced or completely lost with time, because of the progress in cryptanalysis or
simply the key becomes suspect (i.e. potential attackers might know some information about the key). The cryptoperiod of
a key may be defined in terms of time between the generation of the key and its end of use or in terms of the maximum
amount of data protected by the key. An adequately defined key cryptoperiod has the following properties:
i) It limits the number of plaintext and ciphertext pairs encrypted with the same key; and therefore, it limits the amount
of information available to attackers to recover the key.
ii) It limits the time for attackers to access resources protected with a key.
In general, short cryptoperiods enhance security. However, frequent changes of keys result in an overhead (due to key gen-
eration and distribution) and key-distribution methods are subject to human errors, which might actually increase the risk
of key exposure. Therefore, a trade-off between cryptoperiod, overhead, and risk is to be considered by security-system
administrators. Table 14.3 summarizes the key types and their respective cryptoperiods suggested by the NIST [1]. Notice
that the cryptoperiod may be different, depending on the entity using the key, the originator (i.e. the entity that starts the
information exchange) or the recipient.
468 14 Key Management
(*) At most two years for originator; and at most three years more than originator, for recipient.
(**) In some applications (e.g. email) where received messages are stored and decrypted at a later time, the recipient key
usage period may exceed the originator-usage period.
(***) In some applications (e.g. email) where received messages are stored and decrypted at a later time, the cryptoperiod
of private key may exceed that of the corresponding public key.
14.2 Key-Generation Schemes 469
longer needed to authenticate data or entities or to decrypt data, previously encrypted with these keys. Public keys
should be de-registered.
4) Destruction phase: the key is no longer available for any cryptographic operation.
B =U ⊕V
where: U is a bit string of Blen bits obtained as the output of an approved DRBG, which shall have at least the secu-
rity strength of the algorithm/application that will use key K. V is a bit string of Blen bits, which could be all zeroes.
U and V are statistically independent of each other. Bit string V may be another key or computed by a hash function
or any other function that can increase the randomness of pair (U , V ).
The bit-length Blen depends on the algorithm/application that will use the key (see Table 14.1).
iterations, C, shall be as large as possible; 1000 is the minimum recommended value for C. For critical keys, C should be in
millions. Figure 14.3 illustrates the generic structure of a PBKDF; and the pseudocode is as follows.
Note. Some functions are generic; and they need specific elements (such as a hash function or some bit-lengths) to build
them before any usage. The elements used one time to instantiate a generic function are specified in parameters clause.
The input clause specifies the values used in each function call.
function PBKDF
parameters HMAC: HMAC with an approved hash function
Hlen: bit-length of hash function used by HMAC
input P: password; S : salt (it is a part of the key of HMAC)
C: iteration count; Klen: key bit-length
output K : key
( )
1. if Klen > 232 − 1 * Hlen then return “Error”
2. Len = Klen / Hlen
3. r = Klen − (Len − 1) * Hlen
4. for i=1 to Len do
Ti = 0; U0 = S || Int ( i )
for j=1 to C do U j = HMAC (P , U j−1 ); Ti = Ti ⊕ U j
5. T = Trunc (TLen , r ) # keep the r first bits of TLen
6. K = T1 || T2 || … || TLen−1 || T ; return K
Notes
– The process of key generation described above is public. Therefore, when passwords are used to generate cryptographic
keys, it is assumed that an attacker is able to perform search attacks (e.g. dictionary attack) on the key generation pro-
cess. Therefore, the password entropy is a critical issue. To make attacks computationally infeasible, it is recommended
i) to use randomly generated passwords instead of user-chosen passwords, ii) the typical password length is of 20 to 30
characters.
– The salt of bit-length Slen allows generating a set of 2S len keys corresponding to each password, for a fixed iteration
count. Using a salt makes it difficult for attackers to prepare a table of potential keys. To make attacks computationally
infeasible, the bit-length of the salt should be as large as possible.
1) Option 1: H ( x ) = Hash( x )
2) Option 2: H ( x ) = HMAC Hash ( Salt , x )
3) Option 3: H ( x ) = KMAC128|256 (Salt , x ," KDF ")
where x denotes the input string; Hash is one of the recommended hash functions, and “KDF” is a constant bit-string,
which represents a sequence of three characters, in 8-bit ASCII. Salt is used as key of HMAC or KMAC. A hash function
can be used directly (option 1) or as a parameter of a keyed MAC (options 2 and 3).
The hash functions recommended to build the auxiliary function of the KDM are shown in Table 14.4. When used in a
KDM, KMAC-128 and KMAC-256 provide a security strength of 128 and 256 bits, respectively. The pseudocode of the
one-step key derivation method is the following:
function One_Step_KDM
parameters H: auxiliary function (hash unction, HMAC or KMAC)
Hlen: bit − lengthoftheoutputofthefunctionH
input Z : shared secret; Klen: bit-length of the key to generate
FixedData: optional data
Output K : key
1. Cnt = 0x00000000 # a 32-bit word with a value of 0
2. N = Klen / Hlen
3. if N > 232 − 1, then return “Error”
4. Result( 0 ) = Empty_Bit_String()
5. for Cnt = 1 to N do
Cnt = Cnt + 1; K ( i ) = H (Cnt || Z || FixedData )
Result ( i ) = Result ( i −1) || K ( i )
6. K = LeftmostBits (Result ( N ), Klen)
7. return K
Note. The one-step derivation method is a generalization of the KDF in counter mode (see Section 14.2.1.5).
function Two_Step_KDM
parameters MAC: MAC function (i.e. HMAC or AES-CMAC)
Hlen: bit-length of the output of the MAC function
KeyExpansion: key expansion function
input Z : shared secret; Klen: bit-length of the key to generate
Salt : a secret or non-secret byte string
FixedData: optional bit-string
IV : initialization vector (used when KDF is in feedback mode)
output K : key
1. Kdk = MAC (Salt , Z )
2. K = KDF (Kdk , Klen, IV , FixedData )
3. return K
As illustrated by Figure 14.6, the two-step KDM, as described above, can be generalized to produce a set of m keys with arbitrary
bit-lengths ( L1 , L2 , …, Lm ) using, when applicable, a set of IVs ( IV1 , IV2 , …, IVm ) and a set of fixed data ( FD1 , FD2 , …, FDm).
Then, the yielded keys may be combined to generate a single key (see Section 14.2.1.4).
474 14 Key Management
function KDF_in_Counter_mode
parameters PRF : pseudorandom function (i.e. HMAC, CMAC, …)
Hlen: bit-length of the PRF output
input Kin : key-derivation key (i.e. a shared secret)
Klen: bit-length of the key to generate
FixedData: optional bit-string
output Kout : generated key
1. N = Klen / Hlen
2. if N > 232 − 1, then return “Error”
3. Result ( 0 ) = EmptyBitString()
476 14 Key Management
function KDF_in_Feedback_mode
parameters PRF : pseudorandom function (i.e. HMAC or CMAC)
Hlen: bit-length of the PRF output
input Kin : key-derivation key (i.e. a shared secret)
Klen: bit-length of the key to generate
IV : initialization vector, which may be a null bit-string
FixedData: optional bit-string
output Kout : generated key
Klen
1. N =
Hlen
2. if N > 232 − 1, then return “Error”
3. Result (0) = EmptyBitString(); K (0) = IV
4. for i = 1 to N do
(
4.1 K (i ) = PRF Kin ,(K (i − 1) FixedData Klen 2 ) )
4.2 Result (i ) = Result (i − 1) K (i )
5. Kout = LeftmostBits (Result (N ), Klen)
6. return Kout
function KDF_in_Double_Pipelined_mode
parameters PRF : pseudorandom function (i.e. HMAC or CMAC)
Hlen: bit-length of the PRF output
input Kin : key-derivation key (i.e. a shared secret)
Klen: bit-length of the key to generate
IV : initialization vector, which may be a null bit-string
FixedData: optional bit-string
output Kout : generated key
Klen
1. N =
Hlen
32
2. if N > 2 − 1, then return “Error”
3. Result (0) = EmptyBitString()
4. A (0) = IV || FixedData || [Klen]2
5. for i = 1 to N do
5.1 A (i ) = PRF (Kin , A (i − 1))
5.2 K (i ) = PRF (Kin , ( A (i ) || FixedData || [Klen]2 ))
5.3 Result (i ) = Result (i − 1) || K (i )
6. Kout = LeftmostBits (Result (N ), Klen)
7. return Kout
Chapter 12) or to find the discrete logarithm for large integers (as mentioned in Chapters 12 and 13). Thus, public-key-
based cryptography is divided into two categories:
● Integer Factorization Cryptography (IFC); RSA is the most known and used algorithm in IFC.
● Discrete logarithm Cryptography (DLC), which is divided into two subcategories, Finite-Field Cryptography (FFC) and
Elliptic-Curve Cryptography (ECC). The most known and commonly used DLC algorithms are Diffie-Hellman (DH) and
Menezes-Qu-Vanstone (MQV) algorithms, which can be used under either FFC or ECC.
In this subsection, we present the methods for generating key-pairs (i.e. public and private key pairs); and in the next
subsection, we address how IFC- and DLC-based algorithms can be used to build key-agreement protocols.
function rsakpg1_basic
input Nb: modulus bit-length; S : expected security strength
e: public exponent
output ( N , d ),( N , e ): private and public keys
1. Check parameter validity
( )
1.1 if e not oddor not in 65537, 2256 − 1 then return “Error”
1.2 if ( S > Nb ), then return “Error”
1.3 if (S not in 112, 256 ), then return “Error”
2. Generate two primes p and q # using a prime generation procedure
3. Determine the private exponent d, such that
d * e = 1 mod (LCM ( p − 1)( q − 1))
4. N = p * q
5. Key-pair consistency verification
if (InconsistencyFound ), then return “Inconsistency”
6. Destroy any copies of primes p andq
7. return ( N , d ),( N , e ) # private and public keys.
478 14 Key Management
function rsakpg2_basic
input Nb: modulus bit-length; S : expected security strength
elen: bit-length of the public exponent e
output ( N , d ),( N , e ): private and public keys
1. Check parameter validity
1.1 if (not (17 ≤ elen ≤ 256)) then return “Error”
1.2 if ( S > Nb ), then return “Error”
1.3 if (S not in 112, 256 ) then return “Error”
2. Generate an odd exponent e in the interval 2elen−1 + 1, 2elen − 1
By using an approved DRBG
3. Generate two primes p and q # using a prime generation procedure
4. Determine the private exponent d, such that
d * e = 1 mod (LCM ( p − 1)(q − 1))
5. N = p * q
6. Key-pair consistency verification
if (InconsistencyFound ), then return “Inconsistency”
7. Destroy any copies of primes p andq
8. return ( N , d , e ) # private and public keys
2) Generation of domain parameters using ad hoc probable or provable primes: the second method to select domain param-
eters is summarized as follows [6]:
– Probable primes can be generated using a hash function H, such as SHA-256, a Counter, which specifies the number
of repetitions of the hash function, and a Seed (a random integer, which must be unique for each set of parameter
domain).
– Provable primes can be generated using Shawe-Taylor’s algorithm [11], as discussed in Section 16.3.4.1.
– Once two primes p and p are generated, select a generator g using the following algorithm.
Below is a simple recommended method for finding a finite field generator:
function Generator_Selection
input p, q: two FFC domain parameters
output g: generator of a finite field Fp
1. u = ( p − 1) / q # u is an integer, because by definition of FFC
# domain parameters q divides p −1
2. Pick a random integer h,2 ≤ h < ( p − 1)
3. g = hu mod p
4. if ( g > 1), then return g
5. else go to step 2
2) Key-pair generation by testing candidates (ECC-KPGTC), which picks a random number and then checks whether it
can produce a valid private key.
The pseudocodes of both key-pair generations are as follows:
key, the latter is securely transmitted to the other party manually or using a key-wrapping or a key-transport protocol. In
case of a public key, the latter is not secret and it is directly sent to the other party or embedded in a digital certificate deliv-
ered by a trusted party. Digital certificates are discussed in Section 15.1.
In the second category, both parties provide to information, which jointly establish a shared secret key. A key derivation
function is then used to derive a secret key from the shared secret. Key-derivation functions are discussed in Section 14.2.1.5.
Definition 14.8 Key establishment: it is the process by which two (or more) parties establish a shared secret key. The
execution of the key-establishment scheme is referred to as key-establishment transaction.
Definition 14.9 Key agreement: it is the process by which the resultant secret key is obtained from the information con-
tributed by both parties. The execution of the key-agreement scheme is referred to as key-agreement transaction.
Definition 14.10 Key transport: it is the process by which one party (the sender) selects and encrypts or wraps a key
and then distributes it to another party (the recipient). The execution of the key-transport scheme is referred to as key
transaction.
Definition 14.11 Key distribution: it is the process by which a key, from an entity that either owns, generates, or other-
wise acquires the key is transmitted to another entity that is intended to use the key. The process may be either manual or
by using a key transport protocol.
Definition 14.12 Perfect Forward Secrecy (PFS): it is a property of key agreement protocols that change the session key
for each user-initiated session, so that if one session key is compromised, only the data encrypted with such a key is vulner-
able; and the data encrypted with any other session key will not be affected.
In the public-key-based key-establishment schemes, the following actions should be performed before starting a key-
establishment process:
● Selection of the FFC or ECC domain parameters to use (for recommended values of domain parameters, see Section
14.2.2).
● Generation (and maybe registration) and distribution of the public keys.
● Selection of a key-derivation function and its parameters (see Section 14.2.1.5).
● Selection of a hash function or a MAC algorithm and the associated parameters (tag bit-length, MAC key bit-length, and
maybe additional fixed data), when a key-confirmation is required (see Section 14.3.3.1.1).
One usual approach is that the initiator of a key-establishment transaction selects and validates all the parameters; and the
other party accepts the proposed parameters.
The output of a key-establishment transaction, called Keying material, is either a secret key or a bit-string from which a
secret key and other information are extracted.
Note. The key-establishment schemes aim to establish keys and other cryptographic elements (e.g. initialization vectors,
etc.), the whole is called keying material. The focus in this chapter is on the shared keys. Thus, by default, the keying
material is limited to a secret key K, which may be used for providing confidentiality assurance and authentication, and
a MAC key, MacKey, which is used only during the agreement process to confirm the possession of private keys. Thus, in
subsequent pseudocodes, KeyingMaterial = ( K , MacKey ).
Symmetric-key distribution
There exist two main solutions:
1) Peer-based generation and distribution: once a symmetric key is generated by one party, it is made available to other
party either manually16 or using an automated key-transport protocol. The latter may be either a key-wrapping protocol
such as KW or KWP, which are addressed in detail in Section 9.2.6, or a public-key key-transport protocol, such as RSA-
KTS-OAEP, which is addressed in Section 14.3.3.2.2.
2) Use of a key distribution center: a server is used to generate and distribute (session) keys to end-users associated with the
server (see Section 14.3.2).
Public-key distribution
For security reasons, the following two recommendations shall be observed when using public-key-based schemes to pro-
tect data or services:
484 14 Key Management
Definition 14.13 Key distribution center (KDC): it is a solution to generate and distribute keys to entities that need to com-
municate with each other but do not share keys except with the center. Entities that have a keying relationship with a KDC are
called subscribers.
A KDC may have two or more levels. At the bottom of the hierarchy, there are entities, called subscribers, that need to
securely exchange data. At the top, a central server is used. When the number of subscribers is large or when fault tolerance
is an issue or for other organizational or security reasons, there may exist intermediate servers. Without loss of generality,
we focus, in the sequel, on two-level KDCs, i.e. subscribers are connected to one server. Each subscriber shares a key with
the server. To enable establishing a secure session between two subscribers, a session key is generated by the server and
distributed to the subscribers. Therefore, the KDC is a solution to simplify the key management when the subscribers
cannot generate and distribute their public keys or when using a symmetric key for each pair of subscribers, which would
result in a huge number of symmetric keys. For example, the KDC-based approach would be appropriate in a virtual
private network or in an IoT network where the things cannot (because of their limited computation resources) make use
of public keys.
As illustrated in Figure 14.9, each subscriber Si shares two keys with the server [13]:
1) A key-wrapping key KWK i , which is used to wrap (i.e. protect) a session key generated by the server when the key is
transmitted to the subscriber s;
2) A data-authentication key DAK i, which is used by the server and the subscriber Si to send authenticated-messages and
to authenticate received messages.
In general, key-wrapping and data-authentication keys are configured manually on the server and the subscribers. Key-
wrapping keys are used by algorithms, such as AES key wrap, AES key wrap with padding, and Triple DEA key wrap (see
Section 9.2.7). Data-authentication keys are used by algorithms
such as CMAC and GMAC, which are discussed in Chapter 9.
There exist two approaches to select the authentication and
wrapping algorithms. In the first approach, the authentication
and wrapping algorithms are fixed on all the components of the
KDC (i.e. the server and subscribers) before requesting any
session key generation. In the second approach, the subscriber
that requests a new session key includes, in its request,
information to indicate which algorithms (out of those available)
to use and their parameters (e.g. the key bit-length and the hash
output bit-length). Then, the provided inputs are either accepted
or rejected by the KDC server or by the other subscriber(s). Notice
that the second approach is more flexible than the first one, but it
is more complex to implement. Without loss of generality, we
Figure 14.9 Relationships between the server of KDC and
its subscribers. assume in the sequel that the first approach is used.
14.3 Key-Establishment Schemes 485
Notes
– All subscribers must trust the KDC server. The latter must be protected against attacks. If the KDC server is compro-
mised, all messages can be easily discovered.
– The availability of the KDC server is an issue. If the KDC server becomes faulty or inaccessible to some subscribers,
some or all subscribers cannot establish session keys.
Session key establishment
When a subscriber Si needs to securely communicate with another subscriber S j , and it does not share a session key with
S j or needs to change the current session key shared with S j , the following operations are performed:
1) Subscriber Si sends an authenticated message M1 to request a session key. The message M1 includes, at least, the IDs of
subscribers Si and S j and a tag computed by the subscriber Si using the key DAK i, which it shared with the server.
2) The server receives the message M1 and authenticates it, using the key DAK i that it shares with subscriber Si . If the
authentication succeeds, the process continues; otherwise, no session key is delivered to subscriber Si , an error notifica-
tion is returned and the process is stopped.
3) The server makes use of derivation function to generate a new session key SK i, j.
4) The server makes use of a key-wrapping algorithm and the key-wrapping keys KWK i and KWK j to protect two copies
of the session key SK i, j. Depending on the implantation of the KDC, there are two options17 to continue the process.
5) Option 1 (illustrated in Figure 14.10a):
5.1 The server builds an authenticated message M 2 (using the key DAK i) that includes the session key SK i, j wrapped
with the key KWK i and an authenticated message M3 (using the key DAK j) that includes the session key SK i, j
wrapped with the key KWK j . Then, the message M 2 is sent to subscriber Si ; and the message M3 to subscriber S j .
( ( )) (
M 2 = A DAK i , W KWK i , SK i, j , M3 = A DAK j , W KWK j , SK i, j ( ))
where A and W are the agreed authentication and wrapping algorithms, respectively.
5.2 The subscriber Si (resp. S j ) receives the message M 2 (resp. M3) and authenticates the message using its key DAK i
(resp. DAK j). If the authentication fails, the subscriber Si (resp. S j ) returns an error notification and the process is
stopped. Otherwise, the subscriber Si (resp. S j ) extracts the wrapped session key from the message M 2 (resp. M3),
and makes use of the agreed key-wrapping algorithm to obtain the session key SK i, j. An authenticated acknowl-
edgment is sent by the subscriber Si (resp. S j ) to the server:
( (
SK i, j = W −1 KWK i , W KWK i , SK i, j ))
(resp. SK i, j =W −1
(KWK ,W (KWK , SK )))
j j i, j
5.3 Upon receipt of the acknowledgment from the subscriber S j , the server sends an authenticated acknowledgment
to the subscriber Si to confirm that the subscriber S j has received the session key.
5.4 When the subscriber Si receives the acknowledgment from the server, the key-establishment process successfully
terminates.
6) Option 2 (illustrated in Figure 14.10b):
6.1 The server builds an authenticated message M 2 (using the key DAK i) that includes two copies of the session key
SK i, j wrapped with the keys KWK i and KWK j . Then, the message M 2 is sent to the subscriber Si .
( ( ( )
M 2 = A DAK i , W KWK i , SK i, j W KWK j , SK i, j ( )))
6.2 The subscriber Si receives the message M 2 and authenticates the message using its key DAK i. If the authentication
fails, an error notification is returned and the process is stopped. Otherwise, the subscriber Si extracts the
( )
part W KWK i , SK i, j from the message; then, using its wrapping key KWK i , the subscriber Si unwraps the wrapped
session-key and obtains the session key SK i, j in cleartext. The subscriber Si sends an authenticated acknowledg-
( )
ment to the server. Then, subscriber Si extracts W KWK j , SK i, j from M 2 and sends it to subscriber S j .
6.3 Using its wrapping key KWK j , the subscriber S j unwraps the wrapped session-key and obtains the session key
SK i, j in cleartext. Then, it sends an acknowledgment to subscriber Si .
6.4 When the subscriber Si receives the acknowledgment from subscriber S j , the key-establishment process success-
fully terminates.
486 14 Key Management
(a) Session-key distribution to all parties (b) Session-key distribution to the applicant
Note. One of the most known and currently used KDCs is with no doubt Kerberos. The latter is presented in Section 15.4.
or key-transport transaction. The key-confirmation may be unilateral (i.e. only one party requires the verification of key-
pair possession) or bilateral (both parties require the verification key-pair possession). A bilateral key-confirmation is
composed of two instances of the unilateral key-confirmation; thus, both parties can detect an error in the key-agreement
process. Key-confirmation makes use of a MAC algorithm among the recommended algorithms (see Table 14.4).
function BitStrToInteger (S , z )
# Convert a bit-string S to integer z
function IntegerToByteStr (z , S )
# Convert an integer z to a bit-string S
function FieldElementToInteger (A, Z)
# Convert an element A of finite field to an integer z
function FieldElementToByteStr (A, S)
# Convert an element A of finite field to a byte-string S
Before starting the key-agreement, both parties must agree on the key-derivation function to use and its associated hash
function. In addition, if a confirmation is required, the parties must agree on a MAC algorithm and the parameters to use (i.e.
bit-lengths of the MAC key and MAC tag). The agreement on the MAC parameters to use is out of the scope of the KASs. Both
KASs make use of two operations, RSASVE_GENERATE (RSA Secret-Value Encapsulation) and RSASVE_RECOVER:
1) RSASVE_GENERATE ( N , e ): this operation enables one party to generate a shared secret Z , and to encrypt it with the
public key of the other party. The operation makes use of a DRBG to produce a random bit-string with the same bit-
length than that of the modulus N . The output of this operation is a pair ( Z , C ), a shared secret and its ciphertext.
2) RSASVE_RECOVER ( N , d): this operation enables the ciphertext recipient to decrypt the received message with its
private key in order to recover the shared secret Z .
The pseudocode of RSASVE_GENERATE and RSASVE_RECOVER operations is the following:
function RSASVE_GENERATE
input ( N , e ): public key
output Z , C : shared secret and its ciphertext
L = len( N ) / 8 # byte-length of the modulus
Z = DRBG ( L ) # generate L random bytes
z = BitStrToInteger ( Z )
if not (1 < z < ( N − 1)), then go to step 2
c = RSAEncrypt ( N , e, z )
C = IntegerToBitStr ( c )
return ( Z , C )
function RSASVE_RECOVER
input C ,( N , d ): ciphertext and private key
output Z : shared secret
L = len( N ) / 8 # byte-length of the modulus
c = BitStr To Integer ( Z )
z = RSADecrypt ( N , d , c )
Z = IntegerToBitStr ( z )
return Z
14.3 Key-Establishment Schemes 489
Party X Party Y
⇠
PrY = ( N , d), PuY = ( N , e )
Obtain PuY Distribute PuY
→
1. ( Z , C ) = RSASVE_GENERATE ( N , e ) 1.
2. Send C 2. Receive C
←
3. 3. Z = RSASVE_RECOVER (C, N , d)
4. Receive NonceY 4. Generate and send nonce NonceY
5. Generate keying material: 5. Generate a keying material:
KeyingMaterial = KDF ( Z , NonceY ) KeyingMaterial = KDF ( Z , NonceY )
6. Destroy Z 6. Destroy Z
Note. In Tables 14.12-14.28, some steps are included without any performed operation; they aim to provide symmetry in party’s
behavior.
490 14 Key Management
where IDX and IDY are the IDs of parties X and Y , respectively. MacKey is extracted from the output of the KDF. Part-
ner X does not need to send a tag, because it does not own a public key to verify.
7.2 The tag TY is exchanged between the parties.
7.3 Verification by party X : If TX ≠ TY , then a KAS error is raised. Otherwise, the key-confirmation succeeds.
7.4 Both parties destroy the key MacKey used to generate the tags.
14.3.3.2.1.2 Key-Agreement Scheme #2 (KAS2)
KAS2 makes use of two key-pairs; thus, both parties equally contribute to the shared secret construction, which is used to
generate a new key. KAS2 family consists of three variants: BasicKAS2 (without key-confirmation), Uni-Cnf-KAS2 (with
key-confirmation by one party), and Bil-Cnf-KAS2 (with bilateral key-confirmation). KAS2 variants are depicted in Figure
14.13. Basic-KAS2 steps are as follows:
1) Party X generates the first part of the shared secret, denoted Z X , and encrypts it using PuY ; the encrypted secret is
denoted C X ; i.e. ( Z X , C X ) = RSASVE_GENERATE ( N Y , eY ).
2) C X is exchanged between the parties.
3) Party Y recovers the first part of shared secret using the operation RSASVE_RECOVER and its private key ( N Y , d);
i.e. Z X = RSASVE_RECOVER(CY , N Y , dY ).
4) Party Y generates the second part of the shared secret, denoted ZY , and encrypts it using Pu X ; the encrypted secret is
denoted CY ; i.e. ( ZY , CY ) = RSASVE_GENERATE ( N X , e X ).
5) CY is exchanged between the parties.
6) Party X recovers the shared secret using the operation RSASVE_RECOVER and its private key ( N X , dX );
i.e. ZY = RSASVE_RECOVER(CY , N X , dX ).
7) Both parties form the shared secret Z , as Z = Z X || ZY .
8) Both parties use the shared secret Z and an agreed key-derivation function KDF (and may be other additional parame-
ters depending on the KDF) to derive a new key K. They derive a MAC key, if the key-confirmation is
required; KeyingMaterial = KDF ( Z , …).
9) The shared secrets Z , Z X , and ZY are destroyed.
Party X Party Y
→
shared secret: ( Z X , C X ) = RSASVE_GENERATE ( N Y , eY )
2. Send C X 2. Receive C X
3. 3. Z X = RSASVE_RECOVER (C X , N Y , dY )
4. 4. Generate the second part of the
←
shared secret: ( ZY , CY ) = RSASVE_GENERATE ( N X , e X )
5. Receive CY 5. Send CY
6. ZY = RSASVE_RECOVER (CY , N X , dX ) 6.
7. Shared secret Z = Z X || ZY 7. Shared secret Z = Z X || ZY
8. KeyingMaterial = KDF ( Z ,…) 8. KeyingMaterial = KDF ( Z ,…)
9. Destroy Z , Z X , ZY 9. Destroy Z , Z X , ZY
Unilateral or bilateral key-confirmation may be added
Unilateral or bilateral confirmation may be added to the basic KAS2 to build the Uni-Cnf-KAS2 and Bil-Cnf-KAS2
respectively. Bil-Cnf-KAS2 is the double instantiation of Uni-Cnf-KAS1 steps. The key-confirmation steps are depicted in
Figure 14.14.
Bilateral key-confirmation
Party X Party Y
Basic-KTS-OAEP
→
2. C = RSAOAEP Encrypt ( PuY , K , A) 2.
3. Send C 3. Receive C
4. 4. ( K , MacKey ) = RSAOAEP Decrypt (( N , d), C )
primitive FFC_DH
input p, g: two domain parameters (a prime p and a generator g)
x A: private key of the party running the primitive
y B : public key of the other party
14.3 Key-Establishment Schemes 493
primitive ECC_CDH
input G : base point
h: cofactor of base point G
x A: the private key of the party running the primitive
ΩB: the public key of the other party (EC point)
output Z: shared secret (byte-string)
1. ErrorIndication = False; Z = ""
2. P = (h * x A ). ΩB # Compute an EC point P (22)
3. if (P = O ), then ErrorIndication = True (23)
4. else { z = x_coordinate( P ); Z = IntegerToString( Z ); Destroy z}
5. return (ErrorIndication, Z )
primitive FFC_MQV
input
p, q, g: three domain parameters (two primes and a generator)
x A: static private key of the party running the primitive
y B : static public key of the other party
rA: ephemeral private key of the party running the primitive
t A: ephemeral public key of the party running the primitive
t B : ephemeral public key of the other party
output Z : shared secret (a byte-string)
1. ErrorIndication = False; Z = ""
1
2. w = log2 ( q )
2
w
3. A T = ( t A mod 2 ) + 2w
4. S A = ( rA + TA * x A ) mod q
5. TB = (t B mod 2w ) + 2w
( )
SA
T
6. z = t B * ( y B ) B mod p
7. if (( z ≤ 1) ∨ ( z = p − 1)), then ErrorIndication = True
8. else {Z=Integer(z); Destroy TA , TB , S A , and z}
9. return (ErrorIndication, Z )
primitive ECC_MQV
function V (R, f )
input R: EC point
output U : integer
1. x R = x_coordinate( R )
( )
f / 2 f / 2
2. U = FieldElementToInteger ( x R ) mod 2 + 2
3. return U
input
G : base point; h: cofactor of base point G
n : order of base point G
x As : static private key of the party running the primitive
494 14 Key Management
● Derivation of keying material, which includes a secret shared key and a MAC key (to generate tags used in key-confir-
mation step). This step is mandatory.
● Key-confirmation, which enables one party to provide to the other party assurance about its used public key.
14.3.3.3.3 Key-Confirmation
Key-confirmation may be included in most of the DLC-based key-agreement transactions to provide assurance that a party
possesses the static private key associated with the static public key used in the key-agreement process. Like RSA-based
KASs, DLC-based KASs can specify unilateral (when only a single static public key is used) or bilateral (if a pair of static
public keys are used) key-confirmation.
The parameters (MAC algorithm and MAC bit-length) and operations (generation and exchange of tags) used in key-
confirmation in DLC-based KASs are the same than those used in RSA-based KASs (Section 14.2.2.1). The only difference
is in the values used in tag generation. The MAC key (denoted MacKey) used to generate the tags is extracted from the
output of the KDF by both parties. There exist four key-confirmation schemes:
1) 2e-2s key-confirmation scheme is applicable when two ephemeral and two static public keys are used. Each of the
parties participates with an ephemeral key, denoted Ephem X or EphemY . The 2e-2s key-confirmation scheme is depicted
in Figure 14.18.
2) 1e-2s key-confirmation scheme is applicable when only one party, say X , makes use of an ephemeral public key and two
static public keys are used. Party Y participates in the key-confirmation by a nonce, instead of an ephemeral key. The
1e-2s key-confirmation is depicted in Figure 14.19.
3) 1e-1s key-confirmation scheme is applicable when the party X has an ephemeral public key and the party Y has a static
public key. No bilateral key-confirmation is provided, because there is a single static public key in this scheme. Party X
participates with a nonce. The 1e-1s key-confirmation is depicted in Figure 14.20.
4) 0e-2s key-confirmation scheme is applicable when no ephemeral public key is used and two static public keys are used.
The 0e-2s key-confirmation is depicted in Figure 14.21.
496 14 Key Management
→
TX = MAC ( MacKey, S X ,TagLen) TY = MAC ( MacKey, S X ,TagLen)
3. Send tag TX 3. Receive tag TX
4. 4. If (TX ≠ TY ), then return “Error”
5. Destroy MacKey 5. Destroy MacKey
←
2. Receive tag TY 2. Send tag TY
3. If TX ≠ TY , then return “Error” 3.
4. Destroy MacKey 4. Destroy MacKey
→
3. Send tag TX 3. Receive tag TX
←
4. Receive tag TY 4. Send tag TY
5. Compute tag TXY : 5. Compute tag TYX :
SY = " KC_2_Y " || IDY || IDX || SX = " KC_2_X" || IDX || IDY ||
NonceY || Nonce X Nonce X || NonceY
TXY = MAC ( MacKey, SY ,TagLen) TYX = MAC ( MacKey, SX ,TagLen)
6. If (TY ≠ TXY ) , then return “Error” 6. if (TX ≠ TYX ), then return “Error”
7. Destroy MacKey 7. Destroy MacKey
Each key-confirmation scheme may have three alternatives: unilateral key-confirmation provided by party X , unilateral
key-confirmation provided by party Y , or a bilateral key-confirmation.
Party X Party Y
←
2. Send ephemeral public key Pu eX 2. Receive Pu eX
3. Receive PuYe 3. Send ephemeral public key PuYe
4. Compute the shared secret: 4. Compute the shared secret:
Party X Party Y
⇠
Distribute static public key Pu X Obtain Pu X
Obtain PuY Distribute static public key PuY
1. Generate and send nonce Nonce X → 1. Receive Nonce X
2. Compute the shared secret: 2. Compute the shared secret:
( EI , Z ) = FFC_CDH ( PrX , PuY ) ( EI , Z ) = FFC_CDH ( PrY , PuX )
3. If (not ( EI )): 3. If (not ( EI )):
3.1 Derive the keying material: 3.1. Derive the keying material:
KeyingMaterial = KDF ( Z , Nonce X ) KeyingMaterial = KDF ( Z , Nonce X )
3.2. Destroy Z
3.2. Destroy Z
Party X Party Y
Party X Party Y
⇢
(PrX , ΩuX ) : ΩuX = PrX .G (PrY , ΩuY ) : ΩuY = PrY .G
⇠
Distribute static public key Ωu X Obtain Ωu X
Obtain ΩuY Distribute static public key ΩuY
1. Generate an ephemeral key-pair 1.
( PrXe , Ωu eX ): Ωu eX = PrXe .G
2. Send ephemeral public key Ωu eX → 2. Receive Ωu eX
3. Compute the first part of the shared secret: 3. Compute the first part of the shared secret:
( EI1 , Z1 ) = ECC_CDH ( PrX , ΩuY ) ( EI1 , Z1 ) = ECC_CDH ( PrY , ΩuX )
4. Compute the second part of the shared secret: 4. Compute the second part of the shared secret:
( EI2 , Z2 ) = ECC_CDH PrXe , ΩuY ( ) (
( EI2 , Z2 ) = ECC_CDH PrY , ΩueX )
5. If (not ( EI1 ) ∧ not ( EI2 )): 5. If (not ( EI1 ) ∧ not ( EI2 )):
5.1 Z = Z2 || Z1 5.1 Z = Z2 || Z1
5.2 Derive the keying material: 5.2 Derive the keying material:
KeyingMaterial = KDF ( Z ,…) KeyingMaterial = KDF ( Z ,…)
5.3. Destroy Z , Z1 , Z2 5.3. Destroy Z , Z1 , Z2
Party X Party Y
⇠
Distribute static public key Ωu X Obtain Ωu X
Obtain ΩuY Distribute static public key ΩuY
1. Generate an ephemeral key-pair 1.
→
( PrXe , Ωu eX ) : Ωu eX = PrXe .G
2. Send ephemeral public key Ωu eX 2. Receive Ωu eX
3. Compute the shared secret: 3. Compute the shared secret:
( EI , Z ) = ( EI , Z ) =
(
ECC_MQV PrX , ΩuY , PrXe , Ωu eX , ΩuY ) (
ECC_MQV PrY , Ωu X , PrY , ΩuY , Ωu Xe )
4. If (not ( EI )): 4. If (not ( EI )):
4.1. Derive the keying material: 4.1. Derive the keying material:
KeyingMaterial = KDF ( Z ,…) KeyingMaterial = KDF ( Z ,…)
4.2. Destroy Z 4.2. Destroy Z
Party X Party Y
⇠
Distribute static public key Pu X Obtain PuY
Obtain PuY Distribute static public key PuY
1. Generate an ephemeral key-pair 1. Generate an ephemeral key-pair
(PrXe , ΩueX ) : ΩueX = PrXe .G (PrYe , ΩuYe ) : ΩuYe = PrYe .G
→
←
2. Send ephemeral public key Ωu eX 2. Receive Ωu eX
3. Receive ΩuYe 3. Send ephemeral public key ΩuYe
4. Compute the first part of the shared secret: 4. Compute the first part of the shared secret:
( EI1 , Z1 ) = ECC_CDH ( PrX , uY ) ( EI1 , Z1 ) = ECC_CDH ( PrY , uX )
5. Compute the second part of the shared secret: 5. Compute the second part of the shared secret:
(
( EI2 , Z2 ) = ECC_CDH PrXe , uYe ) ( EI2 , Z2 ) = ECC_CDH (PrYe , ueX )
6. If (not ( EI1 ) ∧ not ( EI2 )): 6. If (not ( EI1 ) ∧ not ( EI2 )):
6.1 Z = Z2 || Z1 6.1. Z = Z2 || Z1
6.2 Derive the keying material: 6.2. Derive the keying material:
KeyingMaterial = KDF ( Z ,…) KeyingMaterial = KDF ( Z ,…)
6.3. Destroy Z , Z1 , Z2 6.3. Destroy Z , Z1 , Z2
Problem 14.1
Given two moduli N1 and N 2, it is easy to find their greatest common divider, GCD ( N1 , N 2 ) = p . Since any RSA modulus
is a product of only two primes, if the first prime is found, then it is very easy to find the second. Therefore, any observer
who has access to Bob’s public keys can easily disclose the private keys he is using.
Problem 14.2
1) The malicious member in the network knows that the modulus of any public key is in the interval 22047 , 22048 − 1 and
its public exponent is e = 3. Any key K, randomly selected by Alice, has a value less than 2256. Thus,
3 256 *3 2047 2048 3 3
K <2 <2 ≤ NB < 2 ⇒ K mod N B = K = C . Therefore, using C, the attacker can derive the secret key
1
shared by Alice and Bob, i.e. K = C 3 .
2) To make Alice’s protocol secure, one suggestion would be to generate a random integer n in the interval 1, 22048 − 1 .
Then, she computes and sends C = ne mod N B . Next, n is recovered by Bob. Then, Alice and Bob use the rightmost 256
bits of n as their AES-256 key.
504 14 Key Management
Problem 14.3
Let RSA modulus N be of large bit-length, say 2048. Imagine an attacker who assumes that one of the primes, p or q , say
p, is of a short bit-length, say m bits. Then, the attacker can test a maximum of 2m integers to factorize N ; and then discloses
the second prime and the private key. The attack succeeds using reasonable resources, if m is less than 80; even if the bit-
length of the modulus is very large, it does not prevent the recovery of the private key if one of the primes is small. When
the modulus N is of a bit-length of 2048 or even more (e.g. 3072 or 4096) and p and q primes are selected such that
len ( N )
−100
p−q > 2 2 ,
the bit-lengths of both primes is in magnitude of 1000 or even more, which makes the attack above
computationally infeasible.
Lenstra’s elliptic curve factorization method is the most efficient method to factorize large integers, when one of their
prime factors is small.
Problem 14.4
1) In the first solution, 1000 * 999 / 2 permanent keys are required.
In the second solution, 1000 authentication keys and 1000 wrapping keys are required; in total, 2000 permanent keys
are required. Wrapping keys are used to transport session keys. Since each host can exchange at most with two other
peers, a maximum of 1000 session keys may be used.
2) In the first solution, the number of keys (keys to configure, store, and communicate to all parties) is large. In addition,
if a key shared between two parties is compromised, all the plaintexts exchanged between the parties can be recovered
and a manual reconfiguration of the key is required to protect the future exchanges. In the second solution, there are
less keys to store, to change manually, and to secure. Session keys are generated on-demand and hosts can change them
to prevent attacks making exploitation of a huge plaintexts encrypted with the same key. If the ith session key is com-
promised, only the plaintexts encrypted with the ith session key can be recovered.
3) AES-CBC provides only confidentiality guarantees, while AES-GCM provides authenticity and confidentiality. In both
solutions, to prevent attacks that alter the ciphertexts, we recommend the use of AES-GCM. In general, when a KDC is
used, it is recommended that subscribers use session keys with authenticated-encryption algorithms to preserve confi-
dentiality and integrity.
Problem 14.5
1) The session-key request includes the IDs of the parties that need to obtain a session key and a tag computed with the
authentication key shared between the request-originator and the server. In addition, the session key is wrapped using
the wrapping-key of the request originator. Therefore, unless Eve knows the authentication and wrapping keys of Bob,
she cannot impersonate Bob to generate a session key, shared with Alice, with Bob being the originator of the request.
2) The KDC scheme is vulnerable to replay attacks as shown by the following example. Bob establishes a first session key
with Alice. To limit the amount of data encrypted with the same session key, Bob requests a new session key for each
data block to send to Alice. Eve intercepts the first authenticated message containing the first wrapped session-key.
Then, each time Bob requests a new session key, Eve intercepts the request and replies with the message that contains
the first session key. Notice that Eve cannot know the value of the session key, but she compels Alice and Bob to use the
same session key for a long time and maybe she can infer some information about the ciphertexts she intercepts. To
prevent replay attacks, one solution is to use a nonce in each key request; the same nonce is included in the message
returned by the server. Since both messages (i.e. the request and the response) are authenticated and they include a
nonce, the replay attack cannot succeed.
Problem 14.6
1) The key verification process run by Alice and Bob enables to confirm the key possession by both parties:
First verification operation: Alice sends C A = N A ⊕ K ; Bob sends C B = C A ⊕ K = N A ; Alice receives N A, which is the
random number she generated and concludes that Bob possesses the key K.
Second verification operation: Bob sends C B′ = N B ⊕ K ; Alice sends C ′A = C B′ ⊕ K = N B; Bob receives N B, which is the
random number he generated and concludes that Alice possesses the key K.
2) The protocol used by Alice and Bob is insecure when their exchanges can be intercepted. If Eve receives the messages
C A and C B , she derives the secret key by: C A ⊕ C B = N A ⊕ K ⊕ N A = K .
Problem 14.7
No security properties are guaranteed with the proposed actions, because of the man-in-the-middle-attack. An attacker who
can intercept the first message (which contains a public key) sent by Alice or Bob, can reply to the sender using his own
public key, which results in a shared key computed between a legitimate party and the attacker.
14.4 Problems and Solutions 505
Problem 14.8
In general, static public keys are distributed by a trusted third party or each static public key is included in the sender’s
digital certificate to prove that the name of the entity on the certificate owns the private key associated with the public key.
A key-agreement is a process to establish a secret key between two parties to exchange confidential data. If no static public
key is used, both parties cannot trust each other. Therefore, it is not recommended to use a key-agreement without static
public keys. Otherwise, any interested attacker can apply a man-in-the-middle attack and compromise the confidentiality
of transmitted data. For example, consider the following scenario:
Bob wants to establish a secret key with Alice. He generates an ephemeral key-pair and sends his ephemeral public key
to Alice. Eve intercepts the message sent by Bob and replies with her ephemeral public key. Then, Bob and Eve compute
a shared secret, which contains a secret key K. Next, Bob encrypts his messages using the key K, which is known to Eve.
Therefore, no transmitted data by Bob remains confidential to Eve.
Problem 14.9
Since the hash function H is not invertible, Eve cannot recover any session key before session m, whatever the key-deriva-
tion method from the three.
In Derivation 1, once the key of session m is recovered, Eve can derive the session keys of all the subsequent sessions,
(
because the hash function is public. The same applies to Derivation 2, because the SKm+1 = H SKm ⊕ (m + 1) mod 2 Hlen , )
where all elements (i.e. SKm , m, Hlen, and H) are known to Eve.
In Derivation 3, once the key of session m is recovered, Eve cannot derive the session keys of the subsequent sessions,
because the key SKm is XORed with Kmst before hashing. Therefore, Eve cannot recover SKm+1 only from SKm ; she needs
Kmst.
Problem 14.10
1) There are mainly two reasons, which are extensively discussed in literature. The first is that for the same security
strength, the asymmetric encryption is known to be very slow compared to symmetric encryption, in particular when
symmetric encryption is achieved by hardware. The second reason is that the symmetric encryption preserves the
length of the plaintext, while some asymmetric encryption algorithms, such as RSA-OAEP, need to extend the original
plaintext with padding bits to prevent some attacks, when the very short messages are encrypted (see Problem 12.5).
2) If only the recipient public key is available, the sender encrypts data using this public key and the recipient decrypts
using his/her private key. Alternatively, the sender can generate a symmetric key K, encrypts it with the recipient public
key, and sends it to the data recipient. Then, the sender encrypts the data using the symmetric key K, which is known
to the recipient.
Problem 14.11
When Alice and Bob use the Diffie-Hellman scheme with a modulus p of 1024, they establish a session key of a bit-length
of 1024, which is larger than the keys used by AES or DEA. Therefore, only a piece of the session key can be used to
encrypt with either AES or DEA. There exist many ways to derive a block cipher key from a session key. In practice, key-
derivation functions are used. Let us focus on the methods suggested in this problem.
1) Use of AES: it is admitted that brute-force attack against AES-128 is computationally infeasible using the current tech-
nologies. Since the session key K A, B is unknown to Eve, the three proposed methods provide the same security strength.
From the known plaintext, Eve cannot recover the AES key to disclose other plaintexts. Notice that the third method
makes use of a hash function, which does not increase the security strength.
2) Use of DEA: it is known that DEA key recovery using brute-force attack is computationally feasible, because 256 keys
can be tested with an acceptablecomputation time.
i) The first method enables to change the DEA key after 100 blocks, which seems introducing unpredictability in
DEA keys. When ciphertext, at the position of the known plaintext, is intercepted, Eve runs a brute-force attack
(i.e. she tests a maximum of 256 keys) to recover the DEA key used to encrypt the known plaintext. Since the
formula of DEA key updating is linear and known to Eve, she can recover the previous (by modular subtraction)
and the next (by modular addition) DEA keys. Therefore, she can disclose all the plaintexts. Therefore, this
method is insecure.
ii) When the second method is used, Eve can recover the key, which served to encrypt the plaintext she knew; let
this key be K p. Then, since the key of the ith group of 100 blocks is yielded from the previous key plus one, Eve
can disclose the keys before and after the key K p. The hash function does not help to secure the messages.
iii) When the third method is used, Eve can recover the key K p, which served to encrypt the plaintext she knew.
Then, she can decrypt a maximum of 100 consecutive plaintexts that have been encrypted using the key K p.
506 14 Key Management
However, even if the DEA-key updating formula is known to Eve, she cannot recover the other keys, because the
hash function is not invertible. From K p = H ( K A, B + p), Eve cannot derive K A, B + p in order to compute
K A, B + p −1 or K A, B + p + 1; and then disclose the keys after and before key K p. Therefore, the third method can
be considered as partially secure.
Problem 14.12
1) Computation of the secret pieces:
D1 = Q (1) mod 1999 = 1723 + 1500 * 1 + 1001 * 1 = 226
2) Take three pieces and their indices, say (731, 2), (1239, 3), and (265, 5). Build the following equation system:
731 = a0 + 2a1 + 4a2 mod 1999 (a)
Notes
1 Protection may be provided manually, in an automated fashion, or by some combination of manual and automated methods.
This book does not focus on manual protection of keys (including trusted courier, bags, safes, etc.).
2 DRBG stands for Deterministic Random Bit Generator. Chapter 16 addresses in detail the approved DRBGs.
3 The following formula is useful to compute S (n), the maximum security strength of RSA with a modulus of a bit-length of n:
2
S (n) = 1.923 * 3 n * ln(2) * 3 ln (n * ln(2)) − 4.69 / ln(2). S (n) is rounded to a standard value (i.e. 112, 128, 192, …).
4 Support services mainly include key-agreement, key-transport, and random number generation.
References 507
5 Sometimes, “key derivation method” and “key derivation function” are used interchangeably.
6 The security strength is the same whether the hash function is used in option 1 or in option 2. It also is the same when used
in the two-step key derivation method.
7 The Chinese Remainder Theorem (CRT) is presented in Section 3.3.4 and the RSA-CRT-based decryption is described in
Section 12.2.2.2. RSA implementations are faster when the CRT is used for decryption.
8 p is a safe prime if ( p−1) / 2 is also a prime.
9 Parameters a and b are used in traditional elliptic curves. Edwards and Montgomery curves make use of other parameters
(see Section 13.2.4).
10 Other names may be used in Internet RFCs, but the specification is the same.
11 P224, P-256, P-384, P-521, W-25519, and W-448 are names of Weierstrass (i.e. traditional) curves. Curve25519 and Curve448
are names of Montgomery curves. E488 is an Edwards curve.
12 The number of EC points that can be generated by the selected base point is the number of points ( x , y ) that match the EC
equation divided by the cofactor.
13 Curves E448 and Edwards-448 differ in the value of parameter d .
14 Since 2019, binary curves are deprecated, because of their limited adoption in industry [12, 15].
15 Some ECs have the same irreducible polynomial, but differ in other domain parameters.
16 “Manual key-transport” refers to a variety of methods to let the other party know the key, including face-to-face exchange,
suitcase, email, phone, etc. In general, all those methods are not recommended.
17 Option 1 results in more activities performed by the KDC server, while option 2 results in more activities by the subscriber
that originates a session-key transaction.
18 KMAC generates tags of variable bit-length. In practice, the bit-length should be close to either 128 or 256.
19 Notice that in KAS1, the party X generates the shared secret Z, while the party Y generates the nonce Nonce . Therefore,
Y
both parties do not equally contribute to the shared secret, which is used to generate a new secret key.
20 The output of the KDF is split into two parts: a shared key K and a MAC key MacKey (used to generate tags when required).
" , " means optional.
21 "…" means that other optional parameters may be used.
22 “*” denotes integer multiplication, while “⋅” denotes the multiplication of an EC point by a scalar.
23 O denotes the point to infinity.
24 Nonce X used in 0e-2s key-confirmation alternatives is the same as the one used in KDF.
References
1 Barker, E. (2020). Recommendation for Key Management: Part 1 - General - Special Publication 800-57 Part 1 (Rev. 5). NIST.
2 Barker, E., Roginsky, A., and Davis, R. (2020). Recommendation for Cryptographic Key Generation - Special Publication
800-133 (Rev. 2). NIST.
3 Turan, M.S., Barker, E., Burr, W. et al. (2010). Recommendation for Password-Based Key Derivation, Part 1: Storage
Applications, Special Publication, 800-132. NIST.
4 Barker, E., Chen, L., and Davis, R. (2020). Recommendation for Key-Derivation Methods in Key-Establishment Schemes - Special
Publication 800-56C. NIST.
5 Chen, L. (2009). Recommendation for Key Derivation Using Pseudorandom Functions, Special Publication 800-108. NIST.
6 NIST (2013). Digital Signature Standard (DSS) - FIPS PUB 186-4. National Institute of Standards and Technology.
7 Barker, E., Chen, L., Roginsky, A. et al. (2019). Recommendation for Pair-Wise Key Establishment Using Integer Factorization
Cryptography - Special Publication 800-56B (Rev. 2). NIST.
8 Barker, E. and Kelsey, J.J. (2015). Recommendation for Random Number Generation Using Deterministic Random Bit
Generators - Special Publication 800-90A (Rev. 1). NIST.
9 Kivinen, T. and Kojo, M. (2003). More Modular Exponential (MODP) Diffie-Hellman groups for Internet Key Exchange (IKE),
RFC 3526. Internet Engineering Task Force (IETF).
10 Gillmor, D. (2016). Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for Transport Layer Security (TLS), RFC
7919. Internet Engineering Task Force (IETF).
11 Shawe-Taylor, J. (1986). Generating Strong Primes. Electronic Letters 22 (16): 875–877.
508 14 Key Management
12 Chen, L., Moody, D., Regenscheid, A. et al. (2019). Recommendations for Discrete Logarithm-Based Cryptography: Elliptic
Curve Domain Parameters, (Draft) SP 800-186. NIST.
13 Barker, E. and Barker, W.C. (2018). Recommendation for Key Establishment Using Symmetric Block Ciphers - Special
Publication 800-71. NIST.
14 Barker, E., Chen, L., Roginsky, A. et al. (2018). Recommendation for Pair-Wise Key-Establishment Schemes Using Discrete
Logarithm Cryptography - Special Publication 800-56A (Rev. 3). NIST.
15 NIST (2019). Digital Signature Standard (DSS) - FIPS PUB 186-5 (Draft). National Institute of Standards and Technology.
509
15
There exist two approaches to establish trust between communicating entities: trust based on public keys and trust based
on symmetric keys. The first category is used to secure communications between clients and servers over Internet, while
the second is used in private networks where clients and servers share symmetric keys with a central entity, called Key
Distribution Center.
In the first category, to perform cryptographic operations (e.g. message decryption or signature verification), users of a
public key require confidence that the associated private key (used to encrypt or sign) is owned by the legitimate remote
entity (person, system, or organization). This confidence is obtained thanks to digital certificates, which are delivered by
trusted third parties, called Certificate authorities (CAs).
To better understand the notions relating to digital certificates in the computer-based society, let us take the following
example: imagine someone who wants to sell a painting to somebody, who can afford it. The seller claims that the painting
is made by a known painter and his/her signature is at the bottom of the painting. The painter’s signature is publicly known.
The painting is (very) expensive. The question is: will the buyer take the seller at his/her word? Of course not. He/she
requires a certificate (a document), which proves that the signature on the painting is that of the painter. The buyer will not
trust any certificate; rather, he/she asks the seller to provide a certificate signed by a known authority in the art field, and
whom the buyer trusts. Transactions in the digital world (in particular e-commerce transactions) require the same caution.
Public-key infrastructures are the frameworks, which provide certification management functions (creation, granting,
revocation, renew, cancellation, and storage of digital signatures). They are of paramount importance to establish trust
between partners that do not a priori trust each other in the open digital world. Today, digital certificates are used by bil-
lions of end-entities, including web servers and their clients, in many applications, such as calls and conferences via VPNs,
cloud servers, and Internet-of-things devices. The main protocol to secure communications over the internet is with no
doubt TLS (Transport Layer Security), which is the underlying security layer of the well-known HTTPS.
This chapter aims to discuss the notions of digital certificate, CA (certificate authority), PKI (public-key infrastructure),
and TLS.
A second alternative to establish trust among peers that have only symmetric keys is to use a key distribution center, like
Kerberos, to generate and distribute shared keys (called session keys) inside private networks. The last section of this
chapter aims at introducing the main notions and operations of Kerberos.
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
510 15 Digital Certificate, Public-Key Infrastructure, TLS, and Kerberos
The certificate authority is an organization, a company or a governmental agency that issues digital signatures to confirm
that the private keys associated with the public keys included in the certificates belong to the entities noted in the certifi-
cates. A CA issuing a certificate is trusted by all parties that use the public key included in the certificate. If an entity Y
trusts a CA, which delivered a certificate C X to entity X associated with public key Pu X , then the entity Y can verify that the
public key Pu X is owned by the entity X identified in the certificate C X .
– CRL distribution points (CDP): when a user, service, or computer presents a certificate, the verifying application or ser-
vice must determine whether the certificate has been revoked before its validity period has expired. The CDP extension
provides one or more URLs where the application or service can retrieve the certificate revocation list (CRL).
– A certification path, which includes the chain of certification (i.e. the CAs used to issue a certificate to the CA under
consideration). See Section 15.2.4.
● Issuer unique identifier: (optional and not recommended field) it enables the reuse of the issuer name over time.
● Subject unique identifier: (optional and not recommended field) it enables the reuse of the subject name over time.
● Signature of the CA: to sign a certificate, the CA computes the hash of the fields of the certificate and then encrypts it with
its private key. Thus, the authenticity of the certificate can be verified using the public key of the CA. Any entity, which
trusts a CA, knows the public key of that CA. Certificate verifier first decrypts the signature using the CA public-key, then
it hashes the fields of the certificate, using the same hash function than that used by the CA, and then compares the hashes.
Figure 15.2 illustrates one of the digital certificates issued to the domain www.google.com (in 2022). Google is its own
certificate authority.
A certificate has a validity period. Therefore, certificate-using clients can cache certificates, while being valid, and verify
them once, which limits unnecessary resource-consuming exchanges.
Public PKIs belong either to private companies or to governmental agencies/services. Examples of public CAs (operational
in 2022) include: Comodo, DigiCert, Geant Vereniging, GlobalSign, Verisign, and Google Trust Services. It is very likely that
if you check the list of certificates available in your computer (and used by the web browser or other networking-applica-
tions), at least one of the CAs above is present in your list.
Definition 15.6 Trust anchor: it is an authoritative entity for which trust is assumed. All certificates are delivered on behalf
of the trust anchor and the security provided by a PKI depends upon the authenticity and integrity of the trust anchor. Trust
anchor certificates are often distributed as self-signed certificates.
From a functional perspective, a PKI includes the following components (not all of them are mandatory):
● Certificate authority that stores, issues, and signs the digital certificates.
● Registration authority (RA): it operates on behalf of a CA. It receives and checks the validity of the information sub-
mitted by the end-entities, which need to register their public keys and obtain certificates.
● A repository: a system or a collection of distributed systems that stores certificates and CRLs (certificate revocation lists)
and serves as a means of distributing these certificates and CRLs to end-entities.
● Validation authority (VA): allows end-entities to check if a certificate has been revoked. VA has access to a certificate
revocation list to check certificate validity.
● A directory in secure location in which CA private-keys are stored.
● A certificate policy stating the PKI requirements concerning its procedures. Its purpose is to allow end-entities to analyze the
PKI trustworthiness. In general, only PKIs with a strong and verifiable certificate policy are recommended to end-entities.
Notes
– Depending on the number of PKI subscribers (i.e. the end-entities) and their particularities (geographic locations,
required level of security, frequency of certificate validation requests, etc.), a PKI may be composed of one CA or a set
of CAs (one of them is the root CA), one or a set of registration authorities, and one or a set of validation authorities.
– In this chapter, the PKI components are addressed from the functional point of view only. Depending on the number
of end-entities that use a PKI and their geographical locations and the applications they use, a single computer may
implement all the components or a computer is dedicated to each component or a distributed system is dedicated to
each component or to a group of components.
Definition 15.7 Root CA: it is the topmost CA (i.e. the trust anchor) of any certification hierarchy. A root CA is a CA that
issues the certificates that are used by its subordinate CAs to sign other certificates. Root CA certificates are self-signed certifi-
cates. For security reasons, the root CA is isolated from network access, and is often kept in an offline state.
Definition 15.8 Issuing CA: it is a CA that issues certificates to end-entities (i.e. owners of public keys).
Definition 15.9 Intermediate CA: it is any CA between the root CA and the issuing CAs.
A huge number of entities (individuals, systems, and organizations) around the world need certificates to be trusted by
their partners in a large variety of transactions (e.g. e-commerce, e-administration, etc.). A single CA used to issue and
verify certificates for all entities connected to internet is not appropriate for many reasons, including:
● Performance: a single CA would have to process millions of requests (verification of public keys, certification of new
public keys, etc.) per second, which would result in a worldwide bottleneck. Any transaction using a public key would
take a long time.
● Fault-tolerance: in the event the unique CA is down (or in maintenance), all the internet (and intranets) may be blocked.
● Security: a unique CA would be a perfect target for attackers to break its private keys or to block it, using DDoS attacks.
● Sovereignty: the country hosting the unique CA would prevent other countries or companies to perform transactions
requiring public keys.
Because of the reasons above, public-key certification, either inside a company or a country or worldwide, is based on hier-
archized structures. Well-designed CA structures have several benefits:
15.2 Public-Key Infrastructure 513
The certification hierarchy in Figure 15.3 is a 3-level hierarchy. The PKI can be used by a worldwide company where
one intermediate CA is assigned to region (Europe, America, Africa, and Asia) and an issuing CA is assigned to each
country.
7) The CA C generates a certificate, including the information confirmed by the RA R and the validity period. It signs the
certificate and records in its repository. Then, the certificate, generally complying with X.509 standard, is delivered to
user U.
8) User U receives the certificate and can use it to perform secured operations.
Definition 15.10 Chain of trust (or path of trust): it is the list of certificates used to authenticate an end- entity.
A chain (or path) of trust begins with the certificate of uppermost CA, i.e. the root CA, and finishes with the certificate of
an end-entity. Figure 15.5 illustrates an example of chain of trust composed of four certificates: the end-entity User1 has a
certificate signed by the CA CA2. The certificate of CA2 is signed by the CA CA1 and finally the certificate of CA1 is singed
by CA0 whose certificate is self-signed. Thus, the chain of trust is CA0 → CA1 → CA2 → User1.
Definition 15.11 Model of trust: it refers to the mechanism or method used to trust the signer of a certificate.
The question here is: how an entity that receives a certificate signed by a CA can trust the signing CA? To answer the
question, various models of trust have been proposed, each appropriate to a particular context of certificate use. The com-
monly used models include the following ones:
Single-CA model: in an organization or a company, a single CA is used and any certificate signed by the CA is trusted by all
end-entities. In the event the unique CA is corrupted, the security of exchanges in the entire organization/company is
compromised.
Hierarchical trust model: the end-entities trust delegated (i.e. intermediate) CAs that, in turn, trust an upper-level CA until
the root-CA. The whole security depends on the root-CA honesty.
Oligarchy-based trust model: multiple trust anchors are used and they sign each other (forming a mesh trust network).
To trust a certificate of an end-entity, the latter shall have a trust path, which terminates at more than one trust anchors.
Notes
– Whatever the context, the trust in certificates is only as good as the trust in the underlying trust anchors.
– Roaming users should be aware that they are implicitly trusting all software on the host systems that they use. In
particular, when they are traveling abroad, they should have concerns about trust-anchor certificates used by web
browsers, when they use systems in airports, hotels, conferences, etc.
available to interested users. Therefore, an entity, which needs to verify the public key validity, checks if the certificate
sent by a remote end-entity is in the most recent CRL known to him/her/it. Any CRL includes timestamps to indicate
when each certificate was invalidated by the CA. CRL timestamps should be used by end-entities to check if some trans-
actions performed before their invalidity timestamps are suspicious (e.g. detect transactions performed using stolen
private keys). Each revoked certificate remains recorded in the CRL until its expiration date, after which the certificate
is removed from the CRL.
SSL3 (Secure Socket Layer) was introduced by Netscape in 1991 to secure communications over Internet. When the SSL
protocol, which is proprietary to Netscape, was standardized by the IETF, it was renamed Transport Layer Security (TLS).
TLS is the most used protocol to secure communications between web servers and their clients. TLS is also widely used to
secure emails and file transfers. Common protocols such as HTTPS, SMTPS, and FTPS make use of TLS to secure commu-
nications. Since 2018, almost all websites make use of TLS, which provides authentication, confidentiality, and integrity to
communicating entities.
TLS 1.3 is the most recent version of the standard; it was finalized by IETF in 2018 [2]. TLS 1.0 and 1.1 were deprecated
in 2021 and they are no more supported by current systems. TLS 1.2 is still in use. Some reported vulnerabilities of TLS 1.2
were addressed in TLS 1.3 to enhance security. Compared to TLS 1.2, the TLS 1.3 introduced some enhancements including:
● Addition of encryption mechanisms when establishing a connection handshake between a client and server;
● The number of steps required to complete a handshake is reduced, which results in faster handshake process;
● Several cryptographic algorithms (e.g. 3DES and CBC) used to encrypt data were removed, as they were not recom-
mended for secure transport;
● Several hashing algorithms (e.g. RC4, MD5, and SHA-1) used to generate hashes were removed, as they were vulnerable
to some reported attacks.
● Authentication can make use of elliptic curve signatures (i.e. ECDSA and EdDSA) or symmetric pre-shared keys. DSA
was deprecated.
● All public-key-based key-exchange mechanisms used in TLS 1.3 provide forward secrecy.4
In the sequel, the main features and (sub)protocols of TLS 1.3 are introduced. As we only focus on TLS 1.3, TLS implicitly
refers to TLS 1.3.
● Early data indication extension: it allows the client to send application data encrypted with the pre-shared symmetric
key, without performing the authentication.
Figure 15.7 illustrates the steps of basic full handshake, where ESK () means encryption using the shared key.
Notes
– In Figure 15.7, gray boxes indicate that the authentication of the client is not mandatory. Indeed, many people access-
ing web servers do not have certificates; thus, they cannot be authenticated.
– A Hello message may be transmitted in a single record or split into two or many records.
15.3.2.1.2 Authentication
Authentication of the server is mandatory, while that of the client is optional (because not all clients own certificates).
● Authentication to the client: using the shared key included in the Key-share extension of the ServerHello, the server
sends two extensions: Certificate (that contains the encrypted server certificate) and CertificateVerify (that
is a signature over all the previous items of the handshake using the server private-key). CertificateVerify
extension is used to provide explicit proof that the sender possesses the private key corresponding to its certificate. If the
client validates the signature included in the CertificateVerify, then the server is trusted. Finally, an encrypted
extension Finished is sent.
● Authentication to the server: when the server needs to authenticate the client, it sends an encrypted CertificateRequest
extension. Then, as in the previous case, the client makes use of the shared key to send two encrypted extensions
Certificate (that includes the client certificate) and CertificateVerify. If the server validates signature
included in the CertificateVerify, then the client is trusted. Finally, an encrypted extension Finished is sent by
the client.
15.4 Kerberos
Kerberos7 is a network authentication protocol, developed at the MIT (Massachusetts Institute of Technology), which is
used to verify the identity of users or hosts, called clients, which need to connect to applications servers, which do not trust
each other. Application servers include Web, email, print, and file servers. The fundamental design approach of Kerberos
is to provide a secure system whose unique service is to authenticate users to multiple application/service servers. Therefore,
it frees applications and service servers from having to perform their own authentication. With Kerberos, passwords are no
more transmitted to authenticate a user.
Kerberos is supported in all major operating systems (i.e. Microsoft Windows, Apple Mac OS, and Linux) and plat-
forms (such as Oracle and Amazon Web services). The current version of Kerberos is the 5th version, published in RFC
4210 [3].
Kerberos is a kind of key-distribution center, which relies on symmetric keys. Kerberos is the most used KDC to authen-
ticate users to access resources in private networks. In theory, it can be adapted to operate with public keys. However, to
date there is no operational Kerberos implementation based on public keys.
This section aims at introducing the main principles and features of Kerberos. For specific details, refer to Kerberos RFCs
[3], and its updates.
Definition 15.12 Authentication: it is the process of verifying the identity claimed by a user, a device, or a system.
Definition 15.13 Session key: a temporary encryption key shared between two entities, with a lifetime limited to the duration
of a single login “session.”
Definition 15.14 Session sub-key: it is a temporary encryption key used by a client and a server, selected and exchanged using
the session key; its lifetime is limited to a single association (e.g. transfer of a file, messages downloading from a mail box, etc.).
Definition 15.15 Ticket: it is a record that enables a client authenticate itself to a server; it contains the client’s identity, a
session key, a timestamp, and other information, all encrypted using the private key of the server.
Kerberos protocol consists of several sub-protocols to provide two-step9 and three-step authentications, each with several
options, for intra-domain or inter-domain usages. In this chapter, we focus only on the most used sub-protocol, precisely
the three-step authentication in intra-domain, where a client logs into a local system and then accesses one or several appli-
cation servers in the same domain. As illustrated by Figure 15.9, the simplified description of Kerberos authentication
proceeds as follows.
Step 1: authentication to Kerberos server
● Authentication server request: at the initiation of a login session, the client, which wishes to access some servers, sends an
authentication request to Kerberos authentication server (KAS). The authentication server request includes the names
of the client and the ticket-granting server, all in cleartext, because no sensitive information is included.
● Authentication server response: upon receiving an authentication server request, the KAS verifies that the client name is
in the KDC database and retrieves its (private10) key. If the request-originator client is registered in the database, the KAS
generates a random session key, which will be shared between the client and the TGS. Then, the KAS builds a response
message composed of three parts: the client name and realm in cleartext, a ticket to the TGS, and a part (encrypted using
the client key) containing the session key along with other data. The ticket generated at this step is denoted TGT11
(Ticket-Granting Ticket) and is used in the next step to obtain tickets to access application servers. The TGT includes the
session key and other data; all encrypted using the TGS key. Only the request-originator client can recover the session
key included in the response message and only the TGS can check to which client the TGT is granted. When the client
receives the response, the initial authentication terminates; the client is logged into the local system. Notice that the
client key is used only at this initial authentication step, which provides a better protection to client keys.
sends a service ticket request to the TGS. In particular, the request includes the TGT received from the KAS and the
client name along with other data, encrypted using the session key.
● Service ticket response: upon receiving a service ticket request, the TGS verifies that the application server is in the KDC
database and retrieves its key. It also verifies that the client has received the session key. If the requested application
server is registered in the database and the client has been authenticated by the KAS, the TGS builds a service ticket,
which includes the session key extracted from the TGT along with the client name and other data. The service ticket is
encrypted with the application server key; thus, only the latter can check to which client the ticket is granted. The format
of the response message sent by the TGS to the client is almost identical to that of the response message sent by the KAS
to the client as above. The difference is that the TGS makes use of the session key (and not the client key) to encrypt the
second part of the response message.
Step 3: Mutual client/server authentication
● Application server request: upon receiving a service ticket, the client can authenticate to the application server whose
name is included in the service ticket. The client builds a message including the service ticket and an authenticator. The
latter contains the name and realm of the client along with other data, all encrypted with the session key. The authenti-
cator is used by the application server to verify that the client, which sent the request, possesses the session key included
in the service ticket (i.e. the client is the principal to whom the ticket was issued).
● Application server response: upon receiving an application service request, the application server verifies that the client
possesses the session key. Then, it builds a response message, which includes some values sent by the client, all
encrypted using the session key. Upon receiving the response message, the client decrypts the message using the session
key and compares the values included in the response to those in its request. If both values are identical, the client has
the proof that the application server is the one that holds the key registered in the KDC database; i.e. the mutual
authentication is confirmed.
Notations
Cname, Crealm: client name and realm.
Sname, Srealm: application server name and realm. When only a single domain is considered, Crealm and Srealm are
the same.
StartTime: time after which the granted authentication is valid.
EndTime: time after which the granted authentication is no more valid.
TimeStamp: time12 at which Kerberos issued the response.
CtimeStamp: time at which the client issued the request.
Nonce: random number, unique for each request.
Cipher : block cipher to be used.
E K ( P ) : encryption of P using the key of the client C.
C
E K ( P ) : encryption of P using the key of the application server S.
S
E K ( P ): encryption of P using the session key.
SK
E K ( P ): encryption of P using the TGS key.
TGS
2) Upon reception of a KRB_ AS_Req message, the KAS performs the following:
– Verify that the requesting client is in the database. If no, return an error.
– Verify that the nonce is distinct from those nonces included in requests previously received from the requesting
client. If no, return an error.
– From the database, retrieve the key of the requesting client; let KC denote the client key.
– Generate a random session key SK, which matches the key bit-length of the block cipher desired by the client.
– Build a message KRB_ AS_Rep composed of three parts: the first part is the name and the realm of the client (in cleartext),
the second part is a TGT (encrypted with the TGS key), and the third is an encryption of the parameters from the request.
15.4 Kerberos 525
Srealm, Sname,
where TGT =
E KTGS (Cname, Crealm, TimeStamp, StartTime, EndTime, …)
Note that the values of Nonce, StartTime, and EndTime are the same in both messages KRB_ AS_Req and KRB_ AS_Rep .
Srealm and Sname are those of the TGS.
– Send the message KRB_ AS_Rep to the client.
3) Upon receiving a message KRB_ AS_Rep , the client decrypts the encrypted part of the message using its key KC. If one
of the values of Nonce, StartTime, and EndTime is not identical to one included in the KRB_ AS_Req , an error in raised.
Otherwise, the client concludes that the sender of KRB_ AS_Rep knows its key. Then, the client saves the TGT and the
session key SK. The authentication of the client by the KAS is finished.
Note that the values of Nonce, Start Time, and EndTime are the same in both messages KRB_TGS_Req and
KRB_TGS _ Rep . Srealm and Sname are those of the application server requested by the client.
3) Upon receiving a message KRB_TGS_Rep, the client decrypts the encrypted part of the message using the session key.
If one of the values of Nonce, Start Time, and End Time is not identical to one included in the KRB_TGS_Req, an error
is raised. Otherwise, the client concludes that the sender of KRB_TGS_Rep is the TGS. Then, the client saves the appli-
cation server ticket AST.
2) Upon reception of a request KRB_ AP_Req, the application server performs the following actions:
– Decrypt the ticket AST using its key K S .
– From the ticket, get the session key and the name and realm of the sender.
– Decrypt the authenticator using the session key.
– If the data (i.e. client name and realm and other information) included in the authenticator is not identical to that
included in the ticket AST , an error is returned to the client. Otherwise, the application server successfully authenti-
cates the client.
– The application server builds a response message KRB_ AP_Rep, which includes the timestamp and sequence number
from the KRB_ AP_Req message, all encrypted using the session key:
KRB_ AP_Rep = EK (CtimeStamp, SeqNumber , …)
SK
3) Upon reception of a response message KRB_ AP_Rep, the client decrypts the message using the session key. If the
content of the message matches the data included in the request message KRB_ AP_Req, the mutual authentication suc-
cessfully terminates.
● Kerberos separates authentication from services. The application servers do not know, or ask for, the client passwords.
● A single client authentication to Kerberos server is enough to access all Kerberos-authenticated services. Therefore,
tication server.
● Kerberos concentrates the maintenance of secrets (i.e. stored keys) in a small number of places (that can be protected
part of Kerberos.
● Any denial-of-service attack against Kerberos results in a denial-of-service attack against all the principals using Kerberos.
● Kerberos generates and securely transmits the session key to the client and server. Once obtained, the session key must
be protected by the client and the server without actions from Kerberos. In particular, clients may be attacked to recover
the session key and then attackers disclose the private communications.
● Validity check of ticket period relies on synchronized clocks in the whole system. Clock synchronization is required, but
not provided by Kerberos. Any desynchronization (at some drift) may result in invalid tickets. Therefore, any partici-
pants (clients, application servers, and Kerberos) must use the appropriate time services (e.g. Network Time Protocol).
● As an authentication service, Kerberos provides a means of verifying the identity of principals on a network. Authentication
is usually useful primarily as a first step in the process of authorization, determining whether a client may use a service,
which objects the client is allowed to access, and the type of access allowed for each object. Kerberos does not, by itself,
provide authorization. Possession of an application server ticket provides only authentication of the client to that service,
and not how the client can use the resources of the application server (i.e. read, write, delete, … objects).
● Kerberos does not, by itself, provide integrity and confidentiality of data exchanged between a client and an application
server. Additional mechanisms (such as HMAC or authenticated-encryption algorithms) should be agreed between the
parties before sending data.
Security. Researchers have been investigating Kerberos since it was first published. Weaknesses have been discovered in
specific Kerberos implementations, as well as in the protocol itself. Those weaknesses have been addressed, and Kerberos
remains fundamental for authentication in the private networks. Kerberos has been widely implemented for decades, and
it is considered a mature and safe protocol for authenticating users. Kerberos uses strong cryptography, including secret-
key encryption, to protect sensitive data. Therefore, Kerberos protocol is currently considered secure.
15.5 Exercises and Problems 527
Exercise 15.1
Consider a PKI with a single CA, which acts as root-CA and issuing CA. It signs and sends three certificates to three col-
laborative users U1 , U 2, and U 3 . User U1 wants to send a signed document to user U 2. Then, user U 2 updates the document,
signs it, and then sends it to user U 3 . The hash function used by the collaborating users is known before the start of the
document update. Explain how the digital certificates are used to protect the integrity of the document.
Exercise 15.2
Is a registration authority an intermediate CA?
Exercise 15.3
1) Imagine that Eve knew Bob’s public key and certificate. Can she use the known information to exchange data with Alice
pretending to be Bob?
2) Can Eve change Bob’s certificate and include her public key in place of that of Bob, and then sends the certificate to
Alice?
Exercise 15.4
Alice and Bob obtained digital certificates from a CA. Then, they authenticated to each other and exchanged some data
encrypted with a session key established using the Diffie-Hellman protocol, and stopped their session. Eve intercepted all
the ciphertexts exchanged between Alice and Bob; and she recovered the private key used by the CA to generate Alice and
Bob’s certificates.
1) Can Eve disclose plaintexts exchanged between Alice and Bob in the closed session?
2) Can Eve disclose plaintexts to be exchanged in a future session?
Exercise 15.5
Users in domains D1 and D2 have CA C1 and CA C2 as trust anchors, respectively. Both domains are acquired by a company,
which owns a domain D3 and has CA C3 as trust anchor. What are the steps that the users in the three domains must follow
to communicate with each other?
Exercise 15.6
1) Can Kerberos protect against denial-of-service attacks?
2) Can Kerberos protect against replay attacks?
3) Can Kerberos guarantee the integrity of data exchanged between principals?
4) Can Kerberos protect application server resources against unauthorized accesses?
Problem 15.1
Some people may be attacked, because they consider that any website with HTTPS and a padlock icon belongs to an honest
entity. In addition, some people do not carefully read, letter by letter, the names of secured websites. Suggest a use case of
fraudulent website where an attacker owning an authentic digital certificate, delivered by a trusted authority, can obtain
confidential data from un-warned or naïve people.
Problem 15.2
Assume that the secret keys of Kerberos clients are derived from their passwords, which are entered securely in the data-
base, i.e. passwords cannot be intercepted during transfer. Show a scenario where an attacker can obtain tickets to access
application servers.
Problem 15.3
This problem aims to discuss a simple way to include public keys into Kerberos. Consider a modification of Kerberos,
which provides a two-step validation: the Kerberos authentication server delivers application-server tickets to clients.
Instead of using private keys stored on Kerberos database, each principal has a certificate delivered by an authority trusted
by Kerberos. The modified Kerberos frees principals from checking the validity of certificates. Suggest a public-key-based
protocol to deliver tickets and session keys. List some of the drawbacks of public-key-based Kerberos.
528 15 Digital Certificate, Public-Key Infrastructure, TLS, and Kerberos
Problem 15.1
We suggest the following scenario. An attacker legally obtains a certificate for a domain bnpparisbas.com, and mounts
a website identical to that of https//:bnpparibas.com, a French bank. Then, he sends messages using some emailing
list, asking customers of BNP Paribas to use an included link to do some operations on their accounts. People who have no
accounts at BNP Paribas ignore the message, but some of the BNP Paribas customers may click on the link provided in the
email and perform the requested operations. If they check the certificate, they can see the name of bnpparisbas.com
and they do not pay attention to the “s” after “pari”, which does not exist in the authentic domain name of BNP Paribas.
Therefore, a digital certificate plus a secured website do not necessarily mean an honest website.
Problem 15.2
It is known that Kerberos is vulnerable to attacks based on password guessing. If the passwords used by clients are weak,
attackers can disclose them, using dictionary attacks, derive their secret keys (because the derivation function of keys from
passwords is known), and then can authenticate to Kerberos and obtain application server tickets. Therefore, it is recom-
mended to use strong passwords and change them periodically.
Problem 15.3
The suggested protocol is as follows:
● The client obtains the certificate of the application server, then sends a ticket request including his/her certificate and
certificates).
● Modified Kerberos generates a random session key and a ticket (that includes the session key and client name) encrypted
with the public key of the application server. The session key is encrypted using the public key of the client. Then, a mes-
sage, including the encrypted session key and the ticket, is sent to the client.
● The client decrypts the first part of the message to recover the session key. Then, he/she prepares an authenticator
(which includes authentication-data, e.g. a timestamp and/or a name) encrypted using the session key. Then, he/she
sends a request to the application server. The request includes some of authentication data (in cleartext), the authenti-
cator, and the ticket.
● Upon reception of a client request, the application server decrypts the ticket using his/her private key and recovers the
session key. Then, he/she decrypts the authenticator to confirm that the sender knows the session key. Finally, a response
is sent to the client. The response includes some of the authentication data of the client encrypted with the session key.
● The client receives the server response and decrypts the message to confirm that the responding server holds the appro-
Notes
1 The issuer and subject names are commonly represented using an X.500 or Lightweight Directory Access Protocol (LDAP)
format.
2 It may take time before an invalid certificate is added to the CRL. The period of CRL updating may be an hour, a day, a week
…; it depends on each CA and the usages of the public-keys certified by that CA.
3 Since 2015, all SSL versions are deprecated. Today, when people use the term SSL, they talk about TLS. The reason of still
using SSL or SSL/TLS is that the term SSL persists in minds as it was a guarantee of security over Internet.
4 Forward secrecy is a feature of key agreement schemes, which provide the property that session keys are not compromised if
the private keys used in the key agreement become compromised.
5 AES-128-CCM and AES-128- CCM-8 are identical with an exception: AES-128- CCM-8 uses eight octets for authentication,
instead of the full 16 octets used by AES-128-CCM.
530 15 Digital Certificate, Public-Key Infrastructure, TLS, and Kerberos
6 The name of the hash function is not specified, because implicitly Edwards’s curve 25519 is used with SHA512 and the
curve with SHAKE256.
7 The name Kerberos was derived from the Greek mythology; it is a name of a three-head dog that protected the gates of hells.
8 The term realm is used to make the analogy between the protection of digital systems and that of the realms in the spirit of
the Greek mythology of the three-head dog.
9 In the two-step authentication, the client must authenticate to the Kerberos authentication server for each application
server to access.
10 It is a symmetric key; therefore, “private” is omitted in the sequel.
11 The TGT (also called initial ticket) generated by Kerberos is similar to the certificate issued by a certificate authority when a
public key is used. It is used to prove that the client holding the TGT was authenticated and it can share, with the applica-
tion server, the session key included in the TGT to encrypt and decrypt messages.
12 Kerberos makes use of absolute time. So, the clocks of the entities (Kerberos, clients, and application servers) must be
synchronized (with a bounded difference between clocks).
References
1 Cooper, D., Santesson, S., Farrell, S. et al. (2008). Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation
List (CRL) Profile - RFC 5280. Internet Engineering Task Force (IETF).
2 Rescorla, E. (2018). The Transport Layer Security (TLS) Protocol Version 1.3, RFC 8446. Internet Engineering Task Force
(IETF).
3 Neuman, C. (2005). The Kerberos Network Authentication Service (V5), RFC 4120. Internet Engineering Task Force (IETF).
531
16
As emphatically underlined in previous chapters, random numbers (RNs) and prime numbers (PNs) play a fundamental
role in cryptography. In particular, cryptographic keys and nonces used in some cryptographic algorithms shall appear as
entirely random bit-strings for observers (i.e. attackers).
In general, there exist two basic strategies for generating random numbers: non-deterministic and deterministic strat-
egies. In the first category, a physical process is used to generate bit sequences, while in the second category, an algorithm
is used. Non-deterministic RN generators produce true RNs, while deterministic RN generators produce pseudo RNs. The
second category of RN generators is the most dominant in computer-based systems and are built using deterministic
random bit generators (DRBGs). The latter are algorithms that output random bit-strings, which mainly depend on an
initial input called seed. Therefore, the outputs of DRBGs are pseudorandom bit-strings instead of true random ones. Even
if the algorithm of a DRBG is known, when the seed is picked from a (very) large set and kept secret, the DRBG output is
very likely to be unpredictable and looks like a random value.
Pseudorandom bit-strings are also called pseudorandom numbers and DRBGs are referred to as Pseudo Random Number
Generators (PRNGs). The first part of this chapter addresses basic and recommended algorithms to generate pseudo RNs.
The security of IFC (Integer Factorization Cryptography) and DLC (Discrete Logarithm Cryptography)-based algorithms
fundamentally relies on prime numbers. Unlike for PRNs, there does not exist algorithms that deterministically generate,
with certainty, large prime numbers. A practical alternative to true primes is to use integers that are not proven to be
composite. The second part of this chapter presents the recommended algorithms to support prime number generation
based on primality testing.
It is worth noticing that since the security of cryptographic algorithms depends on PRNGs, if a PRNG can be made pre-
dictable for attackers, it can be used as a backdoor to compromise confidentiality and integrity of protected data. The same
threat applies to the algorithms used to select prime numbers.
Definition 16.1 Ideal random bit-string: it is a bit-string in which each bit is unpredictable and unbiased, with a value that
is independent on the values of the other bits in the sequence.
Definition 16.2 Random number sequence: it is a random sequence of numbers, which has no order and does not follow
an intelligible pattern or combination. For external observers, a random sequence of numbers appears like a digitalization of
noise.
Definition 16.3 Random number generator: it is an algorithm (or a circuit) which outputs a sequence of statistically
independent and unbiased numbers.
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
532 16 Generation of Pseudorandom and Prime Numbers for Cryptographic Applications
Definition 16.4 Truly random number generator (TRNG): it is a process, which relies on physical observations (e.g. coin
flipping, lottery, thermal noise of an equipment, natural phenomena, etc.) to generate numbers.
Definition 16.5 Seed: it is the initial value provided to a random number (or bits) generator to output a sequence of pseudo-
random numbers (or bit-strings).
In practice, TRNGs are used only to generate seeds (i.e. initial inputs) for software pseudorandom number generators,
which are capable of generating RNs at high rates.
Definition 16.6 Pseudorandom number generator (PRNG): it is a deterministic algorithm which, given a truly random
number, called seed, outputs a sequence of numbers, which appear as being random.
Definition 16.7 Pseudorandom Bit Generator (PRBG) (also called Deterministic Random Bit Generator (DRBG)): it is
a deterministic1 algorithm which, given a truly random binary sequence of length k, called seed, outputs a binary sequence of
length L which appears to be random. The output of a PRBG is called a pseudorandom bit sequence.
A DRBG can be used to generate (uniformly distributed) random numbers. For example, a random integer in the interval
[0, n] can be obtained by generating a random bit sequence of length log2 (n) + 1, and converting it to an integer; if the
resulting integer exceeds n, one option is to discard it and generate a new random bit sequence. The other option is to pick
the modulo n of the DRBG output.
Definition 16.8 Period of a PRNG/PRBG: any PRNG/PRBG repeats a specific pattern of random numbers (or bits). The
period of a PRNG/PRBG measures the number of output numbers (or bits) after which the PRNG/PRBG begins to repeat itself.
16.1.2 Entropy
In cryptography, the unpredictability of secrets (such as cryptographic keys) is essential. If X is a random variable associ-
ated with a secret, then the probability that a secret value is guessed correctly is related to the entropy of the random vari-
able X . If a process used to generate secret items has a small entropy (i.e. it is so poor that it can only generate a small
number of different random numbers), the cryptographic items (such as session keys, nonces, and initialization vectors)
become predictable. Therefore, entropy is of paramount importance to design secrets. Basics of entropy are presented in
this section.
Definition 16.9 Entropy: it is the amount of information provided by an observation of a random variable. It reflects the
uncertainty associated with predicting the variable value. The larger the value of entropy, the greater the uncertainty in predict-
ing the value of an observation.
● Analogue noise source: an analogue signal is sampled and digitalized. Notice that without a genuine noise, adding other
deterministic components in the chain of random bit generation would not help in producing unpredictable numbers,
because the algorithms used in number generation are public, in general.
● Conditioning component: it is an optional deterministic function responsible for reducing bias and/or increasing the
entropy rate of the resulting output bits. In general, keyed-hash and encryption functions are used as conditioning
components.
● Health testing of a noise source aims to detect failures of the noise source (e.g. no change in the signal due to a hardware
failure) or to detect a deviation from the expected output during the correct operation of the noise source (e.g. no varia-
tion in a physical phenomenon as expected).
Noise sources can be divided into two categories: physical and digital noise sources. The following physical phenomena
may be used as physical noise sources:
● The sound from a microphone or a video input from a camera.
● The air turbulence within a sealed disk drive, which causes random fluctuations in read latency times of disk drive sector.
● The frequency instability of a free running oscillator.
● Elapsed time between emission of particles during radioactive decay.
● Thermal noise from a semiconductor diode or resistor.
The following may be used as digital noise sources:
● The system time measured at a fine granularity.
● The current value of a portion of the random access memory.
● The position of a PC mouse.
● A portion of a file (e.g. in Linux, the file /dev/random contains information collected from device drivers, which can
be used to generate random numbers).
Definition 16.10 Shannon’s entropy: it is a measure of the average uncertainty of a random variable X . Formally, the
Shannon’s entropy is defined as follows: let X be a random variable, which takes its values in a set S = { x1 , x 2 ,…, x N }, with
probability Pr ( X = x i ) = pi , i ∈ [1, N ], the entropy of the random variable X , denoted H ( X ), is defined by [1]:
N
H ( X ) = −∑ ( pi * log2 ( pi ))
i=1
It also is the minimum number of bits required on the average to describe a value x i of the random variable X .
Example 16.1
– Let X be a random variable that takes its values in the Latin alphabet. If all the letters are equiprobable, then
H ( X ) = log2 (26) = 4.70. Therefore, five bits are required to represent each value of the variable X .
– Let Y bet a random variable, which takes its values in a set of passwords. Assume that a password is composed of eight
equiprobable characters: five letters (upper or lower cases) || two decimal digits || one special character out of eight. There
exist 525 arrangements of 5 letters out of 52, 102 arrangements of two digits out of 10, and eight arrangements of one special
character out of eight. Therefore, the cardinality N of the distinct passwords is N = 525 * 102 * 8 = 3041 ≈ 63225600238.14.
Hence,
N
1 1
H ( X ) = −∑ log2 = log2 ( N ) = 38.14
i=1
N N
Definition 16.11 Joint entropy of two random variables X and Y : it measures the uncertainty of a joint event “X and Y .”
It is denoted H ( X , Y ) and defined by:
N M
(
H ( X , Y ) = −∑∑ pi, j * log2 ( pi, j ) )
i=1 j=1
( )
where pi, j = Pr X = x i , Y = y j and N and M are the numbers of values of X and Y , respectively.
Definition 16.12 Conditional entropy: it quantifies the amount of information needed to describe the outcome of a random
variable Y given the value of a random variable X is known. It is written as H (Y | X ) and defined by:
N M pi, j
H (Y | X ) = −∑∑pi, j * log2
i=1 j=1
pi
pi, j
where is the conditional probability. The conditional entropy of Y if X = x i is defined by:
pi
M
( (( )) ( ((
H (Y | X = x i ) = −∑ Pr Y = y j | X = x i * log2 Pr Y = y j | X = x i
j=1
))))
Properties of entropy
Let X and Y be two random variables, which take N and M distinct values, respectively. The following properties hold:
i. 0 ≤ H ( X ) ≤ log2 N , which means that there is an upper bound to the entropy.
ii. H ( X ) = 0, if and only if ∃ i ∈ [1, N ]| pi = 1. H ( X ) = 0 means that we are certain of the variable value that will be
observed.
1 n 1 1
iii. H ( X ) = − ∑ i=1 log2 = log2 N , if and only if pi = p j = , ∀i, ∀j ∈ [1, N ], which is the most uncertain situation
N N N
to predict the value of the random variable.
iv. Any change toward equalization of the probabilities p1 , p2 ,…, pN increases the entropy H ( X ). H ( X ) reaches it max-
imal value when all the probabilities are equal.
v. H (X , Y ) ≤ H ( X ) + H (Y ) . The uncertainty of a joint event is less than or equal to the sum of the individual uncertainties.
16.1 Introduction to Pseudorandom Number Generation 535
vi. H (Y | X ) = H ( X , Y ) − H ( X ) or alternatively, H ( X , Y ) = H ( X ) + H (Y | X ).
vii. H (Y | X ) = 0, if and only if the value of Y is completely determined by the value of X . H(Y | X ) = H (Y ), if and only if
Y and X are independent. Uncertainty of Y is never increased, if X is known.
Definition 16.13 Min-entropy of a random variable X that takes values from a set S = { x1 , x 2 ,…, x N }, with proba-
bility Pr ( X = x i ) = pi , i = 1, …, N , is denoted H _min ( X ) and defined by: H _min ( X ) = min i=1,…, N (−log2 pi ) = −log2
maxi=1,…, N pi .
The min-entropy is the negative logarithm of the probability that X is determined correctly with only one guess of the form
“is X equal to x i ?”
Properties of min-entropy
i. The maximum possible value for the min-entropy of a random variable with N distinct values is log2 N that is reached
when the random variable has a uniform probability distribution.
ii. If a random variable X has a min-entropy of h, then the probability of observing (or guessing) any particular value of X
is no greater than 2−h .
Definition 16.14 Hartley’s entropy: it is also called max-entropy; and it is a simple measurement that only relies on the
cardinality of the set of possible values of the variable. Let N denote the cardinality of the values of a variable X . The Hartley’s
entropy of X is defined by: HH ( X ) = log2 ( N ).
Hartley’s entropy assumes the distribution of values of the random variable is uniform. Therefore, the Shannon’s entropy is a
generalization of that of Hartley, because when all the values are identically distributed, i.e. pi = p j = N1 , ∀i ∈ [1, N ], ∀j ∈ [1, N ],
the Shannon’s entropy formula becomes:
N 1 1
1 1
H ( X ) = −∑ * log2 = −N * * log2 = log2 ( N )
N
N N N
i=1
Note. The most used model of entropy in cryptography is the min-entropy, which measures the lower bound on the
entropy. The min-entropy is never greater than the Shannon’s entropy, which measures the average unpredictability of
the outcomes.
( )
X i = Middle_digits_of X n2−1 , n , i > 0
where X 0 is a selected seed. If some X i has less than 2n digits, it is padded, on the left, with 0s to get a number with 2n digits.
The generated sequence of numbers in the interval [0, 10n − 1] appear as a sequence of random numbers.
Example 16.2
– Let X 0 = 89.
X 01 = 7921; hence, X 1 = 92. X 12 = 8464 ; hence, X 2 = 46.
X 22 = 2116; hence, X 3 = 11. X 32 = 0121; hence, X 4 = 12.
The sequence continues as follows: 14, 19, 36, 29, 84, 5, 2, 0, 0, 0, …0.
The PRNG stops producing distinct values when it reach X 12 = 0 .
536 16 Generation of Pseudorandom and Prime Numbers for Cryptographic Applications
● Let X 0 = 2916
X 02 = 29162 = 08503056; thus, X 1 = 5030.
X 12 = 50302 = 25300900; thus, X 2 = 3009.
X 22 = 30092 = 09054081; thus, X 3 = 0540 .
X 32 = 05402 = 00291600 ; thus, X 4 = 2916 = X 0 .
Therefore, the second PRNG has a period of 4, which is a very low value.
One of the most known and used LCGs was proposed by Park and Miller in 1988; it is referred to as MINSTD. The original
version of Park and Miller’s LCG was defined by a modulus m = 231 − 1 = 2147 483647 , a multiplier a = 75 = 16807 , and an
increment b = 0. Some implementations use a = 48, 271 or a = 69621. Park and Miller’s LCG has a (full) period of m −1. It
is worth noticing that the rand() function of ISO C standard is based on Park and Miller’s LCG.
Another known LCG is the one used by the drand48() function of Linux (complying with POSIX 1.-2001), where the
random number sequence is defined by: X i = (25214903917 * X i−1 + 11) mod 248. The values returned by drand48() are
nonnegative double-precision, floating-point values uniformly distributed over the interval 0, 1).
Example 16.3 Let LCG parameters be X 0 = 19, m = 101, a = 13, and b = 11. The numbers generated with the selected
parameters are:
19, 56, 32, 23, 7, 1, 24, 20, 69, 100, 99, 86, 18, 43, 65, 48, 29, 85, 5, 76, 90, 70, 12, 66, 61, 97, 60, 84, 93, 8, 14, 92, 96, 47, 16,
17, 30, 98, 73, 51, 68, 87, 31, 10, 40, 26, 46, 3, 50, 55, 19, 56, 32, 23, 7, 1, 24, 20, 69, 100, 99, 86, 18, 43, 65, 48, 29, 85, 5, 76, 90,
70, 12, 66, 61, 97, 60, 84, 93, 8, 14, 92, 96, 47, 16, 17, 30, 98, 73, 51, 68, 87, 31, 10, 40, 26, 46, 3, 50, 55.
First, notice that all the numbers appear in double. Therefore, they are uniformly distributed. Second, notice that when
the seed (i.e. 19) repeats, all the following numbers repeat. Therefore, the generated sequence has a cycle of 50 numbers;
and it should not be used when more than 50 random numbers are required.
Notes
– In general, LCGs have greater cycle periods than Middle-square algorithms, which makes them preferred PRNGs.
– The period of an LCG may be the same than that of its modulus.
– Because of their predictability, LCGs should not be used as building blocks of cryptosystems (see Problem 16.1).
Note. For interested readers, Park and Miller discussed some properties to design and implement good random number
generators [3].
Definition 16.15 Cryptographically secure PRNG (CSPRNG): it is a PRNG suitable to cryptographic applications and
services. Numbers generated by a CSPRNG shall be statistically indistinguishable from pure random numbers and unpredict-
able for an adversary that does not know the seed.
16.1 Introduction to Pseudorandom Number Generation 537
In other words, a pseudorandom number sequence is cryptographically secure, if it is difficult for an attacker, with limited
computational resources, to predict the next number(s) from the numbers already in his/her possession. A minimum secu-
rity requirement for PRNG is that the length k of the random seed should be sufficiently large, so that a search over 2k
elements (i.e. the entire seed space of possible seeds) is computationally infeasible, which prevents brute-force attacks.
When DRBGs recommended by the NIST are considered, the conditioning function may be one of the following:
● HMAC algorithm (see Section 5.3.2.1)
● AES-CMAC (see Section 9.2.2)
● AES-CBC-MAC3
● An approved hash function (see Table 16.1)
● Hash_DerivationFunction (see Section 16.2.2)
● BC_DerivationFunction (see Section 16.2.4)
Definition 16.16 Full entropy bit-string: it is a bit-string in which each bit is with a uniform distribution and independent
of every other bits of that bit-string. A bit-string of n bits is said to have full entropy, if the bit-string is estimated to contain at
least (1−)n bits of entropy, where ε is a very small value (e.g. ε ≤ 2−64 ), which represents the upper bound on bias.
In [6], it is considered that when a process (which may be a noise source, a noise source with conditioning function, or a
combination of multiple noise sources) has an input with an entropy of at least 2n, the process is sufficient to generate full
entropy bit-strings of n bits.
2) To include fresh signals from the current source of entropy or to add new sources of entropy to the system in order to
improve the randomness of the seed.
Reseeding is optional, but recommended, and it may be
● Explicitly requested by a consuming cryptographic application or service.
● Performed when prediction resistance is requested by a consuming application.
● Triggered when a predetermined number of pseudorandom outputs have been produced or a predetermined number of
generate requests have been made (i.e. at the end of the seed life).
● Triggered by external events (e.g. whenever a new entropy is available).
As discussed in the next section, the NIST recommends to reseed a DRBG after some amount of generated bit-strings (see
Tables 16.1 and 16.2).
function ModularConversion
input X : bit-string generated by a DRBG
n : n −1 represents the maximum value of valid result
ε: upper bound on bias (in general, ε ≤ 2−64 )
output Res: integer in range [1, n − 1]
1. L = len ( X ); N = 2L
2. if ( N < n ), then return “Invalid” (# the bit-length of the output of the
DRBG is not enough)
3. r = N mod ( n − 1) ; ρ = r / ( n − 1)
4. if ((2ρ (1 − ρ ) ( n − 1) > ε*N )), then return “Invalid”
5. z = BitStringToInteger ( X ) # Bit-string to integer conversion.
6. Res = ( z mod n − 1) + 1
7. return Res # Res is in range [1, n − 1]
function DiscardMethod
input X : bit-string generated by a DRBG
n : n −1 represents the maximum value of valid result; n ≥ 2
output Res: integer in range [1, n − 1]
1. L = len ( X ); N = 2L
2. if ((n ≥ N ) or (n < 2)), then return “Invalid”
3. z = BitStringToInteger ( X ) # Bit-string to integer conversion
4. if ( z > n −2) , then return “Invalid”
5. Res = z +1
6. return Res # Res is in the range [0, n − 1]
In [4], the NIST recommends three models of DRBGs: hash-function-based, HMAC-based, and block-cipher-based DRBGs.
The three models share common notions: inputs, internal state (i.e. variables that represent the current state of the DRBG),
and access interface functions.
Note. Using a random bit-string yielded by a concatenation of m outputs, each of L bits, of a DRBG with a maximum
strength level of 128 bits, will not result in a security strength of m * 128 bits, but of min (128, m * L) .
● If the lengths of some parameters do not comply with the limits (as specified in Tables 16.1 and 16.2), then return an
error.
● Get the entropy input from the entropy source. If the used source of entropy does not have the capacity to deliver outputs
with a bit-length that can provide the DRBG_instance_security_strength , then return an error.
● Use the Reseed function to compute the new internal state of the DRBG.
Notes
– SHA-1 is deprecated for its insecurity and not recommended in DRBGs.
– SHA3 is not recommended in [4]. However, it may be used to build (not NIST-approved) DRBGs.
A hash-based DRBG is characterized by its hash function. Its internal state consists of the common elements and two
specific variables:
● V : a variable of the same bit-length than that of the seed. It changes each time a new random bit-string is generated;
● C: a variable of the same bit-length than that of the seed. It changes only when the DRBG is instantiated or reseeded.
Hash-DRBG instantiation
function Hash_DRBG_Instantiate
parameters Hash, Hlen: hash function and its output bit-length
SeedLen: bit-length of the seed
input EntropyInput : bit-string generated by the entropy source
Nonce: nonce; PersonalizationString: optional bit-string
output (V , C , ResedCounter ): initial internal state of DRBG
1. Str _Instantiate = EntropyInput || Nonce || PersonalizationString
2. Seed = Hash_DerivationFunction ( Str _Instantiate, SeedLen )
3. V = Seed
4. C = Hash_DerivationFunction (( 0x00 || V ), SeedLen )
5. ReseedCounter = 1
6. return (V , C , ReseedCounter )
16.2 Pseudorandom Bit Generators Recommended for Cryptography 543
function Hash_DerivationFunction
parameters Hash, Hlen: hash function and its output bit-length
SeedLen: bit-length of the seed
input StrInput : bit-string to hash; ReqStrLen: requested bit-length
output ResStr : bit-string
1. Str = EmptyString(); m = ReqStrLen / Hlen ; count = 0x01
2. for j=1 to m do
Str = Str || Hash(count || ReqStrLen || StrInput)
count = count + 1
3. RndStrGen = leftmost ( Str , ReqStrLen )
4. return RndStrGen
Hash-DRBG reseeding
function Hash_DRBG_Reseed
parameters SeedLen: bit-length of the seed
input (V , C , ReseedCounter ): current internal state of DRBG
EntropyInput : bit-string generated by the entropy source
AdditionalInput: optional bit-string
output ( V , C , ReseedCounter ): new internal state of DRBG
1. Str _reseed = 0x01|| V || EntropyInput || AdditionalInput
2. Seed = Hash_DerivationFunction ( Str _reseed , SeedLen )
3. V = Seed ; C = Hash_DerivationFunction (( 0x00 || V ), SeedLen )
4. ReseedCounter = 1
5. return ( V , C , ReseedCounter )
function HashGen
parameters Hash, Hlen: hash function and its output bit-length
SeedLen: bit-length of the seed
input ReqStrLen: number of requested bits
V : variable in the internal state of DRBG
output RndStrGen: returned random bit-string
1. m = ReqStrLen / Hlen ; D = V ; W = emptyString()
2. for j=1 to m do
W = W || Hash (D); D = ( D + 1) mod 2SeedLen
3. RndStrGen = leftmost (W , ReqStrLen )
4. return RndStrGen
544 16 Generation of Pseudorandom and Prime Numbers for Cryptographic Applications
The overall structure of hash-based DRBGs is depicted in Figure 16.4; the pseudocodes of the DRBG functions are given below.
HMAC-DRBG instantiation
function HMAC_DRBG_Instantiate
parameters Hash, Hlen: hash function and its output bit-length
input EntropyInput : random bit-string from the entropy source
Nonce: a unique bit-string
PersonalizationString: optional bit-string
output (V , Key , ReseedCounter ): initial internal state of DRBG
1. Str _Instantiate = EntropyInput || Nonce || PersonalizationString
(Hlen)
2. Key = 0 # a bit-string of Hlen 0-bits
3. V = 0 x 01010…0101 # a bit-string of Hlen alternating 0-1 bits
4. ( Key ,V ) = HMAC _DRBG_Update ( Str _Instantiate, Key ,V )
5. ReseedCounter = 1
6. return ( V , Key , ReseedCounter )
function HMAC_DRBG_Update
parameters Hash, Hlen: hash function and its output bit-length
input ProvidedData: optional bit-string
Key : current value of the key used in HMAC algorithm
V : current value of variable V
output Key : new value of the key; V : new value of variable V
1. Key = HMAC ( Key ,(V || 0x00 || ProvidedData )); V = HMAC (Key , V )
2. if ( len( ProvidedData ) = 0 ), then return ( Key , V )
3. else
Key = HMAC ( Key , V || 0x01 || ( ProvidedData )); V = HMAC ( Key , V )
return ( Key , V )
HMAC-DRBG reseeding
function HMAC_DRBG_Reseed
parameters Hash, Hlen: hash function and its output bit-length
input ( V , Key , ReseedCounter ) : current internal state of DRBG
EntropyInput : random bit-string from the entropy source
AdditionalInput : optional bit-string
output ( V , key , ReseedCounter ) : new internal state of DRBG
1. Str _Reseed = EntropyInput || AdditionalInput
2. ( Key ,V ) = HMAC _DRBG_Update ( Str _Reseed , Key ,V )
3. ReseedCounter = 1
4. return ( V , Key , ReseedCounter )
546 16 Generation of Pseudorandom and Prime Numbers for Cryptographic Applications
CTR-DRBG instantiation
function CTR_DRBG_Instantiate
parameters DF _used: boolean, which indicates if a derivation
function is used in the implementation of DRBG
BC .Encrypt : encryption primitive of AES or TDEA
BlkLen: block bit-length of the used block cipher
KeyLen: key bit-length of the used block cipher
SeedLen: seed bit-length
input EntropyInput: random bit-string from the entropy source
Nonce: nonce (used only if DF _used is true)
PersonalizationString: optional bit-string
output (V , Key , ReseedCounter ): new internal state of DRBG
1. L = len (PersonalizationString )
2. if (DF _used ), then
Str_Instantiate = EntropyInput || Nonce || PersonalizationString
16.2 Pseudorandom Bit Generators Recommended for Cryptography 547
Str_Instantiate = BC_DerivFunction(Str_Instance,SeedLen)
else
PersonalizationString = PersonalizationString || 0((SeedLen-L))
Str _Instantiate = EntropyInput ⊕ PersonalizationString
(KeyLen)
3. Key = 0 # a bit-string of KeyLen 0-bits
(BlkLen)
4. V = 0 # a bit-string of BlkLen 0-bits
5. (Key ,V ) = CTR_DRBG_Update (Str _Instantiate, Key ,V )
6. ReseedCounter = 1
7. return (V , Key , ReseedCounter )
function CTR_DRBG_Update
parameters BC .Encrypt : encryption primitive of either TDEA or AES
BlkLen: block bit-length of the used block cipher
KeyLen : key bit-length of the used block cipher
CtrLen: a value between 4 and BlkLen, which specifies how the
input V is incremented (full or partial increment). See step 2.1.
SeedLen: seed bit-length
input ProvidedData: optional bit-string
Key : current value of the key used to encrypt
V : current value of variable V of DRBG
output Key: new value of the key
V : new value of variable V
548 16 Generation of Pseudorandom and Prime Numbers for Cryptographic Applications
CTR-DRBG reseeding
function CTR_DRBG_Reseed
parameters DF _used: boolean, which indicates if a derivation
function is used in the implementation of DRBG
SeedLen: seed bit-length
input (V , Key , ReseedCounter ): variable values of the current state
EntropyInput : random bit-string from the entropy source
AdditionalInput : optional bit-string
output (Key , V , ReseedCounter ): new internal state of DRBG
1. L = len ( AdditionalInput )
2. if (DF _used ), then
Str _Reseed = EntropyInput || AdditionalInput
Str _Reseed = BC _DerivFunction (Str _Reseed , SeedLen)
else
AdditionalInput = AdditionalInput || 0(SeedLen−L)
Str _Reseed = EntropyInput ⊕ AdditionalInput
3. (Key ,V ) = CTR_DRBG_Update (Str _Reseed , Key ,V )
4. ReseedCounter = 1
5. return (V , Key , ReseedCounter )
Public-key cryptographic algorithms (such as RSA, Diffie-Hellman, and MQV algorithms) require prime numbers to select
their domain parameters (i.e. public and private keys and other parameters). The first approach is to use true primes, also
called provable primes. As discussed in this section, generating provable primes may be very time consuming. The second
approach is to use numbers that are very likely to be primes; such numbers are referred to as probably-primes.
In the previous section, we discussed methods for generating large random numbers. Since there are no guarantees that
a random number is prime, we need to test if a randomly generated number is prime before using it. The problem of deter-
mining whether a given number is prime has become a challenge for centuries. With the event of computer-based systems,
the issue had become more challenging, because larger and larger prime numbers are required to strengthen the security
of infrastructures and services. This section aims at introducing some basics of prime numbers and the NIST-recommended
methods to generate primes for use in Diffie-Hellman, Menezes-Qu-Vanstone, and RSA algorithms.
550 16 Generation of Pseudorandom and Prime Numbers for Cryptographic Applications
Definition 16.17 Provable prime (or true prime): it is a prime that is confirmed using a deterministic algorithm.
Definition 16.18 Probably prime (or pseudoprime): a large odd integer p is said to be probably prime if there is a high
probability that it is prime. An integer p is probably prime if it has not been demonstrated to be either composite or prime.
Definition 16.19 Safe prime and Sophie Germain prime: a prime p is said to be safe prime, if there exists a prime q, called
Sophie Germain prime, such that p = 2q + 1.
Example 16.4
11 is a safe prime, because 11 = 2 * 5 + 1.
83 is a safe prime, because 83 = 2 * 41 + 1.
381 is a safe prime, because 381 = 2 * 191 + 1.
Definition 16.20 Mersenne prime: a prime p is said to be a Mersenne prime, if there exists a positive integer m, such that
p = 2m − 1.
Definition 16.21 Strong prime: it is an integer p satisfying the following conditions:
● p is chosen at random using a PRNG.
● p is a large prime.
● p −1 has a large prime factor p1 .
● p + 1 has a large prime factor p2.
● p1 − 1 has a prime factor p3 .
Example 16.5 Below are two strong primes (not usable in cryptography)
– 127 is a (non-cryptographic) strong prime, because
127 − 1 = 126 has a prime factor of 7.
127 + 1 = 128 has a prime factor of 2.
7 − 1 = 6; and 6 has a prime factor of 3.
– 331 is a (non-cryptographic) strong prime, because
331 − 1 = 330 has a prime factor of 11.
331 + 1 = 332 has a prime factor of 83.
11 − 1 = 10; and 10 has a prime factor of 5.
Currently, the method recommended to generate provable primes for FFC and IFC algorithms is based on Shawe-Taylor’s
algorithm, which generates strong primes (see Section 16.3.4).
1
Thus, for a large integer n, the probability that a random integer, not greater than n, is prime is approximately log(n ) ; and
the average gap between consecutive prime numbers out of the first n integers is approximately ln(n) .
16.3 Prime Number Generation 551
Example 16.6 Recall that for a prime p to be used to generate keys of RSA with a modulus of 2048 bits, it shall fulfill the
2048−1
condition 2 2
≤ p < 22048/2 . The number of primes that can be used for p is approximated, using the prime number the-
orem, by:
2048 2047 2048 2047
2048 2047
2 2 2 2 2 2 2 2
π 2 2 − π 2 2 = − = 2048 − 2047
204 8 2047 ln (2) ln (2)
2 * 2 *
ln 2 2 ln 2 2
2048 2047 2047
2 1
2 2
2027
1 2 2 2 2 = 2 2 0.597
= * 10 − ≅ *
10 2 − 1 *
ln (2) 2 1
210 − ln(2) * 2
2
16.3.2.1.1 Generating Primes Using Sieve-of-Eratosthenes Method and Trial Division Test
function Lucas-Lehmer_Primality_Test
input p = 2m − 1, number to be tested
output “Prime” or “Not prime”
1. s0 = 4
2. for i = 1 to m −2 do si = ( si2−1 − 2) mod p
3. if ( si = 0 ), then return “Prime”
4. else return “Not prime”
Example 16.7 Consider p = 27 − 1 and apply Lucas-Lehmer test to check if p is a prime. The generated sequence is: s0 = 4 ,
s1 = 14, s2 = 67 , s3 = 42 , s4 = 111, s5 = 0. Hence, 27 − 1 = 127 is a prime.
It is worth noticing that the NIST recommends the Pocklington-Lehmer primality test to generate provable primes.
Example 16.8 We make use of Pocklington-Lehmer theorem to check the primality of n = 547, which is known to be prime.
– Factor 547 − 1 as (2 * 3 * 13) * 7 ; i.e. F = (2 * 3 * 13) and R = 7. F and R fulfill the theorem requirements.
– Using a tool, which provides GCD and modular exponentiation functions, we try different integers a for p = 13, which is
a prime factor of F :
Start with a = 2:
(2 *3*7)*13 13
2546 ≡ (2) mod 547 ≡ (475) mod 547 = 1
546
GCD 2 13 − 1, 547 = 1
Conditions of the theorem are met. Therefore, we stop the search and confirm that 547 is a prime.
Theorem 16.4 enables to answer the question: Isn’t an integer x prime? The inverse statement of Theorem 16.4 is not
always true. That is, if a p−1 ≡ 1 mod p, for some a coprime to p, then p is not always prime, as shown by the following coun-
terexamples. When a p−1 ≡ 1 mod p, while composite, a is called a Fermat liar for p.
Example 16.9 210 ≡ 1 mod 341; hence, (210 )34 ≡ (1)34 mod 341 = 1, but 341 is not prime, as it is equal to 31 * 11. Therefore,
2 is a Fermat liar for 341.
580 ≡ 1 mod 561; thus, (580 )7 ≡ (1)7 mod 561 = 1, but 561 is not prime, as it is equal to 17 * 11 * 3. Therefore, 5 is a Fermat
liar for 561.
One of the seminal works on primality testing was proposed by Fermat. The latter came up with the following algorithm,
which is a direct application of Theorem 16.4:
Fermat’s primality test is not efficient to declare with a low probability that an integer n is prime. However, it was a starting
idea for many primality tests in literature. Since, by design, a random integer a is picked for testing, the algorithms that
improved Fermat’s test are probabilistic in nature. A number of iterations should be fixed in advance to stop the algorithm,
if the input p is not declared composite. That is why the result of the test is “Probably prime”. In the sequel, the focus is on
the most referenced and used primality test, the one proposed by Miller and Rabin [8, 9].
Definition 16.22 Carmichael number: an integer n is said to be Carmichael number if there exists an integer a coprime to
n such that an−1 ≡ 1mod n .
Property of Carmichael numbers: any Carmichael number n is composite and will pass Fermat’s primality test, for any
number a coprime to n.
As numbers become very large, Carmichael numbers become very rare. For example, it is shown in [10] that there exist
approximately 20 million Carmichael numbers between 1 and 1021. Hence, the probability to pick a Carmichael number,
21
from the interval [1, 10 ], is very low (i.e. approximately 5 * 10−13). Therefore, for randomly chosen odd integer n with hun-
dreds of digits, the probability for n to be a Carmichael number is zero for practical purpose. Such a property limits the
number of false positives yielded by Fermat’s primality test.
(n−1)/2
Lemma 16.17 If a ≡ ± 1 mod n, with n coprime to a, then n must be composite.
554 16 Generation of Pseudorandom and Prime Numbers for Cryptographic Applications
function Miller_Rabin_Primality_Test
input p: integer to be tested; p > 1
Nb_iterations : maximum number of iterations to perform
output Decision: “Probably prime” or “Composite”
a
1. Find a, the largest integer such that 2 dividesp − 1
p−1
2. m = a ; L = len ( p )
2
3. for i = 1 to Nb_iterations do
3.1 Using a random number generator, obtain a random
integer b with a bit-length of L
3.2 if (( b ≤ 1)or( b ≥ p − 1)), then go to step 4.1
3.3 V = bm mod p
3.4 if ((V = 1)or(V = p − 1)), then go to step 4.7
3.5 for j = 1 to a −1 do
V = V 2 mod p
if ( V = p −1), then go to step 4.7
if ( V = 1), then return (“Composite”)
continue
3.6 return (“Composite”)
3.7 continue
4. return (“Probably prime”)
function Generate_Probably_Prime_Pair_FFC
parameters Hash, Hlen: hash function and its output bit-length
input Lenp , Lenq : requested bit-lengths of primes p and q, respectively
SeedLen: seed bit-length, where SeedLen ≥ Lenq
output p, q: generated probably-primes
Seed: seed computed when generating the primes (optional)
Ctr: counter computed when generating the primes
Lenp
1. n = − 1; b = Len − 1 − ( n Hlen )
p *
Hlen
2. Seed = DRBG .generate ( SeedLen ); U = Hash ( Seed ) mod 2Lenq −1
Lenq −1
3. q = 2 + U + 1 − (U mod 2)
4. if ( Miller _Rabin_Primality _Test ( q ) = " Probably prime "),
then go to step 3
5. Offset = 1
6. for Counter = 0 to ( 4 * Lenp − 1) do
6.1 for j = 0 to n do V j = ( Hash ( Seed + Offset + j ) mod 2SeedLen )
6.2 W = (∑ n−1
j =0
(Vj * 2 j * Hlen
)) + ((V
n mod 2b ) * 2n *Hlen )
Lenp −1
6.3 X = W + 2 ; c = X mod 2 * q
6.4 p = X − ( c − 1) # p ≡ 1 mod 2 * q, which is required for FFC
domain parameters
Len −1
6.5 if ( p < 2 p ) go to step 8.8
6.6 if ( Miller _Rabin_Primality _Test ( q ) = " Probablyprime "),
then go to step 10
6.7 Offset = Offset + n + 1
7. go to step 3
8. return ( p, q, Seed , Counter )
Notice that the function above stops only when a probably-prime pair is found, while the other functions presented in the
sequel have a limit in the number of tries and may fail in producing valid outputs [11] does not provide evidence that the
algorithm terminates within a reasonable time.
function Generate_Probably_Prime_Pair_RSA
input ModLen: bit-length of the modulus p * q; e: public exponent
output status: “Success” or “Failure”; p, q: generated probably-primes
1. # Generate p
1.1 i = 0; p = DRBG .generate ( 2 )
ModLen
1.3 if p < 2(
( ModLen−1) / 2
) then go to step 1.2
1.4 if (GCD ( p − 1, e ) = 1), then
if ( Miller _Rabin_Primality _Test ( q ) = " Probably prime "),
then go to step 2
1.5 i = i + 1
1.6 if (i ≥ 5 * Modlen / 2), then return (" Failure ", 0, 0)
else go to step 1.2
2. # Generate q
2.1 i = 0; q = DRG .generate ( ModLen2 )
( )
2.2 if Not (Odd (q )) , then q = q + 1
Note. The algorithm above may fail in finding a pair of probably primes.
which is less than 33, and it returns a prime (if any), denoted c0.Then, an integer 2 * t * c0 + 1 is generated. The value of t is
chosen such that c is guaranteed to be less than 2 ReqLen . Finally, the primality of c is tested using Pocklington-Lehmer pri-
mality test and an output is returned.
● Third case: 63 ≤ ReqLen:
The first call generates a prime c1 = 2 * t1 * c2 + 1, of a bit-length of ReqLen. The second call generates a prime
c2 = 2 * t2 * c3 + 1, of a bit-length of ReqLen / 2 + 1.
ReqLen ReqLen
The third call generates a prime c3 = 2 * t3 * c4 + 1, of a bit-length of 2
+1
. If 2 is less than 32, then c4
+1
+ 1
2 2
is the first fully-generated prime. Otherwise, the division process of the initial requested bit-length, ReqLen, continues.
function Shawe_Taylor_Provable_Prime
parameters Hash, Hlen: hash function and its output bit-length
input ReqLen: requested bit-length of the prime to be generated
InputSeed: seed
output status: “Success” or “Failure”; p: generated provable-prime
pSeed : a seed computed during prime generation
pGenCtr : counter incremented during prime generation
1. if (ReqLen ≥ 33), then go to step 11
# Case where the generated prime can be tested using
# Trial-Division test
2. pSeed = InputSeed; pGenCtr = 0
3. c = Hash ( pSeed ) ⊕ Hash ( pSeed + 1)
4. c = 2
ReqLen−1
+ (c mod 2ReqLen−1 )
5. c = (2 * c / 2 ) + 1 # c is guaranteed to be of bit-length of ReqLen
6. pGenCtr = pGenCtr + 1
7. pSeed = pSeed + 2
8. if (Trial_Division_Primality _Test (c ) = Prime ), then return
(" Success ", c , pSeed , pGenCtr )
9. if ( pGenCtr > 4 * ReqLen), then return (" Failure ", 0, 0, 0)
10. go to step 3
# Case where a long bit-length prime is required.
11. ( status, c0 , pSeed , pGenCtr ) =
Shawe_Taylor _Provable_Prime ( ReqLen / 2 + 1, InputSeed )
12. if ( status = " Failure "), then return (" Failure ", 0, 0, 0)
13. Nb_iterations = ReqLen / Hlen −1
14. OldCtr = pGenCtr
15. # Generate an integer c in range 2 , 2ReqLen − 1 and
ReqLen−1
test its primality using a random integer a in range 2,c − 2
15.1.1 x = 0
15.1.2 for i = 0 to Nb_iterations do
558 16 Generation of Pseudorandom and Prime Numbers for Cryptographic Applications
15.2.4 c = 2 * t * c0 + 1
15.2.5 pGenCtr = pGenCtr + 1
# Choose an integer a in 2,c − 2
15.3.1 a = 0
15.3.2 for i = 0 to Nbiterations do
a = a + ( Hash ( pSeed + i ) * 2i * Hlen )
15.3.3 a = 2 + (a mod ( c − 3))
15.3.4 pSeed = pseed + Nb_iterations + 1
# Use of Pocklington-Lehmer primality test to check if c is prime
2t
15.4.1 z = a * mod c
15.4.2. if ((GCD ( z − 1, c ) = 1) and (1 = z o mod c )), then
c
function Generate_Provable_Prime_Pair_FFC
parameters Hash, Hlen: hash function and its output bit-length
input Lenp , Lenq : requested bit-length of primes p and q , respectively
SeedLen: seed bit-length used to generate pseudorandom
numbers, where SeedLen ≥ Lenq
output status: “Success” or “Failure”; p, q: generated provable primes
pSeed , qSeed , pGenCtr , qGenCtr : optional outputs, which can
serve as random numbers for other FFC domain parameters
# Phase 1: first seed generation
Len −1
1. # Generate a first seed generation with a value ≥ 2 q
1.1 FirstSeed = 0
(
1.2 while FirstSeed < 2Lenq −1 do )
FirstSeed = DRBG .generate (SeedLen)
# Phase 2: generation of two primes q and p0
2. # Use Shawe-Taylor algorithm to obtain a prime q and two numbers
2.1 ( status, q, qSeed , qGenCtr ) =
16.3 Prime Number Generation 559
)
3.2 if ( status = " Failure "), then return “Failure”
# Phase 3: using p0 and q, generate a prime p that fulfills FFC
requirements
4. Nbiterations = Hlenp −1
Len
5. OldCtr = pGenCtr
6. # Generate a pseudorandom number x in range 2Lenp −1 , 2Lenp
6.1 x = 0
6.2 for i = 0 to Nb_iterations do
x = x + (Hash ( pSeed + i ) * 2 * )
i Hlen
Len −1 Len −1
6.3 x = 2 p + ( x mod 2 p )
7. # Generate a candidate prime p in range 2Lenp −1 , 2Lenp
7.1 pSeed = pSeed + Nb_iterations + 1
7.2 t = x / (2 * q * p0 )
( Len
)
7.3 if (2 * t * q * p0 + 1) > 2 p , then t = 2 p / (2 * q * p0 )
Len −1
7.4 p = 2 * t * q * p0 + 1
7.5 pGenCtr = pGenCtr + 1
8. # Choose an integer a in 2, p − 2
8.1 a = 0
8.2 for i = 0 to Nb_iterations : a = a + (Hash ( pSeed + i ) * 2i *Hlen )
8.3 a = 2 + (a mod ( p − 3))
9. pSeed = pSeed + Nb_iterations + 1
10. # Use random integer a and Pocklington-Lehmer primality test
to check if p is prime
10.1 z = a2*t * q mod p
( )
10.2. if (GCD ( z − 1, p) = 1) and (1 = z p0 mod p) , then
return (" Success ", p, q, pSeed , qSeed , pGenCtr , qGenCtr )
( )
11. if pGenCtr > (4 * Lenp + OldCtr ) , then return (" Failure ", 0, 0)
12. t = t +1
13. go to step 7.3
Note. The algorithm above may fail to find two primes that fulfill the FFC domain parameter requirements.
function Generate_Provable_Prime_Pair_RSA
input nLen: intended bit-length of the modulus n = p * q
e: public exponent
output status: “Success” or “Failure”; p, q: generated provable primes
# Phase 1: seed generation
1.1 SecurityStrength = security strength associated to a modulus
of nLen bits
1.2 Seed = DRBG .generate (2 * SecurityStrength )
560 16 Generation of Pseudorandom and Prime Numbers for Cryptographic Applications
function Generate_Provable_RSA_Prime
# Note. The pseudocode below is a simplification of a more general
function specified in reference [11] to generate strong primes
parameters Hash, Hlen: hash function and its output bit-length
input pLen: intended bit-length of the RSA prime to be generated
InputSeed: a seed value
e: public exponent
output status: “Success” or “Failure”; p: generated provable-prime
pSeed : seed computed during provable-prime generation; it
will be used as input to generate the second RSA-prime
# Phase 1: Generate a prime p0 of bit-length of pLen / 2 + 1
1. ( status, p0 , pSeed , pGenCtr ) =
Shawe_Taylor _Provable_Prime pLen
2 (
+ 1, inputSeed )
2. if ( status = " Failure "), then return (" Failure ", 0, 0 )
# Phase 2: generate a strong prime p of a bit-length of pLen
3. Nb_iterations = pLen / Hlen −1
4. pGenCtr = 0
pLen−1
5. # Generate a random integer x in range [ 2 * 2 , 2pLen − 1]
5.1 x = 0
5.2 for i = 0 to Nb_iterations do x = x + ( Hash ( pSeed + i ) * 2i *Hlen )
( (
5.3 x = 2 * 2pLen−1 + x mod 2pLen − 2 * 2pLen−1
))
6. pSeed = pSeed + Nb_iterations + 1
7. t = (2 * p0 + x ) / (2 * p0 )
8. if ((2 * (t − 1) * p0 + 1) > 2pLen ), then
( )
t = (2 ∗ p0 ) + 2 ∗ 2pLen−1 / (2 ∗ p0 )
9. p = 2 * (t − 1) * p0 + 1
10. pGenCtr = pGenCtr + 1
# By definition of an RSA-prime p, GCD ( p − 1, e ) = 1
11. if (GCD ( p − 1, e ) = 1), then
# Choose an integer a in [2, p − 2] and test primality of p
16.4 Exercises and Problems 561
11.1 a = 0
11.2 for i = 0 to Nb _ iterations do
a = a + ( Hash ( pSeed + i ) * 2i * Hlen )
11.3 a = 2 + ( a mod ( p − 3))
11.4 pSeed = pSeed + Nb_iterations + 1
# Test the primality of p using the Pocklington-Lehmer test
11.5 z = a2*( t −1 ) mod p
11.6 if, ((GCD ( Z − 1, p ) = 1) and (1 = z p0 mod p )), then
return (" Success ", p, pSeed )
12. if ( pGenCtr > (5 * pLen )), then return (" Failure ", 0, 0 )
13. t = t +1
14. go to step 8
Note. The algorithm above may fail to find a prime that fulfills the RSA domain parameter requirements.
Exercise 16.1
Let X be a one-character random variable that takes its values in a set composed of 26 uppercase Latin letters, 10 decimal
digits, and 8 special characters. Let prc , prv , prd, and prs denote the probability of selection of a consonant, a vowel, a digit,
and a special character, respectively.
What is the entropy of random variable X assuming that Prc = 2 Prv = 4 Prd = 10 Prs ?
Exercise 16.2
Consider a function F that generates an output of one decimal digit and the observed sequence is {1, 2, 7, 0, 4, 6, 3, 5, 9, 8},
which repeats indefinitely. Can F satisfy the properties of a cryptographically-secure PRNG?
Exercise 16.3
This exercise aims to highlight the sensitivity of LCGs in terms of the period of the longest generated number sequence,
when selecting its seed.
1) Consider an LCG with parameters m = 256, a = 25, and b = 16.
What is the period of the LCG as defined above when the seed is selected as follows: X 0 = 255, X 0 = 2, X 0 = 6 ,
X 0 = 10, X 0 = 0?
2) Consider an LCG with parameters m = 255, a = 25, and b = 16. What do you observe if X 0 = 0 or if X 0 = 4?
Exercise 16.4
Make use of Miller-Rabin test for primality to check the primality under the following scenarios:
1) n = 19 assuming the picked random values are {3, 7, 17}
2) n = 113 assuming the picked random values are {107, 76, 2}
Exercise 16.5
How many prime numbers of a bit-length of 1024 are there?
Problem 16.1
How can an attacker, who knew five successive random numbers generated by a linear congruential generator, break such
an LCG (i.e. he/she can find the LCG parameters)?
Problem 16.2
What is the category (i.e. safe prime and strong prime) of primes generated by the function Shawe_Taylor_Provable_
Prime? Use the pseudocode of the function in Section 16.3.4.1.
Problem 16.3
1
By the prime number theorem, we know that the probability of an integer z ∈ 2, N to be prime is ln ( N ) . Consider m RSA
2048 1024
public-keys, with moduli of at most 2 ; and all used primes are no greater than 2 .
562 16 Generation of Pseudorandom and Prime Numbers for Cryptographic Applications
1) Assume that all used primes are generated by a truly PRNG (pseudorandom number generator). Then, estimate the
probability that there exist, at least, two RSA keys, out of the m known keys, that have a prime factor in common.
2) Assume that you know 100 million public-keys generated using the same PRNG Π; and you find out that 1000 moduli
share a common prime factor. What can you conclude?
Exercise 16.1
Let X be a one-character random variable that takes its values in a set composed of 26 uppercase Latin letters (20 conso-
nants and 6 vowels), 10 decimal digits, and 8 special characters. All the 20 consonants have the same selection probability,
and the same applies to vowels, digits, and special characters. Therefore,
20 6
∑ c ( Pr * log 2 ( Pr c )) + (
∑ v 2 v
Pr * log ( Pr ))
= − i=10 1 i=1
6
+∑ ( Prd * log2 ( Prd )) + ∑ ( Prs * log2 ( Prs ))
i=1
i=1
20 * Pr * log ( Pr ) + 6 * Pr * log ( Pr ) +
c 2 c v 2 v
= −
10 * Prd * log2 ( Prd ) + 8 * Prs * log2 ( Prs )
20 Pr log ( Pr ) + 6 Prc log Prc +
= −
* c * 2 c *
2
* 2 2 ( )
Prc Prc
10 *
4
( )
Prc
* log2 4 + 8 *
10
Prc
* log2 10 ( )
= 5.122
Exercise 16.2
The function F , which generates a cyclic sequence of {1, 2, 7, 0, 4, 6, 3, 5, 9, 8}, fulfills the first condition of PRNG, i.e. the
outputs are independent and identically distributed. However, it does not fulfill the property of unpredictability, because
the output can be easily predicted, when the first period is known. Therefore, F is not appropriate to be used in crypto-
graphic applications.
Exercise 16.3
1) Consider an LCG with parameters m = 256, a = 25, and b = 16. Below are the longest sequences generated, depending
on the initial value of the seed X 0 :
– X 0 = 255 results in a longest sequence of 32 numbers: {255, 247, 47, 167, 95, 87, 143, 7, 191, 183, 239, 103, 31, 23, 79,
199, 127, 119, 175, 39, 223, 215, 15, 135, 63, 55, 111, 231, 159, 151, 207, 71}
– X 0 = 2 results in a longest sequence of four numbers: {2, 66, 130, 194}
– X 0 = 6 results in a longest sequence of eight numbers: {6, 166, 70, 230, 134, 38, 198, 102}
– X 0 = 10: results in a longest sequence of a single number: {10}, i.e. no new number can be generated.
– X 0 = 0: results in a longest sequence of 16 numbers: {0, 16, 160, 176, 64, 80, 224, 240, 128, 144, 32, 48, 192, 208, 96, 112}.
2) Consider an LCG with parameters m = 255, a = 25, and c = 16. What do you observe if X 0 = 0?
16.4 Exercises and Problems 563
– When X 0 = 0, the sequence that repeats is {16, 161, 216, 61, 11, 36, 151, 221, 186, 76, 131, 231, 181, 206, 66, 136, 101,
246, 46, 146, 96, 121, 236, 51}. We observe that the number 0 is not generated. In this case, 0 is called a tail, which does
not repeat in the cycle of the PRNG.
– When X 0 = 4, the sequence which repeats is {116, 111, 241, 176, 81, 1, 41, 21, 31, 26, 156, 91, 251, 171, 211, 191, 201,
196, 71, 6, 166, 86, 126, 106}. We observe that the number 4 is not generated. In this case, 4 is a tail.
Exercise 16.4
Check of primality using Miller-Rabin test.
1) n = 19 with random values {3, 7, 17}. The algorithm runs in a maximum of three iterations.
Step 1:
19 = 21 * 9 + 1. Hence, s = 1 and m = 9
Step 4: (1st iteration)
4.1 Let a = 3 be the selected random value
4.3 V = 39 mod 19 = 18
4.5 Since s = 1, “for j from 1 to s −1” is skipped
Step 4: (2nd iteration)
4.1 Let a = 7 be the selected random value
4.3 V = 79 mod 19 = 1
4.4 Go to Step 4.7
Step 4: (3rd iteration)
4.1 Let a = 17 be the selected random value
4.3 V = 179 mod 19 = 1
4.5 Go to Step 4.7
Step 5: return “Probably prime”.
2) n = 113 with random values {107, 76, 2}. The algorithm runs in a maximum of three iterations.
Step 1:
113 = 24 * 7 + 1. Hence, s = 4 and m = 7
Step 4: (1st iteration)
4.1 Let a = 107 be the selected random value
4.3 V = 1077 mod 113 = 78
4.5.1 j=1: V = 782 mod 113 = 95
Assume that the attacker knows five successive outputs: 73, 42, 20, 50, and 55.
The attacker builds and solves the following 3-equation system:
42 ≡ (73a + b) mod m (a)
20 ≡ ( 42a + b) mod m (b)
50 ≡ (20a + b) mod m (c)
To generate m RSA public-keys, a maximum of 2m primes are required (because RSA modulus is a product of two primes).
If among 2m primes, two (or more) values are identical, then there exists at least two RSA keys that share a common prime
factor. We randomly pick the first prime out of n primes. Then, when we randomly pick the second prime, there is a prob-
ability of 1/n that the new prime is identical to the first one. Then, when we randomly pick the third prime, there is a
probability of 2/n that the new prime is identical to one of the two old primes, etc. Finally, when we randomly pick the last
prime, there is a probability of (2m − 1)/n that the new prime is identical to one of the 2m − 1 old primes. Therefore, the
References 565
( 2m−1+1) ( 2m−1) 2
probability to have at least two identical primes is P = n1 + n2 +…. + 2mn−1 = n
≈ 2*nm . Notice that we can
obtain the same result by applying the formula of birthday paradox, which states that the probability of a collision among
2
k integers randomly picked out of a set of L integers is P (k ) ≈ 2kL .
2) By the answer to the first question, if a truly PRNG is used to generate 100 million RSA public-keys, the probability to
(108 )2
have two RSA keys that share a common prime factor is , which is by far smaller than that provided by PRNG Π,
21024
3
710
10
which is of 10 8 . Therefore, we can conclude that PRNG Π is faulty; it lacks randomness.
Notes
1 Deterministic means that given a seed value, the generator will always produce the same output sequence.
2 As far as we know, the NIST has not yet recommended CSPRNGs, which are mainly based on stream ciphers.
3 CMAC is an improvement of CBC-MAC. Some weaknesses of CBC-MAC have been addressed in literature; and CBC-MAC is
not considered secure, under specific usage conditions (see some problems discussed in Chapter 9).
4 In this chapter, user requesting DRBG outputs is referred to as “consuming application”.
5 The required minimum entropy bit-length is the same than that of the highest security strength that can be provided.
6 B = (2CtrLen − 4) * BlkLen; CtrLen is a building parameter of CTR-DRBGs.
7 See Problem 3.19 for proof of Lemma 16.1.
References
1 Shannon, C. (1948). A mathematical theory of communication. Bell System Technical Journal 27: 379–423, 623–656.
2 Matsumoto, M. and Nishimura, T. (1998). Mersenne Twister: a 623-dimensionally equidistributed uniform pseudo-random
number generator. ACM Transactions on Modeling and Computer Simulation 8 (1): 3–30.
3 Park, S. and Miller, K. (1988). Random number generators: good ones are hard to find. Communications of the ACM 31 (10):
1192–1201.
4 Barker, E. and Kelsey, J. (2015). Recommendation for Random Number Generation Using Deterministic Random Bit
Generators - Special Publication 800-90A (Rev. 1). NIST. National Institute for Standards and Technology.
5 Turan, M., Barker, E., Kelsey, J., and et, A. (2018). Recommendation for the Entropy Sources Used for Random Bit Generation,
Special Publication 800-90B. NIST. National Institute for Standards and Technology.
6 Barker, E. and Kelsey, J. (2016). Recommendation for Random Bit Generator (RBG) Constructions - Second draft SP 800-90C.
NIST. National Institute of Standards and Technology.
7 NIST (2019). Digital Signature Standard (DSS) - FIPS PUB 186-5 (Draft). National Institute of Standards and Technology.
8 Miller, G.L. (1975). Riemann’s hypothesis and tests for primality. 7th ACM Annual Symposium on Theory of Computing,
234–239. Albuquerque, NM, US: ACM.
9 Rabin, M.O. (1980). Probabilistic algorithm for testing primality. Journal of Number Theory 12 (1): 128–138.
10 Pinch, R. (2007). The carmichael numbers up to 10^21. Proceedings of Conference on Algorithmic Number Theory, 129–131.
Turku, Finland: TUCS General Publication.
11 NIST (2013). Digital Signature Standard (DSS) - FIPS PUB 186-4. National Institute of Standards and Technology. Institute
for Standards and Technology.
12 Shawe-Taylor, J. (1986). Generating strong primes. Electronic Letters 22 (16): 875–877.
566
A.1 Questions
A.1.1 Basic Definitions of Security and Cryptography
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
68. Assume an affine cipher with key K = (5, 7) and a modulus of 26. Which one of the following letters is the ciphertext of the
plaintext B?
a) K b) T c) E d) Q
69. What weakness is present in a ciphertext produced by substitution alone?
a) It has a length distinct from that of the plaintext b) It is hard to break
c) It maintains letter frequency d) It is too simple to implement
70. In which mode of operation of block ciphers each plaintext block has one and only one corresponding ciphertext?
a) CBC b) ECB c) Hash function d) HMAC
71. Which algorithm has supplanted DES?
a) RS b) Diffie-Hellman c) AES d) Elliptic curve encryption
72. How long is the ciphertext corresponding to an 88-bit plaintext if encrypted with a block cipher?
a) 128 b) 88 c) 256 d) 89
73. How long is the ciphertext corresponding to an 88-bit plaintext if encrypted with AES?
a) 128 b) 256 c) 88 d) 512
74. What is maximum key space of AES?
a) 256 b) 2256 c) 21024 d) 22048
75. Which of the following pair of number of rounds and key length is not correct regarding AES?
a) NbRounds=10, KeyLen=128 b) NbRounds=14, KeyLen=256
c) NbRounds=16, KeyLen=256 d) NbRounds=12, KeyLen=192
76. Which of the following is one of the main drawbacks of symmetric systems?
a) Key length b) Key distribution c) Key storage d) Key generation
77. Which of the following is said to be unbreakable by brute-force attack?
a) RSA b) One-time pad c) AES d) TDEA
78. Both AES and TDEA are
a) Stream ciphers b) Byte ciphers c) Block ciphers d) Public-key ciphers
79. Which of the following mode is not a mode of operation of block ciphers?
a) RSA b) CBC c) CFB d) CTR
80. Which of the following best describes Vigenere’s cipher?
a) Transposition b) Mono-alphabetic c) Poly-alphabetic d) Additive cipher
81. Which of the following characteristics is not good for a stream cipher?
a) Statistically unbiased b) Long period
c) Keystream not linearly related to the key d) Statistically predictable
82. Which of the following ciphers makes use of two distinct keys to encrypt and to decrypt?
a) Symmetric b) Asymmetric c) Stream d) Block
83. How long would be the ciphertext of a 100 bit message encrypted with a stream cipher?
a) 156 bits b) 228 bits c) 90 bits d) 100 bits
84. Which of the following modes of operation of AES can be used as a stream cipher?
a) ECB b) OFB c) CBC d) XTS
85. Which pair of words in the following list refers to the labor needed to encrypt or decrypt a plaintext?
a) Stream encryption, block decryption b) Symmetric, asymmetric
c) Confusion, diffusion d) Block encryption, stream decryption
86. In which of the following categories TDEA is included?
a) Stream ciphers b) MAC algorithms c) Hashing algorithms d) Block ciphers
87. What is the maximum key space of TDEA?
a) 256 b) 2168 c) 2128 d) 2256
88. Which of the following is not a mode of operation of block ciphers?
a) ECB b) CEB c) CBC d) CFB
89. Which of the following is not a parameter of block ciphers?
a) Number of rounds b) Key length c) Block length d) Message length
90. Which of the following transformations is not applied in AES?
a)SubBytes b) ShiftRows c) MixColumns d) PermuteKey
91. Which of the following transformations does not (at some level) contribute to diffusion in AES?
a) SubBytes b) ShiftRows c) AddRoundKey d) MixColumns
92. Which of the following operations most contribute to confusion in DEA?
a) Permutation b) S-boxes c) Round key scheduling d) Key expansion
93. Which of the following is correct?
a) Rijndael is a symmetric cipher, while AES is an asymmetric cipher
b) Rijndael is a stream cipher, while AES is a block cipher
c) AES is the standard version of Rijndael
d) Rijndael is Feistel structure-based, while AES is not
94. Which of the following operations most contributes to diffusion in DEA?
a) Permutation b) S-boxes c) Round key scheduling d) Key expansion
95. Which of the following transformations most contribute to diffusion in AES?
a) SubBytes b) ShiftRows
c) AddRoundKey d) MixColumns and ShiftRows
110. Which of the following algorithms can be used to verify message integrity?
a) AES b) SHA-1 c) DES d) RSA
111. Message authentication code is also referred to as
a) Cryptographic code b) Cyclic redundancy check
c) Cryptographic check bits d) Cryptographic checksum
146. Which of the following algorithm does not belong to the public-key family?
a) DSA b) DHKE c) AES d) ECIES
147. What is the most common use of Diffie-Hellman algorithm?
a) To secure the exchange of keys b) To generate signatures
c) To encrypt and decrypt messages d) To provide certificates
148. Which of the following is the ciphertext of plaintext 5 if RSA modulus is 209 and the public key is e=17?
a) 418 b) 80 c) 34 d) 85
149. Which of the following cannot be used as a public key?
a) 3 b) 2 c) 7 d) 11
150. What is the discrete logarithm problem?
a) Given a large integer N, find all prime dividers of N.
b) Given an integer a and a large integer N, find an integer z such that z 2 ≡ a mod N .
c) Given two integers a and b and a large prime p, find an integer z, such that a z ≡ b mod p.
d) Given an integer a and a large prime p, find an integer z, such that a * z ≡ 1 mod p.
151. Consider the integer factorization problem and the discrete logarithm problem. Which of the following is not correct?
a) They have the same computational complexity
b) They make cryptographic algorithms hard to break
c) They are the basis of public-key cryptography
d) One of them is the basis of elliptic curve cryptography
152. Which of the following public-key encryption is based on the difficulty of factoring large numbers?
a) AES cipher b) Elliptic curve encryption c) ElGamal encryption d) RSA
153. Which statement describes asymmetric ciphers?
a) They are slow compared to stream ciphers
b) They have a key bit-length ranging from 56 to 256
c) They include AES and TDEA
d) They use a shared secret key
154. In what way does RSA fundamentally differ from AES?
a) It uses a single key b) It uses two keys
c) It is based on a symmetric algorithm d) It cannot produce a signature
155. Which one of the following is not an elliptic curve recommended in standards?
a) Edwards curve b) Montgomery curve c) Rabin curve d) Weierstrass curve
a) 7 b) 25 c) 17 d) 29
188. Which of the following is Euler’s totient φ(n), when n = 1111?
a) 1000 b) 100 c) 121 d) 111
189. Of which of the following congruences −5 is a square root?
a) 2 mod 17 b) 2 mod 19 c) 2 mod 23 d) 2 mod 29
190. Which of the following polynomials is irreducible over binary field F2?
a) x 2 + 1 b) x 2 + x c) x +1 d) x 2 + x + 1
191. Which of the following is an extension field?
a) F2 b) F3 c) F8 d) F5
192. Which of the following values is the order of the group < Z21
*
,×>?
a) 20 b) 12 c) 13 d) 15
193. 2100 mod 101 =
a) 7 b) 1 c) 3 d) 7
194. A primitive polynomial is also called
a) Singular Polynomial b) Non-factorizable Polynomial
c) Perfect Polynomial d) Irreducible Polynomial
2
195. What is the GCD of x 3 + x + 1 and x + 1 over F2?
2
a) x b) x c) 1 d) x +1
d) a
4 mod p
a) a 3 mod p b) a p−1 mod p c) a 2 mod p
198. Which of the following is a bad source of entropy to random number generators?
a) Number of key strokes per minute b) Outdoor temperature
c) Number of cars in a car park d) Number of students in a classroom
199. Which of the following statements is false? x is an element of Zn
A.2 Answers
Index
Note: Italic page numbers refer to figure and Bold page numbers reference to tables. Page numbers followed by ‘n’ refer to
notes.
Cryptography: Algorithms, Protocols, and Standards for Computer Security, First Edition. Zoubir Mammeri.
© 2024 John Wiley & Sons, Inc. Published 2024 by John Wiley & Sons, Inc.
ciphertext-only attack (COA) 46, 47, 338 countermeasures 1, 5, 16–19, 24, 193, 384, 389, 396, 440
ciphertext stealing 251, 252, 265 Counter with Cipher block chaining-Message authentication
client certificates 510, 520 code (CCM-MAC) 161, 248, 281, 283, 285–289, 306,
ClientHello 518, 519 329, 330–332, 519
clocking technique 181 crackers 12, 45, 52
clock synchronization 526 crib 130, 131, 131, 132, 140
codebook 124, 125, 125, 130, 279n2 crib-based attack 130–132
code (or software) signing certificates 510 cryptanalysis 33–34, 34, 38, 43, 45–50, 130, 188, 194, 220,
codomain 315, 316, 333 224, 232, 268, 305, 338–380, 401, 467
cofactor 429–431, 436, 437, 439, 443–445, 480, 507n12 cryptanalysts 34, 43–46, 50, 54, 129, 132, 356, 382, 389
cofactor-less verification 445 cryptographically secure PRNG (CSPRNG) 536, 537, 561,
collision 142, 144, 152, 161, 164–168, 220, 272, 283, 284, 306, 565n2
307, 311, 312, 322, 336n5, 339–340, 342, 343, 347, 375, cryptographic key 36, 300, 301, 465, 468, 469, 469, 470, 471,
376, 565 531, 532
collision attack 143, 144, 144, 152, 161, 168, 169, 307 cryptography 1, 29, 33–57, 59–115, 117, 134, 142, 177, 208,
collision probability 92–93, 145 209, 279n2, 281, 301, 314, 320, 339, 361, 381, 394–399,
collision resistance 143, 163, 166, 167 405, 424–463, 477, 478, 492, 502, 526, 529, 531, 532,
collision-resistant 143, 164, 165, 167, 168 535–550
column mixing 222 cryptoperiod 465–468, 468
combination generators 181, 182 CTR-DRBGs 546, 547, 548, 565n6
Common Vulnerabilities Exposure (CVC) 18 cube attacks 338, 368–372, 380n10
complementation property 220, 235, 236, 242 cube variables 369
compression permutation 218, 243 curve generator 430
computational complexity 45, 194 cybercriminals 11–13, 15, 29, 45
computational difficulty 314, 336n1 cybernetics 2
computationally indistinguishable 315, 316, 474 cybersecurity 3–4, 4, 27
computationally infeasible 38, 43, 47, 50, 59, 143, 161, 167, cyberspace 1–4, 6, 8, 8, 11, 33, 42, 43, 161, 162, 383
168, 220, 314, 341, 376, 381, 383, 384, 388, 389, 394, 396, cyclic group 68–69, 71, 79, 95, 381, 382, 394–396, 402, 404,
412, 416, 422, 436, 471, 504, 505, 537 429, 431, 434, 436, 438, 442, 478
computationally secure algorithm 43 cylinder messages 34, 35
computational security 43, 52, 54
conditional entropy 133, 141n7, 534 d
conditioning component 533 Daemen, J. 36, 222, 245n6
conditioning function 537, 538 data authenticity 247, 281, 282, 289, 292, 312n2
confidentiality 4, 6, 17–19, 29, 30, 33, 34, 36, 40, 163, 165, data availability 7
170, 184, 247–279, 281–312, 322–326, 381, 382, 409, data consent 27
424, 465–467, 483, 502, 504, 505, 517, 519, 520, 526, 531 Data Encryption Algorithm (DEA) 209, 211–217, 220,
confusion 208 222–224, 235–237, 241–243, 245n3, 363, 484, 502, 503,
congruence 61, 62, 72, 81, 86, 87, 89, 91, 105, 106, 114, 136, 505
141n1, 166, 385, 386, 408, 411 Data Encryption Standard (DES) 36, 37, 40, 50, 211, 220–222,
congruence class 62 235, 236, 241, 242, 244, 245n3, 245n4, 320, 321, 339,
congruence systems 80, 88, 89, 103–107, 386, 564 347, 360, 363, 503
content filtering 20, 21 data integrity 6, 19, 39, 40, 42, 142, 143, 145, 247, 269, 281,
contingency plans 19 446, 465, 467
COPACOBANA 220 data processors 28, 29
coprime 60, 61, 63–65, 68, 81, 83, 85, 86, 92–94, 96, 103, 104, data protection 3, 18, 27, 28–29, 247
110, 113, 114, 200, 385, 387–389, 402, 406, 409–411, data unit 265, 267, 268, 270, 278, 279n10
413, 417, 420, 454, 552, 553, 557 decryption algorithm 36, 37, 207, 212, 243, 261, 263,
correlation attacks 338, 373, 373–374 265–268, 287, 295, 297, 301
counter (CTR) 191, 192, 197, 199, 220, 248–249, 253–255, decryption key 36, 37, 40, 446, 466
255, 269–277, 279n14, 285–289, 291, 293–294, 296, 297, denial-of-service attack 10, 526, 527
299, 306, 323–325, 330, 335, 337n12, 366, 472, 474, 479, derived polynomial 180, 369–371, 380n9
537, 546, 555, 556 detection methods 17
entropy input 537, 537–539, 541, 542 463n2, 463n4, 463n6, 465, 478–480, 487, 509–511, 511,
entropy source 532–533, 533, 535, 538, 541–546, 548 516, 518–520, 523, 535
ephemeral keys 36, 396, 402, 409, 420, 441, 462, 469, 494, 495 field generators 74, 76, 456, 479
ephemeral public key 448, 493–495, 505 filter functions 366, 367, 372–374, 378
error detecting code 142 filter generators 181
error-propagation 175, 250, 253, 256, 269, 275, 276 finding multiplicative inverse 81
Euclidean algorithm 80, 91, 100 fingerprints 40, 142, 165
Euler phi function 61 finite field cryptography (FFC) 37, 381, 382, 396, 477–480,
Euler’s criterion 64, 65, 87, 104, 109, 115n14, 451, 454, 455 483, 492, 494, 550, 554, 555, 558, 559
Euler’s theorem 63, 65, 81, 94, 134, 137, 402, 410 finite fields 37, 38, 60, 69–71, 73–75, 78, 89, 96, 98, 137, 186,
Euler’s totient 61, 63, 65, 81, 93, 94, 96, 137, 389, 402, 422n16 196, 205n12, 229, 290, 361, 381–422, 424–427, 430, 432,
Euler totient function 61, 63, 65, 93, 96, 422n16 435–437, 441, 442, 453, 454, 459, 463n2, 478–480, 487,
European Telecommunications Standards Institute 518, 519
(ETSI) 182, 188, 205n9 finite state machine (FSM) 182, 184, 186–188, 190, 195,
exhaustive search attack 47, 360 205n14
existential forgery 161, 163, 399 firewalls 10, 16, 19–22, 24–26, 31n3
existential forgery attack 326, 383, 403, 412 flip-flop (FF) 177–179, 202, 205n4, 238–239, 242
experiment 316, 321 forbidden attack 293–294, 306
Extended Euclidean algorithm 80–81, 91, 101, 107, 402, 406, forgery attacks 283, 299, 305, 306, 308, 310, 312, 326, 383,
407 403, 412
extended field 71, 205n14, 361 forgery probability 328
extended validation (EV) certificates 517 format-preserving encryption (FPE) mode 256–265, 269
extension fields 71–79, 98, 180, 188, 195, 197, 198, 222, 229, frequency analysis 49, 118, 120, 123, 129, 130, 132, 134
232–234, 245, 265, 289, 290, 293–295, 395, 425, 426, full entropy bit-string 538
431–435, 437, 480, 516 Func(M, R) 316, 333
function domain 315, 322
f function F 182, 188, 190, 209, 216, 235–237, 239, 241, 561,
F2 field 75 562
F2m fields 75, 77, 432 function family 315–317, 320, 327, 333
false alarm 221, 236, 242–244, 339–342, 345–347
fast scalar multiplication 434 g
fault injection attacks 49, 50 Galois/Counter MAC 161
feedback coefficients 178, 180, 197, 199, 201, 202 Galois/Counter Mode (GCM) 161, 281, 283, 289–295, 306,
feedback polynomial 180, 181, 183, 184, 188, 197–199, 201, 312n4, 329, 330–332
203–205, 375, 378, 379n5 Galois MAC (GMAC) 161, 248, 281, 289–294, 306, 326, 327,
Feedback Shift Registers 178 330, 331, 484
Feistel network 209, 211, 235, 241 Galois Message Authentication Code (GMAC) 161, 248, 281,
Feistel structure 209–210, 210, 222, 245n1, 257, 258, 270, 272 289–294, 306, 326, 327, 330, 331, 484
Fermat’s little theorem 63, 68, 91, 94, 102, 110, 113–115, 385, game 14, 316, 321–323, 324, 326–328
388, 408, 411, 416, 417, 552, 553 Gauss’s algorithm 65, 80, 86–89, 91, 92, 103, 105, 106, 114,
Fermat’s primality test 552–553 386, 402, 411
FF1 197, 199, 248, 249, 256–258, 258, 259, 259–263, 270–274 General Data Protection Regulation (GDPR) 27–29
FF3 197, 199, 248, 279n6 general number field sieve (GNFS) 389
FFC-DH 492, 498 generator 45, 47, 57n7, 60, 68–71, 74, 79, 80, 95, 96, 99,
FFC-KPGERB 479 110–112, 135, 142, 166, 173, 177, 181, 182, 182, 183,
FFC-KPGTC 479 185, 306, 394, 396, 400–402, 404, 405, 408, 416–418,
FFC-MQV 492 420, 421, 422n8, 429–430, 433, 434, 436, 439, 450–453,
field 1, 3, 4, 7, 13, 21, 24, 29, 45, 60, 69–80, 89, 90, 92, 96–99, 456–458, 460, 461, 463n5, 465, 470, 478, 479, 492, 493,
111–113, 115n9, 125, 133, 135, 137, 145, 174, 180, 184, 502, 520, 531, 532, 536, 565n1
186, 188, 194–198, 201, 205n12, 205n14, 208, 222, 227, generators of F2m field 76–78
229, 232–234, 245, 249, 256, 257, 265, 269, 274, 289, generic attacks 10–11, 143–144, 157, 161, 164, 338
290, 293–295, 314, 320, 338, 348, 361, 368, 381, 390, GHash 290, 291, 293–295
394, 395, 424–439, 441, 442, 448, 450–456, 459–461, greatest common divider 59, 60, 80, 503
key-confirmation 483, 484, 486–487, 489–491, 491, 495–498, Lenstra’s algorithm 389
496–498, 498, 507n24 lightweight cryptography (LWC) 194–197
key derivation 42 linear approximation 347–360, 375, 377, 379n2
key derivation function (KDF) 295–297, 312n5, 329, linear approximation table (LAT) 351, 351–358, 375, 377
446–448, 463n16, 466, 467, 469, 470, 472–476, 475, 483, linear congruential generator (LCG) 177, 197, 200, 201, 536,
486, 488–490, 494, 495, 498, 507n5, 507n20, 507n24 561–563
key derivation methods (KDM) 471–474, 472, 473, 502, 505, linear cryptanalysis 47, 220, 224, 338, 347–360, 365, 378
507n5, 507n6 linear expressions 349, 350, 351, 352–356, 359, 370, 377, 378
key distribution 465, 468, 483, 486 linear-feed-back-shift-register-based generators 177
key distribution center (KDC) 483, 484–486, 501, 502, 504, linear-feedback shift registers (LFSR) 177–181, 178, 179, 180,
507n17, 509, 521, 521, 522, 523 181–182, 182, 183, 184, 186–191, 193, 197, 198, 198,
keyed hash functions 41, 158, 537, 544 199, 201–205, 204, 205n6, 366, 367, 370, 372–374, 378,
key establishment 37, 247, 465, 467–469, 478, 482–501 379n5
key-establishment protocols 482, 482 linear full-cipher approximation 352, 353, 356–358
key-establishment transaction 466 logic bomb 15
key expansion 120, 121, 159, 208–209, 209, 223, 227–229, loyalty and patriotism 3, 18
228, 231, 238, 472, 473 Lucas-Lehmer primality test 551, 552
key generation 43, 47, 135, 157, 299, 384, 465, 467–482, 470, Lucas’s primality test 552
473, 474, 474, 484
keying material 447, 463n16, 483, 491, 492, 495, 518, 520, m
540 mac-advantage 326
keylogger 15 MAC forgery attacks 283, 306
key management 247, 465–507 MAC key 158, 446–448, 467, 472, 483, 488–492, 495, 507n20
key schedule function 209, 211, 212, 217, 218–220, 219, 235, MAC-then-Encrypt 282, 294
238, 241–243 malicious code 13–15
key-scheduling algorithm (KSA) 173, 193 malicious software 8, 13, 15
key scope 265 Malleability 45, 135, 140
keystream 40, 45, 135, 173, 174, 178, 182, 197–199, 201, 203, Malware 13–15, 31, 32n18
205, 271, 272, 275–277, 299, 300, 366–369, 373, 374, 378 manager awareness 18
keystream generator 173, 174–177, 182–198, 203, 204, 312, man-in-the-middle attack 48, 48, 52, 140, 382, 404, 418, 504, 505
367, 367, 368, 369, 373, 373, 374 mapping integers to EC points 448
key transaction 483 masks 11, 15, 298, 349, 351, 352, 355, 356, 359, 360, 375, 377,
key transport 465, 469, 483, 486, 487, 506n4, 507n16 390–393
key-transport schemes (KTSs) 483, 486, 491–492 master key 282, 294–297, 299, 329, 502
key wrapping (KW) 248, 281, 282, 300–305, 466, 483–486 master polynomial 368–371, 380n9, 380n11
key-wrapping protocol (KWP) 248, 281, 301–305, 483, 484, Matsui-Algorithm 1 356
486 Matsui-Algorithm 2 359–360
key wrappings modes 282, 300–305, 486 maximal-length LFSR 179, 180, 199
KMAC 158, 160–161, 471, 472, 474, 507n18 maxterm 369–371, 380n10
KMAC-128 160, 472 MD family 144
KMAC-256 160, 472 meet-in-the-middle (MITM) attack 48, 52, 53, 220–221, 236
known-plaintext attack (KPA) 47, 269, 347, 360, 366 memory-time trade-off (MTTO) attacks 338, 339–347, 376
kr-advantage 321 Menezes-Qu-Vanstone (MQV) 381, 382, 395, 396, 397, 424,
KTS-OAEP 483, 486, 491, 492 440, 477–478, 486, 492, 549, 555, 556, 558–559
Merkle-Damgård construction 145, 146, 165, 170
l Mersenne prime 550
Lagrange’s theorem 68, 418, 429, 452 Mersenne Twister 536
lamp panel 122 message authentication 42, 163, 165
least common multiple 60 message authentication code (MAC) 11, 39, 40–41, 45, 50,
Left-or-Right (LOR) 323–324, 324 142–171, 207, 247, 269, 281–286, 286, 287, 290,
left-to-right binary method for point multiplication 434, 453, 305–307, 309, 310, 314, 315, 326, 326, 327–329, 331,
460 368, 446–448, 465, 466, 472, 473, 483, 487, 488, 488,
Legendre symbol 64, 435, 459, 461 489–492, 495, 507n20, 520
234, 235, 237, 242, 243, 272, 273, 314–323, 325–327, pre-shared-key extension 520
329, 332–335, 353, 354, 356–360, 365 prevention methods 16, 17
permutation domain 315, 333 PRF-advantage 316, 317, 320, 322
permutation family 315, 317, 318, 320–323, 327, 332–334 PRF/PRP switching lemma 319–320, 325
permuted choice 218 primality testing 531, 551–554
personal data 12, 26–28, 31, 45 prime 1, 18, 38, 42, 50, 60–71, 73, 75, 77, 78, 80, 81, 83, 85,
personalization string 539, 541 87–91, 93–96, 102, 105–110, 112, 113, 115n6, 115n10,
pharming 10 122, 137, 180, 188, 197, 200, 207, 281, 294, 300, 381, 383,
phishing 11, 13, 21, 45 385–389, 391, 394, 395, 400–407, 409–411, 413, 416,
physical noise sources 533 418, 420–421, 422n15, 425, 429, 430, 432, 435, 437, 438,
physical protection 3, 18 443, 444, 448, 459–461, 463n2, 465, 477–480, 492, 493,
Piling-up lemma 348–349, 352–356, 378 501–504, 507n8, 520, 531–565
PKCS# 392 prime fields 70, 71, 80, 112, 180, 188, 425–435, 437–439, 441,
plaintext 34–36, 40, 43–49, 52–57, 57n8, 117–119, 121–123, 450, 451, 461
125, 128, 130–140, 165, 173–175, 177, 181, 183, prime numbers 50, 96, 383, 384, 388, 389, 404, 411, 422n15,
192–193, 197–199, 201–203, 205, 207–212, 217, 220, 437, 438, 531–565
221, 224, 234–241, 243, 244, 247–253, 255–265, prime number theorem 550, 551, 561, 563, 564
268–279, 279n2, 279n8, 279n15, 279n16, 281–285, 287, prime power 60, 69, 70, 73, 78, 425, 431, 437, 480
289–291, 293–297, 299–303, 305–310, 312, 314, 315, prime power fields 431
317, 318, 321–324, 327–332, 334, 335, 336n4, 338–347, primitive element 68, 74, 76, 77, 111, 265, 429, 452
349, 352, 353, 356, 357, 357, 358–361, 363–367, 372, primitive polynomial 74, 76, 77, 180, 195, 197, 199, 201, 204
375, 376, 378, 379n4, 383–388, 398, 402, 403, 408–415, primitive root 68, 96
418, 446–449, 467, 502–505, 527, 528 principals 521, 523, 526–529
planes 152, 153 privacy 2, 3, 5, 6, 26–29, 33, 294, 314, 322, 329, 330
plug board 123, 124, 124, 125, 126–132 private authentication keys 466
Pocklington-Lehmer primality test 552, 557–559 private authorization keys 466
Pohlig-Hellman 394, 401 private ephemeral key-agreement keys 466
point addition 426, 427, 428, 431, 433, 434, 453, 456, 457 private key 37–39, 41, 42, 45, 49, 50, 83, 145, 157, 158, 160,
point at infinity 426 162, 163, 165, 383–386, 388, 390–393, 395, 396,
point doubling 427, 428, 431, 434, 453, 457, 460 398–400, 402–404, 406, 407, 409, 410, 412–419, 422,
point multiplication by a scalar 427, 428, 429, 434, 481, 482 422n8, 422n9, 436, 439, 441–446, 448, 450, 452, 462,
point to infinity 426–429, 431, 434, 451, 453, 455, 456, 461, 463n5, 463n7, 466, 468, 469, 476, 477, 479–484, 486,
507n23 488–490, 492–495, 501, 503–505, 509–512, 514, 516,
Pollard’s rho 394 517, 520–522, 527–529, 529n4, 549
Poly 1305 298–300 private key-transport keys 466
Poly1305-AES 248, 282, 298–299, 308, 312 private signature-generation keys 466
polyalphabetic cipher 35, 117, 120 private static key-agreement keys 466
polyalphabetic substitution cipher 122, 128 probabilistic bias 348
polynomial 60, 62, 71–75, 77–80, 89, 90, 96–100, 107, 108, probabilistic dictionary attack 339
111–113, 163, 165, 166, 180, 181, 183, 184, 186, 188, probabilistic encryption 248
195, 197–199, 201–205, 229–234, 265, 290, 293–295, probabilistic mapping method 448, 449, 452, 462
366–371, 375, 378, 379n5, 380n8, 380n9, 380n11, 389, probabilistic primality testing 552
432–434, 437, 448, 452, 456, 460, 480, 503, 507n15 probable primes 478, 479
polynomial basis 73–75 probably prime 478, 549–551, 553, 554–556, 563
polynomial basis of F2m 76 proof of possession (POP) 514
polynomial congruence 72 provable prime/provable-prime 479, 549, 550, 552, 556–561
polynomial root 72 proxies 16, 20, 21, 21, 21–22, 25
Polyval 294, 295–298 PRP-advantage 317–320, 322
port scanning 9, 10, 25 PRP-PRF switching lemma 319
power analysis attacks 49 pseudoprime 550
prediction resistance 538, 539 pseudorandom bit generator 142, 177, 465, 532, 541–549
preimage attack 144, 168, 169, 412 pseudorandom function (PRF) 259–262, 314–324, 327–329,
preimage resistance 143, 166, 542 470, 474–476
pseudorandom number generators (PRNGs) 43, 47, 57n7, recursive method for point multiplication 434, 435, 452, 460
173, 177, 207, 249, 418, 531, 532, 535–537, 539, 562 reduction function 83, 92, 339–341, 343, 344, 346, 375, 376
pseudorandom permutations (PRP) 272, 273, 314–323, 325, reduction polynomial 60, 73, 74, 76–78, 80, 89, 99, 112, 265,
328, 331–335 432, 434, 437, 452, 456, 460, 480
public authentication keys 466 reflector 123–127, 129
public authorization keys 466 registration authority (RA) 389, 512, 514, 515, 527, 528
public bits 368 related-key attack 46, 47
public cryptosystems 38–40, 42, 43, 50, 53, 83, 123, 158, 162, relatively prime 60, 61, 384
381–463, 468 replay attack 11, 48, 250, 269, 270, 305, 306, 502, 504, 518,
public ephemeral key-agreement keys 466 527, 528
public-key 33, 36, 37, 39–42, 45, 48, 157, 158, 161–163, 165, reseeding 538–539, 541–543, 545, 548
247, 381–422, 424–463, 465–469, 477, 478, 480–484, residue class 62
486, 488–495, 501–505, 509–514, 516–518, 520, 521, RFC 391, 424, 465, 507n10, 521
527–529, 529n2, 530n11, 561–562, 564–565 right-to-left binary exponentiation method 82, 91, 102, 114,
public-key certificate 42, 509 385, 387, 402, 403, 407, 408, 413, 415, 422n4
public-key cryptography 33, 36–38, 381, 383, 529, 549 Rijmen, V. 36, 222, 245n6
public-key distribution 384, 483–484 Rijndael 36, 187, 190, 222, 245n6
public-key exponent 384, 389, 402, 409 Rijndael’s table 187, 190
public-key infrastructures (PKIs) 384, 465, 509–530 ring 66–67, 69
public-key modulus 384 risk 2, 3, 5–6, 18, 20, 24, 25, 29, 234, 260, 307, 311, 312, 385,
public-key signature 381, 383 467
public key-transport keys 466 risk assessment 18
public signature-verification keys 466 Rivest, R. 36, 343, 381, 383
public static key-agreement keys 466 root CA 512, 513, 515, 516, 527, 528
rootkit 13, 15
q rotors 123, 123–129, 131, 132, 134, 139, 141n3, 141n4
quadratic residue 63–65, 88, 109, 454, 458, 459 round key 209, 211, 213, 216–218, 222, 223, 227, 228,
quarter-round 191, 192, 192 234–238, 241–243, 245n2, 352, 356, 360, 363, 365
query 22, 47, 271, 314, 316–335, 336n4, 336n6, 368, 370–372 round key addition 222, 363
row shifting 222
r
RSA 12, 36, 37, 49, 50, 81, 83, 123, 162, 381–422, 424, 441,
Rabin’s algorithm 80
466, 467, 477–478, 484, 486, 487–492, 495, 501, 503,
Rabin test of irreducibility 89, 90–91
504, 506n3, 507n7, 510, 514, 520, 549, 551, 555–556,
radix 83, 85, 257–261, 263, 264
559–562, 564, 565
rainbow chains 338, 343–347, 376
RSA key-pair generators (RSAKPGs) 477, 478
rainbow table 339, 343–344, 344, 345, 346, 346, 347,
RSAKPG1 477
374–376
RSAKPG2 477, 478
Random Access Machine (RAM) 320, 336n2
RSA-KTS-OAEP 483
random function 315–317, 319, 322, 327, 333, 474
RSA-OAEP 390–392, 505
randomness extraction 472
RSA-PSS 392, 393, 393
random numbers 43, 57n7, 173, 193, 422n8, 463n5, 465, 479,
RSA signature 162, 391–394, 403, 412, 413
481, 504, 506n4, 524, 531–533, 535, 536, 539, 540, 549,
RSASSA 162, 171n14, 391
554, 558, 561, 563, 565n3
RSASSA-PKCS1-v1 392
random number sequence 531, 532, 536
RSASSA-PSS 392
random permutation 315, 317–320, 322, 325, 326, 332–334
RSASVE_GENERATE 488–490
ransom attacks 1, 12, 14
RSASVE_RECOVER 488–490
ransomware 12–14, 30, 31
RC4 183, 193–194, 194, 517 s
reaction methods 16–17 safe prime 404, 405, 418, 420, 478, 479, 507n8, 550,
realms 521–526, 530n8 561, 564
Real-or-Random (ROR) 316, 323, 332 safety 3, 18
recommended elliptic curves 480 Salsa20 205n15
record protocol 518, 520 salt 164, 168, 392–394, 470–474
s-box 186, 187, 190, 208, 208, 209, 215, 224, 225, 227, 229, 340, 346, 349, 353, 356, 359–361, 364, 366, 370–373,
232, 233, 236, 238, 245n10, 348, 349–350, 350, 351, 351, 378, 380n9, 390, 392, 394, 399, 425, 426, 430, 432, 435,
352–353, 354, 355–357, 357, 358–361, 362, 363–366, 436, 439, 443, 444, 446, 447, 452, 468, 471, 473, 479, 510,
375, 377–378 512, 523, 531, 534, 535, 539, 541, 551, 561, 562, 565
screen scraper 15 SHA-0 144, 146
second preimage attack 144, 168, 169 SHA-1 144–152, 156, 158, 328, 329, 517, 542
second-preimage collision 161 SHA-1 collisions 152
second preimage resistance 143, 166 SHA-2 144–146, 152, 156, 158, 329
secrecy 6, 33, 44–45, 51–53, 55–57, 122, 133, 271, 314, 517 SHA-3 144, 146, 150, 152, 155, 157, 160, 165, 170, 171n7,
secret key 34–36, 40, 41, 43, 45, 49, 50, 120, 123, 133, 134, 171n8, 329
157–159, 161, 165, 173, 175, 177, 178, 181, 190, 197, SHA 3-384 152, 157, 470
201, 207, 209, 216, 257, 283, 285, 286, 290, 300, 307, SHA-224 146–150, 170, 329
339–341, 344, 346, 370, 374, 381, 383, 404, 407, SHA-256 146–150, 158, 328, 329, 390, 441, 446, 470,
416–418, 424, 483, 491, 492, 502–505, 507n19, 518, 523, 479, 510
527, 529 SHA-512 146, 147, 150–152, 165, 170, 329, 390, 441, 443, 445,
secret prefix MAC 158, 161, 165, 170, 171 446, 510
secret suffix MAC 158, 161, 165, 171 SHA algorithm family 146
secure-by-default 17, 18 Shake128 152
secure-by-design 18 Shake256 152, 443–445, 463n10, 530n6
secure PRF 317, 322, 329 Shamir, A. 36, 220, 360, 368, 369, 381, 383, 503
secure PRP under CCA 318 Shamir’s secret sharing 503
secure PRP under CPA 318 Shannon’s entropy 533–535
secure socket layer (SSL) 193, 424, 510, 517, 529n3 shared secret 39, 42–43, 121, 133, 158, 163, 283, 381, 382,
security analysis 314–336 395, 396, 404, 416–418, 437–440, 446–448, 465, 469,
security assessment 18 471–473, 475, 476, 483, 486, 488–490, 492–494, 505,
security penetration testing tools (SPTTs) 19 507n19, 518
security rules 20 Shawe-Taylor’s algorithm 479, 550, 556–558, 560, 564
security strength 38, 45, 129, 139, 144, 146, 152, 158, 160, sheets 125, 152, 153
168, 188, 383, 400, 401, 404, 417, 418, 437, 443, 465, shift cipher 117, 119
466–467, 470, 472, 505, 506n3, 507n6, 541, 542, 546, ShiftRows 223, 224, 226, 226–227, 233, 235, 238, 238, 239
565n5 side-channel analysis 49
seed 43, 54, 177, 181, 197, 199, 249, 279n1, 390–392, 404, 418, side-channel attacks 49–50, 234
479, 531–532, 535–539, 542, 555, 556, 559–561, 563, sieve of Eratosthenes 551
565n1 signature-based approach 23
segment 10, 24, 255, 256, 270, 273, 275, 276, 298, 299, 312, signature with appendix 162, 162, 171n14
322, 422n3 signature with message recovery 162
selection functions 213, 215, 215, 235, 237 single-CA model 515
selective forgery 163, 383 single sign-on service 526
selective replay attack 269 slices 152–154
self-clocking stream cipher 174 small subgroup attack 439–440
self-synchronization stream ciphers 175 SNOW 3G 182–188, 189, 190, 198
self-synchronizing stream ciphers 175, 176, 197 source authentication 7, 8, 40, 41
semi-weak 217, 222, 236 source of noise 537, 538
ServerHello 518, 520 spam filters 11
service ticket 522, 523 spams 11, 13, 15, 21, 30, 31, 45
session key 38, 42, 44, 45, 47, 312n5, 396, 422n9, 446, spear phishing 11
483–485, 486, 501, 502, 504, 505, 507n17, 509, 521–529, sponge construction 146, 152, 155–156, 156, 157, 171n9
529n4, 530n11, 532 sponge function 152, 155–157, 160, 170
set 5, 15, 17, 23, 25, 31, 44, 47, 53, 59–63, 66–69, 71–76, 78, spoofing 10, 11
79, 89, 92, 105, 111, 112, 117, 125, 128, 142, 145, 146, spyware 13, 14
168, 173, 175–177, 188, 191, 200, 201, 204, 229, 236, square-and-multiply method 80–82, 385, 403, 413
241, 245n11, 248, 257, 259, 269, 273, 279n8, 281, 285, square root 63–66, 71, 77, 80, 87–89, 91, 105–107, 110, 115,
290, 294, 296, 297, 299, 307, 311, 315, 322, 327, 332–334, 293, 294, 454, 455
w z
0-RTT protocol 518
weak collision resistance 143
0e-2s key-confirmation 495, 507n24
weak keys 217, 242
ZUC 182, 183, 188–191, 205n13