DPA contest v4 攻击
DPA contest v4收集了10 0000条trace,trace只涉及了AES-256 RSM 第一轮的加密。AES-256 RSM是在一个连接到SASEBO-W板的ATMega-163智能卡上实现的。
AES RSM介绍
AES-256 RSM 添加了掩码保护,Subbytes操作被替换成了嵌入掩码的版本 MaskedSubBytes:
M
a
s
k
e
d
S
u
b
B
y
t
e
s
i
(
X
)
=
S
u
b
B
y
t
e
s
(
X
⊕
M
i
)
⊕
M
i
+
1
MaskedSubBytes_i(X) = SubBytes(X \oplus M_i)\oplus M_{i+1}
MaskedSubBytesi(X)=SubBytes(X⊕Mi)⊕Mi+1
其中掩码
M
i
M_i
Mi是公开的:
M
i
∈
0
,
15
=
{
0
x
00
,
0
x
0
f
,
0
x
36
,
0
x
39
,
0
x
53
,
0
x
5
c
,
0
x
65
,
0
x6a
,
0
x
95
,
0
x
9
a
,
0
xa3
,
0
x
x
c
,
0xf6
,
0
x
c9
,
0
xf0
,
0
xff
}
.
\begin{aligned} M_{i \in 0,15}= & \{0\text{x}00,0\text{x}0f, 0\text{x}36,0\text{x}39,0\text{x}53,0\text{x}5c, 0\text{x}65,0\text{x6a}, \\ & 0\text{x}95,0\text{x}9a, 0\text{xa3}, 0x\text{x}c, \text{0xf6}, 0x\text{c9}, 0\text{xf0},0\text{xff}\} . \end{aligned}
Mi∈0,15={0x00,0x0f,0x36,0x39,0x53,0x5c,0x65,0x6a,0x95,0x9a,0xa3,0xxc,0xf6,0xc9,0xf0,0xff}.
AES RSM 泄露分析
在AES 256 RSM实现第一轮中X首先异或
M
a
s
k
Mask
Mask得到
X
′
X'
X′,然后用
X
′
X'
X′异或
R
o
u
n
d
K
e
y
RoundKey
RoundKey最后经过
M
a
s
k
e
d
S
u
b
B
y
t
e
s
MaskedSubBytes
MaskedSubBytes。分析$ MaskedSubBytes_i$的输入输出的异或:
X
[
i
]
⊕
M
i
⊕
R
o
u
n
d
K
e
y
1
[
i
]
M
a
s
k
e
d
S
u
b
B
y
t
e
s
i
(
X
[
i
]
⊕
R
o
u
n
d
K
e
y
1
[
i
]
⊕
M
i
⊕
M
i
)
⊕
M
i
+
1
=
X
[
i
]
⊕
R
o
u
n
d
K
e
y
1
[
i
]
⊕
S
u
b
B
y
t
e
s
i
(
X
[
i
]
⊕
R
o
u
n
d
K
e
y
1
[
i
]
)
⊕
M
i
⊕
M
i
+
1
\begin{align*} X[i]\oplus M_i\oplus RoundKey_1[i]{ Masked}SubBytes_i(X[i]\oplus RoundKey_1[i]\oplus M_i \oplus M_i)\oplus M_{i+1}\\ =X[i]\oplus RoundKey_1[i]\oplus SubBytes_i(X[i]\oplus RoundKey_1[i])\oplus M_i\oplus M_{i+1} \end{align*}
X[i]⊕Mi⊕RoundKey1[i]MaskedSubBytesi(X[i]⊕RoundKey1[i]⊕Mi⊕Mi)⊕Mi+1=X[i]⊕RoundKey1[i]⊕SubBytesi(X[i]⊕RoundKey1[i])⊕Mi⊕Mi+1
但
M
i
⊕
M
i
+
1
M_i\oplus M_{i+1}
Mi⊕Mi+1是不均匀的!
M
i
⊕
M
i
+
1
i
∈
0
,
15
=
{
0
x0f
,
0
x39
,
0
x0f
,
0
x6a
,
0
x0f
,
0
x39
,
0
x0f
,
0
xff
,
0
x0f
,
0
x39
,
0
x0f
,
0
x6a
,
0
x0f
,
0
x39
,
0
x0f
,
0
xff
}
.
\begin{align*} \underset{i\in 0,15}{M_i\oplus M_{i+1}}= & \{0\text{x0f},0\text{x39}, 0\text{x0f},0\text{x6a},0\text{x0f},0\text{x39},0\text{x0f},0\text{xff},\\ & 0\text{x0f},0\text{x39}, 0\text{x0f},0\text{x6a}, 0\text{x0f},0\text{x39},0\text{x0f},0\text{xff}\} . \end{align*}
i∈0,15Mi⊕Mi+1={0x0f,0x39,0x0f,0x6a,0x0f,0x39,0x0f,0xff,0x0f,0x39,0x0f,0x6a,0x0f,0x39,0x0f,0xff}.
8 个 0x0f, 4 个 0x39, 2 个0x6a, 2 个 0xff, 分布不均匀!
所以我们利用的泄露模型为:
H
=
X
⊕
R
o
u
n
d
K
e
y
1
⊕
S
B
o
x
(
X
⊕
R
o
u
n
d
K
e
y
1
)
H=X \oplus RoundKey_1 \oplus SBox(X \oplus RoundKey_1)
H=X⊕RoundKey1⊕SBox(X⊕RoundKey1)
利用上式可以消除掩码的保护。
使用1000个trace 求平均值画出波形,可以发现200
μ
s
\mu s
μs到 400
μ
s
\mu s
μs 是 Subbytes的过程,可以大致分辨出16个state分别操作的过程如下图:
使用10000条trace,针对明文的第一字节们进行测试,测试 X [ 1 ] ⊕ R o u n d K e y 1 ∗ [ 1 ] ⊕ S u b B y t e s i ( X [ 1 ] ⊕ R o u n d K e y 1 ∗ [ 1 ] ) X[1]\oplus RoundKey_1^{*}[1]\oplus SubBytes_i(X[1]\oplus RoundKey_1^{*}[1]) X[1]⊕RoundKey1∗[1]⊕SubBytesi(X[1]⊕RoundKey1∗[1])与trace的相关度( R o u n d K e y 1 ∗ RoundKey_1^{*} RoundKey1∗是真实的轮密钥),发现正确密钥对应的相关度是可与其他错误密钥明显区分开。明文的其他字节与trace的相关度图也类似的形状。
实施攻击
根据DPA Contest 的规则,密钥的猜测必须是稳定的。这意味着,当算法在继续使用更多trace时,能够持续保持其正确的密钥,密钥稳定的阈值固定在100。
在此条件下恢复第一轮密钥
K
K
K的各个字节所需要的trace条数如下:
密钥字节 | number of traces |
---|---|
K[0] | 200 |
K[1] | 529 |
K[2] | 442 |
K[3] | 401 |
K[4] | 401 |
K[5] | 401 |
K[6] | 423 |
K[7] | 401 |
K[8] | 643 |
K[9] | 948 |
K[10] | 511 |
K[11] | 423 |
K[12] | 835 |
K[13] | 504 |
K[14] | 471 |
K[15] | 401 |
攻击在Python下实施,由于需要不断计算皮尔逊相关系数(Pearson correlation coefficient),十分耗时,所以恢复正确密钥花费了11h。
攻击代码的改进
由于测信道攻击中频繁使用科学计算,所以为了方便一直使用 python,但
python 实在太慢,然后了解并学习了 C++的科学计算库 Eigen。
Eigen 是一个高层次的 C ++库,有效支持线性代数,矩阵和矢量运算,数
值分析及其相关的算法。
使用 eigen 库实现与上周攻击 DPA Contest v4 的 python 程序相同的功能。
在 python 版本的攻击程序运行 11h 才完成,而利用 Eigen 库编写的 C++程序只
需要 64 分钟,速度提升 10 倍之多。