= Appendix D: AES-256 13th Round Key Script =
<presyntaxhighlight lang=python># AES-256 13th Round Key Scriptfrom chipwhisperer.common.scripts.base import UserScriptBase# Imports from Preprocessingimport chipwhisperer.analyzer.preprocessing as preprocessing# Imports from Attackcw
from chipwhisperer.analyzer.attacks.cpa import CPA
from chipwhisperer.analyzer.attacks.cpa_algorithms.progressive import CPAProgressive
import from chipwhisperer.analyzer.attacks.models.AES128_8bitimport AES128_8bit, AESLeakageHelper# Imports from utilListchipwhisperer.analyzer.preprocessing.resync_sad import ResyncSAD
# Imports for AES256 Attackfrom chipwhisperer.analyzer.attacks.models.base import ModelsBasefrom chipwhisperer.analyzer.attacks.models.AES128_8bit import AESLeakageHelper, AES128_8bit class AES256_ModelAES256_Round13_Model(AESLeakageHelper): name = 'Our model'
def leakage(self, pt, ct, guess, bnum):
knownkey #You must but YOUR recovered 14th round key here - this example may not be accurate! calc_round_key = [0xea, 0x79, 0x79, 0x20, 0xc8, 0x71, 0x44, 0x7d, 0x46, 0x62, 0x5f, 0x51, 0x85, 0xc1, 0x3b, 0xcb] xored = [knownkeycalc_round_key[i] ^ pt[i] for i in range(0, 16)]
block = xored
block = self.inv_shiftrows(block)
return self.inv_sbox((result[bnum] ^ guess[bnum]))
class UserScript(UserScriptBase): _name traces = "Auto-generated" _description = "Auto-generated Attack Script" def __init__(self, api): UserScriptBase.__init__(self, api) self.initProject() self.initPreprocessing() self.initAnalysis() self.initReporting() def initProject(self): pass def initPreprocessing(self): ppMod0 = preprocessing.resync_sad.ResyncSAD(self.api.project().traceManager()) ppMod0.setEnabled(True) ppMod0.setReference(rtraceno=0, refpoints=(9100,9300), inputwindow=(8900,9500)) ppMod0.init() self.traces = ppMod0 def initAnalysis(self): self.attack = CPA() self.attack.setProject(self.api.project()) self.attack.setTraceSource(self.traces, blockSignal=True) leakage_object = AES128_8bit(AES256_Model) self.attack.setAnalysisAlgorithm(chipwhisperer.analyzer.attacks.cpa_algorithms.progressive.CPAProgressive,leakage_object) self.attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) self.attack.setTraceStart(0) self.attack.setTracesPerAttack(150) self.attack.setIterations(1) self.attack.setReportingInterval(10) self.attack.setPointRange((0,10991)) def initReporting(self): # Configures the attack observers (usually a set of GUI widgets) self.api.getResults("Attack Settings").setAnalysisSource(self.attack) self.api.getResults("Correlation vs Traces in Attack").setAnalysisSource(self.attack) self.api.getResults("Output vs Point Plot").setAnalysisSource(self.attack) self.api.getResults("PGE vs Trace Plot").setAnalysisSource(self.attack) self.api.getResults("Results Table").setAnalysisSource(self.attack) self.api.getResults("Save to Files").setAnalysisSource(self.attack) self.api.getResults("Trace Output Plot").setTraceSource(self.traces) self.api.getResults("Trace Recorder").setTraceSource(self.traces)
def runresync_traces = ResyncSAD(selftraces): selfresync_traces.attackenabled = Trueresync_traces.ref_trace = 0resync_traces.ref_points = (9100, 9300)resync_traces.processTracesinput_window = (8900, 9500)
if __name__ attack =CPA()leak_model = '__main__':AES128_8bit(AES256_Round13_Model) import chipwhisperer.analyzer.uiattack.CWAnalyzerGUI as cwasetAnalysisAlgorithm(CPAProgressive, leak_model) from chipwhisperer.common.utilsattack.parameter import ParametersetTraceSource(resync_traces) Parameterattack.usePyQtGraph = True # Comment if you don't need the GUIsetTraceStart(0) api = CWCoreAPIattack.setTracesPerAttack(-1) # Instantiate the API app = cwaattack.makeApplicationsetIterations("Analyzer"1) # Comment if you don't need the GUI gui = cwaattack.CWAnalyzerGUIsetReportingInterval(api10) # Comment if you don't need the GUI apiattack.runScriptClasssetTargetSubkeys(UserScript[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) # Run UserScript through the API appattack.exec_setPointRange((0, -1)) # Comment if you don't need the GUI
self.results_table.setAnalysisSource(attack)self.correlation_plot.setAnalysisSource(attack)self.output_plot.setAnalysisSource(attack)self.pge_plot.setAnalysisSource(attack)attack.processTraces()</presyntaxhighlight>
{{Template:Tutorials}}
[[Category:Tutorials]]