Cryptography & Data Protection

Chapter 4
Asymmetric Cryptography and Key Exchange

Certificate in Cybersecurity
Cryptography & Data Protection   •   Certificate

Asymmetric Cryptography and Key Exchange

Introduction and Context

Cryptography protects information by transforming readable plaintext into ciphertext and by providing mechanisms for authentication, integrity, and non-repudiation. Earlier chapters typically introduce symmetric cryptography, in which the same secret key is used for encryption and decryption. Symmetric cryptography is efficient, but it creates a fundamental distribution problem: communicating parties must already share a secret key through a secure channel.

Asymmetric cryptography addresses this problem by using a mathematically related pair of keys: a public key and a private key. The public key may be distributed openly, while the private key must remain confidential. This distinction enables secure key establishment over an insecure network and supports digital signatures. In practice, asymmetric algorithms are usually combined with symmetric algorithms because asymmetric operations are computationally expensive and less suitable for encrypting large data volumes.

This chapter explains public-key systems, RSA, elliptic-curve cryptography (ECC), Diffie–Hellman key exchange, hybrid encryption, security parameters, and deployment trade-offs.

Learning Objectives

By the end of this chapter, you should be able to:

  1. Explain the roles of public and private keys.
  2. Distinguish encryption, key exchange, and digital signatures.
  3. Describe the mathematical foundations and practical use of RSA.
  4. Explain elliptic-curve cryptography and elliptic-curve Diffie–Hellman.
  5. Describe how Diffie–Hellman establishes a shared secret.
  6. Explain why modern systems use hybrid encryption.
  7. Compare security, performance, deployment, and governance considerations.
  8. Identify common implementation failures and appropriate safeguards.

1. Public-Key Cryptography

A public-key system uses two related keys. The public key is published or distributed to others. The private key is retained by its owner and protected against disclosure. The relationship is designed so that knowing the public key does not make it computationally feasible to derive the private key.

For confidentiality, a sender encrypts using the recipient’s public key, and the recipient decrypts using the corresponding private key. In abstract form:

C = Enc(P, Kpub)
P = Dec(C, Kpriv)

Here, P is plaintext, C is ciphertext, Kpub is the recipient’s public key, and Kpriv is the corresponding private key. The notation describes the intended relationship; the exact algorithms and security conditions differ between systems.

For authentication and integrity, the private key is used to create a digital signature, and the public key is used to verify it:

σ = Sign(m, Kpriv)
Verify(m, σ, Kpub) = true

Here, m is a message and σ is its signature. A signature does not normally provide confidentiality. Anyone with the public key may verify it, but only the private-key holder should be able to create a valid signature.

Public-Key Encryption and Digital Signatures

These two uses are conceptually related but operationally different.

PurposeKey normally used to create operationKey used to reverse or verify operationMain security property
Public-key encryptionRecipient’s public keyRecipient’s private keyConfidentiality
Digital signatureSigner’s private keySigner’s public keyIntegrity and authentication
Key agreementEach participant’s private value and the other participant’s public valueBoth participants derive the same secretShared-secret establishment

A public key must also be associated with the correct identity. If an attacker substitutes a false public key, encryption may be performed for the attacker rather than the intended recipient. Public-key certificates and a public-key infrastructure (PKI) help bind keys to identities.

2. Security Assumptions and Threat Model

Asymmetric cryptography does not make systems automatically secure. Security depends on assumptions about computation, implementation, identity, randomness, and endpoint protection.

Important assumptions include:

  • Certain mathematical problems are difficult for appropriately chosen parameters.
  • Private keys remain secret.
  • Random-number generation is unpredictable.
  • Public keys are authenticated or obtained through a trustworthy mechanism.
  • Implementations correctly follow the algorithm’s required encoding and validation rules.
  • Attackers may observe, alter, replay, delay, or inject network messages.

A passive attacker observes communication. An active attacker may modify messages or impersonate a participant. A man-in-the-middle attack is especially important: an attacker establishes one key with the client and another with the server, relaying messages between them. Unauthenticated key exchange alone does not prevent this attack. Authentication through certificates, signatures, or a pre-shared trust mechanism is therefore essential.

3. RSA

RSA is an asymmetric cryptosystem based on modular arithmetic and the practical difficulty of factoring a large composite integer. Its security depends on parameter size, correct padding, secure random generation, and protection of private-key operations.

Key Generation

At a simplified level, RSA key generation proceeds as follows:

  1. Select two large distinct primes, p and q.
  2. Compute the modulus:
n = p × q
  1. Compute Euler’s totient for distinct primes:
φ(n) = (p − 1)(q − 1)
  1. Select a public exponent e such that:
gcd(e, φ(n)) = 1
  1. Compute the private exponent d satisfying:
d × e ≡ 1 mod φ(n)

The public key is (n,e), and the private key includes d and normally additional private parameters. Real implementations use very large primes and carefully specified generation procedures.

RSA Operations

For a suitably encoded message representative m, basic textbook RSA is represented as:

c ≡ me mod n

for encryption, and:

m ≡ cd mod n

for decryption. These equations are explanatory and are not a safe implementation specification. Textbook RSA is deterministic and vulnerable to several attacks. Modern encryption uses RSA-OAEP, while modern signatures use schemes such as RSA-PSS. The padding and encoding scheme is part of the security design, not an optional formatting step.

RSA is generally used for relatively small values, such as an encrypted symmetric key, rather than for bulk data. RSA ciphertext size is related to the modulus size, and the plaintext capacity is reduced by padding overhead.

Small Illustrative RSA Example

The following example is educational only and uses insecurely small numbers. Let p = 5 and q = 11. Then:

n = 5 × 11 = 55
φ(n) = (5 − 1)(11 − 1) = 40

Choose e = 3, since gcd(3,40) = 1. The value d = 27 satisfies:

3 × 27 = 81 ≡ 1 mod 40

For the representative m = 7, encryption gives:

c = 73 mod 55 = 343 mod 55 = 13

Decryption gives:

m = 1327 mod 55 = 7

This demonstrates the key relationship, not real security. A real RSA modulus is hundreds or thousands of bits long, and secure padding is mandatory.

RSA Strengths and Limitations

RSA is widely supported, well understood, and compatible with many certificate systems. It can support both encryption and signatures. However, RSA keys and signatures are relatively large, private-key operations can be costly, and poor padding choices have caused serious vulnerabilities. RSA encryption should not be used with ad hoc padding or raw modular exponentiation.

4. Elliptic-Curve Cryptography

Elliptic-curve cryptography uses algebraic structures defined over finite fields. A commonly used curve is represented abstractly by:

y² = x³ + ax + b

where a and b are curve parameters and the coordinates are interpreted over a finite field. The curve must satisfy a non-singularity condition. For a prime field, a usual condition is:

4a³ + 27b² ≠ 0 mod p

where p is the field modulus. ECC operations use point addition and scalar multiplication. If G is a public base point and k is a private scalar, the corresponding public point is:

Q = kG

The operation is easy to compute in the forward direction but computationally difficult to reverse: given G and Q, finding k is the elliptic-curve discrete logarithm problem.

In practice, developers should use standardized, well-reviewed curves and cryptographic libraries rather than implementing curve arithmetic themselves. Modern systems commonly use elliptic-curve Diffie–Hellman for key agreement and elliptic-curve digital signatures for authentication.

ECC Advantages and Cautions

ECC can provide security comparable to RSA with much smaller public keys and signatures. Smaller keys reduce bandwidth, certificate size, and storage requirements, which is valuable for mobile devices, embedded systems, and high-volume services. ECC implementations are nevertheless sensitive to invalid-curve attacks, nonce failures, side channels, poor parameter choices, and incompatible protocol profiles.

A major distinction is between ordinary elliptic-curve cryptography and particular protocols. ECDH is a key-agreement method; ECDSA is a signature method. One does not automatically replace the other.

5. Diffie–Hellman Key Exchange

Diffie–Hellman (DH) allows two parties to derive a common secret over a public channel without transmitting the secret itself. In a finite cyclic group, public parameters include a large prime p and a generator g.

Alice selects a private random value a and sends:

A = ga mod p

Bob selects b and sends:

B = gb mod p

Alice computes:

S = Ba mod p

Bob computes:

S = Ab mod p

Both values are equal because:

Ba = (gb)a = g^(ab) mod p

and:

Ab = (ga)b = g^(ab) mod p

The shared value should normally be processed through a key-derivation function (KDF), rather than used directly as an encryption key:

K = KDF(S, salt, context)

The variables salt and context provide protocol-specific separation and binding where required. The exact KDF and inputs must be defined by the protocol.

Illustrative DH Calculation

This small example is not secure. Let p = 23 and g = 5. Alice chooses a = 6, and Bob chooses b = 15.

A = 56 mod 23 = 8
B = 515 mod 23 = 19

Alice computes:

S = 196 mod 23 = 2

Bob computes:

S = 815 mod 23 = 2

The example demonstrates equality, but the small parameters can be attacked immediately.

Ephemeral and Static Keys

Ephemeral Diffie–Hellman uses a fresh private value for each session. Ephemeral ECDH or DHE can provide forward secrecy: compromise of a long-term authentication key does not automatically reveal previously established session keys, provided the ephemeral private values were erased and the protocol was correctly designed.

Static keys may simplify some deployments but can weaken forward secrecy and increase the consequences of key compromise. Modern secure protocols generally prefer authenticated ephemeral key exchange.

6. Hybrid Encryption

Hybrid encryption combines asymmetric and symmetric cryptography:

  1. Generate a fresh random symmetric data-encryption key.
  2. Encrypt the data using an authenticated symmetric algorithm, such as an authenticated-encryption mode.
  3. Protect or establish the symmetric key using public-key encryption or key agreement.
  4. Transmit the encrypted data, protected key material, nonce or initialization data, and authentication metadata.
  5. The recipient recovers the symmetric key and verifies before releasing plaintext.

Conceptually:

Cdata = AEADEncrypt(Ksession, nonce, plaintext, associateddata)

and, in an RSA-based design:

Ckey = RSAOAEPEncrypt(Kpub, Ksession)

The recipient first recovers Ksession, then verifies and decrypts the data. In a key-agreement design, both parties derive Ksession using a KDF.

Authenticated encryption provides confidentiality and integrity. Associated data may include headers or identifiers that must be authenticated but need not be encrypted. Nonces must satisfy the specific algorithm’s uniqueness requirements; nonce reuse can seriously undermine security in several authenticated-encryption modes.

Hybrid encryption is used in secure messaging, protected file exchange, web protocols, virtual private networks, and cloud key-wrapping systems. It is efficient because symmetric algorithms handle bulk data while asymmetric mechanisms solve the distribution and authentication problem.

7. Security Parameters and Algorithm Selection

Security strength is influenced by key size, algorithm design, implementation quality, and the expected attacker. Key sizes should not be compared merely by numerical bit length. A 256-bit elliptic-curve key does not mean exactly the same practical security as a 256-bit RSA modulus.

MechanismTypical contemporary roleMain consideration
RSACompatibility, certificates, signatures, key transportLarger keys and slower operations
Finite-field DHLegacy or specific protocol environmentsParameter validation and larger parameters
ECDHModern key agreementSmall keys, efficient exchange, implementation care
ECDSA or EdDSADigital signaturesCorrect nonce/randomness and ecosystem support
Symmetric AEADBulk encryptionKey secrecy and nonce discipline

Organizations should follow current guidance from recognized standards bodies and product-specific security policies. The correct choice depends on required security lifetime, interoperability, hardware capacity, regulatory obligations, and migration plans. Algorithms should be selected with an explicit cryptographic-agility strategy so that parameters can be upgraded without redesigning the entire system.

Classical and Quantum Considerations

RSA and finite-field DH rely on problems that are threatened by sufficiently capable quantum computers using Shor’s algorithm. ECC is threatened for the same broad reason. Symmetric cryptography is affected differently; Grover’s algorithm provides a quadratic speedup in idealized search, which is commonly addressed by selecting appropriately larger symmetric keys. Post-quantum cryptography is therefore an important migration area. Hybrid key-establishment mechanisms may be used during transition, but they must be standardized and carefully composed rather than improvised.

8. Performance and Deployment Trade-offs

Asymmetric operations involve substantially more computation than ordinary symmetric encryption. RSA public-key operations may be relatively fast with common public exponents, while private-key operations are more expensive. ECC generally offers smaller keys and lower communication overhead, although performance varies by curve, library, processor, and implementation.

Relevant deployment factors include:

  • Latency: handshake operations affect connection setup time.
  • Throughput: bulk traffic should use symmetric encryption.
  • Memory and bandwidth: smaller ECC keys benefit constrained devices.
  • Hardware acceleration: cryptographic accelerators may alter the practical comparison.
  • Library maturity: a theoretically efficient algorithm is not attractive if dependable support is unavailable.
  • Interoperability: certificates, protocols, operating systems, and clients must support the selected scheme.
  • Operational complexity: rotation, revocation, backup, recovery, and monitoring require resources.
  • Failure recovery: lost private keys may make protected data unrecoverable unless a governed recovery design exists.

Private keys should be generated in trusted environments, protected with hardware security modules or secure elements where appropriate, and excluded from logs. Key rotation must be planned according to risk, usage, and policy. Revocation and certificate-status mechanisms are important when identities or private keys may be compromised.

9. Certificates, PKI, and Trust

A certificate is a signed data structure that binds a public key to an identity or set of attributes. A certificate authority (CA) signs the certificate. A relying party validates the CA signature, validity period, intended use, name constraints, and trust chain.

PKI does not prove that an organization is trustworthy in every respect. It provides a mechanism for distributing and validating key-to-identity bindings under a defined trust policy. Certificate compromise, mis-issuance, weak validation, expired certificates, and incorrect hostname checking remain practical risks.

In enterprise environments, governance should specify who may issue certificates, how identities are verified, how private keys are protected, how certificates are renewed, and how incidents are handled. Access controls should distinguish certificate administration from application administration.

10. Common Failure Modes

Several failures recur across real systems:

  • Using raw RSA instead of OAEP or an approved signature scheme.
  • Reusing a signing nonce in ECDSA, potentially exposing the private key.
  • Failing to authenticate Diffie–Hellman, enabling man-in-the-middle attacks.
  • Reusing nonces with authenticated encryption.
  • Accepting invalid or malicious public points without validation where required.
  • Using predictable random values for keys or ephemeral secrets.
  • Storing private keys in source code, configuration files, or unprotected backups.
  • Treating encryption as a substitute for access control or endpoint security.
  • Selecting obsolete algorithms for new deployments.
  • Failing to test rotation, revocation, recovery, and algorithm migration.

The safest engineering practice is to use reputable, maintained libraries and high-level protocols, minimize custom cryptographic code, and obtain independent review for security-critical designs.

11. Illustrative Case Study: Protecting a Cloud File-Exchange Service

Background

A regional health organization exchanges sensitive reports with clinics through a cloud service. The files may contain personal and medical information. The service must support web clients, automated uploads, and long-term auditability.

Problem

The original design encrypts files with a single server-side symmetric key stored in an application configuration file. A compromise of the application server could expose all files. The system also lacks reliable key rotation and cannot demonstrate which recipient was authorized to decrypt a file.

Analysis

Bulk file encryption requires a symmetric algorithm for performance. However, one global key creates a large blast radius. The service needs separate per-file or per-object keys, controlled access, authenticated encryption, key protection, and audit records. Public-key mechanisms can protect data-encryption keys, but they do not replace authorization decisions.

Approach and Solution

For each file, the service generates a fresh random data-encryption key and encrypts the file with an approved AEAD scheme. Metadata such as file identifier and recipient identifier is supplied as associated data. The data key is then wrapped using a key-management service, which protects a suitable asymmetric key or uses an approved key-agreement and wrapping design. Access is granted only after authentication and authorization. Private key operations occur inside a managed cryptographic boundary where possible.

The service records key version, recipient, time, algorithm identifier, and successful or failed access events. Keys are rotated according to policy, while old versions remain available only for authorized decryption of objects that require them. Backups are encrypted and recovery procedures are tested.

Outcome

A compromise of one application component no longer directly reveals every file. Per-file keys reduce exposure, AEAD detects unauthorized modification, and centralized key management improves rotation and auditability. The design still requires secure client endpoints, correct identity management, monitoring, and tested incident response.

Learning Points

  1. Asymmetric cryptography is most useful for protecting keys and establishing sessions, not for bulk file encryption.
  2. Confidentiality must be combined with integrity and authentication.
  3. Key-management architecture often determines practical security more than the choice between two modern algorithms.
  4. Recovery, rotation, authorization, and auditability are part of cryptographic design.

12. Governance, Ethics, and Professional Practice

Strong encryption protects privacy, safety, and commercial information. It can also complicate lawful investigations and data recovery. Professionals must follow applicable privacy, records-management, export-control, sectoral, and incident-reporting requirements. Encryption should not be designed to conceal unauthorized surveillance, facilitate abuse, or bypass legitimate governance.

Data minimization is complementary to encryption: organizations should avoid collecting or retaining information unnecessarily. Access should follow least privilege, and cryptographic controls should be documented so that users understand what is protected, from which threats, and under which assumptions.

Best-Practice Checklist

  • Use standardized, currently supported algorithms and protocols.
  • Use authenticated encryption for data where appropriate.
  • Authenticate public keys and key exchanges.
  • Use ephemeral key exchange when forward secrecy is required.
  • Protect private keys with strong access controls and suitable hardware.
  • Use approved padding and encoding schemes; never invent them.
  • Obtain randomness from a cryptographically secure source.
  • Use KDFs for derived keys and separate keys by purpose.
  • Plan rotation, revocation, backup, recovery, and migration.
  • Test failure cases, downgrade resistance, and certificate validation.
  • Keep cryptographic libraries patched and monitor security advisories.

Chapter Summary

Asymmetric cryptography uses related public and private keys to support confidentiality, authentication, signatures, and key establishment. RSA is based on the difficulty of factoring large integers and requires secure padding such as OAEP for encryption and approved signature schemes for signing. ECC provides comparable security with smaller keys and is widely used for ECDH key agreement and modern signatures.

Diffie–Hellman enables two parties to derive a common secret without transmitting it directly, but it must be authenticated to resist man-in-the-middle attacks. Ephemeral key exchange can provide forward secrecy. Hybrid encryption combines asymmetric mechanisms for key protection or agreement with symmetric authenticated encryption for efficient bulk data protection.

Real security depends on parameter selection, randomness, key protection, certificate validation, implementation quality, lifecycle management, and governance. Performance, interoperability, hardware support, regulatory requirements, and future migration—including post-quantum planning—must inform deployment decisions.

Key Terms

Public key: A key distributed openly for encryption, verification, or key agreement.

Private key: A confidential key used for decryption, signing, or key agreement.

Asymmetric cryptography: Cryptography using mathematically related public and private keys.

RSA: A public-key algorithm based primarily on the difficulty of factoring a large composite integer.

Elliptic-curve cryptography: Public-key cryptography based on operations over elliptic curves in finite fields.

Diffie–Hellman: A protocol for establishing a shared secret over a public channel.

ECDH: Elliptic-curve Diffie–Hellman key agreement.

Digital signature: A private-key-generated value that supports integrity and authentication verification.

Forward secrecy: Protection of past session keys after compromise of a long-term key.

Hybrid encryption: A design combining asymmetric key protection or agreement with symmetric data encryption.

KDF: Key-derivation function that converts secret material into keys for defined purposes.

AEAD: Authenticated encryption with associated data.

Nonce: A value used according to an algorithm’s uniqueness requirements, often with encryption.

PKI: Public-key infrastructure for issuing, distributing, validating, and revoking certificates.

Certificate: A signed binding between a public key and an identity or defined attributes.

Certificate authority: An entity trusted to issue or sign certificates.

Key rotation: Replacement of keys according to a schedule or security event.

Cryptographic agility: The ability to replace algorithms or parameters without major system redesign.

Post-quantum cryptography: Cryptography designed to resist attacks from quantum-capable adversaries.

Review Questions

Short Answer Questions

  1. What is the difference between a public key and a private key?
  2. Why is raw textbook RSA unsuitable for modern encryption?
  3. What problem does Diffie–Hellman solve?
  4. Why are symmetric algorithms used for bulk data in hybrid encryption?
  5. What is forward secrecy?

Long Answer Questions

  1. Explain RSA key generation and identify the purpose of the modulus, public exponent, and private exponent.
  2. Compare RSA and ECC in terms of security assumptions, key sizes, performance, and deployment.
  3. Explain how an unauthenticated Diffie–Hellman exchange is vulnerable to a man-in-the-middle attack.
  4. Describe a complete hybrid-encryption workflow for a secure file-transfer system.
  5. Discuss the operational responsibilities involved in managing certificates and private keys.

Analytical / Application Questions

  1. A company encrypts all customer files with one symmetric key stored on an application server. Analyze the risks and design a safer architecture using per-object keys and asymmetric protection.
  2. An organization is choosing between RSA and ECDH for a mobile application with limited bandwidth. Evaluate the relevant technical and operational trade-offs and justify a recommendation.
  3. A security review discovers that a system uses fresh RSA keys but does not authenticate exchanged public keys. Identify the likely attack and propose controls that address identity, integrity, and key lifecycle management.

Multiple Choice Questions with Answers

Question 1

Which key is normally used to encrypt a message intended for a recipient in a public-key encryption system?

A. The sender’s private key

B. The recipient’s public key

C. The recipient’s private key

D. A publicly shared symmetric key

Correct Answer: B. The recipient’s public key

Question 2

What is the primary mathematical problem associated with conventional RSA security?

A. Factoring a large composite integer

B. Finding a collision in a hash function only

C. Solving a linear equation

D. Recovering a nonce from plaintext

Correct Answer: A. Factoring a large composite integer

Question 3

Why should textbook RSA not be used directly for modern encryption?

A. It cannot represent numbers

B. It is deterministic and lacks secure padding

C. It requires no public key

D. It is a symmetric algorithm

Correct Answer: B. It is deterministic and lacks secure padding

Question 4

In Diffie–Hellman key exchange, what do both parties derive?

A. The other party’s private exponent

B. The same shared secret

C. A shared plaintext message

D. The same private key file

Correct Answer: B. The same shared secret

Question 5

What is a major danger of unauthenticated Diffie–Hellman?

A. Compression failure

B. Man-in-the-middle attack

C. Automatic key recovery

D. Loss of symmetric-key speed

Correct Answer: B. Man-in-the-middle attack

Question 6

Which mechanism is generally best suited to encrypting a large file efficiently?

A. Symmetric authenticated encryption

B. Raw RSA exponentiation

C. A certificate signature

D. A public-key certificate alone

Correct Answer: A. Symmetric authenticated encryption

Question 7

What does forward secrecy primarily protect?

A. Past session contents after later compromise of a long-term key

B. The availability of a certificate authority

C. The secrecy of a public key

D. The speed of bulk encryption

Correct Answer: A. Past session contents after later compromise of a long-term key

Question 8

In ECC, a public point is commonly calculated from a private scalar using which operation?

A. Scalar multiplication of a base point

B. RSA padding

C. Certificate revocation

D. Symmetric decryption

Correct Answer: A. Scalar multiplication of a base point

Question 9

What is the principal role of a certificate authority in PKI?

A. To encrypt every application message

B. To bind public keys to identities through signed certificates

C. To generate all users’ passwords

D. To replace endpoint authorization

Correct Answer: B. To bind public keys to identities through signed certificates

Question 10

Why is a key-derivation function commonly applied to a Diffie–Hellman shared value?

A. To publish the private exponent

B. To derive properly separated keys for defined protocol purposes

C. To make the public key smaller

D. To eliminate the need for authentication

Correct Answer: B. To derive properly separated keys for defined protocol purposes

Cryptography & Data Protection
Chapter 4 of 15