lecture12
lecture12
Information Flow
Week 12: Information Leakage
Sebastian Mödersheim
May 5, 2025
Sebastian Mödersheim 1 of 26
Challenge
lookup_result(db:array[testrecord:{⊥}]{⊥},
client:cpr{⊥})
returns result:bool{client:client}
finished=false;
result=1;
while(x>0){
result=result*b mod N;
x=x-1;
}
finished=true
• Assume finished is level Low, while all other variables are High.
Sebastian Mödersheim 5 of 26
Timing Leaks
finished=false;
result=1;
while(x>0){
result=result*b mod N;
x=x-1;
}
finished=true
• Assume finished is level Low, while all other variables are High.
• This satisfies classical information flow.
Sebastian Mödersheim 5 of 26
Timing Leaks
finished=false;
result=1;
while(x>0){
result=result*b mod N;
x=x-1;
}
finished=true
• Assume finished is level Low, while all other variables are High.
• This satisfies classical information flow.
• However, an intruder who can observe finished can estimate x
— if they have a clock.
Sebastian Mödersheim 5 of 26
Timing Leaks
finished=false;
result=1;
while(x>0){
result=result*b mod N;
x=x-1;
}
finished=true
• Assume finished is level Low, while all other variables are High.
• This satisfies classical information flow.
• However, an intruder who can observe finished can estimate x
— if they have a clock.
• This can be a problem in cryptographic algorithms, although the
above example would never be used in crypto. (Why?)
Sebastian Mödersheim 5 of 26
Timing Leaks
Consider the following less naı̈ve algorithm for b x mod N:
result=1;
while(x>1){
if (x%2==0){x=x/2;}
else{
x=(x-1)/2;
result=result*b % N;
}
b=b*b % N;
}
result=result*b % N;
Sebastian Mödersheim 6 of 26
Timing Leaks
Consider the following less naı̈ve algorithm for b x mod N:
result=1;
while(x>1){
if (x%2==0){x=x/2;}
else{
x=(x-1)/2;
result=result*b % N;
}
b=b*b % N;
}
result=result*b % N;
• The runtime still depends on x
Sebastian Mödersheim 6 of 26
Timing Leaks
Consider the following less naı̈ve algorithm for b x mod N:
result=1;
while(x>1){
if (x%2==0){x=x/2;}
else{
x=(x-1)/2;
result=result*b % N;
}
b=b*b % N;
}
result=result*b % N;
• The runtime still depends on x
⋆ position of the most significant set bit in x
⋆ number of bits set in x
Sebastian Mödersheim 6 of 26
Timing Leaks
Consider the following less naı̈ve algorithm for b x mod N:
result=1;
while(x>1){
if (x%2==0){x=x/2;}
else{
x=(x-1)/2;
result=result*b % N;
}
b=b*b % N;
}
result=result*b % N;
• The runtime still depends on x
⋆ position of the most significant set bit in x
⋆ number of bits set in x
• It is not difficult to make this algorithm constant time:
⋆ Ensure that also the then case performs a modular multiplication.
⋆ Ensure that there are exactly η rounds of the while loop
Sebastian Mödersheim
where η is the number of bits of x. 6 of 26
A Remote Timing Attack on RSA
Sebastian Mödersheim 7 of 26
Recall: RSA
Keygeneration:
• Choose bit-size η (recommended: η ≥ 2048)
• Choose random primes p, q of size η2 .
• Let N := p · q
• Choose random e of size η
• Compute d := e −1 mod (p − 1)(q − 1)
• The resulting public key is (N, e)
⋆ in OFMC for instance pk(B)
• The resulting private key is (p, q, d)
⋆ in OFMC for instance: inv(pk(B))
Encryption:
• c := me mod N
⋆ in OFMC for instance: {m}pk(B)
Decryption:
• m := c d mod N
⋆ in OFMC: decryption handled as part of the Dolev-Yao rules
Sebastian Mödersheim 8 of 26
Recall: RSA
Keygeneration:
• Choose bit-size η (recommended: η ≥ 2048)
• Choose random primes p, q of size η2 .
• Let N := p · q
• Choose random e of size η
• Compute d := e −1 mod (p − 1)(q − 1)
• The resulting public key is (N, e)
⋆ in OFMC for instance pk(B)
• The resulting private key is (p, q, d)
⋆ in OFMC for instance: inv(pk(B))
Encryption: to prevent guessing and multiplication attacks
e
• c := pad,m,rand mod N
⋆ where pad is a fixed padding string, rand is a fresh random string
Decryption:
• pad,m,rand := c d mod N
⋆ if pad is the fixed padding string, return m, otherwise error.
Sebastian Mödersheim 8 of 26
Montgomery Representation
Sebastian Mödersheim 9 of 26
Multiplication modulo N in MR
a · R · b · R ≡N a · b · R · R
| {z } | {z } | {z }
η bits η bits 2η bits
Sebastian Mödersheim 10 of 26
Multiplication modulo N in MR
a · R · b · R ≡N a · b · R · R
| {z } | {z } | {z }
η bits η bits 2η bits
Sebastian Mödersheim 10 of 26
Multiplication modulo N in MR
a · R · b · R ≡N a · b · R · R
| {z } | {z } | {z }
η bits η bits 2η bits
Sebastian Mödersheim 10 of 26
Multiplication modulo N in MR
a · R · b · R ≡N a · b · R · R
| {z } | {z } | {z }
η bits η bits 2η bits
Sebastian Mödersheim 10 of 26
Multiplication modulo N in MR
Sebastian Mödersheim 11 of 26
Multiplication modulo N in MR
a 1 0 1 1 0 1 0 0
+4N 0 0 0 1 0 1 0 0
≡N a 1 1 0 0 1 0 0 0
Sebastian Mödersheim 11 of 26
Multiplication modulo N in MR
a 1 0 1 1 0 1 0 0
+4N 0 0 0 1 0 1 0 0
≡N a 1 1 0 0 1 0 0 0
Sebastian Mödersheim 11 of 26
Multiplication modulo N in MR
So we now have:
• Step 1:
a · R · b · R ≡N a · b · R · R
| {z } | {z } | {z }
η bits η bits 2η bits
• Step 2:
a · b · R · R + k · N = XY 0...0
| {z } |{z} | {z }
2η bits η bits η bits
• Step 3: a · b · R ≡N XY
|{z}
η bits
Sebastian Mödersheim 12 of 26
Multiplication modulo N in MR
So we now have:
• Step 1:
a · R · b · R ≡N a · b · R · R
| {z } | {z } | {z }
η bits η bits 2η bits
• Step 2:
a · b · R · R + k · N = XY 0...0
| {z } |{z} | {z }
2η bits η bits η bits
• Step 3: a · b · R ≡N XY
|{z}
η bits
• But there is one small problem: XY may be larger than N (but
not larger than 2N)
⋆ So Step 4: if XY > N subtract N from it!
Sebastian Mödersheim 12 of 26
Multiplication modulo N in MR
So we now have:
• Step 1:
a · R · b · R ≡N a · b · R · R
| {z } | {z } | {z }
η bits η bits 2η bits
• Step 2:
a · b · R · R + k · N = XY 0...0
| {z } |{z} | {z }
2η bits η bits η bits
• Step 3: a · b · R ≡N XY
|{z}
η bits
• But there is one small problem: XY may be larger than N (but
not larger than 2N)
⋆ So Step 4: if XY > N subtract N from it!
• This last step is a timing leak!
⋆ In the exponentation c d mod N, this is happening more often if
c is close to N, and that can give a measurable difference!
Sebastian Mödersheim 12 of 26
Chinese Remainder Theorem
Sebastian Mödersheim 13 of 26
The Timing Attack
The intruder can send an arbitrary value c and B will try to decrypt
it. What to send as c?
Sebastian Mödersheim 14 of 26
The Timing Attack
The intruder can send an arbitrary value c and B will try to decrypt
it. What to send as c?
• Suppose the intruder already knows the a few of the most
significant bits of q. Then the next bit can be obtained like this:
g = b1 b2 b3 0 0 0 0 0
ghi = b1 b2 b3 1 0 0 0 0
Sebastian Mödersheim 14 of 26
The Timing Attack
The intruder can send an arbitrary value c and B will try to decrypt
it. What to send as c?
• Suppose the intruder already knows the a few of the most
significant bits of q. Then the next bit can be obtained like this:
g = b1 b2 b3 0 0 0 0 0
ghi = b1 b2 b3 1 0 0 0 0
Sebastian Mödersheim 14 of 26
The Timing Attack
The intruder can send an arbitrary value c and B will try to decrypt
it. What to send as c?
• Suppose the intruder already knows the a few of the most
significant bits of q. Then the next bit can be obtained like this:
g = b1 b2 b3 0 0 0 0 0
ghi = b1 b2 b3 1 0 0 0 0
Sebastian Mödersheim 14 of 26
The Timing Attack
The intruder can send an arbitrary value c and B will try to decrypt
it. What to send as c?
• Suppose the intruder already knows the a few of the most
significant bits of q. Then the next bit can be obtained like this:
g = b1 b2 b3 0 0 0 0 0
ghi = b1 b2 b3 1 0 0 0 0
Sebastian Mödersheim 14 of 26
The Timing Attack
The intruder can send an arbitrary value c and B will try to decrypt
it. What to send as c?
• Suppose the intruder already knows the a few of the most
significant bits of q. Then the next bit can be obtained like this:
g = b1 b2 b3 0 0 0 0 0
ghi = b1 b2 b3 1 0 0 0 0
• Recommendations [1]:
⋆ blinding: multiply c with random r before decryption (and divide
result by r afterwards)
⋆ constant time: ensure runtime does not depend on the data.
• Compiler Design with special forms of information flow can help
here:
⋆ Generate Code that does not have timing leaks.
⋆ Compiler ensures that optimizations are not introducing time
leaks.
⋆ Target all popular processors.
⋆ Verified implementation (no gap to mathematical model)
Sebastian Mödersheim 15 of 26
Spectre
Sebastian Mödersheim 16 of 26
Speculative Execution
a =3;
b=A r r a y [ 6 ] ;
c=f ( a ) ;
Sebastian Mödersheim 17 of 26
Speculative Execution
a =3;
i f ( Array [6] >3)
c=f ( a ) ;
else
c=g ( a ) ;
Sebastian Mödersheim 18 of 26
Speculative Execution
a =3;
i f ( Array [6] >3)
c=f ( a ) ;
else
c=g ( a ) ;
Sebastian Mödersheim 18 of 26
Speculative Execution
a =3;
i f ( Array [6] >3)
c=f ( a ) ;
else
c=g ( a ) ;
Sebastian Mödersheim 18 of 26
Spectre: Example
Sebastian Mödersheim 19 of 26
Spectre: Example
Sebastian Mödersheim 20 of 26
Spectre: Example
Sebastian Mödersheim 21 of 26
Spectre: Example
Sebastian Mödersheim 21 of 26
Spectre: Example
Sebastian Mödersheim 21 of 26
Spectre: Example
Sebastian Mödersheim 22 of 26
Spectre: Example
Sebastian Mödersheim 22 of 26
Spectre: Example
Sebastian Mödersheim 22 of 26
Spectre: Example
Sebastian Mödersheim 22 of 26
Spectre: Example
Sebastian Mödersheim 23 of 26
Spectre: Example
Sebastian Mödersheim 23 of 26
Spectre: Example
Sebastian Mödersheim 23 of 26
Spectre: Example
Sebastian Mödersheim 24 of 26
Side Channel Analysis
• Side channels are usually leaks that the designers never have
thought of.
• Many problems exist for years without getting noticed – how
much else is out there?
• Very active research field:
⋆ In order to prove a solution correct, one needs a precise model
first.
⋆ For instance Speculative non-interference and the Spectector tool.
[2] Marco Guarnieri et al.: Spectector: Principled Detection of
Speculative Information Flows, Security and Privacy, 2020.
Sebastian Mödersheim 25 of 26
References I
Sebastian Mödersheim 26 of 26