5-RSA Stuff
5-RSA Stuff
5-RSA Stuff
Example pp. 278-279 of Singh (1999): Scientific American (Martin Gardner) published a
challenge in 1997 to factor a number N with 129 digits. Solution found by team of 600 people
in 1994. In solution p and q were 64- and 65-digit primes.
1
I.e. ed = k(p 1)(q 1) + 1, k integer.
Here: 7d mod — 32 = 1 −
giving d = 23.
Show this: 7 . 23 = 161. 161/32 = 5 + remainder 1. Consequently we see that 161 mod
32 = 1.
– Next define the public key: (e, n) = (7, 51).
– Say, message is M = 2.
– Ciphertext, C = Me mod n = 27 mod 51 = 128 mod 51 = 26.
– Decipherment requires knowledge of (d, n). I.e. (23, 51).
– Then: M = Cd mod n = 2623 mod 51.
But how do we solve this?!
– One thing we can do is factorize as follows:
2623 mod 51 = (261.262.264.2616) mod 51
We know that ab mod n = (a mod n . b mod n) mod n.
So this implies:
(261.262.264.2616) mod 51 = 26 mod 51 . 676 mod 51 . 264 mod 51 . 2616 mod 51) mod 51
(We’ve left some parts unresolved for the moment. Now we’ll use: 676 = 51 . 13 +
remainder 13)
= (26.13.((13.13) mod 51).(2616 mod 51)) mod 51
(Now we’ll use: 13 . 13 = 169. 169 mod 51 = 16.)
= (26.13.16.((16.16.16.16) mod 51)) mod 51
= (26.13.16.((16.16) mod 51).((16.16) mod 51)) mod 51
(Now use: 16 . 16 = 256. 256 mod 51 = 1.)
= (26.13.16.1.1) mod 51
(Just multiply this out. 26 . 13 . 16 = 5408. We find that this equals 51 . 106 with
remainder 2.)
= 2.
This is of course our input message, M = 2.
We certainly need a better way to solve such an equation. We will write a little program
which will do this for us.
2
Example of back-substitution.
Take [1] r(2) = a(3).r(3) + r(4) = r(4) = r(2) a(3).r(3).
Now r(1) = a(2).r(2) + r(3) = r(3) ⇒ = r(1) a(2).r(2)
−
Back to [1]: ⇒ −
r(4) = r(2) a(3).r(1) + a(2).a(3).r(2) = r(4) = r(2) 1.7 + 1.1.r(2)
—
Now r(0) = a(1).r(1) + r(2) = r(2) = r(0)⇒ a(1).r(1) =− r(2) = 32 4.7 = r(2) = 4
⇒
So, r(4) = r(0) a(1).r(1) a(3).r(1) −
+ a(2).a(3)[r(0) ⇒
a(1).r(1)] = −
—
r(4) = r(0)[1 + a(2).a(3)] −
+ r(1)[ −
a(1) a(3) a(1).a(2).a(3)] =
r(4) = r(0)[1 + 1.1] + r(1)[ 4 1— 1.1.4] − = −
r(4) = r(0).2 + r(1).( 9) — − −
So now we finally have − our value, 9. Are we right? We have r(0) = 32, r(1) =
7, and r(4) = 1. So we are right. −
But a positive number is needed (unless we want to deal with very small fractions). We
are working in an arithmetic modulo φ, i.e. modulo 32. We know that 9 23 mod 32 which
—
is what we are looking for. This was the value used in the example previously..
RSA Example 3
– 2 primes, p, q. p = 7,q = 17.
– n = pq: 7 x 17 = 119 = n.
– φ(n) = (p 1)(q 1) = 6 16 = 96.
– e relatively —
prime − × than φ(n), greater than 3. Take e = 5.
to φ(n), less
– d s.t. ed = 1 mod 96 and d < 96. Find d = 77 (because 77 5 = 385 = 4 96 + 14).
– Public key = (e, n) = (5, 119). × ×
Private key = (d, n) = (77, 119).
– Plaintext input message: M = 19.
– Ciphertext, C = Me(mod n) = 195(mod 119) = 2476099 mod 119 = 66.
– Decryption: M = Cd(mod n) = 6677(mod 119) = 19.
– Best to have a little program to solve these equations! We’ll look now at an algorithm.
3
Review
DES, IDEAL etc. use symmetric keys
I.e. same key for E and for D
With public key systems, you create KE and
KD KE is public, available to anyone
KD is private, available to you only
Key length is short, e.g. 56
compared to key lengths in public systems
4
Σ
k
b 2i k
i
Therefore: am i=
a =
(Read: product over i = 0, 2, . . . k of a to the power of bi 2i .)
For the example of a17:
4 3 2 1 0 4 3 2 1 0
a1×2 +0×2 +0×2 +0×2 +1×2 = a1×2 ×a0×2 ×a0×2 ×a0×2 ×a1×2 .
So, now, finally:
i i
am mod n = [Πk abi 2 ] mod n = (Πk [abi 2 mod n]) mod n.
i i
Here we are generalizing: (ab) mod n = [(a mod n)(b mod n)] mod n.
Algorithm:
c → 0; d → 1;
for i → k downto 0{
c → 2 × c;
d → (d × d) mod n;
if bi = 1 then {
c → c + 1;
d → (d × a) mod n;
}
}
return d
bi 1 0 0 0 1 1 0 0 0 0
c 2.0 + 1 2.1 2.2 2.4 2.8 + 1 2.17 + 1 2.35 2.70 2.140 2.280
= 1 = 2 =4 = 8 = 17 = 35 = 70 = 140 = 280 = 560
5
– Divisible by 2? No. Keep 3.
– Add 1.
– Divisible by 2, 3? Yes for 2. Reject.
– Etc. Not too practical for large primes.
– Note: there are “weak” and “strong” prime numbers for RSA.
El Gamal encryption
– Based on discrete logarithm problem (which we will not discuss).
– Unlike RSA, El Gamal encryption has public parameters which are shared between a
number of users. They are called domain parameters.
• p, a large prime, around 1024 bits,
• p − 1 is divisible by another prime, q, of around 160 bits,
• g such that g(p−1)/q mod p ⊕=
1. Then, one creates
• private key, x, an integer,
• public key, h = gx mod p.
– Note: in RSA two large primes are needed. In El Gamal, a random number is needed,
plus a modular exponentiation.
– To encrypt a message, m (also in mod p)
• generate a random ephemeral key, k,
• set c1 = gk
• set c2 = mhk
• which gives ciphertext c = (c1, c2).
6
– Each message has a different ephemeral key, so encrypting the same message twice
will produce different ciphertexts.
– To decrypt a ciphertext c = (c1, c2):
c2/cx = mhk/gxk = mgxk/gxk = m all with modulus p.
1
– Example: p = 809,q = 101,g = 3
– Aside: recall that Fermat’s Little Theorem states that if p is prime, and a is a positive
integer not divisible by p, then it holds: ap−1 1 mod p, and hence 3808 1 mod p.
– For public and private keys, choose: x =≡68, and h = gx mod p = 368 ≡mod 809 = 65.
(Exercise: check this.)
– Encrypt a message, m = 100.
– Generate a random ephemeral key, k = 89.
– c1 = gk mod p = 389 mod 809 = 345. (Exercise: check this.)
– c2 = mhk mod p = 100(6589 mod 809) mod p = 100 709 mod p = 517. (Exercise:
check this.) ×
– Ciphertext, c = (345, 517).
– Decryption: c2/cx = 517/34568 = 517/709. (Exercise: check this.)
1
– Here we look a bit stuck. Let’s see... what is 709−1 mod 809? We see that we need the
multiplicative inverse of 709 modulo 809.
– What is 2−1 mod 5? Answer is 3, since 2 3 = 6 1 mod 5.
– Here is how we solve this. We first determine × gcd(709,
≡ 809) using the Euclid algorithm.
Do this. We solve for gcd(809, 709):
809 = 1 709 + 100 gcd(709, 100)
709 = 7 ×100 + 9 gcd(100, 9)
100 = 11 × 9 + 1
So gcd(809,×709) = 1 (hence these numbers are relatively prime).
Now we seek the linear combination d = ua + vb for d = gcd(a, b).
We back-substitute from the Euclid algorithm in order to do this:
1 = 100 11 9
= 809 1 — 709 × 11(709 7 100)
= 809 —1 ×709 −11 709−+ 77(809 1 709)
= 809 12 709 + 77 × 809 77 709
— × − −
—
= 78 809 89 709× × − ×
×
(Excercise: − this.)
check ×
From this, we read off the multiplicative inverse of 709 with modulus 809, i.e. 709−1 mod
809 = 89.
We −need a positive integer, so knowing that 1 809 = 720 89 we find the solution as
720. — × −
Good, now back to solving 517/709 mod 809.
We have 517/709 mod 809 = 517×709−1 mod 809 = [(517 mod 809)(709−1 mod 809)] mod
809 = 517 × 720 mod 809 = 100. QED.
– Another version of El Gamal uses elliptical functions. (We won’t deal with these.)
– Rabin encryption: based on the difficulty of extracting square root modulo n = pq.
Authentication
1. Message confidentiality
– Disclosure
– Traffic analysis
2. Message authentication
– Masquerade
– Content modification
– Sequence modification
– Timing modification
7
3. Digital signature
– Repudiation
Alternative based on hash functions: hash code can be appended to message and then all
encrypted.
Simple hash function:
ci = bi1 ⊕ bi2 . . . ⊕ bim
ci is ith bit of block.
b is block, ⊕ is XOR.
Fixed length public function key
D.S. – – Y
MAC Y Y Y
Hash Y Y –
Informally, we could say that D.S. is to check human violation, MAC is to check
“technical” and human violation, and Hash is to check “technical” violation.
8
Hash functions
– Basic properties include:
– 1. Ease of computation.
– 2. Compression. h(x) is of fixed length.
– 3. Pre-image resistance. Given y, it is difficult to find x s.t. h(x) = y.
– 4. Weak collision resistence. Difficult to find x and xJ, x xJ s.t. h(x) = h(xJ).
– 5. Strong collision resistence. Infeasible to find...
– Points 1 to 4 lead to one-way hash function. Point 5 leads to a collision-resistent hash
function.
– Output of hash function: hash value, message digest, checksum.
– Examples: SHA-1 (Secure Hash Algorithm 1), MD4, MD5. SHA-1 processes 512-bit
blocks and generates 160-bit hash values.
– 80 rounds of processing on five 32-bit inputs. Combinations of AND, OR, NOT and
XOR operations used.
– See Stallings.
– Rivest’s MD5, Message Digest Algorithm.
– Arbitrary length message is mapped into 128-bit hash (“fingerprint of message digest”).
– Seek:
(1) “Impossible” to find 2 messages which produce same result.
(2) “Impossible” to generate a message that will produce a predefined hash result.
– Estimated that the number of operations required to generate two messages that
produce the same MD is 264.
– Complexity of finding a message with a predefined MD is 2128.
9
– Translate this to the area of hash functions: for a given length of hash code, n, and a
given number of attempts at cracking it, r, we find a particular probability, p.
– For the probability of cracking the hash code to be less than 10 −6 after 255 attempts,
then we must have n > 2128. I.e., hash code length, n, must be at least 128 bits.
– We can use DES as a hash function.
– Message, M, is enciphered with DES and a secret key.
– Result is added to M, modulo 2.
– Key for subsequent blocks could be defined from the hash function. If the hash function
is based on a specified number of bits, then these can be read off (e.g., from the left of the
final outcome).
A B
Step 1 Secret key chosen, e.g. 3 Secret key chosen, e.g. 6
Step 2 Encrypt: 73(mod11) Encrypt: 76(mod11)
= 343 mod 11 = 2 = 117649 mod 11 = 4
Step 3 A sends 2 to B B sends 4 to A
Step 4 Works out: 43(mod11) Works out: 26(mod11)
= 64 mod 11 = 9 = 64 mod 11 = 9
10
Hence they have ended up with one and the same key.
One could say that a secret key has been established by public
discussion. Diffie-Hellman-Merkle key exchange protocol.
Alice Bob
a ga −→ ga
gb ←− gb b
– Ephemeral “secrets”, a, b.
– Alice can compute K = (gb)a since she knows a and was sent gb by Bob.
– Bob can also compute K = (ga)b since he knows b and was sent ga by Alice.
– Attacker Eve can see ga, gb and needs to recover K = gab. Not easy!
– Another example: p = 2147483659, g = 2.
Alice Bob
a = 12345 b = 654323
A = ga = 428647416 given to Bob A
B Given to Alice by Bob B = gb = 450904856
Digital signature
– To authenticate the sender.
– Let the sender encrypt a message using his/her private key.
(Not a good idea in principle, since anyone can decrypt this using the sender’s known –
axiomatically – public key.)
– Then decrypt using the sender’s public key.
We know therefore that it could only have come from them.
– This is a public key system in reverse!
– Used e.g. for authentication of software.
11
Left → right Encryption: Decryption:
You use: my public key I use: my private key
– We could use RSA for both data and the digital signature:
– Before A sends message, a digital signature is added which is encrypted with A’s
private key, SA. (S = secret.)
– Then encrypted with public key of B, PB .
– Sent.
– B then decrypts using SB .
– Authenticates using A’s public key, PA.
– Overall: PA SB PB SA (M)
– Hash function may precede use of RSA to make for compact set of data.
– Key pair: anyone who wishes to sign messages or to receive encrypted messages must
have a key pair.
– Companies may use one or more pairs for encryption – maybe keys stored under key
escrow to safeguard the key in event of loss, maybe a single key non-escrowed for authentica-
tion.
– Key escrow.
12
– User can generate own key pair, or company officer. Kerberos is a secret-key authenti-
cation system, which uses a central server to generate keys.
– After key pair generation, a user must register the public key with a central
administra- tion called a Certifying Authority, CA. The CA returns a certificate attesting to
– Kerberos
the validity of the user’s public key.
Certificates
– Certificates: digital documents attesting to the binding of a public key to an individual
or other entity. In some cases, there may be a chain of certificates, each one certifying the
previous one.
– In simplest form, certificates contain a public key and a name. Also: expiration date,
name of CA, digital signature of the certificate issuer. Most widely used format for certificates
is X.509.
13
– Certificates typically used to generate confidence in the legitimacy of the public key.
They are a type of digital signature which protect keys from forgery, false representation, or
alteration. Verification can be performed with greater or lesser rigour.
– Could associate one or more certificates with every signed message. Alternative is a
hierarchical certificate chain, with one certificate testifying to the authenticity of the
previous certificate. A top level certifying authority is trusted without a certificate from any
other certifying authority.
– Examples of CAs: Baltimore Technologies, RSA Security, VeriSign. Or a CA protocol
is found in Apple’s Mac System 7.5.
– Preventing attacks on CAs: extensive cryptanalytic attack is preempted by regular key
change; if an old key is broken, then time-stamping becomes important; impersonation is
avoided by personal indentification, notarization, etc.; bribery or other CA employee
illegality is limited by more than one employee being required to issue a certificate.
Standards authorities
– (Not just related to public keys, of course.)
– ANSI
– ITU (CCITT)
– ISO
– IEEE
– IETF
– Industry consortia
– Government bodies, agencies
Zero-knowledge techniques
– In authentication, to prove your identity, you say something about yourself. E.g. pass-
word. But now your identity is known. What if the partner in the exchange exploited this
knowledge to pretend that he/she was you?
– Zero knowledge techniques authenticate you without giving secret information away.
– Use techniques similar to RSA. But, for digital signatures, much more efficient techniques
than RSA are used.
– Identification sequence is established which, for the correct person, must lead to a right
conclusion for that person.
– See pp. 181-190 of van der Lubbe for a good description.
14
Fair cryptosystem
– How to cater for criminal use of cryptography?
– Force surrender of keys is threat to person’s privacy.
– Fair cryptosystem: authorized body can decrypt.
– How?
– Deposits parts of key with trusted body.
– Clipper, capstone.
Two encryption systems, resp. for telephone and computer communication, adhering to
American Escrowed Encryption Standard, adopted in 1994.
System of key escrow: a pre-installed chip holds half your private key, and the other
half is lodged with a government agency.
Considered to have failed.
15
– S/MIME (Secure / Multipurpose Internet Mail Extensions) adds digital signatures and
encryption to MIME messages. MIME is an email standard: (structured) header and (unstruc-
tured) body of message are specified. MIME allows for support of multimedia files (image,
audio, video, etc.)
– PGP is due to Phil Zimmermann. Used, e.g., in email. Multiple platform. Address:
www.pgp.com, www.pgpi.com
– Lots of difficulties due to (i) RSA holding licences, (ii) US Govt’s objections to export
of anything strongly encrypted, and even more so the technologies behind strong
encryption.
– So put onto a newsgroup in 1991.
– Symmetric encryption is fast, IDEA even more than DES.
– Symmetric key is a problem, in practice.
– RSA looks after key distribution well, but is computationally more costly.
– PGP combines these: RSA is used for the key, and IDEA for the message.
16