Skip to content

Instantly share code, notes, and snippets.

@CharlesLedger
Created February 14, 2019 15:28
Show Gist options
  • Save CharlesLedger/3867502c9752673c537c353bd210d90c to your computer and use it in GitHub Desktop.
Save CharlesLedger/3867502c9752673c537c353bd210d90c to your computer and use it in GitHub Desktop.
from lascar import *
from lascar.tools.aes import sbox
filename = "/home/johndoe/ASCAD_data/ASCAD_databases/ATMega8515_raw_traces.h5"
# poi = Points Of Interest.
# We use the SNRs computed before to extract time samples where both mask and masked sensitive variable are used.
snrs = DictOutputMethod.load('SNR.pickle') # we load the snr results computed at 02-snr.py
poi = []
poi = [snrs['SNR4: masked sbox output in linear parts'][5000].argmax()]
poi += [snrs['SNR5: sbox output mask in linear parts'][5000].argmax()]
# Container creation: we take the same file, but set the leakage_section to the computed poi.
container = Hdf5Container(filename,
leakages_dataset_name="traces",
values_dataset_name="metadata",
leakage_section=poi,
)
container.number_of_traces = 500
# Then we make a container that will apply a CenteredProduct to recombine all the points of interest.
container.leakage_processing = CenteredProductProcessing(container)
# Now a classical CPA, targetting the output of the 3rd Sbox:
cpa_engine = CpaEngine("cpa-high-order",
lambda value, guess: hamming(sbox[value['plaintext'][3] ^ guess]),
range(256),
solution=container[0].value['key'][3],
jit=False)
session = Session(container,
engine=cpa_engine,
output_method=ScoreProgressionOutputMethod(cpa_engine),
output_steps=10) # the steps at which the results will be computed
session.run(1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment