ANSSI-FR / ASCAD

Side Channels Analysis and Deep Learning

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

one_hot probability rank problem

luvf opened this issue · comments

When the classifier predict a one hot probability
the rank is always 0
when calculating key_bytes_proba,
when proba == 0
key_bytes_proba is calculated by taking the square of the second min element in the array. this is problematic when the second min element == 1 (happens in 1 hot vectors)

the in the rank function in ASCAD_test_models.py
Suggestion :ASCAD_test_models.py (function rank) line 70
replace
key_bytes_proba[i] += np.log(min_proba**2) by
key_bytes_proba[i] += np.log(min_proba/2)#or divided by a larger

Or add another if case.

A second related bug/bad behavior.

an uniform classifier have a rank of 0
the reason is
real_key_rank = np.where(sorted_proba == key_bytes_proba[real_key])[0][0]
should be repaced with
real_key_rank = np.where(sorted_proba == key_bytes_proba[real_key])[-1][-1]

when multiple keys have the same proba, we call the pessimistic case
or the mean case [len1/2][len2/2]

Thank you. You are totally right on both points and I updated the script accordingly.