Chapter 3 Public Key Crypto Digital Sign and Cert
Chapter 3 Public Key Crypto Digital Sign and Cert
1
Outline
• Public and Private Keys
• Public Key Cryptography
• RSA Security
• Diffie-Hellman Algorithm
• Message authentication, Security
requirements
• Digital Signature Using Public Key
• Digital Signature Using Message Digest
• Digital certificates
• Distribution of public keys
2
Asymmetric Encryption
Decrypt Encrypt
3
Public and Private Keys
• With asymmetric encryption each user can be
assigned a key pair: a private and public key
4
Public and Private keys…
• Anything encrypted with
the private key can only
be decrypted with the
public key Encrypt
• And vice versa
• Since the private key is
known only to the owner,
this is very powerful…
• Overcomes the problem
of looking for secured Decrypt
channel.
5
Public Key Cryptography…
Public key Cryptography
• One of the encryption or decryption key is made
public depends on the use of the key.
If Abe wants to send a confidential message to Selam
He encrypts the message using Selam’s public key
Send the message
Selam will then decode it using her own private key
On the other hand, if Selam needs to make sure that a
message sent by Abe really comes from him, how can she
make that?
6
Public Key Cryptography…
• Using digital signature
Abe has to first encrypt a digital signature using his private
key.
Then encrypt the message (signature included) with
Selam’s public key.
Send the encrypted message to Selam.
7
Public Key Cryptography and RSA
RSA
• Major Activities
- Key Generation
- Encryption
- Digital signature
- Decryption
- Signature verification
9
Asymmetric RSA
Key Generation Algorithm
1. Generate two large random primes, p and q
2. Compute n = pq and (φ) phi = (p-1)(q-1)
3. Choose an integer e, 1 < e < φ, such that gcd(e, phi) = 1
4. Compute the secret exponent d, 1 < d < φ, such that
d = e-1 mod φ , i.e. φ divides (ed-1)
5. The public key is (n, e) and the private key is (n, d).
Keep all the values d, p, q and φ secret
n is known as the modulus
e is known as the public exponent or encryption exponent
d is known as the secret exponent or decryption exponent.
10
Asymmetric RSA
Encryption and Decryption
Encryption
• Sender A does the following
- Obtains the recipient B's public key (n, e)
- Represents the plaintext message as a positive integer m
- Computes the ciphertext c = me mod n
- Sends the ciphertext c to B
Decryption
• Recipient B does the following
- Uses his private key (n, d) to compute m = cd mod n
- Extracts the plaintext from the message representative m
11
Asymmetric RSA
Digital signature and signature verification
Digital signature
• Sender A does the following
- Creates a message digest of the information to be sent
- Represents this digest as an integer m between 0 and n - 1
- Uses his/her private key (n, d) to compute the signature
s = md mod n.
- Sends this signature s to the recipient, B.
Signature verification
• Recipient B does the following
- Uses sender A's public key (n, e) to compute integer v = se mod n
- Extracts the message digest from this integer
- Independently computes the message digest of the information that has been
signed
- If both message digests are identical, the signature is valid
12
Asymmetric RSA
Key Generation example
1. Select primes p=11, q=3.
2. n = pq = 11*3 = 33
phi = (p-1)(q-1) = 10*2 = 20
3. Choose e=3
Check gcd(e, p-1) = gcd(3, 10) = 1 (i.e. 3 and 10 are relatively prime -
have no common factors except 1) and check gcd(e, q-1) = gcd(3, 2) = 1,
therefore gcd(e, phi) = gcd(e, (p-1)(q-1)) = gcd(3, 20) = 1
13
Asymmetric RSA
Encryption and Decryption example
• Given
Public key = (n, e) = (33, 3)
Private key = (n, d) = (33, 7)
Encryption
• Now say we want to encrypt the message m = 7
- c = me mod n = 73 mod 33 = 343 mod 33 = 13
- Hence the ciphertext c = 13
Decryption
• To check decryption we compute
- m = cd mod n = 137 mod 33 = 7
14
RSA algorithm example
15
RSA Example - Key Setup
17
RSA
Algorithm
Summary
18
The Security of RSA
• Approaches to attack the RSA algorithm are:
• Brute force: This involves trying all possible private keys.
19
Speed of RSA
• In hardware, RSA is about 1000 times slower
than DES.
20
The Diffie-Hellman Algorithm for generating
a shared secret session key
21
Diffie-Hellman Key Exchange Algorithm
• a public-key distribution scheme
– cannot be used to exchange an arbitrary message
– rather it can establish a common key
– known only to the two participants
• value of key depends on the participants (and their
private and public key information)
• based on exponentiation in a finite field (modulo a
prime or a polynomial) - easy
• security relies on the difficulty of computing discrete
logarithms (similar to factoring) – hard
22
The Diffie-Hellman Algorithm for generating
a shared secret session key
• The pair of numbers (q, α) is public.
• This pair of numbers may be used for several runs of the
protocol.
• These two numbers may even stay the same for a large
number of users for a long period of time.
• Subsequently, A and B use the algorithm described below
to calculate their public keys that are then made available
by each party to the other:
– We will denote A’s and B’s private keys by XA and XB.
– And their public keys by YA and YB.
– In other words, X stands for private and Y for public.
23
The Diffie-Hellman Algorithm for generating
a shared secret session key
• A selects a random number XA from the set {1, 2, . . . , q − 2} to
serve as his/her private key.
• A then calculates a public-key integer YA that is guaranteed to exist:
YA = αXA mod q
• A makes the public key YA available to B.
• Similarly, B selects a random number XB from the set
{1, 2, . . . , q − 2} to serve as his/her private key.
• B then calculates an integer YB that serves his/her public key:
YB = αXB mod q
• B makes the public-key YB available to A.
24
The Diffie-Hellman Algorithm for generating
a shared secret session key
• A now calculates the secret key K from his/her private
key XA and B’s public key YB :
K = (YB)XA mod q
K = (YA)XB mod q
25
Diffie-Hellman Key Exchange
• shared session key for users A & B is KAB:
KAB = αxA.xB mod q
= yAxB mod q (which B can compute)
= yBxA mod q (which A can compute)
• KAB is used as session key in private-key
encryption scheme between Alice and Bob
• if Alice and Bob subsequently communicate, they
will have the same key as before, unless they
choose new public-keys
• attacker needs an x, must solve discrete log
26
Diffie-Hellman Example
• users Alice & Bob who wish to swap keys:
• agree on prime q=353 and α=3
• select random secret keys:
– A chooses xA=97, B chooses xB=233
• compute public keys:
– yA=397 mod 353 = 40 (Alice)
– yB=3233 mod 353 = 248 (Bob)
• compute shared session key as:
KAB= yBxA mod 353 = 24897 mod 353= 160 (Alice)
KAB= yAxB mod 353 = 40233 mod 353= 160 (Bob)
27
The Diffie-Hellman Algorithm with key
exchange
28
The Diffie-Hellman Algorithm Security
29
The Diffie-Hellman Algorithm Security
30
Digital Signatures and Digital
Certificates
31
Message Authentication
• Up till now, we have been concerned with protecting
message content (i.e secrecy) by encrypting the message.
32
Message Authentication…
• Message authentication is concerned with:
– Protecting the integrity of a message
– Validating identity of originator
– Non-repudiation of origin (dispute resolution)
33
Security Requirements
• In the context of communications across a network, the
following attacks can be identified:
• Disclosure: Release of message contents to any person or
process not possessing the appropriate cryptographic key.
34
Security Requirements
• Content modification: Changes to the contents of a message,
including insertion, deletion, transposition, and modification.
35
Security Requirements
• disclosure Belongs to message confidentiality, and are
handled using the encryption techniques already
• traffic analysis discussed.
36
Message Encryption
– E.g. DES,3DES,...
37
Message Encryption…
38
Authentication using session-key
• If a message is being encrypted using a session key known
only to the sender and receiver, then the message may
also be authenticated.
– since only sender or receiver could have created it
– any interference will corrupt the message
– but this does not provide non-repudiation since it is
impossible to prove who created the message
• E.g. DH
39
Digital Signature
• Digital signatures allow the world
to verify I created a piece of data
– e.g. email, code
40
Why Digital Signatures?
41
Digital Signature using pubic key
cryptography (RSA)
• RSA may be used directly as a digital signature scheme
– given an RSA scheme {(e,n), (d,n)}
• To sign a message, compute:
– s = md(mod n)
• To verify a signature, compute:
– m = se(mod n) = me.d(mod n)
• Thus know the message was signed by the owner of the
public-key.
• More commonly use a hash function to create a separate
Message Digest (MD) which is then signed.
42
Hash Function Properties
• a Hash Function produces a fingerprint of some file/message/data
h = H(M)
– condenses a variable-length message M
– to a fixed-sized fingerprint h
-
the length of h must be at least 128 bits.
-
given M, it must be easy to calculate H(M) = h
-
given h, it must be difficult to calculate M = H-1(h)
-
given M, it must be difficult to find M’ such that H(M) = H(M’)
• Examples:
●
SNEFRU: hash of 128 or 256 bits;
●
MD4/MD5: hash of 128 bits;
●
SHA : hash of 160,256 bits.
• assumed to be public
43
Digital Signatures – Authentication
using hash function
• Abe calculates the hash of the
message: a 128 bit value based on
Abe
the content of the message
• Abe encrypts the hash using his
private key: the encrypted hash is message
message Hash A
the digital signature.
• Abe sends the signed message to Digital Signature
Digital Signature
Kebe.
• Kebe calculates the hash of the
message
• Decrypts A with Abe’s public key. Kebe
45
Key Distribution: Problems
• Distribution of a key is a difficult matter!
46
Key Management
47
Using public keys to exchange secrete
session keys
• Public key cryptography fulfills an extremely important
role in the overall design and operation of secure
computer net-works.
– because it leads to superior protocols for managing and
distributing secret session keys
– that can subsequently be used for the encryption of actual
message content using symmetric-key algorithms such as
3DES, AES, etc..
48
Using public keys to exchange secrete
session keys…
Scenario 1
• If party A simply wants to receive all communications
confidentially
– meaning that A does not want anyone to snoop on the incoming
message traffic and
– A is not worried about the authenticity of the messages received,
• all that A has to do is to publish his/her public key in some
publicly accessible place (such as on a web page).
• Subsequently, anyone wanting to send a confidential message
to A would encrypt that message with A’s public key.
• Only A would be able to decrypt such messages.
49
Using public keys to exchange secrete
session keys…
• If two parties A and B are sure about each other’s identity, and can be
certain that a third party will not masquerade,
– they can use a simple and direct key exchange protocol for
exchanging a secret session key. ( Scenario 2)
• In general, such protocols will not require support from any
coordinating or certificating agencies.
• The key exchange protocols are more complex for security that
provides a higher level of either one-sided or mutual authenti- cation
between two communicating parties.
• These protocols usually involve Certificate Authorities.
Scenario 3
50
A direct key exchange protocol
(Scenario 2)
• If each of the two parties A and B has full confidence that
a message received from the other party is indeed
authentic,
• the exchange of the secret session key for a symmetric-key
based secure communication link can be carried out with a
simple protocol such as the one described below:
53
A direct key exchange protocol…
• This transmission from B is again intercepted by E, who for
obvious reasons is able to decode the message.
• E now encodes the secret key KS with A’s public key PUA
and sends the encoded message back to A.
• A retrieves the secret key and, not suspecting any foul
play, starts communicating with B using the secret key.
• E can now successfully eavesdrop on all communications
between A and B.
54
Certificate Authorities for authenticating
your public key
• A certificate issued by a certificate authority (CA)
authenticates your public key.
– A certificate is your public key signed by the CA’s private key.
• A certificate assigned to a user consists of:
– The user’s public key,
– the identifier of the key owner,
– a time stamp (in the form of a period of validity), etc.,
55
Certificate Authorities for authenticating
your public key…
• We may therefore express a certificate issued to party A by
CA = E (PRCA, [T, IDA, PUA])
– where PRCA is the private key of the Certificate Authority,
– T the expiration date/time for the A’s public key PUA that is being
validated by the CA, and
– IDA the party A’s identifier.
58
Using Authenticated Public Keys to Exchange a
Secret Session Key
• Having acquired the public keys, the two parties A and B then
proceed to exchange a secret session key.
Party A Party B
59
Using Authenticated Public Keys to
Exchange a Secret Session Key…
• A uses B’s public key PUB to encrypt a message that contains A’s
identifier IDA and a nonce N1 as a transaction identifier.
• A sends this encrypted message to B.
• This message can be ex-pressed as
E (PUB, [N1, IDA])
• B responds back with a message encrypted using A’s public key
PUA, the message containing A’s nonce N1 and new nonce N2
from B to A.
• The structure of this message can be expressed as
E (PUA, [N1, N2])
60
Using Authenticated Public Keys to Exchange a
Secret Session Key…
• Since only B could have decrypted the first message from A to B, the
presence of the nonce N1 in this response from B further assures A
that the responding party is actually B
– since only B could have decrypted the original message containing the nonce N1.
61
Using Authenticated Public Keys to
Exchange a Secret Session Key…
• Further encryption with B’s public key means that only B will be
able to read it.
• B decrypts the message first with its own private key PRB and
then recovers the secret key by applying another round of
decryption using A public key PUA.
62
63
The X.509 Certificate format standard for
Public Key Infrastructure
• The set of standards related to the creation, distribution,
use, and revocation of digital certificates is referred to as
the Public Key Infrastructure (PKI).
• X.509 is one of the PKI standards.
– It is this standard that specifies the format of digital certificates.
• The X.509 standard is described in the IETF document RFC 5280,
RFC 6818.
• The X.509 standard is based on a strict hierarchical organization
of the CAs in which the trust can only flow downwards.
• The CAs at the top of the hierarchy are known as root CAs.
• The CAs below the root are generally referred to as intermediate-
level CAs.
64
Role of a PKI
• Create…
… Manage…
… Store…
… Distribute and revoke
certificates !
• For:
– Authentication, Integrity, Confidentiality, Non-
repudiation, (access control)
65
Delegation of authority
66
67
X.509 Certificate Format
• Version Number: describes the
version of the X.509 standard to
which the certificate corresponds.
• Serial Number: This is the serial
number assigned to a certificate by
the CA.
• Signature Algorithm ID: This is the
name of the digital signature
algorithm used to sign the certificate.
(MD5,SHA)
• Issuer Name: This is the name of
the Certificate Authority that issued
this certificate.
• Validity Period: This field states the
time period during which the
certificate is valid.
• Subject Name: This field identifies
the individual/organization to which 68
the certificate was issued.
X.509 Certificate Format
• Subject Public Key: This field
presents the public key that is
meant to be authenticated by this
certificate.
– This field also names the algorithm
used for public-key generation.
• Issuer Unique Identifier:
(optional)With the help of this
identifier, two or more different CA’s
can operate as logically a single CA.
– The Issuer Name field will be
distinct for each such CA but they
will share the same value for the
Issuer Unique Identifier.
• Subject Unique Identifier:
(optional) With the help of this
identifier, two or more different
certificate holders can act as a single
logical entity. 69
X.509 Certificate Format
• Each holder will have a different
value for the Subject Name field
but they will share the same value
for the Subject Unique Identifier
field.
• Extensions: (optional) This field
allows a CA to add additional private
information to a certificate.
• Signature: This field contains the
signature of the CA that issued the
certificate.
– This signature is obtained by first
computing a message digest
from the rest of the fields with a
hashing algorithm like SHA-1,
– Then CA will encrypt MD using
private key Signature
70
The X.509 Certificate format standard for Public
Key Infrastructure
• The digital representation of an X.509 certificate, described in RFC 5280, is
created by first using the following ASN.1 representation to generate a byte
stream for the certificate and converting the byte stream into a printable form
with Base64 encoding.
Certificate ::= SEQUENCE {
71
The X.509 Certificate format standard for
Public Key Infrastructure
72
The X.509 Certificate format standard for
Public Key Infrastructure
• It is the hash of the bytestream that corresponds to what is
stored for the field TBSCertificate that is encrypted by the CA’s
private key for the digital signature that then becomes the value
of the signatureValue field.
73
The X.509 Certificate format standard for
Public Key Infrastructure
• Shown below is an example of a certificate in Base64
representation and it resides in a file whose name carries the
“.pem” suffix.
74
The X.509 Certificate format standard for
Public Key Infrastructure
• Ordinarily you would request a CA for a certificate for your
public key.
• But that does not prevent you from generating your own
certificates for testing purposes.
openssl> req -new -newkey rsa:1024 -days 365 -nodes -x509 -keyout
test.pem -out test.cert
• Where the first argument req to openssl is for generating an X509 certificate
• You can also use OpenSSL to make your own organization a CA.
• Visit http://sandbox.rulemaker.net/ngps/m2/howto.ca.html to find out how
you can do it.
75
Public-Key Certification
User Certificate
Serial No.
Certificate
User Database
Name & User Name
other
credentials User’s Email
Signed Address
Signed
by using
Certificate by using
CA’s
License issued
by CCA
Request CA’s User’s Publish
private
private Public Key
key
User’s key User 1 certificate
Public CA’s Name
key User 2 certificate
Certificate .
Class
Public
Public
Private Validity Web site of CA
Digital
Signature
of CA
Key pair 76
Generation
Digital Certificates
• Types of Digital Certificates
– site certificates
• used to authenticate web servers
– personal certificates
• used to authenticate individual users
– software publishers certificates
• used to authenticate executable
– CA certificates
• used to authenticate CA’s public keys
77
s t
L a
h e
T