1. FPGA для анализа хардвара
DEFCON RUSSIA DCG#7812
Дмитрий Недоспасов <dmitry@h.rdw.re>
2. Кратко обо мне…
• Закончил аспирантуру в TU Berlin, тема новые виды анализа чипов
• Работаю совместно с Olivier THOMAS и Texplained SARL во Фрации
• Еще работаю как фрилансер и тренер “IC RE 101” и “Keep it Synple Stupid”
• Преподаю “Hardware Security” в TU Berlin
• Буду в конце года делать стартап под более совершенствуемого
конкурента Yubikey
• Twitter: @nedos
• Email: dmitry@h.rdw.re
3. WTFPGA?
• Программируемая пользователем
вентильная матрица
• Не программируют в “классическом”
смысле
• Вместо этого реализуется логическая
схема
• Это не замена софту и
микроконтроллерам но имеет некие
преимущества
4. Hardware Basics
Logic Gates
4
ASSIGNMENT 2.3
Half Adder A B SUM CARRY Full Adder A B C_IN SUM C_OUT
NOR
A B Y
0 0 1
0 1 0
1 0 0
1 1 0
NAND
A B Y
0 0 1
0 1 1
1 0 1
1 1 0
AND
A B Y
0 0 0
0 1 0
1 0 0
1 1 1
XOR
A B Y
0 0 0
0 1 1
1 0 1
1 1 0
OR
A B Y
0 0 0
0 1 1
1 0 1
1 1 1
NOT
A Y
0 1
1 0
5. Hardware Basics
Karnaugh Map for Combinational Logic
๏ Boolean results are
transferred from a truth table
not Karnaugh map
๏ Writing minimal boolean
expressions
5
Figure Source: Wikipedia
7. Place & RouteSynthesis
Chapter 2: FPGA Design Flow
R
Design Flow Diagram
Figure 2-1, “Design Flow Overview Diagram,” shows an overview of the design flow
steps.
Figure 2-1: Design Flow Overview Diagram
X10303
Entering your Design
and Selecting Hierarchy
Functional Simulation
of your Design
Synthesizing and Optimizing
your Design
Adding Design
Constraints
Evaluating your Design Size
and Performance
Placing and Routing
your Design
Downloading to the Device,
In-System Debugging
Generating a Bitstream
Creating a PROM, ACE
or JTAG File
Evaluating your Design's Coding Style
and System Features
Timing Simulation
of your Design
Static Timing
Analysis
Дизайн
Simulation
8. Hardware Description Languages
• Я для начинающих настоятельно рекомендую Verilog
• Verilog очень часто используется и поддерживается
как промежуточный формат между различными
тулз
• Главное, что надо помнить когда читаешь HDL, что
блок синтезируется как логическая цепочка из
вентилей и выполняется постоянно!
• В императивном программирование каждая строка
кода выполняется одна за другой, а в синтезе HDL
все выполняются одновременно.
• Чаще всего используется стиль с blocking
assignemnts (<=), а это означает что последнее
присвоение это то значение которая будет в
регистре при следующем цикле
module
counter
(
input
wire
clk,
input
wire
rst,
input
wire
enable,
output
reg
[31:0]
count
);
always
@(posedge
clk)
begin
if
(
rst
)
begin
count
<=
32'b0;
end
else
begin
count
<=
count;
if
(
enable
)
begin
count
<=
count
+
1'b1;
end
end
end
endmodule
9. Конечный Автомат UART START
UART DATA
UART STOP
UART IDLE
Default assignments
etu cnt <= (etu cnt + 1);
dout <= dout;
rdy <= rdy;
data <= data;
state <= state;
bit cnt <= bit cnt;
en
etu cnt <= 9’d0;
bit cnt <= 3’d0;
rdy <= 1’b0;
dout <= 1’b0;
data <= data out;
state <= ‘UART DATA;
etu full
etu cnt <= 9’d0;
bit cnt <= (bit cnt + 1);
dout <= data[0];
data <= {data[0], data[7:1]};
bit cnt == 3’d7
state <= ‘UART STOP;
etu full
etu cnt <= 9’d0;
dout <= 1’b1;
state <= ‘UART IDLE;
etu full
rdy <= 1’b1;
state <= ‘UART START;
Figure 7: UART transmitter state machine.
• С помощью always @ (posedge clk) и
блокирующего присвоения (<=) синтезируется
секвенциальная логика
• С помощью assign и не блокирующего
присвоения синтезируется комбинационная
логика
• Синтез комбинационной логики одно из
мощнещих преимуществ HDL-а так как
комбинационная логика реагирует
моментально на сигнал
• Например можно выделить предикаты в логике:
assign etu_full = (etu_cnt == `UART_FULL_ETU);
•
13. MITM: DoS
rotocol. UART is one of the simplest serial protocols and is commonly used for debugging and
nication between di↵erent ICs on a PCB. UART is identical to RS-232 except for the voltage
ed the signaling. The speed of the serial communications, i.e. the baud rate or the frequency
character, is predetermined. Generally in UART implementations, the line is held high while
tocol is in the idle state. To signal the start of a transfer a start character is transmited during
he signal is held low, i.e. a logical 0. Next 5 - 8 data bits are transmited: a high signal state
onds to a logical 1, a low signal state corresponds to a logical 0. This may be followed by a
it, depending on the configuration. At the end of the transmission one or two stop characters
smitted.
uart tx
SysClk clk
SysRst rst
en en
data out[7:0] data out[7:0]
8
doutdout
rdyrdy
Figure 6: module uart tx
ons:
sume we have 100MHz system clock. For a 9600 baud UART what is the delay in clock cycles
ween charcters?
nsider the signals necessary for a UART transmitter, see Figure 6. Why is the rdy signal
essary?
aw a UART transmitter state machine in Figure 7.
S 0 1 2 3 4 5 6 7 S
d[0] d[1] d[2] d[3] d[4] d[5] d[6] d[7]
Figure 5: UART timing diagram.
exercise will we will create a module capable of transmitting bytes of data using the UART
rotocol. UART is one of the simplest serial protocols and is commonly used for debugging and
nication between di↵erent ICs on a PCB. UART is identical to RS-232 except for the voltage
ed the signaling. The speed of the serial communications, i.e. the baud rate or the frequency
character, is predetermined. Generally in UART implementations, the line is held high while
tocol is in the idle state. To signal the start of a transfer a start character is transmited during
he signal is held low, i.e. a logical 0. Next 5 - 8 data bits are transmited: a high signal state
onds to a logical 1, a low signal state corresponds to a logical 0. This may be followed by a
it, depending on the configuration. At the end of the transmission one or two stop characters
smitted.
uart tx
SysClk clk
SysRst rst
en en
data out[7:0] data out[7:0]
8
doutdout
rdyrdy
Figure 6: module uart tx
14. PIN
• Через UART вводится PIN
• При не правильном вводи PIN-а диоды
на плате начинают мигать
• Диоды мигают 5 секунд
• Надо убрать эту задержку
16. Тайминг пароля
• В embedded системах навсегда есть
strcmp
• Часто разработчики пишут свой strcmp
особенно если пароль определенной
длины
• Пароль проверяется по одной букве
18. Спасибо за внимание
• Точно будет этот тренинг на REC0N и Toorcon
• Скорее всего мы его с 0x90 постараемся сделать на ЗН
• Очень хочу в какой-то момент под него сделать Kickstarter
• Могу сделать он-сайт: Dmitry Nedospasov <dmitry@h.rdw.re>