Skip to content

Commit 4d5bac8

Browse files
committed
metrics: fixes #166 reliability metric
1 parent 4346016 commit 4d5bac8

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pypuf is published [via Zenodo](https://zenodo.org/badge/latestdoi/87066421).
3535
Please cite this work as
3636

3737
> Nils Wisiol, Christoph Gräbnitz, Christopher Mühl, Benjamin Zengin, Tudor Soroceanu, Niklas Pirnay, & Khalid T. Mursi.
38-
> pypuf: Cryptanalysis of Physically Unclonable Functions (Version v2, March 2021). Zenodo.
38+
> pypuf: Cryptanalysis of Physically Unclonable Functions (Version 2, June 2021). Zenodo.
3939
> https://doi.org/10.5281/zenodo.3901410
4040
4141
or use the following BibTeX:

pypuf/metrics/common.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ def reliability_data(responses: np.ndarray) -> np.ndarray:
2222
where :math:`\text{eval}(x)` is the response of the (noisy) PUF when evaluated on input :math:`x`, and the
2323
probability is taken over the noise in the evaluation process.
2424
25+
The approximation is derived from an approximation of :math:`E_\text{eval} \left[ \text{eval}(x) \right]`,
26+
which is given by the mean of ``responses``,
27+
28+
.. math:: \Pr_\text{eval} \left[ \text{eval}(x) = \text{eval}(x) \right] =
29+
\frac{1}{2} E_\text{eval} \left[ \text{eval}(x) \right]^2 + \frac{1}{2}.
30+
31+
The formula can be obtained by observing
32+
:math:`\Pr_\text{eval} \left[ \text{eval}(x) = \text{eval}(x) \right] =
33+
\Pr\left[\text{eval}(x)=1\right]^2 + \Pr\left[\text{eval}(x)=-1\right]^2` and
34+
:math:`\Pr_\text{eval}\left[\text{eval}(x)=1\right] = \frac{1}{2}E_\text{eval}\left[\text{eval}(x)\right]
35+
+ \frac{1}{2}`.
36+
2537
An array of shape :math:`(N,m)` is returned, estimating above probability for each challenge and each response bit.
2638
To obtain a the reliability for each response bit, average along the first axis, to obtain the general reliability,
2739
average over all axes.
@@ -30,9 +42,11 @@ def reliability_data(responses: np.ndarray) -> np.ndarray:
3042
>>> from numpy import average, array
3143
>>> responses = array([[[1, 1, -1]], [[1, 1, 1]], [[1, 1, 1]], [[1, 1, 1]]])
3244
>>> average(reliability_data(responses), axis=0)
33-
array([0.83333333])
45+
array([0.88888889])
3446
"""
35-
return np.absolute(np.average(responses, axis=-1))
47+
m = np.average(responses, axis=-1) # approximate E[eval(x)]
48+
f1 = (m + 1) / 2 # P[eval(x) = 1] = 1/2 E[eval(x)] + 1/2
49+
return f1**2 + (1 - f1)**2 # P[eval(x) = eval(x)] = P[eval(x) = 1]**2 + P[eval(x) = -1]**2
3650

3751

3852
def reliability(instance: Simulation, seed: int, N: int = 10000, r: int = 17) -> np.ndarray:
@@ -50,12 +64,28 @@ def reliability(instance: Simulation, seed: int, N: int = 10000, r: int = 17) ->
5064
reliability of this instance, average across all axes. Note that bad reliability on single response bits may be
5165
problematic.
5266
53-
>>> from pypuf.simulation import XORArbiterPUF
67+
>>> from pypuf.simulation import ArbiterPUF, XORArbiterPUF
5468
>>> from pypuf.metrics import reliability
5569
>>> from numpy import average
5670
>>> puf = XORArbiterPUF(n=128, k=2, seed=1, noisiness=.2)
5771
>>> average(reliability(puf, seed=2), axis=0)
58-
array([0.77729412])
72+
array([0.84887197])
73+
74+
An example of an extremely noisy PUF:
75+
76+
>>> average(reliability(XORArbiterPUF(n=32, k=12, seed=1, noisiness=1), seed=2), axis=0)
77+
array([0.52879308])
78+
79+
80+
An example of a very reliable PUF:
81+
82+
>>> average(reliability(ArbiterPUF(n=32, seed=1, noisiness=.01), seed=2), axis=0)
83+
array([0.99576886])
84+
85+
An example of a perfectly reliable PUF:
86+
87+
>>> average(reliability(ArbiterPUF(n=64, seed=1, noisiness=0), seed=2), axis=0)
88+
array([1.])
5989
"""
6090
inputs = random_inputs(n=instance.challenge_length, N=N, seed=seed)
6191
return np.absolute(reliability_data(instance.r_eval(r, inputs)))

0 commit comments

Comments
 (0)