uwu 3
This commit is contained in:
parent
42e0cf6a0e
commit
9876dcff1f
|
@ -91,8 +91,26 @@ def main(db):
|
||||||
model[:, i] = AES_SBOX[model[:, i] ^ pt_v] ^ mask_v
|
model[:, i] = AES_SBOX[model[:, i] ^ pt_v] ^ mask_v
|
||||||
model = numpy_popcount.popcount(model).astype("double")
|
model = numpy_popcount.popcount(model).astype("double")
|
||||||
|
|
||||||
input_matrix = numpy.vstack((model, traces.transpose()))
|
# O - (n,t) array of n traces with t samples each
|
||||||
coefs = numpy.corrcoef(input_matrix)[0:256, 256:]
|
# P - (n,m) array of n predictions for each of the m candidates
|
||||||
|
# returns an (m,t) correaltion matrix of m traces t samples each
|
||||||
|
def corr_submatrix(O, P):
|
||||||
|
O -= numpy.mean(O, axis=0)
|
||||||
|
P -= numpy.mean(P, axis=0)
|
||||||
|
|
||||||
|
numerator = numpy.einsum("nm,nt->mt", P, O, optimize='optimal')
|
||||||
|
denominator = numpy.sqrt(numpy.outer((P * P).sum(axis=0), (O * O).sum(axis=0)))
|
||||||
|
|
||||||
|
return numerator / denominator
|
||||||
|
|
||||||
|
# boring, slow, uses too much RAM
|
||||||
|
# input_matrix = numpy.vstack((model, traces.transpose()))
|
||||||
|
# coefs = numpy.corrcoef(input_matrix)[0:256, 256:]
|
||||||
|
|
||||||
|
# uwu
|
||||||
|
coefs = corr_submatrix(traces, model.transpose())
|
||||||
|
|
||||||
|
# plot absmax
|
||||||
coefs = numpy.abs(coefs)
|
coefs = numpy.abs(coefs)
|
||||||
max_by_key = numpy.max(coefs, axis=1)
|
max_by_key = numpy.max(coefs, axis=1)
|
||||||
plt.plot(max_by_key)
|
plt.plot(max_by_key)
|
||||||
|
|
Loading…
Reference in New Issue