# Lecture 3: Password Attack with Difference Analysis - Introduction
%% Cell type:markdown id: tags:
In this example we want to improve the basic passwdcheck to be resistant against the attack from the last tutorial.
## Improving the code
Let's first recap the password checking loop from the basic passwdcheck:
```c
for(uint8_ti=0;i<sizeof(stored_password);i++)
{
if(stored_password[i]!=passwd[i])
{
password_correct=0;
break;
}
}
```
The timing attack discussed in the last example worked because the loop's runtime varies with the number of correct characters. Once the first wrong character occurs the loop breaks.
This is, what we want to change:
```c
for(uint8_ti=0;i<sizeof(stored_password);i++)
{
if(stored_password[i]!=passwd[i])
{
password_correct=0;
}
}
```
This is an excerpt from `3_password_fixed.c`. It is clear that the loop does not break after the first wrong character and always all characters of the password are checked.
# Lecture 3: Password Attack with Difference Analysis - Analyse
%% Cell type:markdown id: tags:
In this example we want to improve the basic passwdcheck to be resistant against the attack from the last tutorial.
## Improving the code
Let's first recap the password checking loop from the basic passwdcheck:
```c
for(uint8_ti=0;i<sizeof(stored_password);i++)
{
if(stored_password[i]!=passwd[i])
{
password_correct=0;
break;
}
}
```
The timing attack discussed in the last example worked because the loop's runtime varies with the number of correct characters. Once the first wrong character occurs the loop breaks.
This is, what we want to change:
```c
for(uint8_ti=0;i<sizeof(stored_password);i++)
{
if(stored_password[i]!=passwd[i])
{
password_correct=0;
}
}
```
This is an excerpt from `3_password_fixed.c`. It is clear that the loop does not break after the first wrong character and always all characters of the password are checked.
%% Cell type:markdown id: tags:
## MAD password attack
Given two traces $t_1, t_2$ their MAD value is defined as:
Have a look at the assembly code of `3_password_fixed.c`. It's the `.lss` file. Understand instruction per instruction what the CPU is doing. The [XMEGA reference manual](http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-8210-8-and-16-bit-AVR-Microcontrollers-XMEGA-D_Manual.pdf) might be helpful.
Create a plot to explain your investigations and especially their relation to the MAD-Attack. The plot below is an example. The manual of [bokeh](https://docs.bokeh.org/en/latest/index.html) might be helpful. I used `line`, `Span`, `Label`.
<imgsrc="Lecture 3: Password Attack with Difference Analysis - Analyse.png"></img>
# Lecture 3: Password Attack with Difference Analysis - Analyse
%% Cell type:markdown id: tags:
In this example we want to improve the basic passwdcheck to be resistant against the attack from the last tutorial.
## Improving the code
Let's first recap the password checking loop from the basic passwdcheck:
```c
for(uint8_ti=0;i<sizeof(stored_password);i++)
{
if(stored_password[i]!=passwd[i])
{
password_correct=0;
break;
}
}
```
The timing attack discussed in the last example worked because the loop's runtime varies with the number of correct characters. Once the first wrong character occurs the loop breaks.
This is, what we want to change:
```c
for(uint8_ti=0;i<sizeof(stored_password);i++)
{
if(stored_password[i]!=passwd[i])
{
password_correct=0;
}
}
```
This is an excerpt from `3_password_fixed.c`. It is clear that the loop does not break after the first wrong character and always all characters of the password are checked.
%% Cell type:markdown id: tags:
## MAD password attack
Given two traces $t_1, t_2$ their MAD value is defined as: