# Imports for AES256 Attack
from chipwhisperer.analyzer.attacks.models.base import ModelsBase
from chipwhisperer.analyzer.attacks.models.aes.funcs AES128_8bit import sboxAESLeakageHelper, inv_sbox, inv_shiftrows, inv_mixcolumns, inv_subbytesAES128_8bit
class AES256AttackAES256_Model(ModelsBaseAESLeakageHelper): _name name = 'AES 128Our model' def __init__(self): ModelsBase.__init__(self, 16, 256, model=None) self.numRoundKeys = 10 def leakage(self, textinpt, textoutct, guess, bnum, state):
knownkey = [0xea, 0x79, 0x79, 0x20, 0xc8, 0x71, 0x44, 0x7d, 0x46, 0x62, 0x5f, 0x51, 0x85, 0xc1, 0x3b, 0xcb]
xored = [knownkey[i] ^ textinpt[i] for i in range(0, 16)]
block = xored
block = self.inv_shiftrows(block) block = self.inv_subbytes(block) block = self.inv_mixcolumns(block) block = self.inv_shiftrows(block)
result = block
return self.HW[inv_sbox((result[bnum] ^ guess[bnum]))]
class UserScript(UserScriptBase):
name _name = "Auto-generated" description _description = "Auto-generated Attack Script"
def __init__(self, api):
UserScriptBase.__init__(self, api)
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) #leakage_object = chipwhisperer.analyzer.attacks.models.AES128_8bit.AES128_8bit(chipwhisperer.analyzer.attacks.models.AES128_8bit.SBox_output) self.attack.setAnalysisAlgorithm(chipwhisperer.analyzer.attacks.cpa_algorithms.progressive.CPAProgressive, AES256Attackleakage_object) self.attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, None15])
self.attack.setTraceStart(0)
self.attack.setTracesPerAttack(200150)
self.attack.setIterations(1)
self.attack.setReportingInterval(10)
self.attack.setTargetSubkeys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) self.attack.setPointRange((85000,10991))
def initReporting(self):
if __name__ == '__main__':
from chipwhisperer.common.api.CWCoreAPI import CWCoreAPI
import chipwhisperer.analyzer.ui.CWAnalyzerGUI as cwa
from chipwhisperer.common.utils.parameter import Parameter
app = cwa.makeApplication() # Comment if you don't need the GUI Parameter.usePyQtGraph = True # Comment if you don't need the GUI api = CWCoreAPI() # Instantiate the API gui app = cwa.CWAnalyzerGUImakeApplication(api"Analyzer") # Comment if you don't need the GUI gui= cwa.showCWAnalyzerGUI(api) # Comment if you don't need the GUI api.runScriptClass(UserScript) # Run UserScript through the API app.exec_() # Comment if you don't need the GUITraceback (most recent call last):GUI
</pre>